microgen.shape package

Shape.

Shape (microgen.shape)

class microgen.shape.Box(dim: tuple[float, float, float] = (1, 1, 1), dim_x: float | None = None, dim_y: float | None = None, dim_z: float | None = None, **kwargs: Vector3DType)

Bases: Shape

Class to generate a box.

_images/microgen.shape_1_0.png
generate(**_: KwargsGenerateType) cq.Shape

Generate a box CAD shape using the given parameters.

generateVtk(**kwargs: KwargsGenerateType) pv.PolyData

Deprecated. Use generate_vtk() instead.

generate_vtk(level: int = 0, **_: KwargsGenerateType) pv.PolyData

Generate a box VTK shape using the given parameters.

class microgen.shape.Capsule(height: float = 1, radius: float = 0.5, **kwargs: Vector3DType)

Bases: Shape

Class to generate a capsule (cylinder with hemispherical ends).

_images/microgen.shape_2_0.png
generate(**_: KwargsGenerateType) cq.Shape

Generate a capsule CAD shape using the given parameters.

generateVtk(resolution: int = 100, theta_resolution: int = 50, phi_resolution: int = 50, **_: KwargsGenerateType) pv.PolyData

Deprecated. Use generate_vtk() instead.

generate_vtk(resolution: int = 100, theta_resolution: int = 50, phi_resolution: int = 50, **_: KwargsGenerateType) pv.PolyData

Generate a capsule VTK shape using the given parameters.

class microgen.shape.Cylinder(height: float = 1, radius: float = 0.5, **kwargs: Vector3DType)

Bases: Shape

Class to generate a cylinder.

_images/microgen.shape_3_0.png
generate(**_: KwargsGenerateType) cq.Shape

Generate a cylinder CAD shape using the given parameters.

generateVtk(resolution: int = 100, **kwargs: KwargsGenerateType) pv.PolyData

Deprecated. Use generate_vtk() instead.

generate_vtk(resolution: int = 100, **_: KwargsGenerateType) pv.PolyData

Generate a cylinder VTK shape using the given parameters.

class microgen.shape.CylindricalTpms(radius: float, surface_function: Field, offset: float | OffsetGrading | Field | None = None, phase_shift: Sequence[float] = (0.0, 0.0, 0.0), cell_size: float | Sequence[float] = 1.0, repeat_cell: int | Sequence[int] = 1, center: Vector3DType = (0, 0, 0), orientation: Vector3DType = (0, 0, 0), resolution: int = 20, density: float | None = None)

Bases: Tpms

Class used to generate cylindrical TPMS geometries (sheet or skeletals parts).

class microgen.shape.Ellipsoid(radii: tuple[float, float, float] = (1, 0.5, 0.25), a_x: float | None = None, a_y: float | None = None, a_z: float | None = None, **kwargs: Vector3DType)

Bases: Shape

Class to generate an ellipsoid.

_images/microgen.shape_4_0.png
generate(**_: KwargsGenerateType) cq.Shape

Generate an ellipsoid CAD shape using the given parameters.

generateVtk(**_: KwargsGenerateType) pv.PolyData

Deprecated. Use generate_vtk() instead.

generate_vtk(**_: KwargsGenerateType) pv.PolyData

Generate an ellipsoid VTK polydta using the given parameters.

class microgen.shape.ExtrudedPolygon(list_corners: Sequence[tuple[float, float]] | None = None, height: float = 1, **kwargs: Vector3DType | dict[str, Sequence[tuple[float, float]]])

Bases: Shape

ExtrudedPolygon.

Class to generate an extruded polygon with a given list of points and a thickness

_images/microgen.shape_5_0.png
generate(**_: KwargsGenerateType) cq.Shape

Generate an extruded polygon CAD shape using the given parameters.

generateVtk(**_: KwargsGenerateType) pv.PolyData

Deprecated. Use generate_vtk() instead.

generate_vtk(**_: KwargsGenerateType) pv.PolyData

Generate an extruded polygon VTK shape using the given parameters.

class microgen.shape.Infill(obj: PolyData, surface_function: Callable[[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]], ndarray[tuple[Any, ...], dtype[float64]]], offset: float | OffsetGrading | Callable[[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]], ndarray[tuple[Any, ...], dtype[float64]]] | None = None, cell_size: float | Sequence[float] | ndarray[tuple[Any, ...], dtype[float64]] | None = None, repeat_cell: int | Sequence[int] | ndarray[tuple[Any, ...], dtype[int8]] | None = None, phase_shift: Sequence[float] = (0.0, 0.0, 0.0), resolution: int = 20, density: float | None = None)

Bases: Tpms

Generate a TPMS infill inside a given object.

class microgen.shape.NormedDistance(obj: PolyData, boundary_offset: float, furthest_offset: float, boundary_weight: float = 1.0)

Bases: OffsetGrading

Compute the offset based on the implicit distance to an object.

compute_offset(grid: pv.UnstructuredGrid | pv.StructuredGrid) npt.NDArray[np.float64]

Compute the offset of the grid.

This method should compute the offset on each point of the grid and return it as a 1D array. The lower_surface and upper_surface fields of the grid will then be updated using this computed offset.

Parameters:

grid (pv.UnstructuredGrid | pv.StructuredGrid) – The grid to compute the offset on.

Returns:

The offset of the grid as a 1D array that matches the number of points in the grid.

Return type:

npt.NDArray[np.float64]

class microgen.shape.Polyhedron(dic: dict[str, list[Vertex | Face]] | None = None, **kwargs: Vector3DType)

Bases: Shape

Class to generate a Polyhedron with a given set of faces and vertices.

_images/microgen.shape_6_0.png
generate(**_: KwargsGenerateType) cq.Shape

Generate a polyhedron CAD shape using the given parameters.

generateVtk(**_: KwargsGenerateType) pv.PolyData

Deprecated method. Use generate_vtk instead.

generate_vtk(**_: KwargsGenerateType) pv.PolyData

Generate a polyhedron VTK shape using the given parameters.

class microgen.shape.Shape(center: Vector3DType = (0, 0, 0), orientation: Vector3DType | Rotation = (0, 0, 0), func: Field | None = None, bounds: BoundsType | None = None)

Bases: object

Unified shape with optional implicit (F-rep) and CAD representations.

Every shape has a center and orientation. It may also carry an implicit scalar field (_func) where f(x, y, z) < 0 means inside. When the implicit field is present, the default generate_vtk() and generate() produce geometry via marching cubes. Subclasses (e.g. Sphere, Tpms) override these methods with their own implementations.

Boolean operators (|, &, -, ~) and smooth boolean methods operate on the implicit field and return a new Shape.

Parameters:
  • center – center of the shape

  • orientation – orientation of the shape

  • func – implicit scalar field (x, y, z) -> array, or None

  • bounds(xmin, xmax, ymin, ymax, zmin, zmax) or None

property bounds: tuple[float, float, float, float, float, float] | None

The bounding box (xmin, xmax, ymin, ymax, zmin, zmax), or None.

evaluate(x: ndarray[tuple[Any, ...], dtype[float64]], y: ndarray[tuple[Any, ...], dtype[float64]], z: ndarray[tuple[Any, ...], dtype[float64]]) ndarray[tuple[Any, ...], dtype[float64]]

Evaluate the implicit scalar field at the given coordinates.

Coordinates are in the field’s local framecenter and orientation are NOT applied here (they only affect mesh output in generate_vtk()). Use translate() / rotate() to bake transforms into the field itself.

Parameters:
  • x – x coordinates

  • y – y coordinates

  • z – z coordinates

Returns:

scalar field values (negative = inside)

property func: Callable[[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]], ndarray[tuple[Any, ...], dtype[float64]]] | None

The implicit scalar field, or None.

generate(bounds: BoundsType | None = None, resolution: int = 50, **_: KwargsGenerateType) cq.Shape

Generate a CAD shape.

The default implementation builds a CadQuery shape from the implicit-field VTK mesh. Subclasses override this with native CAD construction.

Parameters:
  • bounds(xmin, xmax, ymin, ymax, zmin, zmax)

  • resolution – number of grid points per axis

Returns:

CadQuery Shape

generateVtk(**kwargs: KwargsGenerateType) pv.PolyData

Deprecated. Use generate_vtk() instead.

generate_vtk(bounds: BoundsType | None = None, resolution: int = 50, **_: KwargsGenerateType) pv.PolyData

Generate a VTK mesh of the shape.

The default implementation meshes the implicit field via marching cubes (f < 0 convention). Subclasses override this with their own geometry generation.

Parameters:
  • bounds(xmin, xmax, ymin, ymax, zmin, zmax)

  • resolution – number of grid points per axis

Returns:

triangulated surface mesh

require_func() Callable[[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]], ndarray[tuple[Any, ...], dtype[float64]]]

Return _func or raise if not set.

rotate(angles: tuple[float, float, float], convention: str = 'ZXZ') Shape

Return a new shape rotated by Euler angles (degrees, implicit field).

scale(factor: float) Shape

Return a new shape uniformly scaled by factor (implicit field).

smooth_difference(other: Shape, k: float) Shape

Smooth difference with blending radius k.

smooth_intersection(other: Shape, k: float) Shape

Smooth intersection with blending radius k.

smooth_union(other: Shape, k: float) Shape

Smooth union with blending radius k.

translate(offset: tuple[float, float, float]) Shape

Return a new shape translated by offset (implicit field).

class microgen.shape.Sphere(radius: float = 1, **kwargs: Vector3DType)

Bases: Shape

Class to generate a sphere.

_images/microgen.shape_7_0.png
generate(**_: KwargsGenerateType) cq.Shape

Generate a sphere CAD shape using the given parameters.

generateVtk(theta_resolution: int = 50, phi_resolution: int = 50, **_: KwargsGenerateType) pv.PolyData

Deprecated method. Use generate_vtk instead.

generate_vtk(theta_resolution: int = 50, phi_resolution: int = 50, **_: KwargsGenerateType) pv.PolyData

Generate a sphere VTK shape using the given parameters.

class microgen.shape.SphericalTpms(radius: float, surface_function: Field, offset: float | OffsetGrading | Field | None = None, phase_shift: Sequence[float] = (0.0, 0.0, 0.0), cell_size: float | Sequence[float] = 1.0, repeat_cell: int | Sequence[int] = 1, center: Vector3DType = (0, 0, 0), orientation: Vector3DType = (0, 0, 0), resolution: int = 20, density: float | None = None)

Bases: Tpms

Class used to generate spherical TPMS geometries (sheet or skeletals parts).

class microgen.shape.Tpms(surface_function: Field, offset: float | OffsetGrading | Field | None = None, phase_shift: Sequence[float] = (0.0, 0.0, 0.0), cell_size: float | Sequence[float] = 1.0, repeat_cell: int | Sequence[int] = 1, resolution: int = 20, density: float | None = None, **kwargs: Vector3DType)

Bases: Shape

Triply Periodical Minimal Surfaces.

Class to generate Triply Periodical Minimal Surfaces (TPMS) geometry from a given mathematical function, with given offset

functions available :
generate(type_part: TpmsPartType = 'sheet', smoothing: int = 0, algo_resolution: int | None = None, **_: KwargsGenerateType) cq.Shape

Generate CadQuery Shape object of the required TPMS part.

Parameters:
  • type_part – part of the TPMS desired (‘sheet’, ‘lower skeletal’, ‘upper skeletal’ or ‘surface’)

  • smoothing – smoothing loop iterations

  • verbose – display progressbar of the conversion to CadQuery object

  • algo_resolution – if offset must be computed to fit density, resolution of the temporary TPMS used to compute the offset

Returns:

CadQuery Shape object of the required TPMS part

generateVtk(type_part: TpmsPartType = 'sheet', algo_resolution: int | None = None, **_: KwargsGenerateType) pv.PolyData

Deprecated. Use generate_vtk() instead.

generate_grid_vtk(type_part: TpmsPartType = 'sheet', algo_resolution: int | None = None, **_: KwargsGenerateType) pv.UnstructuredGrid

Generate VTK UnstructuredGrid object of the required TPMS part.

generate_vtk(type_part: TpmsPartType = 'sheet', algo_resolution: int | None = None, **_: KwargsGenerateType) pv.PolyData

Generate VTK PolyData object of the required TPMS part.

Parameters:
  • type_part – part of the TPMS desireds

  • algo_resolution – if offset must be computed to fit density, resolution of the temporary TPMS used to compute the offset

Returns:

VTK PolyData object of the required TPMS part

property grid_lower_skeletal: UnstructuredGrid

Return lower skeletal part.

property grid_sheet: UnstructuredGrid

Return sheet part.

property grid_upper_skeletal: UnstructuredGrid

Return upper skeletal part.

property lower_skeletal: PolyData

Return lower skeletal part.

property offset: float | ndarray[tuple[Any, ...], dtype[float64]] | None

Returns the offset value.

classmethod offset_from_density(surface_function: Field, part_type: TpmsPartType, density: float, resolution: int = 20) float

Return the offset corresponding to the required density.

Parameters:
  • surface_function – tpms function

  • part_type – type of the part (sheet, lower skeletal or upper skeletal)

  • density – Required density, 0.5 for 50%

  • resolution – resolution of the tpms used to compute the offset

Returns:

corresponding offset value

property sheet: PolyData

Return sheet part.

property skeletals: tuple[PolyData, PolyData]

Returns both skeletal parts.

property surface: PolyData

Returns isosurface f(x, y, z) = 0.

property upper_skeletal: PolyData

Return upper skeletal part.

microgen.shape.batch_smooth_union(shapes: list[Shape], k: float = 0.0) Shape

Combine many shapes with smooth union in a flat loop (no recursion).

This avoids the recursion-depth limit that arises when chaining hundreds of binary smooth_union calls, each wrapping the previous in a lambda.

microgen.shape.from_field(func: Field, bounds: BoundsType | None = None) Shape

Wrap any callable f(x, y, z) -> scalar as a Shape with an implicit field.

microgen.shape.newGeometry(shape: str, param_geom: dict[str, GeometryParameterType], center: tuple[float, float, float] = (0, 0, 0), orientation: tuple[float, float, float] = (0, 0, 0)) Shape

Create a new basic geometry with given shape and geometrical parameters.

Parameters:
  • shape – name of the geometry

  • param_geom – dictionary with required geometrical parameters

  • center – center

  • orientation – orientation

Return geometry:

Shape

microgen.shape.new_geometry(shape: str, param_geom: dict[str, GeometryParameterType], center: tuple[float, float, float] = (0, 0, 0), orientation: tuple[float, float, float] = (0, 0, 0)) Shape

Create a new basic geometry with given shape and geometrical parameters.

Parameters:
  • shape – name of the geometry

  • param_geom – dictionary with required geometrical parameters

  • center – center

  • orientation – orientation

