All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
bbox3d.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_GF_BBOX3D_H
8#define PXR_BASE_GF_BBOX3D_H
9
12
13#include "pxr/pxr.h"
15#include "pxr/base/gf/range3d.h"
16#include "pxr/base/gf/api.h"
17
18#include <iosfwd>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
67class GfBBox3d {
68
69 public:
70
75 _matrix.SetIdentity();
76 _inverse.SetIdentity();
77 _isDegenerate = false;
78 _hasZeroAreaPrimitives = false;
79 }
80
82 GfBBox3d(const GfRange3d &box) :
83 _box(box) {
84 _matrix.SetIdentity();
85 _inverse.SetIdentity();
86 _isDegenerate = false;
87 _hasZeroAreaPrimitives = false;
88 }
89
91 GfBBox3d(const GfRange3d &box, const GfMatrix4d &matrix) {
92 Set(box, matrix);
93 _hasZeroAreaPrimitives = false;
94 }
95
97 void Set(const GfRange3d &box, const GfMatrix4d &matrix) {
98 _box = box;
99 _SetMatrices(matrix);
100 }
101
104 void SetMatrix(const GfMatrix4d& matrix) {
105 _SetMatrices(matrix);
106 }
107
110 void SetRange(const GfRange3d& box) {
111 _box = box;
112 }
113
115 const GfRange3d & GetRange() const {
116 return _box;
117 }
118
121 const GfRange3d & GetBox() const {
122 return GetRange();
123 }
124
126 const GfMatrix4d & GetMatrix() const {
127 return _matrix;
128 }
129
132 const GfMatrix4d & GetInverseMatrix() const {
133 return _inverse;
134 }
135
138 void SetHasZeroAreaPrimitives(bool hasThem) {
139 _hasZeroAreaPrimitives = hasThem;
140 }
141
145 return _hasZeroAreaPrimitives;
146 }
147
149 GF_API
150 double GetVolume() const;
151
155 void Transform(const GfMatrix4d &matrix) {
156 _SetMatrices(_matrix * matrix);
157 }
158
162 GF_API
164
170 return ComputeAlignedRange();
171 }
172
177 GF_API
178 static GfBBox3d Combine(const GfBBox3d &b1, const GfBBox3d &b2);
179
182 GF_API
184
186 friend inline size_t hash_value(const GfBBox3d &b) {
187 return TfHash::Combine(
188 b._box,
189 b._matrix
190 );
191 }
192
197 bool operator ==(const GfBBox3d &b) const {
198 return (_box == b._box &&
199 _matrix == b._matrix);
200 }
201
206 bool operator !=(const GfBBox3d &that) const {
207 return !(*this == that);
208 }
209
210 private:
212 GfRange3d _box;
214 GfMatrix4d _matrix;
216 GfMatrix4d _inverse;
218 bool _isDegenerate;
220 bool _hasZeroAreaPrimitives;
221
224 GF_API
225 void _SetMatrices(const GfMatrix4d &matrix);
226
230 static GfBBox3d _CombineInOrder(const GfBBox3d &b1, const GfBBox3d &b2);
231};
232
239GF_API std::ostream& operator<<(std::ostream&, const GfBBox3d&);
240
241PXR_NAMESPACE_CLOSE_SCOPE
242
243#endif // PXR_BASE_GF_BBOX3D_H
Basic type: arbitrarily oriented 3D bounding box.
Definition: bbox3d.h:67
void SetHasZeroAreaPrimitives(bool hasThem)
Sets the zero-area primitives flag to the given value.
Definition: bbox3d.h:138
bool HasZeroAreaPrimitives() const
Returns the current state of the zero-areaprimitives flag".
Definition: bbox3d.h:144
GfBBox3d(const GfRange3d &box, const GfMatrix4d &matrix)
This constructor takes a box and a transformation matrix.
Definition: bbox3d.h:91
void SetMatrix(const GfMatrix4d &matrix)
Sets the transformation matrix only.
Definition: bbox3d.h:104
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:155
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:126
void Set(const GfRange3d &box, const GfMatrix4d &matrix)
Sets the axis-aligned box and transformation matrix.
Definition: bbox3d.h:97
const GfRange3d & GetBox() const
Returns the range of the axis-aligned untransformed box.
Definition: bbox3d.h:121
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:74
const GfRange3d & GetRange() const
Returns the range of the axis-aligned untransformed box.
Definition: bbox3d.h:115
void SetRange(const GfRange3d &box)
Sets the range of the axis-aligned box only.
Definition: bbox3d.h:110
bool operator!=(const GfBBox3d &that) const
Component-wise inequality test.
Definition: bbox3d.h:206
GfRange3d ComputeAlignedBox() const
Returns the axis-aligned range (as a GfRange3d) that results from applying the transformation matrix ...
Definition: bbox3d.h:169
const GfMatrix4d & GetInverseMatrix() const
Returns the inverse of the transformation matrix.
Definition: bbox3d.h:132
friend size_t hash_value(const GfBBox3d &b)
Hash.
Definition: bbox3d.h:186
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:82
bool operator==(const GfBBox3d &b) const
Component-wise equality test.
Definition: bbox3d.h:197
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
GfMatrix4d & SetIdentity()
Sets the matrix to the identity matrix.
Definition: matrix4d.h:232
Basic type: 3-dimensional floating point range.
Definition: range3d.h:47
Basic type for a vector of 3 double components.
Definition: vec3d.h:46
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:475
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].