hoops_ai.cadencoder
Quick Overview
Classes
BrepEncoder(brep_access[, storage_handler])A single class to compute + persist geometry and topology data.
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.
- class hoops_ai.cadencoder.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.
See full documentation: BrepEncoder.push_average_face_pair_angle_histograms(grid=5, num_bins=64)
- 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.
See full documentation: BrepEncoder.push_average_face_pair_distance_histograms(grid=5, num_bins=64)
- push_curvegrid(ugrid=5)
Ensures ‘edge_u_grids’ is in storage or returns the edge grid data directly.
Requires ‘edge_indices’ if using storage.
See full documentation: BrepEncoder.push_curvegrid(ugrid=5)
- 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.
See full documentation: BrepEncoder.push_edge_attributes()
- 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.
See full documentation: BrepEncoder.push_edge_indices()
- 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.
See full documentation: BrepEncoder.push_extended_adjacency()
- 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.
See full documentation: BrepEncoder.push_face_adjacency_graph()
- 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_centroids’, ‘face_loops’ in storage or returns the computed data.
Requires ‘face_indices’ to already be pushed if using storage.
See full documentation: BrepEncoder.push_face_attributes()
- 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_centroids()
Ensures ‘face_centroids’ is in storage or returns the face centroid data directly.
See full documentation: BrepEncoder.push_face_centroids()
- Returns:
str - the key name of stored data If storage_handler is None: np.ndarray - the face centroid data
- Return type:
If storage_handler is not None
- push_face_discretization(pointsamples=25)
Ensures ‘face_discretization’ is in storage or returns the face discretization data directly.
Requires ‘face_indices’ if using storage.
See full documentation: BrepEncoder.push_face_discretization(pointsamples=25)
- Parameters:
pointsamples (int) – Number of points to sample per face (default 25)
- Returns:
str - the key name of stored data If storage_handler is None: np.ndarray - the face discretization
- Return type:
If storage_handler is not None
- push_face_indices()
Ensures ‘face_indices’ is in storage or returns the face indices directly.
See full documentation: BrepEncoder.push_face_indices()
- 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.
See full documentation: BrepEncoder.push_face_neighbors_count()
- 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.
See full documentation: BrepEncoder.push_face_pair_edges_path(max_allow_edge_length=16)
- 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)