Skip to content

Feature/implicit voronoi lattice#143

Open
chemiskyy wants to merge 10 commits into
mainfrom
feature/implicit_voronoi_lattice
Open

Feature/implicit voronoi lattice#143
chemiskyy wants to merge 10 commits into
mainfrom
feature/implicit_voronoi_lattice

Conversation

@chemiskyy
Copy link
Copy Markdown
Member

This pull request introduces a new CAD backend for microgen, replacing CadQuery with direct OCP (OCCT) calls, and updates example scripts to use the new backend API. The main changes include adding a well-structured microgen.cad package with clear separation of concerns, providing factory functions for CAD primitives, and updating all example usages to the new Phase.from_cad and .cad API. This modernizes the codebase, improves modularity, and ensures a smoother user experience for CAD operations.

CAD Backend Introduction and API Modernization

  • Added a new microgen.cad subpackage as a direct OCCT backend, replacing CadQuery. This includes a comprehensive __init__.py that re-exports all public symbols, ensuring backward compatibility for imports.
  • Added an install gate (_install.py) with a require_cad() function to lazily check for the OCP dependency and provide user-friendly error messages if missing.
  • Added a standalone STEP file import function in io.py for reading CAD files, with export methods now living on the CadShape class.
  • Added a set of factory functions in primitives.py for creating basic CAD shapes (box, sphere, cylinder, capsule, ellipsoid, polyhedron, extruded polygon) as CadShape instances, serving as the new backend for implicit shape classes.

Example Script Updates

  • Updated all example scripts under examples/3Doperations and examples/Lattices to use Phase.from_cad instead of Phase(shape=...), and to access the CAD object via .cad instead of .shape. This ensures compatibility with the new backend and API. [1] [2] [3] [4] [5] [6]

These changes collectively provide a more robust, modular, and user-friendly CAD interface for microgen, with improved error handling and future extensibility.

chemiskyy added 10 commits May 21, 2026 18:52
Make Shape.generate_surface_mesh polymorphic for Box, Sphere and Spinodoid by accepting optional bounds/resolution and falling back to the SDF/marching-cubes path when callers request explicit sampling. Add BoundsType imports and update docstrings to explain the behavior. Remove the legacy rotate_pv_euler function and its export from operations/__init__ (cleanup of Euler helper). Tidy Rve by removing unused is_matrix/matrix_number defaults. Expose new TPMS-related classes (GradedInfill, Sweep) in shape exports and update __all__ accordingly. Add a lint test (tests/test_no_top_level_ocp_imports.py) to prevent top-level OCP imports outside the CAD boundary.
Make Rve a frozen dataclass with validated inputs and explicit pbc flags. Introduce helper validators, cached min_point/max_point and a cached box property (lazy CAD box creation). Add Rve.grid(...) to produce a pyvista.StructuredGrid with flexible resolution handling. Improve __repr__ and update from_min_max to accept pbc. Expand tests to cover pbc behavior, immutability, min/max consistency, grid generation, invalid inputs, and repr content.
Introduce shared shape type aliases and an intrinsic period attribute, and add a generic CAD bridge and periodic-shell sewing.

- Add microgen/shape/_types.py with Field, BoundsType and PeriodType aliases to centralize type defs.
- Add microgen/shape/periodic_shell.py: mesh_to_periodic_shell builds sewn OCCT shells with planar cap faces for periodic meshes.
- Add shape_to_cad in microgen/cad.py: generic fallback to build a tessellated CadShape from an implicit Shape.
- Update microgen/shape/shape.py: import shared types, add Shape.period property, and delegate default generate_cad to shape_to_cad.
- Update Tpms and Spinodoid to set their intrinsic _period and reuse mesh_to_periodic_shell; remove duplicated periodic-sewing code.
- Add tests/tests_shapes/test_shape_period.py to verify period behavior and periodicity for Tpms/Spinodoid.

These changes centralize type annotations, avoid duplicated sewing logic, and expose intrinsic periodicity as a data-structure invariant used by TPMS/Spinodoid shapes. The periodic shell code requires the optional CAD backend.
Replace the single monolithic microgen/cad.py with a microgen.cad subpackage. The functionality has been split across new modules: __init__.py, _install.py, io.py, meshbridge.py, primitives.py, shape.py and topo.py to isolate responsibilities and enable lazy OCP imports (OCP remains an optional dependency). Tests were updated to reflect the package layout (no top-level OCP import). This reorganization improves maintainability and ensures import-time safety when OCP is not installed.
Introduce shared shape type aliases and an intrinsic period attribute, and add a generic CAD bridge and periodic-shell sewing.

- Add microgen/shape/_types.py with Field, BoundsType and PeriodType aliases to centralize type defs.
- Add microgen/shape/periodic_shell.py: mesh_to_periodic_shell builds sewn OCCT shells with planar cap faces for periodic meshes.
- Add shape_to_cad in microgen/cad.py: generic fallback to build a tessellated CadShape from an implicit Shape.
- Update microgen/shape/shape.py: import shared types, add Shape.period property, and delegate default generate_cad to shape_to_cad.
- Update Tpms and Spinodoid to set their intrinsic _period and reuse mesh_to_periodic_shell; remove duplicated periodic-sewing code.
- Add tests/tests_shapes/test_shape_period.py to verify period behavior and periodicity for Tpms/Spinodoid.

These changes centralize type annotations, avoid duplicated sewing logic, and expose intrinsic periodicity as a data-structure invariant used by TPMS/Spinodoid shapes. The periodic shell code requires the optional CAD backend.
Replace the single monolithic microgen/cad.py with a microgen.cad subpackage. The functionality has been split across new modules: __init__.py, _install.py, io.py, meshbridge.py, primitives.py, shape.py and topo.py to isolate responsibilities and enable lazy OCP imports (OCP remains an optional dependency). Tests were updated to reflect the package layout (no top-level OCP import). This reorganization improves maintainability and ensures import-time safety when OCP is not installed.
Large refactor of Phase to an implicit-first, CAD-optional design (Phase 2.0). Introduced Phase.from_cad/from_shape/from_mesh, lazy cad materialisation (.cad), piece extraction, PyVista-backed grid/mesh views, cached moments (center_of_mass, inertia_matrix), and immutable transform methods. Updated mesh/operations/periodic code to use the new Phase API (use phase.cad, Phase.from_cad, and new helpers), added _split_cad_in_grid and improved raster/repeat logic. Added _phase_solid_count in mesh to correctly account for CAD solids. Updated many examples and tests to match the new API and added a new test (tests/test_phase_pieces.py). Overall: unify implicit and CAD workflows, isolate CAD seam, and make Phase behaviour more robust and lazy.
Use 26-connectivity when extracting connected pieces from implicit fields in Phase to avoid fragmenting convex shapes (generate_binary_structure(3,3)).

Implement a convex half-space intersection SDF for Polyhedron: compute world-frame face normals and centroids, bake transforms into a cached _func and _bounds (f(p)=max_k n_k·(p−c_k)). This enables implicit-first workflows for Voronoi cells.

Add AbstractLattice.generate_implicit which composes strut Cylinders and optional Sphere joints into a single implicit Shape (union) clipped by the cell Box, allowing marching-cubes / grid-based processing without CAD.

Add tests (tests/test_implicit_voronoi_lattice.py) validating polyhedron SDF signs, phase volume/COM, and implicit lattice connectivity/volume/COM behavior.
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