Tulip  4.6.0
Better Visualization Through Research
library/tulip-core/include/tulip/BoundingBox.h
00001 /*
00002  *
00003  * This file is part of Tulip (www.tulip-software.org)
00004  *
00005  * Authors: David Auber and the Tulip development Team
00006  * from LaBRI, University of Bordeaux
00007  *
00008  * Tulip is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation, either version 3
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Tulip is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  */
00019 
00020 #ifndef Tulip_BOUNDINGBOX_H
00021 #define Tulip_BOUNDINGBOX_H
00022 
00023 #include <tulip/Vector.h>
00024 #include <tulip/tulipconf.h>
00025 
00026 namespace tlp {
00027 /**
00028  * \ingroup Structures
00029  * \brief This class represents the 3D bounding box of an object.
00030  * It is mostly used to determine whether or not two object are in a state of collision.
00031  *
00032  * It is defined by two 3d points, the first one (A) being the lowest point, the second (B) being the highest.
00033  * As a bounding box is a mathematical entity describing the lowest and highest points, whether these points are in the top-left corner or
00034  * lower-right corner depends on the axes we use.
00035  * Below is a crude ASCII-art description of the axes we use in our 3D world and the points where the min and max are thus positioned.
00036  * Through the rest of this class's documentation, it will be assumed that this is the convention.
00037  *
00038  *
00039  * @verbatim
00040       y
00041      |
00042      |
00043      |_____ x
00044     /
00045    /
00046   z
00047 
00048      _________ B
00049     /        /|
00050    /        / |
00051   /________/  |
00052   |        |  |
00053   |        |  |
00054   |        | /
00055   |________|/
00056   A
00057 
00058   @endverbatim
00059  *
00060  *
00061  * Author : <a href="www.tulip-software.org">Tulip team</a>
00062  */
00063 struct TLP_SCOPE BoundingBox : public Array<Vec3f, 2> {
00064 
00065 
00066   /**
00067   * @brief Creates an invalid boundig box.
00068   * The minimum is (1, 1, 1) and the maximum is (-1, -1, -1).
00069   *
00070   **/
00071   BoundingBox();
00072 
00073   /**
00074   * @brief Creates a bounding box that must be valid.
00075   * Validity is checked in debug mode by an assert.
00076   *
00077   * @param min The lower left closest point of the box.
00078   * @param max The higher right most farther point of the box.
00079   **/
00080   BoundingBox(const tlp::Vec3f& min, const tlp::Vec3f& max);
00081 
00082   /**
00083   * @brief Returns the geometrical center of the bounding box.
00084   * An assertion is raised in debug mode if the BoundingBox is not valid.
00085   *
00086   * @return The center of the bounding box :Vec3f
00087   **/
00088   Vec3f center() const;
00089 
00090   /**
00091   * @brief Returns the width of the bounding box
00092   * An assertion is raised in debug mode if the BoundingBox is not valid.
00093   *
00094   **/
00095   float width() const;
00096 
00097   /**
00098   * @brief Returns the height of the bounding box
00099   * An assertion is raised in debug mode if the bounding box is not valid.
00100   *
00101   **/
00102   float height() const;
00103 
00104   /**
00105   * @brief Returns the depth of the bounding box
00106   * An assertion is raised in debug mode if the bounding box is not valid.
00107   *
00108   **/
00109   float depth() const;
00110 
00111 
00112   /**
00113   * @brief Expands the bounding box to one containing the vector passed as parameter.
00114   * If the parameter is inside the bounding box, it remains unchanged.
00115   *
00116   * @param coord A point in the 3D space we want the bounding box to encompass.
00117   * @return void
00118   **/
00119   void expand(const tlp::Vec3f& coord);
00120 
00121   /**
00122   * @brief Translates the bounding box by the displacement given by the vector passed as parameter.
00123   *
00124   * @param vec The displacement vector in 3D space to translate this bounding box by.
00125   * @return void
00126   **/
00127   void translate(const tlp::Vec3f& vec);
00128 
00129   /**
00130   * @brief Scales the bounding box, i.e. multiplying its components by a vector passed as parameter.
00131   *
00132   * @param factor The factor vector to scale this bounding box by.
00133   * @return void
00134   **/
00135   void scale(const tlp::Vec3f& factor);
00136 
00137   /**
00138   * @brief Checks whether the bounding box's lowest point is less than it's highest point.
00139   * "Less Than" means axis-by-axis comparison, i.e. x1 < x2 && y1 < y2 && z1 < z2.
00140   *
00141   * @return bool Whether this bounding box is valid.
00142   **/
00143   bool isValid() const;
00144 
00145   /**
00146   * @brief Checks if the given vector is inside the current bounding box. If the bounding box is invalid the result is always false.
00147   * @param coord A point in the 3D space.
00148   * @return bool Wether coord is in the bounding box.
00149   **/
00150   bool contains(const tlp::Vec3f& coord) const;
00151 
00152   /**
00153   * @brief Checks if the given bounding box is inside the current bounding box. If one of the bounding boxes is invalid the result is always false.
00154   * @param boundingBox The bounding box to test inclusion
00155   * @return bool Wether boundingBox is in the bounding box.
00156   **/
00157   bool contains(const tlp::BoundingBox& boundingBox) const;
00158 
00159   /**
00160   * @brief Checks if the given bounding box intersect the current one. If one of the bounding box is invalid return false.
00161   * @param boundingBox The bounding box to compare with.
00162   * @return bool Wether the bounding boxes intersect.
00163   **/
00164   bool intersect(const tlp::BoundingBox& boundingBox) const;
00165 
00166   /**
00167   * @brief Checks if the bounding box intersects a given line segment. If the bounding box is invalid the result is always false.
00168   * @param segStart the start point of the line segment on which to check intersection
00169   * @param segEnd the end point of the line segment on which to check intersection
00170   * @return bool Wether the line segment intersects the bounding box
00171   **/
00172   bool intersect(const Vec3f& segStart, const Vec3f& segEnd) const;
00173 
00174 
00175   /**
00176   * @brief The vector passed as parameter is modified to contain the 8 points of the bounding box.
00177   * The points are, in order :
00178   * 0: lower leftmost closest point (the bounding box's minimum)
00179   * 1: lower rightmost closest point
00180   * 2: highest rightmost closest point
00181   * 3: highest leftmost closest point
00182   * 4: lower rightmost farthest point
00183   * 5: lower rightmost farthest point
00184   * 6: highest rightmost farthest point
00185   * 7: highest leftmost farthest point
00186   *
00187   * Crude ASCII art again, sorry for your eyes.
00188   *
00189   * @verbatim
00190 
00191      6_________ 7
00192      /|       /|
00193     / |      / |
00194   3/__|_____/2 |
00195    |  |_____|__|
00196    |  /4    |  /5
00197    | /      | /
00198    |/_______|/
00199    0        1
00200 
00201    @endverbatim
00202   *
00203   * @param bb A vector in which to put the points of the bounding box.
00204   * @return void
00205   **/
00206   void getCompleteBB(Vec3f bb[8]) const;
00207 };
00208 
00209 }
00210 
00211 #endif // Tulip_BOUNDINGBOX_H
 All Classes Files Functions Variables Enumerations Enumerator Properties