upxo.pxtal.fm_steel_3d.block_generator_3d module
BlockGenerator3D: Worker class for slicing PAGs into martensitic blocks.
This module contains the stateless block generation logic. It receives PAG data and returns block partitions. No state is held between calls.
- Classes:
BlockGenerator3D: Block generation worker.
- class upxo.pxtal.fm_steel_3d.block_generator_3d.BlockGenerator3D(verbosity: int = 0, default_voxel_size: float = 1.0)[source]
Bases:
objectWorker class for generating martensitic blocks within PAGs.
This is a stateless utility class. It receives PAG voxel data and orientation information, and returns partitioned blocks. Multiple calls produce different results based on random seeds (stochastic slicing plane selection).
All methods are instance methods (not static) to allow storing session config (default parameters, verbosity, etc.) in future.
- generate_blocks_for_all_pags(clusters_dict: Dict[int, List[int]], grain_locs: Dict[int, ndarray], pag_orientations: Dict[int, Tuple[float, float, float]], block_thickness_range: Tuple[float, float] = (2.0, 5.0), random_seed: int | None = None, slab_connectivity: int = 26) Tuple[Dict[str, ndarray], Dict[int, List[str]], Dict[int, int], Dict[str, ndarray]][source]
Generate blocks for all PAGs.
- Parameters:
clusters_dict (dict) – {pag_id: [grain_id, …]}.
grain_locs (dict) – {grain_id: (n_voxels, 3) array}.
pag_orientations (dict) – {pag_id: (phi1, Phi, phi2)}.
block_thickness_range (tuple of (float, float), optional) – (lower, upper) bounds for block thickness in physical units. Each packet draws its own thickness uniformly from this range, producing natural thickness variation across the microstructure. Default (2.0, 5.0).
random_seed (int, optional) – Random seed for reproducibility.
- Returns:
(all_blocks, grain_to_blocks_map, grain_to_plane_idx, block_slicing_normals). grain_to_blocks_map keys are grain_ids (= packet identifiers); values are the list of block_ids created from that packet. block_slicing_normals maps each block_id to the unit normal of the slicing plane used to create it — required by SubBlockGenerator3D.
- Return type:
- get_slicing_planes_for_packet(pag_id: int, pag_orientations: Dict[int, Tuple[float, float, float]]) List[Plane][source]
Return the four crystallographic slicing-plane candidates for a PAG.
The four {111}FCC plane normals (habit planes for martensite packets) are defined in the PAG crystal frame and rotated into the sample frame using the PAG’s Bunge Euler angles. If no orientation is stored for the PAG the four normals are returned in the reference (lab) frame as a fallback.
- slice_packet_into_blocks(packet_gid: int, cluster_id: int, voxel_coords: ndarray, block_thickness: float, slicing_plane: Plane, slab_connectivity: int = 26) Dict[str, ndarray][source]
Slice a PAG/packet into contiguous blocks using plane-normal projection.
Algorithm: 1. Project all voxels onto the slicing-plane unit normal via signed distance. 2. Divide the projection range into parallel slabs of width block_thickness. 3. Within each slab, rasterise voxels into a local 3D boolean grid and run
connected-component labeling (cc3d, connectivity=slab_connectivity, default 26) to find spatially contiguous blocks.
Return each component as a named block with its global voxel coordinates.
- Parameters:
packet_gid (int) – Grain/packet identifier (used in block names).
cluster_id (int) – Parent cluster (PAG) identifier (used in block names).
voxel_coords (np.ndarray) – (n_voxels, 3) integer voxel coordinates.
block_thickness (float) – Desired slab thickness along the slicing-plane normal.
slicing_plane (Plane) – Plane whose unit_normal defines the slicing direction and whose point is the projection origin (typically the PAG centroid).
- Returns:
newly_created_blocks – {block_name: (n_voxels, 3) array of global voxel coordinates}. Names are already globally unique (cluster_id + packet_gid + a local per-packet counter), so no separate global id is needed.
- Return type: