This project provides a Python script for performing automated quality analysis by comparing a 3D design (STL file) with a 3D scan (PLY file). The script performs the following steps:
- Loading and Processing: Loads the STL design file and the PLY scan file and converts the STL into a point cloud format.
- Visualization: Previews the point clouds for initial inspection.
- Point Cloud Registration: Uses the Iterative Closest Point (ICP) algorithm to align the scan point cloud to the design point cloud.
- Similarity Scoring: Computes a similarity score based on the alignment of the two point clouds.
- Visualization: Displays the aligned point clouds and their differences.
It is recommended to use Python 3.12.7 in a virtual environment to ensure compatibility.
-
Clone or Download the Repository:
Clone this repository or download the code files to your local machine.
-
Create a Virtual Environment:
python3.12 -m venv .venv
-
Activate the Virtual Environment:
-
On Windows:
.venv\Scripts\activate
-
On Unix or MacOS:
source .venv/bin/activate
-
-
Install the Required Packages:
pip install -r requirements.txt
requirements.txtcontent:numpy==2.1.3 pandas==2.2.3 pyntcloud==0.3.1 scipy==1.14.1 trimesh==4.5.2 pyvista==0.44.2
The main script is automated_quality_analysis.py. It takes two arguments:
- STL File: The path to the 3D design file (e.g.,
design_model.stl). - PLY File: The path to the 3D scan file (e.g.,
scan_data.ply).
Run the script using the following command:
python automated_quality_analysis.py <filename.stl> <filename.ply>Example:
cd /srcpython automated_quality_analysis.py example_path/design_model.stl example_path/scan_data.ply- Loading and Processing: Efficiently loads and processes large STL and PLY files into point clouds.
- Visualization: Provides previews of both the design and scan point clouds for visual inspection.
- Point Cloud Registration: Implements the ICP algorithm for accurate alignment of point clouds.
- Similarity Scoring: Calculates a similarity score based on the Mean Squared Error (MSE) between the aligned point clouds.
- Final Visualization:
- Colored Dots: Represent the scan cloud (normalized distances).
- Gray Dots: Represent the design cloud.
The project includes the following Python modules and key functions:
This is the main script that orchestrates the quality analysis process.
main(stl_file, ply_file): Performs the automated quality analysis steps, including loading files, visualization, ICP registration, similarity scoring, and final visualization.
Contains utility functions for point cloud operations.
compute_sample_fraction(total_points, target_num_points=1000000, scaling_factor=1.0): Computes the sampling fraction for point clouds.perform_icp(source_points, target_points, max_iterations=20, tolerance=1e-6): Aligns two point clouds by minimizing the distance between them iteratively (Iterative Closest Point).downsample_points(points, max_points=1000000): Reduces the number of points in a cloud.align_cloud_scales(source_points, target_points): Normalizes point clouds to the same scale on all axes.
Contains functions for visualizing point clouds.
visualize_point_cloud(cloud, target_num_points, coloring, compression_factor, title): Visualizes a single point cloud using PyVista.plot_point_clouds_multi_view(cloud1, cloud2, target_num_points, compression_factor, title): Visualizes two aligned point clouds with PyVista.
Ensure the following Python packages are installed in your virtual environment:
numpypandaspyntcloudscipytrimeshpyvista
These are specified in the requirements.txt file.
- Error Loading STL or PLY Files: Verify that the files are not corrupted and the paths are correct.
- NaN or Infinite Values in Aligned Points: Check the input data for inconsistencies or preprocessing requirements.