hoops_ai.cadencoder
CAD Encoding Module
The CAD Encoding module transforms CAD geometric data into machine learning-ready representations. It bridges the gap between CAD geometry and ML algorithms by converting B-Rep (Boundary Representation) data into graph structures and numerical features that can be processed by neural networks.
This module is essential for preparing CAD data for machine learning workflows, providing standardized encoding schemes that preserve geometric relationships while making the data compatible with ML frameworks like PyTorch and DGL (Deep Graph Library).
For detailed usage examples and encoding strategies, see the CAD Data Encoding Programming Guide.
Classes
|
A single class to compute + persist geometry and topology data. |
- class hoops_ai.cadencoder.brep_encoder.BrepEncoder(brep_access, storage_handler=None)
Bases:
objectA single class to compute + persist geometry and topology data.
- Each ‘push_*’ method:
Looks at storage_handler.get_keys().
Ensures schema definition exists for the data.
Computes the result, saves to storage.
Returns 0, discarding any data from memory after storage.
- Parameters:
brep_access (BrepAccess)
storage_handler (DataStorage)
- push_average_face_pair_angle_histograms(grid=5, num_bins=64)
Ensures ‘a3_distance’ is in storage or returns the face pair angle histograms directly. - Requires ‘face_indices’ if using storage.
- push_average_face_pair_distance_histograms(grid=5, num_bins=64)
Ensures ‘d2_distance’ is in storage or returns the face pair distance histograms directly. - Requires ‘face_indices’ if using storage.
- push_curvegrid(ugrid=5)
Ensures ‘edge_u_grids’ is in storage or returns the edge grid data directly. - Requires ‘edge_indices’ if using storage.
- Returns:
str - the key name of stored data If storage_handler is None: np.ndarray - the edge U grids
- Return type:
If storage_handler is not None
- Parameters:
ugrid (int)
- push_edge_attributes()
Ensures ‘edge_types’, ‘edge_lengths’, ‘edge_dihedral_angles’, ‘edge_convexities’ are in storage or returns the computed data directly. - Requires ‘edge_indices’ if using storage.
- Returns:
Tuple[List[str], Dict] - (list of stored key names, edge_type_descrip dictionary) If storage_handler is None: Tuple[List[np.ndarray], Dict] - (list of numpy arrays, edge_type_descrip dictionary)
where edge_type_descrip is a dictionary mapping edge type IDs to descriptions
- Return type:
If storage_handler is not None
- push_edge_indices()
Ensures ‘edge_indices’ is in storage or returns the edge indices directly.
- Returns:
str - the key name of stored data If storage_handler is None: np.ndarray - the edge indices
- Return type:
If storage_handler is not None
- push_extended_adjacency()
Ensures ‘extended_adjacency’ is in storage or returns the extended adjacency data directly. - Requires ‘graph’ if using storage.
- Returns:
str - the key name of stored data If storage_handler is None: np.ndarray - the extended adjacency matrix
- Return type:
If storage_handler is not None
- push_face_adjacency_graph()
Ensures ‘graph’ is in storage or returns the face adjacency graph directly.
- Returns:
str - the key name of stored data If storage_handler is None: nx.Graph - the face adjacency graph
- Return type:
If storage_handler is not None
- push_face_attributes()
Ensures ‘face_types’, ‘face_areas’, ‘face_loops’ in storage or returns the computed data. - Requires ‘face_indices’ to already be pushed if using storage.
- Returns:
Tuple[List[str], Dict] - (list of stored key names, face_types_descr dictionary) If storage_handler is None: Tuple[List[np.ndarray], Dict] - (list of numpy arrays, face_types_descr dictionary)
where face_types_descr is a dictionary mapping face type IDs to descriptions
- Return type:
If storage_handler is not None
- push_face_indices()
Ensures ‘face_indices’ is in storage or returns the face indices directly.
- Returns:
str - the key name of stored data If storage_handler is None: np.ndarray - the face indices
- Return type:
If storage_handler is not None
- push_face_neighbors_count()
Ensures ‘face_neighborscount’ is in storage or returns the neighbor count data directly. - Requires ‘graph’ if using storage.
- Returns:
str - the key name of stored data If storage_handler is None: np.ndarray - array of neighbor counts for each face
- Return type:
If storage_handler is not None
- push_face_pair_edges_path(max_allow_edge_length=16)
Ensures ‘face_pair_edges_path’ is in storage or returns the edge path data directly. - Requires ‘graph’ if using storage.
- Returns:
str - the key name of stored data If storage_handler is None: np.ndarray - the face pair edges path array
- Return type:
If storage_handler is not None
- Parameters:
max_allow_edge_length (int)
- push_facegrid(ugrid=5, vgrid=5)
Ensures ‘face_uv_grids’ is in storage or returns the face grid data directly. - Requires ‘face_indices’ if using storage.
- class hoops_ai.cadencoder.brep_encoder.FacePairAngleComputation
Bases:
objectDemonstrates sampling 25 normals per face, then computing fully broadcasted angle histograms (A3).
- static compute_average_face_pair_angle_histograms(face_normals_list, num_bins, sample_size=25)
Returns a (F, F, num_bins) float32 array of normalized angle histograms between each pair of faces.
- Parameters:
face_normals_list (List[numpy.ndarray])
num_bins (int)
sample_size (int)
- Return type:
- class hoops_ai.cadencoder.brep_encoder.FacePairDistanceComputation
Bases:
objectDemonstrates: 1) Using float32 2) Sampling 25 points per face (or less, if P < 25) 3) Blocking faces into two chunks 4) Merging partial histograms in two threads
- static compute_average_face_pair_distance_histograms(face_points_list, get_diagonal_length_func, num_bins, sample_size=25)
Returns a (F, F, num_bins) float32 array of normalized distance histograms between each pair of faces.
- Parameters:
face_points_list (List[numpy.ndarray])
num_bins (int)
sample_size (int)
- Return type: