cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
toolbox::pcl::bfknn_generic_t< Element, Metric > Class Template Reference

暴力K近邻搜索算法的通用实现 / Generic brute-force K-nearest neighbors search implementation More...

#include <bfknn.hpp>

Inheritance diagram for toolbox::pcl::bfknn_generic_t< Element, Metric >:

Public Types

using base_type = base_knn_generic_t< bfknn_generic_t< Element, Metric >, Element, Metric >
 
using traits_type = typename base_type::traits_type
 
using element_type = typename traits_type::element_type
 
using metric_type = typename traits_type::metric_type
 
using distance_type = typename traits_type::distance_type
 
using container_type = typename base_type::container_type
 
using container_ptr = typename base_type::container_ptr
 
using value_type = typename Element::value_type
 
- Public Types inherited from toolbox::pcl::base_knn_generic_t< Derived, Element, Metric >
using traits_type = knn_traits< Element, Metric >
 
using element_type = typename traits_type::element_type
 
using metric_type = typename traits_type::metric_type
 
using distance_type = typename traits_type::distance_type
 
using container_type = std::vector< element_type >
 
using container_ptr = std::shared_ptr< container_type >
 

Public Member Functions

 bfknn_generic_t ()=default
 
 ~bfknn_generic_t ()=default
 
 bfknn_generic_t (const bfknn_generic_t &)=delete
 
bfknn_generic_toperator= (const bfknn_generic_t &)=delete
 
 bfknn_generic_t (bfknn_generic_t &&)=delete
 
bfknn_generic_toperator= (bfknn_generic_t &&)=delete
 
std::size_t set_input_impl (const container_type &data)
 设置输入数据的实现 / Implementation of setting input data
 
std::size_t set_input_impl (const container_ptr &data)
 设置输入数据的实现(智能指针版本) / Implementation of setting input data (smart pointer version)
 
void set_metric_impl (const metric_type &metric)
 设置度量方式的实现(编译时版本) / Implementation of setting metric (compile-time version)
 
template<typename T = typename Element::value_type>
void set_metric_impl (std::shared_ptr< toolbox::metrics::IMetric< T > > metric)
 设置度量方式的实现(运行时版本 - shared_ptr) / Implementation of setting metric (runtime version - shared_ptr)
 
template<typename T = typename Element::value_type>
void set_metric_impl (std::unique_ptr< toolbox::metrics::IMetric< T > > metric)
 设置度量方式的实现(运行时版本 - unique_ptr) / Implementation of setting metric (runtime version - unique_ptr)
 
bool kneighbors_impl (const element_type &query, std::size_t num_neighbors, std::vector< std::size_t > &indices, std::vector< distance_type > &distances)
 K近邻搜索的实现 / Implementation of K-nearest neighbors search.
 
bool radius_neighbors_impl (const element_type &query, distance_type radius, std::vector< std::size_t > &indices, std::vector< distance_type > &distances)
 半径近邻搜索的实现 / Implementation of radius neighbors search
 
- Public Member Functions inherited from toolbox::pcl::base_knn_generic_t< Derived, Element, Metric >
std::size_t set_input (const container_type &data)
 设置输入数据 / Set input data
 
std::size_t set_input (const container_ptr &data)
 设置输入数据(智能指针版本) / Set input data (smart pointer version)
 
template<typename T = typename Element::value_type, typename = std::enable_if_t<std::is_same_v<Element, point_t<T>>>>
std::size_t set_input (const toolbox::types::point_cloud_t< T > &cloud)
 设置点云输入数据(仅当Element为point_t时可用) / Set point cloud input data (only available when Element is point_t)
 
template<typename T = typename Element::value_type, typename = std::enable_if_t<std::is_same_v<Element, point_t<T>>>>
std::size_t set_input (const std::shared_ptr< toolbox::types::point_cloud_t< T > > &cloud)
 设置点云输入数据(智能指针版本) / Set point cloud input data (smart pointer version)
 
void set_metric (const metric_type &metric)
 设置度量方式(编译时版本) / Set metric (compile-time version)
 
template<typename T = typename Element::value_type>
void set_metric (std::shared_ptr< toolbox::metrics::IMetric< T > > metric)
 设置度量方式(运行时版本 - shared_ptr) / Set metric (runtime version - shared_ptr)
 
template<typename T = typename Element::value_type>
void set_metric (std::unique_ptr< toolbox::metrics::IMetric< T > > metric)
 设置度量方式(运行时版本 - unique_ptr) / Set metric (runtime version - unique_ptr)
 
bool kneighbors (const element_type &query, std::size_t num_neighbors, std::vector< std::size_t > &indices, std::vector< distance_type > &distances)
 K近邻搜索 / K-nearest neighbors search.
 
bool radius_neighbors (const element_type &query, distance_type radius, std::vector< std::size_t > &indices, std::vector< distance_type > &distances)
 半径近邻搜索 / Radius neighbors search
 
 base_knn_generic_t (const base_knn_generic_t &)=delete
 
