mascaf.cgal¶
Optional CGAL-backed native preprocessing for MASCAF.
Provides Python wrappers around three compiled C++ executables:
mesh_repair— attempt to produce a watertight mesh.mesh_simplify— reduce mesh face count.mesh_skeletonize— extract a mean-curvature skeleton as a polylines file.
The executables are built separately from the cpp/ directory using CMake
and vcpkg. See Skeletonization for setup instructions.
Classes¶
- CGALConfig
Locate executables and configure CMake.
- CGALBuilder
Run CMake configure/build and discover executables.
- CGALOperator
High-level Python methods for each CGAL operation.
- CGALCommandResult
Immutable record of a completed CGAL subprocess invocation.
- exception mascaf.cgal.CGALError[source]¶
Bases:
RuntimeErrorBase exception for all CGAL integration errors.
- exception mascaf.cgal.CGALBuildError[source]¶
Bases:
CGALErrorRaised when a CMake configure or build step fails.
- class mascaf.cgal.CGALCommandResult(operation, command, input_path, output_path, stdout, stderr, returncode)[source]¶
Bases:
objectImmutable record of a completed CGAL executable invocation.
- Parameters:
- command¶
Full command line that was executed.
- Type:
tuple[str,]
- input_path¶
Path to the input file passed to the executable.
- Type:
Path
- output_path¶
Path to the output file produced by the executable.
- Type:
Path
- class mascaf.cgal.CGALConfig(cpp_dir=<factory>, executable_dir=None, build_dir=None, cmake_executable='cmake', vcpkg_toolchain_file=None, build_configs=('Release', 'Debug', 'RelWithDebInfo', 'MinSizeRel'), executable_suffix='')[source]¶
Bases:
objectConfiguration for locating and invoking CGAL executables and CMake.
- Parameters:
- cpp_dir¶
Root of the native C++ source tree (default:
<repo>/cpp/).- Type:
Path
- executable_dir¶
Explicit directory to search first for compiled executables. If
None, the search falls back to build subdirectories and theMASCAF_CGAL_BIN_DIRenvironment variable.- Type:
PathorNone
- build_dir¶
CMake build directory. If
None, resolved fromMASCAF_CGAL_BUILD_DIRor<cpp_dir>/build.- Type:
PathorNone
- vcpkg_toolchain_file¶
Path to the vcpkg CMake toolchain file. Auto-detected from
VCPKG_ROOTif not set.- Type:
PathorNone
- build_configs¶
CMake build configurations to search when looking for executables (default: Release, Debug, RelWithDebInfo, MinSizeRel).
- Type:
tuple[str,]
- executable_suffix¶
Platform-specific suffix appended to executable names (
".exe"on Windows,""elsewhere).- Type:
- classmethod from_overrides(*, cpp_dir=None, executable_dir=None, build_dir=None, cmake_executable='cmake', vcpkg_toolchain_file=None)[source]¶
Construct a
CGALConfigfrom optional keyword overrides.Any argument left as
Nonefalls back to the class default. This is the preferred factory when building a config from CLI arguments or environment variables.
- default_build_dir()[source]¶
Return the effective CMake build directory.
Priority order:
build_dirset on this config instance.MASCAF_CGAL_BUILD_DIRenvironment variable.<cpp_dir>/build(fallback).
- Return type:
- __init__(cpp_dir=<factory>, executable_dir=None, build_dir=None, cmake_executable='cmake', vcpkg_toolchain_file=None, build_configs=('Release', 'Debug', 'RelWithDebInfo', 'MinSizeRel'), executable_suffix='')¶
- class mascaf.cgal.CGALBuilder(config=None, **config_kwargs)[source]¶
Bases:
objectHandles CMake configure/build orchestration and executable discovery.
CGALBuilderknows how to:Construct the
cmakeconfigure and build commands from aCGALConfig.Search a prioritised list of directories for compiled CGAL executables.
Run subprocesses and surface errors cleanly.
- Parameters:
config (
CGALConfig|None) – Configuration to use. IfNone, a defaultCGALConfigis constructed, optionally accepting extra keyword arguments that are forwarded toCGALConfig.from_overrides().**config_kwargs – Forwarded to
CGALConfig.from_overrides()whenconfigisNone.
- __init__(config=None, **config_kwargs)[source]¶
- Parameters:
config (CGALConfig | None)
- Return type:
None
- executable_filename(operation)[source]¶
Return the platform-appropriate filename for a CGAL executable.
- candidate_build_dirs()[source]¶
Return an ordered list of directories likely to contain build output.
Includes the build root itself plus each configured build-type subdirectory (e.g.
build/Release).
- candidate_executable_dirs()[source]¶
Return a deduplicated, priority-ordered list of directories to search for CGAL executables.
Priority order:
CGALConfig.executable_dir(if set).MASCAF_CGAL_BIN_DIRenvironment variable (if set).Each candidate build directory from
candidate_build_dirs().CGALConfig.cpp_diritself.
- resolve_executable(operation)[source]¶
Locate the compiled executable for operation.
- Parameters:
operation (
str) – Base name of the operation (e.g."mesh_skeletonize").- Returns:
Absolute path to the first matching executable found.
- Return type:
- Raises:
CGALExecutableNotFoundError – If the executable is not found in any candidate directory.
- configure_command(*, build_dir=None, build_type='Release', generator=None)[source]¶
Build the
cmakeconfigure command without running it.- Parameters:
- Returns:
The full command as a list of strings, suitable for
subprocess.run().- Return type:
- build_command(*, build_dir=None, config='Release', target=None)[source]¶
Build the
cmake --buildcommand without running it.
- run_configure(*, build_dir=None, build_type='Release', generator=None, check=True)[source]¶
Run the CMake configure step.
- Parameters:
- Returns:
The completed process record.
- Return type:
- exception mascaf.cgal.CGALExecutableNotFoundError[source]¶
Bases:
CGALErrorRaised when a required CGAL executable cannot be located.
- mascaf.cgal.CGALMeshProcessor¶
alias of
CGALOperator
- class mascaf.cgal.CGALOperator(config=None, builder=None, **config_kwargs)[source]¶
Bases:
objectHigh-level interface for running CGAL mesh operations.
CGALOperatorwraps the three native CGAL executables (mesh_repair,mesh_simplify,mesh_skeletonize) and exposes them as Python methods. Each method resolves the executable, assembles the argument list, runs the process, and returns aCGALCommandResult.- Parameters:
config (
CGALConfig|None) – Configuration used to locate executables and set up CMake. IfNone, a default config is constructed.builder (
CGALBuilder|None) – Provide a pre-builtCGALBuilderinstead of constructing one from config.**config_kwargs – Forwarded to
CGALConfig.from_overrides()when neither config nor builder is supplied.
- __init__(config=None, builder=None, **config_kwargs)[source]¶
- Parameters:
config (CGALConfig | None)
builder (CGALBuilder | None)
- Return type:
None
- repair(input_path, output_path)[source]¶
Run CGAL mesh repair on input_path, writing result to output_path.
Mesh repair fills holes and attempts to produce a valid, watertight triangle mesh suitable for skeletonization.
- Parameters:
- Returns:
Record of the completed operation.
- Return type:
- simplify(input_path, output_path, target)[source]¶
Run CGAL mesh simplification on input_path.
- Parameters:
- Returns:
Record of the completed operation.
- Return type:
- Raises:
ValueError – If target is not a positive number.
- skeletonize(input_path, output_path, quality_speed_tradeoff=0.5, medially_centered_speed_tradeoff=5.0)[source]¶
Run CGAL mean-curvature skeleton extraction on input_path.
The output is a
.polylines.txtfile compatible withmascaf.SkeletonGraph.from_txt().- Parameters:
input_path (
str|Path) – Path to the input mesh file (must be a closed triangle mesh).output_path (
str|Path) – Path where the skeleton polylines file will be written.quality_speed_tradeoff (
float) – CGALquality_speed_tradeoffparameter (w_H). Controls the quality–speed balance; higher values favour quality. Default:0.5.medially_centered_speed_tradeoff (
float) – CGALmedially_centered_speed_tradeoffparameter (w_M). Higher values push the skeleton toward the medial axis. Default:5.0.
- Returns:
Record of the completed operation.
- Return type: