pub trait PointCloudNeighbors {
// Required methods
fn k_nearest_neighbors(&self, k: usize) -> Vec<Vec<(usize, f32)>>;
fn find_k_nearest(&self, query: &Point3f, k: usize) -> Vec<(usize, f32)>;
fn find_radius_neighbors(
&self,
query: &Point3f,
radius: f32,
) -> Vec<(usize, f32)>;
fn find_k_nearest_brute_force(
&self,
query: &Point3f,
k: usize,
) -> Vec<(usize, f32)>;
fn find_radius_neighbors_brute_force(
&self,
query: &Point3f,
radius: f32,
) -> Vec<(usize, f32)>;
}
Expand description
Extension trait for PointCloud to add k-nearest neighbors functionality
Required Methods§
Sourcefn k_nearest_neighbors(&self, k: usize) -> Vec<Vec<(usize, f32)>>
fn k_nearest_neighbors(&self, k: usize) -> Vec<Vec<(usize, f32)>>
Find k nearest neighbors for each point in the cloud using KD-tree
This method returns a vector where each element contains the indices and distances of the k nearest neighbors for the corresponding point in the cloud.
§Arguments
k
- Number of nearest neighbors to find for each point
§Returns
Vec<Vec<(usize, f32)>>
- Vector of neighbor results for each point
§Example
use threecrate_core::{PointCloud, Point3f};
use threecrate_algorithms::point_cloud_ops::PointCloudNeighbors;
let mut cloud = PointCloud::new();
cloud.push(Point3f::new(0.0, 0.0, 0.0));
cloud.push(Point3f::new(1.0, 0.0, 0.0));
cloud.push(Point3f::new(0.0, 1.0, 0.0));
let neighbors = cloud.k_nearest_neighbors(2);
// neighbors[0] contains the 2 nearest neighbors for point 0
Sourcefn find_k_nearest_brute_force(
&self,
query: &Point3f,
k: usize,
) -> Vec<(usize, f32)>
fn find_k_nearest_brute_force( &self, query: &Point3f, k: usize, ) -> Vec<(usize, f32)>
Find k nearest neighbors using brute force search (for small datasets or testing)
This method is useful for small point clouds or when you want to verify the results of the KD-tree implementation.
§Arguments
query
- The query point to find neighbors fork
- Number of nearest neighbors to find
§Returns
Vec<(usize, f32)>
- Vector of (index, distance) pairs for the k nearest neighbors