Commit 94cc4a5e authored by Andy Regensky's avatar Andy Regensky
Browse files

Add control point points

parent e1a6c206
......@@ -30,7 +30,7 @@
import sys
from PySide2.QtGui import QPainter, QColor, QPen, QPalette, QPolygonF
from PySide2.QtGui import QPainter, QColor, QPen, QPalette, QPolygonF, QBrush
from PySide2.QtWidgets import QWidget, QApplication
from PySide2.QtCore import QSize, Qt, QPointF, QRect, Slot
from fishui.MainViewModel import MainViewModel
......@@ -50,6 +50,8 @@ class PerspectiveBlockWidget(QWidget):
self.perspectiveMovedPolygon = None
self.controlPointPolygon = None
self.controlPointMovedPolygon = None
self.controlPointPoints = None
self.controlPointMovedPoints = None
self.updatePolygon(update=False)
self.initialCPMVs = None
......@@ -77,7 +79,7 @@ class PerspectiveBlockWidget(QWidget):
perspectiveMovedPolygon.append(QPointF(block_xpm[idx], block_ypm[idx]))
self.perspectivePolygon = perspectivePolygon
self.perspectiveMovedPolygon = perspectiveMovedPolygon
if self.viewModel.motion_model != 'translatory':
if self.viewModel.motion_model == 'affine4' or self.viewModel.motion_model == 'affine6':
if self.viewModel.block_ctr_px is None:
return
ctr_px = self.viewModel.block_ctr_px + sensor_offset_x
......@@ -89,6 +91,18 @@ class PerspectiveBlockWidget(QWidget):
controlPointMovedPolygon.append(QPointF(ctr_pxm[idx], ctr_pym[idx]))
self.controlPointPolygon = controlPointPolygon
self.controlPointMovedPolygon = controlPointMovedPolygon
if self.viewModel.motion_model == "affine4":
self.controlPointPoints = [controlPointPolygon.at(0),
controlPointPolygon.at(1)]
self.controlPointMovedPoints = [controlPointMovedPolygon.at(0),
controlPointMovedPolygon.at(1)]
else:
self.controlPointPoints = [controlPointPolygon.at(0),
controlPointPolygon.at(1),
controlPointPolygon.at(3)]
self.controlPointMovedPoints = [controlPointMovedPolygon.at(0),
controlPointMovedPolygon.at(1),
controlPointMovedPolygon.at(3)]
if update:
self.update()
......@@ -101,9 +115,9 @@ class PerspectiveBlockWidget(QWidget):
painter.setWindow(QRect(0, 0, self.viewModel.perspective_scale * self.viewModel.sensor_size_px[0],
self.viewModel.perspective_scale * self.viewModel.sensor_size_px[1]))
painter.setRenderHint(QPainter.Antialiasing)
self.drawPolygon(event, painter)
if self.viewModel.motion_model != 'translatory':
if self.viewModel.motion_model == 'affine4' or self.viewModel.motion_model == 'affine6':
self.drawControlPointBlock(event, painter)
self.drawPolygon(event, painter)
painter.end()
def drawPolygon(self, event, painter):
......@@ -127,11 +141,21 @@ class PerspectiveBlockWidget(QWidget):
pen = QPen()
pen.setColor(color)
pen.setWidth(painter.window().width()/400)
painter.setPen(pen)
brush = painter.brush()
if self.controlPointPolygon:
painter.setPen(pen)
painter.drawPolygon(self.controlPointPolygon)
painter.setBrush(color)
for point in self.controlPointPoints:
painter.drawEllipse(point, 2 * pen.width(), 2 * pen.width())
painter.setBrush(brush)
if self.controlPointMovedPolygon:
painter.setPen(pen)
painter.drawPolygon(self.controlPointMovedPolygon)
painter.setBrush(color)
for point in self.controlPointMovedPoints:
painter.drawEllipse(point, 2 * pen.width(), 2 * pen.width())
painter.setBrush(brush)
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
......
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