Python bindings for threecrate: a high-performance 3D point cloud and mesh processing library
Project description
threecrate (Python)
Python bindings for threecrate — a high-performance 3D point cloud and mesh processing library written in Rust.
Installation
Pre-built wheels (no Rust required):
pip install threecrate
Build from source (requires Rust and maturin):
pip install maturin
cd threecrate-python
maturin develop --release
Quick Start
import numpy as np
import threecrate as tc
# Load a point cloud
cloud = tc.read_point_cloud("scan.ply")
print(cloud) # PointCloud(120000 points)
# Or create from a numpy array (N, 3) float32
pts = np.random.rand(1000, 3).astype(np.float32)
cloud = tc.PointCloud.from_numpy(pts)
# Get points back as numpy
arr = cloud.to_numpy() # shape (N, 3), dtype float32
API Reference
Types
| Class | Description |
|---|---|
PointCloud |
XYZ point cloud. Construct with from_numpy() or read_point_cloud(). |
NormalPointCloud |
Point cloud with per-point surface normals. Returned by estimate_normals(). |
TriangleMesh |
Triangle mesh with vertices and faces. |
IcpResult |
Registration result: transformation, mse, iterations, converged. |
PlaneSegmentationResult |
RANSAC plane result: plane_coefficients(), inlier_indices(), inlier_cloud(), num_inliers. |
Filtering
# Voxel grid downsampling
cloud = tc.voxel_downsample(cloud, voxel_size=0.05)
# Statistical outlier removal (default: k=20, std_ratio=2.0)
cloud = tc.remove_statistical_outliers(cloud, k_neighbors=20, std_ratio=2.0)
# Radius outlier removal
cloud = tc.remove_radius_outliers(cloud, radius=0.1, min_neighbors=5)
Normal Estimation
# Estimate normals using K nearest neighbours (default k=10)
normal_cloud = tc.estimate_normals(cloud, k_neighbors=10)
# Access positions and normals as numpy arrays
positions = normal_cloud.positions() # (N, 3) float32
normals = normal_cloud.normals() # (N, 3) float32
Registration
# Point-to-point ICP
result = tc.icp(source, target, max_iterations=50)
print(result.converged) # True / False
print(result.mse) # float
print(result.iterations) # int
T = result.transformation() # (4, 4) float32 numpy array
Segmentation
# RANSAC plane fitting
result = tc.segment_plane(cloud, threshold=0.01, max_iterations=1000)
coeffs = result.plane_coefficients() # (4,) float32 [a, b, c, d]
indices = result.inlier_indices() # list[int]
plane_cloud = result.inlier_cloud(cloud) # PointCloud of inliers
print(result.num_inliers)
# Remove the dominant plane and keep the rest
non_plane_pts = [cloud.to_numpy()[i] for i in range(len(cloud))
if i not in set(indices)]
# Euclidean cluster extraction
clusters = tc.extract_clusters(cloud, tolerance=0.02,
min_cluster_size=100, max_cluster_size=25000)
for i, cluster in enumerate(clusters):
print(f"Cluster {i}: {len(cluster)} points")
Mesh Simplification
# Reduce mesh to 50 % of original face count (quadric error decimation)
simplified = tc.simplify_mesh(mesh, reduction_ratio=0.5)
print(simplified.vertex_count, simplified.face_count)
Mesh Smoothing
# Laplacian smoothing (fast, mild shrinkage)
smooth = tc.smooth_mesh_laplacian(mesh, iterations=10, lambda_=0.5)
# Taubin smoothing (volume-preserving, recommended)
smooth = tc.smooth_mesh_taubin(mesh, iterations=10, lambda_=0.5, mu=-0.53)
# HC smoothing (good volume preservation with fine control)
smooth = tc.smooth_mesh_hc(mesh, iterations=10, alpha=0.0, beta=0.5)
Surface Reconstruction
# Automatic algorithm selection
mesh = tc.reconstruct(cloud)
# Poisson reconstruction (higher quality, requires normals)
normal_cloud = tc.estimate_normals(cloud)
mesh = tc.poisson_reconstruct(normal_cloud)
print(mesh.vertex_count)
print(mesh.face_count)
verts = mesh.vertices() # (N, 3) float32
faces = mesh.faces() # (M, 3) uint32
I/O
# Point clouds — PLY, PCD, XYZ, CSV, LAS, LAZ, E57
cloud = tc.read_point_cloud("scan.ply")
tc.write_point_cloud(cloud, "output.pcd")
# Meshes — PLY, OBJ
mesh = tc.read_mesh("model.obj")
tc.write_mesh(mesh, "output.ply")
Full Example
import numpy as np
import threecrate as tc
# Load and preprocess
cloud = tc.read_point_cloud("scene.ply")
cloud = tc.voxel_downsample(cloud, voxel_size=0.02)
cloud = tc.remove_statistical_outliers(cloud, k_neighbors=20, std_ratio=2.0)
# Register two scans
source = tc.read_point_cloud("scan_a.ply")
target = tc.read_point_cloud("scan_b.ply")
result = tc.icp(source, target, max_iterations=100)
if result.converged:
print(f"Aligned with MSE {result.mse:.4f}")
print(result.transformation())
# Reconstruct surface
normal_cloud = tc.estimate_normals(cloud, k_neighbors=15)
mesh = tc.poisson_reconstruct(normal_cloud)
tc.write_mesh(mesh, "reconstruction.ply")
print(f"Mesh: {mesh.vertex_count} vertices, {mesh.face_count} faces")
Building from Source
Requirements: Rust 1.70+, Python 3.8+, maturin 1.x
# Install maturin
pip install maturin
# Development build (editable install)
cd threecrate-python
maturin develop --release
# Build a distributable wheel
maturin build --release --out dist/
pip install dist/threecrate-*.whl
License
Dual-licensed under MIT or Apache-2.0. See LICENSE-MIT for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file threecrate-0.7.1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: threecrate-0.7.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 753.7 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec94c74b85080ff520e990d41d4591cc9f39eb8867c33a567603446a465937b5
|
|
| MD5 |
5fec72f66eb3379411671f0e1c22fcbf
|
|
| BLAKE2b-256 |
b6071929cc0d50514a69472d3ff829bb122ba24dc9f4ce5f9fafcfc92f15daa9
|
Provenance
The following attestation bundles were made for threecrate-0.7.1-cp311-cp311-win_amd64.whl:
Publisher:
python.yml on rajgandhi1/threecrate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
threecrate-0.7.1-cp311-cp311-win_amd64.whl -
Subject digest:
ec94c74b85080ff520e990d41d4591cc9f39eb8867c33a567603446a465937b5 - Sigstore transparency entry: 1283207893
- Sigstore integration time:
-
Permalink:
rajgandhi1/threecrate@bd3a83ebe6a7273d03669b2d2c8d3f66cf72dfe1 -
Branch / Tag:
refs/tags/v0.7.1 - Owner: https://github.com/rajgandhi1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python.yml@bd3a83ebe6a7273d03669b2d2c8d3f66cf72dfe1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file threecrate-0.7.1-cp311-cp311-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: threecrate-0.7.1-cp311-cp311-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 999.3 kB
- Tags: CPython 3.11, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e35a1161cb058ed08dd8033433557b85cbe87dca0821e97281a5ac9a221d1e29
|
|
| MD5 |
835738a0c469ea58f637dc8a2aa221b9
|
|
| BLAKE2b-256 |
b1742e3157b6993b9b159b49275d8a92351c769e3d6dc077942448fabceeba4e
|
Provenance
The following attestation bundles were made for threecrate-0.7.1-cp311-cp311-manylinux_2_35_x86_64.whl:
Publisher:
python.yml on rajgandhi1/threecrate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
threecrate-0.7.1-cp311-cp311-manylinux_2_35_x86_64.whl -
Subject digest:
e35a1161cb058ed08dd8033433557b85cbe87dca0821e97281a5ac9a221d1e29 - Sigstore transparency entry: 1283207888
- Sigstore integration time:
-
Permalink:
rajgandhi1/threecrate@bd3a83ebe6a7273d03669b2d2c8d3f66cf72dfe1 -
Branch / Tag:
refs/tags/v0.7.1 - Owner: https://github.com/rajgandhi1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python.yml@bd3a83ebe6a7273d03669b2d2c8d3f66cf72dfe1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file threecrate-0.7.1-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: threecrate-0.7.1-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 850.3 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
797424a9737bcec0d3451e18d532b7a7e0ec3acb65c422868658eda0af996a46
|
|
| MD5 |
bd355e2033cf6543b36bcb837302578e
|
|
| BLAKE2b-256 |
6ca33ef3d6ad01717b6e0fe2e9a18a5c3960c0c05824fa116b74ffb408860523
|
Provenance
The following attestation bundles were made for threecrate-0.7.1-cp311-cp311-macosx_11_0_arm64.whl:
Publisher:
python.yml on rajgandhi1/threecrate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
threecrate-0.7.1-cp311-cp311-macosx_11_0_arm64.whl -
Subject digest:
797424a9737bcec0d3451e18d532b7a7e0ec3acb65c422868658eda0af996a46 - Sigstore transparency entry: 1283207881
- Sigstore integration time:
-
Permalink:
rajgandhi1/threecrate@bd3a83ebe6a7273d03669b2d2c8d3f66cf72dfe1 -
Branch / Tag:
refs/tags/v0.7.1 - Owner: https://github.com/rajgandhi1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python.yml@bd3a83ebe6a7273d03669b2d2c8d3f66cf72dfe1 -
Trigger Event:
release
-
Statement type: