From f6332efa7e18b86106cde51f1e11ec0c12a5dd73 Mon Sep 17 00:00:00 2001 From: Aurore LAFAURIE Date: Thu, 16 May 2024 11:04:55 +0200 Subject: [PATCH] [ui] uvCenterOffset set according to principal point corrected or not + undistorted image path resolve according to output value of node --- meshroom/ui/components/filepath.py | 19 +++++++++++++++++++ meshroom/ui/qml/Viewer/Viewer2D.qml | 24 +++--------------------- meshroom/ui/reconstruction.py | 26 ++++++++++++++++---------- 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/meshroom/ui/components/filepath.py b/meshroom/ui/components/filepath.py index 1e06d20f..0db0bb8e 100644 --- a/meshroom/ui/components/filepath.py +++ b/meshroom/ui/components/filepath.py @@ -98,3 +98,22 @@ class FilepathHelper(QObject): def fileSizeMB(self, path): """ Returns the file size in MB. """ return QFileInfo(self.asStr(path)).size() / (1024*1024) + + @Slot(str, QObject, result=str) + def resolve(self, path, vp): + # Resolve dynamic path that depends on viewpoint + + replacements = { + "": str(vp.childAttribute("viewId").value), + "": str(vp.childAttribute("intrinsicId").value), + "": str(vp.childAttribute("poseId").value), + "": vp.childAttribute("path").value, + "": FilepathHelper.basename(FilepathHelper, vp.childAttribute("path").value), + "": FilepathHelper.removeExtension(FilepathHelper, FilepathHelper.basename(FilepathHelper, vp.childAttribute("path").value)), + } + + resolved = path + for key in replacements: + resolved = resolved.replace(key, replacements[key]) + + return resolved \ No newline at end of file diff --git a/meshroom/ui/qml/Viewer/Viewer2D.qml b/meshroom/ui/qml/Viewer/Viewer2D.qml index b1912a38..87d39835 100644 --- a/meshroom/ui/qml/Viewer/Viewer2D.qml +++ b/meshroom/ui/qml/Viewer/Viewer2D.qml @@ -222,24 +222,6 @@ FocusScope { return undefined } - function resolve(path, vp) { - // Resolve dynamic path that depends on viewpoint - - let replacements = { - "": vp.childAttribute("viewId").value, - "": vp.childAttribute("intrinsicId").value, - "": vp.childAttribute("poseId").value, - "": vp.childAttribute("path").value, - "": Filepath.removeExtension(Filepath.basename(vp.childAttribute("path").value)), - } - - let resolved = path; - for (let key in replacements) { - resolved = resolved.replace(key, replacements[key]) - } - - return resolved; - } function getImageFile() { // Entry point for getting the image file URL @@ -258,7 +240,7 @@ FocusScope { let vp = getViewpoint(_reconstruction.pickedViewId) let attr = getAttributeByName(displayedNode, outputAttribute.name) let path = attr ? attr.value : "" - let resolved = vp ? resolve(path, vp) : path + let resolved = vp ? Filepath.resolve(path, vp) : path return Filepath.stringToUrl(resolved) } @@ -277,7 +259,7 @@ FocusScope { let seq = []; for (let i = 0; i < objs.length; i++) { - seq.push(resolve(path_template, objs[i])) + seq.push(Filepath.resolve(path_template, objs[i])) } return seq @@ -1032,7 +1014,7 @@ FocusScope { property var vp: _reconstruction ? getViewpoint(_reconstruction.selectedViewId) : null sourceComponent: CameraResponseGraph { - responsePath: resolve(path, vp) + responsePath: Filepath.resolve(path, vp) } } } diff --git a/meshroom/ui/reconstruction.py b/meshroom/ui/reconstruction.py index 69fe64ed..bf94503f 100755 --- a/meshroom/ui/reconstruction.py +++ b/meshroom/ui/reconstruction.py @@ -17,6 +17,7 @@ from meshroom.core import Version from meshroom.core.node import Node, CompatibilityNode, Status, Position from meshroom.ui.graph import UIGraph from meshroom.ui.utils import makeProperty +from meshroom.ui.components.filepath import FilepathHelper class Message(QObject): @@ -171,6 +172,8 @@ class ViewpointWrapper(QObject): sfmParamsChanged = Signal() undistortedImageParamsChanged = Signal() internalChanged = Signal() + principalPointCorrectedChanged = Signal() + uvCenterOffsetChanged = Signal() def __init__(self, viewpointAttribute, reconstruction): """ @@ -195,6 +198,9 @@ class ViewpointWrapper(QObject): self._undistortedImagePath = '' self._activeNode_PrepareDenseScene = self._reconstruction.activeNodes.get("PrepareDenseScene") self._activeNode_ExportAnimatedCamera = self._reconstruction.activeNodes.get("ExportAnimatedCamera") + self._principalPointCorrected = False + self.principalPointCorrectedChanged.connect(self.uvCenterOffsetChanged) + self.sfmParamsChanged.connect(self.uvCenterOffsetChanged) # update internally cached variables self._updateInitialParams() @@ -240,17 +246,17 @@ class ViewpointWrapper(QObject): def _updateUndistortedImageParams(self): """ Update internal members depending on PrepareDenseScene or ExportAnimatedCamera. """ # undistorted image path - if not self._activeNode_PrepareDenseScene.node or not self._activeNode_ExportAnimatedCamera.node: - # if not self._activeNode_PrepareDenseScene.node: - self._undistortedImagePath = '' if self._activeNode_ExportAnimatedCamera.node: - basename = "{}_{}".format(self._viewpoint.intrinsicId.value, os.path.basename(self._viewpoint.path.value)) - filename = "{}.{}".format(os.path.splitext(basename)[0], self._activeNode_ExportAnimatedCamera.node.undistortedImageType.value) - self._undistortedImagePath = os.path.join(self._activeNode_ExportAnimatedCamera.node.output.value, "undistort", filename) + self._undistortedImagePath = FilepathHelper.resolve(FilepathHelper, self._activeNode_ExportAnimatedCamera.node.outputUndistorted.value, self._viewpoint) + self._principalPointCorrected = self._activeNode_ExportAnimatedCamera.node.correctPrincipalPoint.value + elif self._activeNode_PrepareDenseScene.node: + self._undistortedImagePath = FilepathHelper.resolve(FilepathHelper, self._activeNode_PrepareDenseScene.node.undistorted.value, self._viewpoint) + self._principalPointCorrected = False else: - filename = "{}.{}".format(self._viewpoint.viewId.value, self._activeNode_PrepareDenseScene.node.outputFileType.value) - self._undistortedImagePath = os.path.join(self._activeNode_PrepareDenseScene.node.output.value, filename) + self._undistortedImagePath = '' + self._principalPointCorrected = False self.undistortedImageParamsChanged.emit() + self.principalPointCorrectedChanged.emit() # Get the underlying Viewpoint attribute wrapped by this Viewpoint. attribute = Property(QObject, lambda self: self._viewpoint, constant=True) @@ -334,10 +340,10 @@ class ViewpointWrapper(QObject): """ Get camera up vector. """ return QVector3D(0.0, 1.0, 0.0) - @Property(type=QVector2D, notify=sfmParamsChanged) + @Property(type=QVector2D, notify=uvCenterOffsetChanged) def uvCenterOffset(self): """ Get UV offset corresponding to the camera principal point. """ - if not self.solvedIntrinsics: + if not self.solvedIntrinsics or self._principalPointCorrected: return None pp = self.solvedIntrinsics["principalPoint"] # compute principal point offset in UV space