Refactor/phase#142
Open
chemiskyy wants to merge 9 commits into
Open
Conversation
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.
…o refactor/shape
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new CAD backend for the project, replacing CadQuery with direct OCP (OpenCASCADE) calls through the new
microgen.cadsubpackage. The changes refactor example scripts to use the new CAD interface and add a comprehensive set of CAD utilities and primitives. The update also ensures that the CAD backend is an optional dependency, loaded only when needed, and provides user-friendly error messages if the dependency is missing.The most important changes are:
Introduction of the new CAD backend:
microgen.cadsubpackage, which provides a direct OCP-based CAD backend as a replacement for CadQuery. This includes a newCadShapewrapper class, primitive shape builders, STEP file I/O, and various CAD utility functions, all re-exported throughmicrogen/cad/__init__.py.require_cad) inmicrogen/cad/_install.pyto check for the optional OCP dependency and provide clear installation instructions if it's missing.CAD primitives and utility functions:
microgen/cad/primitives.pyfor creating core parametric primitives (box, sphere, cylinder, capsule, ellipsoid, polyhedron, extruded polygon), all returningCadShapeinstances.import_stepinmicrogen/cad/io.py, complementing export methods now available onCadShape.Refactoring of example scripts:
Phase.from_cadconstructor instead ofPhase(shape=...), and to use.cad(instead of.shape) for downstream CAD operations and exports. This ensures compatibility with the new backend and makes use of the newCadShapeinterface. [1] [2] [3] [4] [5] [6]These changes modernize the CAD foundation of the codebase, improve modularity and error handling, and pave the way for further CAD-related enhancements.