Tulip  5.2.0
Large graphs analysis and drawing
BoundingBox.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 #ifndef Tulip_BOUNDINGBOX_H
21 #define Tulip_BOUNDINGBOX_H
22 
23 #include <cassert>
24 #include <tulip/Vector.h>
25 #include <tulip/tulipconf.h>
26 
27 namespace tlp {
28 /**
29  * \ingroup Structures
30  * \brief This class represents the 3D bounding box of an object.
31  * It is mostly used to determine whether or not two object are in a state of collision.
32  *
33  * It is defined by two 3d points, the first one (A) being the lowest point, the second (B) being
34  the highest.
35  * As a bounding box is a mathematical entity describing the lowest and highest points, whether
36  these points are in the top-left corner or
37  * lower-right corner depends on the axes we use.
38  * Below is a crude ASCII-art description of the axes we use in our 3D world and the points where
39  the min and max are thus positioned.
40  * Through the rest of this class's documentation, it will be assumed that this is the convention.
41  *
42  *
43  * @verbatim
44  y
45  |
46  |
47  |_____ x
48  /
49  /
50  z
51 
52  _________ B
53  / /|
54  / / |
55  /________/ |
56  | | |
57  | | |
58  | | /
59  |________|/
60  A
61 
62  @endverbatim
63  *
64  *
65  */
66 struct TLP_SCOPE BoundingBox : public Array<Vec3f, 2> {
67 
68  /**
69  * @brief Creates an invalid boundig box.
70  * The minimum is (1, 1, 1) and the maximum is (-1, -1, -1).
71  *
72  **/
73  BoundingBox();
74 
75  /**
76  * @brief Creates a bounding box that must be valid.
77  * Validity is checked in debug mode by an assert.
78  *
79  * @param min The lower left closest point of the box.
80  * @param max The higher right most farther point of the box.
81  * @param compute indicates whether the bounding box has to be computed with the min/max args
82  *
83  **/
84  BoundingBox(const tlp::Vec3f &min, const tlp::Vec3f &max, bool checkMinMax = false);
85 
86  /**
87  * @brief Returns the geometrical center of the bounding box.
88  * An assertion is raised in debug mode if the BoundingBox is not valid.
89  *
90  * @return The center of the bounding box :Vec3f
91  **/
92  inline Vec3f center() const {
93  assert(isValid());
94  return ((*this)[0] + (*this)[1]) / 2.f;
95  }
96 
97  /**
98  * @brief Returns the width of the bounding box
99  * An assertion is raised in debug mode if the BoundingBox is not valid.
100  *
101  **/
102  inline float width() const {
103  assert(isValid());
104  return ((*this)[1][0] - (*this)[0][0]);
105  }
106 
107  /**
108  * @brief Returns the height of the bounding box
109  * An assertion is raised in debug mode if the bounding box is not valid.
110  *
111  **/
112  inline float height() const {
113  assert(isValid());
114  return ((*this)[1][1] - (*this)[0][1]);
115  }
116 
117  /**
118  * @brief Returns the depth of the bounding box
119  * An assertion is raised in debug mode if the bounding box is not valid.
120  *
121  **/
122  inline float depth() const {
123  assert(isValid());
124  return ((*this)[1][2] - (*this)[0][2]);
125  }
126 
127  /**
128  * @brief Expands the bounding box to one containing the vector passed as parameter.
129  * If the parameter is inside the bounding box, it remains unchanged.
130  *
131  * @param coord A point in the 3D space we want the bounding box to encompass.
132  * @return void
133  **/
134  void expand(const tlp::Vec3f &coord);
135 
136  /**
137  * @brief Expands the bounding box to one containing the bounding box passed as parameter.
138  * If the parameter is inside the bounding box, it remains unchanged.
139  *
140  * @param bb A bounding box.
141  * @return void
142  **/
143  void expand(const tlp::BoundingBox &bb, bool noCheck = false);
144 
145  /**
146  * @brief Translates the bounding box by the displacement given by the vector passed as parameter.
147  *
148  * @param vec The displacement vector in 3D space to translate this bounding box by.
149  * @return void
150  **/
151  void translate(const tlp::Vec3f &vec);
152 
153  /**
154  * @brief Scales the bounding box, i.e. multiplying its components by a vector passed as parameter.
155  *
156  * @param factor The factor vector to scale this bounding box by.
157  * @return void
158  **/
159  void scale(const tlp::Vec3f &factor);
160 
161  /**
162  * @brief Checks whether the bounding box's lowest point is less than it's highest point.
163  * "Less Than" means axis-by-axis comparison, i.e. x1 < x2 && y1 < y2 && z1 < z2.
164  *
165  * @return bool Whether this bounding box is valid.
166  **/
167  bool isValid() const;
168 
169  /**
170  * @brief Checks if the given vector is inside the current bounding box. If the bounding box is
171  *invalid the result is always false.
172  * @param coord A point in the 3D space.
173  * @return bool Wether coord is in the bounding box.
174  **/
175  bool contains(const tlp::Vec3f &coord) const;
176 
177  /**
178  * @brief Checks if the given bounding box is inside the current bounding box. If one of the
179  *bounding boxes is invalid the result is always false.
180  * @param boundingBox The bounding box to test inclusion
181  * @return bool Wether boundingBox is in the bounding box.
182  **/
183  bool contains(const tlp::BoundingBox &boundingBox) const;
184 
185  /**
186  * @brief Checks if the given bounding box intersect the current one. If one of the bounding box is
187  *invalid return false.
188  * @param boundingBox The bounding box to compare with.
189  * @return bool Wether the bounding boxes intersect.
190  **/
191  bool intersect(const tlp::BoundingBox &boundingBox) const;
192 
193  /**
194  * @brief Checks if the bounding box intersects a given line segment. If the bounding box is
195  *invalid the result is always false.
196  * @param segStart the start point of the line segment on which to check intersection
197  * @param segEnd the end point of the line segment on which to check intersection
198  * @return bool Wether the line segment intersects the bounding box
199  **/
200  bool intersect(const Vec3f &segStart, const Vec3f &segEnd) const;
201 
202  /**
203  * @brief The vector passed as parameter is modified to contain the 8 points of the bounding box.
204  * The points are, in order :
205  * 0: lower leftmost closest point (the bounding box's minimum)
206  * 1: lower rightmost closest point
207  * 2: highest rightmost closest point
208  * 3: highest leftmost closest point
209  * 4: lower rightmost farthest point
210  * 5: lower rightmost farthest point
211  * 6: highest rightmost farthest point
212  * 7: highest leftmost farthest point
213  *
214  * Crude ASCII art again, sorry for your eyes.
215  *
216  * @verbatim
217 
218  6_________ 7
219  /| /|
220  / | / |
221  3/__|_____/2 |
222  | |_____|__|
223  | /4 | /5
224  | / | /
225  |/_______|/
226  0 1
227 
228  @endverbatim
229  *
230  * @param bb A vector in which to put the points of the bounding box.
231  * @return void
232  **/
233  void getCompleteBB(Vec3f bb[8]) const;
234 };
235 }
236 
237 #endif // Tulip_BOUNDINGBOX_H
float height() const
Returns the height of the bounding box An assertion is raised in debug mode if the bounding box is no...
Definition: BoundingBox.h:112
float depth() const
Returns the depth of the bounding box An assertion is raised in debug mode if the bounding box is not...
Definition: BoundingBox.h:122
float width() const
Returns the width of the bounding box An assertion is raised in debug mode if the BoundingBox is not ...
Definition: BoundingBox.h:102
This class represents the 3D bounding box of an object. It is mostly used to determine whether or not...
Definition: BoundingBox.h:66
Vec3f center() const
Returns the geometrical center of the bounding box. An assertion is raised in debug mode if the Bound...
Definition: BoundingBox.h:92