diff --git a/meshroom/aliceVision/KeyframeSelection.py b/meshroom/aliceVision/KeyframeSelection.py index 6fb405774d..a28563d291 100644 --- a/meshroom/aliceVision/KeyframeSelection.py +++ b/meshroom/aliceVision/KeyframeSelection.py @@ -1,6 +1,7 @@ __version__ = "5.0" from meshroom.core import desc +from meshroom.core.desc.validators import success, error from meshroom.core.utils import EXR_STORAGE_DATA_TYPE, VERBOSE_LEVEL # List of supported video extensions (provided by OpenImageIO) @@ -283,8 +284,9 @@ class KeyframeSelection(desc.AVCommandLineNode): "For input videos, 'none' should not be used since the written keyframes are used to generate the output SfMData file.", value="none", values=["none", "exr", "jpg", "png"], - validValue=lambda node: not (any(ext in input.value.lower() for ext in videoExts for input in node.inputPaths.value) and node.outputExtension.value == "none"), - errorMessage="A video input has been provided. The output extension should be different from 'none'.", + validators=[ + lambda node, _ : success() if not (any(ext in input.value.lower() for ext in videoExts for input in node.inputPaths.value) and node.outputExtension.value == "none") else error("A video input has been provided. The output extension should be different from 'none'.") + ], ), desc.ChoiceParam( name="storageDataType", diff --git a/meshroom/aliceVision/LdrToHdrCalibration.py b/meshroom/aliceVision/LdrToHdrCalibration.py index e125ee00b4..8d19753d93 100644 --- a/meshroom/aliceVision/LdrToHdrCalibration.py +++ b/meshroom/aliceVision/LdrToHdrCalibration.py @@ -4,6 +4,7 @@ from meshroom.core import desc from meshroom.core.utils import COLORSPACES, VERBOSE_LEVEL +from . ldrToHdrCommon import NbOfBracketsShouldBeAMultipleOfNbOfImages def findMetadata(d, keys, defaultValue): v = None @@ -55,9 +56,8 @@ class LdrToHdrCalibration(desc.AVCommandLineNode): value=0, range=(0, 15, 1), invalidate=False, - group="user", # not used directly on the command line - errorMessage="The set number of brackets is not a multiple of the number of input images.\n" - "Errors will occur during the computation.", + group="user", # not used directly on the command line, + validators=[NbOfBracketsShouldBeAMultipleOfNbOfImages()], exposed=True, ), desc.IntParam( @@ -176,23 +176,15 @@ def update(cls, node): if "userNbBrackets" not in node.getAttributes().keys(): # Old version of the node return - node.userNbBrackets.validValue = True # Reset the status of "userNbBrackets" cameraInitOutput = node.input.getLinkParam(recursive=True) if not cameraInitOutput: node.nbBrackets.value = 0 return if node.userNbBrackets.value != 0: - # The number of brackets has been manually forced: check whether it is valid or not - if cameraInitOutput and cameraInitOutput.node and cameraInitOutput.node.hasAttribute("viewpoints"): - viewpoints = cameraInitOutput.node.viewpoints.value - # The number of brackets should be a multiple of the number of input images - if (len(viewpoints) % node.userNbBrackets.value != 0): - node.userNbBrackets.validValue = False - else: - node.userNbBrackets.validValue = True - node.nbBrackets.value = node.userNbBrackets.value - return + if len(node.userNbBrackets.getErrorMessages()) > 0: + node.nbBrackets.value = node.userNbBrackets.value + return if not cameraInitOutput.node.hasAttribute("viewpoints"): if cameraInitOutput.node.hasAttribute("input"): diff --git a/meshroom/aliceVision/LdrToHdrMerge.py b/meshroom/aliceVision/LdrToHdrMerge.py index ba71e0e21b..8404c4f02d 100644 --- a/meshroom/aliceVision/LdrToHdrMerge.py +++ b/meshroom/aliceVision/LdrToHdrMerge.py @@ -4,6 +4,7 @@ from meshroom.core import desc from meshroom.core.utils import COLORSPACES, EXR_STORAGE_DATA_TYPE, VERBOSE_LEVEL +from . ldrToHdrCommon import NbOfBracketsShouldBeAMultipleOfNbOfImages def findMetadata(d, keys, defaultValue): v = None @@ -55,8 +56,7 @@ class LdrToHdrMerge(desc.AVCommandLineNode): range=(0, 15, 1), invalidate=False, group="user", # not used directly on the command line - errorMessage="The set number of brackets is not a multiple of the number of input images.\n" - "Errors will occur during the computation.", + validators=[NbOfBracketsShouldBeAMultipleOfNbOfImages()], exposed=True, ), desc.IntParam( @@ -249,23 +249,15 @@ def update(cls, node): if "userNbBrackets" not in node.getAttributes().keys(): # Old version of the node return - node.userNbBrackets.validValue = True # Reset the status of "userNbBrackets" cameraInitOutput = node.input.getLinkParam(recursive=True) if not cameraInitOutput: node.nbBrackets.value = 0 return if node.userNbBrackets.value != 0: - # The number of brackets has been manually forced: check whether it is valid or not - if cameraInitOutput and cameraInitOutput.node and cameraInitOutput.node.hasAttribute("viewpoints"): - viewpoints = cameraInitOutput.node.viewpoints.value - # The number of brackets should be a multiple of the number of input images - if (len(viewpoints) % node.userNbBrackets.value != 0): - node.userNbBrackets.validValue = False - else: - node.userNbBrackets.validValue = True - node.nbBrackets.value = node.userNbBrackets.value - return + if len(node.userNbBrackets.getErrorMessages()) > 0: + node.nbBrackets.value = node.userNbBrackets.value + return if not cameraInitOutput.node.hasAttribute("viewpoints"): if cameraInitOutput.node.hasAttribute("input"): diff --git a/meshroom/aliceVision/LdrToHdrSampling.py b/meshroom/aliceVision/LdrToHdrSampling.py index fa88ccd3c8..6c8b3f35d0 100644 --- a/meshroom/aliceVision/LdrToHdrSampling.py +++ b/meshroom/aliceVision/LdrToHdrSampling.py @@ -4,6 +4,7 @@ from meshroom.core import desc from meshroom.core.utils import COLORSPACES, VERBOSE_LEVEL +from . ldrToHdrCommon import NbOfBracketsShouldBeAMultipleOfNbOfImages def findMetadata(d, keys, defaultValue): @@ -71,8 +72,9 @@ class LdrToHdrSampling(desc.AVCommandLineNode): range=(0, 15, 1), invalidate=False, group="user", # not used directly on the command line - errorMessage="The set number of brackets is not a multiple of the number of input images.\n" - "Errors will occur during the computation.", + validators=[ + NbOfBracketsShouldBeAMultipleOfNbOfImages() + ], exposed=True, ), desc.IntParam( @@ -202,23 +204,16 @@ def update(cls, node): # Old version of the node return node.outliersNb = 0 # Reset the number of detected outliers - node.userNbBrackets.validValue = True # Reset the status of "userNbBrackets" cameraInitOutput = node.input.getLinkParam(recursive=True) if not cameraInitOutput: node.nbBrackets.value = 0 return if node.userNbBrackets.value != 0: - # The number of brackets has been manually forced: check whether it is valid or not - if cameraInitOutput and cameraInitOutput.node and cameraInitOutput.node.hasAttribute("viewpoints"): - viewpoints = cameraInitOutput.node.viewpoints.value - # The number of brackets should be a multiple of the number of input images - if (len(viewpoints) % node.userNbBrackets.value != 0): - node.userNbBrackets.validValue = False - else: - node.userNbBrackets.validValue = True - node.nbBrackets.value = node.userNbBrackets.value - return + + if len(node.userNbBrackets.getErrorMessages()) > 0: + node.nbBrackets.value = node.userNbBrackets.value + return if not cameraInitOutput.node.hasAttribute("viewpoints"): if cameraInitOutput.node.hasAttribute("input"): diff --git a/meshroom/aliceVision/ldrToHdrCommon.py b/meshroom/aliceVision/ldrToHdrCommon.py new file mode 100644 index 0000000000..7ce85036fb --- /dev/null +++ b/meshroom/aliceVision/ldrToHdrCommon.py @@ -0,0 +1,27 @@ +from meshroom.core.attribute import Attribute +from meshroom.core.node import Node +from meshroom.core.desc.validators import AttributeValidator, success, error + + +class NbOfBracketsShouldBeAMultipleOfNbOfImages(AttributeValidator): + + def __call__(self, node: Node, attribute: Attribute): + + if node.userNbBrackets.value == 0: + return success() + + cameraInitOutput = node.input.getLinkParam(recursive=True) + + # The number of brackets has been manually forced: check whether it is valid or not + if cameraInitOutput and cameraInitOutput.node and cameraInitOutput.node.hasAttribute("viewpoints"): + viewpoints = cameraInitOutput.node.viewpoints.value + # The number of brackets should be a multiple of the number of input images + if (len(viewpoints) % node.userNbBrackets.value != 0): + return error( + "The set number of brackets is not a multiple of the number of input images.", + "Errors will occur during the computation." + ) + else: + return success() + + return success()