Return geometry:

Shape

Basic Geometry.

Basic Geometry (microgen.shape.shape)

class microgen.shape.shape.Shape(center: Vector3DType = (0, 0, 0), orientation: Vector3DType | Rotation = (0, 0, 0), func: Field | None = None, bounds: BoundsType | None = None)

Bases: object

Unified shape with optional implicit (F-rep) and CAD representations.

Every shape has a center and orientation. It may also carry an implicit scalar field (_func) where f(x, y, z) < 0 means inside. When the implicit field is present, the default generate_vtk() and generate() produce geometry via marching cubes. Subclasses (e.g. Sphere, Tpms) override these methods with their own implementations.

Boolean operators (|, &, -, ~) and smooth boolean methods operate on the implicit field and return a new Shape.

Parameters:
  • center – center of the shape

  • orientation – orientation of the shape

  • func – implicit scalar field (x, y, z) -> array, or None

  • bounds(xmin, xmax, ymin, ymax, zmin, zmax) or None

property bounds: tuple[float, float, float, float, float, float] | None

The bounding box (xmin, xmax, ymin, ymax, zmin, zmax), or None.

evaluate(x: ndarray[tuple[Any, ...], dtype[float64]], y: ndarray[tuple[Any, ...], dtype[float64]], z: ndarray[tuple[Any, ...], dtype[float64]]) ndarray[tuple[Any, ...], dtype[float64]]

Evaluate the implicit scalar field at the given coordinates.

Coordinates are in the field’s local framecenter and orientation are NOT applied here (they only affect mesh output in generate_vtk()). Use translate() / rotate() to bake transforms into the field itself.

Parameters:
  • x – x coordinates

  • y – y coordinates

  • z – z coordinates

Returns:

scalar field values (negative = inside)

property func: Callable[[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]], ndarray[tuple[Any, ...], dtype[float64]]] | None

The implicit scalar field, or None.

generate(bounds: BoundsType | None = None, resolution: int = 50, **_: KwargsGenerateType) cq.Shape

Generate a CAD shape.

The default implementation builds a CadQuery shape from the implicit-field VTK mesh. Subclasses override this with native CAD construction.

Parameters:
  • bounds(xmin, xmax, ymin, ymax, zmin, zmax)

  • resolution – number of grid points per axis

Returns:

CadQuery Shape

generateVtk(**kwargs: KwargsGenerateType) pv.PolyData

Deprecated. Use generate_vtk() instead.

generate_vtk(bounds: BoundsType | None = None, resolution: int = 50, **_: KwargsGenerateType) pv.PolyData

Generate a VTK mesh of the shape.

The default implementation meshes the implicit field via marching cubes (f < 0 convention). Subclasses override this with their own geometry generation.

Parameters:
  • bounds(xmin, xmax, ymin, ymax, zmin, zmax)

  • resolution – number of grid points per axis

Returns:

triangulated surface mesh

require_func() Callable[[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]], ndarray[tuple[Any, ...], dtype[float64]]]

Return _func or raise if not set.

rotate(angles: tuple[float, float, float], convention: str = 'ZXZ') Shape

Return a new shape rotated by Euler angles (degrees, implicit field).

scale(factor: float) Shape

Return a new shape uniformly scaled by factor (implicit field).

smooth_difference(other: Shape, k: float) Shape

Smooth difference with blending radius k.

smooth_intersection(other: Shape, k: float) Shape

Smooth intersection with blending radius k.

smooth_union(other: Shape, k: float) Shape

Smooth union with blending radius k.

translate(offset: tuple[float, float, float]) Shape

Return a new shape translated by offset (implicit field).

exception microgen.shape.shape.ShellCreationError

Bases: Exception

Raised when a CadQuery shell cannot be created from a mesh.

Box.

Box (microgen.shape.box)

class microgen.shape.box.Box(dim: tuple[float, float, float] = (1, 1, 1), dim_x: float | None = None, dim_y: float | None = None, dim_z: float | None = None, **kwargs: Vector3DType)

Bases: Shape

Class to generate a box.

_images/microgen.shape_8_0.png
generate(**_: KwargsGenerateType) cq.Shape

Generate a box CAD shape using the given parameters.

generateVtk(**kwargs: KwargsGenerateType) pv.PolyData

Deprecated. Use generate_vtk() instead.

generate_vtk(level: int = 0, **_: KwargsGenerateType) pv.PolyData

Generate a box VTK shape using the given parameters.

Capsule.

Capsule (microgen.shape.capsule)

class microgen.shape.capsule.Capsule(height: float = 1, radius: float = 0.5, **kwargs: Vector3DType)

Bases: Shape

Class to generate a capsule (cylinder with hemispherical ends).

_images/microgen.shape_9_0.png
generate(**_: KwargsGenerateType) cq.Shape

Generate a capsule CAD shape using the given parameters.

generateVtk(resolution: int = 100, theta_resolution: int = 50, phi_resolution: int = 50, **_: KwargsGenerateType) pv.PolyData

Deprecated. Use generate_vtk() instead.

generate_vtk(resolution: int = 100, theta_resolution: int = 50, phi_resolution: int = 50, **_: KwargsGenerateType) pv.PolyData

Generate a capsule VTK shape using the given parameters.

Cylinder.

Cylinder (microgen.shape.cylinder)

class microgen.shape.cylinder.Cylinder(height: float = 1, radius: float = 0.5, **kwargs: Vector3DType)

Bases: Shape

Class to generate a cylinder.

_images/microgen.shape_10_0.png
generate(**_: KwargsGenerateType) cq.Shape

Generate a cylinder CAD shape using the given parameters.

generateVtk(resolution: int = 100, **kwargs: KwargsGenerateType) pv.PolyData

Deprecated. Use generate_vtk() instead.

generate_vtk(resolution: int = 100, **_: KwargsGenerateType) pv.PolyData

Generate a cylinder VTK shape using the given parameters.

Ellipsoid.

Ellipsoid (microgen.shape.ellipsoid)

class microgen.shape.ellipsoid.Ellipsoid(radii: tuple[float, float, float] = (1, 0.5, 0.25), a_x: float | None = None, a_y: float | None = None, a_z: float | None = None, **kwargs: Vector3DType)

Bases: Shape

Class to generate an ellipsoid.

_images/microgen.shape_11_0.png
generate(**_: KwargsGenerateType) cq.Shape

Generate an ellipsoid CAD shape using the given parameters.

generateVtk(**_: KwargsGenerateType) pv.PolyData

Deprecated. Use generate_vtk() instead.

generate_vtk(**_: KwargsGenerateType) pv.PolyData

Generate an ellipsoid VTK polydta using the given parameters.

Extruded Polygon.

Extruded Polygon (microgen.shape.extruded_polygon)

class microgen.shape.extruded_polygon.ExtrudedPolygon(list_corners: Sequence[tuple[float, float]] | None = None, height: float = 1, **kwargs: Vector3DType | dict[str, Sequence[tuple[float, float]]])

Bases: Shape

ExtrudedPolygon.

Class to generate an extruded polygon with a given list of points and a thickness

_images/microgen.shape_12_0.png
generate(**_: KwargsGenerateType) cq.Shape

Generate an extruded polygon CAD shape using the given parameters.

generateVtk(**_: KwargsGenerateType) pv.PolyData

Deprecated. Use generate_vtk() instead.

generate_vtk(**_: KwargsGenerateType) pv.PolyData

Generate an extruded polygon VTK shape using the given parameters.

Polyhedron.

Polyhedron (microgen.shape.polyhedron)

class microgen.shape.polyhedron.Polyhedron(dic: dict[str, list[Vertex | Face]] | None = None, **kwargs: Vector3DType)

Bases: Shape

Class to generate a Polyhedron with a given set of faces and vertices.

_images/microgen.shape_13_0.png
generate(**_: KwargsGenerateType) cq.Shape

Generate a polyhedron CAD shape using the given parameters.

generateVtk(**_: KwargsGenerateType) pv.PolyData

Deprecated method. Use generate_vtk instead.

generate_vtk(**_: KwargsGenerateType) pv.PolyData

Generate a polyhedron VTK shape using the given parameters.

microgen.shape.polyhedron.read_obj(filename: str) dict[str, list[Tuple[float, float, float] | Dict[str, List[int]]]]

Read vertices and faces from obj format file for polyhedron.

Sphere.

Sphere (microgen.shape.sphere)

class microgen.shape.sphere.Sphere(radius: float = 1, **kwargs: Vector3DType)

Bases: Shape

Class to generate a sphere.

_images/microgen.shape_14_0.png
generate(**_: KwargsGenerateType) cq.Shape

Generate a sphere CAD shape using the given parameters.

generateVtk(theta_resolution: int = 50, phi_resolution: int = 50, **_: KwargsGenerateType) pv.PolyData

Deprecated method. Use generate_vtk instead.

generate_vtk(theta_resolution: int = 50, phi_resolution: int = 50, **_: KwargsGenerateType) pv.PolyData

Generate a sphere VTK shape using the given parameters.

TPMS.

TPMS (microgen.shape.tpms)

class microgen.shape.tpms.CylindricalTpms(radius: float, surface_function: Field, offset: float | OffsetGrading | Field | None = None, phase_shift: Sequence[float] = (0.0, 0.0, 0.0), cell_size: float | Sequence[float] = 1.0, repeat_cell: int | Sequence[int] = 1, center: Vector3DType = (0, 0, 0), orientation: Vector3DType = (0, 0, 0), resolution: int = 20, density: float | None = None)

Bases: Tpms

Class used to generate cylindrical TPMS geometries (sheet or skeletals parts).

class microgen.shape.tpms.Infill(obj: PolyData, surface_function: Callable[[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]], ndarray[tuple[Any, ...], dtype[float64]]], offset: float | OffsetGrading | Callable[[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]], ndarray[tuple[Any, ...], dtype[float64]]] | None = None, cell_size: float | Sequence[float] | ndarray[tuple[Any, ...], dtype[float64]] | None = None, repeat_cell: int | Sequence[int] | ndarray[tuple[Any, ...], dtype[int8]] | None = None, phase_shift: Sequence[float] = (0.0, 0.0, 0.0), resolution: int = 20, density: float | None = None)

