1 // =============================================================================
2 // PROJECT CHRONO - http://projectchrono.org
3 //
4 // Copyright (c) 2014 projectchrono.org
5 // All rights reserved.
6 //
7 // Use of this source code is governed by a BSD-style license that can be found
8 // in the LICENSE file at the top level of the distribution and at
9 // http://projectchrono.org/license-chrono.txt.
10 //
11 // =============================================================================
12 
13 #ifndef CHC_AABBTREE_H
14 #define CHC_AABBTREE_H
15 
16 #include "chrono/collision/edgetempest/ChCCollisionTree.h"
17 #include "chrono/collision/edgetempest/ChCAABB.h"
18 
19 namespace chrono {
20 namespace collision {
21 
22 ///
23 /// Class containing a tree of Axially Aligned Bounding Boxes, ready for
24 /// collision detection.
25 /// Each rigid body can have one of these models
26 ///
27 
28 class CHAABBTree : public ChCollisionTree {
29   public:
30     CHAABBTree();
31     ~CHAABBTree();
32 
33     /// Deletes all inserted geometries and resets bounding box hierarchies
34     int ResetModel();
35 
36     /// Rebuilds the AABB hierarchy
37     /// (boxes may be inflated by an 'envelope' amount).
38     int BuildModel(double envelope = 0.);
39 
40     /// This function can be used if you want to easily scan the hierarchy
41     /// of bounding boxes. You must provide a callback to a function which
42     /// will be automatically called per each bounding box in this tree.
43     /// Note that the callback will get info about the rotation Rot of the
44     /// box, its position Pos, its size d, its level. Also you can pass generic
45     /// user data via a pointer.  \return the number of scanned boxes.
46     int TraverseBoundingBoxes(void callback(ChMatrix33<>& Rot, Vector& Pos, Vector& d, int level, void* userdata),
47                               void* userdata);
48 
49     /// Returns the n-th child of the tree.
child(int n)50     CHAABB* child(int n) { return &b[n]; }
51 
52   public:
53     /// Vector of AABB bounding boxes.
54     std::vector<CHAABB> b;
55 
56     /// Used by internal algorithms
57     int current_box;
58 
59     /// From geometric objects, builds the hierarchy of BV bounding volumes
60     int build_model(double envelope);
61 };
62 
63 }  // end namespace collision
64 }  // end namespace chrono
65 
66 #endif
67