Quickstart¶
End-to-end workflow¶
Prepare a mesh — Start from a closed triangle mesh.
Generate or obtain a skeleton — See Skeletonization for options.
Load inputs — Load the mesh with
MeshManagerand the skeleton withfrom_txt().Fit a morphology graph — Use
CableFitterwithFitOptions.Optionally optimize the morphology basis — Configure
BasisOptimizerOptionsviaFitOptions.basis_optimizer_options.Validate and export — Inspect results, optionally scale radii, and export to SWC.
Full example¶
from mascaf import (
BasisOptimizerOptions,
CableFitter,
FitOptions,
MeshManager,
SkeletonGraph,
)
mesh_mgr = MeshManager(mesh_path="neuron.obj")
skeleton = SkeletonGraph.from_txt("neuron.polylines.txt")
fit_options = FitOptions(
max_edge_length=1.0,
radius_strategy="equivalent_area",
basis_optimizer_options=BasisOptimizerOptions(
do_snapping=True,
do_forcing=True,
max_iterations=50,
smoothing_weight=0.5,
),
)
fitter = CableFitter(fit_options)
morphology = fitter.fit(mesh_mgr, skeleton)
morphology.scale_radii_to_match_mesh(mesh_mgr, metric="surface_area")
morphology.to_swc_file("neuron.swc")
Minimal example¶
If you already have a skeleton and do not want basis optimization:
from mascaf import CableFitter, FitOptions, MeshManager, SkeletonGraph
mesh_mgr = MeshManager(mesh_path="shape.obj")
skel = SkeletonGraph.from_txt("shape.polylines.txt")
fitter = CableFitter(FitOptions(max_edge_length=0.5))
morph = fitter.fit(mesh_mgr, skel)
morph.to_swc_file("shape.swc")
Radius strategies¶
Supported values for FitOptions.radius_strategy:
equivalent_area(recommended) —r = sqrt(A/π)from cross-section area.equivalent_perimeter—r = L/(2π)from boundary length.section_median— median ray-to-boundary distance in the section plane.section_circle_fit— algebraic circle fit (Kasa) to the section boundary.nearest_surface— distance from sample point to nearest mesh surface.