Open Inventor Reference
SbBoxd.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37
38/*
39 * Copyright (C) 1990,91 Silicon Graphics, Inc.
40 *
41 _______________________________________________________________________
42 ______________ S I L I C O N G R A P H I C S I N C . ____________
43 |
44 | $Revision: 1.1.1.1 $
45 |
46 | Description:
47 | This file contains definitions of SbBoxes, 2D/3D boxes. A
48 | box has planes parallel to the major axes and can therefore
49 | be specified by two points on a diagonal. The points with minimum
50 | and maximum x, y, and z coordinates are used.
51 |
52 | Author(s) : originally by Paul S. Strauss, Nick Thompson, David Mott
53 | adapted for double values by Wolf Spindler
54 |
55 ______________ S I L I C O N G R A P H I C S I N C . ____________
56 _______________________________________________________________________
57 */
58
59#ifndef _SB_BOXD_
60#define _SB_BOXD_
61
63#include <Inventor/SbBasic.h>
64#include <Inventor/SbLineard.h>
65
68
81
83 public:
84
86 SbBox3d() { makeEmpty(); }
87
89 SbBox3d(double xmin, double ymin, double zmin,
90 double xmax, double ymax, double zmax)
91 { min.setValue(xmin, ymin, zmin); max.setValue(xmax, ymax, zmax); }
92
95 SbBox3d(const SbVec3d &min, const SbVec3d &max)
96 { this->min = min; this->max = max; }
97
100
103 const SbVec3d & getMin() const { return min; }
106 const SbVec3d & getMax() const { return max; }
109 SbVec3d & getMin() { return min; }
112 SbVec3d & getMax() { return max; }
113
116
118 void extendBy(const SbVec3d &pt);
119
121 void extendBy(const SbBox3d &bb);
122
124 bool intersect(const SbVec3d &pt) const;
125
127 bool intersect(const SbBox3d &bb) const;
128
140 bool outside(const SbMatrixd &MVP, int &cullBits) const;
141
143 void setBounds(double xmin, double ymin, double zmin,
144 double xmax, double ymax, double zmax)
145 { min.setValue(xmin, ymin, zmin); max.setValue(xmax, ymax, zmax); }
146
147 void setBounds(const SbVec3d &_min, const SbVec3d &_max)
148 { min = _min; max = _max; }
149
150 void getBounds(double &xmin, double &ymin, double &zmin,
151 double &xmax, double &ymax, double &zmax) const
152 { min.getValue(xmin, ymin, zmin); max.getValue(xmax, ymax, zmax); }
153
154 void getBounds(SbVec3d &_min, SbVec3d &_max) const
155 { _min = min; _max = max; }
156
160
162 void getOrigin(double &originX,
163 double &originY,
164 double &originZ) const
165 { originX = min[0]; originY = min[1]; originZ = min[2]; }
166
168 void getSize(double &sizeX, double &sizeY, double &sizeZ) const
169 { sizeX = max[0] - min[0];
170 sizeY = max[1] - min[1];
171 sizeZ = max[2] - min[2]; }
172
174 void makeEmpty();
175
177 bool isEmpty() const { return max[0] < min[0]; }
178
181 bool hasVolume() const
182 { return (max[0] > min[0] && max[1] > min[1] && max[2] > min[2] ); }
183
189 void getSpan(const SbVec3d &direction,
190 double &dMin, double &dMax) const;
191
193 void transform(const SbMatrixd &m);
194
196 double getVolume() const;
197
199 friend INVENTOR_API bool operator ==(const SbBox3d &b1, const SbBox3d &b2);
200 friend INVENTOR_API bool operator !=(const SbBox3d &b1, const SbBox3d &b2);
201
202 private:
204 SbVec3d min, max;
205};
206
207INVENTOR_API bool operator ==(const SbBox3d &b1, const SbBox3d &b2);
208inline INVENTOR_API bool operator !=(const SbBox3d &b1, const SbBox3d &b2)
209{ return !(b1 == b2); }
210
213
228
230 public:
231
234
236 SbXfBox3d(const SbVec3d &_min, const SbVec3d &_max);
237
239 SbXfBox3d(const SbBox3d &box);
240
243
245 void setTransform(const SbMatrixd &m);
246
248 const SbMatrixd & getTransform() const { return xform; }
250 const SbMatrixd & getInverse() const { return xformInv; }
251
254
267 void extendBy(const SbVec3d &pt);
268
273 void extendBy(const SbBox3d &bb)
274 { extendBy(SbXfBox3d(bb)); }
275
277 void extendBy(const SbXfBox3d &bb);
278
280 bool intersect(const SbVec3d &pt) const;
281
283 bool intersect(const SbBox3d &bb) const
284 { return project().intersect(bb); }
285
287 void setBounds(double xmin, double ymin, double zmin,
288 double xmax, double ymax, double zmax)
289 { SbBox3d::setBounds(xmin, ymin, zmin, xmax, ymax, zmax); }
290
292 void setBounds(const SbVec3d &_min, const SbVec3d &_max)
293 { SbBox3d::setBounds(_min, _max); }
294
295 void getBounds(double &xmin, double &ymin, double &zmin,
296 double &xmax, double &ymax, double &zmax) const
297 { SbBox3d::getBounds(xmin, ymin, zmin, xmax, ymax, zmax); }
298
299 void getBounds(SbVec3d &_min, SbVec3d &_max) const
300 { SbBox3d::getBounds(_min, _max); }
301
303 void getOrigin(double &originX,
304 double &originY,
305 double &originZ)
306 { SbBox3d::getOrigin(originX, originY, originZ); }
307
309 void getSize(double &sizeX, double &sizeY, double &sizeZ)
310 { SbBox3d::getSize(sizeX, sizeY, sizeZ); }
311
313 double getVolume() const;
314
317
322 bool isEmpty() const { return SbBox3d::isEmpty(); }
323
326 bool hasVolume() const { return SbBox3d::hasVolume(); }
327
329 void getSpan(const SbVec3d &direction,
330 double &dMin, double &dMax) const
331 { project().getSpan(direction, dMin, dMax); }
332
334 void transform(const SbMatrixd &m);
335
338
340 friend INVENTOR_API bool operator ==(const SbXfBox3d &b1, const SbXfBox3d &b2);
341 friend INVENTOR_API bool operator !=(const SbXfBox3d &b1, const SbXfBox3d &b2);
342
343 private:
345 const SbVec3d & getMin() const { return SbBox3d::getMin(); }
346 const SbVec3d & getMax() const { return SbBox3d::getMax(); }
347
349 SbMatrixd xform;
350 SbMatrixd xformInv;
351};
352
353INVENTOR_API bool operator ==(const SbXfBox3d &b1, const SbXfBox3d &b2);
354inline INVENTOR_API bool operator !=(const SbXfBox3d &b1, const SbXfBox3d &b2)
355{ return !(b1 == b2); }
356
359
372
374 public:
375
377 SbBox2d() { makeEmpty(); };
378
380 SbBox2d(double xmin, double ymin, double xmax, double ymax)
381 { min.setValue(xmin, ymin); max.setValue(xmax, ymax); }
382
384 SbBox2d(const SbVec2d &_min, const SbVec2d &_max)
385 { min = _min; max = _max; }
386
389
391 const SbVec2d & getMin() const { return min; }
393 const SbVec2d & getMax() const { return max; }
394
397
399 void extendBy(const SbVec2d &pt);
400
402 void extendBy(const SbBox2d &r);
403
405 bool intersect(const SbVec2d &pt) const;
406
408 bool intersect(const SbBox2d &bb) const;
409
411 void setBounds(double xmin, double ymin, double xmax, double ymax)
412 { min.setValue(xmin, ymin); max.setValue(xmax, ymax); }
413
414 void setBounds(const SbVec2d &_min, const SbVec2d &_max)
415 { min = _min; max = _max; }
416
417 void getBounds(double &xmin, double &ymin,
418 double &xmax, double &ymax) const
419 { min.getValue(xmin, ymin); max.getValue(xmax, ymax); }
420
421 void getBounds(SbVec2d &_min, SbVec2d &_max) const
422 { _min = min; _max = max; }
423
427
429 void getOrigin(double &originX, double &originY) const
430 { originX = min[0]; originY = min[1]; }
431
433 void getSize(double &sizeX, double &sizeY) const
434 { sizeX = max[0] - min[0]; sizeY = max[1] - min[1]; }
435
437 double getAspectRatio() const
438 { return (max[0] - min[0]) / (max[1] - min[1]); }
439
441 void makeEmpty();
442
444 bool isEmpty() const { return max[0] < min[0]; }
445
448 bool hasArea() const
449 { return (max[0] > min[0] && max[1] > min[1]); }
450
452 friend INVENTOR_API bool operator ==(const SbBox2d &b1, const SbBox2d &b2);
453 friend INVENTOR_API bool operator !=(const SbBox2d &b1, const SbBox2d &b2);
454
455 private:
457 SbVec2d min, max;
458};
459
460INVENTOR_API bool operator ==(const SbBox2d &b1, const SbBox2d &b2);
461inline INVENTOR_API bool operator !=(const SbBox2d &b1, const SbBox2d &b2)
462{ return !(b1 == b2); }
463
464
465#endif /* _SB_BOXD_ */
INVENTOR_API bool operator!=(const SbBox3f &b1, const SbBox3f &b2)
Definition SbBox.h:207
INVENTOR_API bool operator==(const SbBox3f &b1, const SbBox3f &b2)
INVENTOR_API bool operator==(const SbBox3d &b1, const SbBox3d &b2)
INVENTOR_API bool operator!=(const SbBox3d &b1, const SbBox3d &b2)
Definition SbBoxd.h:208
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition SbSystem.h:77
2D box class.
Definition SbBoxd.h:373
void setBounds(const SbVec2d &_min, const SbVec2d &_max)
Definition SbBoxd.h:414
void getBounds(SbVec2d &_min, SbVec2d &_max) const
Definition SbBoxd.h:421
bool intersect(const SbBox2d &bb) const
Returns TRUE if intersection of given Box2d and Box2d is not empty.
void setBounds(double xmin, double ymin, double xmax, double ymax)
Sets the corners of the box.
Definition SbBoxd.h:411
void extendBy(const SbVec2d &pt)
Extends Box2d (if necessary) to contain given 2D point.
bool hasArea() const
Returns TRUE if both dimensions of the box have positive size, and FALSE otherwise.
Definition SbBoxd.h:448
SbVec2d getClosestPoint(const SbVec2d &point)
Returns the closest point on the box to the given point.
void getSize(double &sizeX, double &sizeY) const
Gets box size.
Definition SbBoxd.h:433
void getBounds(double &xmin, double &ymin, double &xmax, double &ymax) const
Definition SbBoxd.h:417
void getOrigin(double &originX, double &originY) const
Gets box origin.
Definition SbBoxd.h:429
void extendBy(const SbBox2d &r)
Extends Box2d (if necessary) to contain given Box2d.
~SbBox2d()
Destructor.
Definition SbBoxd.h:388
bool intersect(const SbVec2d &pt) const
Returns TRUE if intersection of given point and Box2d is not empty.
SbVec2d getCenter() const
Returns the center of the box.
const SbVec2d & getMin() const
Returns the minimum and maximum points of the box.
Definition SbBoxd.h:391
SbBox2d(double xmin, double ymin, double xmax, double ymax)
Constructor given bounds.
Definition SbBoxd.h:380
SbBox2d(const SbVec2d &_min, const SbVec2d &_max)
Constructor given minimum and maximum points.
Definition SbBoxd.h:384
const SbVec2d & getMax() const
Returns the minimum and maximum points of the box.
Definition SbBoxd.h:393
bool isEmpty() const
Returns TRUE if the box is empty, and FALSE otherwise.
Definition SbBoxd.h:444
SbBox2d()
Constructs an empty box.
Definition SbBoxd.h:377
double getAspectRatio() const
Gets box aspect ratio.
Definition SbBoxd.h:437
void makeEmpty()
Makes an empty box.
3D box class.
Definition SbBoxd.h:82
SbBox3d(const SbVec3d &min, const SbVec3d &max)
Constructor given minimum and maximum points min and max are the corners of the diagonal that define ...
Definition SbBoxd.h:95
const SbVec3d & getMax() const
Returns the maximum point of the box.
Definition SbBoxd.h:106
void setBounds(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
Common get and set functions.
Definition SbBoxd.h:143
void makeEmpty()
Makes an empty box.
SbVec3d & getMax()
Returns the maximum point of the box.
Definition SbBoxd.h:112
~SbBox3d()
Destructor.
Definition SbBoxd.h:99
bool outside(const SbMatrixd &MVP, int &cullBits) const
Returns TRUE if bounding box is completely outside the view-volume defined by the model+view+projecti...
void setBounds(const SbVec3d &_min, const SbVec3d &_max)
Definition SbBoxd.h:147
void getBounds(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const
Definition SbBoxd.h:150
void getOrigin(double &originX, double &originY, double &originZ) const
Gets box origin which is the same as the minimum corner of the box.
Definition SbBoxd.h:162
void getBounds(SbVec3d &_min, SbVec3d &_max) const
Definition SbBoxd.h:154
SbBox3d()
Empty box constructor.
Definition SbBoxd.h:86
bool hasVolume() const
Returns TRUE if all three dimensions of the box have positive size, and FALSE otherwise.
Definition SbBoxd.h:181
void getSize(double &sizeX, double &sizeY, double &sizeZ) const
Gets box size.
Definition SbBoxd.h:168
bool isEmpty() const
Returns TRUE if the box is empty, and FALSE otherwise.
Definition SbBoxd.h:177
const SbVec3d & getMin() const
Returns the minimum point of the box.
Definition SbBoxd.h:103
SbVec3d & getMin()
Returns the minimum point of the box.
Definition SbBoxd.h:109
bool intersect(const SbVec3d &pt) const
Returns TRUE if intersection of given point and Box3d is not empty.
SbBox3d(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
Constructor given bounds.
Definition SbBoxd.h:89
SbVec3d getCenter() const
Returns the center of the box.
void transform(const SbMatrixd &m)
Transforms box by matrix, enlarging box to contain result.
void extendBy(const SbVec3d &pt)
Extends Box3d (if necessary) to contain given 3D point.
bool intersect(const SbBox3d &bb) const
Returns TRUE if intersection of given Box3d and Box3d is not empty.
void extendBy(const SbBox3d &bb)
Extends Box3d (if necessary) to contain given Box3d.
SbVec3d getClosestPoint(const SbVec3d &point)
Returns the closest point on the box to the given point.
void getSpan(const SbVec3d &direction, double &dMin, double &dMax) const
Finds the span of a box along a specified direction.
double getVolume() const
Returns the volume of the box.
4x4 matrix class with double values.
Definition SbLineard.h:616
2D vector class with double members.
Definition SbLineard.h:242
3D vector class with double values.
Definition SbLineard.h:116
3D box with an associated transformation matrix.
Definition SbBoxd.h:229
void setBounds(const SbVec3d &_min, const SbVec3d &_max)
Set and get the bounds of the box.
Definition SbBoxd.h:292
void extendBy(const SbXfBox3d &bb)
Extends the box (if necessary) to contain the given SbXfBox3d.
void makeEmpty()
Sets Box3d to contain nothing.
Definition SbBoxd.h:316
void getSize(double &sizeX, double &sizeY, double &sizeZ)
Returns size of the box.
Definition SbBoxd.h:309
~SbXfBox3d()
Constructors and destructor.
Definition SbBoxd.h:242
void setBounds(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
Common get and set functions.
Definition SbBoxd.h:287
bool hasVolume() const
Checks if the box has volume; i.e., all three dimensions have positive size.
Definition SbBoxd.h:326
const SbMatrixd & getTransform() const
Gets the transformation on the box, and its inverse.
Definition SbBoxd.h:248
bool isEmpty() const
Checks if the box is empty (degenerate) note that this relies on boxes being completely degenerate if...
Definition SbBoxd.h:322
void transform(const SbMatrixd &m)
Transforms the box by the given matrix.
void setTransform(const SbMatrixd &m)
Sets the transformation on the box.
void extendBy(const SbBox3d &bb)
Extends the box (if necessary) to contain the given SbBox3d.
Definition SbBoxd.h:273
double getVolume() const
Gives the volume of the box (0 for an empty box).
SbXfBox3d()
Constructors and destructor.
SbXfBox3d(const SbBox3d &box)
Constructors and destructor.
void extendBy(const SbVec3d &pt)
Extends the box (if necessary) to contain the given 3D point.
const SbMatrixd & getInverse() const
Gets the transformation on the box, and its inverse.
Definition SbBoxd.h:250
SbBox3d project() const
Projects an SbXfBox3d to an SbBox3d.
void getSpan(const SbVec3d &direction, double &dMin, double &dMax) const
Finds the extent of the box along a particular direction.
Definition SbBoxd.h:329
bool intersect(const SbBox3d &bb) const
Returns TRUE if intersection of given XfBox3d and Box3d is not empty.
Definition SbBoxd.h:283
SbVec3d getCenter() const
Returns the center of the box.
void getBounds(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const
Definition SbBoxd.h:295
SbXfBox3d(const SbVec3d &_min, const SbVec3d &_max)
Constructors and destructor.
void getOrigin(double &originX, double &originY, double &originZ)
Returns origin (minimum point) of the box.
Definition SbBoxd.h:303
bool intersect(const SbVec3d &pt) const
Returns TRUE if intersection of given point and Box3d is not empty.
void getBounds(SbVec3d &_min, SbVec3d &_max) const
Definition SbBoxd.h:299