Tree — leaf nodes#

Leaves are terminal Node subclasses: they do not wrap other nodes as children. They are where concrete implicit geometry and sources live—analytic primitives, meshes, CAD imports, lattices, extruded profiles, and signed-distance fields.

Nodes that combine or transform subtrees are composition operators; see Tree — composition nodes.

class pyvcad.Function#

A function geometry primitive/leaf node. This is analogous to an F-rep. Functions can be defined in Cartesian, cylindrical, or spherical coordinates.

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(self: pyvcad.pyvcad.Function, function: str, min: pyvcad.pyvcad.Vec3 = <pyvcad.pyvcad.Vec3 object at 0x108faf2b0>, max: pyvcad.pyvcad.Vec3 = <pyvcad.pyvcad.Vec3 object at 0x108fa4f30>) -> None

Constructor that takes a function to evaluate, a material, and bounding box.

Parameters:
  • function (string) – The function expression to evaluate. This can be any math expression, such as x^2 + y^2 + z^2 - 1.

  • min (glm::vec3) – The minimum bounding box coordinates.

  • max (glm::vec3) – The maximum bounding box coordinates.

  1. __init__(self: pyvcad.pyvcad.Function, function: collections.abc.Callable[[typing.SupportsFloat, typing.SupportsFloat, typing.SupportsFloat, typing.SupportsFloat, typing.SupportsFloat, typing.SupportsFloat, typing.SupportsFloat, typing.SupportsFloat], float], min: pyvcad.pyvcad.Vec3 = <pyvcad.pyvcad.Vec3 object at 0x108faeb30>, max: pyvcad.pyvcad.Vec3 = <pyvcad.pyvcad.Vec3 object at 0x108fb6b70>) -> None

Constructor that takes a native python function to evaluate, a material id, and bounding box.

Parameters:
  • function (function<double(double x, double y, double z, double rho, double phic, double r, double theta, double phis)>) – The function to evaluate. This must return the signed distance to the surface. The function must take three parameters (all vec3): xyz, cylindrical coordinates, and spherical coordinates. You may use those to compute the signed distance.

  • min (glm::vec3) – The minimum bounding box coordinates.

  • max (glm::vec3) – The maximum bounding box coordinates.

class pyvcad.Mesh#

A mesh geometry primitive/leaf node. The mesh is loaded from a file and converted into a signed distance field using OpenVDB.

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(self: pyvcad.pyvcad.Mesh, path: str, center: bool = False, disable_validation: bool = False, override_voxel_size: typing.SupportsFloat | None = None, compensate_slicer_ras: bool = False) -> None

Creates a Mesh from a file path.

Parameters:
  • path (string) – The path to the mesh file to load.

  • center (bool) – If true, the mesh will be centered at the origin after loading.

  • disable_validation (bool) – If true, the mesh will not be validated for errors.

  • override_voxel_size (float, optional) – Explicit voxel size to use when voxelizing the mesh into an SDF.

  • compensate_slicer_ras (bool) – If true, mirrors the mesh across Y to compensate for 3D Slicer RAS mesh exports used with DICOMLoader volumes.

Example

>>> import pyvcad as pv
>>> node = pv.Mesh('model.stl', center=True, override_voxel_size=0.1)
  1. __init__(self: pyvcad.pyvcad.Mesh, path: str, sample_size: pyvcad.pyvcad.Vec3, center: bool = False, disable_validation: bool = False, override_voxel_size: typing.SupportsFloat | None = None, compensate_slicer_ras: bool = False) -> None

Creates a Mesh from a file path and sample size.

Parameters:
  • path (string) – The path to the mesh file to load.

  • sample_size (Vec3) – The voxel size to use when voxelizing the mesh into an SDF.

  • center (bool) – If true, the mesh will be centered at the origin after loading.

  • disable_validation (bool) – If true, the mesh will not be validated for errors.

  • override_voxel_size (float, optional) – Explicit voxel size to use when voxelizing the mesh into an SDF. If provided, this takes precedence over sample_size.

  • compensate_slicer_ras (bool) – If true, mirrors the mesh across Y to compensate for 3D Slicer RAS mesh exports used with DICOMLoader volumes.

Example

>>> import pyvcad as pv
>>> node = pv.Mesh('model.stl', pv.Vec3(0.1, 0.1, 0.1), center=True)
  1. __init__(self: pyvcad.pyvcad.Mesh, mesh: pyvcad.pyvcad.SurfaceMesh, center: bool = False, override_voxel_size: typing.SupportsFloat | None = None, compensate_slicer_ras: bool = False) -> None

Creates a Mesh from an existing SurfaceMesh.

Parameters:
  • mesh (SurfaceMesh) – The mesh to load.

  • center (bool) – If true, the mesh will be centered at the origin before voxelization.

  • override_voxel_size (float, optional) – Explicit voxel size to use when voxelizing the mesh into an SDF.

  • compensate_slicer_ras (bool) – If true, mirrors the mesh across Y to compensate for 3D Slicer RAS mesh exports used with DICOMLoader volumes.

Example

>>> import pyvcad as pv
>>> surface = pv.SurfaceMesh('model.stl')
>>> node = pv.Mesh(surface, center=True, override_voxel_size=0.1)
class pyvcad.RectPrism#

A rectangular prism leaf node/geometric primitive. This node is a rectangular prism with a center point, size, and material ID.

static FromMinAndMax(min: pyvcad.pyvcad.Vec3, max: pyvcad.pyvcad.Vec3) pyvcad.pyvcad.RectPrism#

Create a RectPrism from the given minimum and maximum points.

Parameters:
  • min (vec3) – The minimum point of the RectPrism.

  • max (vec3) – The maximum point of the RectPrism.

Returns:

The created RectPrism.

Return type:

RectPrism

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(self: pyvcad.pyvcad.RectPrism) -> None

Default constructor. Creates a RectPrism with a center of (0, 0, 0), size of (1, 1, 1).

  1. __init__(self: pyvcad.pyvcad.RectPrism, center: pyvcad.pyvcad.Vec3, size: pyvcad.pyvcad.Vec3) -> None

Constructor. Creates a RectPrism with a center, size.

Parameters:
  • center (vec3) – The center point of the RectPrism.

  • size (vec3) – The side length of the RectPrism.

class pyvcad.Sphere#

A sphere leaf node/geometric primitive. This node is a sphere with a center point, radius

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(self: pyvcad.pyvcad.Sphere) -> None

Default constructor. Creates a Sphere with a center of (0, 0, 0), radius of 1

Example

>>> from libvcad import pyvcad as pv
>>> sphere = pv.Sphere()
  1. __init__(self: pyvcad.pyvcad.Sphere, center: pyvcad.pyvcad.Vec3, radius: typing.SupportsFloat) -> None

Constructor. Creates a Sphere with a center, radius, and material id.

Parameters:
  • center (vec3) – The center point of the Sphere.

  • radius (double) – The radius of the Sphere.

class pyvcad.Strut#

A leaf node that represents a strut.

__init__(self: pyvcad.pyvcad.Strut, start: pyvcad.pyvcad.Vec3, end: pyvcad.pyvcad.Vec3, radius: SupportsFloat) None#

Constructor. Creates a Strut with a start point, end point, radius.

Parameters:
  • start (vec3) – The start point of the strut.

  • end (vec3) – The end point of the strut.

  • radius (double) – The radius of the strut.

class pyvcad.CAD#

A CAD geometry primitive/leaf node. The CAD is loaded from a file into memory for sampling. The node supports .STEP and .igs files. NOTE: using fast mode will convert the CAD model into a mesh for faster sampling. This hurts acuracy but dramatically speeds up performance. For the Inkjet compiler fast mode is recommended.

__init__(self: pyvcad.pyvcad.CAD, path: str, use_fast_mode: bool = True) None#

Constructor that takes a path to the CAD file to load, whether to use fast mode.

Parameters:
  • path (string) – The path to the CAD file to load.

  • use_fast_mode (bool) – Whether to use fast mode.

class pyvcad.Cylinder#

A cylinder leaf node/ geometric primitive. The cylinder is aligned along the Z-axis, standing upright, and centered at (0,0,0).

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(self: pyvcad.pyvcad.Cylinder) -> None

Default constructor. Creates a Cylinder with a center of (0,0,0), radius of 1, height of 1.

  1. __init__(self: pyvcad.pyvcad.Cylinder, center: pyvcad.pyvcad.Vec3, radius: typing.SupportsFloat, height: typing.SupportsFloat) -> None

Constructor. Creates a Cylinder with a center, radius, height.

Parameters:
  • center (vec3) – The center point of the Cylinder.

  • radius (double) – The radius of the Cylinder.

  • height (double) – The height of the Cylinder.

class pyvcad.Cone#

A cone leaf node/geometric primitive.

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(self: pyvcad.pyvcad.Cone) -> None

Default constructor. Creates a Cone with default dimensions.

  1. __init__(self: pyvcad.pyvcad.Cone, angle: typing.SupportsFloat, height: typing.SupportsFloat) -> None

Constructor. Creates a Cone defined by an angle and height.

Parameters:
  • angle (double) – The aperture half-angle in radians.

  • height (double) – The height of the cone.

class pyvcad.Torus#

A torus leaf node/geometric primitive. This node is a torus with a major and minor radius

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(self: pyvcad.pyvcad.Torus) -> None

Default constructor. Creates a Torus with a center of (0, 0, 0), major radius of 2 and minor radius of 1.

  1. __init__(self: pyvcad.pyvcad.Torus, r1: typing.SupportsFloat, r2: typing.SupportsFloat) -> None

Constructor. Creates a Torus with a major and minor radii.

Parameters:
  • r1 (double) – Major radius.

  • r2 (double) – Minor radius.

class pyvcad.GraphLattice#

A graph lattice leaf node. This class represents a lattice structure defined by a set of edges and a radius for the struts.

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(self: pyvcad.pyvcad.GraphLattice, edges: collections.abc.Sequence[tuple[pyvcad.pyvcad.Vec3, pyvcad.pyvcad.Vec3]], radius: typing.SupportsFloat) -> None

Constructor. Creates a GraphLattice with edges, radius, and material.

Parameters:
  • edges (List[Tuple[Vec3, Vec3]]) – The edges of the lattice.

  • radius (float) – The radius of the struts.

  1. __init__(self: pyvcad.pyvcad.GraphLattice, type: pyvcad.pyvcad.LatticeType, size: pyvcad.pyvcad.Vec3, radius: typing.SupportsFloat) -> None

Constructor. Creates a GraphLattice with a lattice type, size, radius.

Parameters:
  • type (LatticeType) – The type of the lattice (BodyCenteredCubic, FaceCenteredCubic, Cubic, or KelvinCell).

  • size (Vec3) – The size of the lattice unit cell.

  • radius (float) – The radius of the struts.

class pyvcad.Text#

A text leaf node which generates a 3D text object by extruding the text along the Z-axis. The node takes a string, height, depth, material id, font aspect, font name, and alignment options. The CAD part is created from the provided text.

__init__(self: pyvcad.pyvcad.Text, text: str, height: SupportsFloat, depth: SupportsFloat, aspect: pyvcad.pyvcad.FontAspect = <FontAspect.Regular: 0>, font: str = 'Consolas', h_align: pyvcad.pyvcad.HorizontalAlignment = <HorizontalAlignment.Center: 1>, v_align: pyvcad.pyvcad.VerticalAlignment = <VerticalAlignment.Center: 1>) None#

Constructor. Creates a Text node with the provided text content, height, depth, material id, font aspect, font name and alignment options.

Parameters:
  • text (str) – The text content for the 3D text.

  • height (float) – The height of the text.

  • depth (float) – The extrusion depth of the text.

  • aspect (FontAspect, optional) – The font aspect. Defaults to FontAspect.Regular.

  • font (str, optional) – The name of the font to use. Defaults to Consolas.

  • h_align (HorizontalAlignment, optional) – Horizontal alignment of the text. Defaults to Center.

  • v_align (VerticalAlignment, optional) – Vertical alignment of the text. Defaults to Center.

class pyvcad.SignedDistanceField#

Represents a signed distance field using OpenVDB.

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(self: pyvcad.pyvcad.SignedDistanceField) -> None

  2. __init__(self: pyvcad.pyvcad.SignedDistanceField, grid: openvdb::v13_0::Grid<openvdb::v13_0::tree::Tree<openvdb::v13_0::tree::RootNode<openvdb::v13_0::tree::InternalNode<openvdb::v13_0::tree::InternalNode<openvdb::v13_0::tree::LeafNode<float, 3u>, 4u>, 5u>>>>) -> None

  3. __init__(self: pyvcad.pyvcad.SignedDistanceField, occupancy_grid: openvdb::v13_0::Grid<openvdb::v13_0::tree::Tree<openvdb::v13_0::tree::RootNode<openvdb::v13_0::tree::InternalNode<openvdb::v13_0::tree::InternalNode<openvdb::v13_0::tree::LeafNode<bool, 3u>, 4u>, 5u>>>>, half_width_voxels: typing.SupportsInt = 3, closing_steps: typing.SupportsInt = 0, dilation_voxels: typing.SupportsInt = 0, smoothing_steps: typing.SupportsInt = 3) -> None

Create a SignedDistanceField from an OpenVDB BoolGrid occupancy grid.

The topology options are passed to OpenVDB topologyToLevelSet(). They only apply when converting boolean occupancy grids. The defaults preserve OpenVCAD’s existing conversion behavior.

