Skip to main content

Compute the geometric features associated with each point's neighborhood:

Project description

Point Geometric Features

python C++ license

📌 Description

Python wrapper around C++ helper to compute, for each point in a 3D point cloud, local geometric features in parallel on CPU:

️List of computed features️
  • linearity
  • planarity
  • scattering
  • verticality (two formulations)
  • normal_x
  • normal_y
  • normal_z
  • length
  • surface
  • volume
  • curvature
  • optimal neighborhood size

The wrapper allows to compute feature in multiple fashions (on the fly subset of features a la jakteristics, an array of features or multiscale features...). Moreover, it offers basic interfaces to compute fast K-NN or Radius search on point clouds. The overall code is not intended to be DRY nor generic, it aims at providing efficient as possible implementations for some limited scopes and usages.

🧱 Installation

python -m pip install pgeof 

or

python -m pip install git+https://github.com/drprojects/point_geometric_features

building from sources

pgeof depends on Eigen library, Taskflow, nanoflann and nanobind.

pgeof adhere to PEP 517 and use scikit-build-core as build backend. Build dependencies (nanobind, scikit-build-core...) are fetched at build time. C++ third party libraries are embedded as submodules.

# clone project
git clone --recurse-submodules https://github.com/drprojects/point_geometric_features.git
cd point_geometric_features
# build and install the package
python -m pip install .

🚀 Using Point Geometric Features

Here we summarize the very basics of pgeof usage. Users are invited to use help(pgeof) for further details on parameters.

At its core pgeof provides three functions to compute a set of features given a 3D point cloud and some precomputed neighborhoods.

import pgeof

# Compute a set of 11 predefined features per points.
pgeof.compute_features(
    xyz, # The point cloud. A numpy array of shape (n, 3).
    nn, # CSR data structure see below.
    nn_ptr, # CSR data structure see below.
    k_min = 1 # Minimum number of neighbors to consider for features computation. 
    verbose = false # Basic verbose output, for debug purposes.
)
# Sequence of n scales feature computation.
pgeof.compute_features_multiscale(
    ...
    k_scale # array of neighborhood size
)
# Feature computation with optimal neighborhood selection as exposed in Weinmann et al., 2015. 
# return a set of 12 features per points (11 + the optimal neighborhood size)
pgeof.compute_features_optimal(
    ...
    k_min = 1, # Minimum number of neighbors to consider for features computation.
    k_step = 1, # Step size to take when searching for the optimal neighborhood
    k_min_search = 1, # Minimum neighborhood size at which to start when searching for the optimal neighborhood size for each point. it should be >= to k_min parameter.
)

⚠️ Please note that for theses three functions the neighbors are expected in CSR format. This allows expressing neighborhoods of varying sizes with dense arrays (eg the output of a radius search).

We provide very tiny and specialized k-NN / radius-NN search routines. They rely on nanoflann C++ library and they should be faster and lighter than scipy and sklearn alternatives.

Here are some examples of how to easily compute and convert typical k-NN or radius-NN neighborhoods to CSR format (nn and nn_ptr are two flat uint32 arrays):

import pgeof
import numpy as np

# Generate a random synthetic point cloud and k-nearest neighbors
num_points = 10000
k = 20
xyz = np.random.rand(num_points, 3).astype("float32")
knn, _ = pgeof.knn_search(xyz, xyz, k)

# Converting k-nearest neighbors to CSR format
nn_ptr = np.arange(num_points + 1) * k
nn = knn.flatten()

# You may need to convert nn/nn_ptr to uint32 arrays
nn_ptr = nn_ptr.astype("uint32")
nn = nn.astype("uint32")

features = pgeof.compute_features(xyz, nn, nn_ptr)
import pgeof
import numpy as np

# Generate a random synthetic point cloud and k-nearest neighbors
num_points = 10000
radius = 0.2
k = 20
xyz = np.random.rand(num_points, 3).astype("float32")
knn, _ = pgeof.radius_search(xyz, xyz, radius, k)

