39 #ifndef PCL_RECOGNITION_VOXEL_STRUCTURE_HPP_ 40 #define PCL_RECOGNITION_VOXEL_STRUCTURE_HPP_ 42 template<
class T,
typename REAL>
inline void 48 bounds_[0] = bounds[0];
49 bounds_[1] = bounds[1];
50 bounds_[2] = bounds[2];
51 bounds_[3] = bounds[3];
52 bounds_[4] = bounds[4];
53 bounds_[5] = bounds[5];
55 num_of_voxels_[0] = num_of_voxels[0];
56 num_of_voxels_[1] = num_of_voxels[1];
57 num_of_voxels_[2] = num_of_voxels[2];
58 num_of_voxels_xy_plane_ = num_of_voxels[0]*num_of_voxels[1];
59 total_num_of_voxels_ = num_of_voxels_xy_plane_*num_of_voxels[2];
62 voxels_ =
new T[total_num_of_voxels_];
65 spacing_[0] = (bounds[1]-bounds[0])/static_cast<REAL> (num_of_voxels[0]);
66 spacing_[1] = (bounds[3]-bounds[2])/static_cast<REAL> (num_of_voxels[1]);
67 spacing_[2] = (bounds[5]-bounds[4])/static_cast<REAL> (num_of_voxels[2]);
70 min_center_[0] = bounds_[0] +
static_cast<REAL
> (0.5)*spacing_[0];
71 min_center_[1] = bounds_[2] +
static_cast<REAL
> (0.5)*spacing_[1];
72 min_center_[2] = bounds_[4] +
static_cast<REAL
> (0.5)*spacing_[2];
77 template<
class T,
typename REAL>
inline T*
80 if ( p[0] < bounds_[0] || p[0] >= bounds_[1] || p[1] < bounds_[2] || p[1] >= bounds_[3] || p[2] < bounds_[4] || p[2] >= bounds_[5] )
83 int x =
static_cast<int> ((p[0] - bounds_[0])/spacing_[0]);
84 int y =
static_cast<int> ((p[1] - bounds_[2])/spacing_[1]);
85 int z =
static_cast<int> ((p[2] - bounds_[4])/spacing_[2]);
87 return &voxels_[z*num_of_voxels_xy_plane_ + y*num_of_voxels_[0] + x];
92 template<
class T,
typename REAL>
inline T*
95 if ( x < 0 || x >= num_of_voxels_[0] )
return NULL;
96 if ( y < 0 || y >= num_of_voxels_[1] )
return NULL;
97 if ( z < 0 || z >= num_of_voxels_[2] )
return NULL;
99 return &voxels_[z*num_of_voxels_xy_plane_ + y*num_of_voxels_[0] + x];
104 template<
class T,
typename REAL>
inline int 107 if ( p[0] < bounds_[0] || p[0] >= bounds_[1] || p[1] < bounds_[2] || p[1] >= bounds_[3] || p[2] < bounds_[4] || p[2] >= bounds_[5] )
110 const int x =
static_cast<int> ((p[0] - bounds_[0])/spacing_[0]);
111 const int y =
static_cast<int> ((p[1] - bounds_[2])/spacing_[1]);
112 const int z =
static_cast<int> ((p[2] - bounds_[4])/spacing_[2]);
114 const int x_m1 = x-1, x_p1 = x+1;
115 const int y_m1 = y-1, y_p1 = y+1;
116 const int z_m1 = z-1, z_p1 = z+1;
121 voxel = this->getVoxel (x_p1, y_p1, z_p1);
if ( voxel ) neighs[num_neighs++] = voxel;
122 voxel = this->getVoxel (x_p1, y_p1, z );
if ( voxel ) neighs[num_neighs++] = voxel;
123 voxel = this->getVoxel (x_p1, y_p1, z_m1);
if ( voxel ) neighs[num_neighs++] = voxel;
124 voxel = this->getVoxel (x_p1, y , z_p1);
if ( voxel ) neighs[num_neighs++] = voxel;
125 voxel = this->getVoxel (x_p1, y , z );
if ( voxel ) neighs[num_neighs++] = voxel;
126 voxel = this->getVoxel (x_p1, y , z_m1);
if ( voxel ) neighs[num_neighs++] = voxel;
127 voxel = this->getVoxel (x_p1, y_m1, z_p1);
if ( voxel ) neighs[num_neighs++] = voxel;
128 voxel = this->getVoxel (x_p1, y_m1, z );
if ( voxel ) neighs[num_neighs++] = voxel;
129 voxel = this->getVoxel (x_p1, y_m1, z_m1);
if ( voxel ) neighs[num_neighs++] = voxel;
131 voxel = this->getVoxel (x , y_p1, z_p1);
if ( voxel ) neighs[num_neighs++] = voxel;
132 voxel = this->getVoxel (x , y_p1, z );
if ( voxel ) neighs[num_neighs++] = voxel;
133 voxel = this->getVoxel (x , y_p1, z_m1);
if ( voxel ) neighs[num_neighs++] = voxel;
134 voxel = this->getVoxel (x , y , z_p1);
if ( voxel ) neighs[num_neighs++] = voxel;
135 voxel = this->getVoxel (x , y , z );
if ( voxel ) neighs[num_neighs++] = voxel;
136 voxel = this->getVoxel (x , y , z_m1);
if ( voxel ) neighs[num_neighs++] = voxel;
137 voxel = this->getVoxel (x , y_m1, z_p1);
if ( voxel ) neighs[num_neighs++] = voxel;
138 voxel = this->getVoxel (x , y_m1, z );
if ( voxel ) neighs[num_neighs++] = voxel;
139 voxel = this->getVoxel (x , y_m1, z_m1);
if ( voxel ) neighs[num_neighs++] = voxel;
141 voxel = this->getVoxel (x_m1, y_p1, z_p1);
if ( voxel ) neighs[num_neighs++] = voxel;
142 voxel = this->getVoxel (x_m1, y_p1, z );
if ( voxel ) neighs[num_neighs++] = voxel;
143 voxel = this->getVoxel (x_m1, y_p1, z_m1);
if ( voxel ) neighs[num_neighs++] = voxel;
144 voxel = this->getVoxel (x_m1, y , z_p1);
if ( voxel ) neighs[num_neighs++] = voxel;
145 voxel = this->getVoxel (x_m1, y , z );
if ( voxel ) neighs[num_neighs++] = voxel;
146 voxel = this->getVoxel (x_m1, y , z_m1);
if ( voxel ) neighs[num_neighs++] = voxel;
147 voxel = this->getVoxel (x_m1, y_m1, z_p1);
if ( voxel ) neighs[num_neighs++] = voxel;
148 voxel = this->getVoxel (x_m1, y_m1, z );
if ( voxel ) neighs[num_neighs++] = voxel;
149 voxel = this->getVoxel (x_m1, y_m1, z_m1);
if ( voxel ) neighs[num_neighs++] = voxel;
156 #endif // PCL_RECOGNITION_VOXEL_STRUCTURE_HPP_ T * getVoxel(const REAL p[3])
Returns a pointer to the voxel which contains p or NULL if p is not inside the structure.
void build(const REAL bounds[6], int num_of_voxels[3])
Call this method before using an instance of this class.
int getNeighbors(const REAL *p, T **neighs) const
Saves pointers to the voxels which are neighbors of the voxels which contains 'p'.