pchandler.scalar_fields.scalar_field_manager

ScalarFieldManager: container for the per-point scalar fields of a PointCloudData.

Module Attributes

SF_T

Base scalar field TypeAlias

SFLikeT

Scalar Field like TypeAlias, also supporting other arrays of similar shape

RGBLikeT

RGB like TypeAlias

NormalLikeT

Normal like TypeAlias

SFMLikeT

ScalarFieldManager like dict TypeAlias

Classes

ScalarFieldManager

Manages scalar fields associated with a point cloud.

class pchandler.scalar_fields.scalar_field_manager.ScalarFieldManager

Bases: object

Manages scalar fields associated with a point cloud.

Contains mechanisms for adding, changing and removing scalar fields as well as validating lengths with respect to a parent point cloud object.

Parameters:
__init__(fields=None, *, parent=None)

Initialise the scalar field manager.

Ensures all fields passed are converted to ScalarField (or the appropriate RGBFields / NormalFields) objects. If a parent point cloud is provided, it is stored as a weakref and scalar-field lengths will be validated against it.

Parameters:
fields: dict[str, SF_T]
validate_lengths()

Check that every scalar field’s length matches the parent point cloud’s point count.

Raises:

ValueError – If any scalar field’s length differs from the parent point count.

keys()

Return the scalar field names stored in the manager.

Return type:

KeysView[str]

values()

Return the scalar field values stored in the manager.

Return type:

ValuesView[SF_T]

items()

Return the scalar field names and values stored in the manager.

Return type:

ItemsView[str, SF_T]

property parent: PointCloudData | None

Return the parent point cloud object.

Return type:

PointCloudData | None

property shape: tuple[int, int]

Return the shape of the scalar field manager.

The shape will be in the form (num_points, num_fields).

Return type:

tuple[int, int]

property num_points: int

Return the number of points in the parent point cloud, or -1 if no parent is set.

Returns:

Parent point count, or -1.

Return type:

int

property rgb: RGBFields | None

Get the RGB fields.

Return type:

RGBFields | None

property normals: NormalFields | None

Get the normals fields.

Return type:

NormalFields | None

property intensity: ScalarField | None

Get the intensity field, or None if not set.

Returns:

Intensity field, or None.

Return type:

ScalarField | None

property reflectance: ScalarField | None

Get the reflectance field.

Return type:

ScalarField | None

sample(mask)

Sample the scalar fields based on a mask.

Parameters:

mask (IndexLike) – The mask corresponds to indexing the rows or points in the parent point cloud.

Return type:

ScalarFieldManager

reduce(mask)

Reduce every scalar field in place to the rows selected by mask.

Parameters:

mask (IndexLike) – The mask corresponds to indexing the rows or points in the parent point cloud.

extract(mask)

Return a new manager carrying the selected rows; also reduces self to the complement.

Parameters:

mask (IndexLike) – The mask corresponds to indexing the rows or points in the parent point cloud.

Returns:

New manager containing the rows selected by mask.

Return type:

ScalarFieldManager

add_field(sf_field)

Add a new scalar field to the manager (keyed by sf_field.name).

Parameters:

sf_field (SF_T) – Scalar field to add.

remove_field(field_name)

Remove a scalar field from the manager by name.

Parameters:

field_name (LowerStr) – Name of the field to remove.

create_field(name, data)

Create a scalar field from a name and an array, then add it to the manager.

Supports Array_Nx3_T for the creation of RGB or Normals fields.

Parameters:
  • name (str) – Name of the new field.

  • data (VectorT | Array_Nx3_T) – Field data.

classmethod merge(scalar_field_managers)

Merge a list of scalar-field managers, keeping only the fields they all share.

Parameters:

scalar_field_managers (Iterable[ScalarFieldManager]) – Managers to merge.

Returns:

New manager containing every commonly-named scalar field concatenated along axis 0.

Return type:

ScalarFieldManager

Raises:

ValueError – If scalar_field_managers is empty.

as_struct_array()

Return the scalar fields packed into a single numpy structured array.