polyfoammesh.commercial.cad_healer

CAD defeaturing & healing — inspired by ANSA CAD Cleanup, SpaceClaim.

Provides automatic detection and repair of common CAD issues that prevent or degrade mesh generation:

  • Small feature detection (holes, fillets, chamfers, sliver faces)

  • Automatic hole filling

  • Narrow-face merging

  • STL watertight check and repair

  • Facet count reduction (decimation) with feature preservation

All operations preserve the original file — a healed copy is written to the case directory.

Classes

CADHealer([thresholds])

Automatic CAD healing and defeaturing.

HealReport([original_faces, ...])

Summary of CAD healing operations performed.

class polyfoammesh.commercial.cad_healer.HealReport(original_faces=0, original_vertices=0, final_faces=0, final_vertices=0, holes_filled=0, degenerate_removed=0, watertight=False, operations=<factory>, warnings=<factory>)[source]

Bases: object

Summary of CAD healing operations performed.

Parameters:
  • original_faces (int)

  • original_vertices (int)

  • final_faces (int)

  • final_vertices (int)

  • holes_filled (int)

  • degenerate_removed (int)

  • watertight (bool)

  • operations (list[str])

  • warnings (list[str])

original_faces: int = 0
original_vertices: int = 0
final_faces: int = 0
final_vertices: int = 0
holes_filled: int = 0
degenerate_removed: int = 0
watertight: bool = False
operations: list[str]
warnings: list[str]
property face_reduction_pct: float
class polyfoammesh.commercial.cad_healer.CADHealer(thresholds=None)[source]

Bases: object

Automatic CAD healing and defeaturing.

Operates on trimesh.Trimesh objects. For file-level healing use heal_file() which reads → heals → writes.

Usage:

healer = CADHealer()
for mesh in meshes:
    report = healer.heal_mesh(mesh)
healer.heal_file("input.step", "output.stl")
Parameters:

thresholds (dict[str, float] | None)

MIN_HOLE_DIAMETER: float = 0.001
MIN_FILLET_RADIUS: float = 0.0005
MIN_SLIVER_AREA: float = 1e-06
MAX_DECIMATION_RATIO: float = 0.3
heal_mesh(mesh)[source]

Apply all healing operations to a single mesh.

Returns a HealReport summarising what was done.

Return type:

HealReport

Parameters:

mesh (Trimesh)

heal_meshes(meshes)[source]

Heal multiple meshes, returning a report per mesh.

Return type:

list[HealReport]

Parameters:

meshes (list[Trimesh])

heal_file(input_path, output_path=None)[source]

Read a geometry file, heal all patches, optionally write.

Parameters:
  • input_path (Path | str) – Path to input file (.step, .stp, .stl).

  • output_path (Path | str | None) – Optional output path. If None, a healed STL is written alongside the input as <stem>_healed.stl.

Return type:

tuple[list[Trimesh] | None, list[HealReport]]

Returns:

(meshes, reports) — the healed meshes and a report per patch.

detect_small_features(mesh)[source]

Analyse a mesh and return information about small features.

Returns a dict with keys like min_edge_length, n_sliver_faces, estimated_hole_diameters.

Return type:

dict[str, Any]

Parameters:

mesh (Trimesh)

summarise(reports)[source]

Aggregate multiple heal reports into a summary dict.

Return type:

dict[str, Any]

Parameters:

reports (list[HealReport])