KrisLibrary  1.0.0
PointLocation.h
1 #ifndef POINT_LOCATION_H
2 #define POINT_LOCATION_H
3 
4 #include "CSpace.h"
5 //#include <KrisLibrary/geometry/Grid.h>
6 #include <KrisLibrary/geometry/KDTree.h>
7 #include <KrisLibrary/geometry/BallTree.h>
8 #include <memory>
9 
15 {
16  public:
17  PointLocationBase(std::vector<Vector>& _points);
18  virtual ~PointLocationBase() {}
20  virtual void OnBuild() =0;
22  virtual void OnAppend() =0;
25  virtual bool OnDelete(int id) { return false; }
27  virtual bool OnClear() { return false; }
29  virtual bool Exact() { return true; }
33  virtual bool NN(const Vector& p,int& nn,Real& distance) { return false; }
37  virtual bool KNN(const Vector& p,int k,std::vector<int>& nn,std::vector<Real>& distances) { return false; }
41  virtual bool Close(const Vector& p,Real r,std::vector<int>& neighbors,std::vector<Real>& distances) { return false; }
43  virtual bool FilteredNN(const Vector& p,bool (*filter)(int),int& nn,Real& distance) { return false; }
45  virtual bool FilteredKNN(const Vector& p,int k,bool (*filter)(int),std::vector<int>& nn,std::vector<Real>& distances) { return false; }
47  virtual bool FilteredClose(const Vector& p,Real r,bool (*filter)(int),std::vector<int>& neighbors,std::vector<Real>& distances) { return false; }
49  virtual void GetStats(PropertyMap& stats) {}
50 
51  std::vector<Vector>& points;
52 };
53 
56 {
57  public:
58  NaivePointLocation(std::vector<Vector>& points,CSpace* _space);
59  virtual void OnBuild() {}
60  virtual void OnAppend() {}
61  virtual bool OnDelete(int id) { return true; }
62  virtual bool OnClear() { return true; }
63  virtual bool NN(const Vector& p,int& nn,Real& distance);
64  virtual bool KNN(const Vector& p,int k,std::vector<int>& nn,std::vector<Real>& distances);
65  virtual bool Close(const Vector& p,Real r,std::vector<int>& nn,std::vector<Real>& distances);
66  virtual bool FilteredNN(const Vector& p,bool (*filter)(int),int& nn,Real& distance);
67  virtual bool FilteredKNN(const Vector& p,int k,bool (*filter)(int),std::vector<int>& nn,std::vector<Real>& distances);
68  virtual bool FilteredClose(const Vector& p,Real r,bool (*filter)(int),std::vector<int>& neighbors,std::vector<Real>& distances);
69 
70 
71  CSpace* space;
72 };
73 
78 {
79  public:
80  RandomPointLocation(std::vector<Vector>& points);
81  virtual void OnBuild() {}
82  virtual void OnAppend() {}
83  virtual bool OnDelete(int id) { return true; }
84  virtual bool OnClear() { return true; }
85  virtual bool Exact() { return false; }
86  virtual bool NN(const Vector& p,int& nn,Real& distance);
87  virtual bool KNN(const Vector& p,int k,std::vector<int>& nn,std::vector<Real>& distances);
88  virtual bool FilteredNN(const Vector& p,bool (*filter)(int),int& nn,Real& distance);
89  virtual bool FilteredKNN(const Vector& p,int k,bool (*filter)(int),std::vector<int>& nn,std::vector<Real>& distances);
90 };
91 
96 {
97  public:
98  RandomBestPointLocation(std::vector<Vector>& points,CSpace* _space,int k=1);
99  virtual void OnBuild() {}
100  virtual void OnAppend() {}
101  virtual bool OnDelete(int id) { return true; }
102  virtual bool OnClear() { return true; }
103  virtual bool Exact() { return false; }
104  virtual bool NN(const Vector& p,int& nn,Real& distance);
105  virtual bool KNN(const Vector& p,int k,std::vector<int>& nn,std::vector<Real>& distances);
106  virtual bool FilteredNN(const Vector& p,bool (*filter)(int),int& nn,Real& distance);
107  virtual bool FilteredKNN(const Vector& p,int k,bool (*filter)(int),std::vector<int>& nn,std::vector<Real>& distances);
108 
109  CSpace* space;
110  int k;
111 };
112 
113 
121 {
122  public:
123  KDTreePointLocation(std::vector<Vector>& points);
124  KDTreePointLocation(std::vector<Vector>& points,Real norm,const Vector& weights);
125  virtual void OnBuild();
126  virtual void OnAppend();
127  virtual bool OnClear();
128  virtual bool NN(const Vector& p,int& nn,Real& distance);
129  virtual bool KNN(const Vector& p,int k,std::vector<int>& nn,std::vector<Real>& distances);
130  virtual bool Close(const Vector& p,Real r,std::vector<int>& nn,std::vector<Real>& distances);
131  virtual void GetStats(PropertyMap& stats);
132 
133  Real norm;
134  Vector weights;
135  std::unique_ptr<Geometry::KDTree> tree;
136 };
137 
145 {
146  public:
147  BallTreePointLocation(CSpace* cspace,std::vector<Vector>& points);
148  virtual void OnBuild();
149  virtual void OnAppend();
150  virtual bool OnClear();
151  virtual bool NN(const Vector& p,int& nn,Real& distance);
152  virtual bool KNN(const Vector& p,int k,std::vector<int>& nn,std::vector<Real>& distances);
153  virtual bool Close(const Vector& p,Real r,std::vector<int>& nn,std::vector<Real>& distances);
154  virtual void GetStats(PropertyMap& stats);
155 
156  CSpace* cspace;
157  std::unique_ptr<Geometry::BallTree> tree;
158 };
159 
160 #endif
virtual bool FilteredNN(const Vector &p, bool(*filter)(int), int &nn, Real &distance)
Same as NN, but with a filter.
Definition: PointLocation.h:43
An accelerated point location algorithm that uses a K-D tree.
Definition: PointLocation.h:120
virtual void OnAppend()
Call this when something is appended to the point list.
Definition: PointLocation.h:60
virtual bool Exact()
Subclass returns true if this is exact nearest neighbors.
Definition: PointLocation.h:29
Motion planning configuration space base class. The configuration space implements an interpolation s...
Definition: CSpace.h:39
virtual void OnAppend()
Call this when something is appended to the point list.
Definition: PointLocation.h:100
virtual bool OnDelete(int id)
Definition: PointLocation.h:61
A uniform abstract interface to point location data structures. The point locator operators in-place ...
Definition: PointLocation.h:14
virtual void OnBuild()
Call this when the point list is completely changed.
Definition: PointLocation.h:99
virtual bool FilteredKNN(const Vector &p, int k, bool(*filter)(int), std::vector< int > &nn, std::vector< Real > &distances)
Same as KNN, but with a filter.
Definition: PointLocation.h:45
virtual bool OnClear()
Call this when the point list is cleared.
Definition: PointLocation.h:62
virtual void OnBuild()
Call this when the point list is completely changed.
Definition: PointLocation.h:59
The approximate O(k) point location algorithm that returns the closest of k randomly chosen points...
Definition: PointLocation.h:95
virtual bool OnClear()
Call this when the point list is cleared.
Definition: PointLocation.h:84
virtual void OnBuild()=0
Call this when the point list is completely changed.
virtual void OnBuild()
Call this when the point list is completely changed.
Definition: PointLocation.h:81
virtual bool OnDelete(int id)
Definition: PointLocation.h:101
virtual void GetStats(PropertyMap &stats)
Returns any potentially interesting statistics.
Definition: PointLocation.h:49
virtual bool NN(const Vector &p, int &nn, Real &distance)
Definition: PointLocation.h:33
virtual bool FilteredClose(const Vector &p, Real r, bool(*filter)(int), std::vector< int > &neighbors, std::vector< Real > &distances)
Same as close, but with a filter.
Definition: PointLocation.h:47
virtual bool Exact()
Subclass returns true if this is exact nearest neighbors.
Definition: PointLocation.h:85
virtual bool OnDelete(int id)
Definition: PointLocation.h:25
virtual bool OnClear()
Call this when the point list is cleared.
Definition: PointLocation.h:102
virtual bool Exact()
Subclass returns true if this is exact nearest neighbors.
Definition: PointLocation.h:103
A simple map from keys to values.
Definition: PropertyMap.h:27
virtual bool OnDelete(int id)
Definition: PointLocation.h:83
virtual bool KNN(const Vector &p, int k, std::vector< int > &nn, std::vector< Real > &distances)
Definition: PointLocation.h:37
virtual void OnAppend()
Call this when something is appended to the point list.
Definition: PointLocation.h:82
virtual bool OnClear()
Call this when the point list is cleared.
Definition: PointLocation.h:27
virtual bool Close(const Vector &p, Real r, std::vector< int > &neighbors, std::vector< Real > &distances)
Definition: PointLocation.h:41
The approximate O(1) point location algorithm that simply returns a random point. ...
Definition: PointLocation.h:77
An accelerated point location algorithm that uses a ball tree.
Definition: PointLocation.h:144
The Naive O(n) point location algorithm.
Definition: PointLocation.h:55
virtual void OnAppend()=0
Call this when something is appended to the point list.