Commit ac7f3fdf authored by Andy Regensky's avatar Andy Regensky
Browse files

Add file menu and allow saving fisheye and perspective domain images

parent 18bb26a9
from PySide2.QtWidgets import *
from PySide2.QtCore import Qt
from PySide2.QtCore import Qt, Slot
import fishui.widgets as widgets
from fishui.MainViewModel import MainViewModel
......@@ -22,6 +22,23 @@ class MainWindow(QMainWindow):
splitter.setStyleSheet("QSplitter:handle { background-color: gray; }")
self.setCentralWidget(splitter)
# menu bar
mainMenu = self.menuBar()
mainMenu.setNativeMenuBar(False)
fileMenu = mainMenu.addMenu("File")
openAction = QAction("Open", self)
openAction.triggered.connect(self.distortionWidget.fisheyeWidget.openImage)
fileMenu.addAction(openAction)
saveMenu = fileMenu.addMenu("Save")
saveFisheyeAction = QAction("Fisheye", self)
saveFisheyeAction.triggered.connect(self.distortionWidget.fisheyeWidget.saveImage)
saveMenu.addAction(saveFisheyeAction)
savePerspectiveAction = QAction("Perspective", self)
savePerspectiveAction.triggered.connect(self.distortionWidget.perspectiveWidget.saveImage)
saveMenu.addAction(savePerspectiveAction)
self.setFocus()
self.show()
......
......@@ -20,7 +20,8 @@ class DistortionVisualizationWidget(QWidget):
self.fisheyeLabel.setStyleSheet("font-weight: bold; font-size: 16px")
self.fisheyeLabel.setAlignment(Qt.AlignCenter)
self.fisheyeLabel.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
self.fisheyeWidget = AspectRatioWidget(FisheyeWidget(self, viewModel), self)
self.fisheyeWidget = FisheyeWidget(self, viewModel)
self.fisheyeARWidget = AspectRatioWidget(self.fisheyeWidget, self)
# Perspective visualization
self.perspectiveLabel = QLabel(self)
......@@ -28,7 +29,8 @@ class DistortionVisualizationWidget(QWidget):
self.perspectiveLabel.setStyleSheet("font-weight: bold; font-size: 16px")
self.perspectiveLabel.setAlignment(Qt.AlignCenter)
self.perspectiveLabel.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
self.perspectiveWidget = AspectRatioWidget(PerspectiveWidget(self, viewModel), self)
self.perspectiveWidget = PerspectiveWidget(self, viewModel)
self.perspectiveARWidget = AspectRatioWidget(self.perspectiveWidget, self)
# Constrain both labels to have same minimum width
fisheye_label_width = self.fisheyeLabel.sizeHint().width()
......@@ -40,9 +42,9 @@ class DistortionVisualizationWidget(QWidget):
# Layout
layout = QGridLayout(self)
layout.addWidget(self.fisheyeLabel, 0, 0)
layout.addWidget(self.fisheyeWidget, 1, 0)
layout.addWidget(self.fisheyeARWidget, 1, 0)
layout.addWidget(self.perspectiveLabel, 0, 1)
layout.addWidget(self.perspectiveWidget, 1, 1)
layout.addWidget(self.perspectiveARWidget, 1, 1)
self.setLayout(layout)
......@@ -69,15 +71,15 @@ class DistortionVisualizationWidget(QWidget):
if self.viewModel.sensor_dimensions_valid:
self.overlay.setVisible(False)
self.fisheyeLabel.setGraphicsEffect(None)
self.fisheyeWidget.setGraphicsEffect(None)
self.fisheyeARWidget.setGraphicsEffect(None)
self.perspectiveLabel.setGraphicsEffect(None)
self.perspectiveWidget.setGraphicsEffect(None)
self.perspectiveARWidget.setGraphicsEffect(None)
aspect_ratio = self.viewModel.sensor_size_px[0]/self.viewModel.sensor_size_px[1]
self.fisheyeWidget.setAspectRatio(aspect_ratio)
self.perspectiveWidget.setAspectRatio(aspect_ratio)
self.fisheyeARWidget.setAspectRatio(aspect_ratio)
self.perspectiveARWidget.setAspectRatio(aspect_ratio)
else:
self.overlay.setVisible(True)
self.fisheyeLabel.setGraphicsEffect(QGraphicsBlurEffect(self))
self.fisheyeWidget.setGraphicsEffect(QGraphicsBlurEffect(self))
self.fisheyeARWidget.setGraphicsEffect(QGraphicsBlurEffect(self))
self.perspectiveLabel.setGraphicsEffect(QGraphicsBlurEffect(self))
self.perspectiveWidget.setGraphicsEffect(QGraphicsBlurEffect(self))
self.perspectiveARWidget.setGraphicsEffect(QGraphicsBlurEffect(self))
......@@ -56,19 +56,3 @@ class FisheyeBackgroundWidget(QWidget):
2 * self.viewModel.fov_180_radius
)
)
def contextMenuEvent(self, event):
menu = QMenu(self)
openAct = QAction("Open", self)
openAct.setStatusTip("Open a background image")
openAct.triggered.connect(self.openImage)
menu.addAction(openAct)
menu.exec_(event.globalPos())
@Slot()
def openImage(self):
image_files = QFileDialog.getOpenFileNames(self,
"Open images",
".",
"Images (*.png *.jpg *.jpeg)")[0]
self.viewModel.setFisheyeImages(image_files)
from PySide2.QtWidgets import QWidget, QGridLayout, QLabel, QGraphicsBlurEffect, QSizePolicy
from PySide2.QtCore import Qt, Slot, QSize
from PySide2.QtWidgets import QWidget, QFileDialog, QMenu, QAction
from PySide2.QtGui import QImage, QPainter
from PySide2.QtCore import Qt, Slot, QSize, QPoint
from fishui.MainViewModel import MainViewModel
from fishui.widgets.FisheyeBackgroundWidget import FisheyeBackgroundWidget
from fishui.widgets.FisheyeBlockWidget import FisheyeBlockWidget
# TODO: Overlaying widgets using QWidget leads to repainting all widgets if child widget is updated. Use QGraphics...?
class FisheyeWidget(QWidget):
def __init__(self, parent, viewModel: MainViewModel):
super().__init__(parent)
self.viewModel = viewModel
self.fisheyeBackgroundWidget = FisheyeBackgroundWidget(self, viewModel)
self.fisheyeBlockWidget = FisheyeBlockWidget(self, viewModel)
self.show()
......@@ -24,4 +25,38 @@ class FisheyeWidget(QWidget):
self.fisheyeBlockWidget.setGeometry(0, 0, w, h)
def contextMenuEvent(self, event):
self.fisheyeBackgroundWidget.contextMenuEvent(event)
menu = QMenu(self)
openAct = QAction("Open", self)
openAct.setStatusTip("Open fisheye background image")
openAct.triggered.connect(self.openImage)
menu.addAction(openAct)
saveAct = QAction("Save", self)
saveAct.setStatusTip("Save fisheye domain image")
saveAct.triggered.connect(self.saveImage)
menu.addAction(saveAct)
menu.exec_(event.globalPos())
@Slot()
def openImage(self):
image_files = QFileDialog.getOpenFileNames(self,
"Open images",
".",
"Images (*.png *.jpg *.jpeg)")[0]
self.viewModel.setFisheyeImages(image_files)
@Slot()
def saveImage(self):
filename = QFileDialog.getSaveFileName(self, "Save file", ".", ".png")[0]
if len(filename) == 0:
return
if not filename.endswith(".png"):
filename = filename + ".png"
height = 1080
scale = 1080 / self.size().height()
width = scale * self.size().width()
image = QImage(width, height, QImage.Format_RGB32)
painter = QPainter(image)
painter.scale(scale, scale)
self.render(painter, QPoint())
painter.end()
image.save(filename)
from PySide2.QtWidgets import QWidget, QGridLayout, QLabel, QGraphicsBlurEffect, QSizePolicy
from PySide2.QtCore import Qt, Slot, QSize
from PySide2.QtWidgets import QWidget, QGridLayout, QLabel, QGraphicsBlurEffect, QSizePolicy, QFileDialog, QMenu, QAction
from PySide2.QtGui import QImage, QPainter
from PySide2.QtCore import Qt, Slot, QSize, QPoint
from fishui.MainViewModel import MainViewModel
from fishui.widgets.PerspectiveBackgroundWidget import PerspectiveBackgroundWidget
from fishui.widgets.PerspectiveBlockWidget import PerspectiveBlockWidget
# TODO: Overlaying widgets using QWidget leads to repainting all widgets if child widget is updated. Use QGraphics...?
class PerspectiveWidget(QWidget):
def __init__(self, parent, viewModel: MainViewModel):
......@@ -22,3 +22,28 @@ class PerspectiveWidget(QWidget):
h = event.size().height()
self.perspectiveBackgroundWidget.setGeometry(0, 0, w, h)
self.perspectiveBlockWidget.setGeometry(0, 0, w, h)
def contextMenuEvent(self, event):
menu = QMenu(self)
saveAct = QAction("Save", self)
saveAct.setStatusTip("Save perspective domain image")
saveAct.triggered.connect(self.saveImage)
menu.addAction(saveAct)
menu.exec_(event.globalPos())
@Slot()
def saveImage(self):
filename = QFileDialog.getSaveFileName(self, "Save file", ".", ".png")[0]
if len(filename) == 0:
return
if not filename.endswith(".png"):
filename = filename + ".png"
height = 1080
scale = 1080 / self.size().height()
width = scale * self.size().width()
image = QImage(width, height, QImage.Format_RGB32)
painter = QPainter(image)
painter.scale(scale, scale)
self.render(painter, QPoint())
painter.end()
image.save(filename)
......@@ -139,10 +139,8 @@ class BlockProjectionWorker(QRunnable):
def updateReprojectedBlockpoints(self):
r_pm, phi_m = coordinate_conversion.cartesian_to_polar(self.block_ypm, self.block_xpm)
phi_m = phi_m - (self.uwc_sign < 0) * np.pi
r_fm = self.perspective.transform_to(self.projection, r_pm)
# FIXME: Use NEW UWC
rf_90 = self.projection.radius(np.deg2rad(90))
r_fm = r_fm + (self.uwc_sign < 0) * 2 * (rf_90 - r_fm)
theta_m = self.perspective.theta(r_pm) * self.uwc_sign + (self.uwc_sign < 0) * np.pi
r_fm = self.projection.radius(theta_m)
block_yfm, block_xfm = coordinate_conversion.polar_to_cartesian(r_fm, phi_m)
self.block_yfm = block_yfm + self.center[1]
self.block_xfm = block_xfm + self.center[0]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment