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

[ui] Remove intrinsic if not used by any viewpoint #2395

Merged
merged 5 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions meshroom/core/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ def __init__(self, node, attributeDesc, isOutput, root=None, parent=None):
def __len__(self):
return len(self._value)

def __iter__(self):
return iter(self._value)

def getBaseType(self):
return self.attributeDesc.elementDesc.__class__.__name__

Expand Down
23 changes: 23 additions & 0 deletions meshroom/ui/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,29 @@ def appendAttribute(self, attribute, value=QJsonValue()):
def removeAttribute(self, attribute):
self.push(commands.ListAttributeRemoveCommand(self._graph, attribute))

@Slot(Attribute)
def removeImage(self, image):
Just-Kiel marked this conversation as resolved.
Show resolved Hide resolved
with self.groupedGraphModification("Remove Image"):
# look if the viewpoint's intrinsic is used by another viewpoint
# if not, remove it
intrinsicId = image.intrinsicId.value

intrinsicUsed = False
for intrinsic in self.cameraInit.attribute("viewpoints").getExportValue():
if image.getExportValue() != intrinsic and intrinsic['intrinsicId'] == intrinsicId:
intrinsicUsed = True
break

if not intrinsicUsed:
#find the intrinsic and remove it
for intrinsic in self.cameraInit.attribute("intrinsics"):
if intrinsic.getExportValue()["intrinsicId"] == intrinsicId:
self.removeAttribute(intrinsic)
break

# After every check we finally remove the attribute
self.removeAttribute(image)

@Slot()
def removeAllImages(self):
with self.groupedGraphModification("Remove All Images"):
Expand Down
14 changes: 8 additions & 6 deletions meshroom/ui/qml/ImageGallery/ImageGallery.qml
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,14 @@ Panel {
}

function sendRemoveRequest() {
if (!readOnly) {
removeImageRequest(object)
// If the last image has been removed, make sure the viewpoints and intrinsics are reset
if (m.viewpoints.count === 0)
allViewpointsCleared()
}
if (readOnly)
return

removeImageRequest(object)

// If the last image has been removed, make sure the viewpoints and intrinsics are reset
if (m.viewpoints.count === 0)
allViewpointsCleared()
}

function removeAllImages() {
Expand Down
4 changes: 2 additions & 2 deletions meshroom/ui/qml/WorkspaceView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ Item {
cameraInit: reconstruction ? reconstruction.cameraInit : null
tempCameraInit: reconstruction ? reconstruction.tempCameraInit : null
cameraInitIndex: reconstruction ? reconstruction.cameraInitIndex : -1
onRemoveImageRequest: reconstruction.removeAttribute(attribute)
onAllViewpointsCleared: { reconstruction.removeAllImages(); reconstruction.selectedViewId = "-1" }
onRemoveImageRequest: reconstruction.removeImage(attribute)
onAllViewpointsCleared: { reconstruction.selectedViewId = "-1" }
onFilesDropped: {
if (drop["meshroomScenes"].length == 1) {
ensureSaved(function() {
Expand Down