A 3D Slicer extension for batch comparison of PLY (reference) and STL (comparison) mesh files with multiple distance metrics suitable for scientific publications.
- Batch Processing: Automatically processes all matching PLY/STL file pairs in a directory
- Landmark-Based Initial Alignment: Manual placement of 3 anatomical landmarks for initial registration
- ICP Fine Registration: Automatic Iterative Closest Point (ICP) algorithm for precise alignment
- Visual Verification: Visual inspection of alignment before distance calculation
- Multiple Distance Metrics:
- Hausdorff Distance (maximum distance)
- RMS (Root Mean Square) Distance
- Mean Absolute Distance
- Median Distance
- 95th Percentile Distance
- Heatmap Generation: Automatic creation of distance heatmap visualizations (saved as PNG)
- Excel Export: All results exported to a single Excel file with comprehensive metrics
- Transform Documentation: Complete transformation matrix stored for reproducibility
This tool implements unsigned distance metrics, which are appropriate for mesh comparison when:
- Meshes may not be perfectly watertight
- Inside/outside distinction is not clearly defined
- Focus is on surface-to-surface deviation measurement
The implemented metrics are widely used in scientific publications for mesh quality assessment:
- Hausdorff Distance: Reports the maximum deviation, useful for identifying largest errors
- RMS Distance: Provides an overall accuracy measure, commonly reported in mesh validation studies
- Mean Absolute Distance: Average deviation across all points
- 95th Percentile: Robust metric less sensitive to outliers
- Median Distance: Central tendency of the distance distribution
- 3D Slicer 5.0 or later
- No additional Slicer extensions required (works with core Slicer functionality)
- Open 3D Slicer
- Go to:
View→Extension Manager - Search for "Mesh Comparison Tool"
- Click
Install - Restart 3D Slicer
-
Download or clone this repository:
git clone https://github.com/mreymus/MeshComparisonTool.git
-
Open 3D Slicer
-
Add the module to Slicer:
-
Method A (Drag & Drop - Easiest):
- Drag the
MeshComparisonTool.pyfile into the Slicer application window - Select "Add Python scripted modules to the application"
- Click "Yes"
- Drag the
-
Method B (Application Settings):
- Go to:
Edit→Application Settings→Modules - In "Additional module paths", click the
>>button - Navigate to the
MeshComparisonToolfolder - Select the folder and click
OK - Restart 3D Slicer
- Go to:
-
-
The module will appear under:
Modules→Surface Models→Mesh Comparison Tool
The extension automatically installs required Python packages on first use:
pandas- For Excel exportopenpyxl- For Excel file creationnumpy- For numerical calculations (usually pre-installed with Slicer)
-
Prepare your mesh files:
- Reference files:
.plyformat (ground truth) - Comparison files:
.stlformat (to be compared) - Naming convention: Files must have identical names (except extension)
- Example:
model1.plyandmodel1.stlwill be paired - Example:
scan_tooth_12.plyandscan_tooth_12.stlwill be paired
- Example:
- Reference files:
-
Place all files in a single input directory
- Open the module:
Modules→Surface Models→Mesh Comparison Tool - Select Input Directory: Folder containing your PLY and STL files
- Select Output Directory: Where results and heatmaps will be saved
- Click "Scan for File Pairs"
- The module will list all matching file pairs found
For each file pair, follow these steps:
- Click "Load Next Pair"
- Reference mesh (PLY) appears in green
- Comparison mesh (STL) appears in red (semi-transparent)
- Click "Set Reference Landmarks (Green)"
- Place 3 anatomical landmarks on the reference mesh
- Use consistent anatomical features (e.g., cusps, ridges)
- Click "Set Comparison Landmarks (Red)"
- Place 3 corresponding landmarks on the comparison mesh
- Order matters: place landmarks in the same sequence
- Click "Perform Alignment (Landmark + ICP)"
- The tool performs:
- Landmark-based rigid transformation
- ICP fine registration for optimal alignment
- Visually verify the alignment in the 3D view
- If alignment looks good: Click "Accept && Calculate Distances"
- Distance metrics are calculated
- Heatmap is automatically saved
- Results are stored
- Next pair loads automatically
- If alignment needs adjustment: Modify landmarks and re-align
- To skip this pair: Click "Skip This Pair"
- After processing all pairs (or aborting batch), click "Export Results to Excel"
- Excel file
mesh_comparison_results.xlsxis saved to output directory - Heatmaps are saved to
output_directory/heatmaps/subfolder
- Click "Abort Batch" to stop processing
- All results calculated so far will be kept
- You can still export results
File: mesh_comparison_results.xlsx
Columns:
Filename: Name of the reference PLY fileHausdorff Distance (max): Maximum surface deviationRMS Distance: Root mean square distanceMean Distance: Average distanceMedian Distance: Median distance95th Percentile Distance: 95th percentile of distancesNumber of Points (Reference): Point count in reference meshNumber of Points (Comparison): Point count in comparison meshTransform Matrix: 4x4 transformation matrix (landmark + ICP combined)Timestamp: Date and time of calculation
Location: output_directory/heatmaps/
Files: [filename]_heatmap.png
- Visual representation of distance distribution
- Color scale: Blue (close) → Red (far)
- Useful for identifying regions of high deviation
-
Choose distinct anatomical features:
- Cusps, corners, or prominent ridges
- Avoid flat or featureless regions
-
Maintain consistent order:
- Place landmarks in the same sequence on both meshes
- Example: anterior cusp → posterior cusp → buccal cusp
-
Spread landmarks across the mesh:
- Don't cluster all landmarks in one area
- Triangular configuration works best
Before clicking "Accept", check:
- Meshes overlap well in all views
- No obvious misalignments
- Major features coincide
- Rotate the 3D view to check from multiple angles
Q: "No matching PLY/STL file pairs found"
- Verify files have identical names (except extension)
- Check files are directly in the input directory (not in subfolders)
Q: Alignment fails or looks incorrect
- Verify you placed exactly 3 landmarks on each mesh
- Check landmarks are in corresponding positions
- Try replacing landmarks with more distinct features
Q: "Error loading files"
- Ensure PLY and STL files are valid mesh files
- Check files are not corrupted
- Try opening files in another mesh viewer first
Q: Module doesn't appear after installation
- Restart 3D Slicer
- Check
Application Settings→Modulesfor the correct path - Check Slicer's Python console for error messages
- Uses VTK's
vtkLandmarkTransformwith rigid body mode - Computes optimal rotation and translation from point correspondences
- VTK's
vtkIterativeClosestPointTransform - Parameters:
- Maximum iterations: 100
- Maximum mean distance: 0.001
- Maximum landmarks: 1000
- Start by matching centroids: ON
- Mode: Rigid body (translation + rotation only, no scaling)
- Point-to-surface distance using
vtkCellLocator - Unsigned distance (always positive)
- Calculated from comparison mesh points to reference surface
The tool uses VTK's native readers:
- PLY:
vtkPLYReader - STL:
vtkSTLReader
Both ASCII and binary formats are supported.
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
MIT License
- Marcel Reymus - LMU Munich
- Developed using 3D Slicer Python API
- VTK library for mesh processing
- Pandas for data export
For questions, issues, or feature requests:
- Open an issue on GitHub
- Contact: info@virtualendodontics.com
- Batch processing of PLY/STL file pairs
- Landmark-based + ICP registration
- Multiple distance metrics
- Heatmap generation
- Excel export
Keywords: mesh comparison, surface distance, Hausdorff distance, ICP registration, 3D Slicer, mesh validation, surface analysis, scientific mesh comparison