pyntcloud Documentation

repository·main·Indexed 23 days ago

https://github.com/daavoo/pyntcloud

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

Tokens
12.9K
Snippets
31
Records
101
Agent score
80%

What's inside pyntcloud

  1. Overview of pyntcloud modules

    main

    The pyntcloud library 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.
  2. Use VoxelGrid for spatial analysis

    main

    A VoxelGrid structure 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.
  3. How to implement a custom Scalar Field

    main

    Scalar fields are used by the PyntCloud.add_scalar_field method to generate new DataFrame columns based on point cloud data. To implement a new scalar field, you must follow a hierarchical inheritance pattern:

    1. Inherit from ScalarField: All filters must inherit from the base class pyntcloud.scalar_fields.base.ScalarField and implement its abstract methods.
    2. Implement extract_info: Override this method to extract and save the information required for computation into an attribute.
    3. 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__ and extract_info to handle that shared data extraction.

  4. PyntCloud method categories

    main

    Methods in PyntCloud are 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).
  5. Implement a Submodule Base Class for shared data requirements

    main

    Scalar fields are organized into submodules based on the information they require (e.g., sf_voxelgrid.py for fields requiring a VoxelGrid).

    To avoid redundant code, create a Submodule Base Class that inherits from ScalarField. This class should override __init__ and extract_info to 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 the compute method.

  6. How to implement a custom Sampler

    main

    To add a new sampler to pyntcloud, you must follow a hierarchical inheritance pattern. All samplers are classes that are eventually used by the PyntCloud.get_sampler method.

    Implementation Steps:

    1. Inherit from the Base Class: All samplers must inherit from pyntcloud.samplers.base.Sampler.
    2. 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.
    3. Implement compute: This is where the actual sampling logic resides. It must use the information previously extracted by extract_info to generate and return the sample.
    4. 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_Voxelgrid in pyntcloud.samplers.s_voxelgrid) that overrides __init__ and extract_info to handle that specific data requirement.
    5. 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).
  7. How to implement a custom filter in PyntCloud

    main

    To create a new filter, you must follow a hierarchical inheritance pattern. All filters are classes that are eventually used by the PyntCloud.get_filter method.

    1. Inherit from the Base Class: All filters must inherit from pyntcloud.filters.base.Filter.
    2. Implement extract_info: Override this method to extract and save the information required to compute the filter into an attribute.
    3. Implement compute: Override this method to generate and return the boolean array that decides which points should be filtered.
    4. 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_KDTree in pyntcloud/filters/f_kdtree.py) instead of the root Filter class. These submodule bases override __init__ and extract_info to handle the shared requirements.
  8. Create PyntCloud instances from custom data sources

    main
    If your data is in a format not supported by from_file, you can still create a PyntCloud instance manually. The requirement is that you must be able to load the data into Python and adapt it to the specific restrictions required by the PyntCloud constructor (see the points documentation for these restrictions).
  9. Add structures to PyntCloud instances

    main

    Structures are used to add advanced capabilities (superpowers) to PyntCloud instances, 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 a PyntCloud instance using the add_structure method.

    PyntCloud.add_structure
  10. What are Scalar Fields in PyntCloud?

    main
    In pyntcloud, a Scalar Field is essentially any column in the PyntCloud.points DataFrame. While point clouds fundamentally require at least three columns for x, y, and z coordinates, 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, pyntcloud extends this term to any column in the Points DataFrame.
  11. The PyntCloud core class

    main
    The PyntCloud class is the central object in the library. Unlike a simple set of points, a PyntCloud instance 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.