base_knn_generic_toperator= (const base_knn_generic_t &)=delete
 
 base_knn_generic_t (base_knn_generic_t &&)=delete
 
base_knn_generic_toperator= (base_knn_generic_t &&)=delete
 

Additional Inherited Members

- Protected Member Functions inherited from toolbox::pcl::base_knn_generic_t< Derived, Element, Metric >
 base_knn_generic_t ()=default
 
 ~base_knn_generic_t ()=default
 

Detailed Description

template<typename Element, typename Metric = toolbox::metrics::L2Metric<typename Element::value_type>>
class toolbox::pcl::bfknn_generic_t< Element, Metric >

暴力K近邻搜索算法的通用实现 / Generic brute-force K-nearest neighbors search implementation

该类通过遍历所有数据点来查找最近邻,适用于小规模数据集或需要精确结果的场景。 支持任意元素类型和度量方式。 / This class finds nearest neighbors by iterating through all data points, suitable for small datasets or scenarios requiring exact results. Supports arbitrary element types and metrics.

Template Parameters
Element元素类型(如point_t<float>) / Element type (e.g., point_t<float>)
Metric度量类型(默认为L2度量) / Metric type (default is L2 metric)
// 基本使用示例 / Basic usage example
bfknn_generic_t<point_t<float>, L2Metric<float>> knn;
std::vector<point_t<float>> points = generate_points();
knn.set_input(points);
// K近邻搜索 / K-nearest neighbors search
point_t<float> query = {1.0f, 2.0f, 3.0f};
std::vector<std::size_t> indices;
std::vector<float> distances;
knn.kneighbors(query, 5, indices, distances);
bool kneighbors(const element_type &query, std::size_t num_neighbors, std::vector< std::size_t > &indices, std::vector< distance_type > &distances)
K近邻搜索 / K-nearest neighbors search.
Definition base_knn.hpp:179
std::size_t set_input(const container_type &data)
设置输入数据 / Set input data
Definition base_knn.hpp:83
暴力K近邻搜索算法的通用实现 / Generic brute-force K-nearest neighbors search implementation
Definition bfknn.hpp:45
3D点/向量模板类 / A 3D point/vector template class
Definition point.hpp:48
// 使用不同的度量 / Using different metrics
bfknn_generic_t<point_t<float>, L1Metric<float>> knn_l1;
knn_l1.set_input(points);
// 运行时切换度量 / Runtime metric switching
auto metric = MetricFactory<float>::instance().create("cosine");
knn.set_metric(std::move(metric));
void set_metric(const metric_type &metric)
设置度量方式(编译时版本) / Set metric (compile-time version)
Definition base_knn.hpp:129

Member Typedef Documentation

◆ base_type

template<typename Element , typename Metric = toolbox::metrics::L2Metric<typename Element::value_type>>
using toolbox::pcl::bfknn_generic_t< Element, Metric >::base_type = base_knn_generic_t<bfknn_generic_t<Element, Metric>, Element, Metric>

◆ container_ptr

template<typename Element , typename Metric = toolbox::metrics::L2Metric<typename Element::value_type>>
using toolbox::pcl::bfknn_generic_t< Element, Metric >::container_ptr = typename base_type::container_ptr

◆ container_type

template<typename Element , typename Metric = toolbox::metrics::L2Metric<typename Element::value_type>>
using toolbox::pcl::bfknn_generic_t< Element, Metric >::container_type = typename base_type::container_type

◆ distance_type

template<typename Element , typename Metric = toolbox::metrics::L2Metric<typename Element::value_type>>
using toolbox::pcl::bfknn_generic_t< Element, Metric >::distance_type = typename traits_type::distance_type

◆ element_type

template<typename Element , typename Metric = toolbox::metrics::L2Metric<typename Element::value_type>>
using toolbox::pcl::bfknn_generic_t< Element, Metric >::element_type = typename traits_type::element_type

◆ metric_type

template<typename Element , typename Metric = toolbox::metrics::L2Metric<typename Element::value_type>>
using toolbox::pcl::bfknn_generic_t< Element, Metric >::metric_type = typename traits_type::metric_type

◆ traits_type

template<typename Element , typename Metric = toolbox::metrics::L2Metric<typename Element::value_type>>
using toolbox::pcl::bfknn_generic_t< Element, Metric >::traits_type = typename base_type::traits_type

◆ value_type

template<typename Element , typename Metric = toolbox::metrics::L2Metric<typename Element::value_type>>
using toolbox::pcl::bfknn_generic_t< Element, Metric >::value_type = typename Element::value_type

Constructor & Destructor Documentation

◆ bfknn_generic_t() [1/3]

template<typename Element , typename Metric = toolbox::metrics::L2Metric<typename Element::value_type>>
toolbox::pcl::bfknn_generic_t< Element, Metric >::bfknn_generic_t ( )
default

◆ ~bfknn_generic_t()

template<typename Element , typename Metric = toolbox::metrics::L2Metric<typename Element::value_type>>
toolbox::pcl::bfknn_generic_t< Element, Metric >::~bfknn_generic_t ( )
default

◆ bfknn_generic_t() [2/3]

template<typename Element , typename Metric = toolbox::metrics::L2Metric<typename Element::value_type>>
toolbox::pcl::bfknn_generic_t< Element, Metric >::bfknn_generic_t ( const bfknn_generic_t< Element, Metric > &  )
delete

◆ bfknn_generic_t() [3/3]

template<typename Element , typename Metric = toolbox::metrics::L2Metric<typename Element::value_type>>
toolbox::pcl::bfknn_generic_t< Element, Metric >::bfknn_generic_t ( bfknn_generic_t< Element, Metric > &&  )
delete

Member Function Documentation

◆ kneighbors_impl()

template<typename Element , typename Metric >
bool toolbox::pcl::bfknn_generic_t< Element, Metric >::kneighbors_impl ( const element_type query,
std::size_t  num_neighbors,
std::vector< std::size_t > &  indices,
std::vector< distance_type > &  distances 
)

K近邻搜索的实现 / Implementation of K-nearest neighbors search.

Parameters
query查询点 / Query point
num_neighbors要查找的最近邻数量 / Number of nearest neighbors to find
indices[out] 找到的最近邻索引 / Indices of found nearest neighbors
distances[out] 对应的距离 / Corresponding distances
Returns
是否成功 / Whether successful

◆ operator=() [1/2]

template<typename Element , typename Metric = toolbox::metrics::L2Metric<typename Element::value_type>>
bfknn_generic_t & toolbox::pcl::bfknn_generic_t< Element, Metric >::operator= ( bfknn_generic_t< Element, Metric > &&  )
delete

◆ operator=() [2/2]

template<typename Element , typename Metric = toolbox::metrics::L2Metric<typename Element::value_type>>
bfknn_generic_t & toolbox::pcl::bfknn_generic_t< Element, Metric >::operator= ( const bfknn_generic_t< Element, Metric > &  )
delete

◆ radius_neighbors_impl()

template<typename Element , typename Metric >
bool toolbox::pcl::bfknn_generic_t< Element, Metric >::radius_neighbors_impl ( const element_type query,
distance_type  radius,
std::vector< std::size_t > &  indices,
std::vector< distance_type > &  distances 
)

半径近邻搜索的实现 / Implementation of radius neighbors search

Parameters
query查询点 / Query point
radius搜索半径 / Search radius
indices[out] 半径内所有点的索引 / Indices of all points within radius
distances[out] 对应的距离 / Corresponding distances
Returns
是否成功 / Whether successful

◆ set_input_impl() [1/2]

template<typename Element , typename Metric >
std::size_t toolbox::pcl::bfknn_generic_t< Element, Metric >::set_input_impl ( const container_ptr data)

设置输入数据的实现(智能指针版本) / Implementation of setting input data (smart pointer version)

Parameters
data输入数据容器的智能指针 / Smart pointer to input data container
Returns
数据点的数量 / Number of data points

◆ set_input_impl() [2/2]

template<typename Element , typename Metric >
std::size_t toolbox::pcl::bfknn_generic_t< Element, Metric >::set_input_impl ( const container_type data)

设置输入数据的实现 / Implementation of setting input data

Parameters
data输入数据容器 / Input data container
Returns
数据点的数量 / Number of data points

◆ set_metric_impl() [1/3]

template<typename Element , typename Metric >
void toolbox::pcl::bfknn_generic_t< Element, Metric >::set_metric_impl ( const metric_type metric)

设置度量方式的实现(编译时版本) / Implementation of setting metric (compile-time version)

Parameters
metric度量对象 / Metric object

◆ set_metric_impl() [2/3]

template<typename Element , typename Metric >
template<typename T >
void toolbox::pcl::bfknn_generic_t< Element, Metric >::set_metric_impl ( std::shared_ptr< toolbox::metrics::IMetric< T > >  metric)

设置度量方式的实现(运行时版本 - shared_ptr) / Implementation of setting metric (runtime version - shared_ptr)

Template Parameters
T数据类型 / Data type
Parameters
metric度量接口的智能指针 / Smart pointer to metric interface

◆ set_metric_impl() [3/3]

template<typename Element , typename Metric >
template<typename T >
void toolbox::pcl::bfknn_generic_t< Element, Metric >::set_metric_impl ( std::unique_ptr< toolbox::metrics::IMetric< T > >  metric)

设置度量方式的实现(运行时版本 - unique_ptr) / Implementation of setting metric (runtime version - unique_ptr)

Template Parameters
T数据类型 / Data type
Parameters
metric度量接口的独占指针 / Unique pointer to metric interface

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