pchandler.scalar_fields
Public API for ScalarField and ScalarFieldManager classes.
- class pchandler.scalar_fields.ScalarField
Bases:
BaseVector,AbstractScalarFieldGeneric scalar field backed by a 1D vector.
- __init__(arr, name=None, origin_dtype=None)
Initialise a
ScalarFieldfrom a 1D vector.- Parameters:
arr (VectorT | Array_Nx3_T | Self) – Underlying 1D values.
name (SfNameT, optional) – Field name; inferred from
arror class default if omitted.origin_dtype (SfOrigDtT, optional) – Original
DtypeState; auto-generated if omitted.
- class pchandler.scalar_fields.ScalarFieldTriplet
Bases:
ArrayNx3,AbstractScalarFieldScalar field triplet (
(N, 3)) used as the base for RGB and Normal fields.- Parameters:
arr (Array_Nx3_T) – Underlying
(N, 3)array.
- __init__(arr, name=None, origin_dtype=None)
Initialise a
ScalarFieldTripletfrom an(N, 3)array.
- classmethod initialize(size, value=None, name='', origin_dtype=None)
Build a triplet of length
size, optionally pre-filled withvalue.- Parameters:
size (int) – Number of rows to allocate.
value (Array_Nx3_Uint8_T, optional) – Pre-existing values to seed the triplet with; zeros if omitted.
name (str, optional) – Field name; default is empty.
origin_dtype (SfOrigDtT, optional) – Original
DtypeStateto attach to the resulting field — preserved acrossScalarFieldManager._set_rgb()per-channel sets so that round-trips through PLY / LAS write the field back in its source dtype (DEBT-04).
- class pchandler.scalar_fields.RGBFields
Bases:
ScalarFieldTripletRGB / Color field, represented by a scalar field triplet of uint8 values.
- Parameters:
arr (Array_Nx3_Uint8_T) – Underlying
(N, 3)uint8 array.
- __init__(arr, **kwargs)
Initialise an RGB field.
Will convert any floating point values to uint8.
- as_normalised_float32()
Return the RGB values as a normalized float32 array in the range of [0,1].
- Return type:
Array_Nx3_Float32_T
- property b: GSEGUtils.base_types.Vector_Uint8_T
Return the blue component of the RGB values.
- Return type:
Vector_Uint8_T
- property blue: GSEGUtils.base_types.Vector_Uint8_T
Return the blue component of the RGB values.
- Return type:
Vector_Uint8_T
- property g: GSEGUtils.base_types.Vector_Uint8_T
Return the green component of the RGB values.
- Return type:
Vector_Uint8_T
- property green: GSEGUtils.base_types.Vector_Uint8_T
Return the green component of the RGB values.
- Return type:
Vector_Uint8_T
- property r: GSEGUtils.base_types.Vector_Uint8_T
Return the red component of the RGB values.
- Return type:
Vector_Uint8_T
- property red: GSEGUtils.base_types.Vector_Uint8_T
Return the red component of the RGB values.
- Return type:
Vector_Uint8_T
- arr: Array_Nx3_Uint8_T
Contains the raw numpy ndarray data
- class pchandler.scalar_fields.NormalFields
Bases:
ScalarFieldTripletNormal-vector field represented by a scalar field triplet of float32 unit vectors.
- Parameters:
arr (Array_Nx3_Float32_T) – Underlying
(N, 3)float32 array.
- __init__(arr, **kwargs)
Initialize a normal vector field.
Values will be normalized to unit vectors and converted to float32.
- Parameters:
arr (Array_Nx3_Float_T | Self)
kwargs (Unpack[_ScalarKwargT])
- classmethod initialize(length, value=None)
Build a
NormalFieldsof lengthlength, optionally seeded withvalue.- Parameters:
length (int) – Number of rows to allocate.
value (Array_Nx3_Float32_T, optional) – Existing values to initialise the array with (defaults to unit vectors along
+Z).
- Returns:
New normals field of the requested length.
- Return type:
- property nx: GSEGUtils.base_types.Vector_Float32_T
Return the X component of the normal vector.
- property ny: GSEGUtils.base_types.Vector_Float32_T
Return the Y component of the normal vector.
- property nz: GSEGUtils.base_types.Vector_Float32_T
Return the Z component of the normal vector.
- arr: Array_Nx3_Float32_T
Contains the raw numpy ndarray data
- class pchandler.scalar_fields.ScalarFieldManager
Bases:
objectManages 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:
fields (dict[str, ScalarField|NormalFields|RGBFields])
_parent (weakref.ReferenceType[PointCloudData] | None)
- __init__(fields=None, *, parent=None)
Initialise the scalar field manager.
Ensures all fields passed are converted to
ScalarField(or the appropriateRGBFields/NormalFields) objects. If a parent point cloud is provided, it is stored as aweakrefand scalar-field lengths will be validated against it.- Parameters:
fields (dict[str, ScalarField | NormalFields | RGBFields | np.ndarray] | ScalarFieldManager | None) – Initial scalar fields, either as raw dict, another manager, or
None(empty manager).parent (PointCloudData, optional) – Owning point cloud; stored as a weakref so that length validation can be performed.
- 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.
- as_struct_array()
Return the scalar fields packed into a single numpy structured array.
- create_field(name, data)
Create a scalar field from a name and an array, then add it to the manager.
Supports
Array_Nx3_Tfor the creation of RGB or Normals fields.- Parameters:
name (str) – Name of the new field.
data (VectorT | Array_Nx3_T) – Field data.
- extract(mask)
Return a new manager carrying the selected rows; also reduces
selfto 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:
- property intensity: ScalarField | None
Get the intensity field, or
Noneif not set.- Returns:
Intensity field, or
None.- Return type:
ScalarField | None
- items()
Return the scalar field names and values stored in the manager.
- Return type:
ItemsView[str, SF_T]
- 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:
- Raises:
ValueError – If
scalar_field_managersis empty.
- property normals: NormalFields | None
Get the normals fields.
- Return type:
NormalFields | None
- property num_points: int
Return the number of points in the parent point cloud, or
-1if no parent is set.- Returns:
Parent point count, or
-1.- Return type:
- property parent: PointCloudData | None
Return the parent point cloud object.
- Return type:
PointCloudData | None
- 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.
- property reflectance: ScalarField | None
Get the reflectance field.
- Return type:
ScalarField | None
- remove_field(field_name)
Remove a scalar field from the manager by name.
- Parameters:
field_name (LowerStr) – Name of the field to remove.
- 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:
- property shape: tuple[int, int]
Return the shape of the scalar field manager.
The shape will be in the form (num_points, num_fields).
- 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.
- values()
Return the scalar field values stored in the manager.
- Return type:
ValuesView[SF_T]
Modules
ScalarFieldManager: container for the per-point scalar fields of a PointCloudData. |
|
Per-point typed scalar-field classes (RGB, normals, intensity, segmentation, generic). |