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/KDTree.h>
6 #include <KrisLibrary/geometry/Grid.h>
7 
13 {
14  public:
15  PointLocationBase(std::vector<Vector>& _points);
16  virtual ~PointLocationBase() {}
18  virtual void OnBuild() =0;
20  virtual void OnAppend() =0;
23  virtual bool OnDelete(int id) { return false; }
25  virtual bool OnClear() { return false; }
27  virtual bool Exact() { return true; }
31  virtual bool NN(const Vector& p,int& nn,Real& distance) { return false; }
35  virtual bool KNN(const Vector& p,int k,std::vector<int>& nn,std::vector<Real>& distances) { return false; }
39  virtual bool Close(const Vector& p,Real r,std::vector<int>& neighbors,std::vector<Real>& distances) { return false; }
41  virtual bool FilteredNN(const Vector& p,bool (*filter)(int),int& nn,Real& distance) { return false; }
43  virtual bool FilteredKNN(const Vector& p,int k,bool (*filter)(int),std::vector<int>& nn,std::vector<Real>& distances) { return false; }
45  virtual bool FilteredClose(const Vector& p,Real r,bool (*filter)(int),std::vector<int>& neighbors,std::vector<Real>& distances) { return false; }
46 
47  std::vector<Vector>& points;
48 };
49 
52 {
53  public:
54  NaivePointLocation(std::vector<Vector>& points,CSpace* _space);
55  virtual void OnBuild() {}
56  virtual void OnAppend() {}
57  virtual bool OnDelete(int id) { return true; }
58  virtual bool OnClear() { return true; }
59  virtual bool NN(const Vector& p,int& nn,Real& distance);
60  virtual bool KNN(const Vector& p,int k,std::vector<int>& nn,std::vector<Real>& distances);
61  virtual bool Close(const Vector& p,Real r,std::vector<int>& nn,std::vector<Real>& distances);
62  virtual bool FilteredNN(const Vector& p,bool (*filter)(int),int& nn,Real& distance);
63  virtual bool FilteredKNN(const Vector& p,int k,bool (*filter)(int),std::vector<int>& nn,std::vector<Real>& distances);
64  virtual bool FilteredClose(const Vector& p,Real r,bool (*filter)(int),std::vector<int>& neighbors,std::vector<Real>& distances);
65 
66 
67  CSpace* space;
68 };
69 
74 {
75  public:
76  RandomPointLocation(std::vector<Vector>& points);
77  virtual void OnBuild() {}
78  virtual void OnAppend() {}
79  virtual bool OnDelete(int id) { return true; }
80  virtual bool OnClear() { return true; }
81  virtual bool Exact() { return false; }
82  virtual bool NN(const Vector& p,int& nn,Real& distance);
83  virtual bool KNN(const Vector& p,int k,std::vector<int>& nn,std::vector<Real>& distances);
84  virtual bool FilteredNN(const Vector& p,bool (*filter)(int),int& nn,Real& distance);
85  virtual bool FilteredKNN(const Vector& p,int k,bool (*filter)(int),std::vector<int>& nn,std::vector<Real>& distances);
86 };
87 
92 {
93  public:
94  RandomBestPointLocation(std::vector<Vector>& points,CSpace* _space,int k=1);
95  virtual void OnBuild() {}
96  virtual void OnAppend() {}
97  virtual bool OnDelete(int id) { return true; }
98  virtual bool OnClear() { return true; }
99  virtual bool Exact() { return false; }
100  virtual bool NN(const Vector& p,int& nn,Real& distance);
101  virtual bool KNN(const Vector& p,int k,std::vector<int>& nn,std::vector<Real>& distances);
102  virtual bool FilteredNN(const Vector& p,bool (*filter)(int),int& nn,Real& distance);
103  virtual bool FilteredKNN(const Vector& p,int k,bool (*filter)(int),std::vector<int>& nn,std::vector<Real>& distances);
104 
105  CSpace* space;
106  int k;
107 };
108 
109 
117 {
118  public:
119  KDTreePointLocation(std::vector<Vector>& points);
120  KDTreePointLocation(std::vector<Vector>& points,Real norm,const Vector& weights);
121  virtual ~KDTreePointLocation();
122  virtual void OnBuild();
123  virtual void OnAppend();
124  virtual bool OnClear();
125  virtual bool NN(const Vector& p,int& nn,Real& distance);
126  virtual bool KNN(const Vector& p,int k,std::vector<int>& nn,std::vector<Real>& distances);
127  virtual bool Close(const Vector& p,Real r,std::vector<int>& nn,std::vector<Real>& distances);
128 
129  Real norm;
130  Vector weights;
131  Geometry::KDTree* tree;
132 };
133 
134 
135 #endif
virtual bool FilteredNN(const Vector &p, bool(*filter)(int), int &nn, Real &distance)
Same as NN, but with a filter.
Definition: PointLocation.h:41
An accelerated point location algorithm that uses a K-D tree.
Definition: PointLocation.h:116
virtual void OnAppend()
Call this when something is appended to the point list.
Definition: PointLocation.h:56
virtual bool Exact()
Subclass returns true if this is exact nearest neighbors.
Definition: PointLocation.h:27
Motion planning configuration space base class. The configuration space implements an interpolation s...
Definition: CSpace.h:34
virtual void OnAppend()
Call this when something is appended to the point list.
Definition: PointLocation.h:96
virtual bool OnDelete(int id)
Definition: PointLocation.h:57
A uniform abstract interface to point location data structures. The point locator operators in-place ...
Definition: PointLocation.h:12
virtual void OnBuild()
Call this when the point list is completely changed.
Definition: PointLocation.h:95
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:43
virtual bool OnClear()
Call this when the point list is cleared.
Definition: PointLocation.h:58
virtual void OnBuild()
Call this when the point list is completely changed.
Definition: PointLocation.h:55
The approximate O(k) point location algorithm that returns the closest of k randomly chosen points...
Definition: PointLocation.h:91
virtual bool OnClear()
Call this when the point list is cleared.
Definition: PointLocation.h:80
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:77
virtual bool OnDelete(int id)
Definition: PointLocation.h:97
A kd-tree or a node of one.
Definition: KDTree.h:27
virtual bool NN(const Vector &p, int &nn, Real &distance)
Definition: PointLocation.h:31
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:45
virtual bool Exact()
Subclass returns true if this is exact nearest neighbors.
Definition: PointLocation.h:81
virtual bool OnDelete(int id)
Definition: PointLocation.h:23
virtual bool OnClear()
Call this when the point list is cleared.
Definition: PointLocation.h:98
virtual bool Exact()
Subclass returns true if this is exact nearest neighbors.
Definition: PointLocation.h:99
virtual bool OnDelete(int id)
Definition: PointLocation.h:79
virtual bool KNN(const Vector &p, int k, std::vector< int > &nn, std::vector< Real > &distances)
Definition: PointLocation.h:35
virtual void OnAppend()
Call this when something is appended to the point list.
Definition: PointLocation.h:78
virtual bool OnClear()
Call this when the point list is cleared.
Definition: PointLocation.h:25
virtual bool Close(const Vector &p, Real r, std::vector< int > &neighbors, std::vector< Real > &distances)
Definition: PointLocation.h:39
The approximate O(1) point location algorithm that simply returns a random point. ...
Definition: PointLocation.h:73
The Naive O(n) point location algorithm.
Definition: PointLocation.h:51
virtual void OnAppend()=0
Call this when something is appended to the point list.