Skip to main content

PointCloudNeighbors

Trait PointCloudNeighbors 

Source
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§

Source

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
// Temporarily disabled due to stack overflow - needs investigation
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
Source

fn find_k_nearest(&self, query: &Point3f, k: usize) -> Vec<(usize, f32)>

Find k nearest neighbors for a specific query point using KD-tree

§Arguments
  • query - The query point to find neighbors for
  • k - Number of nearest neighbors to find
§Returns
  • Vec<(usize, f32)> - Vector of (index, distance) pairs for the k nearest neighbors
Source

fn find_radius_neighbors( &self, query: &Point3f, radius: f32, ) -> Vec<(usize, f32)>

Find all neighbors within a given radius using KD-tree

§Arguments
  • query - The query point to find neighbors for
  • radius - Search radius
§Returns
  • Vec<(usize, f32)> - Vector of (index, distance) pairs for neighbors within radius
Source

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 for
  • k - Number of nearest neighbors to find
§Returns
  • Vec<(usize, f32)> - Vector of (index, distance) pairs for the k nearest neighbors
Source

fn find_radius_neighbors_brute_force( &self, query: &Point3f, radius: f32, ) -> Vec<(usize, f32)>

Find all neighbors within a given radius using brute force search

§Arguments
  • query - The query point to find neighbors for
  • radius - Search radius
§Returns
  • Vec<(usize, f32)> - Vector of (index, distance) pairs for neighbors within radius

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl PointCloudNeighbors for PointCloud<Point3f>

Source§

fn k_nearest_neighbors(&self, k: usize) -> Vec<Vec<(usize, f32)>>

Source§

fn find_k_nearest(&self, query: &Point3f, k: usize) -> Vec<(usize, f32)>

Source§

fn find_radius_neighbors( &self, query: &Point3f, radius: f32, ) -> Vec<(usize, f32)>

Source§

fn find_k_nearest_brute_force( &self, query: &Point3f, k: usize, ) -> Vec<(usize, f32)>

Source§

fn find_radius_neighbors_brute_force( &self, query: &Point3f, radius: f32, ) -> Vec<(usize, f32)>

Implementors§