All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bbox3d.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_BASE_GF_BBOX3D_H
25 #define PXR_BASE_GF_BBOX3D_H
26 
29 
30 #include "pxr/pxr.h"
31 #include "pxr/base/gf/matrix4d.h"
32 #include "pxr/base/gf/range3d.h"
33 #include "pxr/base/gf/api.h"
34 
35 #include <iosfwd>
36 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
84 class GfBBox3d {
85 
86  public:
87 
92  _matrix.SetIdentity();
93  _inverse.SetIdentity();
94  _isDegenerate = false;
95  _hasZeroAreaPrimitives = false;
96  }
97 
99  GfBBox3d(const GfBBox3d& rhs) :
100  _box(rhs._box) {
101  _matrix = rhs._matrix;
102  _inverse = rhs._inverse;
103  _isDegenerate = rhs._isDegenerate;
104  _hasZeroAreaPrimitives = rhs._hasZeroAreaPrimitives;
105  }
106 
108  GfBBox3d(const GfRange3d &box) :
109  _box(box) {
110  _matrix.SetIdentity();
111  _inverse.SetIdentity();
112  _isDegenerate = false;
113  _hasZeroAreaPrimitives = false;
114  }
115 
117  GfBBox3d(const GfRange3d &box, const GfMatrix4d &matrix) {
118  Set(box, matrix);
119  _hasZeroAreaPrimitives = false;
120  }
121 
123  void Set(const GfRange3d &box, const GfMatrix4d &matrix) {
124  _box = box;
125  _SetMatrices(matrix);
126  }
127 
130  void SetMatrix(const GfMatrix4d& matrix) {
131  _SetMatrices(matrix);
132  }
133 
136  void SetRange(const GfRange3d& box) {
137  _box = box;
138  }
139 
141  const GfRange3d & GetRange() const {
142  return _box;
143  }
144 
147  const GfRange3d & GetBox() const {
148  return GetRange();
149  }
150 
152  const GfMatrix4d & GetMatrix() const {
153  return _matrix;
154  }
155 
158  const GfMatrix4d & GetInverseMatrix() const {
159  return _inverse;
160  }
161 
164  void SetHasZeroAreaPrimitives(bool hasThem) {
165  _hasZeroAreaPrimitives = hasThem;
166  }
167 
170  bool HasZeroAreaPrimitives() const {
171  return _hasZeroAreaPrimitives;
172  }
173 
175  GF_API
176  double GetVolume() const;
177 
181  void Transform(const GfMatrix4d &matrix) {
182  _SetMatrices(_matrix * matrix);
183  }
184 
188  GF_API
190 
196  return ComputeAlignedRange();
197  }
198 
203  GF_API
204  static GfBBox3d Combine(const GfBBox3d &b1, const GfBBox3d &b2);
205 
208  GF_API
209  GfVec3d ComputeCentroid() const;
210 
212  friend inline size_t hash_value(const GfBBox3d &b) {
213  size_t h = 0;
214  boost::hash_combine(h, b._box);
215  boost::hash_combine(h, b._matrix);
216  return h;
217  }
218 
223  bool operator ==(const GfBBox3d &b) const {
224  return (_box == b._box &&
225  _matrix == b._matrix);
226  }
227 
232  bool operator !=(const GfBBox3d &that) const {
233  return !(*this == that);
234  }
235 
236  private:
238  GfRange3d _box;
240  GfMatrix4d _matrix;
242  GfMatrix4d _inverse;
244  bool _isDegenerate;
246  bool _hasZeroAreaPrimitives;
247 
250  GF_API
251  void _SetMatrices(const GfMatrix4d &matrix);
252 
256  static GfBBox3d _CombineInOrder(const GfBBox3d &b1, const GfBBox3d &b2);
257 };
258 
265 GF_API std::ostream& operator<<(std::ostream&, const GfBBox3d&);
266 
267 PXR_NAMESPACE_CLOSE_SCOPE
268 
269 #endif // PXR_BASE_GF_BBOX3D_H
GF_API double GetVolume() const
Returns the volume of the box (0 for an empty box).
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
const GfMatrix4d & GetInverseMatrix() const
Returns the inverse of the transformation matrix.
Definition: bbox3d.h:158
friend size_t hash_value(const GfBBox3d &b)
Hash.
Definition: bbox3d.h:212
void Set(const GfRange3d &box, const GfMatrix4d &matrix)
Sets the axis-aligned box and transformation matrix.
Definition: bbox3d.h:123
bool HasZeroAreaPrimitives() const
Returns the current state of the zero-areaprimitives flag".
Definition: bbox3d.h:170
bool operator!=(const GfBBox3d &that) const
Component-wise inequality test.
Definition: bbox3d.h:232
GfRange3d ComputeAlignedBox() const
Returns the axis-aligned range (as a GfRange3d) that results from applying the transformation matrix ...
Definition: bbox3d.h:195
const GfRange3d & GetRange() const
Returns the range of the axis-aligned untransformed box.
Definition: bbox3d.h:141
GF_API GfRange3d ComputeAlignedRange() const
Returns the axis-aligned range (as a GfRange3d) that results from applying the transformation matrix ...
GfBBox3d(const GfBBox3d &rhs)
Copy constructor.
Definition: bbox3d.h:99
const GfMatrix4d & GetMatrix() const
Returns the transformation matrix.
Definition: bbox3d.h:152
GF_API GfVec3d ComputeCentroid() const
Returns the centroid of the bounding box.
void SetHasZeroAreaPrimitives(bool hasThem)
Sets the zero-area primitives flag to the given value.
Definition: bbox3d.h:164
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
GfBBox3d()
The default constructor leaves the box empty, the transformation matrix identity, and the zero-areapr...
Definition: bbox3d.h:91
GfMatrix4d & SetIdentity()
Sets the matrix to the identity matrix.
Definition: matrix4d.h:250
void SetRange(const GfRange3d &box)
Sets the range of the axis-aligned box only.
Definition: bbox3d.h:136
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
GfBBox3d(const GfRange3d &box, const GfMatrix4d &matrix)
This constructor takes a box and a transformation matrix.
Definition: bbox3d.h:117
bool operator==(const GfBBox3d &b) const
Component-wise equality test.
Definition: bbox3d.h:223
Basic type for a vector of 3 double components.
Definition: vec3d.h:63
void SetMatrix(const GfMatrix4d &matrix)
Sets the transformation matrix only.
Definition: bbox3d.h:130
void Transform(const GfMatrix4d &matrix)
Transforms the bounding box by the given matrix, which is assumed to be a global transformation to ap...
Definition: bbox3d.h:181
const GfRange3d & GetBox() const
Returns the range of the axis-aligned untransformed box.
Definition: bbox3d.h:147
GfBBox3d(const GfRange3d &box)
This constructor takes a box and sets the matrix to identity.
Definition: bbox3d.h:108
Basic type: arbitrarily oriented 3D bounding box.
Definition: bbox3d.h:84
static GF_API GfBBox3d Combine(const GfBBox3d &b1, const GfBBox3d &b2)
Combines two bboxes, returning a new bbox that contains both.