nanoflann_adaptors.h
Go to the documentation of this file.
1 /*
2  * nanoflann_adaptors.h
3  * Copyright (c) 2018, Simbe Robotics
4  * Copyright (c) 2019, Samsung Research America
5  *
6  * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE
7  * COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY
8  * COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS
9  * AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
10  *
11  * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO
12  * BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS
13  * CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND
14  * CONDITIONS.
15  *
16  */
17 
18 /* Author: Steven Macenski */
19 
20 #include "nanoflann.hpp"
21 
22 // And this is the "dataset to kd-tree" adaptor class:
23 template <typename Derived>
25 {
26  const Derived &obj;
27 
29  VertexVectorPoseNanoFlannAdaptor(const Derived &obj_) : obj(obj_) { }
30 
32  inline const Derived& derived() const { return obj; }
33 
34  // Must return the number of data points
35  inline size_t kdtree_get_point_count() const { return derived().size(); }
36 
37  // Returns the dim'th component of the idx'th point in the class:
38  // Since this is inlined and the "dim" argument is typically an immediate value, the
39  // "if/else's" are actually solved at compile time.
40  inline double kdtree_get_pt(const size_t idx, const size_t dim) const
41  {
42  if (dim == 0) return derived()[idx]->GetObject()->GetCorrectedPose().GetX();
43  else return derived()[idx]->GetObject()->GetCorrectedPose().GetY();
44  }
45 
46  // Optional bounding-box computation: return false to default to a standard bbox computation loop.
47  // Return true if the BBOX was already computed by the class and returned in "bb" so it can be avoided to redo it again.
48  // Look at bb.size() to find out the expected dimensionality (e.g. 2 or 3 for point clouds)
49  template <class BBOX>
50  bool kdtree_get_bbox(BBOX& /*bb*/) const { return false; }
51 
52 }; // end of VertexVectorPoseNanoFlannAdaptor
53 
54 // And this is the "dataset to kd-tree" adaptor class:
55 template <typename Derived>
57 {
58  const Derived &obj;
59 
60  VertexVectorScanCenterNanoFlannAdaptor(const Derived &obj_) : obj(obj_) { }
61 
62  inline const Derived& derived() const { return obj; }
63 
64  inline size_t kdtree_get_point_count() const { return derived().size(); }
65 
66  inline double kdtree_get_pt(const size_t idx, const size_t dim) const
67  {
68  if (dim == 0) return derived()[idx]->GetObject()->GetBarycenterPose().GetX();
69  else return derived()[idx]->GetObject()->GetBarycenterPose().GetY();
70  }
71 
72  template <class BBOX>
73  bool kdtree_get_bbox(BBOX& /*bb*/) const { return false; }
74 
75 }; // end of VertexVectorScanCenterNanoFlannAdaptor
VertexVectorPoseNanoFlannAdaptor::derived
const Derived & derived() const
CRTP helper method.
Definition: nanoflann_adaptors.h:32
VertexVectorPoseNanoFlannAdaptor
Definition: nanoflann_adaptors.h:24
VertexVectorPoseNanoFlannAdaptor::kdtree_get_bbox
bool kdtree_get_bbox(BBOX &) const
Definition: nanoflann_adaptors.h:50
VertexVectorScanCenterNanoFlannAdaptor::VertexVectorScanCenterNanoFlannAdaptor
VertexVectorScanCenterNanoFlannAdaptor(const Derived &obj_)
Definition: nanoflann_adaptors.h:60
VertexVectorPoseNanoFlannAdaptor::kdtree_get_pt
double kdtree_get_pt(const size_t idx, const size_t dim) const
Definition: nanoflann_adaptors.h:40
VertexVectorPoseNanoFlannAdaptor::VertexVectorPoseNanoFlannAdaptor
VertexVectorPoseNanoFlannAdaptor(const Derived &obj_)
The constructor that sets the data set source.
Definition: nanoflann_adaptors.h:29
VertexVectorScanCenterNanoFlannAdaptor::kdtree_get_point_count
size_t kdtree_get_point_count() const
Definition: nanoflann_adaptors.h:64
VertexVectorPoseNanoFlannAdaptor::obj
const Derived & obj
A const ref to the data set origin.
Definition: nanoflann_adaptors.h:26
nanoflann.hpp
VertexVectorPoseNanoFlannAdaptor::kdtree_get_point_count
size_t kdtree_get_point_count() const
Definition: nanoflann_adaptors.h:35
VertexVectorScanCenterNanoFlannAdaptor::kdtree_get_pt
double kdtree_get_pt(const size_t idx, const size_t dim) const
Definition: nanoflann_adaptors.h:66
VertexVectorScanCenterNanoFlannAdaptor::kdtree_get_bbox
bool kdtree_get_bbox(BBOX &) const
Definition: nanoflann_adaptors.h:73
VertexVectorScanCenterNanoFlannAdaptor::derived
const Derived & derived() const
Definition: nanoflann_adaptors.h:62
VertexVectorScanCenterNanoFlannAdaptor::obj
const Derived & obj
Definition: nanoflann_adaptors.h:58
VertexVectorScanCenterNanoFlannAdaptor
Definition: nanoflann_adaptors.h:56


slam_toolbox
Author(s): Steve Macenski
autogenerated on Thu Jan 11 2024 03:37:55