1 #ifndef _SPICA_HASH_GRID_DETAIL_H_
2 #define _SPICA_HASH_GRID_DETAIL_H_
9 HashGrid<T>::HashGrid()
18 HashGrid<T>::~HashGrid()
29 this->_hashSize = hashSize;
30 this->_hashScale = hashScale;
32 this->_data.resize(hashSize);
37 const Vector3d bMin = (boxMin - _bbox.posMin()) * _hashScale;
38 const Vector3d bMax = (boxMax - _bbox.posMin()) * _hashScale;
40 const int minZ = std::abs(static_cast<int>(bMin.
z()));
41 const int maxZ = std::abs(static_cast<int>(bMax.
z()));
42 const int minY = std::abs(static_cast<int>(bMin.
y()));
43 const int maxY = std::abs(static_cast<int>(bMax.
y()));
44 const int minX = std::abs(static_cast<int>(bMin.
x()));
45 const int maxX = std::abs(static_cast<int>(bMax.
x()));
46 for (
int iz = minZ; iz <= maxZ; iz++) {
47 for (
int iy = minY; iy <= maxY; iy++) {
48 for (
int ix = minX; ix <= maxX; ix++) {
49 unsigned int h = hash(ix, iy, iz);
50 _data[h].push_back(p);
63 Assertion(_hashSize > 0,
"hash size is not initialized");
64 return (
unsigned int)((ix * 73856093) ^ (iy * 19349663) ^ (iz * 83492791)) % _hashSize;
68 const typename std::vector<T>& HashGrid<T>::operator[](
const Point3d& v)
const {
69 Vector3d b = (v - _bbox.posMin()) * _hashScale;
70 const int ix = std::abs(static_cast<int>(b.x()));
71 const int iy = std::abs(static_cast<int>(b.y()));
72 const int iz = std::abs(static_cast<int>(b.z()));
73 return _data[hash(ix, iy, iz)];
78 #endif // _SPICA_HASH_GRID_DETAIL_H_
T z() const
Get z.
Definition: vector3d.h:106
void init(const int hashSize, const double hashScale, const Bounds3d &bbox)
Initialize grid.
Definition: hash_grid_detail.h:28
void add(const T &p, const Point3d &boxMin, const Point3d &boxMax)
Set point data for the cells inside the specifed bounding box.
Definition: hash_grid_detail.h:36
T x() const
Get x.
Definition: vector3d.h:98
void construct(std::vector< T > &points, const int imageW=-1, const int imageH=-1)
Construct hash grid.
Definition: hash_grid_detail.h:23
void clear()
Clear grid data.
Definition: hash_grid_detail.h:57
T y() const
Get y.
Definition: vector3d.h:102
Definition: hash_grid.h:12