8#ifndef SIMPLE_OCTREE_HPP_
9#define SIMPLE_OCTREE_HPP_
20template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline
28template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline
36template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void
45template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void
57template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void
64 radius_ =
static_cast<Scalar
> (std::sqrt (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]));
68template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline bool
74 Scalar bounds[6], center[3], childside =
static_cast<Scalar
> (0.5)*(
bounds_[1]-
bounds_[0]);
82 center[0] = 0.5f*(bounds[0] + bounds[1]);
83 center[1] = 0.5f*(bounds[2] + bounds[3]);
84 center[2] = 0.5f*(bounds[4] + bounds[5]);
92 center[2] += childside;
100 center[1] += childside;
108 center[2] -= childside;
116 center[0] += childside;
124 center[2] += childside;
132 center[1] -= childside;
140 center[2] -= childside;
145 for (
int i = 0 ; i < 8 ; ++i )
155template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void
163template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void
171template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void
182template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline
186template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline
193template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void
203template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void
205 NodeDataCreator* node_data_creator)
207 if ( voxel_size <= 0 )
215 Scalar extent = std::max (std::max (bounds[1]-bounds[0], bounds[3]-bounds[2]), bounds[5]-bounds[4]);
216 Scalar center[3] = {
static_cast<Scalar
> (0.5)*(bounds[0]+bounds[1]),
217 static_cast<Scalar
> (0.5)*(bounds[2]+bounds[3]),
218 static_cast<Scalar
> (0.5)*(bounds[4]+bounds[5])};
220 Scalar arg = extent/voxel_size;
224 tree_levels_ =
static_cast<int> (std::ceil (std::log (arg)/std::log (2.0)) + 0.5);
229 Scalar half_root_side =
static_cast<Scalar
> (0.5f*pow (2.0,
tree_levels_)*voxel_size);
232 bounds_[0] = center[0] - half_root_side;
233 bounds_[1] = center[0] + half_root_side;
234 bounds_[2] = center[1] - half_root_side;
235 bounds_[3] = center[1] + half_root_side;
236 bounds_[4] = center[2] - half_root_side;
237 bounds_[5] = center[2] + half_root_side;
241 root_->setCenter (center);
243 root_->setParent (
nullptr);
244 root_->computeRadius ();
248template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline
269 if ( x >= c[0] )
id |= 4;
270 if ( y >= c[1] )
id |= 2;
271 if ( z >= c[2] )
id |= 1;
287template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline
300template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline
323 if ( x >= c[0] )
id |= 4;
324 if ( y >= c[1] )
id |= 2;
325 if ( z >= c[2] )
id |= 1;
337template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void
std::set< Node * > full_leaf_neighbors_
void setBounds(const Scalar *b)
void makeNeighbors(Node *node)
Make this and 'node' neighbors by inserting each node in the others node neighbor set.
const Scalar * getCenter() const
void computeRadius()
Computes the "radius" of the node which is half the diagonal length.
void setData(const NodeData &src)
void setCenter(const Scalar *c)
void insertNeighbors(Node *node)
NodeDataCreator * node_data_creator_
Node * createLeaf(Scalar x, Scalar y, Scalar z)
Creates the leaf containing p = (x, y, z) and returns a pointer to it, however, only if p lies within...
void build(const Scalar *bounds, Scalar voxel_size, NodeDataCreator *node_data_creator)
Creates an empty octree with bounds at least as large as the ones provided as input and with leaf siz...
std::vector< Node * > full_leaves_
Node * getFullLeaf(int i, int j, int k)
Since the leaves are aligned in a rectilinear grid, each leaf has a unique id.