Bases: Tpms

Generate a TPMS infill inside a given object.

exception microgen.shape.tpms.ShellCreationError

Bases: Exception

Raised when a CadQuery shell cannot be created from a mesh.

class microgen.shape.tpms.SphericalTpms(radius: float, surface_function: Field, offset: float | OffsetGrading | Field | None = None, phase_shift: Sequence[float] = (0.0, 0.0, 0.0), cell_size: float | Sequence[float] = 1.0, repeat_cell: int | Sequence[int] = 1, center: Vector3DType = (0, 0, 0), orientation: Vector3DType = (0, 0, 0), resolution: int = 20, density: float | None = None)

Bases: Tpms

Class used to generate spherical TPMS geometries (sheet or skeletals parts).

class microgen.shape.tpms.Tpms(surface_function: Field, offset: float | OffsetGrading | Field | None = None, phase_shift: Sequence[float] = (0.0, 0.0, 0.0), cell_size: float | Sequence[float] = 1.0, repeat_cell: int | Sequence[int] = 1, resolution: int = 20, density: float | None = None, **kwargs: Vector3DType)

Bases: Shape

Triply Periodical Minimal Surfaces.

Class to generate Triply Periodical Minimal Surfaces (TPMS) geometry from a given mathematical function, with given offset

functions available :
generate(type_part: TpmsPartType = 'sheet', smoothing: int = 0, algo_resolution: int | None = None, **_: KwargsGenerateType) cq.Shape

Generate CadQuery Shape object of the required TPMS part.

Parameters:
  • type_part – part of the TPMS desired (‘sheet’, ‘lower skeletal’, ‘upper skeletal’ or ‘surface’)

  • smoothing – smoothing loop iterations

  • verbose – display progressbar of the conversion to CadQuery object

  • algo_resolution – if offset must be computed to fit density, resolution of the temporary TPMS used to compute the offset

Returns:

CadQuery Shape object of the required TPMS part

generateVtk(type_part: TpmsPartType = 'sheet', algo_resolution: int | None = None, **_: KwargsGenerateType) pv.PolyData

Deprecated. Use generate_vtk() instead.

generate_grid_vtk(type_part: TpmsPartType = 'sheet', algo_resolution: int | None = None, **_: KwargsGenerateType) pv.UnstructuredGrid

Generate VTK UnstructuredGrid object of the required TPMS part.

generate_vtk(type_part: TpmsPartType = 'sheet', algo_resolution: int | None = None, **_: KwargsGenerateType) pv.PolyData

Generate VTK PolyData object of the required TPMS part.

Parameters:
  • type_part – part of the TPMS desireds

  • algo_resolution – if offset must be computed to fit density, resolution of the temporary TPMS used to compute the offset

Returns:

VTK PolyData object of the required TPMS part

property grid_lower_skeletal: UnstructuredGrid

Return lower skeletal part.

property grid_sheet: UnstructuredGrid

Return sheet part.

property grid_upper_skeletal: UnstructuredGrid

Return upper skeletal part.

property lower_skeletal: PolyData

Return lower skeletal part.

property offset: float | ndarray[tuple[Any, ...], dtype[float64]] | None

Returns the offset value.

classmethod offset_from_density(surface_function: Field, part_type: TpmsPartType, density: float, resolution: int = 20) float

Return the offset corresponding to the required density.

Parameters:
  • surface_function – tpms function

  • part_type – type of the part (sheet, lower skeletal or upper skeletal)

  • density – Required density, 0.5 for 50%

  • resolution – resolution of the tpms used to compute the offset

Returns:

corresponding offset value

property sheet: PolyData

Return sheet part.

property skeletals: tuple[PolyData, PolyData]

Returns both skeletal parts.

property surface: PolyData

Returns isosurface f(x, y, z) = 0.

property upper_skeletal: PolyData

Return upper skeletal part.

F-rep Implicit Operations.

Implicit Operations (microgen.shape.implicit_ops)

Module-level boolean, blending, and utility operations for shapes that carry an implicit scalar field (_func). All functions accept and return Shape instances.

microgen.shape.implicit_ops.batch_smooth_union(shapes: list[Shape], k: float = 0.0) Shape

Combine many shapes with smooth union in a flat loop (no recursion).

This avoids the recursion-depth limit that arises when chaining hundreds of binary smooth_union calls, each wrapping the previous in a lambda.

microgen.shape.implicit_ops.blend(a: Shape, b: Shape, factor: float = 0.5) Shape

Linear interpolation between two fields: (1-t)*a + t*b.

microgen.shape.implicit_ops.complement(a: Shape) Shape

Complement (negate the field): inside becomes outside and vice versa.

microgen.shape.implicit_ops.difference(a: Shape, b: Shape) Shape

