Skip to content

Commit

Permalink
[BoundingBox] fix automatic bounding box
Browse files Browse the repository at this point in the history
- fix circular dependacy issue in import
- fix dirty hack for reading python variable "automaticBBoxValid" in qml
  • Loading branch information
almarouk committed Aug 28, 2023
1 parent e748cc1 commit 2ae0f16
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 34 deletions.
25 changes: 5 additions & 20 deletions meshroom/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
from meshroom.core import desc, stats, hashValue, nodeVersion, Version
from meshroom.core.attribute import attributeFactory, ListAttribute, GroupAttribute, Attribute
from meshroom.core.exception import NodeUpgradeError, UnknownNodeTypeError
from meshroom.nodes.aliceVision.Meshing import boundingBoxMonitor

from meshroom.core.nodes import getNodeClass

def getWritingFilepath(filepath):
return filepath + '.writing.' + str(uuid.uuid4())
Expand Down Expand Up @@ -1315,20 +1314,6 @@ def _updateChunks(self):
else:
self._chunks[0].range = desc.Range()

class MeshingNode(Node):
def __init__(self, nodeType, position=None, parent=None, **kwargs):
super().__init__(nodeType, position, parent, **kwargs)
self.internalFolderChanged.connect(self.checkBBox)
self.globalStatusChanged.connect(self.checkBBox)

def checkBBox(self):
"""Load automatic bounding box if needed."""
if self.useBoundingBox.value:
return
self.automaticBBoxValid.value = False
with boundingBoxMonitor(self, checkOnce=True) as thread:
pass

class CompatibilityIssue(Enum):
"""
Enum describing compatibility issues when deserializing a Node.
Expand Down Expand Up @@ -1569,8 +1554,8 @@ def upgrade(self):
# store internal attributes that could be used during node upgrade
commonInternalAttributes.append(attrName)

cl = MeshingNode if self.nodeType=="Meshing" else Node
node = cl(self.nodeType, position=self.position)
cls = getNodeClass(self.nodeType)
node = cls(self.nodeType, position=self.position)
# convert attributes from a list of tuples into a dict
attrValues = {key: value for (key, value) in self.inputs.items()}
intAttrValues = {key: value for (key, value) in self.internalInputs.items()}
Expand Down Expand Up @@ -1691,8 +1676,8 @@ def nodeFactory(nodeDict, name=None, template=False, uidConflict=False):
break

if compatibilityIssue is None:
cl = MeshingNode if nodeType=="Meshing" else Node
node = cl(nodeType, position, **inputs)
cls = getNodeClass(nodeType)
node = cls(nodeType, position, **inputs)
node.setInternalAttributeValues(internalInputs)
else:
logging.warning("Compatibility issue detected for node '{}': {}".format(name, compatibilityIssue.name))
Expand Down
30 changes: 30 additions & 0 deletions meshroom/core/nodes/MeshingNode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from meshroom.nodes.aliceVision.Meshing import boundingBoxMonitor
from meshroom.core.node import Node
from meshroom.common import Property, Signal

class MeshingNode(Node):
def __init__(self, nodeType, position=None, parent=None, **kwargs):
super().__init__(nodeType, position, parent, **kwargs)
self.internalFolderChanged.connect(self.checkBBox)
self.globalStatusChanged.connect(self.checkBBox)
self._automaticBBoxValid = False

@property
def automaticBBoxValid(self):
return self._automaticBBoxValid

@automaticBBoxValid.setter
def automaticBBoxValid(self, value):
self._automaticBBoxValid = value
self.automaticBBoxValidChanged.emit()

automaticBBoxValidChanged = Signal()
automaticBBoxValid = Property(bool, automaticBBoxValid.fget, automaticBBoxValid.fset, notify=automaticBBoxValidChanged)

def checkBBox(self):
"""Load automatic bounding box if needed."""
if self.useBoundingBox.value:
return
self.automaticBBoxValid = False
with boundingBoxMonitor(self, checkOnce=True) as thread:
pass
23 changes: 23 additions & 0 deletions meshroom/core/nodes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import TYPE_CHECKING

def getNodeClass(nodeType: str):
"""
Returns the appropriate subclass of `meshroom.core.node.Node` based on `nodeType`.
Inputs
------
nodeType: str
the name of the node type
Returns
-------
type[Node]
the corresponding type class
"""
if nodeType=="Meshing":
from meshroom.core.nodes.MeshingNode import MeshingNode
cls = MeshingNode
else:
from meshroom.core.node import Node
cls = Node
return cls
13 changes: 1 addition & 12 deletions meshroom/nodes/aliceVision/Meshing.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,17 +531,6 @@ class Meshing(desc.AVCommandLineNode):
value="{cache}/{nodeType}/{uid0}/densePointCloud.abc",
uid=[],
),
desc.BoolParam(
name="automaticBBoxValid",
label="",
description="Indicates if the Bounding Box has been "
"automatically computed and loaded.\n"
"Note that this param is always not enabled (not exposed in the UI) and "
"only used to indicate if the automatic bounding box should be displayed.",
value=False,
enabled=False,
uid=[],
),
]

def processChunk(self, chunk):
Expand Down Expand Up @@ -624,7 +613,7 @@ def updateBoundingBox(self) -> bool:
for x in vec.value:
x.value = data[i]
i += 1
self.node.automaticBBoxValid.value = True
self.node.automaticBBoxValid = True
return True

def stopRequest(self):
Expand Down
4 changes: 2 additions & 2 deletions meshroom/ui/qml/Viewer3D/MediaLibrary.qml
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ Entity {
property bool hasBoundingBox: {
if(nodeType === "Meshing" && currentNode.attribute("useBoundingBox")) // Can have a BoundingBox
{
if(currentNode.attribute("automaticBBoxValid"))
return currentNode.attribute("useBoundingBox").value || currentNode.attribute("automaticBBoxValid").value
if(currentNode.automaticBBoxValid !== undefined)
return currentNode.attribute("useBoundingBox").value || currentNode.automaticBBoxValid
return currentNode.attribute("useBoundingBox").value
}
return false
Expand Down

0 comments on commit 2ae0f16

Please sign in to comment.