[4] | 1 | /************************************************************** ggt-head beg |
---|
| 2 | * |
---|
| 3 | * GGT: Generic Graphics Toolkit |
---|
| 4 | * |
---|
| 5 | * Original Authors: |
---|
| 6 | * Allen Bierbaum |
---|
| 7 | * |
---|
| 8 | * ----------------------------------------------------------------- |
---|
| 9 | * File: AABox.h,v |
---|
| 10 | * Date modified: 2004/11/22 15:04:05 |
---|
| 11 | * Version: 1.12 |
---|
| 12 | * ----------------------------------------------------------------- |
---|
| 13 | * |
---|
| 14 | *********************************************************** ggt-head end */ |
---|
| 15 | /*************************************************************** ggt-cpr beg |
---|
| 16 | * |
---|
| 17 | * GGT: The Generic Graphics Toolkit |
---|
| 18 | * Copyright (C) 2001,2002 Allen Bierbaum |
---|
| 19 | * |
---|
| 20 | * This library is free software; you can redistribute it and/or |
---|
| 21 | * modify it under the terms of the GNU Lesser General Public |
---|
| 22 | * License as published by the Free Software Foundation; either |
---|
| 23 | * version 2.1 of the License, or (at your option) any later version. |
---|
| 24 | * |
---|
| 25 | * This library is distributed in the hope that it will be useful, |
---|
| 26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 28 | * Lesser General Public License for more details. |
---|
| 29 | * |
---|
| 30 | * You should have received a copy of the GNU Lesser General Public |
---|
| 31 | * License along with this library; if not, write to the Free Software |
---|
| 32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 33 | * |
---|
| 34 | ************************************************************ ggt-cpr end */ |
---|
| 35 | #ifndef _GMTL_AABOX_H_ |
---|
| 36 | #define _GMTL_AABOX_H_ |
---|
| 37 | |
---|
| 38 | #include <gmtl/Point.h> |
---|
| 39 | |
---|
| 40 | namespace gmtl |
---|
| 41 | { |
---|
| 42 | /** |
---|
| 43 | * Describes an axially aligned box in 3D space. This is usually used for |
---|
| 44 | * graphics applications. It is defined by its minimum and maximum points. |
---|
| 45 | * |
---|
| 46 | * @param DATA_TYPE the internal type used for the points |
---|
| 47 | * |
---|
| 48 | * @ingroup Types |
---|
| 49 | */ |
---|
| 50 | template< class DATA_TYPE > |
---|
| 51 | class AABox |
---|
| 52 | { |
---|
| 53 | // This is a hack to work around a bug with GCC 3.3 on Mac OS X |
---|
| 54 | // where boost::is_polymorphic returns a false positive. The details |
---|
| 55 | // can be found in the Boost.Python FAQ: |
---|
| 56 | // http://www.boost.org/libs/python/doc/v2/faq.html#macosx |
---|
| 57 | #if defined(__MACH__) && defined(__APPLE_CC__) && defined(__GNUC__) && \ |
---|
| 58 | __GNUC__ == 3 && __GNUC_MINOR__ == 3 |
---|
| 59 | bool dummy_; |
---|
| 60 | #endif |
---|
| 61 | public: |
---|
| 62 | typedef DATA_TYPE DataType; |
---|
| 63 | |
---|
| 64 | public: |
---|
| 65 | /** |
---|
| 66 | * Creates a new empty box. |
---|
| 67 | */ |
---|
| 68 | AABox() |
---|
| 69 | : mMin(0,0,0), mMax(0,0,0), mEmpty(true) |
---|
| 70 | {} |
---|
| 71 | |
---|
| 72 | /** |
---|
| 73 | * Creates a new box with the given min and max points. |
---|
| 74 | * |
---|
| 75 | * @param min the minimum point on the box |
---|
| 76 | * @param max the maximum point on the box |
---|
| 77 | * |
---|
| 78 | * @pre all elements of min are less than max |
---|
| 79 | * @pre bot min and max are not zero |
---|
| 80 | */ |
---|
| 81 | AABox(const Point<DATA_TYPE, 3>& min, const Point<DATA_TYPE, 3>& max) |
---|
| 82 | : mMin(min), mMax(max), mEmpty(false) |
---|
| 83 | {} |
---|
| 84 | |
---|
| 85 | /** |
---|
| 86 | * Construcst a duplicate of the given box. |
---|
| 87 | * |
---|
| 88 | * @param box the box the make a copy of |
---|
| 89 | */ |
---|
| 90 | AABox(const AABox<DATA_TYPE>& box) |
---|
| 91 | : mMin(box.mMin), mMax(box.mMax), mEmpty(box.mEmpty) |
---|
| 92 | {} |
---|
| 93 | |
---|
| 94 | /** |
---|
| 95 | * Gets the minimum point of the box. |
---|
| 96 | * |
---|
| 97 | * @return the min point |
---|
| 98 | */ |
---|
| 99 | const Point<DATA_TYPE, 3>& getMin() const |
---|
| 100 | { |
---|
| 101 | return mMin; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | /** |
---|
| 105 | * Gets the maximum point of the box. |
---|
| 106 | * |
---|
| 107 | * @return the max point |
---|
| 108 | */ |
---|
| 109 | const Point<DATA_TYPE, 3>& getMax() const |
---|
| 110 | { |
---|
| 111 | return mMax; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | /** |
---|
| 115 | * Tests if this box occupies no space. |
---|
| 116 | * |
---|
| 117 | * @return true if the box is empty, false otherwise |
---|
| 118 | */ |
---|
| 119 | bool isEmpty() const |
---|
| 120 | { |
---|
| 121 | return mEmpty; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | /** |
---|
| 125 | * Sets the minimum point of the box. |
---|
| 126 | * |
---|
| 127 | * @param min the min point |
---|
| 128 | */ |
---|
| 129 | void setMin(const Point<DATA_TYPE, 3>& min) |
---|
| 130 | { |
---|
| 131 | mMin = min; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | /** |
---|
| 135 | * Sets the maximum point of the box. |
---|
| 136 | * |
---|
| 137 | * @param max the max point |
---|
| 138 | */ |
---|
| 139 | void setMax(const Point<DATA_TYPE, 3>& max) |
---|
| 140 | { |
---|
| 141 | mMax = max; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | /** |
---|
| 145 | * Sets the empty flag on this box. |
---|
| 146 | * |
---|
| 147 | * @param empty true to make the box empty, false otherwise |
---|
| 148 | */ |
---|
| 149 | void setEmpty(bool empty) |
---|
| 150 | { |
---|
| 151 | mEmpty = empty; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | public: |
---|
| 155 | /** |
---|
| 156 | * The minimum point of the box. |
---|
| 157 | */ |
---|
| 158 | Point<DATA_TYPE, 3> mMin; |
---|
| 159 | |
---|
| 160 | /** |
---|
| 161 | * The maximum point on the box. |
---|
| 162 | */ |
---|
| 163 | Point<DATA_TYPE, 3> mMax; |
---|
| 164 | |
---|
| 165 | /** |
---|
| 166 | * Flag for empty box. True if the box is empty. |
---|
| 167 | */ |
---|
| 168 | bool mEmpty; |
---|
| 169 | }; |
---|
| 170 | |
---|
| 171 | // --- helper types --- // |
---|
| 172 | typedef AABox<float> AABoxf; |
---|
| 173 | typedef AABox<double> AABoxd; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | #endif |
---|