Skip to content

Commit

Permalink
[ui] Add removeImage function in Python to check for intrinsic still …
Browse files Browse the repository at this point in the history
…used
  • Loading branch information
Just-Kiel committed May 13, 2024
1 parent 561e9b8 commit c50d3cc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
24 changes: 24 additions & 0 deletions meshroom/ui/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,30 @@ def appendAttribute(self, attribute, value=QJsonValue()):
def removeAttribute(self, attribute):
self.push(commands.ListAttributeRemoveCommand(self._graph, attribute))

@Slot(Attribute)
def removeImage(self, image):
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 x in range(len(self.cameraInit.attribute("intrinsics"))):
intrinsic = self.cameraInit.attribute("intrinsics").at(x)
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
32 changes: 8 additions & 24 deletions meshroom/ui/qml/ImageGallery/ImageGallery.qml
Original file line number Diff line number Diff line change
Expand Up @@ -291,30 +291,14 @@ Panel {
}

function sendRemoveRequest() {
if (!readOnly) {
// look if the viewpoint's intrinsic is used by another viewpoint
var intrinsicId = object.value.get('intrinsicId').value
var intrinsicUsed = false
for (var i = 0; i < m.viewpoints.count; ++i) {
if (m.viewpoints.at(i) != object && m.viewpoints.at(i).value.get("intrinsicId").value === intrinsicId) {
intrinsicUsed = true
break
}
}
if (!intrinsicUsed) {
//find the intrinsic and remove it
for (var i = 0; i < m.intrinsics.count; ++i) {
if (m.intrinsics.at(i).value.get("intrinsicId").value === intrinsicId) {
_reconstruction.removeAttribute(m.intrinsics.at(i))
break
}
}
}
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
2 changes: 1 addition & 1 deletion meshroom/ui/qml/WorkspaceView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Item {
cameraInit: reconstruction ? reconstruction.cameraInit : null
tempCameraInit: reconstruction ? reconstruction.tempCameraInit : null
cameraInitIndex: reconstruction ? reconstruction.cameraInitIndex : -1
onRemoveImageRequest: reconstruction.removeAttribute(attribute)
onRemoveImageRequest: reconstruction.removeImage(attribute)
onAllViewpointsCleared: { reconstruction.removeAllImages(); reconstruction.selectedViewId = "-1" }
onFilesDropped: {
if (drop["meshroomScenes"].length == 1) {
Expand Down

0 comments on commit c50d3cc

Please sign in to comment.