pyntcloud Documentation
repository·main·Indexed 23 days ago
https://github.com/daavoo/pyntcloudA Python library for 3D point cloud processing that leverages the scientific Python stack. It provides a high-level interface via the PyntCloud class for operations including voxelization, sampling, scalar field manipulation, and filtering. The library supports various file formats (such as .ply, .pcd, .las, and .obj) and offers integration with Open3D and PyVista. Key modules include filters, geometry, io, neighbors, and structures for building spatial indexes like KD-Trees.
What's inside pyntcloud
- pyntcloud is a Python library designed for working with 3D point clouds. It provides tools for point cloud manipulation, filtering, sampling, and integration with other scientific Python libraries.
Overview of pyntcloud modules
mainThe
pyntcloudlibrary is organized into several independent modules that cover common point cloud processing operations:- filters: For data filtering operations.
- geometry: For geometric computations.
- io: For input/output operations (reading/writing files).
- learn: For machine learning related tasks.
- neighbors: For spatial neighbor searches.
- plot: For visualization.
- ransac: For RANSAC-based algorithms.
- sampling: For point cloud sampling.
- scalar_fields: For managing and computing scalar attributes on points.
- structures: For building spatial data structures (like KD-Trees).
- utils: General utility functions.
Use VoxelGrid for spatial analysis
mainA
VoxelGridstructure can be added to a point cloud to enable several spatial operations, including:- Converting a point cloud into a valid input for a convolutional neural network.
- Finding nearest neighbors.
- Finding unconnected clusters of points in the point cloud.
How to implement a custom Scalar Field
mainScalar fields are used by the
PyntCloud.add_scalar_fieldmethod to generate new DataFrame columns based on point cloud data. To implement a new scalar field, you must follow a hierarchical inheritance pattern:- Inherit from
ScalarField: All filters must inherit from the base classpyntcloud.scalar_fields.base.ScalarFieldand implement its abstract methods. - Implement
extract_info: Override this method to extract and save the information required for computation into an attribute. - Implement
compute: Override this method to perform the actual calculation and generate the new DataFrame columns.
If your scalar field belongs to a group that shares common data requirements (e.g., all fields requiring a VoxelGrid), you should first create or use a Submodule Base Class (like
ScalarField_Voxelgrid) which overrides__init__andextract_infoto handle that shared data extraction.- Inherit from
PyntCloud method categories
mainMethods in
PyntCloudare organized by their functional purpose:- ADD methods: Used to incorporate new information into existing attributes (e.g.,
add_scalar_field,add_structure). - GET methods: Used to extract information from the cloud (e.g.,
get_filter,get_sample,get_neighbors,get_mesh_vertices). - I/O methods: Used for reading from or writing to different 3D file formats (e.g.,
from_file,to_file). - Other methods: General manipulation tools (e.g.,
apply_filter,split_on,plot).
- ADD methods: Used to incorporate new information into existing attributes (e.g.,
Implement a Submodule Base Class for shared data requirements
mainScalar fields are organized into submodules based on the information they require (e.g.,
sf_voxelgrid.pyfor fields requiring a VoxelGrid).To avoid redundant code, create a Submodule Base Class that inherits from
ScalarField. This class should override__init__andextract_infoto handle the common data extraction logic for all fields in that submodule. Specific scalar field classes then inherit from this submodule base class and only need to implement thecomputemethod.How to implement a custom Sampler
mainTo add a new sampler to
pyntcloud, you must follow a hierarchical inheritance pattern. All samplers are classes that are eventually used by thePyntCloud.get_samplermethod.Implementation Steps:
- Inherit from the Base Class: All samplers must inherit from
pyntcloud.samplers.base.Sampler. - Implement
extract_info: Override this method to extract and save the information required to generate the sample into an attribute. This method is called before computation. - Implement
compute: This is where the actual sampling logic resides. It must use the information previously extracted byextract_infoto generate and return the sample. - Use Submodule Base Classes (Optional but Recommended): If your sampler requires specific data structures (like a
VoxelGrid), create or use a submodule base class (e.g.,Sampler_Voxelgridinpyntcloud.samplers.s_voxelgrid) that overrides__init__andextract_infoto handle that specific data requirement. - Handle User Parameters: If your sampler requires specific user-defined parameters, override the
__init__method to accept them (e.g., specifying whether to use RGB or normal information).
- Inherit from the Base Class: All samplers must inherit from
How to implement a custom filter in PyntCloud
mainTo create a new filter, you must follow a hierarchical inheritance pattern. All filters are classes that are eventually used by the
PyntCloud.get_filtermethod.- Inherit from the Base Class: All filters must inherit from
pyntcloud.filters.base.Filter. - Implement
extract_info: Override this method to extract and save the information required to compute the filter into an attribute. - Implement
compute: Override this method to generate and return the boolean array that decides which points should be filtered. - Use Submodule Base Classes: If your filter belongs to a group that requires specific shared data (e.g., a KDTree), inherit from a submodule base class (like
Filter_KDTreeinpyntcloud/filters/f_kdtree.py) instead of the rootFilterclass. These submodule bases override__init__andextract_infoto handle the shared requirements.
- Inherit from the Base Class: All filters must inherit from
Create PyntCloud instances from custom data sources
mainIf your data is in a format not supported byfrom_file, you can still create aPyntCloudinstance manually. The requirement is that you must be able to load the data into Python and adapt it to the specific restrictions required by thePyntCloudconstructor (see thepointsdocumentation for these restrictions).Add structures to PyntCloud instances
mainStructures are used to add advanced capabilities (superpowers) to
PyntCloudinstances, such as spatial indexing or mesh generation. All structures are built on top of an existing point cloud, mesh, or another structure. You can attach a structure to aPyntCloudinstance using theadd_structuremethod.PyntCloud.add_structureWhat are Scalar Fields in PyntCloud?
mainInpyntcloud, a Scalar Field is essentially any column in thePyntCloud.pointsDataFrame. While point clouds fundamentally require at least three columns forx,y, andzcoordinates, any additional information associated with each point (such as color values like Red, Green, and Blue) is considered a Scalar Field. Although traditionally restricted to numeric values in literature,pyntcloudextends this term to any column in thePointsDataFrame.The PyntCloud core class
mainThePyntCloudclass is the central object in the library. Unlike a simple set of points, aPyntCloudinstance is a rich Python object that encapsulates point cloud data along with various attributes and methods for manipulation. It acts as a container for points, meshes, structures, and metadata.