pyvcad Module

class pyvcad.Arrangement2

Bases: pybind11_object

A class representing a 2D arrangement of polygons and polylines. When polygons and polylines are inserted into the arrangement, they are split by each other and the resulting faces are stored in the arrangement.

__init__(self: pyvcad.pyvcad.Arrangement2) None

Default constructor. Creates an Arrangement2 object.

getBoundedFaces(self: pyvcad.pyvcad.Arrangement2) list[pyvcad.pyvcad.Polygon2]

Returns a list of all bounded faces in the arrangement.

getUnboundedFaces(self: pyvcad.pyvcad.Arrangement2) list[pyvcad.pyvcad.Polygon2]

Returns a list of all unbounded faces in the arrangement.

insert(*args, **kwargs)

Overloaded function.

  1. insert(self: pyvcad.pyvcad.Arrangement2, polygon: pyvcad.pyvcad.Polygon2) -> None

Inserts a Polygon2 into the arrangement.

Parameters:

polygon (Polygon2) – The polygon to insert.

  1. insert(self: pyvcad.pyvcad.Arrangement2, polyline: pyvcad.pyvcad.Polyline2) -> None

Inserts a Polyline2 into the arrangement.

Parameters:

polyline (Polyline2) – The polyline to insert.

class pyvcad.BBoxUnion

Bases: NAry

An n-ary node that represents the union of bounding boxes.

__init__(*args, **kwargs)

Overloaded function.

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

Default constructor for BBoxUnion.

Example

>>> union_node = pv.BBoxUnion()
  1. __init__(self: pyvcad.pyvcad.BBoxUnion, children: list[pyvcad.pyvcad.Node]) -> None

Constructor that creates a BBoxUnion node with the given list of child nodes.

Parameters:

children (list of Node) – The list of child nodes.

Example

>>> children = [child1, child2]
>>> union_node = pv.BBoxUnion(children)
class pyvcad.Binary

Bases: Node

A binary node with exactly two children. The children can be added via a constructor or via set_left() and set_right() methods. Children can be queried with left() and right().

__init__(*args, **kwargs)
left(self: pyvcad.pyvcad.Binary) pyvcad.pyvcad.Node

Returns the left child of this node.

right(self: pyvcad.pyvcad.Binary) pyvcad.pyvcad.Node

Returns the right child of this node.

set_left(self: pyvcad.pyvcad.Binary, left: pyvcad.pyvcad.Node) None

Sets the left child of this node.

Parameters:

left (Node) – The left child to set for this node.

set_right(self: pyvcad.pyvcad.Binary, right: pyvcad.pyvcad.Node) None

Sets the right child of this node.

Parameters:

right (Node) – The right child to set for this node.

class pyvcad.Blend

Bases: Unary

A node that blends the material distributions of its child node over a specified radius.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pyvcad.pyvcad.Blend, radius: float) -> None

Constructor. Creates a Blend with a specified radius.

Parameters:

radius (double) – The radius over which to blend the material distributions.

  1. __init__(self: pyvcad.pyvcad.Blend, radius: float, child: pyvcad.pyvcad.Node) -> None

Constructor. Creates a Blend with a specified radius and a child node.

Parameters:
  • radius (double) – The radius over which to blend the material distributions.

  • child (Node) – The child node.

class pyvcad.CAD

Bases: Leaf

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, material: int = 1) None

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

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

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

  • material (uint8_t) – The material of the CAD.

Example

>>> from libvcad import pyvcad as pv
>>> cad = pv.CAD('path/to/cadfile.step', True, 1)
class pyvcad.Convolution

Bases: Unary

A node that applies a discrete convolution to its child node. This can be used with a kernel to apply a filter to design. This include blurring, sharpening, edge detection, and more. See the paper(https://doi.org/10.1016/j.addma.2023.103912) for details.

static BlendKernel(x: int, y: int, z: int) list[list[list[int]]]

Creates a kernel that averages all values (blends). This means all values are one, including the center value.

Parameters:
  • x (int) – The x dimension of the kernel.

  • y (int) – The y dimension of the kernel.

  • z (int) – The z dimension of the kernel.

static PassKernel(x: int, y: int, z: int) list[list[list[int]]]

Creates a kernel that passes all values through. This means all values are zero except for the center value which is one.

Parameters:
  • x (int) – The x dimension of the kernel.

  • y (int) – The y dimension of the kernel.

  • z (int) – The z dimension of the kernel.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pyvcad.pyvcad.Convolution, kernel: list[list[list[int]]]) -> None

Constructor. Creates a Convolution with a kernel.

Parameters:

kernel (Convolution::Kernel) – The convolution kernel, a 3D matrix of integers. The kernel must be odd in all dimensions.

  1. __init__(self: pyvcad.pyvcad.Convolution, kernel: list[list[list[int]]], child: pyvcad.pyvcad.Node) -> None

Constructor. Creates a Convolution with a kernel and a child node.

Parameters:
  • kernel (Convolution::Kernel) – The convolution kernel, a 3D matrix of integers. The kernel must be odd in all dimensions.

  • child (Node) – The child node.

class pyvcad.Cylinder

Bases: Leaf

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, and material id of 1.

Example

>>> from libvcad import pyvcad as pv
>>> cylinder = pv.Cylinder()
  1. __init__(self: pyvcad.pyvcad.Cylinder, center: pyvcad.pyvcad.Vec3, radius: float, height: float, material: int = 1) -> None

Constructor. Creates a Cylinder with a center, radius, height, and material id.

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

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

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

  • material (uint8_t) – The material id of the Cylinder.

Example

>>> from libvcad import pyvcad as pv
>>> center = pv.vec3(0, 0, 0)
>>> cylinder = pv.Cylinder(center, 2, 5, 1)
class pyvcad.Difference

Bases: Binary

A difference binary node. The difference is taken as the left child minus the right child. This node is binary, so it can have two children.

__init__(*args, **kwargs)

Overloaded function.

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

Default constructor. Creates a Difference node.

Example

>>> from libvcad import pyvcad as pv
>>> radius = 5
>>> left_sphere = pv.Sphere(pv.Vec3(-radius/2, 0, 0), radius, 1)
>>> right_sphere = pv.Sphere(pv.Vec3(radius/2, 0, 0), radius, 1)
>>> difference = pv.Difference()
>>> difference.set_left(left_sphere)
>>> difference.set_right(right_sphere)
  1. __init__(self: pyvcad.pyvcad.Difference, left: pyvcad.pyvcad.Node, right: pyvcad.pyvcad.Node) -> None

Constructor. Creates a Difference node with the given left and right children.

Parameters:
  • left (std::shared_ptr<Node>) – The left child node.

  • right (std::shared_ptr<Node>) – The right child node.

Example

>>> from libvcad import pyvcad as pv
>>> radius = 5
>>> left_sphere = pv.Sphere(pv.Vec3(-radius/2, 0, 0), radius, 1)
>>> right_sphere = pv.Sphere(pv.Vec3(radius/2, 0, 0), radius, 1)
>>> difference = pv.Difference(left_sphere, right_sphere)
class pyvcad.FGrade

Bases: Unary

A node that applies grading functions to a child. The grading functions are probability density functions that must all sum to 1 for any given point. The functions are evaluated, and the material is chosen based on the discrete probability of the location in space. The syntax for the expressions must follow the same format as the Function class. The node has two modes: Probability mode and Threshold mode. This node is unary and must have a single child. It runs in O(n) time, where n is tokens in the longest expression.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pyvcad.pyvcad.FGrade, functions: list[str], materials: list[int], prob_mode: bool) -> None

Constructor. Creates a FGrade with a list of expressions, corresponding materials, and a mode.

Parameters:
  • functions (std::vector<std::string>) – A list of expressions that are probability density functions.

  • materials (std::vector<uint8_t>) – A list of materials that correspond to the expressions.

  • prob_mode (bool) – If true, the node runs in probability mode. If false, the node runs in threshold mode.

Example

>>> import pyvcad as pv
>>> materials = pv.MaterialDefs('configs/default.json')
>>> bar = pv.RectPrism(pv.Vec3(0,0,0), pv.Vec3(100,50,10), materials.id('gray'))
>>> root = pv.FGrade(['x/100 + 0.5', '-x/100 + 0.5'], [materials.id('red'), materials.id('blue')], False)
>>> root.set_child(bar)
  1. __init__(self: pyvcad.pyvcad.FGrade, functions: list[str], materials: list[int], prob_mode: bool, child: pyvcad.pyvcad.Node) -> None

Constructor. Creates a FGrade with a list of expressions, corresponding materials, a mode, and a child node.

Parameters:
  • functions (std::vector<std::string>) – A list of expressions that are probability density functions.

  • materials (std::vector<uint8_t>) – A list of materials that correspond to the expressions.

  • prob_mode (bool) – If true, the node runs in probability mode. If false, the node runs in threshold mode.

  • child (Node) – The child node.

Example

>>> import pyvcad as pv
>>> materials = pv.MaterialDefs('configs/default.json')
>>> bar = pv.RectPrism(pv.Vec3(0,0,0), pv.Vec3(100,50,10), materials.id('gray'))
>>> root = pv.FGrade(['x/100 + 0.5', '-x/100 + 0.5'], [materials.id('red'), materials.id('blue')], False, bar)
  1. __init__(self: pyvcad.pyvcad.FGrade, functions: list[Callable[[float, float, float, float, float, float, float, float, float], float]], materials: list[int], prob_mode: bool) -> None

Constructor. Creates a FGrade with a list of lambda functions, corresponding materials, and a mode.

Parameters:
  • functions (std::vector<std::function<double(double x, double y, double z, double rho, double phic, double r, double theta, double phis)>>) – A list of lambda functions that are volume fraction functions. They should all sum to one for any location in space. The functions must each take three parameters (all vec3): xyz, cylindrical coordinates, and spherical coordinates.

  • materials (std::vector<uint8_t>) – A list of materials that correspond to the functions.

  • prob_mode (bool) – If true, the node runs in probability mode. If false, the node runs in threshold mode.

Example

>>> import pyvcad as pv
>>> materials = pv.MaterialDefs('configs/default.json')
>>> bar = pv.RectPrism(pv.Vec3(0,0,0), pv.Vec3(100,50,10), materials.id('gray'))
>>> def func_a(x, y, z, rho, phic, r, theta, phis):
...     return x/100 + 0.5
>>> def func_b(x, y, z, rho, phic, r, theta, phis):
...     return -x/100 + 0.5
>>> root = pv.FGrade([func_a, func_b], [materials.id('red'), materials.id('blue')], False)
>>> root.set_child(bar)
  1. __init__(self: pyvcad.pyvcad.FGrade, functions: list[Callable[[float, float, float, float, float, float, float, float, float], float]], materials: list[int], prob_mode: bool, child: pyvcad.pyvcad.Node) -> None

Constructor. Creates a FGrade with a list of lambda functions, corresponding materials, a mode, and a child node.

Parameters:
  • functions (List<function<double(double x, double y, double z, double rho, double phic, double r, double theta, double phis)>>) – A list of lambda functions that are volume fraction functions. They should all sum to one for any location in space. The functions must each take parameters: xyz, cylindrical coordinates, and spherical coordinates.

  • materials (List<uint8_t>) – A list of materials that correspond to the functions.

  • prob_mode (bool) – If true, the node runs in probability mode. If false, the node runs in threshold mode.

  • child (Node) – The child node.

Example

>>> import pyvcad as pv
>>> materials = pv.MaterialDefs('configs/default.json')
>>> bar = pv.RectPrism(pv.Vec3(0,0,0), pv.Vec3(100,50,10), materials.id('gray'))
>>> def func_a(x, y, z, rho, phic, r, theta, phis, d):
...     return x/100 + 0.5
>>> def func_b(x, y, z, rho, phic, r, theta, phis, d):
...     return -x/100 + 0.5
>>> root = pv.FGrade([func_a, func_b], [materials.id('red'), materials.id('blue')], False, bar)
class pyvcad.FontAspect

Bases: pybind11_object

Specifies the font aspect for the text node

Members:

Regular : Regular font

Bold : Bold font

Italic : Italic font

BoldItalic : Bold and italic font

Bold = <FontAspect.Bold: 1>
BoldItalic = <FontAspect.BoldItalic: 3>
Italic = <FontAspect.Italic: 2>
Regular = <FontAspect.Regular: 0>
__init__(self: pyvcad.pyvcad.FontAspect, value: int) None
property name
property value
class pyvcad.Function

Bases: Leaf

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, material: int = 1, min: pyvcad.pyvcad.Vec3 = <pyvcad.pyvcad.Vec3 object at 0x0000021BD7E23570>, max: pyvcad.pyvcad.Vec3 = <pyvcad.pyvcad.Vec3 object at 0x0000021BD7E23530>) -> 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.

  • material (uint8_t) – The material for the function.

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

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

Example

>>> from libvcad import pyvcad as pv
>>> function = pv.Function('x^2 + y^2 + z^2 - 1', 1, pv.vec3(-10.0, -10.0, -10.0), pv.vec3(10.0, 10.0, 10.0))
  1. __init__(self: pyvcad.pyvcad.Function, function: Callable[[float, float, float, float, float, float, float, float], float], material: int = 1, min: pyvcad.pyvcad.Vec3 = <pyvcad.pyvcad.Vec3 object at 0x0000021BD7E23730>, max: pyvcad.pyvcad.Vec3 = <pyvcad.pyvcad.Vec3 object at 0x0000021BD7E1B6B0>) -> 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.

  • material (uint8_t) – The material for the function.

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

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

Example

>>> from libvcad import pyvcad as pv
>>> def my_function(x, y, z, rho, phic, r, theta, phis):
>>>     return x**2 + y**2 + z**2 - 1
>>> function = pv.Function(my_function, 1, pv.vec3(-10.0, -10.0, -10.0), pv.vec3(10.0, 10.0, 10.0))
class pyvcad.GraphLattice

Bases: Leaf

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: list[tuple[pyvcad.pyvcad.Vec3, pyvcad.pyvcad.Vec3]], radius: float, material: int) -> 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.

  • material (uint8_t) – The material ID of the lattice.

Example

>>> from libvcad import pyvcad as pv
>>> edges = [(pv.vec3(0, 0, 0), pv.vec3(1, 1, 1))]
>>> graph_lattice = pv.GraphLattice(edges, 0.5, 1)
  1. __init__(self: pyvcad.pyvcad.GraphLattice, type: pyvcad.pyvcad.LatticeType, size: pyvcad.pyvcad.Vec3, radius: float, material: int) -> None

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

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.

  • material (uint8_t) – The material ID of the lattice.

Example

>>> from libvcad import pyvcad as pv
>>> size = pv.vec3(1, 1, 1)
>>> graph_lattice = pv.GraphLattice(pv.LatticeType.BodyCenteredCubic, size, 0.5, 1)
class pyvcad.HexahedralMesh

Bases: pybind11_object

Class representing a hexahedral mesh.

__init__(self: pyvcad.pyvcad.HexahedralMesh, node: pyvcad.pyvcad.Node, x_vox: int, y_vox: int, z_vox: int) None

Constructor that takes a root node and voxel counts.

bounding_box(self: pyvcad.pyvcad.HexahedralMesh) tuple[pyvcad.pyvcad.Vec3, pyvcad.pyvcad.Vec3]

Returns the mesh bounding box.

compute(self: pyvcad.pyvcad.HexahedralMesh) None

Computes the hexahedral mesh based on the root node and voxel counts.

elements(self: pyvcad.pyvcad.HexahedralMesh) list[tuple[int, int, int, int, int, int, int, int]]

Returns the mesh elements.

material_assignments(self: pyvcad.pyvcad.HexahedralMesh) dict[int, list[int]]

Returns the material assignments.

nodes(self: pyvcad.pyvcad.HexahedralMesh) list[pyvcad.pyvcad.Vec3]

Returns the mesh nodes.

class pyvcad.HorizontalAlignment

Bases: pybind11_object

