Fix 3D meshes never loading for uploaded scans - #129
Merged
Conversation
The 3D pane hung on "Loading 3D segmentation..." for every uploaded scan. MeshViewer fetches /api/cases/<id>/mesh-manifest, which only serves pre-baked dataset meshes via get_panTS_id + MESH_PATH; for a session id (a UUID) it 404s, so the manifest stayed null and the pane never rendered. Inference never generated session meshes. Add on-demand session meshes, reusing the existing mesh machinery: - GET /api/sessions/<id>/mesh-manifest: builds the manifest from the session's combined_labels (generate_mesh_manifest with route_base="sessions") - GET /api/sessions/<id>/render_only/<file>: marching-cubes the requested organ from combined_labels (generate_organ_glb_bytes), cached next to the mask - generate_mesh_manifest gains a route_base arg so organ URLs point at the session route (default "cases" keeps dataset behaviour unchanged) - MeshViewer/fetchMeshManifest take isSession; VisualizationPage passes it for session routes - register liver/kidney/colon_lesion (33/34/35) in mesh LABELS so the four LesionSegmenter lesions also get 3D meshes (absent labels are skipped)
| try: | ||
| glb_bytes = generate_organ_glb_bytes(organ_key, seg_path) | ||
| except ValueError as e: | ||
| return jsonify({"error": str(e)}), 404 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When you upload a scan and open it in the viewer, the 2D panes render fine but the
3D pane hangs forever on "Loading 3D segmentation..." (see the stuck viewport
in a
/session/<uuid>view).Cause
MeshViewerfetches/api/cases/<id>/mesh-manifest, which only serves pre-bakeddataset meshes (
get_panTS_id+MESH_PATH, generated offline bypreprocess_meshes.py). For a session the id is a UUID, so that route 404s,manifeststaysnull, and the pane never renders. Inference never generated anysession meshes, so there was nothing to serve.
Fix — generate session meshes on demand, reusing the existing machinery
Backend
GET /api/sessions/<id>/mesh-manifest— builds the manifest from the session'scombined_labels(generate_mesh_manifest(..., route_base="sessions")).GET /api/sessions/<id>/render_only/<file>— marching-cubes the requested organout of
combined_labels(generate_organ_glb_bytes), cached next to the maskso organ toggles / revisits don't recompute.
generate_mesh_manifestgains aroute_basearg so organ URLs point at thesession route; default
"cases"keeps dataset behaviour byte-for-byte.liver_lesion/kidney_lesion/colon_lesion(33/34/35) in meshLABELSso the four LesionSegmenter lesions also get 3D meshes (absent labels are skipped).
Frontend
fetchMeshManifest/SegmentationMeshViewertake anisSessionflag;VisualizationPagepasses it for session routes. Organ GLB URLs come from themanifest, so no other frontend change is needed.
Verification
npm run build(tsc + vite) passes on the server toolchain.combined_labels.nii.gz:generate_mesh_manifest(route_base="sessions")returns organs with correct/api/sessions/<id>/render_only/*.glbURLs, andgenerate_organ_glb_bytesproduced a valid ~1 MB GLB.