Discrete Representation#
Class for discrete representations of volmdlr models.
(voxelization for 3D geometries, pixelization for 2D geometries).
- class volmdlr.discrete_representation.DiscreteRepresentation(element_size: float)#
Bases:
objectAbstract base class for discrete representation in any dimension.
- It is used for:
Voxelization in 3D
Pixelization in 2D
Any discrete representation follows the same approach: The representation is defined on an implicit grid, where each element is defined by its size. The implicit grid consists of axis-aligned elements with a given size, ensuring that the global origin (0, …, 0) is always a corner point of an element.
For example, in 1D with an element size of t, the set of elements (defined by minimum and maximum points) is: {i ∈ N, t ∈ R | (i * t, (i+1) * t)} The corresponding set of element centers is: {i ∈ N, t ∈ R | (i + 0.5) * t}
This approach enables consistent representation across the space, facilitating fast Boolean operations.
- DiscreteRepresentationType = ~DiscreteRepresentationType#
- static check_center_is_in_implicit_grid(element_center: tuple[float, ...], element_size: float) bool#
Check if a given element center point is an element center of the implicit grid, defined by element_size.
- Parameters:
element_center (tuple[float, ...]) – The element center point to check.
element_size (float) – The element edges size.
- Returns:
True if the given element center point is an element center of the implicit grid, False otherwise.
- Return type:
bool
- difference(other: DiscreteRepresentationType) DiscreteRepresentationType#
Perform a difference operation with another discrete representation.
- Parameters:
other (DiscreteRepresentationType) – The discrete representation to perform the difference with.
- Returns:
A new discrete representation resulting from the difference operation.
- Return type:
DiscreteRepresentationType
- flood_fill(start, fill_with: bool) DiscreteRepresentationType#
Perform a flood fill operation on the discrete representation.
- Parameters:
start – The starting point for the flood fill.
fill_with (bool) – The value to fill the elements with during the operation.
- Returns:
A new discrete representation resulting from the flood fill operation.
- Return type:
DiscreteRepresentationType
- interference(other: DiscreteRepresentationType) float#
Compute the percentage of interference between two discrete representations.
- Parameters:
other (DiscreteRepresentation) – The other discrete representation to compute interference with.
- Returns:
The percentage of interference between the two discrete representations.
- Return type:
float
- intersection(other: DiscreteRepresentationType) DiscreteRepresentationType#
Perform an intersection operation with another discrete representation.
- Parameters:
other (DiscreteRepresentationType) – The discrete representation to perform the intersection with.
- Returns:
A new discrete representation resulting from the intersection operation.
- Return type:
DiscreteRepresentationType
- inverse() DiscreteRepresentationType#
Compute the inverse of the discrete representation.
- Returns:
A new discrete representation representing the inverse.
- Return type:
DiscreteRepresentationType
- is_hollow() bool#
Check if the discrete representation is hollow.
A hollow discrete representation is one that has enclosed elements that are not filled.
- Returns:
True if the discrete representation is hollow, False otherwise.
- Return type:
bool
- is_intersecting(other: DiscreteRepresentationType) bool#
Check if two discrete representations are intersecting.
- Parameters:
other (DiscreteRepresentationType) – The other discrete representation to check if there is an intersection with.
- Returns:
True if the discrete representations are intersecting, False otherwise.
- Return type:
bool
- property max_grid_center: tuple#
Get the maximum center point from the set of voxel centers, in the voxel 3D grid.
This point may not be a voxel of the voxelization, because it is the maximum center in each direction (X, Y, Z).
- Returns:
The maximum center point.
- Return type:
tuple[float, …]
- property min_grid_center: tuple#
Get the minimum center point from the set of voxel centers, in the voxel 3D grid.
This point may not be a voxel of the voxelization, because it is the minimum center in each direction (X, Y, Z).
- Returns:
The minimum center point.
- Return type:
tuple[float, …]
- symmetric_difference(other: DiscreteRepresentationType) DiscreteRepresentationType#
Perform a symmetric difference operation with another discrete representation.
- Parameters:
other (DiscreteRepresentationType) – The discrete representation to perform the symmetric difference with.
- Returns:
A new discrete representation resulting from the symmetric difference operation.
- Return type:
DiscreteRepresentationType
- union(other: DiscreteRepresentationType) DiscreteRepresentationType#
Perform a union operation with another discrete representation.
- Parameters:
other (DiscreteRepresentationType) – The discrete representation to perform the union with.
- Returns:
A new discrete representation resulting from the union operation.
- Return type:
DiscreteRepresentationType
- class volmdlr.discrete_representation.MatrixBasedPixelization(pixel_matrix: ndarray[Any, dtype[bool_]], min_grid_center: tuple[float, float], pixel_size: float, name: str = '')#
Bases:
PixelizationPixelization implemented as a 2D matrix.
- border() MatrixBasedPixelization#
Compute the border pixels of the pixelization.
- Returns:
A new pixelization representing the border pixels.
- Return type:
- crop_matrix() MatrixBasedPixelization#
Crop the pixel matrix to the smallest possible size.
- Returns:
The MatrixBasedPixelization with cropped pixel matrix.
- Return type:
- classmethod dict_to_object(dict_: Dict[str, Any], *args, **kwargs) MatrixBasedPixelization#
Specific ‘dict_to_object’ method to allow deserialization of a numpy array.
- difference(other: MatrixBasedPixelization) MatrixBasedPixelization#
Perform a difference operation with another pixelization.
- Parameters:
other (MatrixBasedPixelization) – The MatrixBasedPixelization to perform the difference with.
- Returns:
A new MatrixBasedPixelization resulting from the difference operation.
- Return type:
- flood_fill(start: tuple[int, int], fill_with: bool) MatrixBasedPixelization#
Perform a flood fill operation on the pixelization.
- Parameters:
start (tuple[int, int]) – The indexes of the starting pixel in the 3D matrix for the flood fill.
fill_with (bool) – The value to fill the pixels with during the operation.
- Returns:
A new pixelization resulting from the flood fill operation.
- Return type:
- classmethod from_closed_polygon(closed_polygon: ClosedPolygon2D, pixel_size: float, name: str = '') MatrixBasedPixelization#
Create a pixelization from a ClosedPolygon2D.
- Parameters:
closed_polygon (ClosedPolygon2D) – The ClosedPolygon2D to create the pixelization from.
pixel_size (float) – The size of each pixel.
name (str) – Optional name for the pixelization.
- Returns:
A pixelization created from the ClosedPolygon2D.
- Return type:
- classmethod from_line_segment(line_segment: LineSegment2D, pixel_size: float, name: str = '') MatrixBasedPixelization#
Create a pixelization from a LineSegment2D.
- Parameters:
line_segment (LineSegment2D) – The LineSegment2D to create the pixelization from.
pixel_size (float) – The size of each pixel.
name (str) – Optional name for the pixelization.
- Returns:
A pixelization created from the LineSegment2D.
- Return type:
- classmethod from_point_based_pixelization(point_based_pixelization: PointBasedPixelization) MatrixBasedPixelization#
Create a MatrixBasedPixelization from a PointBasedPixelization.
- Parameters:
point_based_pixelization (PointBasedPixelization) – The PointBasedPixelization to create the MatrixBasedPixelization from.
- Returns:
A MatrixBasedPixelization created from the PointBasedPixelization.
- Return type:
- intersection(other: MatrixBasedPixelization) MatrixBasedPixelization#
Perform an intersection operation with another MatrixBasedPixelization.
- Parameters:
other (MatrixBasedPixelization) – The MatrixBasedPixelization to perform the intersection with.
- Returns:
A new MatrixBasedPixelization resulting from the intersection operation.
- Return type:
- inverse() MatrixBasedPixelization#
Compute the inverse of the pixelization.
- Returns:
A new pixelization representing the inverse.
- Return type:
- property max_grid_center: tuple[float, float]#
Get the maximum center point from the set of pixel centers, in the pixel 3D grid.
This point may not be a pixel of the pixelization, because it is the maximum center in each direction (X, Y, Z).
- Returns:
The maximum center point.
- Return type:
tuple[float, float]
- property min_grid_center: tuple[float, float]#
Get the minimum center point from the set of pixel centers, in the pixel 3D grid.
This point may not be a pixel of the pixelization, because it is the minimum center in each direction (X, Y, Z).
- Returns:
The minimum center point.
- Return type:
tuple[float, float]
- property pixel_indices: ndarray[Any, dtype[int64]]#
Get the indices of the pixels in the pixelization matrix.
- symmetric_difference(other: MatrixBasedPixelization) MatrixBasedPixelization#
Perform a symmetric difference operation with another MatrixBasedPixelization.
- Parameters:
other (MatrixBasedPixelization) – The MatrixBasedPixelization to perform the symmetric difference with.
- Returns:
A new MatrixBasedPixelization resulting from the symmetric difference operation.
- Return type:
- to_dict(*args, **kwargs) Dict[str, Any]#
Specific ‘to_dict’ method to allow serialization of a numpy array.
- to_point_based_pixelization() PointBasedPixelization#
Convert the MatrixBasedPixelization to a PointBasedPixelization.
- Returns:
A PointBasedPixelization representation of the current pixelization.
- Return type:
- union(other: MatrixBasedPixelization) MatrixBasedPixelization#
Perform a union operation with another MatrixBasedPixelization.
- Parameters:
other (MatrixBasedPixelization) – The MatrixBasedPixelization to perform the union with.
- Returns:
A new MatrixBasedPixelization resulting from the union operation.
- Return type:
- class volmdlr.discrete_representation.MatrixBasedVoxelization(voxel_matrix: ndarray[Any, dtype[bool_]], min_grid_center: tuple[float, float, float], voxel_size: float, name: str = '')#
Bases:
VoxelizationVoxelization implemented as a 3D matrix.
- border() MatrixBasedVoxelization#
Compute the border voxels of the voxelization.
- Returns:
A new voxelization representing the border voxels.
- Return type:
- compute_distance_matrix_to_mesh(mesh: Mesh3D, empty_value: float = nan) ndarray[Any, dtype[float]]#
Compute a distance matrix from voxel centers to a mesh.
Returns a matrix with the same shape as the voxelization matrix, where each value represents the distance from the corresponding voxel center to the nearest point on the mesh surface.
- Parameters:
mesh – Target mesh for distance computation
empty_value – Value for empty voxels (default: NaN)
- Returns:
Distance matrix with shape matching self.matrix
- crop_matrix() MatrixBasedVoxelization#
Crop the voxel matrix to the smallest possible size.
- Returns:
The MatrixBasedVoxelization with cropped voxel matrix.
- Return type:
- classmethod dict_to_object(dict_: Dict[str, Any], *args, **kwargs) MatrixBasedVoxelization#
Specific ‘dict_to_object’ method to allow deserialization of a numpy array.
- difference(other: MatrixBasedVoxelization) MatrixBasedVoxelization#
Perform a difference operation with another voxelization.
- Parameters:
other (MatrixBasedVoxelization) – The MatrixBasedVoxelization to perform the difference with.
- Returns:
A new MatrixBasedVoxelization resulting from the difference operation.
- Return type:
- extract_connected_matrix_based_voxelizations() list[MatrixBasedVoxelization]#
Extract connected voxelizations from the current MatrixBasedVoxelization.
- Returns:
A list of MatrixBasedVoxelization objects, each corresponding to a distinct connected component within the original 3D MatrixBasedVoxelization.
- flood_fill(start: tuple[int, int, int], fill_with: bool) MatrixBasedVoxelization#
Perform a flood fill operation on the voxelization.
- Parameters:
start (tuple[int, int, int]) – The indexes of the starting voxel in the 3D matrix for the flood fill.
fill_with (bool) – The value to fill the voxels with during the operation.
- Returns:
A new voxelization resulting from the flood fill operation.
- Return type:
- classmethod from_mesh_data(vertices: Iterable[Iterable[float]], faces: Iterable[Iterable[int]], voxel_size: float, name: str = '') MatrixBasedVoxelization#
Create a MatrixBasedVoxelization from mesh data.
- Parameters:
vertices (Iterable[Iterable[float]]) – The vertices of the mesh.
faces (Iterable[Iterable[int]]) – The faces of the mesh, using vertices indexes.
voxel_size (float) – The size of each voxel.
name (str) – Optional name for the MatrixBasedVoxelization.
- Returns:
A MatrixBasedVoxelization created from mesh data.
- Return type:
- classmethod from_point_based_voxelization(point_based_voxelization: PointBasedVoxelization) MatrixBasedVoxelization#
Create a MatrixBasedVoxelization from a PointBasedVoxelization.
- Parameters:
point_based_voxelization (PointBasedVoxelization) – The PointBasedVoxelization to create the MatrixBasedVoxelization from.
- Returns:
A MatrixBasedVoxelization created from the PointBasedVoxelization.
- Return type:
- intersection(other: MatrixBasedVoxelization) MatrixBasedVoxelization#
Perform an intersection operation with another MatrixBasedVoxelization.
- Parameters:
other (MatrixBasedVoxelization) – The MatrixBasedVoxelization to perform the intersection with.
- Returns:
A new MatrixBasedVoxelization resulting from the intersection operation.
- Return type:
- inverse() MatrixBasedVoxelization#
Compute the inverse of the voxelization.
- Returns:
A new voxelization representing the inverse.
- Return type:
- layers_thickness_by_voxel_centers() dict[tuple[float, float, float], float]#
Get a dictionary with voxel centers as keys and their layers thickness to false or edge values as values.
- Returns:
Dictionary with voxel centers and their corresponding layers thickness to false or edge values.
- Return type:
dict[tuple[float, float, float], float]
- marching_cubes() Mesh3D#
Apply the marching cubes algorithm to the voxelization and return the constructed Mesh3D.
- property max_grid_center: tuple[float, float, float]#
Get the maximum center point from the set of voxel centers, in the voxel 3D grid.
This point may not be a voxel of the voxelization, because it is the maximum center in each direction (X, Y, Z).
- Returns:
The maximum center point.
- Return type:
tuple[float, float, float]
- property min_grid_center: tuple[float, float, float]#
Get the minimum center point from the set of voxel centers, in the voxel 3D grid.
This point may not be a voxel of the voxelization, because it is the minimum center in each direction (X, Y, Z).
- Returns:
The minimum center point.
- Return type:
tuple[float, float, float]
- symmetric_difference(other: MatrixBasedVoxelization) MatrixBasedVoxelization#
Perform a symmetric difference operation with another MatrixBasedVoxelization.
- Parameters:
other (MatrixBasedVoxelization) – The MatrixBasedVoxelization to perform the symmetric difference with.
- Returns:
A new MatrixBasedVoxelization resulting from the symmetric difference operation.
- Return type:
- to_dict(*args, **kwargs) Dict[str, Any]#
Specific ‘to_dict’ method to allow serialization of a numpy array.
- to_greedy_mesh() Mesh3D#
Generate an optimized Mesh3D using greedy meshing algorithm.
This method reduces the number of triangles by merging adjacent coplanar faces into larger rectangles, significantly improving rendering performance.
- Returns:
An optimized mesh representation of the voxelization.
- to_inner_growing_voxelizations(layers_minimal_thickness: float) list[MatrixBasedVoxelization]#
Convert the MatrixBasedVoxelization to multiple MatrixBasedVoxelization, with different voxel size.
The more the voxelization is inside, the more its voxel size become bigger.
- Parameters:
layers_minimal_thickness (float) – The minimal thickness of each layer.
- Returns:
A list of MatrixBasedVoxelization representing the inner growing voxelizations.
- Return type:
list[MatrixBasedVoxelization]
- to_octree_based_voxelization() OctreeBasedVoxelization#
Convert the MatrixBasedVoxelization to an OctreeBasedVoxelization.
- Returns:
The octree based voxelization.
- Return type:
- to_point_based_voxelization() PointBasedVoxelization#
Convert the MatrixBasedVoxelization to a PointBasedVoxelization.
- Returns:
A PointBasedVoxelization representation of the current voxelization.
- Return type:
- translation(offset: tuple[int, int, int]) MatrixBasedVoxelization#
Translate the voxelization by an integer number of voxels in each direction.
- Parameters:
offset – Number of voxels to translate in each direction (i, j, k).
- Returns:
A new translated MatrixBasedVoxelization.
- union(other: MatrixBasedVoxelization) MatrixBasedVoxelization#
Perform a union operation with another MatrixBasedVoxelization.
- Parameters:
other (MatrixBasedVoxelization) – The MatrixBasedVoxelization to perform the union with.
- Returns:
A new MatrixBasedVoxelization resulting from the union operation.
- Return type:
- property voxel_indices: ndarray[Any, dtype[int64]]#
Get the indices of the voxels in the voxelization matrix.
- class volmdlr.discrete_representation.OctreeBasedVoxelization(octree: int | list[Octree], root_center: tuple[float, float, float], octree_depth: int, voxel_size: float, triangles: list[tuple[tuple[float, float, float], tuple[float, float, float], tuple[float, float, float]]] | None = None, name: str = '')#
Bases:
VoxelizationVoxelization implemented as an octree.
- classmethod dict_to_object(dict_: Dict[str, Any], *args, **kwargs) OctreeBasedVoxelization#
Specific ‘dict_to_object’ method.
- difference(other: OctreeBasedVoxelization) OctreeBasedVoxelization#
Perform a difference operation with another voxelization.
- Parameters:
other (OctreeBasedVoxelization) – The OctreeBasedVoxelization to perform the difference with.
- Returns:
A new OctreeBasedVoxelization resulting from the difference operation.
- Return type:
- flood_fill(start: tuple[int, int, int], fill_with: bool) OctreeBasedVoxelization#
Perform a flood fill operation on the voxelization.
- Parameters:
start (tuple[int, int, int]) – The indexes of the starting voxel in the 3D matrix for the flood fill.
fill_with (bool) – The value to fill the voxels with during the operation.
- Returns:
A new voxelization resulting from the flood fill operation.
- Return type:
- classmethod from_mesh_data(vertices: Iterable[Iterable[float]], faces: Iterable[Iterable[int]], voxel_size: float, name: str = '') OctreeBasedVoxelization#
Create a OctreeBasedVoxelization from mesh data.
- Parameters:
vertices (Iterable[Iterable[float]]) – The vertices of the mesh.
faces (Iterable[Iterable[int]]) – The faces of the mesh, using vertices indexes.
voxel_size (float) – The size of each voxel.
name (str) – Optional name for the voxelization.
- Returns:
A OctreeBasedVoxelization created from the mesh data.
- Return type:
- classmethod from_point_based_voxelization(point_based_voxelization: PointBasedVoxelization) OctreeBasedVoxelization#
Create a OctreeBasedVoxelization from a PointBasedVoxelization.
- Parameters:
point_based_voxelization (PointBasedVoxelization) – The PointBasedVoxelization to create the OctreeBasedVoxelization from.
- Returns:
A OctreeBasedVoxelization created from the PointBasedVoxelization.
- Return type:
- get_inner_growing_voxel_centers(layers_minimal_thickness: float, layer_dict: dict[tuple[float, float, float], float] | None = None) dict[float, set[tuple[float, float, float]]]#
Get the center points of inner growing voxels and organize them by voxel size.
- Parameters:
layers_minimal_thickness (float) – The minimal thickness of each layer.
layer_dict (dict[tuple[float, float, float], float]) – A dict with voxel centers and their corresponding layers thickness to false or edge values.
- Returns:
A dictionary where the keys are voxel sizes and the values are sets of voxel centers.
- Return type:
dict[float, set[tuple[float, float, float]]]
- classmethod intersecting_faces_combinations(shell_1: Shell3D, shell_2: Shell3D, voxel_size: float) list[tuple[tuple[Face3D, Face3D], PointBasedVoxelization]]#
Compute the intersecting faces combinations and where the faces are located, as a PointBasedVoxelization.
- Parameters:
shell_1 (Shell3D) – The first shell to find the intersecting faces with.
shell_1 – The second shell to find the intersecting faces with.
voxel_size (float) – The voxel edges size.
- Returns:
The possibly intersecting face combinations.
- Return type:
list[tuple[tuple[Face3D, Face3D], PointBasedVoxelization]]
- intersection(other: OctreeBasedVoxelization) OctreeBasedVoxelization#
Perform an intersection operation with another OctreeBasedVoxelization.
- Parameters:
other (OctreeBasedVoxelization) – The OctreeBasedVoxelization to perform the intersection with.
- Returns:
A new OctreeBasedVoxelization resulting from the intersection operation.
- Return type:
- inverse() OctreeBasedVoxelization#
Compute the inverse of the voxelization.
- Returns:
A new voxelization representing the inverse.
- Return type:
- is_intersecting(other: OctreeBasedVoxelization) bool#
Check is two OctreeBasedVoxelization are intersecting.
- Parameters:
other (OctreeBasedVoxelization) – The other voxelization to check if there is an intersection with.
- Returns:
True if the voxelizations are intersecting, False otherwise.
- Return type:
bool
- property max_grid_center: tuple[float, float, float]#
Get the maximum center point from the set of voxel centers, in the voxel 3D grid.
This point may not be a voxel of the voxelization, because it is the maximum center in each direction (X, Y, Z).
- Returns:
The maximum center point.
- Return type:
tuple[float, float, float]
- property min_grid_center: tuple[float, float, float]#
Get the minimum center point from the set of voxel centers, in the voxel 3D grid.
This point may not be a voxel of the voxelization, because it is the minimum center in each direction (X, Y, Z).
- Returns:
The minimum center point.
- Return type:
tuple[float, float, float]
- symmetric_difference(other: OctreeBasedVoxelization) OctreeBasedVoxelization#
Perform a symmetric difference operation with another OctreeBasedVoxelization.
- Parameters:
other (OctreeBasedVoxelization) – The OctreeBasedVoxelization to perform the symmetric difference with.
- Returns:
A new OctreeBasedVoxelization resulting from the symmetric difference operation.
- Return type:
- to_dict(*args, **kwargs) Dict[str, Any]#
Specific ‘to_dict’ method.
- to_inner_growing_voxelizations(layers_minimal_thickness: float) list[OctreeBasedVoxelization]#
Convert the OctreeBasedVoxelization to multiple OctreeBasedVoxelization, with different size.
The more the voxelization is inside, the more its voxel size become bigger.
- Parameters:
layers_minimal_thickness (float) – The minimal thickness of each layer.
- Returns:
A list of PointBasedVoxelization representing the inner growing voxelization.
- Return type:
list[PointBasedVoxelization]
- to_matrix_based_voxelization() MatrixBasedVoxelization#
Convert the OctreeBasedVoxelization to a MatrixBasedVoxelization.
- Returns:
A MatrixBasedVoxelization representation of the current voxelization.
- Return type:
- to_non_homogeneous_point_based_voxelizations() list[PointBasedVoxelization]#
Convert the OctreeBasedVoxelization to multiple PointBasedVoxelization, with different size.
- Returns:
A PointBasedVoxelization representation of the current voxelization.
- Return type:
- to_point_based_voxelization() PointBasedVoxelization#
Convert the OctreeBasedVoxelization to a PointBasedVoxelization.
- Returns:
A PointBasedVoxelization representation of the current voxelization.
- Return type:
- union(other: OctreeBasedVoxelization) OctreeBasedVoxelization#
Perform a union operation with another OctreeBasedVoxelization.
- Parameters:
other (OctreeBasedVoxelization) – The OctreeBasedVoxelization to perform the union with.
- Returns:
A new OctreeBasedVoxelization resulting from the union operation.
- Return type:
- class volmdlr.discrete_representation.Pixelization(pixel_size: float, name: str)#
Bases:
DiscreteRepresentation,DessiaObjectAbstract base class for creating and manipulating pixelizations of volmdlr geometries.
This approach is used to create a pixelization of the contour, without filling the surface.
The pixelization is defined on an implicit 2D grid, where each pixel is defined by its size. The implicit grid consists of axis-aligned squares with a given size, ensuring that the global origin (0, 0) is always a corner point of a pixel.
For example, in 1D with a pixel size of t, the set of pixels (defined by minimum and maximum points) is: {i ∈ N, t ∈ R | (i * t, (i+1) * t)} The corresponding set of pixel centers is: {i ∈ N, t ∈ R | (i + 0.5) * t}
This approach enables consistent pixelization across the 3D space, facilitating fast Boolean operations.
- PixelizationType = ~PixelizationType#
- property area: float#
Calculate the area of the pixelization.
- Returns:
The volume of the pixelization.
- Return type:
float
- property bounding_rectangle: BoundingRectangle#
Get the bounding rectangle of the pixelization.
- Returns:
The bounding rectangle of the pixelization.
- Return type:
- fill_enclosed_pixels() PixelizationType#
Fill the enclosed pixels of the pixelization.
- Returns:
A new pixelization with enclosed pixels filled.
- Return type:
PixelizationType
- fill_outer_pixels() PixelizationType#
Fill the outer pixels of the pixelization.
- Returns:
A new pixelization with outer pixels filled.
- Return type:
PixelizationType
- classmethod from_closed_polygon(closed_polygon: ClosedPolygon2D, pixel_size: float, name: str = '') PixelizationType#
Create a pixelization from a ClosedPolygon2D.
- Parameters:
closed_polygon (ClosedPolygon2D) – The ClosedPolygon2D to create the pixelization from.
pixel_size (float) – The size of each pixel.
name (str) – Optional name for the pixelization.
- Returns:
A pixelization created from the ClosedPolygon2D.
- Return type:
PixelizationType
- classmethod from_line_segment(line_segment: LineSegment2D, pixel_size: float, name: str = '') PixelizationType#
Create a pixelization from a LineSegment2D.
- Parameters:
line_segment (LineSegment2D) – The LineSegment2D to create the pixelization from.
pixel_size (float) – The size of each pixel.
name (str) – Optional name for the pixelization.
- Returns:
A pixelization created from the LineSegment2D.
- Return type:
PixelizationType
- get_pixel_centers() set[tuple[float, float]]#
Get the center point of each pixel.
- Returns:
The center point of each pixel.
- Return type:
set[tuple[float, float]]
- get_pixel_centers_array() ndarray[Any, dtype[float]]#
Get the center point of each voxel as a numpy array.
- Returns:
The center point of each voxel.
- Return type:
np.ndarray[float]
- property pixel_size: float#
Get the pixel size.
- Returns:
The pixel size.
- Return type:
float
- plot(ax=None, color: str = 'b', **kwargs)#
Plot the pixels on a 2D plane.
- Parameters:
ax – An existing figure to plot on.
color – The color of the pixels.
kwargs – Additional keyword arguments.
- Returns:
The plotted MatPlotLib figure.
- class volmdlr.discrete_representation.PointBasedPixelization(pixel_centers: set[tuple[float, float]], pixel_size: float, name: str = '')#
Bases:
PixelizationPixelization implemented as a set of points, representing each pixel center.
- classmethod dict_to_object(dict_: Dict[str, Any], *args, **kwargs) PointBasedPixelization#
Specific ‘dict_to_object’ method to allow deserialization of a set.
- difference(other: PointBasedPixelization) PointBasedPixelization#
Perform an intersection operation with another PointBasedPixelization.
- Parameters:
other (PointBasedPixelization) – The PointBasedPixelization to perform the intersection with.
- Returns:
A new PointBasedPixelization resulting from the intersection operation.
- Return type:
- flood_fill(start: tuple[float, float], fill_with: bool) PointBasedPixelization#
Perform a flood fill operation on the pixelization.
- Parameters:
start (tuple[float, float]) – The coordinates of the starting point for the flood fill.
fill_with (bool) – The value to fill the pixels with during the operation.
- Returns:
A new pixelization resulting from the flood fill operation.
- Return type:
- classmethod from_closed_polygon(closed_polygon: ClosedPolygon2D, pixel_size: float, name: str = '') PointBasedPixelization#
Create a pixelization from a ClosedPolygon2D.
- Parameters:
closed_polygon (ClosedPolygon2D) – The ClosedPolygon2D to create the pixelization from.
pixel_size (float) – The size of each pixel.
name (str) – Optional name for the pixelization.
- Returns:
A pixelization created from the ClosedPolygon2D.
- Return type:
- classmethod from_line_segment(line_segment: LineSegment2D, pixel_size: float, name: str = '') PointBasedPixelization#
Create a pixelization from a LineSegment2D.
- Parameters:
line_segment (LineSegment2D) – The LineSegment2D to create the pixelization from.
pixel_size (float) – The size of each pixel.
name (str) – Optional name for the pixelization.
- Returns:
A pixelization created from the LineSegment2D.
- Return type:
- classmethod from_matrix_based_pixelization(matrix_based_pixelization: MatrixBasedPixelization) PointBasedPixelization#
Create a PointBasedPixelization object from a MatrixBasedPixelization.
- Parameters:
matrix_based_pixelization (MatrixBasedPixelization) – The MatrixBasedPixelization object representing the pixelization.
- Returns:
A PointBasedPixelization object created from the MatrixBasedPixelization.
- Return type:
- intersection(other: PointBasedPixelization) PointBasedPixelization#
Create a pixelization that is the Boolean intersection of two pixelization.
Both pixelization must have same pixel size.
- Parameters:
other (PointBasedPixelization) – The other pixelization to compute the Boolean intersection with.
- Returns:
The created pixelization resulting from the Boolean intersection.
- Return type:
- inverse() PointBasedPixelization#
Compute the inverse of the pixelization.
- Returns:
A new pixelization representing the inverse.
- Return type:
- property max_grid_center: tuple[float, float]#
Get the maximum center point from the set of pixel centers, in the pixel 3D grid.
This point may not be a pixel of the pixelization, because it is the maximum center in each direction (X, Y).
- Returns:
The maximum center point.
- Return type:
tuple[float, float]
- property min_grid_center: tuple[float, float]#
Get the minimum center point from the set of pixel centers, in the pixel 3D grid.
This point may not be a pixel of the pixelization, because it is the minimum center in each direction (X, Y).
- Returns:
The minimum center point.
- Return type:
tuple[float, float]
- symmetric_difference(other: PointBasedPixelization) PointBasedPixelization#
Perform a symmetric difference operation with another PointBasedPixelization.
- Parameters:
other (PointBasedPixelization) – The PointBasedPixelization to perform the symmetric difference with.
- Returns:
A new PointBasedPixelization resulting from the symmetric difference operation.
- Return type:
- to_dict(*args, **kwargs) Dict[str, Any]#
Specific ‘to_dict’ method to allow serialization of a set.
- to_matrix_based_pixelization() MatrixBasedPixelization#
Convert the point based pixelization to a matrix based pixelization.
- Returns:
The matrix based pixelization.
- Return type:
- union(other: PointBasedPixelization) PointBasedPixelization#
Perform a union operation with another PointBasedPixelization.
- Parameters:
other (PointBasedPixelization) – The PointBasedPixelization to perform the union with.
- Returns:
A new PointBasedPixelization resulting from the union operation.
- Return type:
- class volmdlr.discrete_representation.PointBasedVoxelization(voxel_centers: set[tuple[float, float, float]], voxel_size: float, name: str = '')#
Bases:
VoxelizationVoxelization implemented as a set of points, representing each voxel center.
- classmethod dict_to_object(dict_: Dict[str, Any], *args, **kwargs) PointBasedVoxelization#
Specific ‘dict_to_object’ method to allow deserialization of a set.
- difference(other: PointBasedVoxelization) PointBasedVoxelization#
Perform a difference operation with another PointBasedVoxelization.
- Parameters:
other (PointBasedVoxelization) – The PointBasedVoxelization to perform the difference with.
- Returns:
A new PointBasedVoxelization resulting from the difference operation.
- Return type:
- flood_fill(start: tuple[float, float, float], fill_with: bool) PointBasedVoxelization#
Perform a flood fill operation on the voxelization.
- Parameters:
start (tuple[float, float, float]) – The coordinates of the starting point for the flood fill.
fill_with (bool) – The value to fill the voxels with during the operation.
- Returns:
A new voxelization resulting from the flood fill operation.
- Return type:
- classmethod from_matrix_based_voxelization(matrix_based_voxelization: MatrixBasedVoxelization) PointBasedVoxelization#
Create a PointBasedVoxelization object from a MatrixBasedVoxelization.
- Parameters:
matrix_based_voxelization (MatrixBasedVoxelization) – The MatrixBasedVoxelization object representing the voxelization.
- Returns:
A PointBasedVoxelization object created from the MatrixBasedVoxelization.
- Return type:
- classmethod from_mesh_data(vertices: Iterable[Iterable[float]], faces: Iterable[Iterable[int]], voxel_size: float, name: str = '') PointBasedVoxelization#
Create a PointBasedVoxelization from mesh data.
- Parameters:
vertices (Iterable[Iterable[float]]) – The vertices of the mesh.
faces (Iterable[Iterable[int]]) – The faces of the mesh, using vertices indexes.
voxel_size (float) – The size of each voxel.
name (str) – Optional name for the PointBasedVoxelization.
- Returns:
A PointBasedVoxelization created from the mesh data.
- Return type:
- intersection(other: PointBasedVoxelization) PointBasedVoxelization#
Perform an intersection operation with another PointBasedVoxelization.
- Parameters:
other (PointBasedVoxelization) – The PointBasedVoxelization to perform the intersection with.
- Returns:
A new PointBasedVoxelization resulting from the intersection operation.
- Return type:
- inverse() PointBasedVoxelization#
Compute the inverse of the voxelization.
- Returns:
A new voxelization representing the inverse.
- Return type:
- property max_grid_center: tuple[float, float, float]#
Get the maximum center point from the set of voxel centers, in the voxel 3D grid.
This point may not be a voxel of the voxelization, because it is the maximum center in each direction (X, Y, Z).
- Returns:
The maximum center point.
- Return type:
tuple[float, float, float]
- property min_grid_center: tuple[float, float, float]#
Get the minimum center point from the set of voxel centers, in the voxel 3D grid.
This point may not be a voxel of the voxelization, because it is the minimum center in each direction (X, Y, Z).
- Returns:
The minimum center point.
- Return type:
tuple[float, float, float]
- rotation(center: Point3D, axis: Vector3D, angle: float)#
Rotate the voxelization around the specified center, axis, and angle.
- Parameters:
- Returns:
A new Voxelization object resulting from the rotation.
- Return type:
- symmetric_difference(other: PointBasedVoxelization) PointBasedVoxelization#
Perform a symmetric difference operation with another PointBasedVoxelization.
- Parameters:
other (PointBasedVoxelization) – The PointBasedVoxelization to perform the symmetric difference with.
- Returns:
A new PointBasedVoxelization resulting from the symmetric difference operation.
- Return type:
- to_dict(*args, **kwargs) Dict[str, Any]#
Specific ‘to_dict’ method to allow serialization of a set.
- to_inner_growing_voxelizations(layers_minimal_thickness: float) list[PointBasedVoxelization]#
Convert the PointBasedVoxelization to multiple PointBasedVoxelization, with different voxel size.
The more the voxelization is inside, the more its voxel size become bigger.
- Parameters:
layers_minimal_thickness (float) – The minimal thickness of each layer.
- Returns:
A list of PointBasedVoxelization representing the inner growing voxelizations.
- Return type:
list[PointBasedVoxelization]
- to_matrix_based_voxelization() MatrixBasedVoxelization#
Convert the point based voxelization to a matrix based voxelization.
- Returns:
The matrix based voxelization.
- Return type:
- to_octree_based_voxelization() OctreeBasedVoxelization#
Convert the PointBasedVoxelization to an OctreeBasedVoxelization.
- Returns:
The octree based voxelization.
- Return type:
- translation(offset: Vector3D)#
Translate the voxelization by the specified offset.
- Parameters:
offset (Vector3D) – The translation offset.
- Returns:
A new Voxelization object resulting from the translation.
- Return type:
- union(other: PointBasedVoxelization) PointBasedVoxelization#
Perform a union operation with another PointBasedVoxelization.
- Parameters:
other (PointBasedVoxelization) – The PointBasedVoxelization to perform the union with.
- Returns:
A new PointBasedVoxelization resulting from the union operation.
- Return type:
- class volmdlr.discrete_representation.Voxelization(voxel_size: float, name: str)#
Bases:
DiscreteRepresentation,DessiaObject,Displayable3DAbstract base class for creating and manipulating voxelizations of volmdlr geometries.
This approach is used to create a voxelization of the surfaces, without filling the volume.
The voxelization is defined on an implicit 3D grid, where each voxel is defined by its size. The implicit grid consists of axis-aligned cubes with a given size, ensuring that the global origin (0, 0, 0) is always a corner point of a voxel.
For example, in 1D with a voxel size of t, the set of voxels (defined by minimum and maximum points) is: {i ∈ N, t ∈ R | (i * t, (i+1) * t)} The corresponding set of voxel centers is: {i ∈ N, t ∈ R | (i + 0.5) * t}
This approach enables consistent voxelization across the 3D space, facilitating fast Boolean operations.
- VoxelizationType = ~VoxelizationType#
- property bounding_box: BoundingBox#
Get the bounding box of the voxelization.
- Returns:
The bounding box of the voxelization.
- Return type:
- cad_view#
Implementation of a tag for displays.
- fill_enclosed_voxels() VoxelizationType#
Fill the enclosed voxels of the voxelization.
- Returns:
A new voxelization with enclosed voxels filled.
- Return type:
VoxelizationType
- fill_outer_voxels() VoxelizationType#
Fill the outer voxels of the voxelization.
- Returns:
A new voxelization with outer voxels filled.
- Return type:
VoxelizationType
- classmethod from_mesh(mesh: Mesh3D, voxel_size: float) VoxelizationType#
Create a voxelization from a Mesh3D.
- Parameters:
mesh – The Mesh3D to create the voxelization from.
voxel_size – The size of each voxel.
- classmethod from_mesh_data(vertices: Iterable[Iterable[float]], faces: Iterable[Iterable[int]], voxel_size: float, name: str = '') VoxelizationType#
Create a voxelization from mesh data.
- Parameters:
vertices (Iterable[Iterable[float]]) – The vertices of the mesh.
faces (Iterable[Iterable[int]]) – The faces of the mesh, using vertices indexes.
voxel_size (float) – The size of each voxel.
name (str) – Optional name for the voxelization.
- Returns:
A voxelization created from the mesh data.
- Return type:
VoxelizationType
- classmethod from_shell(shell: Shell3D, voxel_size: float, name: str = '') VoxelizationType#
Create a voxelization from a Shell3D.
- Parameters:
shell (Shell3D) – The Shell3D to create the voxelization from.
voxel_size (float) – The size of each voxel.
name (str) – Optional name for the voxelization.
- Returns:
A voxelization created from the Shell3D.
- Return type:
VoxelizationType
- classmethod from_triangles(triangles: list[tuple[tuple[float, float, float], tuple[float, float, float], tuple[float, float, float]]], voxel_size: float, name: str = '') VoxelizationType#
Create a voxelization from a list of triangles.
- Parameters:
triangles (list[tuple[tuple[float, float, float], tuple[float, float, float], tuple[float, float, float]]]) – The list of triangles to create the voxelization from.
voxel_size (float) – The size of each voxel.
name (str) – Optional name for the voxelization.
- Returns:
A voxelization created from the list of triangles.
- Return type:
VoxelizationType
- classmethod from_volume_model(volume_model: VolumeModel, voxel_size: float, name: str = '') VoxelizationType#
Create a voxelization from a VolumeModel.
- Parameters:
volume_model (VolumeModel) – The VolumeModel to create the voxelization from.
voxel_size (float) – The size of each voxel.
name (str) – Optional name for the voxelization.
- Returns:
A voxelization created from the VolumeModel.
- Return type:
VoxelizationType
- get_voxel_centers() set[tuple[float, float, float]]#
Get the center point of each voxel.
- Returns:
The center point of each voxel.
- Return type:
set[tuple[float, float, float]]
- get_voxel_centers_array() ndarray[Any, dtype[float]]#
Get the center point of each voxel as a numpy array.
- Returns:
The center point of each voxel.
- Return type:
np.ndarray[float]
- to_closed_triangle_shell() ClosedTriangleShell3D#
Generate a closed triangle shell representing the voxelization.
- Returns:
A closed triangle shell representation of the voxelization.
- Return type:
ClosedTriangleShell3D
- to_mesh() Mesh3D#
Generate a Mesh3D representing the voxelization.
- Returns:
A mesh representation of the voxelization.
- Return type:
- to_triangles() set[tuple[tuple[float, float, float], tuple[float, float, float], tuple[float, float, float]]]#
Convert the voxelization to triangles for display purpose.
Only the relevant faces are returned (i.e. the faces that are not at the interface of two different voxel, i.e. the faces that are only present once in the list of triangles representing the triangulated voxels).
- Returns:
The triangles representing the voxelization.
- Return type:
set[tuple[tuple[float, float, float], tuple[float, float, float], tuple[float, float, float]]]
- volmdlr_primitives(**kwargs)#
Generate volmdlr primitives.
- Parameters:
kwargs – Additional keyword arguments.
- Returns:
A list of volmdlr primitives.
- property volume: float#
Calculate the volume of the voxelization.
- Returns:
The volume of the voxelization.
- Return type:
float
- property voxel_size: float#
Get the voxel size.
- Returns:
The voxel size.
- Return type:
float
- static voxel_to_bounding_box(voxel_center: tuple[float, float, float], voxel_size: float) BoundingBox#
Create a bounding box from a voxel.
- Parameters:
voxel_center (tuple[float, float, float]) – The center point of the voxel.
voxel_size (float) – The size of the voxel edge.
- Returns:
The created bounding box.
- Return type: