1 #ifndef GEOMETRY_GRID_SUBDIVISION_H 2 #define GEOMETRY_GRID_SUBDIVISION_H 4 #include <KrisLibrary/math/vector.h> 6 #include <KrisLibrary/utils/IntTuple.h> 7 #include <KrisLibrary/utils/IntTriple.h> 10 #include <KrisLibrary/utils/stl_tr1.h> 20 size_t operator () (
const IntTriple& x)
const;
21 size_t operator () (
const std::vector<int>& x)
const;
38 typedef bool (*QueryCallback)(
void* value);
41 explicit GridHash3D(
const Vector3& h);
42 size_t GetBucketCount()
const {
return buckets.bucket_count(); }
43 void SetBucketCount(
size_t n) { buckets.rehash(n); }
46 void SetResolution(
const Vector3& h);
48 void SetResolution(Real h);
50 void Set(
const Index& i,
void* data);
52 void* Get(
const Index& i)
const;
54 void* Erase(
const Index& i);
56 bool Contains(
const Index& i);
58 void Enumerate(std::vector<Value>& items)
const;
61 void PointToIndex(
const Vector3& p,Index& i)
const;
65 void IndexBucketBounds(
const Index& i,
Vector3& bmin,
Vector3& bmax)
const;
68 void GetRange(Index& imin,Index& imax)
const;
73 bool IndexQuery(
const Index& imin,
const Index& imax,QueryCallback f)
const;
75 bool BoxQuery(
const Vector3& bmin,
const Vector3& bmax,QueryCallback f)
const;
77 bool BallQuery(
const Vector3& c,Real r,QueryCallback f)
const;
79 bool SegmentQuery(
const Vector3& a,
const Vector3& b,QueryCallback f)
const;
82 void IndexItems(
const Index& imin,
const Index& imax,std::vector<Value>& items)
const;
84 void BoxItems(
const Vector3& bmin,
const Vector3& bmax,std::vector<Value>& items)
const;
86 void BallItems(
const Vector3& c,Real r,std::vector<Value>& items)
const;
88 void SegmentItems(
const Vector3& a,
const Vector3& b,std::vector<Value>& items)
const;
91 typedef UNORDERED_MAP_TEMPLATE<Index,Value,IndexHash> HashTable;
102 typedef std::vector<void*> ObjectSet;
104 typedef bool (*QueryCallback)(
void* obj);
107 explicit GridSubdivision3D(
const Vector3& h);
108 size_t GetBucketCount()
const {
return buckets.bucket_count(); }
109 void SetBucketCount(
size_t n) { buckets.rehash(n); }
113 void Insert(
const Index& i,
void* data);
115 bool Erase(
const Index& i,
void* data);
116 ObjectSet* GetObjectSet(
const Index& i);
117 const ObjectSet* GetObjectSet(
const Index& i)
const;
121 void PointToIndex(
const Vector3& p,Index& i)
const;
125 void IndexBucketBounds(
const Index& i,
Vector3& bmin,
Vector3& bmax)
const;
128 void GetRange(Index& imin,Index& imax)
const;
133 bool IndexQuery(
const Index& imin,
const Index& imax,QueryCallback f)
const;
135 bool BoxQuery(
const Vector3& bmin,
const Vector3& bmax,QueryCallback f)
const;
137 bool BallQuery(
const Vector3& c,Real r,QueryCallback f)
const;
139 bool SegmentQuery(
const Vector3& a,
const Vector3& b,QueryCallback f)
const;
142 void IndexItems(
const Index& imin,
const Index& imax,ObjectSet& objs)
const;
144 void BoxItems(
const Vector3& bmin,
const Vector3& bmax,ObjectSet& objs)
const;
146 void BallItems(
const Vector3& c,Real r,ObjectSet& objs)
const;
148 void SegmentItems(
const Vector3& a,
const Vector3& b,ObjectSet& objs)
const;
151 typedef UNORDERED_MAP_TEMPLATE<Index,ObjectSet,IndexHash> HashTable;
169 typedef bool (*QueryCallback)(
void* value);
171 explicit GridHash(
int numDims,Real h=1);
172 explicit GridHash(
const Vector& h);
173 size_t GetBucketCount()
const {
return buckets.bucket_count(); }
174 void SetBucketCount(
size_t n) { buckets.rehash(n); }
175 Vector GetResolution()
const;
177 void SetResolution(
const Vector& h);
179 void SetResolution(Real h);
181 void Set(
const Index& i,
void* data);
183 void* Get(
const Index& i)
const;
185 void* Erase(
const Index& i);
187 bool Contains(
const Index& i);
189 void Enumerate(std::vector<Value>& items)
const;
192 void PointToIndex(
const Vector& p,Index& i)
const;
194 void PointToIndex(
const Vector& p,Index& i,
Vector& u)
const;
196 void IndexBucketBounds(
const Index& i,
Vector& bmin,
Vector& bmax)
const;
199 void GetRange(Index& imin,Index& imax)
const;
204 bool IndexQuery(
const Index& imin,
const Index& imax,QueryCallback f)
const;
206 bool BoxQuery(
const Vector& bmin,
const Vector& bmax,QueryCallback f)
const;
208 bool BallQuery(
const Vector& c,Real r,QueryCallback f)
const;
210 bool SegmentQuery(
const Vector& a,
const Vector& b,QueryCallback f)
const;
213 void IndexItems(
const Index& imin,
const Index& imax,std::vector<Value>& items)
const;
215 void BoxItems(
const Vector& bmin,
const Vector& bmax,std::vector<Value>& items)
const;
217 void BallItems(
const Vector& c,Real r,std::vector<Value>& items)
const;
219 void SegmentItems(
const Vector& a,
const Vector& b,std::vector<Value>& items)
const;
222 typedef UNORDERED_MAP_TEMPLATE<Index,Value,IndexHash> HashTable;
234 typedef std::vector<void*> ObjectSet;
236 typedef bool (*QueryCallback)(
void* obj);
239 explicit GridSubdivision(
const Vector& h);
240 size_t GetBucketCount()
const {
return buckets.bucket_count(); }
241 void SetBucketCount(
size_t n) { buckets.rehash(n); }
245 void Insert(
const Index& i,
void* data);
247 bool Erase(
const Index& i,
void* data);
248 ObjectSet* GetObjectSet(
const Index& i);
249 const ObjectSet* GetObjectSet(
const Index& i)
const;
253 void PointToIndex(
const Vector& p,Index& i)
const;
255 void PointToIndex(
const Vector& p,Index& i,
Vector& u)
const;
257 void IndexBucketBounds(
const Index& i,
Vector& bmin,
Vector& bmax)
const;
260 void GetRange(Index& imin,Index& imax)
const;
265 bool IndexQuery(
const Index& imin,
const Index& imax,QueryCallback f)
const;
267 bool BoxQuery(
const Vector& bmin,
const Vector& bmax,QueryCallback f)
const;
269 bool BallQuery(
const Vector& c,Real r,QueryCallback f)
const;
271 bool SegmentQuery(
const Vector& a,
const Vector& b,QueryCallback f)
const;
274 void IndexItems(
const Index& imin,
const Index& imax,ObjectSet& objs)
const;
276 void BoxItems(
const Vector& bmin,
const Vector& bmax,ObjectSet& objs)
const;
278 void BallItems(
const Vector& c,Real r,ObjectSet& objs)
const;
280 void SegmentItems(
const Vector& a,
const Vector& b,ObjectSet& objs)
const;
283 typedef UNORDERED_MAP_TEMPLATE<Index,ObjectSet,IndexHash> HashTable;
A lightweight integer 3-tuple class.
Definition: IntTriple.h:9
A grid containing objects (referenced by void pointers)
Definition: GridSubdivision.h:32
A 3D vector class.
Definition: math3d/primitives.h:136
An ND grid with a list of arbitrary objects (given by void pointers)
Definition: GridSubdivision.h:230
Class declarations for useful 3D math types.
An integer tuple class.
Definition: IntTuple.h:14
An ND grid containing objects (referenced by void pointers)
Definition: GridSubdivision.h:163
Definition: GridSubdivision.h:17
Contains all the definitions in the Math3D package.
Definition: AnyGeometry.h:13
Contains all definitions in the Math package.
Definition: WorkspaceBound.h:12
Contains all definitions in the Geometry package.
Definition: AnyGeometry.cpp:26
A grid with a list of arbitrary objects (given by void pointers)
Definition: GridSubdivision.h:98