skshapes.decimation package¶
Submodules¶
skshapes.decimation.decimation module¶
Decimation module.
- class skshapes.decimation.decimation.Decimation(*, target_reduction=None, n_points=None, ratio=None)¶
Bases:
object
Decimation class.
This class implements the quadric decimation algorithm. The goal of decimation is to reduce the number of points of a triangular mesh while preserving the global aspect of the shape.
- Parameters:
- Raises:
InputStructureError – If both target_reduction and n_points are provided or if none of them is provided.
Examples
Decimate a mesh with a target reduction:
import skshapes as sks mesh = sks.Sphere() decimator = sks.Decimation(target_reduction=0.5) decimated_mesh = decimator.fit_transform(mesh)
Decimate two meshes with the same connectivity (same triangles):
# assume that pose1 and pose2 are two meshes with the same connectivity: pose1, pose2 = sks.PolyData("data/pose1.vtk", "data/pose2.vtk") decimator = sks.Decimation(n_points=50) decimator.fit(cat1) pose1_decimated = decimator.transform(cat1) pose2_decimated = decimator.transform(cat2) # pose1_decimated and pose2_decimated have the same connectivity assert torch.allclose(pose1_decimated.triangles, pose2_decimated.triangles) # if landmarks are present in the meshes, they are kept after the # decimation if pose1.landmarks is not None: assert pose1_decimated.landmarks is not None if pose2.landmarks is not None: assert pose2_decimated.landmarks is not None
Decimation is often used through the Multiscale interface.
- property actual_reduction¶
Returns the actual reduction of the decimation algorithm.
- property collapses¶
Returns the collapses of the decimation algorithm.
- fit(mesh)¶
Fit the decimation algorithm to a mesh.
- Parameters:
mesh (
polydata_type
) – The mesh to fit the decimation object to.- Raises:
ValueError – If the mesh is not triangular.
- Returns:
self
- Return type:
- fit_transform(mesh, *, target_reduction=None, n_points=None, n_points_strict=None, ratio=None, return_indice_mapping=False)¶
Decimate and return decimated mesh.
- Return type:
polydata_type
|tuple
[polydata_type
,Int64[Tensor, '_']
]
- property ref_mesh¶
Returns the reference mesh of the decimation algorithm.
- transform(mesh, *, target_reduction=None, n_points=None, n_points_strict=None, ratio=None, return_indice_mapping=False)¶
Transform a mesh using the decimation algorithm.
The decimation must have been fitted to a mesh before calling this method. The mesh to decimate could be: - the same mesh as the one used to fit the decimation object - a mesh with the same connectivity as the one used to fit the decimation object (same number of points and same triangles)
- Parameters:
mesh (
polydata_type
) – The mesh to transform.target_reduction (
float
|None
) – The target reduction to apply to the mesh.n_points (
int
|None
) – The targeted number of points. Fast but it is not guaranteed that the decimation algorithm will exactly reach this number of points. If you want to be sure that the decimation algorithm will reach this number of points, use n_points_strict instead.n_points_strict (
int
|None
) – The targeted number of points. This parameter can lead to a slower decimation algorithm because the algorithm will try to reach this number of points exactly, and this may require many iterations.ratio (
float
|None
) – The ratio of the number of points of the mesh to decimate over the number of points of the mesh used to fit the decimation object.return_indice_mapping (
bool
) – If True, the indice mapping is returned as well as the decimated mesh.
- Raises:
ValueError – If the decimation object has not been fitted yet. If the number of points or the triangles structure of the mesh to decimate is not the same as the mesh using to fit.
- Returns:
The decimated mesh.
- Return type: