Commit 22471ec4 authored by Andy Regensky's avatar Andy Regensky
Browse files

Implement dynamic resizing for non-square sensor layouts

parent 480495a3
......@@ -20,8 +20,8 @@ class MainViewModel(QObject):
'calibrated': projections.CalibratedProjection
}
self.sensor_size_mm = (5.2, 10.4)
self.sensor_size_px = (1088, 2176)
self.sensor_size_mm = (5.2, 5.2)
self.sensor_size_px = (1088, 1088)
self.focal_length_mm = 1.8
self.projection_key = 'equisolid'
self.calibration_coeffs = None
......
......@@ -4,9 +4,8 @@ from PySide2.QtWidgets import QBoxLayout, QSpacerItem, QWidget
class AspectRatioWidget(QWidget):
def __init__(self, widget, parent):
super().__init__(parent)
self.aspect_ratio = widget.size().width() / widget.size().height()
self.aspect_ratio = 1
self.setLayout(QBoxLayout(QBoxLayout.LeftToRight, self))
# add spacer, then widget, then spacer
self.layout().addItem(QSpacerItem(0, 0))
self.layout().addWidget(widget)
self.layout().addItem(QSpacerItem(0, 0))
......@@ -14,16 +13,22 @@ class AspectRatioWidget(QWidget):
def resizeEvent(self, e):
w = e.size().width()
h = e.size().height()
self.matchAspectRatio(w, h)
if w / h > self.aspect_ratio: # too wide
def setAspectRatio(self, aspect_ratio):
self.aspect_ratio = aspect_ratio
self.matchAspectRatio(self.size().width(), self.size().height())
def matchAspectRatio(self, current_width, current_height):
if current_width / current_height > self.aspect_ratio: # too wide
self.layout().setDirection(QBoxLayout.LeftToRight)
widget_stretch = h * self.aspect_ratio
outer_stretch = (w - widget_stretch) / 2 + 0.5
widget_stretch = current_height * self.aspect_ratio
outer_stretch = (current_width - widget_stretch) / 2 + 0.5
else: # too tall
self.layout().setDirection(QBoxLayout.TopToBottom)
widget_stretch = w / self.aspect_ratio
outer_stretch = (h - widget_stretch) / 2 + 0.5
widget_stretch = current_width / self.aspect_ratio
outer_stretch = (current_height - widget_stretch) / 2 + 0.5
self.layout().setStretch(0, outer_stretch)
self.layout().setStretch(1, widget_stretch)
self.layout().setStretch(2, outer_stretch)
\ No newline at end of file
self.layout().setStretch(2, outer_stretch)
from PySide2.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QLabel, QGraphicsBlurEffect
from PySide2.QtWidgets import QWidget, QGridLayout, QLabel, QGraphicsBlurEffect, QSizePolicy
from PySide2.QtCore import Qt, Slot
from fishui.MainViewModel import MainViewModel
from fishui.widgets.AspectRatioWidget import AspectRatioWidget
......@@ -19,40 +19,43 @@ class DistortionVisualizationWidget(QWidget):
self.fisheyeLabel.setText("Fisheye domain")
self.fisheyeLabel.setStyleSheet("font-weight: bold; font-size: 16px")
self.fisheyeLabel.setAlignment(Qt.AlignCenter)
self.fisheyeLabel.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
self.fisheyeBlockWidget = AspectRatioWidget(FisheyeBlockWidget(self, viewModel), self)
fisheyeLayout = QVBoxLayout()
fisheyeLayout.addWidget(self.fisheyeLabel)
fisheyeLayout.addWidget(self.fisheyeBlockWidget)
# Perspective visualization
self.perspectiveLabel = QLabel(self)
self.perspectiveLabel.setText("Perspective domain")
self.perspectiveLabel.setStyleSheet("font-weight: bold; font-size: 16px")
self.perspectiveLabel.setAlignment(Qt.AlignCenter)
self.perspectiveLabel.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
self.perspectiveBlockWidget = AspectRatioWidget(PerspectiveBlockWidget(self, viewModel), self)
perspectiveLayout = QVBoxLayout()
perspectiveLayout.addWidget(self.perspectiveLabel)
perspectiveLayout.addWidget(self.perspectiveBlockWidget)
# Constrain both labels to have same minimum width
fisheye_label_width = self.fisheyeLabel.sizeHint().width()
perspective_label_width = self.perspectiveLabel.sizeHint().width()
min_width_constraint = max(fisheye_label_width, perspective_label_width)
self.fisheyeLabel.setMinimumWidth(min_width_constraint)
# Layout
layout = QHBoxLayout(self)
layout.addLayout(fisheyeLayout)
layout.addLayout(perspectiveLayout)
layout = QGridLayout(self)
layout.addWidget(self.fisheyeLabel, 0, 0)
layout.addWidget(self.fisheyeBlockWidget, 1, 0)
layout.addWidget(self.perspectiveLabel, 0, 1)
layout.addWidget(self.perspectiveBlockWidget, 1, 1)
self.setLayout(layout)
# Invalid sensor dimensions overlay
self.overlay = QLabel(self)
self.overlay.setText("Sensor dimensions do not result in square-sized pixels.")
self.overlay.setStyleSheet("background-color: rgba(100, 100, 100, 0.5);"
self.overlay.setStyleSheet("background-color: rgba(55, 55, 55, 0.5);"
"color: white;"
"font-weight: bold;"
"font-size: 16px;")
self.overlay.setAlignment(Qt.AlignCenter)
self.overlay.setVisible(False)
self.viewModelChanged()
self.show()
def resizeEvent(self, e):
......@@ -68,6 +71,9 @@ class DistortionVisualizationWidget(QWidget):
self.fisheyeBlockWidget.setGraphicsEffect(None)
self.perspectiveLabel.setGraphicsEffect(None)
self.perspectiveBlockWidget.setGraphicsEffect(None)
aspect_ratio = self.viewModel.sensor_size_px[0]/self.viewModel.sensor_size_px[1]
self.fisheyeBlockWidget.setAspectRatio(aspect_ratio)
self.perspectiveBlockWidget.setAspectRatio(aspect_ratio)
else:
self.overlay.setVisible(True)
self.fisheyeLabel.setGraphicsEffect(QGraphicsBlurEffect(self))
......
......@@ -19,7 +19,7 @@ class FisheyeBlockWidget(QWidget):
self.initialOrigin = None
self.initialMouse = None
self.setMinimumSize(QSize(300, 300))
# self.setMinimumSize(QSize(300, 300))
self.show()
@Slot()
......
......@@ -24,7 +24,7 @@ class PerspectiveBlockWidget(QWidget):
self.initialMV1 = None
self.initialMouse = None
self.setMinimumSize(QSize(300, 300))
# self.setMinimumSize(QSize(300, 300))
self.show()
@Slot()
......
......@@ -188,7 +188,6 @@ class PropertiesWidget(QWidget):
def sensorSizeWidthEditingFinished(self):
sensor_size = self.viewModel.sensor_size_mm
sensor_size = (float(self.sensorSizeWidthEdit.text()), sensor_size[1])
print(sensor_size)
self.viewModel.setSensorSize(sensor_size)
@Slot()
......
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