Skip to content

Commit e7b308d

Browse files
[ui] Attribute: Refacto of the validation process, using the new validators paradigm
1 parent 07e4add commit e7b308d

File tree

5 files changed

+51
-43
lines changed

5 files changed

+51
-43
lines changed

meshroom/aliceVision/KeyframeSelection.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
__version__ = "5.0"
22

33
from meshroom.core import desc
4+
from meshroom.core.desc.validators import success, error
45
from meshroom.core.utils import EXR_STORAGE_DATA_TYPE, VERBOSE_LEVEL
56

67
# List of supported video extensions (provided by OpenImageIO)
@@ -283,8 +284,9 @@ class KeyframeSelection(desc.AVCommandLineNode):
283284
"For input videos, 'none' should not be used since the written keyframes are used to generate the output SfMData file.",
284285
value="none",
285286
values=["none", "exr", "jpg", "png"],
286-
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"),
287-
errorMessage="A video input has been provided. The output extension should be different from 'none'.",
287+
validators=[
288+
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'.")
289+
],
288290
),
289291
desc.ChoiceParam(
290292
name="storageDataType",

meshroom/aliceVision/LdrToHdrCalibration.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from meshroom.core import desc
66
from meshroom.core.utils import COLORSPACES, VERBOSE_LEVEL
7+
from . common import NbOfBracketsShouldBeAMultipleOfNbOfImages
78

89
def findMetadata(d, keys, defaultValue):
910
v = None
@@ -55,9 +56,8 @@ class LdrToHdrCalibration(desc.AVCommandLineNode):
5556
value=0,
5657
range=(0, 15, 1),
5758
invalidate=False,
58-
group="user", # not used directly on the command line
59-
errorMessage="The set number of brackets is not a multiple of the number of input images.\n"
60-
"Errors will occur during the computation.",
59+
group="user", # not used directly on the command line,
60+
validators=[NbOfBracketsShouldBeAMultipleOfNbOfImages()],
6161
exposed=True,
6262
),
6363
desc.IntParam(
@@ -176,23 +176,15 @@ def update(cls, node):
176176
if "userNbBrackets" not in node.getAttributes().keys():
177177
# Old version of the node
178178
return
179-
node.userNbBrackets.validValue = True # Reset the status of "userNbBrackets"
180179

181180
cameraInitOutput = node.input.getLinkParam(recursive=True)
182181
if not cameraInitOutput:
183182
node.nbBrackets.value = 0
184183
return
185184
if node.userNbBrackets.value != 0:
186-
# The number of brackets has been manually forced: check whether it is valid or not
187-
if cameraInitOutput and cameraInitOutput.node and cameraInitOutput.node.hasAttribute("viewpoints"):
188-
viewpoints = cameraInitOutput.node.viewpoints.value
189-
# The number of brackets should be a multiple of the number of input images
190-
if (len(viewpoints) % node.userNbBrackets.value != 0):
191-
node.userNbBrackets.validValue = False
192-
else:
193-
node.userNbBrackets.validValue = True
194-
node.nbBrackets.value = node.userNbBrackets.value
195-
return
185+
if len(node.userNbBrackets.getErrorMessages()) > 0:
186+
node.nbBrackets.value = node.userNbBrackets.value
187+
return
196188

197189
if not cameraInitOutput.node.hasAttribute("viewpoints"):
198190
if cameraInitOutput.node.hasAttribute("input"):

meshroom/aliceVision/LdrToHdrMerge.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from meshroom.core import desc
66
from meshroom.core.utils import COLORSPACES, EXR_STORAGE_DATA_TYPE, VERBOSE_LEVEL
7+
from . common import NbOfBracketsShouldBeAMultipleOfNbOfImages
78

89
def findMetadata(d, keys, defaultValue):
910
v = None
@@ -55,8 +56,7 @@ class LdrToHdrMerge(desc.AVCommandLineNode):
5556
range=(0, 15, 1),
5657
invalidate=False,
5758
group="user", # not used directly on the command line
58-
errorMessage="The set number of brackets is not a multiple of the number of input images.\n"
59-
"Errors will occur during the computation.",
59+
validators=[NbOfBracketsShouldBeAMultipleOfNbOfImages()],
6060
exposed=True,
6161
),
6262
desc.IntParam(
@@ -249,23 +249,15 @@ def update(cls, node):
249249
if "userNbBrackets" not in node.getAttributes().keys():
250250
# Old version of the node
251251
return
252-
node.userNbBrackets.validValue = True # Reset the status of "userNbBrackets"
253252

254253
cameraInitOutput = node.input.getLinkParam(recursive=True)
255254
if not cameraInitOutput:
256255
node.nbBrackets.value = 0
257256
return
258257
if node.userNbBrackets.value != 0:
259-
# The number of brackets has been manually forced: check whether it is valid or not
260-
if cameraInitOutput and cameraInitOutput.node and cameraInitOutput.node.hasAttribute("viewpoints"):
261-
viewpoints = cameraInitOutput.node.viewpoints.value
262-
# The number of brackets should be a multiple of the number of input images
263-
if (len(viewpoints) % node.userNbBrackets.value != 0):
264-
node.userNbBrackets.validValue = False
265-
else:
266-
node.userNbBrackets.validValue = True
267-
node.nbBrackets.value = node.userNbBrackets.value
268-
return
258+
if len(node.userNbBrackets.getErrorMessages()) > 0:
259+
node.nbBrackets.value = node.userNbBrackets.value
260+
return
269261

270262
if not cameraInitOutput.node.hasAttribute("viewpoints"):
271263
if cameraInitOutput.node.hasAttribute("input"):

meshroom/aliceVision/LdrToHdrSampling.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from meshroom.core import desc
66
from meshroom.core.utils import COLORSPACES, VERBOSE_LEVEL
7+
from . common import NbOfBracketsShouldBeAMultipleOfNbOfImages
78

89

910
def findMetadata(d, keys, defaultValue):
@@ -59,7 +60,7 @@ class LdrToHdrSampling(desc.AVCommandLineNode):
5960
inputs = [
6061
desc.File(
6162
name="input",
62-
label="SfMData",
63+
label="SfMData hello",
6364
description="Input SfMData file.",
6465
value="",
6566
),
@@ -71,8 +72,9 @@ class LdrToHdrSampling(desc.AVCommandLineNode):
7172
range=(0, 15, 1),
7273
invalidate=False,
7374
group="user", # not used directly on the command line
74-
errorMessage="The set number of brackets is not a multiple of the number of input images.\n"
75-
"Errors will occur during the computation.",
75+
validators=[
76+
NbOfBracketsShouldBeAMultipleOfNbOfImages()
77+
],
7678
exposed=True,
7779
),
7880
desc.IntParam(
@@ -202,23 +204,16 @@ def update(cls, node):
202204
# Old version of the node
203205
return
204206
node.outliersNb = 0 # Reset the number of detected outliers
205-
node.userNbBrackets.validValue = True # Reset the status of "userNbBrackets"
206207

207208
cameraInitOutput = node.input.getLinkParam(recursive=True)
208209
if not cameraInitOutput:
209210
node.nbBrackets.value = 0
210211
return
211212
if node.userNbBrackets.value != 0:
212-
# The number of brackets has been manually forced: check whether it is valid or not
213-
if cameraInitOutput and cameraInitOutput.node and cameraInitOutput.node.hasAttribute("viewpoints"):
214-
viewpoints = cameraInitOutput.node.viewpoints.value
215-
# The number of brackets should be a multiple of the number of input images
216-
if (len(viewpoints) % node.userNbBrackets.value != 0):
217-
node.userNbBrackets.validValue = False
218-
else:
219-
node.userNbBrackets.validValue = True
220-
node.nbBrackets.value = node.userNbBrackets.value
221-
return
213+
214+
if len(node.userNbBrackets.getErrorMessages()) > 0:
215+
node.nbBrackets.value = node.userNbBrackets.value
216+
return
222217

223218
if not cameraInitOutput.node.hasAttribute("viewpoints"):
224219
if cameraInitOutput.node.hasAttribute("input"):

meshroom/aliceVision/common.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from meshroom.core.attribute import Attribute
2+
from meshroom.core.node import Node
3+
from meshroom.core.desc.validators import AttributeValidator, success, error
4+
5+
6+
class NbOfBracketsShouldBeAMultipleOfNbOfImages(AttributeValidator):
7+
8+
def __call__(self, node: Node, attribute: Attribute):
9+
10+
if node.userNbBrackets.value == 0:
11+
return success()
12+
13+
cameraInitOutput = node.input.getLinkParam(recursive=True)
14+
15+
# The number of brackets has been manually forced: check whether it is valid or not
16+
if cameraInitOutput and cameraInitOutput.node and cameraInitOutput.node.hasAttribute("viewpoints"):
17+
viewpoints = cameraInitOutput.node.viewpoints.value
18+
# The number of brackets should be a multiple of the number of input images
19+
if (len(viewpoints) % node.userNbBrackets.value != 0):
20+
return error(
21+
"The set number of brackets is not a multiple of the number of input images.",
22+
"Errors will occur during the computation."
23+
)
24+
else:
25+
return success()
26+
27+
return success()

0 commit comments

Comments
 (0)