mascaf.mesh¶
Main mesh class
- mascaf.mesh.example_mesh(kind='cylinder', *, radius=1, height=10, sections=16, major_radius=4, minor_radius=1, major_sections=32, minor_sections=16, **kwargs)[source]¶
Create a simple demo mesh using trimesh primitives.
- Parameters:
kind (
str) – Type of primitive to generate. Default “cylinder”.radius (
float) – Cylinder radius (when kind=”cylinder”). Default 1.height (
float) – Cylinder height (when kind=”cylinder”). Default 10.sections (
int|None) – Cylinder radial resolution (pie wedges). Default 16.major_radius (
float) – Torus major radius (center of hole to centerline of tube). Default 4.minor_radius (
float) – Torus minor radius (tube radius). Default 1.major_sections (
int|None) – Torus resolution around major circle. Default 32.minor_sections (
int|None) – Torus resolution around tube section. Default 16.**kwargs (
dict) – Passed through to Trimesh constructor via trimesh.creation.* helpers (e.g., process=False).
- Returns:
Generated primitive mesh.
- Return type:
Examples
>>> m = example_mesh("cylinder", radius=0.4, height=1.5) >>> t = example_mesh("torus", major_radius=1.0, minor_radius=0.25)
- class mascaf.mesh.MeshManager(mesh=None, mesh_path=None, verbose=True)[source]¶
Bases:
objectUnified mesh class handling loading, processing, and analysis of triangle meshes.
Wraps a
trimesh.Trimeshwith convenience methods for loading, saving, copying, and analyzing mesh geometry. Loading can be deferred by passing amesh_pathto the constructor or by callingload_mesh()directly.- Parameters:
Examples
>>> mgr = MeshManager(mesh_path="neuron.obj") >>> mgr.bounding_box_diagonal()
- load_mesh(filepath, file_format=None)[source]¶
Load a mesh from file and store it as
mesh.- Parameters:
- Returns:
The loaded mesh (also stored as
self.mesh).- Return type:
- Raises:
ValueError – If the file cannot be loaded or does not contain a single mesh.
- copy()[source]¶
Return a new
MeshManagerwrapping a deep copy of the mesh.- Return type:
- to_trimesh()[source]¶
Return the underlying
trimesh.Trimeshobject.- Return type:
- bounding_box_diagonal()[source]¶
Return the length of the bounding box space diagonal.
Computed as the Euclidean distance between the minimum and maximum corners of the axis-aligned bounding box of the mesh. Useful as a scale reference when choosing
max_edge_lengthforFitOptions.- Returns:
Length of the bounding box diagonal.
- Return type:
- analyze_mesh()[source]¶
Analyze mesh properties for diagnostic purposes without modifying the mesh.
- Returns:
Dictionary with keys:
face_count,vertex_count,bounds,is_watertight,is_winding_consistent,volume,is_manifold,euler_characteristic,genus,normal_stats, andissues(list of warning strings).- Return type:
- print_mesh_analysis(verbose=False)[source]¶
Analyze a mesh and print a formatted report of its properties.
- Args:
verbose: Whether to print detailed information
- repair_mesh(fix_holes=True, remove_duplicates=True, fix_normals=True, remove_degenerate=True, fix_negative_volume=True, keep_largest_component=False, verbose=True)[source]¶
Attempt to repair common mesh issues to improve watertightness and quality.
- Return type:
- Parameters:
- Args:
mesh_data: Either a Trimesh object or (vertices, faces) tuple fix_holes: Whether to attempt filling holes remove_duplicates: Whether to remove duplicate faces and vertices fix_normals: Whether to fix face normal consistency remove_degenerate: Whether to remove degenerate faces fix_negative_volume: Whether to invert faces if mesh has negative volume keep_largest_component: Whether to keep only the largest connected component verbose: Whether to print repair summary
- Returns:
Repaired mesh (new copy, original is not modified)
- visualize_mesh_3d(title='3D Mesh Visualization', color='lightblue', backend='auto', show_axes=True, show_wireframe=False, width=800, height=600, *, eye_scale=1.25, skel=None, skel_color='crimson', skel_line_width=3.0, skel_opacity=0.95)[source]¶
Create a 3D visualization of a mesh.
- Return type:
- Parameters:
- Args:
title: Plot title color: Mesh color (named color or RGB tuple) backend: Visualization backend (‘plotly’ or ‘matplotlib’) show_axes: Whether to show coordinate axes show_wireframe: Whether to show wireframe overlay skel: Optional SkeletonGraph or list of SkeletonGraph to overlay as 3D lines skel_color: Color(s) for skeleton overlay. Can be a single color or list of colors (one per skeleton) skel_line_width: Line width for skeleton overlay skel_opacity: Opacity for skeleton overlay (plotly only)
- Returns:
Figure object (backend-dependent) or None if visualization fails
- visualize_mesh_slice_interactive(title='Interactive Mesh Slice', z_range=None, num_slices=50, slice_color='red', mesh_color='lightblue', mesh_opacity=0.3)[source]¶
Create an interactive 3D visualization of a mesh with a controllable slice plane.
This function displays a 3D mesh and calculates the intersection of the mesh with an xy-plane at a user-controlled z-value. The intersection is shown as a colored line on the mesh. A slider allows the user to interactively change the z-value of the intersection plane.
- Return type:
- Parameters:
- Args:
title: Plot title z_range: Tuple of (min_z, max_z) for slice range. Auto-detected if None. num_slices: Number of positions for the slider slice_color: Color for the intersection line mesh_color: Color for the 3D mesh mesh_opacity: Opacity of the 3D mesh (0-1)
- Returns:
Plotly figure with interactive slider for controlling the z-value