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

[BoundingBox] Add visualization for automatically computed bounding box #2087

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions meshroom/core/desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,10 @@ class Node(object):
parallelization = None
documentation = ''
category = 'Other'
coreNode = None

def __init__(self):
pass
def __init__(self, coreNode = None):
self.coreNode = coreNode

def upgradeAttributeValues(self, attrValues, fromVersion):
return attrValues
Expand Down Expand Up @@ -599,6 +600,9 @@ class CommandLineNode(Node):
parallelization = None
commandLineRange = ''

def __init__(self, coreNode = None):
super().__init__(coreNode)

def buildCommandLine(self, chunk):

cmdPrefix = ''
Expand Down Expand Up @@ -665,7 +669,8 @@ class AVCommandLineNode(CommandLineNode):
cmdMem = ''
cmdCore = ''

def __init__(self):
def __init__(self, coreNode = None):
super().__init__(coreNode)

if AVCommandLineNode.cgroupParsed is False:

Expand Down
15 changes: 9 additions & 6 deletions meshroom/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from meshroom.core.attribute import attributeFactory, ListAttribute, GroupAttribute, Attribute
from meshroom.core.exception import NodeUpgradeError, UnknownNodeTypeError


def getWritingFilepath(filepath):
return filepath + '.writing.' + str(uuid.uuid4())

Expand Down Expand Up @@ -487,10 +486,6 @@ def __init__(self, nodeType, position=None, parent=None, **kwargs):
self._nodeType = nodeType
self.nodeDesc = None

# instantiate node description if nodeType is valid
if nodeType in meshroom.core.nodesDesc:
self.nodeDesc = meshroom.core.nodesDesc[nodeType]()

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

Expand All @@ -504,12 +499,17 @@ def __init__(self, nodeType, position=None, parent=None, **kwargs):
self._position = position or Position()
self._attributes = DictModel(keyAttrName='name', parent=self)
self._internalAttributes = DictModel(keyAttrName='name', parent=self)
self._runtimeAttributes = DictModel(keyAttrName='name', parent=self)
self.attributesPerUid = defaultdict(set)
self._alive = True # for QML side to know if the node can be used or is going to be deleted
self._locked = False
self._duplicates = ListModel(parent=self) # list of nodes with the same uid
self._hasDuplicates = False

# instantiate node description if nodeType is valid
if nodeType in meshroom.core.nodesDesc:
self.nodeDesc = meshroom.core.nodesDesc[nodeType](coreNode=self)

self.globalStatusChanged.connect(self.updateDuplicatesStatusAndLocked)

def __getattr__(self, k):
Expand Down Expand Up @@ -613,6 +613,10 @@ def internalAttribute(self, name):
# The internal attribute itself can be returned directly
return self._internalAttributes.get(name)

@Slot(str, result=Attribute)
def runtimeAttribute(self, name):
return self._runtimeAttributes.get(name)

def setInternalAttributeValues(self, values):
# initialize internal attribute values
for k, v in values.items():
Expand Down Expand Up @@ -1323,7 +1327,6 @@ def _updateChunks(self):
else:
self._chunks[0].range = desc.Range()


class CompatibilityIssue(Enum):
"""
Enum describing compatibility issues when deserializing a Node.
Expand Down
4 changes: 2 additions & 2 deletions meshroom/nodes/aliceVision/CameraInit.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ class CameraInit(desc.AVCommandLineNode, desc.InitNode):
),
]

def __init__(self):
super(CameraInit, self).__init__()
def __init__(self, coreNode = None):
super(CameraInit, self).__init__(coreNode)

def initialize(self, node, inputs, recursiveInputs):
# Reset graph inputs
Expand Down
117 changes: 117 additions & 0 deletions meshroom/nodes/aliceVision/Meshing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

from meshroom.core import desc
from meshroom.core.utils import VERBOSE_LEVEL
from meshroom.common import Slot
from meshroom.core.attribute import attributeFactory
import os
import threading
import psutil
import time
from contextlib import contextmanager


class Meshing(desc.AVCommandLineNode):
Expand Down Expand Up @@ -537,3 +544,113 @@ class Meshing(desc.AVCommandLineNode):
uid=[],
),
]

def __init__(self, coreNode=None):
super().__init__(coreNode)

attrDesc = desc.BoolParam(
name="automaticBBoxValid",
label="",
description="",
value=False,
uid=[],
group=""
)
self.coreNode._runtimeAttributes.add(attributeFactory(attrDesc, None, False, self.coreNode))
coreNode.globalStatusChanged.connect(self.checkBBox)

def processChunk(self, chunk):
with boundingBoxMonitor(chunk.node):
super(Meshing, self).processChunk(chunk)

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

@contextmanager
def boundingBoxMonitor(node, checkOnce=False):
"""
Context manager to load the automatic bounding box.

