48#include <pcl/pcl_exports.h>
64 template<
class UserData>
125 Node (std::vector<BoundedObject*>& sorted_objects,
int first_id,
int last_id)
128 auto firstBounds = sorted_objects[first_id]->getBounds();
129 std::copy(firstBounds, firstBounds + 6,
bounds_);
132 for (
int i = first_id + 1 ; i <= last_id ; ++i )
138 if ( first_id != last_id )
141 int mid_id = (first_id + last_id) >> 1;
143 children_[1] =
new Node(sorted_objects, mid_id + 1, last_id);
148 object_ = sorted_objects[first_id];
231 build(std::vector<BoundedObject*>& objects)
235 if ( objects.empty () )
244 root_ =
new Node (objects, 0,
static_cast<int> (objects.size () - 1));
255 inline const std::vector<BoundedObject*>*
264 intersect(
const float box[6], std::list<BoundedObject*>& intersected_objects)
const
269 bool got_intersection =
false;
272 std::list<Node*> working_list;
273 working_list.push_back (
root_);
275 while ( !working_list.empty () )
277 Node* node = working_list.front ();
278 working_list.pop_front ();
281 if ( node->intersect (box) )
284 if ( node->hasChildren () )
286 working_list.push_back (node->getLeftChild ());
287 working_list.push_back (node->getRightChild ());
291 intersected_objects.push_back (node->getObject ());
292 got_intersection =
true;
297 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.
virtual ~BoundedObject()=default
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'.