Skip to content

Feature/implicit shapes#116

Draft
chemiskyy wants to merge 12 commits intomainfrom
feature/implicit_shapes
Draft

Feature/implicit shapes#116
chemiskyy wants to merge 12 commits intomainfrom
feature/implicit_shapes

Conversation

@chemiskyy
Copy link
Member

This pull request adds comprehensive support and documentation for implicit (F-rep) shape modeling in the microgen library. It introduces new example scripts, expands the documentation with detailed tutorials and API references for implicit shapes, and updates the package's public API to expose new implicit modeling utilities and classes.

Documentation Enhancements:

  • Added a new documentation page implicit_shapes.rst with worked examples and images for primitives, boolean operations, lattices, and trabecular bone using implicit modeling.
  • Expanded the main tutorial (tutorials.rst) with a new section on implicit shapes, covering conversion, boolean operations, smooth blending, transforms, utilities, and TPMS composition, including executable code blocks.
  • Updated the table of contents and API references to include implicit shape modules and their members. [1] [2]

New Example Scripts:

  • Added primitives_and_booleans.py demonstrating creation and visualization of implicit primitives, boolean operations, smooth blending, and batch smooth union.
  • Added implicit_lattice.py showing construction of BCC, Octet-Truss, and Cubic lattices using implicit capsules and smooth unions, with comparison to strut lattices and smoothness parameter sweeps.
  • Added trabecular_bone.py for generating a Voronoi-based trabecular bone structure using implicit capsules and spheres, combined with smooth union and intersection.

API and Package Updates:

  • Exposed ImplicitShape, batch_smooth_union, implicit_shape, and implicit_basic_factory in the main microgen and microgen.shape modules and updated their __all__ lists for public API access. [1] [2] [3] [4] [5] [6] [7]

Add the implicit_shape module to the shape package and re-export ImplicitShape, the implicit_shape symbol, and batch_smooth_union at the microgen top-level. Update imports and __all__ in microgen/__init__.py and microgen/shape/__init__.py so implicit shapes and the batch smoothing helper are publicly available.
Add documentation for the implicit shapes (F-rep) feature: a new examples page (docs/examples/implicit_shapes.rst) with included example scripts and images, and a comprehensive tutorials section (docs/tutorials.rst) demonstrating primitives, booleans, smooth blending, batch union, transforms, utilities, and TPMS composition with runnable Jupyter cells. Also expose microgen.shape.implicit_shape in the API docs (docs/microgen.shape.rst) and add the new examples page to the docs index (docs/index.rst). This surfaces the new implicit_shape API and usage patterns for users.
Add three new example scripts demonstrating the F-rep implicit modeling utilities and comparisons to strut lattices.

- examples/ImplicitShapes/primitives_and_booleans.py: Shows primitive implicit shapes (sphere, box, capsule), hard boolean ops (union, intersection, difference) and smooth blending, plus a batch smooth-union demo combining many spheres.
- examples/ImplicitShapes/trabecular_bone.py: Generates a Voronoi-based trabecular-bone-like scaffold (with optional Lloyd relaxation), builds capsules and joint spheres from Voronoi edges/vertices, combines them with batch smooth union and intersects with a clip box, then meshes for visualization.
- examples/Lattices/implicit_lattice.py: Builds implicit cubic, BCC and octet-truss lattices from capsule/sphere primitives (batch smooth union), compares implicit vs original strut meshes, and sweeps the smoothness parameter k for visual comparison.

Examples rely on numpy, pyvista, scipy.spatial.Voronoi and the microgen implicit-shape utilities for construction and visualization.
Add implicit_basic_factory to the shape package and the top-level microgen package exports. The change imports implicit_basic_factory in microgen/shape/__init__.py and microgen/__init__.py and appends it to their __all__ lists so the factory is publicly available from both microgen.shape and the top-level microgen namespace.
Introduce a new implicit primitive factory and wire shape-to-implicit conversions. Adds microgen/shape/implicit_basic_factory.py implementing ImplicitShape factories (implicit_sphere, implicit_box, implicit_cylinder, implicit_plane, implicit_torus, implicit_capsule, implicit_ellipsoid) as SDF-based functions with reasonable bounds. Adds to_implicit methods to Box, Capsule, Cylinder and Ellipsoid that build the corresponding ImplicitShape, apply orientation (as ZXZ Euler angles) and translation. Also updates TYPE_CHECKING imports to reference ImplicitShape. Useful for converting existing geometric shapes to implicit fields for sampling/boolean ops.
Change Tpms to inherit from ImplicitShape (import implicit_shape.ImplicitShape) and initialize implicit-interface attributes for compatibility. The constructor now sets self._func as a lambda wrapping surface_function with k_x/k_y/k_z scaling and phase shifts, and computes self._bounds from cell_size and repeat_cell. This enables Tpms instances to be used where an implicit field/bounds are expected.
@chemiskyy chemiskyy requested a review from ylgrst February 24, 2026 14:02
@chemiskyy chemiskyy marked this pull request as draft February 24, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant