How dcbia-ortholab/slicerdentalmodelseg works
Project type and purpose
• This is a 3D Slicer extension (CrownSegmentation) plus a standalone CLI (CrownSegmentationcli) for deep-learning–based automatic segmentation and labeling of dental crown models (.vtk).
• It provides both a GUI module (loaded by 3D Slicer) and a command-line interface, leverages PyTorch for inference, and wraps everything with CMake for cross-platform build/packaging.
Key directories and files
• Top-level:
• CMakeLists.txt – orchestrates building the Slicer extension and CLI
• readme.md – explains installation and usage
• examples/ – sample .vtk meshes and expected outputs
• CrownSegmentation/ (the Slicer module)
• CrownSegmentation.py – main Python controller for the Slicer GUI
• Resources/UI/CrownSegmentation.ui – QtDesigner file defining the GUI layout
• CrownSegmentation_utils/ – Python helper functions (data I/O, model download/installation)
• CrownSegmentationcli/ (standalone CLI)
• CrownSegmentationcli.py – entry-point script for headless usage
• CrownSegmentationcli.xml – descriptor for CLI arguments, used by CMake to generate wrap
• Testing/ – CMake and Python test scripts
• .gitignore, LICENSE
Architectural overview and components
A. Slicer Host Application
• Loads the extension via CMake-generated module
• Passes MRMLModelNodes (.vtk meshes) into the module
B. GUI Module (CrownSegmentation)
• UI Definition (Qt .ui file)
• Controller (CrownSegmentation.py)
• Invokes utils for pre-/post-processing and inference
C. Core Segmentation Engine
• Python code in CrownSegmentation_utils
• install_pytorch.py for dependency management (CUDA/PyTorch)
• Data preparation: converting 3D mesh to 2D views
• Model inference: loads a serialized .pt or .pth file, runs forward pass
D. CLI Module
• CrownSegmentationcli.py + XML descriptor
• Mirrors GUI module’s calls to utils and core engine
E. External Dependencies
• PyTorch + CUDA
• VTK I/O (via Slicer or directly in Python)
• Qt (embedded in Slicer)
F. Data Flow/Storage
• Input: .vtk mesh → MRMLModelNode (GUI) or file path (CLI)
• Intermediate: rendered 2D slices, tensor batches
• Output: labeled .vtk mesh (single or per-tooth output files)
Relationships and interactions
• UI Controller calls CrownSegmentation_utils for:
• Checking/installing dependencies
• Loading the PyTorch model
• Preprocessing the input mesh
• Running inference
• Postprocessing and saving output mesh(es)
• All data I/O flows through VTK or Slicer MRML APIs
• Testing harness invokes CLI or individual utils functions to validate outputs
Architectural patterns and design principles
• Plugin architecture: the extension cleanly separates GUI (view/controller) from the segmentation engine (model)
• Single Responsibility: utils directory isolates environment setup, model loading, data transforms
• Reuse via CMake: same source code base builds both Slicer module and standalone CLI
• Dependency injection: model path, number of views, resolution, and numbering system are all parameterized
• Blue: Host applications (3D Slicer, CLI)
• Green: GUI Layer (CrownSegmentation.py + .ui)
• Orange: Core Engine (CrownSegmentation_utils)
• Gray: External services/dependencies (PyTorch/CUDA, VTK)
• Yellow: Data stores (input/output .vtk files, model files)
• From Host → GUI/CLI, from GUI/CLI → Core Engine, from Engine → Data Store
• Rectangles for modules