pysdic.PointCloud#
The pysdic.PointCloud stores \(N_p\) points in a space of dimension \(E\) (coordinates of shape \((N_p, E)\)) with optional properties for each point.
PointCloud class#
- class PointCloud(coordinates, *, n_dimensions=None, properties=None)[source]#
Bases:
LockableMixin,JsonSerializerMixin,NpzSerializerMixin,Hdf5SerializerMixinA cloud of \(N_p\) points in a \(E\)-dimensional space.
Each point can carry additional properties (colors, normals, displacements, …) stored in a
pysdic.core.property_container.PropertyContainer, accessible through thepropertiesattribute or directly withpoint_cloud[name].Note
The coordinates are copied when they are set and stored as a
numpy.float64array. Thecoordinatesattribute returns a read-only view: to change the coordinates, assign a new array.Important
The properties are stored in a
pysdic.core.property_container.PropertyContainerwithforce_2d=True, i.e. with shape \((N_p, P)\). A container given by the user with other settings is accepted, but some operations (like VTK export) may behave unexpectedly.- Parameters:
coordinates (ArrayLike) – An array of shape \((N_p, E)\) with the coordinates of the points. A 1D array of shape \((N_p,)\) is accepted if
n_dimensions=1.n_dimensions (Optional[Integral], optional (default:
None)) – The dimension \(E\) of the space. By default, it is inferred from the shape ofcoordinates. If given, it must match this shape.properties (Optional[Union[Dict[str, ArrayLike], PropertyContainer]], optional) –
The properties of the points:
a dictionary mapping names to arrays of shape \((N_p, \dots)\), which are copied into a new
pysdic.core.property_container.PropertyContainer,or a
pysdic.core.property_container.PropertyContainerwith \(N = N_p\), which is shared (not copied).
Notes
len(point_cloud)gives the number of points \(N_p\), whilepoint_cloud[name],name in point_cloudanditer(point_cloud)refer to the properties.The methods never modify the point cloud in place: the methods that change the points (
filter_points(),frame_transform(),remove_dimension(), …) return a new point cloud. Only thecoordinatessetter (same number of points) and the properties modify an existing point cloud.Note
A point cloud can be locked by an object of the package that owns it (for example the mesh of an SDIC analysis, see
pysdic.core.lockable.LockableMixin): thecoordinatessetter then raises aRuntimeErrorexplaining why. The properties can always be modified. A copy (copy) is always unlocked.
Instantiation#
The PointCloud class can be instantiated in several ways:
From an array of coordinates of shape \((N_p, E)\) with the constructor or the classmethod
from_array().From other libraries:
meshio(from_meshio()),pyvista(from_pyvista()) orvtk(from_vtk(),from_vtk_file()).
|
Create a point cloud from an array of coordinates. |
|
Create a point cloud from the vertices of a |
|
Create a point cloud from the points of a |
|
Create a point cloud from the points of a VTK dataset ( |
|
Create a point cloud from a legacy VTK file ( |
Implemented methods and attributes#
The following sections provide an overview of the attributes and methods defined
in the pysdic.PointCloud class.
Attributes#
The points can carry properties stored in a property container (see Core Tools), accessible with obj.properties or directly with obj[name].
[Get/Set] The coordinates of the points, an array of shape \((N_p, E)\). |
|
[Get] The dimension \(E\) of the space. |
|
[Get] The number of points \(N_p\). |
|
[Get] The number of properties of the points. |
|
[Get] The properties of the points. |
|
[Get] The shape \((N_p, E)\) of the coordinates. |
Structure methods#
|
Concatenate two point clouds (the points of |
|
Create a copy of the point cloud. |
|
Keep only the points selected by a boolean mask. |
|
Keep only the points with the given indices. |
|
Remove the points with the given indices. |
|
Insert a new coordinate axis, giving a point cloud of shape \((N_p, E+1)\). |
|
Remove one coordinate axis, giving a point cloud of shape \((N_p, E-1)\). |
Checks and geometry#
|
Validate the integrity of the point cloud. |
|
Check if the points are approximately equal to the points of another point cloud (see |
Check if all the coordinates are finite (no NaN or infinite values). |
|
Check which points have only finite coordinates. |
|
Check which points have at least one NaN coordinate. |
|
Check which points have at least one infinite coordinate. |
|
Compute the axis-aligned bounding box of the point cloud. |
|
Compute a bounding sphere of the point cloud. |
|
|
Express the points, given in |
Conversion and visualization#
Export to arrays and other libraries (the meshio, pyvista, vtk and py3dframe methods require the corresponding optional packages).
Return a copy of the coordinates. |
|
|
Convert the point cloud to a |
|
Convert the point cloud to a |
|
Convert the point cloud to a |
|
Save the point cloud to a legacy VTK file ( |
|
Visualize the point cloud with PyVista (only for \(E \leq 3\)). |
Serialization methods#
The pysdic.PointCloud is converted to a flat dictionary with to_dict (and created back with
from_dict). It inherits the file methods of the serialization mixins
(see Core Tools).
|
Convert the point cloud to a flat dictionary. |
|
Create a point cloud from a dictionary. |
|
Serialize the object to a JSON file. |
|
Deserialize a JSON file to an object of the class. |
|
Serialize the object to an HDF5 file. |
|
Deserialize an object from an HDF5 file. |
|
Serialize the object to an NPZ file. |
|
Deserialize an object from an NPZ file. |