Defines the horizontal position of text relative to its anchor point

Members:

Left : Text is aligned to the left of the anchor point

Center : Text is centered horizontally at the anchor point

Right : Text is aligned to the right of the anchor point

Center = <HorizontalAlignment.Center: 1>
Left = <HorizontalAlignment.Left: 0>
Right = <HorizontalAlignment.Right: 2>
__init__(self: pyvcad.pyvcad.HorizontalAlignment, value: int) None
property name
property value
class pyvcad.Intersection

Bases: NAry

Intersection of two or more nodes. This node is N-ary, so it can have multiple children.

__init__(*args, **kwargs)

Overloaded function.

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

Default constructor. Creates an Intersection node.

Example

>>> from libvcad import pyvcad as pv
>>> radius = 5
>>> sphere1 = pv.Sphere(pv.Vec3(-radius/2, 0, 0), radius, 1)
>>> sphere2 = pv.Sphere(pv.Vec3(radius/2, 0, 0), radius, 1)
>>> intersection = pv.Intersection()
>>> intersection.add_child(sphere1)
>>> intersection.add_child(sphere2)
  1. __init__(self: pyvcad.pyvcad.Intersection, intersect_distribution: bool) -> None

Constructor. Creates an Intersection node with the option to intersect the distribution.

Parameters:

intersect_distribution (bool) – If true, the distribution will be intersected. If false, the distribution will be summed.

Example

>>> from libvcad import pyvcad as pv
>>> radius = 5
>>> sphere1 = pv.Sphere(pv.Vec3(-radius/2, 0, 0), radius, 1)
>>> sphere2 = pv.Sphere(pv.Vec3(radius/2, 0, 0), radius, 1)
>>> intersection = pv.Intersection(True)
>>> intersection.add_child(sphere1)
>>> intersection.add_child(sphere2)
  1. __init__(self: pyvcad.pyvcad.Intersection, intersect_distribution: bool, children: list[pyvcad.pyvcad.Node]) -> None

Constructor. Creates an Intersection node with the option to intersect the distribution and sets the children.

Parameters:
  • intersect_distribution (bool) – If true, the distribution will be intersected. If false, the distribution will be summed.

  • children (std::vector<std::shared_ptr<Node>>) – The children nodes.

Example

>>> from libvcad import pyvcad as pv
>>> radius = 5
>>> sphere1 = pv.Sphere(pv.Vec3(-radius/2, 0, 0), radius, 1)
>>> sphere2 = pv.Sphere(pv.Vec3(radius/2, 0, 0), radius, 1)
>>> intersection = pv.Intersection(True, [sphere1, sphere2])
class pyvcad.LatticeType

Bases: pybind11_object

Enumeration of lattice types.

Members:

BodyCenteredCubic : Body Centered Cubic lattice type.

FaceCenteredCubic : Face Centered Cubic lattice type.

Cubic : Cubic lattice type.

KelvinCell : Kelvin Cell lattice type.

BodyCenteredCubic = <LatticeType.BodyCenteredCubic: 0>
Cubic = <LatticeType.Cubic: 2>
FaceCenteredCubic = <LatticeType.FaceCenteredCubic: 1>
KelvinCell = <LatticeType.KelvinCell: 3>
__init__(self: pyvcad.pyvcad.LatticeType, value: int) None
property name
property value
class pyvcad.Leaf

Bases: Node

A leaf node that cannot have any children.

__init__(*args, **kwargs)
class pyvcad.MaterialDefs

Bases: pybind11_object

Class representing material definitions that translates between material names, colors, and ids.

__init__(self: pyvcad.pyvcad.MaterialDefs, arg0: str) None

Constructor that takes a string as the path to the material configuration file.

color(*args, **kwargs)

Overloaded function.

  1. color(self: pyvcad.pyvcad.MaterialDefs, arg0: int) -> pyvcad.pyvcad.Vec4

Returns the color of the material given the id.

  1. color(self: pyvcad.pyvcad.MaterialDefs, arg0: str) -> pyvcad.pyvcad.Vec4

Returns the color of the material given the name.

contains(self: pyvcad.pyvcad.MaterialDefs, arg0: str) bool

Returns true if the material exists given the name.

id(*args, **kwargs)

Overloaded function.

  1. id(self: pyvcad.pyvcad.MaterialDefs, arg0: str) -> int

Returns the id of the material given the name.

  1. id(self: pyvcad.pyvcad.MaterialDefs, arg0: pyvcad.pyvcad.Vec4) -> int

Returns the id of the material given the color.

name(self: pyvcad.pyvcad.MaterialDefs, arg0: int) str

Returns the name of the material given the id.

num_materials(self: pyvcad.pyvcad.MaterialDefs) int

Returns the number of materials.

palette(self: pyvcad.pyvcad.MaterialDefs) list[pyvcad.pyvcad.Vec4]

Returns a list of colors that are in the floating point range [0, 1]. The list contains 4-component colors (RGBA).

prescaled_color_list(self: pyvcad.pyvcad.MaterialDefs) list[pyvcad.pyvcad.Vec4]

Returns a list of colors that are prescaled to the range [0, 255]. The list contains 4-component colors (RGBA).

update_color(self: pyvcad.pyvcad.MaterialDefs, arg0: int, arg1: pyvcad.pyvcad.Vec4) None

Updates the color of the material given the id. The new color of the material is specified as a 4-component color (RGBA).

class pyvcad.Mesh

Bases: Leaf

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

__init__(self: pyvcad.pyvcad.Mesh, path: str, material: int = 1, disable_validation: bool = False) None

Constructor. Creates a Mesh with a file path and material.

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

  • material – The material of the mesh.

Example

>>> from libvcad import pyvcad as pv
>>> mesh = pv.Mesh('path/to/meshfile.obj', 1)
class pyvcad.NAry

Bases: Node

A node with an arbitrary number of children.

__init__(*args, **kwargs)
add_child(self: pyvcad.pyvcad.NAry, child: pyvcad.pyvcad.Node) bool

Tries to add a child to the node. If the node is full, it returns false.

Parameters:

child (Node) – The child to add to the node.

child(self: pyvcad.pyvcad.NAry, index: int) pyvcad.pyvcad.Node

Returns the child at the given index.

Parameters:

index (uint8_t) – The index of the child to return.

Returns:

The child at the given index.

Return type:

Node

children(self: pyvcad.pyvcad.NAry) list[pyvcad.pyvcad.Node]

Returns the list of children for this node.

num_children(self: pyvcad.pyvcad.NAry) int

Returns the number of children this node has.

class pyvcad.Node

Bases: pybind11_object

Base class for all nodes in the tree. NOTE: the VCAD tree is NOT thread-safe. You must use a separate tree for each thread (see Node.clone()).

__init__(*args, **kwargs)
bounding_box(self: pyvcad.pyvcad.Node) tuple[pyvcad.pyvcad.Vec3, pyvcad.pyvcad.Vec3]

Returns the bounding box of the node as a pair of min and max points.

Example

>>> from libvcad import pyvcad as pv
>>> sphere = pv.Sphere(pv.Vec3(0,0,0), 2, 2)
>>> min, max = sphere.bounding_box() # Will return (Vec3(-2, -2, -2), Vec3(2, 2, 2))
clone(self: pyvcad.pyvcad.Node) pyvcad.pyvcad.Node

Clones the node and returns a pointer to the new node.

Example

>>> from libvcad import pyvcad as pv
>>> sphere = pv.Sphere()
>>> cloned_sphere = sphere.clone()
distribution(self: pyvcad.pyvcad.Node, x: float, y: float, z: float) dict[int, float]

Returns the material distribution at the given point. Returns a list of pairs, each containing the material ID and the probability distribution of that material.

Parameters:
  • x (double) – The x-coordinate of the point to evaluate.

  • y (double) – The y-coordinate of the point to evaluate.

  • z (double) – The z-coordinate of the point to evaluate.

Example

