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, Hdf5SerializerMixin

A 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 the properties attribute or directly with point_cloud[name].

Note

The coordinates are copied when they are set and stored as a numpy.float64 array. The coordinates attribute returns a read-only view: to change the coordinates, assign a new array.

Important

The properties are stored in a pysdic.core.property_container.PropertyContainer with force_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 of coordinates. If given, it must match this shape.

  • properties (Optional[Union[Dict[str, ArrayLike], PropertyContainer]], optional) –

    The properties of the points:

Notes

len(point_cloud) gives the number of points \(N_p\), while point_cloud[name], name in point_cloud and iter(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 the coordinates setter (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): the coordinates setter then raises a RuntimeError explaining 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()) or vtk (from_vtk(), from_vtk_file()).

PointCloud.from_array(coordinates, *[, ...])

Create a point cloud from an array of coordinates.

PointCloud.from_meshio(mesh, *[, ...])

Create a point cloud from the vertices of a meshio.Mesh.

PointCloud.from_pyvista(mesh, *[, ...])

Create a point cloud from the points of a pyvista.DataSet (pyvista.PolyData, pyvista.UnstructuredGrid, ...).

PointCloud.from_vtk(dataset, *[, ...])

Create a point cloud from the points of a VTK dataset (vtkPolyData, vtkUnstructuredGrid, vtkStructuredGrid, ..., i.e. any vtkPointSet).

PointCloud.from_vtk_file(file_path, *[, ...])

Create a point cloud from a legacy VTK file (.vtk, only 3D point clouds).

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].

PointCloud.coordinates

[Get/Set] The coordinates of the points, an array of shape \((N_p, E)\).

PointCloud.n_dimensions

[Get] The dimension \(E\) of the space.

PointCloud.n_points

[Get] The number of points \(N_p\).

PointCloud.n_properties

[Get] The number of properties of the points.

PointCloud.properties

[Get] The properties of the points.

PointCloud.shape

[Get] The shape \((N_p, E)\) of the coordinates.

Structure methods#

PointCloud.concatenate(other, *[, ...])

Concatenate two point clouds (the points of other come after).

PointCloud.copy(*[, copy_properties])

Create a copy of the point cloud.

PointCloud.filter_points(mask, *[, ...])

Keep only the points selected by a boolean mask.

PointCloud.keep_points_by_index(indices, *)

Keep only the points with the given indices.

PointCloud.remove_points_by_index(indices, *)

Remove the points with the given indices.

PointCloud.insert_dimension(dim[, value, ...])

Insert a new coordinate axis, giving a point cloud of shape \((N_p, E+1)\).

PointCloud.remove_dimension(dim, *[, ...])

Remove one coordinate axis, giving a point cloud of shape \((N_p, E-1)\).

Checks and geometry#

PointCloud.validate(*[, recursive])

Validate the integrity of the point cloud.

PointCloud.all_close(other, *[, rtol, atol, ...])

Check if the points are approximately equal to the points of another point cloud (see numpy.allclose).

PointCloud.all_finite()

Check if all the coordinates are finite (no NaN or infinite values).

PointCloud.is_finite()

Check which points have only finite coordinates.

PointCloud.has_nan()

Check which points have at least one NaN coordinate.

PointCloud.has_inf()

Check which points have at least one infinite coordinate.

PointCloud.bounding_box()

Compute the axis-aligned bounding box of the point cloud.

PointCloud.bounding_sphere()

Compute a bounding sphere of the point cloud.

PointCloud.frame_transform([input_frame, ...])

Express the points, given in input_frame, in output_frame (only for 3D point clouds).

Conversion and visualization#

Export to arrays and other libraries (the meshio, pyvista, vtk and py3dframe methods require the corresponding optional packages).

PointCloud.to_array()

Return a copy of the coordinates.

PointCloud.to_meshio(*[, save_properties])

Convert the point cloud to a meshio.Mesh without cells.

PointCloud.to_pyvista(*[, only_finite, ...])

Convert the point cloud to a pyvista.PolyData (only for 3D point clouds).

PointCloud.to_vtk(*[, only_finite, ...])

Convert the point cloud to a vtkPolyData (only for 3D point clouds).

PointCloud.to_vtk_file(file_path, *[, ...])

Save the point cloud to a legacy VTK file (.vtk, only for 3D point clouds).

PointCloud.quick_visualize(*[, warp_by, ...])

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).

PointCloud.to_dict(*[, save_properties])

Convert the point cloud to a flat dictionary.

PointCloud.from_dict(data, *[, load_properties])

Create a point cloud from a dictionary.

PointCloud.to_json_file(file_path, *[, ...])

Serialize the object to a JSON file.

PointCloud.from_json_file(file_path, **kwargs)

Deserialize a JSON file to an object of the class.

PointCloud.to_hdf5_file(file_path, *[, ...])

Serialize the object to an HDF5 file.

PointCloud.from_hdf5_file(file_path, **kwargs)

Deserialize an object from an HDF5 file.

PointCloud.to_npz_file(file_path, *[, make_dirs])

Serialize the object to an NPZ file.

PointCloud.from_npz_file(file_path, **kwargs)

Deserialize an object from an NPZ file.