Skip to content

Commit

Permalink
[ui] Better handling of thumbnails for Homepage
Browse files Browse the repository at this point in the history
We need to check and create the thumbnail if it does not exist.
  • Loading branch information
Just-Kiel committed Jul 8, 2024
1 parent 025b79c commit c733696
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
24 changes: 14 additions & 10 deletions meshroom/ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,21 @@ def _recentProjectFiles(self):
for i in range(size):
settings.setArrayIndex(i)
p = settings.value("filepath")
thumbnail = ""
if p:
# get the first image path from the project
file = open(p)
file = json.load(file)
# find the first camerainit node
file = file["graph"]
thumbnail = ""
for node in file:
if file[node]["nodeType"] == "CameraInit":
if len(file[node]["inputs"]["viewpoints"]) > 0:
thumbnail = ThumbnailCache.thumbnailPath(file[node]["inputs"]["viewpoints"][0]["path"])
break
try:
with open(p) as file:
file = json.load(file)
# find the first camerainit node
file = file["graph"]
for node in file:
if file[node]["nodeType"] == "CameraInit":
if len(file[node]["inputs"]["viewpoints"]) > 0:
thumbnail =ThumbnailCache.createThumbnail(ThumbnailCache, file[node]["inputs"]["viewpoints"][0]["path"], -1, True)
break
except FileNotFoundError:
pass
p = {"path": p, "thumbnail": thumbnail}
projects.append(p)
settings.endArray()
Expand Down Expand Up @@ -306,6 +309,7 @@ def removeRecentProjectFile(self, projectFile):
projectFileNorm = QUrl.fromLocalFile(projectFile).toLocalFile()

projects = self._recentProjectFiles()
projects = [p["path"] for p in projects]

# remove duplicates while preserving order
from collections import OrderedDict
Expand Down
21 changes: 14 additions & 7 deletions meshroom/ui/components/thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,25 @@ def thumbnail(self, imgSource, callerID):

return None

def createThumbnail(self, imgSource, callerID):
def createThumbnail(self, imgSource, callerID, inHomepage=False):
"""Load an image, resize it to thumbnail dimensions and save the result in the cache directory.
Args:
imgSource (QUrl): location of the input image
callerID (int): identifier for the object that requested the thumbnail
"""
imgPath = imgSource.toLocalFile()
path = ThumbnailCache.thumbnailPath(imgPath)
if not inHomepage:
imgPath = imgSource.toLocalFile()
path = ThumbnailCache.thumbnailPath(imgPath)
else:
imgPath = imgSource
path = ThumbnailCache.thumbnailPath(imgPath)

# Check if thumbnail already exists (it may have been created by another thread)
if ThumbnailCache.checkThumbnail(path):
self.thumbnailCreated.emit(imgSource, callerID)
return
if not inHomepage:
self.thumbnailCreated.emit(imgSource, callerID)
return path

logging.debug(f'[ThumbnailCache] Creating thumbnail {path} for image {imgPath}')

Expand All @@ -273,7 +278,7 @@ def createThumbnail(self, imgSource, callerID):
img = reader.read()
if img.isNull():
logging.error(f'[ThumbnailCache] Error when reading image: {reader.errorString()}')
return
return ""

# Scale image while preserving aspect ratio
thumbnail = img.scaled(ThumbnailCache.thumbnailSize,
Expand All @@ -287,7 +292,9 @@ def createThumbnail(self, imgSource, callerID):
logging.error(f'[ThumbnailCache] Error when writing thumbnail: {writer.errorString()}')

# Notify listeners
self.thumbnailCreated.emit(imgSource, callerID)
if not inHomepage:
self.thumbnailCreated.emit(imgSource, callerID)
return path

def handleRequestsAsync(self):
"""Process thumbnail creation requests in LIFO order.
Expand Down
1 change: 0 additions & 1 deletion meshroom/ui/qml/Homepage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ Page {
function onClicked() {
// Open pipeline
mainStack.push("Application.qml")
console.log("Open pipeline", modelData["path"])
_reconstruction.new(modelData["path"])
}
}
Expand Down
2 changes: 2 additions & 0 deletions meshroom/ui/reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,8 @@ def isReconstructed(self, viewpoint):
if not viewpoint:
return False
# fetch up-to-date poseId from sfm result (in case of rigs, poseId might have changed)
if not self._views:
return False
view = self._views.get(str(viewpoint.poseId.value), None) # keys are strings (faster lookup)
return view.get('poseId', -1) in self._poses if view else False

Expand Down

0 comments on commit c733696

Please sign in to comment.