Parameters:
  • occupancy_grid – BoolGrid whose active voxels represent occupied space.

  • half_width_voxels – Half the width of the generated narrow-band level set, in voxel units.

  • closing_steps – Number of morphological closing steps used to fill gaps in the active voxel region.

  • dilation_voxels – Number of voxels to expand the active voxel region before conversion.

  • smoothing_steps – Number of smoothing iterations applied after level-set generation.

  1. __init__(self: pyvcad.pyvcad.SignedDistanceField, vdb_volume: VDBVolume<openvdb::v13_0::Grid<openvdb::v13_0::tree::Tree<openvdb::v13_0::tree::RootNode<openvdb::v13_0::tree::InternalNode<openvdb::v13_0::tree::InternalNode<openvdb::v13_0::tree::LeafNode<float, 3u>, 4u>, 5u>>>>>) -> None

  2. __init__(self: pyvcad.pyvcad.SignedDistanceField, vdb_file_path: str, grid_name: str = ‘occupancy’, half_width_voxels: typing.SupportsInt = 3, closing_steps: typing.SupportsInt = 0, dilation_voxels: typing.SupportsInt = 0, smoothing_steps: typing.SupportsInt = 3) -> None

Create a SignedDistanceField from a VDB file.

The named grid may be either a FloatGrid signed distance field or a BoolGrid occupancy grid. FloatGrid inputs are used directly, and the topology options are ignored. BoolGrid inputs are converted with OpenVDB topologyToLevelSet() using the supplied topology options. The defaults preserve OpenVCAD’s existing conversion behavior.

Parameters:
  • vdb_file_path – Path to the VDB file.

  • grid_name – Name of the grid to load from the file.

  • half_width_voxels – Half the width of the generated narrow-band level set, in voxel units.

  • closing_steps – Number of morphological closing steps used to fill gaps in the active voxel region.

  • dilation_voxels – Number of voxels to expand the active voxel region before conversion.

  • smoothing_steps – Number of smoothing iterations applied after level-set generation.

bounding_box(self: pyvcad.pyvcad.SignedDistanceField) tuple[pyvcad.pyvcad.Vec3, pyvcad.pyvcad.Vec3]#
clone(self: pyvcad.pyvcad.SignedDistanceField) pyvcad.pyvcad.Node#
evaluate(self: pyvcad.pyvcad.SignedDistanceField, x: SupportsFloat, y: SupportsFloat, z: SupportsFloat) float | None#
prepare(self: pyvcad.pyvcad.SignedDistanceField, voxel_size: pyvcad.pyvcad.Vec3, bandwidth: SupportsFloat) None#
save_openvdb_occupancy_grid(self: pyvcad.pyvcad.SignedDistanceField, file_path: str) None#

Save this node as a single OpenVDB BoolGrid named ‘occupancy’. Active SDF voxels with values <= 0 are occupied.

save_openvdb_sdf_grid(self: pyvcad.pyvcad.SignedDistanceField, file_path: str) None#

Save this node as a single OpenVDB FloatGrid named ‘surface’.

class pyvcad.PolygonExtrude#

An extruded polygon leaf node/geometric primitive. Takes a planar polygon defined by 3D vertices and extrudes it along its computed normal (right-hand rule) by a given height.

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(self: pyvcad.pyvcad.PolygonExtrude) -> None

Default constructor. Creates a unit square in the XY plane extruded 1 unit in +Z.

Example

>>> from libvcad import pyvcad as pv
>>> poly = pv.PolygonExtrude()
  1. __init__(self: pyvcad.pyvcad.PolygonExtrude, vertices: collections.abc.Sequence[pyvcad.pyvcad.Vec3], height: typing.SupportsFloat, symmetric: bool = False) -> None

Constructor. Creates an extruded polygon from coplanar 3D vertices.

Parameters:
  • vertices (list[Vec3]) – The vertices of the planar polygon (minimum 3, must be coplanar).

  • height (float) – The extrusion distance along the polygon normal.

  • symmetric (bool) – If True, extrudes height/2 on each side of the polygon plane.

Example

>>> from libvcad import pyvcad as pv
>>> verts = [pv.Vec3(0,0,0), pv.Vec3(10,0,0), pv.Vec3(10,10,0), pv.Vec3(0,10,0)]
>>> poly = pv.PolygonExtrude(verts, 5.0, False)
class pyvcad.Map#

Maps a surface parameterization onto a closed mesh.

__init__(self: pyvcad.pyvcad.Map, surface_path: str, closed_mesh_path: str) None#

Constructor with surface and closed mesh paths.

Parameters:
  • surface_path (str) – Path to the surface file.

  • closed_mesh_path (str) – Path to the closed mesh file.