geometry_pipeline package¶
Submodules¶
geometry_pipeline.angles module¶
geometry_pipeline.convert module¶
- geometry_pipeline.convert.obj2pc(obj_path: str, out_path: str) str [source]¶
Convert an OBJ file to a point cloud (PLY format).
- Parameters:
obj_path (str) – Path to the OBJ file.
out_path (str) – Directory to save the PLY file.
- Returns:
Path to the saved PLY file.
- Return type:
str
- geometry_pipeline.convert.obj2stl(obj_path: str, out_path: str) str [source]¶
Convert an OBJ file to an STL file.
- Parameters:
obj_path (str) – Path to the OBJ file.
out_path (str) – Directory to save the STL file.
- Returns:
Path to the saved STL file.
- Return type:
str
- geometry_pipeline.convert.recenter_and_reaxis_mesh(mesh: Trimesh) Tuple[Trimesh, ndarray] [source]¶
Recenter and reaxis the mesh using its principal inertia transform, ensuring that the mesh is oriented such that the gravity vector (negative Z-axis) aligns with the principal axis corresponding to the object’s “up” direction.
- Parameters:
mesh (trimesh.Trimesh) – The input mesh.
- Returns:
The transformed mesh and the transformation matrix.
- Return type:
Tuple[trimesh.Trimesh, np.ndarray]
- geometry_pipeline.convert.step2mesh(step_path: str) Trimesh [source]¶
Convert a STEP file to a mesh using GMSH.
- Parameters:
step_path (str) – Path to the STEP file.
- Returns:
The generated mesh.
- Return type:
trimesh.Trimesh
- geometry_pipeline.convert.step2obj(step_path: str, out_path: str) str [source]¶
Convert a STEP file to an OBJ file.
- Parameters:
step_path (str) – Path to the STEP file.
out_path (str) – Directory to save the OBJ file.
- Returns:
Path to the saved OBJ file.
- Return type:
str
- geometry_pipeline.convert.step2stl(step_path: str, out_path: str) str [source]¶
Convert a STEP file to an STL file.
- Parameters:
step_path (str) – Path to the STEP file.
out_path (str) – Directory to save the STL file.
- Returns:
Path to the saved STL file.
- Return type:
str
- geometry_pipeline.convert.stl2obj(stl_path: str, out_path: str) str [source]¶
Convert an STL file to an OBJ file.
- Parameters:
stl_path (str) – Path to the STL file.
out_path (str) – Directory to save the OBJ file.
- Returns:
Path to the saved OBJ file.
- Return type:
str
- geometry_pipeline.convert.stl2pc(stl_path: str, out_path: str) str [source]¶
Convert an STL file to a point cloud (PLY format).
- Parameters:
stl_path (str) – Path to the STL file.
out_path (str) – Directory to save the PLY file.
- Returns:
Path to the saved PLY file.
- Return type:
str
- geometry_pipeline.convert.write_ply(points: ndarray, filename: str, text: bool = False, default_rgb: Tuple[int, int, int] = (88, 88, 88)) None [source]¶
Write points to a PLY file.
- Parameters:
points (np.ndarray) – Nx3 array of points.
filename (str) – Path to save the PLY file.
text (bool) – Whether to save the PLY file in text format.
default_rgb (Tuple[int, int, int]) – Default RGB color for the points.
geometry_pipeline.snapshots module¶
- geometry_pipeline.snapshots.capture_snapshots(mesh: Trimesh, camera_orientations: ndarray, camera_distances: List[float], output_dir: str, names: List[str] | None = None, resolution: List[int] = [512, 512], contrast_factor: float = 1.2, font_path: str | None = None, font_size: int = 20) List[str] [source]¶
Capture snapshots of the mesh from different camera orientations and distances.
- Parameters:
mesh (trimesh.Trimesh) – The mesh to capture snapshots of.
camera_orientations (np.ndarray) – List of camera orientations (Euler angles).
camera_distances (List[float]) – List of camera distances.
output_dir (str) – The output directory to save the snapshots.
names (Optional[List[str]], optional) – List of names for the snapshots, defaults to None.
resolution (List[int], optional) – The resolution of the snapshots, defaults to [512, 512].
contrast_factor (float, optional) – Contrast factor for image enhancement, defaults to 1.2.
font_path (Optional[str], optional) – Path to a .ttf font file, defaults to None.
font_size (int, optional) – Font size for the caption, defaults to 20.
- Returns:
A list of paths to the saved snapshot images.
- Return type:
List[str]
- geometry_pipeline.snapshots.enhance_color_contrast(image: Image, factor: float = 1.2) Image [source]¶
Enhance the color contrast of the image.
- Parameters:
image (Image.Image) – The image to enhance.
factor (float, optional) – The contrast enhancement factor, defaults to 1.2.
- Returns:
The enhanced image.
- Return type:
Image.Image
- geometry_pipeline.snapshots.generate_snapshots(file_path: str, output_dir: str = '../data/snapshots', resolution: List[int] = [512, 512], direction: str | Literal['common', 'box', 'omni'] = 'common', preview: bool = False, mesh_color: List[int] = [0, 102, 204], reaxis_gravity: bool = False, **kwargs) List[str] [source]¶
Generate snapshots or previews of a 3D mesh from different camera orientations and distances.
- Parameters:
file_path (str) – Path to the 3D file (OBJ, STEP, or STL).
output_dir (str, optional) – The output directory to save the snapshots, defaults to “../data/snapshots”.
resolution (List[int], optional) – The resolution of the snapshots, defaults to [512, 512].
direction (str | Literal["common", "box", "omni"], optional) – Direction or preset collection of directions: ‘box’, ‘common’, ‘omni’, or a comma-separated list of directions, defaults to “common”.
preview (bool, optional) – Whether to preview the scene interactively, defaults to False.
mesh_color (Optional[List[int]], optional) – The color to apply to the mesh in RGB format, defaults to None.
reaxis_gravity (bool, optional) – Whether to reaxis and recenter the mesh before capturing snapshots, defaults to False.
- Returns:
A list of paths to the saved snapshot images.
- Return type:
List[str]
- geometry_pipeline.snapshots.get_adaptive_camera_distance(mesh: Trimesh, scale_factor: float = 1, fov: float = 30) float [source]¶
Calculate a suitable camera distance based on the mesh’s bounding box.
- Parameters:
mesh (trimesh.Trimesh) – The mesh for which to calculate the camera distance.
scale_factor (float, optional) – Scaling factor for the camera distance, defaults to 1.
fov (float, optional) – Field of view in degrees, defaults to 30.
- Returns:
The calculated camera distance.
- Return type:
float
- geometry_pipeline.snapshots.get_camera_pose(looking_from_direction: str = 'near') ndarray [source]¶
Retrieve the camera pose (Euler angles) for a given direction.
- Parameters:
looking_from_direction (str, optional) – The direction from which the camera is looking, defaults to “near”.
- Returns:
The Euler angles representing the camera pose.
- Return type:
np.ndarray
- geometry_pipeline.snapshots.preview_mesh_interactively(mesh: Trimesh, direction: str = 'front', reaxis_gravity: bool = False, mesh_color: List[int] | None = None) SceneViewer [source]¶
Preview the mesh interactively using trimesh.SceneViewer.
- Parameters:
mesh (trimesh.Trimesh) – The mesh to preview.
direction (str, optional) – The direction from which the camera is looking, defaults to “front”.
reaxis_gravity (bool, optional) – Whether to reaxis and recenter the mesh before previewing, defaults to False.
mesh_color (Optional[List[int]], optional) – The color to apply to the mesh in RGB format, defaults to None.
- Returns:
The SceneViewer object.
- Return type:
SceneViewer
- geometry_pipeline.snapshots.preview_scene_interactive(mesh: Trimesh, camera_orientation: ndarray, camera_distance: float) SceneViewer [source]¶
Create an interactive scene preview using trimesh.SceneViewer.
- Parameters:
mesh (trimesh.Trimesh) – The mesh to be displayed in the scene.
camera_orientation (np.ndarray) – The Euler angles for the camera orientation.
camera_distance (float) – The distance of the camera from the mesh.
- Returns:
The SceneViewer object.
- Return type:
SceneViewer