Difference of two shapes (a minus b).

microgen.shape.implicit_ops.from_field(func: Field, bounds: BoundsType | None = None) Shape

Wrap any callable f(x, y, z) -> scalar as a Shape with an implicit field.

microgen.shape.implicit_ops.intersection(a: Shape, b: Shape) Shape

Intersection of two shapes (hard boolean).

microgen.shape.implicit_ops.normalize_to_sdf(shape: Shape, epsilon: float = 1e-10) Shape

Return a new Shape with gradient-normalized SDF field: f / |nabla f|.

Uses autograd for exact analytical gradients when the field function is differentiable through autograd.numpy. Falls back to central finite differences otherwise.

Parameters:
  • shape – shape whose implicit field to normalize

  • epsilon – floor for gradient magnitude (avoids division by zero at saddle points)

microgen.shape.implicit_ops.repeat(shape: Shape, spacing: tuple[float, float, float], k: float = 0.0) Shape

Infinite repetition via coordinate modulo.

Parameters:
  • shape – unit cell shape to tile

  • spacing(sx, sy, sz) repetition period per axis

  • k – smooth blending radius across cell boundaries. When k > 0, the base field is evaluated at the 26 neighboring periodic images in addition to the current cell and all values are combined with smooth minimum, so that primitives from adjacent cells blend seamlessly. When k <= 0 (default), a simple coordinate-modulo repetition is used (hard tiling).

microgen.shape.implicit_ops.shell(shape: Shape, thickness: float) Shape

Hollow shell: |f(p)| - thickness / 2.

microgen.shape.implicit_ops.smooth_difference(a: Shape, b: Shape, k: float) Shape

Smooth difference (a minus b) with blending radius k.

microgen.shape.implicit_ops.smooth_intersection(a: Shape, b: Shape, k: float) Shape

Smooth intersection with blending radius k.

microgen.shape.implicit_ops.smooth_union(a: Shape, b: Shape, k: float) Shape

Smooth union with blending radius k.

microgen.shape.implicit_ops.union(a: Shape, b: Shape) Shape

Union of two shapes (hard boolean).

microgen.shape.implicit_ops.variable_shell(shape: Shape, thickness_func: Field) Shape

Shell with spatially-varying thickness: |f(p)| - t(p)/2.

Parameters:
  • shape – shape whose implicit field defines the surface

  • thickness_func – callable (x, y, z) -> thickness returning the local shell thickness

TPMS surface functions.

microgen.shape.surface_functions.fischerKochS(x: ndarray, y: ndarray, z: ndarray) ndarray

Fischer-Koch S.

\[cos(2 x) sin(y) cos(z) + cos(x) cos(2 y) sin(z) + sin(x) cos(y) cos(2 z) = 0\]
_images/microgen.shape_16_1.png
microgen.shape.surface_functions.fischer_koch_s(x: ndarray, y: ndarray, z: ndarray) ndarray

Fischer-Koch S.

\[cos(2 x) sin(y) cos(z) + cos(x) cos(2 y) sin(z) + sin(x) cos(y) cos(2 z) = 0\]
_images/microgen.shape_17_1.png
microgen.shape.surface_functions.gyroid(x: ndarray, y: ndarray, z: ndarray) ndarray

Gyroid.

\[sin(x) cos(y) + sin(y) cos(z) + sin(z) cos(x) = 0\]
_images/microgen.shape_18_1.png
microgen.shape.surface_functions.honeycomb(x: ndarray, y: ndarray, z: ndarray) ndarray

Honneycomb.

\[sin(x) cos(y) + sin(y) + cos(z) = 0\]
_images/microgen.shape_19_1.png
microgen.shape.surface_functions.honeycomb_gyroid(x: float, y: float, _: float) float

Honeycomb Gyroid.

\[sin(x) cos(y) + sin(y) + cos(x) = 0\]
_images/microgen.shape_20_1.png
microgen.shape.surface_functions.honeycomb_lidinoid(x: float, y: float, _: float) float

Honeycomb Lidinoid.

\[1.1 (sin(2 x) cos(y) + sin(2 y) sin(x) + cos(x) sin(y)) - (cos(2 x) cos(2 y) + cos(2 y) + cos(2 x)) = 0\]
_images/microgen.shape_21_1.png
microgen.shape.surface_functions.honeycomb_schoenIWP(x: float, y: float, _: float) float

Honneycomb Schoen IWP.

\[cos(x) cos(y) + cos(y) + cos(x) = 0\]
_images/microgen.shape_22_1.png
microgen.shape.surface_functions.honeycomb_schoen_iwp(x: float, y: float, _: float) float

Honneycomb Schoen IWP.

\[cos(x) cos(y) + cos(y) + cos(x) = 0\]
_images/microgen.shape_23_1.png
microgen.shape.surface_functions.honeycomb_schwarzD(x: float, y: float, _: float) float

Honneycomb Schwarz D.

\[cos(x) cos(y) + sin(x) sin(y) + sin(x) cos(y) + cos(x) sin(y) = 0\]
_images/microgen.shape_24_1.png
microgen.shape.surface_functions.honeycomb_schwarzP(x: float, y: float, _: float) float

Honeycomb Schwarz P.

\[cos(x) + cos(y) = 0\]
_images/microgen.shape_25_1.png
microgen.shape.surface_functions.honeycomb_schwarz_d(x: float, y: float, _: float) float

Honneycomb Schwarz D.

\[cos(x) cos(y) + sin(x) sin(y) + sin(x) cos(y) + cos(x) sin(y) = 0\]
_images/microgen.shape_26_1.png
microgen.shape.surface_functions.honeycomb_schwarz_p(x: float, y: float, _: float) float

Honeycomb Schwarz P.

\[cos(x) + cos(y) = 0\]
_images/microgen.shape_27_1.png
microgen.shape.surface_functions.lidinoid(x: ndarray, y: ndarray, z: ndarray) ndarray

Lidinoid.

\[0.5 (sin(2 x) cos(y) sin(z) + sin(2 y) cos(z) sin(x) + sin(2 z) cos(x) sin(y)) - 0.5 (cos(2 x) cos(2 y) + cos(2 y) cos(2 z) + cos(2 z) cos(2 x)) + 0.3 = 0\]
_images/microgen.shape_28_1.png
microgen.shape.surface_functions.neovius(x: ndarray, y: ndarray, z: ndarray) ndarray

Neovius.

\[3 cos(x) + cos(y) + cos(z) + 4 cos(x) cos(y) cos(z) = 0\]
_images/microgen.shape_29_1.png
microgen.shape.surface_functions.pmy(x: ndarray, y: ndarray, z: ndarray) ndarray

PMY.

\[2 cos(x) cos(y) cos(z) + sin(2 x) sin(y) + sin(x) sin(2 z) + sin(2 y) sin(z) = 0\]
_images/microgen.shape_30_1.png
microgen.shape.surface_functions.schoenFRD(x: ndarray, y: ndarray, z: ndarray) ndarray

Schoen FRD.

\[4 cos(x) cos(y) cos(z) - (cos(2 x) cos(2 y) + cos(2 y) cos(2 z) + cos(2 z) cos(2 x)) = 0\]
_images/microgen.shape_31_1.png
microgen.shape.surface_functions.schoenIWP(x: ndarray, y: ndarray, z: ndarray) ndarray

Schoen IWP.

\[2 (cos(x) cos(y) + cos(y) cos(z) + cos(z) cos(x)) - (cos(2 x) + cos(2 y) + cos(2 z)) = 0\]
_images/microgen.shape_32_1.png
microgen.shape.surface_functions.schoen_frd(x: ndarray, y: ndarray, z: ndarray) ndarray

Schoen FRD.

\[4 cos(x) cos(y) cos(z) - (cos(2 x) cos(2 y) + cos(2 y) cos(2 z) + cos(2 z) cos(2 x)) = 0\]
_images/microgen.shape_33_1.png
microgen.shape.surface_functions.schoen_iwp(x: ndarray, y: ndarray, z: ndarray) ndarray

Schoen IWP.

\[2 (cos(x) cos(y) + cos(y) cos(z) + cos(z) cos(x)) - (cos(2 x) + cos(2 y) + cos(2 z)) = 0\]
_images/microgen.shape_34_1.png
microgen.shape.surface_functions.schwarzD(x: ndarray, y: ndarray, z: ndarray) ndarray

Schwarz D.

\[sin(x) sin(y) sin(z) + sin(x) cos(y) cos(z) + cos(x) sin(y) cos(z) + cos(x) cos(y) sin(z) = 0\]
_images/microgen.shape_35_1.png
microgen.shape.surface_functions.schwarzP(x: ndarray, y: ndarray, z: ndarray) ndarray

Schwarz P.

\[cos(x) + cos(y) + cos(z) = 0\]
_images/microgen.shape_36_1.png
microgen.shape.surface_functions.schwarz_d(x: ndarray, y: ndarray, z: ndarray) ndarray

Schwarz D.

\[sin(x) sin(y) sin(z) + sin(x) cos(y) cos(z) + cos(x) sin(y) cos(z) + cos(x) cos(y) sin(z) = 0\]
_images/microgen.shape_37_1.png
microgen.shape.surface_functions.schwarz_p(x: ndarray, y: ndarray, z: ndarray) ndarray

Schwarz P.

\[cos(x) + cos(y) + cos(z) = 0\]
_images/microgen.shape_38_1.png
microgen.shape.surface_functions.split_p(x: ndarray, y: ndarray, z: ndarray) ndarray

Split P.

\[1.1 (sin(2 x) cos(y) sin(z) + sin(2 y) cos(z) sin(x) + sin(2 z) cos(x) sin(y)) - 0.2 (cos(2 x) cos(2 y) + cos(2 y) cos(2 z) + cos(2 z) cos(2 x)) - 0.4 (cos(2 x) + cos(2 y) + cos(2 z)) = 0\]
_images/microgen.shape_39_1.png