>>> from libvcad import pyvcad as pv
>>> sphere = pv.Sphere(pv.Vec3(0,0,0), 2, 2)
>>> distribution = sphere.distribution(0, 0, 0) # Since there is a single material, will return [2, 1.0], meaning 100% material 2
distribution_gradient(self: pyvcad.pyvcad.Node, x: float, y: float, z: float, delta: float = 1) dict[int, pyvcad.pyvcad.Vec3]

Returns the material distribution gradient at the given point using the central difference method. Returns a list of pairs, each containing the material ID and the gradient of the probability distribution of that material.

Parameters:
  • x (double) – The x-coordinate of the point to evaluate.

  • y (double) – The y-coordinate of the point to evaluate.

  • z (double) – The z-coordinate of the point to evaluate.

  • delta (double) – The distance to use for the central difference method.

Example

>>> from libvcad import pyvcad as pv
>>> sphere = pv.Sphere(pv.Vec3(0,0,0), 2, 2)
>>> gradient = sphere.distribution_gradient(0, 0, 0, 1) # There is not a material gradient, so this returns 0
evaluate(self: pyvcad.pyvcad.Node, x: float, y: float, z: float) float

Evaluates the node at the given point. Returns the distance to the surface at the given point.

Parameters:
  • x (double) – The x-coordinate of the point to evaluate.

  • y (double) – The y-coordinate of the point to evaluate.

  • z (double) – The z-coordinate of the point to evaluate.

Example

>>> from libvcad import pyvcad as pv
>>> sphere = pv.Sphere(pv.Vec3(0,0,0), 2, 2)
>>> distance = sphere.evaluate(0, 0, 0) # Signed distance from center is -2
heterogeneity(self: pyvcad.pyvcad.Node, x: float, y: float, z: float) float

Returns a number on the range [0, 1] that represents the heterogeneity of the material distribution at the given point. A value of 0 means that the material distribution is homogeneous (composed completely of a single channel), while a value of 1 means that the material distribution is heterogeneous (even distribution across all channels).

Parameters:
  • x (double) – The x-coordinate of the point to evaluate.

  • y (double) – The y-coordinate of the point to evaluate.

  • z (double) – The z-coordinate of the point to evaluate.

Example

>>> from libvcad import pyvcad as pv
>>> sphere = pv.Sphere(pv.Vec3(0,0,0), 2, 2)
>>> heterogeneity = sphere.heterogeneity(0, 0, 0) # Will return 0 because there is only a single material
material_list(self: pyvcad.pyvcad.Node) list[int]

Returns a list of all the materials used by the node and its children.

Example

>>> from libvcad import pyvcad as pv
>>> sphere = pv.Sphere(pv.Vec3(0,0,0), 2, 2)
>>> materials = sphere.material_list() # Will return [2] as the only material
prepare(self: pyvcad.pyvcad.Node, voxel_size: pyvcad.pyvcad.Vec3, interior_bandwidth: float, exterior_bandwidth: float) None

Performs any single-run operations that need to be done before the tree is evaluated.

Parameters:
  • voxel_size (vec3) – The size of the voxels.

  • interior_bandwidth (double) – The interior bandwidth.

  • exterior_bandwidth (double) – The exterior bandwidth.

Example

>>> from libvcad import pyvcad as pv
>>> sphere = pv.Sphere(pv.Vec3(0,0,0), 2, 2)
>>> sphere.prepare(pv.vec3(1, 1, 1), 0.1, 0.1)
type(self: pyvcad.pyvcad.Node) str

Returns the type of the node as a string.

Example

>>> from libvcad import pyvcad as pv
>>> sphere = pv.Sphere()
>>> node_type = sphere.type() # Should return 'leaf'
class pyvcad.Offset

Bases: Unary

Shifts a child’s signed distance by a constant value. Negative offset moves the surface inward and positive offset moves it outward.

__init__(*args, **kwargs)

Overloaded function.

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

Default constructor with zero offset.

  1. __init__(self: pyvcad.pyvcad.Offset, arg0: float) -> None

Constructor with a specified offset.

Parameters:

offset (double) – The offset to apply to the signed distance.

  1. __init__(self: pyvcad.pyvcad.Offset, arg0: float, arg1: pyvcad.pyvcad.Node) -> None

Constructor with a specified offset and a child node.

Parameters:
  • offset (double) – The offset to apply to the signed distance.

  • child (Node) – The child node.

set_child(self: pyvcad.pyvcad.Offset, child: pyvcad.pyvcad.Node) None

Sets the single child of this node.

class pyvcad.Point2

Bases: pybind11_object

__init__(*args, **kwargs)

Overloaded function.

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

Default constructor creating a point at origin (0,0)

Example

>>> p = Point2()
>>> print(f'({p.x()}, {p.y()})')
(0.0, 0.0)
  1. __init__(self: pyvcad.pyvcad.Point2, arg0: float, arg1: float) -> None

Create a 2D point with given x and y coordinates

Parameters:
  • x (float) – X coordinate

  • y (float) – Y coordinate

Example

>>> p = Point2(1.0, 2.0)
>>> print(f'({p.x()}, {p.y()})')
(1.0, 2.0)
x(self: pyvcad.pyvcad.Point2) float

Get the x coordinate of the point

Returns:

X coordinate

Return type:

float

y(self: pyvcad.pyvcad.Point2) float

Get the y coordinate of the point

Returns:

Y coordinate

Return type:

float

class pyvcad.PointMap

Bases: Leaf

A leaf node that represents simulation results that are imported. This class is used to import simulation results from external files and map a multi-material distribution them as a design. The simulation results must be stored in a tetrahedral mesh saved as a .inp file and a displacement field saved as a .csv file. This class assumes nodal displacements are stored in the displacement field file and that the indices of the nodes in the tetrahedral mesh correspond to the indices of the nodes in the displacement field file. The displacement field file must have the following format (where xyz is the coordinates of the node and uvw is the displacement vector): x1, y1, z1, u1, v1, w1, x2, y2, z2, u2, v2, w2, … The tetrahedral mesh file must be an Abaqus .inp file using C3D4 elements. The point map can be used to evaluate functions at any point in space by interpolating the simulation results. However, the material distribution is only available within the tetrahedral mesh. Likewise, the signed distance returned by the evaluate() function is simple point membership. Mapping functions are defined using the exprtk library and are similar to the f_grade() node. When sampling a point in space, the following variables are available in math expressions: - x, y, z: The coordinates of the point - rho, phic, r: The cylindrical coordinates of the point - theta, phis: The spherical coordinates of the point - dx, dy, dz: The displacement vector at the point - len: The length of the displacement vector. Similar to f_grade(), each function defined must also have a corresponding material id defined with it. When sampled using distribution() the volume fractions/ probability density is returned as evaluated by the functions. The point map can be used in probability mode where the material() function uses the material distribution as a probability masses and returns a random material id based on the distribution. Threshold mode is also available where the material() function returns the material id with the highest probability mass. Note: This class only supports tetrahedral meshes and displacement fields.

__init__(self: pyvcad.pyvcad.PointMap, mesh_path: str, tet_mesh_path: str, displacement_field_path: str, functions: list[str], materials: list[int], prob_mode: bool) None

Constructor. Creates a PointMap with a tetrahedron mesh file path, displacement field file path, functions, materials, and probability mode.

Parameters:
  • mesh_path (std::string) – The path to the surface mesh file.

  • tet_mesh_path (std::string) – The path to the tetrahedron mesh file (INP).

  • displacement_field_path (std::string) – The path to the displacement field file (CSV).

  • functions (std::vector<std::string>) – The functions to evaluate, similar to F-reps or F-grades. These functions map the displacement field to multi-material distribution.

  • materials (std::vector<uint8_t>) – The materials for the functions.

  • prob_mode (bool) – The probability mode of the functions. When sampled using distribution() the volume fractions/ probability density is returned as evaluated by the functions. The point map can be used in probability mode where the material() function uses the material distribution as a probability masses and returns a random material id based on the distribution. Threshold mode is also available where the material() function returns the material id with the highest probability mass.

Example

>>> from libvcad import pyvcad as pv
>>> functions = ['x + y + z', 'x * y * z']
>>> materials = [1, 2]
>>> point_map = pv.PointMap('path/to/meshfile.inp', 'path/to/displacementfile.csv', functions, materials, True)
class pyvcad.Polygon2

Bases: pybind11_object

static Clip(arg0: list[pyvcad.pyvcad.Polygon2], arg1: list[Polyline2]) tuple[list[pyvcad.pyvcad.Polygon2], list[Polyline2]]
static Difference(arg0: list[pyvcad.pyvcad.Polygon2], arg1: list[pyvcad.pyvcad.Polygon2]) list[pyvcad.pyvcad.Polygon2]
static Intersection(arg0: list[pyvcad.pyvcad.Polygon2], arg1: list[pyvcad.pyvcad.Polygon2]) list[pyvcad.pyvcad.Polygon2]
static Offset(arg0: list[pyvcad.pyvcad.Polygon2], arg1: float) list[pyvcad.pyvcad.Polygon2]
static Union(arg0: list[pyvcad.pyvcad.Polygon2], arg1: list[pyvcad.pyvcad.Polygon2]) list[pyvcad.pyvcad.Polygon2]
__init__(*args, **kwargs)

Overloaded function.

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

  2. __init__(self: pyvcad.pyvcad.Polygon2, arg0: list[pyvcad.pyvcad.Point2]) -> None

  3. __init__(self: pyvcad.pyvcad.Polygon2, arg0: list[pyvcad.pyvcad.Vec2]) -> None

bounding_box(self: pyvcad.pyvcad.Polygon2) tuple[pyvcad.pyvcad.Point2, pyvcad.pyvcad.Point2]
diff(self: pyvcad.pyvcad.Polygon2, arg0: pyvcad.pyvcad.Polygon2) list[pyvcad.pyvcad.Polygon2]
do_clip(self: pyvcad.pyvcad.Polygon2, arg0: list[Polyline2]) tuple[list[pyvcad.pyvcad.Polygon2], list[Polyline2]]
do_union(*args, **kwargs)

Overloaded function.

  1. do_union(self: pyvcad.pyvcad.Polygon2, arg0: pyvcad.pyvcad.Polygon2) -> list[pyvcad.pyvcad.Polygon2]

  2. do_union(self: pyvcad.pyvcad.Polygon2, arg0: list[pyvcad.pyvcad.Polygon2]) -> list[pyvcad.pyvcad.Polygon2]

double_area(self: pyvcad.pyvcad.Polygon2) float
draw(self: pyvcad.pyvcad.Polygon2) None
holes(self: pyvcad.pyvcad.Polygon2) list[pyvcad.pyvcad.Polygon2]
inside(self: pyvcad.pyvcad.Polygon2, arg0: pyvcad.pyvcad.Point2) bool
intersect(*args, **kwargs)

Overloaded function.

  1. intersect(self: pyvcad.pyvcad.Polygon2, arg0: pyvcad.pyvcad.Polygon2) -> list[pyvcad.pyvcad.Polygon2]

  2. intersect(self: pyvcad.pyvcad.Polygon2, arg0: list[pyvcad.pyvcad.Polygon2]) -> list[pyvcad.pyvcad.Polygon2]

is_ccw(self: pyvcad.pyvcad.Polygon2) bool
offset(self: pyvcad.pyvcad.Polygon2, arg0: float) list[pyvcad.pyvcad.Polygon2]
on_boundary(self: pyvcad.pyvcad.Polygon2, arg0: pyvcad.pyvcad.Point2) bool
reverse(self: pyvcad.pyvcad.Polygon2) None
set_holes(self: pyvcad.pyvcad.Polygon2, arg0: list[pyvcad.pyvcad.Polygon2]) None
simplify(self: pyvcad.pyvcad.Polygon2, tolerance: float = 0.001) None
to_polyline(self: pyvcad.pyvcad.Polygon2) Polyline2
class pyvcad.Polyline2

Bases: pybind11_object

__init__(*args, **kwargs)

Overloaded function.

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

  2. __init__(self: pyvcad.pyvcad.Polyline2, arg0: list[pyvcad.pyvcad.Point2]) -> None

  3. __init__(self: pyvcad.pyvcad.Polyline2, arg0: list[pyvcad.pyvcad.Vec2]) -> None

append(self: pyvcad.pyvcad.Polyline2, arg0: pyvcad.pyvcad.Polyline2) None
length(self: pyvcad.pyvcad.Polyline2) float
points(self: pyvcad.pyvcad.Polyline2) list[pyvcad.pyvcad.Point2]
prepend(self: pyvcad.pyvcad.Polyline2, arg0: pyvcad.pyvcad.Polyline2) None
reverse(self: pyvcad.pyvcad.Polyline2) None
segments(self: pyvcad.pyvcad.Polyline2) list[pyvcad.pyvcad.Segment2]
simplify(self: pyvcad.pyvcad.Polyline2, tolerance: float = 0.001) None
translate(self: pyvcad.pyvcad.Polyline2, arg0: pyvcad.pyvcad.Point2) None
class pyvcad.RectPrism

Bases: Leaf

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

__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), and material id of 1.

Example

>>> from libvcad import pyvcad as pv
>>> rect_prism = pv.RectPrism()
  1. __init__(self: pyvcad.pyvcad.RectPrism, center: pyvcad.pyvcad.Vec3, size: pyvcad.pyvcad.Vec3, material: int = 1) -> None

Constructor. Creates a RectPrism with a center, size, and material id.

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

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

  • material (uint8_t) – The material id of the RectPrism.

Example

>>> from libvcad import pyvcad as pv
>>> center = pv.vec3(0, 0, 0)
>>> size = pv.vec3(2, 2, 2)
>>> rect_prism = pv.RectPrism(center, size, 1)
class pyvcad.Rotate

Bases: Unary

Rotates a child node around a point. The rotation is specified by a pitch, yaw, and roll angles and a point around which the rotation is performed. The rotation is performed in the order: roll, yaw, pitch. By default, rotation is around the point (0, 0, 0), but you can specify a different point in the constructor.

__init__(*args, **kwargs)

Overloaded function.

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

Default constructor. Defaults to no rotation.

Example

>>> from libvcad import pyvcad as pv
>>> rect_prism = pv.RectPrism(pv.vec3(0, 0, 0), pv.vec3(2, 2, 2), 1)
>>> rotate = pv.Rotate()
>>> rotate.set_child(rect_prism)
  1. __init__(self: pyvcad.pyvcad.Rotate, pitch: float, yaw: float, roll: float, around: pyvcad.pyvcad.Vec3 = <pyvcad.pyvcad.Vec3 object at 0x0000021BD7DEDBF0>) -> None

Constructor. Creates a Rotate with pitch, yaw, roll angles, and a point around which the rotation is performed.

Parameters:
  • pitch (double) – Pitch angle in degrees.

  • yaw (double) – Yaw angle in degrees.

  • roll (double) – Roll angle in degrees.

  • around (glm::vec3) – Point around which the rotation is performed. Defaults to (0, 0, 0).

Example

>>> from libvcad import pyvcad as pv
>>> pitch = 30
>>> yaw = 45
>>> roll = 60
>>> around = pv.vec3(1, 1, 1)
>>> rect_prism = pv.RectPrism(pv.vec3(0, 0, 0), pv.vec3(2, 2, 2), 1)
>>> rotate = pv.Rotate(pitch, yaw, roll, around)
>>> rotate.set_child(rect_prism)
  1. __init__(self: pyvcad.pyvcad.Rotate, pitch: float, yaw: float, roll: float, around: pyvcad.pyvcad.Vec3, child: pyvcad.pyvcad.Node) -> None

Constructor. Creates a Rotate with pitch, yaw, roll angles, a point around which the rotation is performed, and a child node.

Parameters:
  • pitch (double) – Pitch angle in degrees.

  • yaw (double) – Yaw angle in degrees.

  • roll (double) – Roll angle in degrees.

  • around (glm::vec3) – Point around which the rotation is performed.

  • child (std::shared_ptr<Node>) – The child node.

Example

