|
| PointHashGrid (float radiusHint, const shared_ptr< MemoryManager > &m=MemoryManager::create()) |
|
| PointHashGrid (const Array< Value > &init, float radiusHint=-1.0f, const shared_ptr< MemoryManager > &m=MemoryManager::create()) |
| If radiusHint is negative, it is automatically chosen to put about 5 values in each grid cell (which means about 27 * 5 values for each beginIntersection call). More...
|
|
Iterator | begin () const |
| Iterate through all members. More...
|
|
SphereIterator | begin (const Sphere &sphere) const |
| Finds all values whose positions are within sphere. More...
|
|
BoxIterator | beginBoxIntersection (const AABox &box, bool exact=true) const |
| Finds all values whose positions are within box. More...
|
|
CellIterator | beginCells () const |
| Iterates through the non-empty cells. More...
|
|
void | clear (float radiusHint) |
|
void | clear (bool shrink=true) |
| Removes all data. More...
|
|
void | clearAndSetMemoryManager (const shared_ptr< MemoryManager > &m) |
|
void | clearAndSetRadiusHint (float radiusHint) |
|
const AABox & | conservativeBoxBounds () const |
| Returns a conservative bounding box around the contents. More...
|
|
bool | contains (const Value &v) const |
| Returns true if there is a value that is exactly equal to v. More...
|
|
float | debugGetAverageBucketSize () const |
|
int | debugGetDeepestBucketSize () const |
|
void | debugPrintStatistics () const |
|
void | deleteAll () |
| Calls delete on all of the values, which are assumed to be pointers. More...
|
|
const Iterator & | end () const |
|
const BoxIterator & | endBoxIntersection () const |
|
const CellIterator & | endCells () const |
|
void | getCellCoord (const Point3 &pos, Point3int32 &cellCoord) const |
| Compute the grid cell index of a real position. More...
|
|
void | getIntersectingMembers (const Sphere &sphere, Array< Value > &result) const |
| Appends results. More...
|
|
void | insert (const Value &v) |
| Insert v at position p given by getPosition(v, p) . More...
|
|
void | insert (const Array< Value > &v) |
| Inserts all elements of the array. More...
|
|
float | radiusHint () const |
|
bool | remove (const Value &v, bool shrinkIfNecessary=true) |
| If there are multiple copies of an element, you must delete them multiple times. More...
|
|
void | remove (const Array< Value > &v, bool shrink=true) |
| Removes all elements of v. More...
|
|
int | size () const |
| Returns the number of elements. More...
|
|
template<class Value, class PosFunc = PositionTrait<Value>, class EqualsFunc = EqualsTrait<Value>>
class G3D::PointHashGrid< Value, PosFunc, EqualsFunc >
A sparse 3D grid of point-based data.
The space cost for n elements is O(n). For data with approximately uniform density (with respect to the radius hint), the time cost of searching for neighbors is O(1).
You can move members of the data set by first removing them and then adding them with a new location.
Template argument PosFunc must provide a static getPosition
method and EqualsFunc must provide a static equals
method, as described below.
You can either write classes that support these yourself, provide template specializations of G3D::PositionTrait and G3D::EqualsTrait, or rely on the default template specializations, which already exist for common G3D classes like G3D::Point3. For example:
class PosFunc {
public:
static void getPosition(
const Data& d,
Vector3& pos) {
pos = d.location;
}
};
class EqualsFunc {
public:
static bool equals(const Data& p, const Data& q) {
return p == q;
}
};
PointHashGrid<Data, Data::PosFunc, Data::EqualsFunc> grid;
If the Value class defines operator==
, then the Equalsfunc is optional, so you can just write:
PointHashGrid<Data, Data::PosFunc> grid;
The simplest way to define these is often to make them both methods of the parameter class itself, e.g.,
class Data {
public:
...
return (location == other.location) && ...;
}
static void getPosition(
const Data& p,
Vector3& pos) {
pos = p.location;
}
};
typedef PointHashGrid<Data, Data> DataGrid;