8 #ifndef SIMPLE_OCTREE_HPP_ 9 #define SIMPLE_OCTREE_HPP_ 13 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline 22 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline 31 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void 41 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void 54 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void 61 radius_ =
static_cast<Scalar
> (std::sqrt (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]));
66 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline bool 72 Scalar bounds[6], center[3], childside =
static_cast<Scalar
> (0.5)*(
bounds_[1]-
bounds_[0]);
80 center[0] = 0.5f*(bounds[0] + bounds[1]);
81 center[1] = 0.5f*(bounds[2] + bounds[3]);
82 center[2] = 0.5f*(bounds[4] + bounds[5]);
90 center[2] += childside;
98 center[1] += childside;
106 center[2] -= childside;
114 center[0] += childside;
122 center[2] += childside;
130 center[1] -= childside;
138 center[2] -= childside;
143 for (
int i = 0 ; i < 8 ; ++i )
154 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void 166 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void 178 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void 190 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline 199 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline 207 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void 221 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void 223 NodeDataCreator* node_data_creator)
225 if ( voxel_size <= 0 )
233 Scalar extent = std::max (std::max (bounds[1]-bounds[0], bounds[3]-bounds[2]), bounds[5]-bounds[4]);
234 Scalar center[3] = {
static_cast<Scalar
> (0.5)*(bounds[0]+bounds[1]),
235 static_cast<Scalar> (0.5)*(bounds[2]+bounds[3]),
236 static_cast<Scalar> (0.5)*(bounds[4]+bounds[5])};
238 Scalar arg = extent/voxel_size;
242 tree_levels_ =
static_cast<int> (ceil (log (arg)/log (2.0)) + 0.5);
247 Scalar half_root_side =
static_cast<Scalar
> (0.5f*pow (2.0,
tree_levels_)*voxel_size);
250 bounds_[0] = center[0] - half_root_side;
251 bounds_[1] = center[0] + half_root_side;
252 bounds_[2] = center[1] - half_root_side;
253 bounds_[3] = center[1] + half_root_side;
254 bounds_[4] = center[2] - half_root_side;
255 bounds_[5] = center[2] + half_root_side;
267 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline 290 if ( x >= c[0] )
id |= 4;
291 if ( y >= c[1] )
id |= 2;
292 if ( z >= c[2] )
id |= 1;
309 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline 316 bounds_[4] + offset +
static_cast<Scalar
> (k)*voxel_size_};
323 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline 348 if ( x >= c[0] )
id |= 4;
349 if ( y >= c[1] )
id |= 2;
350 if ( z >= c[2] )
id |= 1;
363 template<
typename NodeData,
typename NodeDataCreator,
typename Scalar>
inline void
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...
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 setBounds(const Scalar *b)
std::set< Node * > full_leaf_neighbors_
void makeNeighbors(Node *node)
Make this and 'node' neighbors by inserting each node in the others node neighbor set...
const Scalar * getCenter() const
void setData(const NodeData &src)
NodeDataCreator * node_data_creator_
void setParent(Node *parent)
Node * getFullLeaf(int i, int j, int k)
Since the leaves are aligned in a rectilinear grid, each leaf has a unique id.
void insertNeighbors(Node *node)
std::vector< Node * > full_leaves_
void setCenter(const Scalar *c)
void computeRadius()
Computes the "radius" of the node which is half the diagonal length.