>>> from libvcad import pyvcad as pv
>>> pitch = 30
>>> yaw = 45
>>> roll = 60
>>> around = pv.vec3(1, 1, 1)
>>> rect_prism = pv.RectPrism(pv.vec3(0, 0, 0), pv.vec3(2, 2, 2), 1)
>>> rotate = pv.Rotate(pitch, yaw, roll, around, rect_prism)
class pyvcad.Scale

Bases: Unary

Scales a child by a factor in each dimension. This node is unary, therefore can only have one child. The scale is applied during evaluate() and performs the inverse of the scaling on the point.

__init__(*args, **kwargs)

Overloaded function.

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

Default constructor. Sets the scale to 1.0 in each dimension.

Example

>>> from libvcad import pyvcad as pv
>>> rect_prism = pv.RectPrism(pv.vec3(0, 0, 0), pv.vec3(2, 2, 2), 1)
>>> scale = pv.Scale()
>>> scale.set_child(rect_prism)
  1. __init__(self: pyvcad.pyvcad.Scale, x: float, y: float, z: float) -> None

Constructor. Sets the scale to the supplied values.

Parameters:
  • x (double) – The scale in the x dimension.

  • y (double) – The scale in the y dimension.

  • z (double) – The scale in the z dimension.

Example

>>> from libvcad import pyvcad as pv
>>> rect_prism = pv.RectPrism(pv.vec3(0, 0, 0), pv.vec3(2, 2, 2), 1)
>>> scale = pv.Scale(2.0, 2.0, 2.0)
>>> scale.set_child(rect_prism)
  1. __init__(self: pyvcad.pyvcad.Scale, x: float, y: float, z: float, child: pyvcad.pyvcad.Node) -> None

Constructor. Sets the scale to the supplied values and sets the child.

Parameters:
  • x (double) – The scale in the x dimension.

  • y (double) – The scale in the y dimension.

  • z (double) – The scale in the z dimension.

  • child (std::shared_ptr<Node>) – The child node.

Example

>>> from libvcad import pyvcad as pv
>>> rect_prism = pv.RectPrism(pv.vec3(0, 0, 0), pv.vec3(2, 2, 2), 1)
>>> scale = pv.Scale(2.0, 2.0, 2.0, rect_prism)
class pyvcad.Segment2

Bases: pybind11_object

__init__(self: pyvcad.pyvcad.Segment2, arg0: pyvcad.pyvcad.Point2, arg1: pyvcad.pyvcad.Point2) None

Create a 2D line segment between two points

Parameters:
  • p1 (Point2) – The first point of the segment

  • p2 (Point2) – The second point of the segment

Example

>>> p1 = Point2(0.0, 0.0)
>>> p2 = Point2(1.0, 1.0)
>>> segment = Segment2(p1, p2)
>>> source = segment.source()
>>> target = segment.target()
>>> print(f'From ({source.x()}, {source.y()}) to ({target.x()}, {target.y()})')
From (0.0, 0.0) to (1.0, 1.0)
source(self: pyvcad.pyvcad.Segment2) pyvcad.pyvcad.Point2

Returns the source point of the segment

Returns:

The starting point of the segment

Return type:

Point2

target(self: pyvcad.pyvcad.Segment2) pyvcad.pyvcad.Point2

Returns the target point of the segment

Returns:

The ending point of the segment

Return type:

Point2

class pyvcad.Shell

Bases: Unary

Computes an inward shell of a child node using a specified thickness.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pyvcad.pyvcad.Shell, thickness: float) -> None

Constructor with shell thickness. Thickness must be positive.

  1. __init__(self: pyvcad.pyvcad.Shell, thickness: float, child: pyvcad.pyvcad.Node) -> None

Constructor with shell thickness and a child node. Thickness must be positive.

class pyvcad.Sphere

Bases: Leaf

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

__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, and material id of 1.

Example

>>> from libvcad import pyvcad as pv
>>> sphere = pv.Sphere()
  1. __init__(self: pyvcad.pyvcad.Sphere, cx: float, cy: float, cz: float, radius: float, material: int = 1) -> None

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

Parameters:
  • cx (double) – The x coordinate of the center point of the Sphere.

  • cy (double) – The y coordinate of the center point of the Sphere.

  • cz (double) – The z coordinate of the center point of the Sphere.

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

  • material (uint8_t) – The material id of the Sphere.

Example

>>> from libvcad import pyvcad as pv
>>> sphere = pv.Sphere(0, 0, 0, 5, 1)
  1. __init__(self: pyvcad.pyvcad.Sphere, center: pyvcad.pyvcad.Vec3, radius: float, material: int = 1) -> 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.

  • material (uint8_t) – The material id of the Sphere.

Example

>>> from libvcad import pyvcad as pv
>>> center = pv.vec3(0, 0, 0)
>>> sphere = pv.Sphere(center, 5, 1)
class pyvcad.Strut

Bases: Leaf

A leaf node that represents a strut.

__init__(self: pyvcad.pyvcad.Strut, start: pyvcad.pyvcad.Vec3, end: pyvcad.pyvcad.Vec3, radius: float, material: int = 1) None

Constructor. Creates a Strut with a start point, end point, radius, and material ID.

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

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

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

  • material (uint8_t) – The material ID for the strut.

Example

>>> from libvcad import pyvcad as pv
>>> start = pv.vec3(0, 0, 0)
>>> end = pv.vec3(1, 1, 1)
>>> strut = pv.Strut(start, end, 0.5, 1)
class pyvcad.Sum

Bases: NAry

A node that sums all child Signed Distance Fields (SDFs). This node is N-ary, meaning it can have multiple children. The sum is calculated during evaluate() and results in the combined sum of all child SDFs.

__init__(*args, **kwargs)

Overloaded function.

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

Default constructor.

  1. __init__(self: pyvcad.pyvcad.Sum, iso_value: float) -> None

Constructor. Sets the iso value for the sum node.

Parameters:

iso_value (double) – The iso value for the sum node.

  1. __init__(self: pyvcad.pyvcad.Sum, iso_value: float, children: list[pyvcad.pyvcad.Node]) -> None

Constructor. Sets the iso value and the children for the sum node.

Parameters:
  • iso_value (double) – The iso value for the sum node.

  • children (std::vector<std::shared_ptr<Node>>) – The children of the sum node.

class pyvcad.TetrahedralMesh

Bases: pybind11_object

Class representing a tetrahedral mesh using CGAL. Contains functions to build a mesh from a tree, write the mesh to an INP file

__init__(self: pyvcad.pyvcad.TetrahedralMesh, arg0: CGAL::Mesh_complex_3_in_triangulation_3<CGAL::Mesh_3_regular_triangulation_3_wrapper<CGAL::Robust_weighted_circumcenter_filtered_traits_3<CGAL::Epick>, CGAL::Mesh_triangulation_3<CGAL::Labeled_mesh_domain_3<CGAL::Epick, int, std::pair<int, int> >, CGAL::Default, CGAL::Parallel_tag, CGAL::Default, CGAL::Default>::Tds>, int, int>) None

Constructor that takes a C3t3 object.

static from_tree(*args, **kwargs)

Overloaded function.

  1. from_tree(arg0: pyvcad.pyvcad.Node, arg1: float, arg2: float, arg3: float, arg4: int, arg5: float) -> pyvcad.pyvcad.TetrahedralMesh

Creates a TetrahedralMesh from a tree using a static cell size.

  1. from_tree(arg0: pyvcad.pyvcad.Node, arg1: float, arg2: float, arg3: float, arg4: int, arg5: float, arg6: float, arg7: str) -> pyvcad.pyvcad.TetrahedralMesh

Creates a TetrahedralMesh from a tree using a variable cell size based on the material properties gradient.

write_to_inp(self: pyvcad.pyvcad.TetrahedralMesh, arg0: str, arg1: MaterialDefs, arg2: pyvcad.pyvcad.Node) None

Writes the tetrahedral mesh to an INP file.

class pyvcad.Text

Bases: Leaf

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: float, depth: float, material: int = 1, 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.

  • material (int, optional) – The material id of the text node. Defaults to 1.

  • 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.

bounding_box(self: pyvcad.pyvcad.Text) tuple[pyvcad.pyvcad.Vec3, pyvcad.pyvcad.Vec3]

