NuriKit v0.1.0b2
Loading...
Searching...
No Matches
nuri::VoxelGrid Class Reference

A uniform voxel-grid (cell list) index for 3D point clouds with a fixed neighbor cutoff. More...

#include <nuri/core/geometry.h>

Public Types

using Points = ConstRef<Matrix3Xd>

Public Member Functions

 VoxelGrid ()=default
 VoxelGrid (Points pts, double cutoff)
void rebuild (Points pts, double cutoff=-1.0)
void find_neighbors_d (const Vector3d &pt, std::vector< int > &idxs, std::vector< double > &distsq) const
 Find indices of all points within the build-time cutoff of a query point.
void find_neighbors_grid (const VoxelGrid &grid, std::vector< int > &self, std::vector< int > &other) const
 Find all pairs (i, j) where i is in *this and j is in grid and the distance between the points is within the build-time cutoff of *this.
std::vector< std::vector< int > > find_neighbors_grid (const VoxelGrid &grid) const
 Convenience overload returning a per-self adjacency list.
void find_neighbors_self (std::vector< int > &left, std::vector< int > &right) const
 Find all non-redundant pairs of neighbors within the build-time cutoff.
const Matrix3Xd & pts () const
 The grid-owned, cell-reordered copy of the input coordinates.
double cutoff () const
const Vector3d & origin () const
const Array3i & dims () const
int num_cells () const
const ArrayXi & cell_offset () const
const ArrayXi & cell_pts () const

Detailed Description

A uniform voxel-grid (cell list) index for 3D point clouds with a fixed neighbor cutoff.

Unlike OCTree, the cutoff distance is baked in at build time and equals the voxel edge length. Neighbor queries therefore only need to scan the 3x3x3 = 27 voxels around each query point. The grid stores its contents in a CSR-style layout:

The grid owns its own copy of the input coordinates, reordered so that points belonging to the same voxel are contiguous in memory. pts() returns this reordered copy, not the original input; the p-th column of pts() corresponds to the original input point cell_pts()[p]. The original point set is not referenced after rebuild() returns, so the caller is free to mutate or destroy it.

Member Typedef Documentation

◆ Points

using nuri::VoxelGrid::Points = ConstRef<Matrix3Xd>

Constructor & Destructor Documentation

◆ VoxelGrid() [1/2]

nuri::VoxelGrid::VoxelGrid ( )
default

◆ VoxelGrid() [2/2]

nuri::VoxelGrid::VoxelGrid ( Points pts,
double cutoff )
inlineexplicit

Member Function Documentation

◆ cell_offset()

const ArrayXi & nuri::VoxelGrid::cell_offset ( ) const
inline

◆ cell_pts()

const ArrayXi & nuri::VoxelGrid::cell_pts ( ) const
inline

◆ cutoff()

double nuri::VoxelGrid::cutoff ( ) const
inline

◆ dims()

const Array3i & nuri::VoxelGrid::dims ( ) const
inline

◆ find_neighbors_d()

void nuri::VoxelGrid::find_neighbors_d ( const Vector3d & pt,
std::vector< int > & idxs,
std::vector< double > & distsq ) const

Find indices of all points within the build-time cutoff of a query point.

Parameters
ptThe query point.
idxsOutput indices into pts() of the matched points.
distsqOutput squared distances corresponding to each matched index.

◆ find_neighbors_grid() [1/2]

std::vector< std::vector< int > > nuri::VoxelGrid::find_neighbors_grid ( const VoxelGrid & grid) const

Convenience overload returning a per-self adjacency list.

Parameters
gridThe other voxel grid; only its point set is used.
Returns
A vector of size pts().cols(); the i-th entry contains the indices into grid whose points are within the cutoff of point i in *this.

◆ find_neighbors_grid() [2/2]

void nuri::VoxelGrid::find_neighbors_grid ( const VoxelGrid & grid,
std::vector< int > & self,
std::vector< int > & other ) const

Find all pairs (i, j) where i is in *this and j is in grid and the distance between the points is within the build-time cutoff of *this.

Parameters
gridThe other voxel grid; only its point set is used.
selfOutput indices into *this.
otherOutput indices into grid.

◆ find_neighbors_self()

void nuri::VoxelGrid::find_neighbors_self ( std::vector< int > & left,
std::vector< int > & right ) const

Find all non-redundant pairs of neighbors within the build-time cutoff.

Parameters
leftOutput indices of the first member of each pair.
rightOutput indices of the second member of each pair.

Each pair is reported exactly once with i != j; if (i, j) is emitted then (j, i) will not be. The ordering between left[k] and right[k] is unspecified.

◆ num_cells()

int nuri::VoxelGrid::num_cells ( ) const
inline

◆ origin()

const Vector3d & nuri::VoxelGrid::origin ( ) const
inline

◆ pts()

const Matrix3Xd & nuri::VoxelGrid::pts ( ) const
inline

The grid-owned, cell-reordered copy of the input coordinates.

The p-th column corresponds to the original input point at index cell_pts()[p]. Use cell_pts() to translate between the internal layout and the caller's indexing.

◆ rebuild()

void nuri::VoxelGrid::rebuild ( Points pts,
double cutoff = -1.0 )
inline

The documentation for this class was generated from the following file: