Go to the documentation of this file.
31 #ifndef RTABMAP_FLANN_HIERARCHICAL_CLUSTERING_INDEX_H_
32 #define RTABMAP_FLANN_HIERARCHICAL_CLUSTERING_INDEX_H_
42 #define SIZE_MAX ((size_t) -1)
63 int trees = 4,
int leaf_max_size = 100)
67 (*this)[
"branching"] = branching;
69 (*this)[
"centers_init"] = centers_init;
71 (*this)[
"trees"] = trees;
73 (*this)[
"leaf_max_size"] = leaf_max_size;
85 template <
typename Distance>
122 Distance d = Distance())
178 throw FLANNException(
"Unknown algorithm for choosing initial centers.");
212 size_t old_size =
size_;
220 for (
size_t i=0;
i<points.
rows;++
i) {
235 template<
typename Archive>
247 if (Archive::is_loading::value) {
251 if (Archive::is_loading::value) {
257 if (Archive::is_loading::value) {
293 findNeighborsWithRemoved<true>(
result, vec, searchParams);
296 findNeighborsWithRemoved<false>(
result, vec, searchParams);
333 template<
typename Archive>
337 Index* obj =
static_cast<Index*
>(ar.getObject());
342 if (Archive::is_loading::value) {
386 template<
typename Archive>
390 Index* obj =
static_cast<Index*
>(ar.getObject());
392 if (Archive::is_loading::value) {
399 if (Archive::is_saving::value) {
400 childs_size =
childs.size();
404 if (childs_size==0) {
408 if (Archive::is_loading::value) {
409 childs.resize(childs_size);
411 for (
size_t i=0;
i<childs_size;++
i) {
412 if (Archive::is_loading::value) {
449 if (src->
childs.size()==0) {
454 for (
size_t i=0;
i<src->
childs.size();++
i) {
465 for (
int i=0;
i<indices_length; ++
i) {
469 for (
int j=1;
j<centers_length; ++
j) {
493 node->
points.resize(indices_length);
494 for (
int i=0;
i<indices_length;++
i) {
503 std::vector<int>
labels(indices_length);
506 (*chooseCenters_)(
branching_,
indices, indices_length, ¢ers[0], centers_length);
509 node->
points.resize(indices_length);
510 for (
int i=0;
i<indices_length;++
i) {
527 for (
int j=0;
j<indices_length; ++
j) {
536 node->
childs[
i]->pivot_index = centers[
i];
538 node->
childs[
i]->points.clear();
545 template<
bool with_removed>
548 int maxChecks = searchParams.
checks;
560 while (heap->
popMin(branch) && (checks<maxChecks || !
result.full())) {
562 findNN<with_removed>(node,
result, vec, checks, maxChecks, heap, checked);
581 template<
bool with_removed>
585 if (node->
childs.empty()) {
586 if (checks>=maxChecks) {
587 if (
result.full())
return;
590 for (
size_t i=0;
i<node->
points.size(); ++
i) {
595 if (checked.
test(pointInfo.
index))
continue;
608 if (domain_distances[
i]<domain_distances[best_index]) {
617 delete[] domain_distances;
618 findNN<with_removed>(node->
childs[best_index],
result,vec, checks, maxChecks, heap, checked);
626 if (node->
childs.empty()) {
629 pointInfo.
index = index;
630 node->
points.push_back(pointInfo);
635 for (
size_t i=0;
i<node->
points.size();++
i) {
647 center = node->
childs[
i]->pivot;
void insert(const T &value)
void copyTree(NodePtr &dst, const NodePtr &src)
HierarchicalClusteringIndex(const Matrix< ElementType > &inputData, const IndexParams &index_params=HierarchicalClusteringIndexParams(), Distance d=Distance())
NNIndex< Distance > BaseClass
BaseClass * clone() const
std::vector< Node * > childs
T get_param(const IndexParams ¶ms, std::string name, const T &default_value)
void findNN(NodePtr node, ResultSet< DistanceType > &result, const ElementType *vec, int &checks, int maxChecks, Heap< BranchSt > *heap, DynamicBitset &checked) const
void serialize(Archive &ar)
HierarchicalClusteringIndex(const HierarchicalClusteringIndex &other)
void findNeighbors(ResultSet< DistanceType > &result, const ElementType *vec, const SearchParams &searchParams) const
std::vector< ElementType * > points_
flann_centers_init_t centers_init_
void addPoints(const Matrix< ElementType > &points, float rebuild_threshold=2)
Incrementally add points to the index.
void loadIndex(FILE *stream)
virtual ~HierarchicalClusteringIndex()
HierarchicalClusteringIndex & operator=(HierarchicalClusteringIndex other)
bool test(size_t index) const
std::vector< std::string > labels
void addPointToTree(NodePtr node, size_t index)
BranchStruct< NodePtr, DistanceType > BranchSt
void serialize(Archive &ar)
void computeClustering(NodePtr node, int *indices, int indices_length)
Distance::ResultType DistanceType
DynamicBitset removed_points_
void swap(GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &a, GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &b)
void swap(HierarchicalClusteringIndex &other)
void saveIndex(FILE *stream)
void setDataset(const Matrix< ElementType > &dataset)
HierarchicalClusteringIndexParams(int branching=32, flann_centers_init_t centers_init=FLANN_CENTERS_RANDOM, int trees=4, int leaf_max_size=100)
void serialize(Archive &ar)
HierarchicalClusteringIndex(const IndexParams &index_params=HierarchicalClusteringIndexParams(), Distance d=Distance())
void findNeighborsWithRemoved(ResultSet< DistanceType > &result, const ElementType *vec, const SearchParams &searchParams) const
void computeLabels(int *indices, int indices_length, int *centers, int centers_length, int *labels, DistanceType &cost)
void swap(NNIndex &other)
CenterChooser< Distance > * chooseCenters_
std::vector< Node * > tree_roots_
flann_algorithm_t getType() const
@ FLANN_CENTERS_GROUPWISE
Distance::ElementType ElementType
std::vector< PointInfo > points
std::map< std::string, any > IndexParams
virtual void buildIndex()
@ FLANN_INDEX_HIERARCHICAL
#define USING_BASECLASS_SYMBOLS
void extendDataset(const Matrix< ElementType > &new_points)
IndexParams index_params_
rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:11