Computes the axis-aligned bounding box of the text node.

Returns:

A pair of vec3 objects representing the minimum and maximum points of the bounding box.

Return type:

tuple

clone(self: pyvcad.pyvcad.Text) pyvcad.pyvcad.Node

Creates a deep copy of the text node.

distribution(self: pyvcad.pyvcad.Text, arg0: float, arg1: float, arg2: float) dict[int, float]

Provides the material distribution at a given point.

Parameters:
  • x (float) – X-coordinate.

  • y (float) – Y-coordinate.

  • z (float) – Z-coordinate.

Returns:

A dictionary with the material id as key and occupancy as value if the point is inside; otherwise, an empty dict.

Return type:

dict

evaluate(self: pyvcad.pyvcad.Text, arg0: float, arg1: float, arg2: float) float

Evaluates the text node at a given coordinate to compute the signed distance to the surface.

Parameters:
  • x (float) – X-coordinate.

  • y (float) – Y-coordinate.

  • z (float) – Z-coordinate.

Returns:

The signed distance from the point to the text surface.

Return type:

float

material_list(self: pyvcad.pyvcad.Text) list[int]

Returns a list containing the material id associated with this text node.

prepare(self: pyvcad.pyvcad.Text, arg0: pyvcad.pyvcad.Vec3, arg1: float, arg2: float) None

Prepares the text node by generating its CAD representation.

Parameters:
  • voxel_size (vec3) – The voxel size of the grid.

  • interior_bandwidth (float) – The interior bandwidth for calculations.

  • exterior_bandwidth (float) – The exterior bandwidth for calculations.

class pyvcad.Tile

Bases: Unary

A node that tiles a child geometry in a grid pattern. This unary operator repeats a geometry based on specified cell dimensions. The tiling occurs when evaluate() or material() is called, which can be used to create lattice structures.

__init__(*args, **kwargs)

Overloaded function.

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

Default constructor. The cell dimensions will be calculated from the child node when prepare is called.

Example

>>> from libvcad import pyvcad as pv
>>> tile = pv.Tile()
  1. __init__(self: pyvcad.pyvcad.Tile, child: pyvcad.pyvcad.Node) -> None

Constructor. Sets the child node. The cell dimensions will be calculated from the child node.

Parameters:

child (std::shared_ptr<Node>) – The child node.

Example

>>> from libvcad import pyvcad as pv
>>> rect_prism = pv.RectPrism(pv.Vec3(0, 0, 0), pv.Vec3(2, 2, 2), 1)
>>> tile = pv.Tile(rect_prism)
  1. __init__(self: pyvcad.pyvcad.Tile, cell_x: float, cell_y: float, cell_z: float) -> None

Constructor. Sets the dimensions of a cell in the grid.

Parameters:
  • cell_x (double) – The x dimension of a cell.

  • cell_y (double) – The y dimension of a cell.

  • cell_z (double) – The z dimension of a cell.

Example

>>> from libvcad import pyvcad as pv
>>> tile = pv.Tile(1.0, 1.0, 1.0)
  1. __init__(self: pyvcad.pyvcad.Tile, cell_x: float, cell_y: float, cell_z: float, child: pyvcad.pyvcad.Node) -> None

Constructor. Sets the dimensions of a cell in the grid and sets the child.

Parameters:
  • cell_x (double) – The x dimension of a cell.

  • cell_y (double) – The y dimension of a cell.

  • cell_z (double) – The z dimension of a cell.

  • child (std::shared_ptr<Node>) – The child node.

Example

>>> from libvcad import pyvcad as pv
>>> rect_prism = pv.RectPrism(pv.Vec3(0, 0, 0), pv.Vec3(2, 2, 2), 1)
>>> tile = pv.Tile(1.0, 1.0, 1.0, rect_prism)
class pyvcad.Translate

Bases: Unary

Translates a child in Cartesian space by a given amount. This node is unary, with only one child, and performs the inverse translation on coordinates during material() and evaluate().

__init__(*args, **kwargs)

Overloaded function.

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

Default constructor. Sets the translation to 0, 0, 0.

Example

>>> from libvcad import pyvcad as pv
>>> rect_prism = pv.RectPrism(pv.vec3(0, 0, 0), pv.vec3(2, 2, 2), 1)
>>> translate = pv.Translate()
>>> translate.set_child(rect_prism)
  1. __init__(self: pyvcad.pyvcad.Translate, x: float, y: float, z: float) -> None

Constructor. Sets the translation to given values in Cartesian space.

Parameters:
  • x (double) – Translation in the x direction.

  • y (double) – Translation in the y direction.

  • z (double) – Translation in the z direction.

Example

>>> from libvcad import pyvcad as pv
>>> rect_prism = pv.RectPrism(pv.vec3(0, 0, 0), pv.vec3(2, 2, 2), 1)
>>> translate = pv.Translate(1.0, 2.0, 3.0)
>>> translate.set_child(rect_prism)
  1. __init__(self: pyvcad.pyvcad.Translate, x: float, y: float, z: float, child: pyvcad.pyvcad.Node) -> None

Constructor. Sets the translation to given values and sets the child.

Parameters:
  • x (double) – Translation in the x direction.

  • y (double) – Translation in the y direction.

  • z (double) – Translation in the z direction.

  • child (std::shared_ptr<Node>) – The child to set.

Example

>>> from libvcad import pyvcad as pv
>>> rect_prism = pv.RectPrism(pv.vec3(0, 0, 0), pv.vec3(2, 2, 2), 1)
>>> translate = pv.Translate(1.0, 2.0, 3.0, rect_prism)
class pyvcad.Unary

Bases: Node

A node with a single child.

__init__(*args, **kwargs)
child(self: pyvcad.pyvcad.Unary) pyvcad.pyvcad.Node

Returns the one and only child of this node.

set_child(self: pyvcad.pyvcad.Unary, child: pyvcad.pyvcad.Node) None

Sets the one and only child of this node.

Parameters:

child (Node) – The child node to be set.

class pyvcad.Union

Bases: NAry

A union of two or more nodes. This is equivalent to the summing of the children. This node is N-ary, so it can have multiple children.

__init__(*args, **kwargs)

Overloaded function.

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

Default constructor. Creates a Union node with no children.

Example

>>> from libvcad import pyvcad as pv
>>> radius = 5
>>> sphere1 = pv.Sphere(pv.Vec3(-radius/2, 0, 0), radius, 1)
>>> sphere2 = pv.Sphere(pv.Vec3(radius/2, 0, 0), radius, 1)
>>> union_node = pv.Union()
>>> union_node.add_child(sphere1)
>>> union_node.add_child(sphere2)
  1. __init__(self: pyvcad.pyvcad.Union, should_union_distribution: bool) -> None

Constructor. Creates a Union node with an option to union distributions.

Parameters:

should_union_distribution (bool) – If true, the distribution will be unioned. If false, the distribution will be summed.

Example

>>> from libvcad import pyvcad as pv
>>> radius = 5
>>> sphere1 = pv.Sphere(pv.Vec3(-radius/2, 0, 0), radius, 1)
>>> sphere2 = pv.Sphere(pv.Vec3(radius/2, 0, 0), radius, 1)
>>> union_node = pv.Union(True)
>>> union_node.add_child(sphere1)
>>> union_node.add_child(sphere2)
  1. __init__(self: pyvcad.pyvcad.Union, should_union_distribution: bool, children: list[pyvcad.pyvcad.Node]) -> None

Constructor. Creates a Union node with an option to union distributions and sets the children.

Parameters:
  • should_union_distribution (bool) – If true, the distribution will be unioned. If false, the distribution will be summed.

  • children (std::vector<std::shared_ptr<Node>>) – The children nodes.

Example

>>> from libvcad import pyvcad as pv
>>> radius = 5
>>> sphere1 = pv.Sphere(pv.Vec3(-radius/2, 0, 0), radius, 1)
>>> sphere2 = pv.Sphere(pv.Vec3(radius/2, 0, 0), radius, 1)
>>> union_node = pv.Union(True, [sphere1, sphere2])
class pyvcad.Vec2

