Skip to content

Commit 87a8376

Browse files
committed
[BoundingBox] refactor automatic bounding box
- remove hardcoded nodes information from the code engine - add "runtime attributes" for more flexibility
1 parent 2ae0f16 commit 87a8376

File tree

7 files changed

+49
-70
lines changed

7 files changed

+49
-70
lines changed

meshroom/core/desc.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,10 @@ class Node(object):
556556
parallelization = None
557557
documentation = ''
558558
category = 'Other'
559+
coreNode = None
559560

560-
def __init__(self):
561-
pass
561+
def __init__(self, coreNode = None):
562+
self.coreNode = coreNode
562563

563564
def upgradeAttributeValues(self, attrValues, fromVersion):
564565
return attrValues
@@ -599,6 +600,9 @@ class CommandLineNode(Node):
599600
parallelization = None
600601
commandLineRange = ''
601602

603+
def __init__(self, coreNode = None):
604+
super().__init__(coreNode)
605+
602606
def buildCommandLine(self, chunk):
603607

604608
cmdPrefix = ''
@@ -665,7 +669,8 @@ class AVCommandLineNode(CommandLineNode):
665669
cmdMem = ''
666670
cmdCore = ''
667671

668-
def __init__(self):
672+
def __init__(self, coreNode = None):
673+
super().__init__(coreNode)
669674

670675
if AVCommandLineNode.cgroupParsed is False:
671676

meshroom/core/node.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from meshroom.core import desc, stats, hashValue, nodeVersion, Version
2121
from meshroom.core.attribute import attributeFactory, ListAttribute, GroupAttribute, Attribute
2222
from meshroom.core.exception import NodeUpgradeError, UnknownNodeTypeError
23-
from meshroom.core.nodes import getNodeClass
2423

2524
def getWritingFilepath(filepath):
2625
return filepath + '.writing.' + str(uuid.uuid4())
@@ -483,10 +482,6 @@ def __init__(self, nodeType, position=None, parent=None, **kwargs):
483482
self._nodeType = nodeType
484483
self.nodeDesc = None
485484

486-
# instantiate node description if nodeType is valid
487-
if nodeType in meshroom.core.nodesDesc:
488-
self.nodeDesc = meshroom.core.nodesDesc[nodeType]()
489-
490485
self.packageName = self.packageVersion = ""
491486
self._internalFolder = ""
492487

@@ -500,12 +495,17 @@ def __init__(self, nodeType, position=None, parent=None, **kwargs):
500495
self._position = position or Position()
501496
self._attributes = DictModel(keyAttrName='name', parent=self)
502497
self._internalAttributes = DictModel(keyAttrName='name', parent=self)
498+
self._runtimeAttributes = DictModel(keyAttrName='name', parent=self)
503499
self.attributesPerUid = defaultdict(set)
504500
self._alive = True # for QML side to know if the node can be used or is going to be deleted
505501
self._locked = False
506502
self._duplicates = ListModel(parent=self) # list of nodes with the same uid
507503
self._hasDuplicates = False
508504

505+
# instantiate node description if nodeType is valid
506+
if nodeType in meshroom.core.nodesDesc:
507+
self.nodeDesc = meshroom.core.nodesDesc[nodeType](coreNode=self)
508+
509509
self.globalStatusChanged.connect(self.updateDuplicatesStatusAndLocked)
510510

511511
def __getattr__(self, k):
@@ -609,6 +609,10 @@ def internalAttribute(self, name):
609609
# The internal attribute itself can be returned directly
610610
return self._internalAttributes.get(name)
611611

612+
@Slot(str, result=Attribute)
613+
def runtimeAttribute(self, name):
614+
return self._runtimeAttributes.get(name)
615+
612616
def setInternalAttributeValues(self, values):
613617
# initialize internal attribute values
614618
for k, v in values.items():
@@ -1554,8 +1558,7 @@ def upgrade(self):
15541558
# store internal attributes that could be used during node upgrade
15551559
commonInternalAttributes.append(attrName)
15561560

