Loading...
Searching...
No Matches
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"
32#include "pxr/base/gf/range3d.h"
33#include "pxr/base/gf/api.h"
34
35#include <iosfwd>
36
37PXR_NAMESPACE_OPEN_SCOPE
38
84class GfBBox3d {
85
86 public:
87
92 _matrix.SetIdentity();
93 _inverse.SetIdentity();
94 _isDegenerate = false;
95 _hasZeroAreaPrimitives = false;
96 }
97
99 GfBBox3d(const GfRange3d &box) :
100 _box(box) {
101 _matrix.SetIdentity();
102 _inverse.SetIdentity();
103 _isDegenerate = false;
104 _hasZeroAreaPrimitives = false;
105 }
106
108 GfBBox3d(const GfRange3d &box, const GfMatrix4d &matrix) {
109 Set(box, matrix);
110 _hasZeroAreaPrimitives = false;
111 }
112
114 void Set(const GfRange3d &box, const GfMatrix4d &matrix) {
115 _box = box;
116 _SetMatrices(matrix);
117 }
118
121 void SetMatrix(const GfMatrix4d& matrix) {
122 _SetMatrices(matrix);
123 }
124
127 void SetRange(const GfRange3d& box) {
128 _box = box;
129 }
130
132 const GfRange3d & GetRange() const {
133 return _box;
134 }
135
138 const GfRange3d & GetBox() const {
139 return GetRange();
140 }
141
143 const GfMatrix4d & GetMatrix() const {
144 return _matrix;
145 }
146
149 const GfMatrix4d & GetInverseMatrix() const {
150 return _inverse;
151 }
152
155 void SetHasZeroAreaPrimitives(bool hasThem) {
156 _hasZeroAreaPrimitives = hasThem;
157 }
158
162 return _hasZeroAreaPrimitives;
163 }
164
166 GF_API
167 double GetVolume() const;
168
172 void Transform(const GfMatrix4d &matrix) {
173 _SetMatrices(_matrix * matrix);
174 }
175
179 GF_API
181
187 return ComputeAlignedRange();
188 }
189
194 GF_API
195 static GfBBox3d Combine(const GfBBox3d &b1, const GfBBox3d &b2);
196
199 GF_API
201
203 friend inline size_t hash_value(const GfBBox3d &b) {
204 return TfHash::Combine(
205 b._box,
206 b._matrix
207 );
208 }
209
214 bool operator ==(const GfBBox3d &b) const {
215 return (_box == b._box &&
216 _matrix == b._matrix);
217 }
218
223 bool operator !=(const GfBBox3d &that) const {
224 return !(*this == that);
225 }
226
227 private:
229 GfRange3d _box;
231 GfMatrix4d _matrix;
233 GfMatrix4d _inverse;
235 bool _isDegenerate;
237 bool _hasZeroAreaPrimitives;
238
241 GF_API
242 void _SetMatrices(const GfMatrix4d &matrix);
243
247 static GfBBox3d _CombineInOrder(const GfBBox3d &b1, const GfBBox3d &b2);
248};
249
256GF_API std::ostream& operator<<(std::ostream&, const GfBBox3d&);
257
258PXR_NAMESPACE_CLOSE_SCOPE
259
260#endif // PXR_BASE_GF_BBOX3D_H
Basic type: arbitrarily oriented 3D bounding box.
Definition: bbox3d.h:84
void SetHasZeroAreaPrimitives(bool hasThem)
Sets the zero-area primitives flag to the given value.
Definition: bbox3d.h:155
bool HasZeroAreaPrimitives() const
Returns the current state of the zero-areaprimitives flag".
Definition: bbox3d.h:161
GfBBox3d(const GfRange3d &box, const GfMatrix4d &matrix)
This constructor takes a box and a transformation matrix.
Definition: bbox3d.h:108
void SetMatrix(const GfMatrix4d &matrix)
Sets the transformation matrix only.
Definition: bbox3d.h:121
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:172
GF_API double GetVolume() const
Returns the volume of the box (0 for an empty box).
const GfMatrix4d & GetMatrix() const
Returns the transformation matrix.
Definition: bbox3d.h:143
void Set(const GfRange3d &box, const GfMatrix4d &matrix)
Sets the axis-aligned box and transformation matrix.
Definition: bbox3d.h:114
const GfRange3d & GetBox() const
Returns the range of the axis-aligned untransformed box.
Definition: bbox3d.h:138
GF_API GfVec3d ComputeCentroid() const
Returns the centroid of the bounding box.
GfBBox3d()
The default constructor leaves the box empty, the transformation matrix identity, and the zero-areapr...
Definition: bbox3d.h:91
const GfRange3d & GetRange() const
Returns the range of the axis-aligned untransformed box.
Definition: bbox3d.h:132
void SetRange(const GfRange3d &box)
Sets the range of the axis-aligned box only.
Definition: bbox3d.h:127
bool operator!=(const GfBBox3d &that) const
Component-wise inequality test.
Definition: bbox3d.h:223
GfRange3d ComputeAlignedBox() const
Returns the axis-aligned range (as a GfRange3d) that results from applying the transformation matrix ...
Definition: bbox3d.h:186
const GfMatrix4d & GetInverseMatrix() const
Returns the inverse of the transformation matrix.
Definition: bbox3d.h:149
friend size_t hash_value(const GfBBox3d &b)
Hash.
Definition: bbox3d.h:203
static GF_API GfBBox3d Combine(const GfBBox3d &b1, const GfBBox3d &b2)
Combines two bboxes, returning a new bbox that contains both.
GF_API GfRange3d ComputeAlignedRange() const
Returns the axis-aligned range (as a GfRange3d) that results from applying the transformation matrix ...
GfBBox3d(const GfRange3d &box)
This constructor takes a box and sets the matrix to identity.
Definition: bbox3d.h:99
bool operator==(const GfBBox3d &b) const
Component-wise equality test.
Definition: bbox3d.h:214
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
GfMatrix4d & SetIdentity()
Sets the matrix to the identity matrix.
Definition: matrix4d.h:249
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
Basic type for a vector of 3 double components.
Definition: vec3d.h:63
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:492
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].