Open Inventor Reference
SbBox.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) : Paul S. Strauss, Nick Thompson, David Mott
53  |
54  ______________ S I L I C O N G R A P H I C S I N C . ____________
55  _______________________________________________________________________
56  */
57 
58 #ifndef _SB_BOX_
59 #define _SB_BOX_
60 
62 #include <Inventor/SbBasic.h>
63 #include <Inventor/SbLinear.h>
64 
67 
80 
82  public:
83 
85  SbBox3f() { makeEmpty(); }
86 
88  SbBox3f(float xmin, float ymin, float zmin,
89  float xmax, float ymax, float zmax)
90  { min.setValue(xmin, ymin, zmin); max.setValue(xmax, ymax, zmax); }
91 
94  SbBox3f(const SbVec3f &min, const SbVec3f &max)
95  { this->min = min; this->max = max; }
96 
98  ~SbBox3f() { }
99 
102  const SbVec3f & getMin() const { return min; }
105  const SbVec3f & getMax() const { return max; }
108  SbVec3f & getMin() { return min; }
111  SbVec3f & getMax() { return max; }
112 
115 
117  void extendBy(const SbVec3f &pt);
118 
120  void extendBy(const SbBox3f &bb);
121 
123  bool intersect(const SbVec3f &pt) const;
124 
126  bool intersect(const SbBox3f &bb) const;
127 
139  bool outside(const SbMatrix &MVP, int &cullBits) const;
140 
142  void setBounds(float xmin, float ymin, float zmin,
143  float xmax, float ymax, float zmax)
144  { min.setValue(xmin, ymin, zmin); max.setValue(xmax, ymax, zmax); }
145 
146  void setBounds(const SbVec3f &_min, const SbVec3f &_max)
147  { min = _min; max = _max; }
148 
149  void getBounds(float &xmin, float &ymin, float &zmin,
150  float &xmax, float &ymax, float &zmax) const
151  { min.getValue(xmin, ymin, zmin); max.getValue(xmax, ymax, zmax); }
152 
153  void getBounds(SbVec3f &_min, SbVec3f &_max) const
154  { _min = min; _max = max; }
155 
159 
161  void getOrigin(float &originX,
162  float &originY,
163  float &originZ) const
164  { originX = min[0]; originY = min[1]; originZ = min[2]; }
165 
167  void getSize(float &sizeX, float &sizeY, float &sizeZ) const
168  { sizeX = max[0] - min[0];
169  sizeY = max[1] - min[1];
170  sizeZ = max[2] - min[2]; }
171 
173  void makeEmpty();
174 
176  bool isEmpty() const { return max[0] < min[0]; }
177 
180  bool hasVolume() const
181  { return (max[0] > min[0] && max[1] > min[1] && max[2] > min[2] ); }
182 
188  void getSpan(const SbVec3f &direction,
189  float &dMin, float &dMax) const;
190 
192  void transform(const SbMatrix &m);
193 
195  float getVolume() const;
196 
198  friend INVENTOR_API bool operator ==(const SbBox3f &b1, const SbBox3f &b2);
199  friend INVENTOR_API bool operator !=(const SbBox3f &b1, const SbBox3f &b2);
200 
201  private:
203  SbVec3f min, max;
204 };
205 
206 INVENTOR_API bool operator ==(const SbBox3f &b1, const SbBox3f &b2);
207 inline INVENTOR_API bool operator !=(const SbBox3f &b1, const SbBox3f &b2)
208 { return !(b1 == b2); }
209 
212 
227 
229  public:
230 
233 
235  SbXfBox3f(const SbVec3f &_min, const SbVec3f &_max);
236 
238  SbXfBox3f(const SbBox3f &box);
239 
242 
244  void setTransform(const SbMatrix &m);
245 
247  const SbMatrix & getTransform() const { return xform; }
249  const SbMatrix & getInverse() const { return xformInv; }
250 
253 
266  void extendBy(const SbVec3f &pt);
267 
272  void extendBy(const SbBox3f &bb)
273  { extendBy(SbXfBox3f(bb)); }
274 
276  void extendBy(const SbXfBox3f &bb);
277 
279  bool intersect(const SbVec3f &pt) const;
280 
282  bool intersect(const SbBox3f &bb) const
283  { return project().intersect(bb); }
284 
286  void setBounds(float xmin, float ymin, float zmin,
287  float xmax, float ymax, float zmax)
288  { SbBox3f::setBounds(xmin, ymin, zmin, xmax, ymax, zmax); }
289 
291  void setBounds(const SbVec3f &_min, const SbVec3f &_max)
292  { SbBox3f::setBounds(_min, _max); }
293 
294  void getBounds(float &xmin, float &ymin, float &zmin,
295  float &xmax, float &ymax, float &zmax) const
296  { SbBox3f::getBounds(xmin, ymin, zmin, xmax, ymax, zmax); }
297 
298  void getBounds(SbVec3f &_min, SbVec3f &_max) const
299  { SbBox3f::getBounds(_min, _max); }
300 
302  void getOrigin(float &originX,
303  float &originY,
304  float &originZ)
305  { SbBox3f::getOrigin(originX, originY, originZ); }
306 
308  void getSize(float &sizeX, float &sizeY, float &sizeZ)
309  { SbBox3f::getSize(sizeX, sizeY, sizeZ); }
310 
312  float getVolume() const;
313 
316 
321  bool isEmpty() const { return SbBox3f::isEmpty(); }
322 
325  bool hasVolume() const { return SbBox3f::hasVolume(); }
326 
328  void getSpan(const SbVec3f &direction,
329  float &dMin, float &dMax) const
330  { project().getSpan(direction, dMin, dMax); }
331 
333  void transform(const SbMatrix &m);
334 
336  SbBox3f project() const;
337 
339  friend INVENTOR_API bool operator ==(const SbXfBox3f &b1, const SbXfBox3f &b2);
340  friend INVENTOR_API bool operator !=(const SbXfBox3f &b1, const SbXfBox3f &b2);
341 
342  private:
344  const SbVec3f & getMin() const { return SbBox3f::getMin(); }
345  const SbVec3f & getMax() const { return SbBox3f::getMax(); }
346 
348  SbMatrix xform;
349  SbMatrix xformInv;
350 };
351 
352 INVENTOR_API bool operator ==(const SbXfBox3f &b1, const SbXfBox3f &b2);
353 inline INVENTOR_API bool operator !=(const SbXfBox3f &b1, const SbXfBox3f &b2)
354 { return !(b1 == b2); }
355 
358 
371 
373  public:
374 
376  SbBox2f() { makeEmpty(); };
377 
379  SbBox2f(float xmin, float ymin, float xmax, float ymax)
380  { min.setValue(xmin, ymin); max.setValue(xmax, ymax); }
381 
383  SbBox2f(const SbVec2f &_min, const SbVec2f &_max)
384  { min = _min; max = _max; }
385 
387  ~SbBox2f() { }
388 
390  const SbVec2f & getMin() const { return min; }
392  const SbVec2f & getMax() const { return max; }
393 
396 
398  void extendBy(const SbVec2f &pt);
399 
401  void extendBy(const SbBox2f &r);
402 
404  bool intersect(const SbVec2f &pt) const;
405 
407  bool intersect(const SbBox2f &bb) const;
408 
410  void setBounds(float xmin, float ymin, float xmax, float ymax)
411  { min.setValue(xmin, ymin); max.setValue(xmax, ymax); }
412 
413  void setBounds(const SbVec2f &_min, const SbVec2f &_max)
414  { min = _min; max = _max; }
415 
416  void getBounds(float &xmin, float &ymin,
417  float &xmax, float &ymax) const
418  { min.getValue(xmin, ymin); max.getValue(xmax, ymax); }
419 
420  void getBounds(SbVec2f &_min, SbVec2f &_max) const
421  { _min = min; _max = max; }
422 
426 
428  void getOrigin(float &originX, float &originY) const
429  { originX = min[0]; originY = min[1]; }
430 
432  void getSize(float &sizeX, float &sizeY) const
433  { sizeX = max[0] - min[0]; sizeY = max[1] - min[1]; }
434 
436  float getAspectRatio() const
437  { return (max[0] - min[0]) / (max[1] - min[1]); }
438 
440  void makeEmpty();
441 
443  bool isEmpty() const { return max[0] < min[0]; }
444 
447  bool hasArea() const
448  { return (max[0] > min[0] && max[1] > min[1]); }
449 
451  friend INVENTOR_API bool operator ==(const SbBox2f &b1, const SbBox2f &b2);
452  friend INVENTOR_API bool operator !=(const SbBox2f &b1, const SbBox2f &b2);
453 
454  private:
456  SbVec2f min, max;
457 };
458 
459 INVENTOR_API bool operator ==(const SbBox2f &b1, const SbBox2f &b2);
460 inline INVENTOR_API bool operator !=(const SbBox2f &b1, const SbBox2f &b2)
461 { return !(b1 == b2); }
462 
465 
478 
480  public:
481 
483  SbBox2s() { makeEmpty(); };
484 
487  SbBox2s(short xmin, short ymin, short xmax, short ymax)
488  { min.setValue(xmin, ymin); max.setValue(xmax, ymax); }
489 
492  SbBox2s(const SbVec2s &min, const SbVec2s &max)
493  { this->min = min; this->max = max; }
494 
496  ~SbBox2s() { }
497 
499  const SbVec2s & getMin() const { return min; }
501  const SbVec2s & getMax() const { return max; }
502 
504  void extendBy(const SbVec2s &pt);
505 
507  void extendBy(const SbBox2s &r);
508 
510  bool intersect(const SbVec2s &pt) const;
511 
513  bool intersect(const SbBox2s &bb) const;
514 
516  void setBounds(short xmin, short ymin, short xmax, short ymax)
517  { min.setValue(xmin, ymin); max.setValue(xmax, ymax); }
518 
520  void setBounds(const SbVec2s &_min, const SbVec2s &_max)
521  { min = _min; max = _max; }
522 
523  void getBounds(short &xmin, short &ymin,
524  short &xmax, short &ymax) const
525  { min.getValue(xmin, ymin); max.getValue(xmax, ymax); }
526 
527  void getBounds(SbVec2s &_min, SbVec2s &_max) const
528  { _min = min; _max = max; }
529 
531  void getOrigin(short &originX, short &originY) const
532  { originX = min[0]; originY = min[1]; }
533 
535  void getSize(short &sizeX, short &sizeY) const
536  { sizeX = max[0] - min[0]; sizeY = max[1] - min[1]; }
537 
539  float getAspectRatio() const
540  { return float(max[0] - min[0]) / float(max[1] - min[1]); }
541 
543  void makeEmpty();
544 
546  friend INVENTOR_API bool operator ==(const SbBox2s &b1, const SbBox2s &b2);
547  friend INVENTOR_API bool operator !=(const SbBox2s &b1, const SbBox2s &b2);
548 
549  private:
551  SbVec2s min, max;
552 };
553 
554 INVENTOR_API bool operator ==(const SbBox2s &b1, const SbBox2s &b2);
555 inline INVENTOR_API bool operator !=(const SbBox2s &b1, const SbBox2s &b2)
556 { return !(b1 == b2); }
557 
558 #endif /* _SB_BOX_ */
INVENTOR_API bool operator!=(const SbBox3f &b1, const SbBox3f &b2)
Definition: SbBox.h:207
INVENTOR_API bool operator==(const SbBox3f &b1, const SbBox3f &b2)
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition: SbSystem.h:81
2D box class.
Definition: SbBox.h:372
~SbBox2f()
Destructor.
Definition: SbBox.h:387
float getAspectRatio() const
Gets box aspect ratio.
Definition: SbBox.h:436
SbBox2f()
Constructs an empty box.
Definition: SbBox.h:376
void setBounds(const SbVec2f &_min, const SbVec2f &_max)
Definition: SbBox.h:413
void getSize(float &sizeX, float &sizeY) const
Gets box size.
Definition: SbBox.h:432
const SbVec2f & getMax() const
Returns the minimum and maximum points of the box.
Definition: SbBox.h:392
SbVec2f getCenter() const
Returns the center of the box.
bool intersect(const SbVec2f &pt) const
Returns TRUE if intersection of given point and Box2f is not empty.
SbBox2f(float xmin, float ymin, float xmax, float ymax)
Constructor given bounds.
Definition: SbBox.h:379
SbBox2f(const SbVec2f &_min, const SbVec2f &_max)
Constructor given minimum and maximum points.
Definition: SbBox.h:383
bool intersect(const SbBox2f &bb) const
Returns TRUE if intersection of given Box2f and Box2f is not empty.
void setBounds(float xmin, float ymin, float xmax, float ymax)
Sets the corners of the box.
Definition: SbBox.h:410
void getBounds(SbVec2f &_min, SbVec2f &_max) const
Definition: SbBox.h:420
void getOrigin(float &originX, float &originY) const
Gets box origin.
Definition: SbBox.h:428
void getBounds(float &xmin, float &ymin, float &xmax, float &ymax) const
Definition: SbBox.h:416
bool hasArea() const
Returns TRUE if both dimensions of the box have positive size, and FALSE otherwise.
Definition: SbBox.h:447
void makeEmpty()
Makes an empty box.
void extendBy(const SbVec2f &pt)
Extends Box2f (if necessary) to contain given 2D point.
SbVec2f getClosestPoint(const SbVec2f &point)
Returns the closest point on the box to the given point.
void extendBy(const SbBox2f &r)
Extends Box2f (if necessary) to contain given Box2f.
bool isEmpty() const
Returns TRUE if the box is empty, and FALSE otherwise.
Definition: SbBox.h:443
const SbVec2f & getMin() const
Returns the minimum and maximum points of the box.
Definition: SbBox.h:390
2D box class.
Definition: SbBox.h:479
~SbBox2s()
Destructor.
Definition: SbBox.h:496
const SbVec2s & getMin() const
Returns the minimum and maximum points of the box.
Definition: SbBox.h:499
void getBounds(short &xmin, short &ymin, short &xmax, short &ymax) const
Definition: SbBox.h:523
void setBounds(short xmin, short ymin, short xmax, short ymax)
Sets the corners of the box.
Definition: SbBox.h:516
void setBounds(const SbVec2s &_min, const SbVec2s &_max)
Sets the corners of the box.
Definition: SbBox.h:520
void extendBy(const SbBox2s &r)
Extends Box2s (if necessary) to contain given Box2s.
void getOrigin(short &originX, short &originY) const
Returns origin (minimum point) of box.
Definition: SbBox.h:531
float getAspectRatio() const
Returns aspect ratio (ratio of width to height) of box.
Definition: SbBox.h:539
void getSize(short &sizeX, short &sizeY) const
Returns box size.
Definition: SbBox.h:535
SbBox2s()
Constructs an empty box.
Definition: SbBox.h:483
SbBox2s(const SbVec2s &min, const SbVec2s &max)
Constructor for a 2D integer box.
Definition: SbBox.h:492
void makeEmpty()
Makes an empty box.
void getBounds(SbVec2s &_min, SbVec2s &_max) const
Definition: SbBox.h:527
SbBox2s(short xmin, short ymin, short xmax, short ymax)
Constructor for a 2D integer box.
Definition: SbBox.h:487
void extendBy(const SbVec2s &pt)
Extends Box2s (if necessary) to contain given 2D point.
const SbVec2s & getMax() const
Returns the minimum and maximum points of the box.
Definition: SbBox.h:501
bool intersect(const SbVec2s &pt) const
Returns TRUE if intersection of given point and Box2s is not empty.
bool intersect(const SbBox2s &bb) const
Returns TRUE if intersection of given Box2s and Box2s is not empty.
3D box class.
Definition: SbBox.h:81
bool intersect(const SbVec3f &pt) const
Returns TRUE if intersection of given point and Box3f is not empty.
const SbVec3f & getMin() const
Returns the minimum point of the box.
Definition: SbBox.h:102
~SbBox3f()
Destructor.
Definition: SbBox.h:98
float getVolume() const
Returns the volume of the box.
void getOrigin(float &originX, float &originY, float &originZ) const
Gets box origin which is the same as the minimum corner of the box.
Definition: SbBox.h:161
void makeEmpty()
Makes an empty box.
void setBounds(float xmin, float ymin, float zmin, float xmax, float ymax, float zmax)
Common get and set functions.
Definition: SbBox.h:142
void getSpan(const SbVec3f &direction, float &dMin, float &dMax) const
Finds the span of a box along a specified direction.
void setBounds(const SbVec3f &_min, const SbVec3f &_max)
Definition: SbBox.h:146
void getBounds(float &xmin, float &ymin, float &zmin, float &xmax, float &ymax, float &zmax) const
Definition: SbBox.h:149
void getSize(float &sizeX, float &sizeY, float &sizeZ) const
Gets box size.
Definition: SbBox.h:167
void getBounds(SbVec3f &_min, SbVec3f &_max) const
Definition: SbBox.h:153
void extendBy(const SbBox3f &bb)
Extends Box3f (if necessary) to contain given Box3f.
bool outside(const SbMatrix &MVP, int &cullBits) const
Returns TRUE if bounding box is completely outside the view-volume defined by the model+view+projecti...
bool hasVolume() const
Returns TRUE if all three dimensions of the box have positive size, and FALSE otherwise.
Definition: SbBox.h:180
bool isEmpty() const
Returns TRUE if the box is empty, and FALSE otherwise.
Definition: SbBox.h:176
bool intersect(const SbBox3f &bb) const
Returns TRUE if intersection of given Box3f and Box3f is not empty.
const SbVec3f & getMax() const
Returns the maximum point of the box.
Definition: SbBox.h:105
SbVec3f getCenter() const
Returns the center of the box.
SbBox3f(const SbVec3f &min, const SbVec3f &max)
Constructor given minimum and maximum points min and max are the corners of the diagonal that define ...
Definition: SbBox.h:94
SbVec3f & getMax()
Returns the maximum point of the box.
Definition: SbBox.h:111
SbVec3f getClosestPoint(const SbVec3f &point)
Returns the closest point on the box to the given point.
SbVec3f & getMin()
Returns the minimum point of the box.
Definition: SbBox.h:108
SbBox3f(float xmin, float ymin, float zmin, float xmax, float ymax, float zmax)
Constructor given bounds.
Definition: SbBox.h:88
void transform(const SbMatrix &m)
Transforms box by matrix, enlarging box to contain result.
void extendBy(const SbVec3f &pt)
Extends Box3f (if necessary) to contain given 3D point.
SbBox3f()
Empty box constructor.
Definition: SbBox.h:85
4x4 matrix class.
Definition: SbLinear.h:823
2D vector class.
Definition: SbLinear.h:246
2D vector class.
Definition: SbLinear.h:354
3D vector class.
Definition: SbLinear.h:120
3D box with an associated transformation matrix.
Definition: SbBox.h:228
void transform(const SbMatrix &m)
Transforms the box by the given matrix.
SbXfBox3f(const SbBox3f &box)
Constructors and destructor.
void extendBy(const SbXfBox3f &bb)
Extends the box (if necessary) to contain the given SbXfBox3f.
float getVolume() const
Gives the volume of the box (0 for an empty box).
SbXfBox3f(const SbVec3f &_min, const SbVec3f &_max)
Constructors and destructor.
const SbMatrix & getInverse() const
Gets the transformation on the box, and its inverse.
Definition: SbBox.h:249
bool isEmpty() const
Checks if the box is empty (degenerate) note that this relies on boxes being completely degenerate if...
Definition: SbBox.h:321
SbBox3f project() const
Projects an SbXfBox3f to an SbBox3f.
void getOrigin(float &originX, float &originY, float &originZ)
Returns origin (minimum point) of the box.
Definition: SbBox.h:302
SbXfBox3f()
Constructors and destructor.
SbVec3f getCenter() const
Returns the center of the box.
~SbXfBox3f()
Constructors and destructor.
Definition: SbBox.h:241
void getBounds(float &xmin, float &ymin, float &zmin, float &xmax, float &ymax, float &zmax) const
Definition: SbBox.h:294
void getSpan(const SbVec3f &direction, float &dMin, float &dMax) const
Finds the extent of the box along a particular direction.
Definition: SbBox.h:328
void setBounds(const SbVec3f &_min, const SbVec3f &_max)
Set and get the bounds of the box.
Definition: SbBox.h:291
bool intersect(const SbBox3f &bb) const
Returns TRUE if intersection of given XfBox3f and Box3f is not empty.
Definition: SbBox.h:282
void getSize(float &sizeX, float &sizeY, float &sizeZ)
Returns size of the box.
Definition: SbBox.h:308
void setTransform(const SbMatrix &m)
Sets the transformation on the box.
void getBounds(SbVec3f &_min, SbVec3f &_max) const
Definition: SbBox.h:298
void makeEmpty()
Sets Box3f to contain nothing.
Definition: SbBox.h:315
void setBounds(float xmin, float ymin, float zmin, float xmax, float ymax, float zmax)
Common get and set functions.
Definition: SbBox.h:286
bool intersect(const SbVec3f &pt) const
Returns TRUE if intersection of given point and Box3f is not empty.
void extendBy(const SbBox3f &bb)
Extends the box (if necessary) to contain the given SbBox3f.
Definition: SbBox.h:272
const SbMatrix & getTransform() const
Gets the transformation on the box, and its inverse.
Definition: SbBox.h:247
void extendBy(const SbVec3f &pt)
Extends the box (if necessary) to contain the given 3D point.
bool hasVolume() const
Checks if the box has volume; i.e., all three dimensions have positive size.
Definition: SbBox.h:325