Skip to content

Commit 21442c8

Browse files
committed
[ui] uvCenterOffset set according to principal point corrected or not + undistorted image path resolve according to output value of node
1 parent ad7745a commit 21442c8

File tree

3 files changed

+33
-31
lines changed

3 files changed

+33
-31
lines changed

meshroom/ui/components/filepath.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,22 @@ def globFirst(self, path):
9898
def fileSizeMB(self, path):
9999
""" Returns the file size in MB. """
100100
return QFileInfo(self.asStr(path)).size() / (1024*1024)
101+
102+
@Slot(str, QObject, result=str)
103+
def resolve(self, path, vp):
104+
# Resolve dynamic path that depends on viewpoint
105+
106+
replacements = {
107+
"<VIEW_ID>": str(vp.childAttribute("viewId").value),
108+
"<INTRINSIC_ID>": str(vp.childAttribute("intrinsicId").value),
109+
"<POSE_ID>": str(vp.childAttribute("poseId").value),
110+
"<PATH>": vp.childAttribute("path").value,
111+
"<FILENAME>": FilepathHelper.basename(FilepathHelper, vp.childAttribute("path").value),
112+
"<FILESTEM>": FilepathHelper.removeExtension(FilepathHelper, FilepathHelper.basename(FilepathHelper, vp.childAttribute("path").value)),
113+
}
114+
115+
resolved = path
116+
for key in replacements:
117+
resolved = resolved.replace(key, replacements[key])
118+
119+
return resolved

meshroom/ui/qml/Viewer/Viewer2D.qml

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -222,24 +222,6 @@ FocusScope {
222222
return undefined
223223
}
224224

225-
function resolve(path, vp) {
226-
// Resolve dynamic path that depends on viewpoint
227-
228-
let replacements = {
229-
"<VIEW_ID>": vp.childAttribute("viewId").value,
230-
"<INTRINSIC_ID>": vp.childAttribute("intrinsicId").value,
231-
"<POSE_ID>": vp.childAttribute("poseId").value,
232-
"<PATH>": vp.childAttribute("path").value,
233-
"<FILENAME>": Filepath.removeExtension(Filepath.basename(vp.childAttribute("path").value)),
234-
}
235-
236-
let resolved = path;
237-
for (let key in replacements) {
238-
resolved = resolved.replace(key, replacements[key])
239-
}
240-
241-
return resolved;
242-
}
243225

244226
function getImageFile() {
245227
// Entry point for getting the image file URL
@@ -258,7 +240,7 @@ FocusScope {
258240
let vp = getViewpoint(_reconstruction.pickedViewId)
259241
let attr = getAttributeByName(displayedNode, outputAttribute.name)
260242
let path = attr ? attr.value : ""
261-
let resolved = vp ? resolve(path, vp) : path
243+
let resolved = vp ? Filepath.resolve(path, vp) : path
262244
return Filepath.stringToUrl(resolved)
263245
}
264246

@@ -277,7 +259,7 @@ FocusScope {
277259

278260
let seq = [];
279261
for (let i = 0; i < objs.length; i++) {
280-
seq.push(resolve(path_template, objs[i]))
262+
seq.push(Filepath.resolve(path_template, objs[i]))
281263
}
282264

283265
return seq
@@ -1032,7 +1014,7 @@ FocusScope {
10321014
property var vp: _reconstruction ? getViewpoint(_reconstruction.selectedViewId) : null
10331015

10341016
sourceComponent: CameraResponseGraph {
1035-
responsePath: resolve(path, vp)
1017+
responsePath: Filepath.resolve(path, vp)
10361018
}
10371019
}
10381020
}

meshroom/ui/reconstruction.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from meshroom.core.node import Node, CompatibilityNode, Status, Position
1818
from meshroom.ui.graph import UIGraph
1919
from meshroom.ui.utils import makeProperty
20+
from meshroom.ui.components.filepath import FilepathHelper
2021

2122

2223
class Message(QObject):
@@ -171,6 +172,7 @@ class ViewpointWrapper(QObject):
171172
sfmParamsChanged = Signal()
172173
undistortedImageParamsChanged = Signal()
173174
internalChanged = Signal()
175+
principalPointCorrectedChanged = Signal()
174176

175177
def __init__(self, viewpointAttribute, reconstruction):
176178
"""
@@ -195,6 +197,7 @@ def __init__(self, viewpointAttribute, reconstruction):
195197
self._undistortedImagePath = ''
196198
self._activeNode_PrepareDenseScene = self._reconstruction.activeNodes.get("PrepareDenseScene")
197199
self._activeNode_ExportAnimatedCamera = self._reconstruction.activeNodes.get("ExportAnimatedCamera")
200+
self._principalPointCorrected = False
198201

199202
# update internally cached variables
200203
self._updateInitialParams()
@@ -240,16 +243,14 @@ def _updateSfMParams(self):
240243
def _updateUndistortedImageParams(self):
241244
""" Update internal members depending on PrepareDenseScene or ExportAnimatedCamera. """
242245
# undistorted image path
243-
if not self._activeNode_PrepareDenseScene.node or not self._activeNode_ExportAnimatedCamera.node:
244-
# if not self._activeNode_PrepareDenseScene.node:
245-
self._undistortedImagePath = ''
246246
if self._activeNode_ExportAnimatedCamera.node:
247-
basename = "{}_{}".format(self._viewpoint.intrinsicId.value, os.path.basename(self._viewpoint.path.value))
248-
filename = "{}.{}".format(os.path.splitext(basename)[0], self._activeNode_ExportAnimatedCamera.node.undistortedImageType.value)
249-
self._undistortedImagePath = os.path.join(self._activeNode_ExportAnimatedCamera.node.output.value, "undistort", filename)
247+
self._undistortedImagePath = FilepathHelper.resolve(FilepathHelper, self._activeNode_ExportAnimatedCamera.node.outputUndistorted.value, self._viewpoint)
248+
self._principalPointCorrected = self._activeNode_ExportAnimatedCamera.node.correctPrincipalPoint.value
249+
self.principalPointCorrectedChanged.emit()
250+
elif self._activeNode_PrepareDenseScene.node:
251+
self._undistortedImagePath = FilepathHelper.resolve(FilepathHelper, self._activeNode_PrepareDenseScene.node.undistorted.value, self._viewpoint)
250252
else:
251-
filename = "{}.{}".format(self._viewpoint.viewId.value, self._activeNode_PrepareDenseScene.node.outputFileType.value)
252-
self._undistortedImagePath = os.path.join(self._activeNode_PrepareDenseScene.node.output.value, filename)
253+
self._undistortedImagePath = ''
253254
self.undistortedImageParamsChanged.emit()
254255

255256
# Get the underlying Viewpoint attribute wrapped by this Viewpoint.
@@ -334,10 +335,10 @@ def upVector(self):
334335
""" Get camera up vector. """
335336
return QVector3D(0.0, 1.0, 0.0)
336337

337-
@Property(type=QVector2D, notify=sfmParamsChanged)
338+
@Property(type=QVector2D, notify=sfmParamsChanged and principalPointCorrectedChanged)
338339
def uvCenterOffset(self):
339340
""" Get UV offset corresponding to the camera principal point. """
340-
if not self.solvedIntrinsics:
341+
if not self.solvedIntrinsics or self._principalPointCorrected:
341342
return None
342343
pp = self.solvedIntrinsics["principalPoint"]
343344
# compute principal point offset in UV space

0 commit comments

Comments
 (0)