Bases: pybind11_object

__init__(*args, **kwargs)

Overloaded function.

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

Default constructor creating a zero vector (0,0)

Example

>>> v = Vec2()
>>> print(f'({v.x}, {v.y})')
(0.0, 0.0)
  1. __init__(self: pyvcad.pyvcad.Vec2, arg0: float, arg1: float) -> None

Create a 2D vector with given x and y components

Parameters:
  • x (float) – X component

  • y (float) – Y component

Example

>>> v = Vec2(1.0, 2.0)
>>> print(f'({v.x}, {v.y})')
(1.0, 2.0)
property x

X component of the vector

property y

Y component of the vector

class pyvcad.Vec3

Bases: pybind11_object

__init__(*args, **kwargs)

Overloaded function.

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

Default constructor creating a zero vector (0,0,0)

Example

>>> v = Vec3()
>>> print(f'({v.x}, {v.y}, {v.z})')
(0.0, 0.0, 0.0)
  1. __init__(self: pyvcad.pyvcad.Vec3, arg0: float, arg1: float, arg2: float) -> None

Create a 3D vector with given x, y, and z components

Parameters:
  • x (float) – X component

  • y (float) – Y component

  • z (float) – Z component

Example

>>> v = Vec3(1.0, 2.0, 3.0)
>>> print(f'({v.x}, {v.y}, {v.z})')
(1.0, 2.0, 3.0)
  1. __init__(self: pyvcad.pyvcad.Vec3, arg0: list[float]) -> None

Create a 3D vector from a list or tuple of 3 floats

Example

>>> v = Vec3([1.0, 2.0, 3.0])
>>> print(f'({v.x}, {v.y}, {v.z})')
(1.0, 2.0, 3.0)
property x

X component of the vector

property y

Y component of the vector

property z

Z component of the vector

class pyvcad.Vec4

Bases: pybind11_object

__init__(*args, **kwargs)

Overloaded function.

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

Default constructor creating a zero vector (0,0,0,0)

Example

>>> v = Vec4()
>>> print(f'({v.r}, {v.g}, {v.b}, {v.a})')
(0.0, 0.0, 0.0, 0.0)
  1. __init__(self: pyvcad.pyvcad.Vec4, arg0: float, arg1: float, arg2: float, arg3: float) -> None

Create a 4D vector with given r, g, b, and a components

Parameters:
  • r (float) – Red component

  • g (float) – Green component

  • b (float) – Blue component

  • a (float) – Alpha component

Example

>>> v = Vec4(1.0, 0.0, 0.0, 1.0)  # Red color with full opacity
>>> print(f'({v.r}, {v.g}, {v.b}, {v.a})')
(1.0, 0.0, 0.0, 1.0)
property a

Alpha component of the vector

property b

Blue component of the vector

property g

Green component of the vector

property r

Red component of the vector

class pyvcad.VerticalAlignment

Bases: pybind11_object

Defines the vertical position of text relative to its anchor point

Members:

Bottom : The anchor lies on the last line of the text

Center : The anchor lies on the center of the text

Top : The anchor lies on the line preceding the first line of the text

Top_First_Line : The anchor lies on the first line of the text

Bottom = <VerticalAlignment.Bottom: 0>
Center = <VerticalAlignment.Center: 1>
Top = <VerticalAlignment.Top: 2>
Top_First_Line = <VerticalAlignment.Top_First_Line: 3>
__init__(self: pyvcad.pyvcad.VerticalAlignment, value: int) None
property name
property value
class pyvcad.Voxels

Bases: Leaf

A leaf node/geometric primitive that contains a voxel grid, which can be loaded from disk or generated from an equation. Voxels are stored in an OpenVDB grid.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pyvcad.pyvcad.Voxels, file_path: str, voxel_size: pyvcad.pyvcad.Vec3, min: pyvcad.pyvcad.Vec3, material_defs: MaterialDefs) -> None

Constructor. Creates Voxels with a file path, voxel size, minimum coordinate of the grid, and material definitions.

Parameters:
  • file_path (string) – The path to the file from which to load the voxel grid.

  • voxel_size (vec3) – The size of each voxel in the grid. It doesn’t need to match what you sample, and can be asymmetric.

  • min (vec3) – The minimum coordinate of the grid.

  • material_defs (MaterialDefs) – A pointer to the material definitions. Required to convert material values in the grid into OpenVCAD material values.

Example

>>> from libvcad import pyvcad as pv
>>> material_defs = pv.MaterialDefs()
>>> voxels = pv.Voxels('path/to/voxelgrid.vdb', pv.vec3(0.1, 0.1, 0.1), pv.vec3(0, 0, 0), material_defs)
  1. __init__(self: pyvcad.pyvcad.Voxels, voxel_size: pyvcad.pyvcad.Vec3, min: pyvcad.pyvcad.Vec3) -> None

Constructor. Creates Voxels with voxel size and minimum coordinate of the grid.

Parameters:
  • voxel_size (vec3) – The size of each voxel in the grid. It doesn’t need to match what you sample, and can be asymmetric.

  • min (vec3) – The minimum coordinate of the grid.

Example

>>> from libvcad import pyvcad as pv
>>> voxels = pv.Voxels(pv.vec3(0.1, 0.1, 0.1), pv.vec3(0, 0, 0))
populate_with_equation(self: pyvcad.pyvcad.Voxels, equation: str, min: pyvcad.pyvcad.Vec3, max: pyvcad.pyvcad.Vec3, voxel_size: pyvcad.pyvcad.Vec3) None

Populates the grid with a VDB file.

Parameters:
  • equation (string) – The equation to populate the grid.

  • min (vec3) – The minimum coordinate of the grid.

  • max (vec3) – The maximum coordinate of the grid.

  • voxel_size (vec3) – The size of each voxel in the grid. It doesn’t need to match what you sample, and can be asymmetric.

Example

>>> from libvcad import pyvcad as pv
>>> voxels.populate_with_equation('x^2 + y^2 + z^2 - 1', pv.vec3(0, 0, 0), pv.vec3(1, 1, 1), pv.vec3(0.1, 0.1, 0.1))
populate_with_png_stack(self: pyvcad.pyvcad.Voxels, dir: str, min: pyvcad.pyvcad.Vec3, voxel_size: pyvcad.pyvcad.Vec3) None

Populates the grid with a PNG stack given a directory. The PNG files are assumed to be named in order (i.e. 001.png, 002.png, etc.). The material values are converted to OpenVCAD material values using the material definitions.

Parameters:
  • dir (string) – The directory containing the PNG files.

  • min (vec3) – The minimum coordinate of the grid.

  • voxel_size (vec3) – The size of each voxel in the grid. It doesn’t need to match what you sample, and can be asymmetric.

Example

>>> from libvcad import pyvcad as pv
>>> voxels.populate_with_png_stack('path/to/png_stack', pv.vec3(0, 0, 0), pv.vec3(0.1, 0.1, 0.1))
save_to_file(self: pyvcad.pyvcad.Voxels, file_path: str) None

Saves the grid to a VDB file.

Parameters:

file_path (string) – The path to the VDB file to save the grid.

Example

>>> from libvcad import pyvcad as pv
>>> voxels.save_to_file('path/to/savefile.vdb')
pyvcad.evaluate_fill(node: pyvcad.pyvcad.Node, buffer: numpy.ndarray[numpy.float64], start: pyvcad.pyvcad.Vec3, nx: int, ny: int, nz: int, voxel_size: pyvcad.pyvcad.Vec3) None
pyvcad.parse_vcad_text(input: str, material_config_path: str = 'configs/testing.json') pyvcad.pyvcad.Node

Parses a VCAD script text and returns the root node of the tree.

pyvcad.resources_path() str

Get the path to the resources directory.

Returns:

Path to the resources directory. On Mac it is located inside of the .app bundle. On Windows and Linux it is the same path as the executable.

Return type:

str

Example

>>> path = resources_path()
>>> print(path)
'../../Resources/' on Mac OS    '' on Windows and Linux
pyvcad.version() str

Get the version of OpenVCAD