# Converting radius neighbors to CSR format
nn_ptr = np.r_[0, (knn >= 0).sum(axis=1).cumsum()]
nn = knn[knn >= 0]
# You may need to convert nn/nn_ptr to uint32 arrays
...

At last and as a by product we also provide a function to compute a subset of features on the fly. it is inspired by the Jakteristics python package (while being less complete but faster). the list of feature to compute is given as an array of EFeatureID

import pgeof
from pgeof import EFeatureID
import numpy as np

# Generate a random synthetic point cloud and k-nearest neighbors
num_points = 10000
radius = 0.2
k = 20
xyz = np.random.rand(num_points, 3)
features = pgeof.compute_features_selected(xyz, radius, k, [EFeatureID.Verticality])

Known limitations

Some functions only accept float scalar types and uint32 index types and we avoid implicit cast / conversions. This could be a limitation in some situations (double coordinates point clouds or need for a big indices). Some C++ function could be templated / to accept other type without conversion. For now, this feature is not enabled everywhere to reduce compilation time or enhance code readability but please let us know if you need this feature !

Normal are forced to be oriented in the Z half space.

Testing

Some basic tests and benchmarks are provided in the tests directory. Test could be run in a clean and reproducible environments via tox (tox run and tox run -e bench).

💳 Credits

This implementation was largely inspired from Superpoint Graph. The main modifications here allow:

  • parallel computation on all points' local neighborhoods, with neighborhoods of varying sizes
  • more geometric features
  • optimal neighborhood search from this paper
  • some corrections on geometric features computation

Some heavy refactoring (port to nanobind, test, benchmarks), packaging, speed optimization, feature addition (NN search, on the fly feature computation...) were funded by:

Centre of Wildfire Research of Swansea University (UK) in collaboration with the Research Institute of Biodiversity (CSIC, Spain) and the Department of Mining Exploitation of the University of Oviedo (Spain).

Funding provided by the UK NERC project (NE/T001194/1):

'Advancing 3D Fuel Mapping for Wildfire Behaviour and Risk Mitigation Modelling'

and by the Spanish Knowledge Generation project (PID2021-126790NB-I00):

‘Advancing carbon emission estimations from wildfires applying artificial intelligence to 3D terrestrial point clouds’.

License

Point Geometric Features is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pgeof-0.1.0.tar.gz (69.0 MB view hashes)

Uploaded Source

Built Distributions

pgeof-0.1.0-cp312-cp312-win_amd64.whl (229.0 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

pgeof-0.1.0-cp312-cp312-musllinux_1_1_x86_64.whl (562.1 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

pgeof-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (252.5 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pgeof-0.1.0-cp312-cp312-macosx_10_14_x86_64.whl (195.0 kB view hashes)

Uploaded CPython 3.12 macOS 10.14+ x86-64

pgeof-0.1.0-cp311-cp311-win_amd64.whl (229.6 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

pgeof-0.1.0-cp311-cp311-musllinux_1_1_x86_64.whl (563.7 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

pgeof-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (253.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pgeof-0.1.0-cp311-cp311-macosx_10_14_x86_64.whl (195.6 kB view hashes)

Uploaded CPython 3.11 macOS 10.14+ x86-64

pgeof-0.1.0-cp310-cp310-win_amd64.whl (229.8 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pgeof-0.1.0-cp310-cp310-musllinux_1_1_x86_64.whl (563.8 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pgeof-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (253.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pgeof-0.1.0-cp310-cp310-macosx_10_14_x86_64.whl (195.8 kB view hashes)

Uploaded CPython 3.10 macOS 10.14+ x86-64

pgeof-0.1.0-cp39-cp39-win_amd64.whl (230.2 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pgeof-0.1.0-cp39-cp39-musllinux_1_1_x86_64.whl (564.1 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pgeof-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (253.9 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pgeof-0.1.0-cp39-cp39-macosx_10_14_x86_64.whl (195.9 kB view hashes)

Uploaded CPython 3.9 macOS 10.14+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page