Inputs
------
node: MeshingNode
The considered meshing node

checkOnce: bool
If `True`, the bounding box file will be checked continuously
till created; if already exists, it will be ignored.
Otherwise, the file is checked only once and it will not be
ignored if already created.

Returns
-------
BoundingBoxThread
"""
bboxThread = None
try:
if not node.useBoundingBox.value:
bboxThread = BoundingBoxThread(node, checkOnce)
bboxThread.start()
yield bboxThread
finally:
if bboxThread is not None:
bboxThread.stopRequest()
bboxThread.join()

class BoundingBoxThread(threading.Thread):
"""Thread that loads the bounding box."""
def __init__(self, node, checkOnce):
threading.Thread.__init__(self)
self.node = node
self.checkOnce = checkOnce
self.parentProc = psutil.Process() # by default current process pid
self._stopFlag = threading.Event()
self.interval = 5 # wait duration before rechecking for bounding box file

def run(self):
self.startTime = time.time() if not self.checkOnce else -1
try:
while True:
updated = self.updateBoundingBox()
if updated or self.checkOnce:
return
if self._stopFlag.wait(self.interval):
# stopFlag has been set
# try to update boundingBox one last time and exit main loop
if self.parentProc.is_running():
self.updateBoundingBox()
return
except (KeyboardInterrupt, SystemError, GeneratorExit, psutil.NoSuchProcess):
pass

def updateBoundingBox(self) -> bool:
"""Tries to load the bounding box.

Returns
-------
bool: indicates if loading was successful
"""
file = os.path.join(os.path.dirname(self.node.outputMesh.value), "boundingBox.txt")
if not os.path.exists(file) or os.path.getmtime(file) < self.startTime:
return False
with open(file, 'r') as stream:
# file contains (in order, one value per line):
# translation: x, y, z ; rotation: x, y, z ; scale: x, y, z
data = list(map(float, stream.read().strip().splitlines()))
i = 0
for vec in self.node.boundingBox.value:
for x in vec.value:
x.value = data[i]
i += 1
self.node.runtimeAttribute('automaticBBoxValid').value = True
return True

def stopRequest(self):
""" Request the thread to exit as soon as possible. """
self._stopFlag.set()
1 change: 1 addition & 0 deletions meshroom/ui/qml/Viewer3D/EntityWithGizmo.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Entity {
property Layer frontLayerComponent
property var window
property alias uniformScale: transformGizmo.uniformScale // By default, if not set, the value is: false
property alias gizmoEnabled : transformGizmo.enabled
property TransformGizmo transformGizmo: TransformGizmo {
id: transformGizmo
camera: root.camera
Expand Down
2 changes: 1 addition & 1 deletion meshroom/ui/qml/Viewer3D/Inspector3D.qml
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ FloatingPane {
enabled: model.visible
Layout.alignment: Qt.AlignTop
Layout.fillHeight: true
text: MaterialIcons.transform
text: MaterialIcons.transform_
font.pointSize: 10
ToolTip.text: model.displayBoundingBox ? "Hide BBox" : "Show BBox"
flat: true
Expand Down
6 changes: 5 additions & 1 deletion meshroom/ui/qml/Viewer3D/MediaLibrary.qml
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@ Entity {

// Specific properties to the MESHING node (declared and initialized for every Entity anyway)
property bool hasBoundingBox: {
if (nodeType === "Meshing" && currentNode.attribute("useBoundingBox")) // Can have a BoundingBox
if(nodeType === "Meshing" && currentNode.attribute("useBoundingBox")) // Can have a BoundingBox
{
if(currentNode.runtimeAttribute("automaticBBoxValid") !== undefined)
return currentNode.attribute("useBoundingBox").value || currentNode.runtimeAttribute("automaticBBoxValid").value
return currentNode.attribute("useBoundingBox").value
}
return false
}
onHasBoundingBoxChanged: model.hasBoundingBox = hasBoundingBox
Expand Down
1 change: 1 addition & 0 deletions meshroom/ui/qml/Viewer3D/MeshingBoundingBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Entity {

EntityWithGizmo {
id: boundingBoxEntity
gizmoEnabled: root.currentMeshingNode ? root.currentMeshingNode.attribute("useBoundingBox").value : true
sceneCameraController: root.sceneCameraController
frontLayerComponent: root.frontLayerComponent
window: root.window
Expand Down
Loading