Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add relative paths to nodes as variables #2629

Draft
wants to merge 10 commits into
base: develop
Choose a base branch
from
16 changes: 13 additions & 3 deletions meshroom/core/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,11 @@ def uid(self):
# To guarantee that each output attribute receives a unique ID, we add the attribute name to it.
return hashValue((self.name, self.node._uid))
else:
# only dependent on the hash of its value without the cache folder
return hashValue(self._invalidationValue)
# Only dependent on the hash of its value without the cache folder.
# "/" at the end of the link is stripped to prevent having different UIDs depending on
# whether the invalidation value finishes with it or not
strippedInvalidationValue = self._invalidationValue.rstrip("/")
return hashValue(strippedInvalidationValue)
if self.isLink:
linkParam = self.getLinkParam(recursive=True)
return linkParam.uid()
Expand Down Expand Up @@ -350,7 +353,14 @@ def getEvalValue(self):
Return the value. If it is a string, expressions will be evaluated.
'''
if isinstance(self.value, str):
return Template(self.value).safe_substitute(os.environ)
substituted = Template(self.value).safe_substitute(os.environ)
try:
varResolved = substituted.format(**self.node._cmdVars)
return varResolved
except KeyError:
# Catch KeyErrors to be able to open files created prior to the support of relative variables
# (when self.node._cmdVars was not used to evaluate expressions in the attribute)
return substituted
return self.value

def getValueStr(self, withQuotes=True):
Expand Down
4 changes: 3 additions & 1 deletion meshroom/core/desc/node.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from inspect import getfile
from pathlib import Path
import os
import psutil
import shlex
Expand All @@ -11,7 +13,6 @@
class Node(object):
"""
"""
internalFolder = '{cache}/{nodeType}/{uid}/'
cpu = Level.NORMAL
gpu = Level.NONE
ram = Level.NORMAL
Expand Down Expand Up @@ -63,6 +64,7 @@ class Node(object):
def __init__(self):
super(Node, self).__init__()
self.hasDynamicOutputAttribute = any(output.isDynamicValue for output in self.outputs)
self.sourceCodeFolder = Path(getfile(self.__class__)).parent.resolve().as_posix()

def upgradeAttributeValues(self, attrValues, fromVersion):
return attrValues
Expand Down
22 changes: 18 additions & 4 deletions meshroom/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ def __init__(self, nodeType, position=None, parent=None, uid=None, **kwargs):

self.packageName = self.packageVersion = ""
self._internalFolder = ""
self._sourceCodeFolder = ""

self._name = None
self.graph = None
Expand Down Expand Up @@ -757,6 +758,8 @@ def _buildAttributeCmdVars(cmdVars, name, attr):

""" Generate command variables using input attributes and resolved output attributes names and values. """
self._cmdVars["uid"] = self._uid
self._cmdVars["nodeCacheFolder"] = self.internalFolder
self._cmdVars["nodeSourceCodeFolder"] = self.sourceCodeFolder

# Evaluate input params
for name, attr in self._attributes.objects.items():
Expand All @@ -766,7 +769,11 @@ def _buildAttributeCmdVars(cmdVars, name, attr):

# For updating output attributes invalidation values
cmdVarsNoCache = self._cmdVars.copy()
cmdVarsNoCache['cache'] = ''
cmdVarsNoCache["cache"] = ""

# Use "self._internalFolder" instead of "self.internalFolder" because we do not want it to be
# resolved with the {cache} information ("self.internalFolder" resolves "self._internalFolder")
cmdVarsNoCache["nodeCacheFolder"] = self._internalFolder.format(**cmdVarsNoCache)

# Evaluate output params
for name, attr in self._attributes.objects.items():
Expand Down Expand Up @@ -1021,8 +1028,10 @@ def updateInternals(self, cacheDir=None):

# Update command variables / output attributes
self._cmdVars = {
'cache': cacheDir or self.graph.cacheDir,
'nodeType': self.nodeType,
"cache": cacheDir or self.graph.cacheDir,
"nodeType": self.nodeType,
"nodeCacheFolder": self._internalFolder,
"nodeSourceCodeFolder": self.sourceCodeFolder
}
self._computeUid()
self._buildCmdVars()
Expand All @@ -1039,6 +1048,10 @@ def updateInternalAttributes(self):
def internalFolder(self):
return self._internalFolder.format(**self._cmdVars)

@property
def sourceCodeFolder(self):
return self._sourceCodeFolder

def updateStatusFromCache(self):
"""
Update node status based on status file content/existence.
Expand Down Expand Up @@ -1440,7 +1453,8 @@ def __init__(self, nodeType, position=None, parent=None, uid=None, **kwargs):

self.packageName = self.nodeDesc.packageName
self.packageVersion = self.nodeDesc.packageVersion
self._internalFolder = self.nodeDesc.internalFolder
self._internalFolder = "{cache}/{nodeType}/{uid}"
self._sourceCodeFolder = self.nodeDesc.sourceCodeFolder

for attrDesc in self.nodeDesc.inputs:
self._attributes.add(attributeFactory(attrDesc, kwargs.get(attrDesc.name, None), isOutput=False, node=self))
Expand Down
2 changes: 1 addition & 1 deletion meshroom/nodes/aliceVision/ApplyCalibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ class ApplyCalibration(desc.AVCommandLineNode):
name="output",
label="SMData",
description="Path to the output SfMData file.",
value=desc.Node.internalFolder + "sfmData.sfm",
value="{nodeCacheFolder}/sfmData.sfm",
),
]
2 changes: 1 addition & 1 deletion meshroom/nodes/aliceVision/CameraCalibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ class CameraCalibration(desc.AVCommandLineNode):
name="output",
label="Output",
description="Output filename for intrinsic [and extrinsic] parameters.",
value=desc.Node.internalFolder + "/cameraCalibration.cal",
value="{nodeCacheFolder}/cameraCalibration.cal",
),
]
4 changes: 2 additions & 2 deletions meshroom/nodes/aliceVision/CameraInit.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ class CameraInit(desc.AVCommandLineNode, desc.InitNode):
name="output",
label="SfMData",
description="Output SfMData.",
value=desc.Node.internalFolder + "cameraInit.sfm",
value="{nodeCacheFolder}/cameraInit.sfm",
),
]

Expand Down Expand Up @@ -670,7 +670,7 @@ def createViewpointsFile(self, node, additionalViews=()):
"featureFolder": "",
"matchingFolder": "",
}
node.viewpointsFile = os.path.join(node.nodeDesc.internalFolder, 'viewpoints.sfm').format(**node._cmdVars)
node.viewpointsFile = os.path.join(node.internalFolder, 'viewpoints.sfm').format(**node._cmdVars)
with open(node.viewpointsFile, 'w') as f:
json.dump(sfmData, f, indent=4)

Expand Down
4 changes: 2 additions & 2 deletions meshroom/nodes/aliceVision/CameraLocalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ class CameraLocalization(desc.AVCommandLineNode):
name="outputAlembic",
label="Alembic",
description="Filename for the SfMData export file (where camera poses will be stored).",
value=desc.Node.internalFolder + "trackedCameras.abc",
value="{nodeCacheFolder}/trackedCameras.abc",
),
desc.File(
name="outputJSON",
label="JSON File",
description="Filename for the localization results as .json.",
value=desc.Node.internalFolder + "trackedCameras.json",
value="{nodeCacheFolder}/trackedCameras.json",
),
]
2 changes: 1 addition & 1 deletion meshroom/nodes/aliceVision/CameraRigCalibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,6 @@ class CameraRigCalibration(desc.AVCommandLineNode):
name="outfile",
label="Output File",
description="The name of the file to store the calibration data in.",
value=desc.Node.internalFolder + "cameraRigCalibration.rigCal",
value="{nodeCacheFolder}/cameraRigCalibration.rigCal",
),
]
2 changes: 1 addition & 1 deletion meshroom/nodes/aliceVision/CameraRigLocalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ class CameraRigLocalization(desc.AVCommandLineNode):
name="outputAlembic",
label="Alembic",
description="Filename for the SfMData export file (where camera poses will be stored).",
value=desc.Node.internalFolder + "trackedcameras.abc",
value="{nodeCacheFolder}/trackedcameras.abc",
),
]
2 changes: 1 addition & 1 deletion meshroom/nodes/aliceVision/CheckerboardCalibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ class CheckerboardCalibration(desc.AVCommandLineNode):
name="output",
label="SfMData File",
description="Path to the output SfMData file.",
value=desc.Node.internalFolder + "sfmData.sfm",
value="{nodeCacheFolder}/sfmData.sfm",
)
]
4 changes: 2 additions & 2 deletions meshroom/nodes/aliceVision/CheckerboardDetection.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ class CheckerboardDetection(desc.AVCommandLineNode):
name="output",
label="Folder",
description="Output folder.",
value=desc.Node.internalFolder,
value="{nodeCacheFolder}",
),
desc.File(
name="checkerLines",
enabled=lambda node: node.exportDebugImages.value,
label="Checker Lines",
description="Debug images.",
semantic="image",
value=desc.Node.internalFolder + "<VIEW_ID>.png",
value="{nodeCacheFolder}/<VIEW_ID>.png",
group="", # do not export on the command line
),
]
4 changes: 2 additions & 2 deletions meshroom/nodes/aliceVision/ColorCheckerCorrection.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ class ColorCheckerCorrection(desc.AVCommandLineNode):
name="outSfMData",
label="SfMData",
description="Output SfMData.",
value=lambda attr: (desc.Node.internalFolder + os.path.basename(attr.node.input.value)) if (os.path.splitext(attr.node.input.value)[1] in [".abc", ".sfm"]) else "",
value=lambda attr: ("{nodeCacheFolder}/" + os.path.basename(attr.node.input.value)) if (os.path.splitext(attr.node.input.value)[1] in [".abc", ".sfm"]) else "",
group="", # do not export on the command line
),
desc.File(
name="output",
label="Folder",
description="Output images folder.",
value=desc.Node.internalFolder,
value="{nodeCacheFolder}",
),
]
2 changes: 1 addition & 1 deletion meshroom/nodes/aliceVision/ColorCheckerDetection.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ class ColorCheckerDetection(desc.AVCommandLineNode):
name="outputData",
label="Color Checker Data",
description="Output position and colorimetric data extracted from detected color checkers in the images.",
value=desc.Node.internalFolder + "/ccheckers.json",
value="{nodeCacheFolder}/ccheckers.json",
),
]
2 changes: 1 addition & 1 deletion meshroom/nodes/aliceVision/ConvertDistortion.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ class ConvertDistortion(desc.AVCommandLineNode):
name="output",
label="Output",
description="Path to the output SfMData file.",
value=desc.Node.internalFolder + "sfm.abc",
value="{nodeCacheFolder}/sfm.abc",
),
]
2 changes: 1 addition & 1 deletion meshroom/nodes/aliceVision/ConvertMesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ class ConvertMesh(desc.AVCommandLineNode):
name="output",
label="Mesh",
description="Output mesh (*.obj, *.mesh, *.meshb, *.ply, *.off, *.stl).",
value=desc.Node.internalFolder + "mesh." + "{outputMeshFileTypeValue}",
value="{nodeCacheFolder}/mesh.{outputMeshFileTypeValue}",
),
]
2 changes: 1 addition & 1 deletion meshroom/nodes/aliceVision/ConvertSfMFormat.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ class ConvertSfMFormat(desc.AVCommandLineNode):
name="output",
label="Output",
description="Path to the output SfMData file.",
value=desc.Node.internalFolder + "sfm.{fileExtValue}",
value="{nodeCacheFolder}/sfm.{fileExtValue}",
),
]
14 changes: 7 additions & 7 deletions meshroom/nodes/aliceVision/DepthMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ class DepthMap(desc.AVCommandLineNode):
name="output",
label="Folder",
description="Output folder for generated depth maps.",
value=desc.Node.internalFolder,
value="{nodeCacheFolder}",
),
# these attributes are only here to describe more accurately the output of the node
# by specifying that it generates 2 sequences of images
Expand All @@ -575,22 +575,22 @@ class DepthMap(desc.AVCommandLineNode):
label="Depth Maps",
description="Generated depth maps.",
semantic="image",
value=desc.Node.internalFolder + "<VIEW_ID>_depthMap.exr",
value="{nodeCacheFolder}/<VIEW_ID>_depthMap.exr",
group="", # do not export on the command line
),
desc.File(
name="sim",
label="Sim Maps",
description="Generated sim maps.",
semantic="image",
value=desc.Node.internalFolder + "<VIEW_ID>_simMap.exr",
value="{nodeCacheFolder}/<VIEW_ID>_simMap.exr",
group="", # do not export on the command line
),
desc.File(
name="tilePattern",
label="Tile Pattern",
description="Debug: Tile pattern.",
value=desc.Node.internalFolder + "<VIEW_ID>_tilePattern.obj",
value="{nodeCacheFolder}/<VIEW_ID>_tilePattern.obj",
group="", # do not export on the command line
enabled=lambda node: node.intermediateResults.exportTilePattern.value,
),
Expand All @@ -599,7 +599,7 @@ class DepthMap(desc.AVCommandLineNode):
label="Depth Maps SGM",
description="Debug: Depth maps SGM",
semantic="image",
value=desc.Node.internalFolder + "<VIEW_ID>_depthMap_sgm.exr",
value="{nodeCacheFolder}/<VIEW_ID>_depthMap_sgm.exr",
group="", # do not export on the command line
enabled=lambda node: node.intermediateResults.exportIntermediateDepthSimMaps.value,
),
Expand All @@ -608,7 +608,7 @@ class DepthMap(desc.AVCommandLineNode):
label="Depth Maps SGM Upscaled",
description="Debug: Depth maps SGM upscaled.",
semantic="image",
value=desc.Node.internalFolder + "<VIEW_ID>_depthMap_sgmUpscaled.exr",
value="{nodeCacheFolder}/<VIEW_ID>_depthMap_sgmUpscaled.exr",
group="", # do not export on the command line
enabled=lambda node: node.intermediateResults.exportIntermediateDepthSimMaps.value,
),
Expand All @@ -617,7 +617,7 @@ class DepthMap(desc.AVCommandLineNode):
label="Depth Maps Refined",
description="Debug: Depth maps after refinement",
semantic="image",
value=desc.Node.internalFolder + "<VIEW_ID>_depthMap_refinedFused.exr",
value="{nodeCacheFolder}/<VIEW_ID>_depthMap_refinedFused.exr",
group="", # do not export on the command line
enabled=lambda node: node.intermediateResults.exportIntermediateDepthSimMaps.value,
),
Expand Down
8 changes: 4 additions & 4 deletions meshroom/nodes/aliceVision/DepthMapFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class DepthMapFilter(desc.AVCommandLineNode):
name="output",
label="Filtered Depth Maps Folder",
description="Output folder for generated depth maps.",
value=desc.Node.internalFolder,
value="{nodeCacheFolder}"
),
# these attributes are only here to describe more accurately the output of the node
# by specifying that it generates 2 sequences of images
Expand All @@ -123,23 +123,23 @@ class DepthMapFilter(desc.AVCommandLineNode):
label="Depth Maps",
description="Filtered depth maps.",
semantic="image",
value=desc.Node.internalFolder + "<VIEW_ID>_depthMap.exr",
value="{nodeCacheFolder}/<VIEW_ID>_depthMap.exr",
group="", # do not export on the command line
),
desc.File(
name="sim",
label="Sim Maps",
description="Filtered sim maps.",
semantic="image",
value=desc.Node.internalFolder + "<VIEW_ID>_simMap.exr",
value="{nodeCacheFolder}/<VIEW_ID>_simMap.exr",
group="", # do not export on the command line
),
desc.File(
name="normal",
label="Normal Maps",
description="Normal maps.",
semantic="image",
value=desc.Node.internalFolder + "<VIEW_ID>_normalMap.exr",
value="{nodeCacheFolder}/<VIEW_ID>_normalMap.exr",
enabled=lambda node: node.computeNormalMaps.value,
group="", # do not export on the command line
),
Expand Down
6 changes: 3 additions & 3 deletions meshroom/nodes/aliceVision/DepthMapRendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ class DepthMapRendering(desc.AVCommandLineNode):
name="output",
label="Folder",
description="Output folder.",
value=desc.Node.internalFolder,
value="{nodeCacheFolder}",
),
desc.File(
name="depth",
label="Depth Maps",
description="Rendered depth maps.",
semantic="image",
value=desc.Node.internalFolder + "<VIEW_ID>_depthMap.exr",
value="{nodeCacheFolder}/<VIEW_ID>_depthMap.exr",
group="", # do not export on the command line
),
desc.File(
name="mask",
label="Masks",
description="Masks.",
semantic="image",
value=desc.Node.internalFolder + "<VIEW_ID>_mask.exr",
value="{nodeCacheFolder}/<VIEW_ID>_mask.exr",
group="", # do not export on the command line
),
]
2 changes: 1 addition & 1 deletion meshroom/nodes/aliceVision/DistortionCalibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ class DistortionCalibration(desc.AVCommandLineNode):
name="output",
label="SfMData File",
description="Path to the output SfMData file.",
value=desc.Node.internalFolder + "sfmData.sfm",
value="{nodeCacheFolder}/sfmData.sfm",
),
]
Loading
Loading