1557-
cls = getNodeClass(self.nodeType)
1558-
node = cls(self.nodeType, position=self.position)
1561+
node = Node(self.nodeType, position=self.position)
15591562
# convert attributes from a list of tuples into a dict
15601563
attrValues = {key: value for (key, value) in self.inputs.items()}
15611564
intAttrValues = {key: value for (key, value) in self.internalInputs.items()}
@@ -1676,8 +1679,7 @@ def nodeFactory(nodeDict, name=None, template=False, uidConflict=False):
16761679
break
16771680

16781681
if compatibilityIssue is None:
1679-
cls = getNodeClass(nodeType)
1680-
node = cls(nodeType, position, **inputs)
1682+
node = Node(nodeType, position, **inputs)
16811683
node.setInternalAttributeValues(internalInputs)
16821684
else:
16831685
logging.warning("Compatibility issue detected for node '{}': {}".format(name, compatibilityIssue.name))

meshroom/core/nodes/MeshingNode.py

-30
This file was deleted.

meshroom/core/nodes/__init__.py

-23
This file was deleted.

meshroom/nodes/aliceVision/CameraInit.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ class CameraInit(desc.AVCommandLineNode, desc.InitNode):
328328
),
329329
]
330330

331-
def __init__(self):
332-
super(CameraInit, self).__init__()
331+
def __init__(self, coreNode = None):
332+
super(CameraInit, self).__init__(coreNode)
333333

334334
def initialize(self, node, inputs, recursiveInputs):
335335
# Reset graph inputs

meshroom/nodes/aliceVision/Meshing.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
__version__ = "7.0"
22

33
from meshroom.core import desc
4+
from meshroom.common import Slot
5+
from meshroom.core.attribute import attributeFactory
46
import os
57
import threading
68
import psutil
@@ -533,10 +535,33 @@ class Meshing(desc.AVCommandLineNode):
533535
),
534536
]
535537

538+
def __init__(self, coreNode=None):
539+
super().__init__(coreNode)
540+
541+
attrDesc = desc.BoolParam(
542+
name="automaticBBoxValid",
543+
label="",
544+
description="",
545+
value=False,
546+
uid=[],
547+
group=""
548+
)
549+
self.coreNode._runtimeAttributes.add(attributeFactory(attrDesc, None, False, self.coreNode))
550+
coreNode.globalStatusChanged.connect(self.checkBBox)
551+
536552
def processChunk(self, chunk):
537553
with boundingBoxMonitor(chunk.node):
538554
super(Meshing, self).processChunk(chunk)
539555

556+
@Slot()
557+
def checkBBox(self):
558+
"""Load automatic bounding box if needed."""
559+
if self.coreNode.useBoundingBox.value:
560+
return
561+
self.coreNode.runtimeAttribute('automaticBBoxValid').value = False
562+
with boundingBoxMonitor(self.coreNode, checkOnce=True) as thread:
563+
pass
564+
540565
@contextmanager
541566
def boundingBoxMonitor(node, checkOnce=False):
542567
"""
@@ -613,7 +638,7 @@ def updateBoundingBox(self) -> bool:
613638
for x in vec.value:
614639
x.value = data[i]
615640
i += 1
616-
self.node.automaticBBoxValid = True
641+
self.node.runtimeAttribute('automaticBBoxValid').value = True
617642
return True
618643

619644
def stopRequest(self):

meshroom/ui/qml/Viewer3D/MediaLibrary.qml

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ Entity {
167167
property bool hasBoundingBox: {
168168
if(nodeType === "Meshing" && currentNode.attribute("useBoundingBox")) // Can have a BoundingBox
169169
{
170-
if(currentNode.automaticBBoxValid !== undefined)
171-
return currentNode.attribute("useBoundingBox").value || currentNode.automaticBBoxValid
170+
if(currentNode.runtimeAttribute("automaticBBoxValid") !== undefined)
171+
return currentNode.attribute("useBoundingBox").value || currentNode.runtimeAttribute("automaticBBoxValid").value
172172
return currentNode.attribute("useBoundingBox").value
173173
}
174174
return false

0 commit comments

Comments
 (0)