pchandler.data_io.core

Base module for I/O handlers and supporting helper methods.

Defines AbstractIOHandler (the contract every per-format handler implements), SUPPORTED_TYPES (the canonical set of file suffixes pchandler.load_file() accepts), find_point_cloud_in_directory() (directory-walking helper), and the private name-cleaning and dtype-derivation helpers used by the concrete handlers.

Functions

find_point_cloud_in_directory(directory_path)

Search a directory for point cloud files with specific extensions.

Classes

AbstractIOHandler

Abstract base class for per-format point-cloud I/O handlers.

PointCloudDataKW

Optional keyword arguments accepted by pchandler.PointCloudData.

class pchandler.data_io.core.AbstractIOHandler

Bases: ABC

Abstract base class for per-format point-cloud I/O handlers.

Concrete subclasses (PlyHandler, LasHandler, etc.) declare the file extensions they support via FORMATS and implement load() and save(). Shared helpers for field-name cleaning, dtype assembly, and structured-array generation are provided here.

FORMATS: list[str] = []
classmethod find_pcds_in_directory(directory_path, include_subdirectories=True)

Find all point cloud files in a specified directory.

Parameters:
  • directory_path (str | Path) – Directory to search.

  • include_subdirectories (bool, default=True) – If True, recurse into subdirectories.

Returns:

Paths to all point-cloud files whose suffix matches FORMATS.

Return type:

list[Path]

abstractmethod classmethod load(path, scalar_fields=None, remove_prefix=True, prefix='scalar_', **pcd_kw)

Load a point cloud (or stream of point clouds) from path — implemented by subclasses.

abstractmethod classmethod save(pcd, path, scalar_fields=None, add_prefix=False, prefix='scalar_', revert_sf_types=False, **config)

Save pcd to path — implemented by subclasses.

classmethod extract_xyz(data, num_points)

Extract XYZ components from the given structured array or dict.

Parameters:
  • data (BaseDataT) – Structured-array or dict keyed by x / y / z.

  • num_points (int) – Number of points in data.

Returns:

An (N, 3) array assembled from the three coordinate columns.

Return type:

Array_Nx3_T

classmethod extract_scalar_fields(pcd, data, num_points, field_names)

Extract scalar fields from the given structured array or dict and attach them to pcd.

Parameters:
  • pcd (PointCloudData) – Point cloud to populate with scalar fields.

  • data (BaseDataT) – Structured array or dict containing per-point scalar columns.

  • num_points (int) – Number of points in data.

  • field_names (dict[str, str]) – Mapping of scalar field names to their corresponding data keys in the dataset.

pchandler.data_io.core.find_point_cloud_in_directory(directory_path, pcd_file_types=SUPPORTED_TYPES, include_subdirectories=True)

Search a directory for point cloud files with specific extensions.

Parameters:
  • directory_path (Path) – Path of directory to search.

  • pcd_file_types (list[str]) – List of extension names (e.g. [‘.ply’, ‘.las’, ‘.txt’]).

  • include_subdirectories (bool, default=True) – Flag to include a subdirectory search

Return type:

list[Path]