How pyushkevich/itksnap works
Project Type and Purpose
• ITK-SNAP is a standalone, cross-platform desktop application for semi-automated 3D medical image segmentation.
• It is written in C++ and uses CMake as its build system. It relies on Qt for the GUI, ITK for image-processing pipelines, VTK/OpenGL for rendering, and various third-party libraries (JSONcpp, REST client, etc.) for support functionality.
High-Level File Structure Analysis
• Top-level directories:
• CMake, Utilities – build scripts, packaging, Dockerfiles, OS-specific installers
• Common – low-level helpers, exception, IPC, JSON, GPU settings, history, registry
• Logic – core image‐processing pipelines, segmentation, meshing, preprocessing, slicing, I/O (REST, CSV), workspace API
• GUI – Qt Model/View, Components, Windows dialogs, coupling code, resources, main entry point
• Renderer – VTK/OpenGL rendering abstractions for slices, 3D views, overlays, annotation, widgets
• ProgramData – runtime data: help pages, tutorials, sample images, presets
• Submodules – embedded third-party libraries (c3d, greedy, digestible)
• Testing – unit and GUI tests, test data
Insights from README
• ITK-SNAP is open source and intended for research labs.
• Users interact via a rich Qt GUI for image loading, annotation, and segmentation.
• No web or distributed microservices; it is monolithic with optional REST calls for workspace integration (Logic/WorkspaceAPI/RESTClient).
Main Architectural Components
a. GUI Layer (Qt)
• Modules:
• GUI/Model – Qt data models (MVC pattern)
• GUI/Qt/Components – custom Qt widgets & panels
• GUI/Qt/Coupling – binding between models and Qt widgets
• GUI/Windows – dialogs, wizards, main windows
• Entry point: GUI/main.cxx
• Responsibilities: user interaction, command dispatch, model updates, menu/toolbars, dialogs.
b. Logic Layer (Core Processing)
• Subsystems:
• Framework – application lifecycle, global state, undo/redo, layer associations
• ImageWrapper – abstraction over ITK image types, CPU‐GPU filters
• Preprocessing, LevelSet, Mesh, Slicing, RLEImage – specialized pipelines
• WorkspaceAPI – optional REST calls (upload/download projects)
• MetaDataAccess, PresetManager, Registry I/O
• Responsibilities: load and transform image data, run segmentation algorithms, maintain application state.
c. Rendering Layer
• Subsystems:
• AbstractVTKRenderer, SceneRenderer – generic rendering interfaces
• Slice & 3D view renderers, annotation renderers, overlays
• Orientation widget, GL→PNG exporter
d. Common Utilities
• Provides cross-cutting functionality: command-line parsing, IPC handlers, JSON parsing, event management, affine transforms, exception handling, threading helpers.
e. Data & Submodules
• ProgramData – read-only assets loaded at runtime (help HTML, preset curves, sample images).
• Submodules – compiled in or linked at build time.
f. Build and Packaging
• CMake scripts (CMakeLists.txt, CMake/DeployQt5.cmake) orchestrate build.
• Utilities manage platform installers (Docker, Linux shell scripts, Mac bundles, InnoSetup for Windows).
Relationships and Interactions
• GUI Layer ↔ Logic Layer:
• GUI models subscribe to Logic framework global state and image data.
• User actions in GUI trigger Logic processes (e.g., segmentation, mesh export).
• Logic Layer ↔ Rendering Layer:
• Logic produces data (slices, meshes, overlays) that Rendering consumes.
• Rendering notifies Logic of user interactions (e.g., ROI selection).
• GUI Layer ↔ Rendering Layer:
• QtVTK integration: Rendering widgets embedded in Qt windows.
• Coupling code links Qt events to rendering updates.
• Logic Layer ↔ Common Utilities:
• Use JSON, IPC, registry I/O, threading from Common.
• Build/Packaging operate externally but produce the deliverable that includes all layers.
Architectural Patterns and Principles
• Model-View-Controller (MVC) / Model-View (Qt): clear separation of data (Logic) and presentation (GUI).
• Layered architecture: Common utilities at bottom, Logic above it, Rendering and GUI on top.
• Plugin-like modularity: individual image processing pipelines under Logic/Common, Logic/Preprocessing, Logic/LevelSet, Logic/Mesh, etc.
• Dependency Injection via Qt coupling classes.