48#include <pcl/pcl_exports.h>
64 template<
class UserData>
127 Node (std::vector<BoundedObject*>& sorted_objects,
int first_id,
int last_id)
130 memcpy (
bounds_, sorted_objects[first_id]->getBounds (), 6*
sizeof (
float));
133 for (
int i = first_id + 1 ; i <= last_id ; ++i )
137 if ( first_id != last_id )
140 int mid_id = (first_id + last_id) >> 1;
142 children_[1] =
new Node(sorted_objects, mid_id + 1, last_id);
147 object_ = sorted_objects[first_id];
230 build(std::vector<BoundedObject*>& objects)
234 if ( objects.empty () )
243 root_ =
new Node (objects, 0,
static_cast<int> (objects.size () - 1));
254 inline const std::vector<BoundedObject*>*
263 intersect(
const float box[6], std::list<BoundedObject*>& intersected_objects)
const
268 bool got_intersection =
false;
271 std::list<Node*> working_list;
272 working_list.push_back (
root_);
274 while ( !working_list.empty () )
276 Node* node = working_list.front ();
277 working_list.pop_front ();
280 if ( node->intersect (box) )
283 if ( node->hasChildren () )
285 working_list.push_back (node->getLeftChild ());
286 working_list.push_back (node->getRightChild ());
290 intersected_objects.push_back (node->getObject ());
291 got_intersection =
true;
296 return (got_intersection);
static bool compareCentroidsXCoordinates(const BoundedObject *a, const BoundedObject *b)
This method is for std::sort.
float bounds_[6]
These are the bounds of the object.
UserData data_
This is the user-defined data object.
BoundedObject(const UserData &data)
float centroid_[3]
This is the centroid.
const float * getCentroid() const
BoundedObject * getObject()
Node(std::vector< BoundedObject * > &sorted_objects, int first_id, int last_id)
'sorted_objects' is a sorted vector of bounded objects.
bool intersect(const float box[6]) const
Returns true if 'box' intersects or touches (with a side or a vertex) this node.
double computeBoundingBoxVolume() const
Computes and returns the volume of the bounding box of this node.
std::vector< BoundedObject * > * sorted_objects_
bool intersect(const float box[6], std::list< BoundedObject * > &intersected_objects) const
Pushes back in 'intersected_objects' the bounded objects intersected by the input 'box' and returns t...
const std::vector< BoundedObject * > * getInputObjects() const
void build(std::vector< BoundedObject * > &objects)
Creates the tree.
void expandBoundingBox(T dst[6], const T src[6])
Expands the destination bounding box 'dst' such that it contains 'src'.