Open Inventor Reference
MeVis/ThirdParty/Sources/Inventor/inventor/lib/database/include/Inventor/SbBox.h
Go to the documentation of this file.
00001 /*
00002  *
00003  *  Copyright (C) 2000 Silicon Graphics, Inc.  All Rights Reserved. 
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  Further, this software is distributed without any warranty that it is
00016  *  free of the rightful claim of any third person regarding infringement
00017  *  or the like.  Any license provided herein, whether implied or
00018  *  otherwise, applies only to this software file.  Patent licenses, if
00019  *  any, provided herein do not apply to combinations of this program with
00020  *  other software, or any other product whatsoever.
00021  * 
00022  *  You should have received a copy of the GNU Lesser General Public
00023  *  License along with this library; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  *  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
00027  *  Mountain View, CA  94043, or:
00028  * 
00029  *  http://www.sgi.com 
00030  * 
00031  *  For further information regarding this notice, see: 
00032  * 
00033  *  http://oss.sgi.com/projects/GenInfo/NoticeExplan/
00034  *
00035  */
00036 
00037 
00038 /*
00039  * Copyright (C) 1990,91   Silicon Graphics, Inc.
00040  *
00041  _______________________________________________________________________
00042  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00043  |
00044  |   $Revision: 1.1.1.1 $
00045  |
00046  |   Description:
00047  |      This file contains definitions of SbBoxes, 2D/3D boxes. A
00048  |      box has planes parallel to the major axes and can therefore
00049  |      be specified by two points on a diagonal.  The points with minimum
00050  |      and maximum x, y, and z coordinates are used.
00051  |
00052  |   Author(s)          : Paul S. Strauss, Nick Thompson, David Mott
00053  |
00054  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00055  _______________________________________________________________________
00056  */
00057 
00058 #ifndef _SB_BOX_
00059 #define _SB_BOX_
00060 
00061 #include <Inventor/system/SbSystem.h>
00062 #include <Inventor/SbBasic.h>
00063 #include <Inventor/SbLinear.h>
00064 
00067 
00079 
00080 
00081 class INVENTOR_API SbBox3f {
00082   public:
00083 
00085     SbBox3f()                                           { makeEmpty(); }
00086 
00088     SbBox3f(float xmin, float ymin, float zmin,
00089             float xmax, float ymax, float zmax)
00090         { min.setValue(xmin, ymin, zmin); max.setValue(xmax, ymax, zmax); }
00091 
00094     SbBox3f(const SbVec3f &min, const SbVec3f &max)
00095         { this->min = min; this->max = max; }
00096 
00098     ~SbBox3f()                                          { }
00099 
00102     const SbVec3f &     getMin() const { return min; }
00105     const SbVec3f &     getMax() const { return max; }
00108     SbVec3f &           getMin()       { return min; }
00111     SbVec3f &           getMax()       { return max; }
00112 
00114     SbVec3f     getCenter() const;
00115 
00117     void        extendBy(const SbVec3f &pt);
00118 
00120     void        extendBy(const SbBox3f &bb);
00121 
00123     SbBool      intersect(const SbVec3f &pt) const;
00124 
00126     SbBool      intersect(const SbBox3f &bb) const;
00127 
00139     SbBool      outside(const SbMatrix &MVP, int &cullBits) const;
00140 
00142     void        setBounds(float xmin, float ymin, float zmin,
00143                           float xmax, float ymax, float zmax)
00144         { min.setValue(xmin, ymin, zmin); max.setValue(xmax, ymax, zmax); }
00145 
00146     void        setBounds(const SbVec3f &_min, const SbVec3f &_max)
00147         { min = _min; max = _max; }
00148 
00149     void        getBounds(float &xmin, float &ymin, float &zmin,
00150                           float &xmax, float &ymax, float &zmax) const
00151         { min.getValue(xmin, ymin, zmin); max.getValue(xmax, ymax, zmax); }
00152 
00153     void        getBounds(SbVec3f &_min, SbVec3f &_max) const
00154         { _min = min; _max = max; }
00155 
00158     SbVec3f     getClosestPoint(const SbVec3f &point);
00159 
00161     void        getOrigin(float &originX,
00162                           float &originY,
00163                           float &originZ) const
00164         { originX = min[0]; originY = min[1]; originZ = min[2]; }
00165 
00167     void        getSize(float &sizeX, float &sizeY, float &sizeZ) const
00168         { sizeX = max[0] - min[0];
00169           sizeY = max[1] - min[1];
00170           sizeZ = max[2] - min[2]; }
00171 
00173     void        makeEmpty();
00174 
00176     SbBool      isEmpty()  const                { return max[0] < min[0]; }
00177 
00180     SbBool      hasVolume() const
00181         { return (max[0] > min[0] && max[1] > min[1] && max[2] > min[2] ); }
00182 
00188     void        getSpan(const SbVec3f &direction,
00189                         float &dMin, float &dMax) const;
00190 
00192     void        transform(const SbMatrix &m);
00193 
00195     float       getVolume() const;
00196 
00198     friend INVENTOR_API int          operator ==(const SbBox3f &b1, const SbBox3f &b2);
00199     friend INVENTOR_API int          operator !=(const SbBox3f &b1, const SbBox3f &b2)
00200         { return !(b1 == b2); }
00201 
00202   private:
00204     SbVec3f     min, max;
00205 };
00206 
00209 
00223 
00224 
00225 class INVENTOR_API SbXfBox3f : public SbBox3f {
00226   public:
00227 
00229     SbXfBox3f();
00230 
00232     SbXfBox3f(const SbVec3f &_min, const SbVec3f &_max);
00233 
00235     SbXfBox3f(const SbBox3f &box);
00236 
00238     ~SbXfBox3f()                                                { }
00239 
00241     void                setTransform(const SbMatrix &m);
00242 
00244     const SbMatrix &    getTransform() const        { return xform; }
00246     const SbMatrix &    getInverse() const          { return xformInv; }
00247 
00249     SbVec3f             getCenter() const;
00250 
00263     void                extendBy(const SbVec3f &pt);
00264 
00269     void                extendBy(const SbBox3f &bb)
00270         { extendBy(SbXfBox3f(bb)); }
00271 
00273     void                extendBy(const SbXfBox3f &bb);
00274 
00276     SbBool              intersect(const SbVec3f &pt) const;
00277 
00279     SbBool              intersect(const SbBox3f &bb) const
00280         { return project().intersect(bb); }
00281 
00283     void        setBounds(float xmin, float ymin, float zmin,
00284                           float xmax, float ymax, float zmax)
00285         { SbBox3f::setBounds(xmin, ymin, zmin, xmax, ymax, zmax); }
00286 
00288     void        setBounds(const SbVec3f &_min, const SbVec3f &_max)
00289         { SbBox3f::setBounds(_min, _max); }
00290 
00291     void        getBounds(float &xmin, float &ymin, float &zmin,
00292                           float &xmax, float &ymax, float &zmax) const
00293         { SbBox3f::getBounds(xmin, ymin, zmin, xmax, ymax, zmax); }
00294 
00295     void        getBounds(SbVec3f &_min, SbVec3f &_max) const
00296         { SbBox3f::getBounds(_min, _max); }
00297 
00299     void        getOrigin(float &originX,
00300                           float &originY,
00301                           float &originZ)
00302         { SbBox3f::getOrigin(originX, originY, originZ); }
00303 
00305     void        getSize(float &sizeX, float &sizeY, float &sizeZ)
00306         { SbBox3f::getSize(sizeX, sizeY, sizeZ); }
00307 
00309     float       getVolume() const;
00310 
00312     void                makeEmpty()             { SbBox3f::makeEmpty(); }
00313 
00318     SbBool              isEmpty() const { return SbBox3f::isEmpty(); }
00319 
00322     SbBool              hasVolume() const { return SbBox3f::hasVolume(); }
00323 
00325     void                getSpan(const SbVec3f &direction,
00326                                 float &dMin, float &dMax) const
00327         { project().getSpan(direction, dMin, dMax); }
00328 
00330     void                transform(const SbMatrix &m);
00331 
00333     SbBox3f             project() const;
00334 
00336     friend INVENTOR_API int          operator ==(const SbXfBox3f &b1, const SbXfBox3f &b2);
00337     friend INVENTOR_API int          operator !=(const SbXfBox3f &b1, const SbXfBox3f &b2)
00338         { return !(b1 == b2); }
00339 
00340   private:
00342     const SbVec3f &     getMin() const                  { return SbBox3f::getMin(); }
00343     const SbVec3f &     getMax() const                  { return SbBox3f::getMax(); }
00344 
00346     SbMatrix            xform;
00347     SbMatrix            xformInv;
00348 };
00349 
00352 
00364 
00365 
00366 class INVENTOR_API SbBox2f {
00367   public:
00368 
00370     SbBox2f()                                   { makeEmpty(); };
00371 
00373     SbBox2f(float xmin, float ymin, float xmax, float ymax)
00374         { min.setValue(xmin, ymin); max.setValue(xmax, ymax); }
00375 
00377     SbBox2f(const SbVec2f &_min, const SbVec2f &_max)
00378         { min = _min; max = _max; }
00379 
00381     ~SbBox2f()                                          { }
00382 
00384     const SbVec2f &     getMin() const                  { return min; }
00386     const SbVec2f &     getMax() const                  { return max; }
00387 
00389     SbVec2f             getCenter() const;
00390 
00392     void        extendBy(const SbVec2f &pt);
00393 
00395     void        extendBy(const SbBox2f &r);
00396 
00398     SbBool      intersect(const SbVec2f &pt) const;
00399 
00401     SbBool      intersect(const SbBox2f &bb) const;
00402 
00404     void        setBounds(float xmin, float ymin, float xmax, float ymax)
00405         { min.setValue(xmin, ymin); max.setValue(xmax, ymax); }
00406 
00407     void        setBounds(const SbVec2f &_min, const SbVec2f &_max)
00408         { min = _min; max = _max; }
00409 
00410     void        getBounds(float &xmin, float &ymin,
00411                           float &xmax, float &ymax) const
00412         { min.getValue(xmin, ymin); max.getValue(xmax, ymax); }
00413 
00414     void        getBounds(SbVec2f &_min, SbVec2f &_max) const
00415         { _min = min; _max = max; }
00416 
00419     SbVec2f     getClosestPoint(const SbVec2f &point);
00420 
00422     void        getOrigin(float &originX, float &originY) const
00423         { originX = min[0]; originY = min[1]; }
00424 
00426     void        getSize(float &sizeX, float &sizeY) const
00427         { sizeX = max[0] - min[0]; sizeY = max[1] - min[1]; }
00428 
00430     float       getAspectRatio() const
00431         { return (max[0] - min[0]) / (max[1] - min[1]); }
00432 
00434     void        makeEmpty();
00435 
00437     SbBool      isEmpty() const         { return max[0] < min[0]; }
00438 
00441     SbBool      hasArea() const
00442         { return (max[0] > min[0] && max[1] > min[1]); }
00443 
00445     friend INVENTOR_API int          operator ==(const SbBox2f &b1, const SbBox2f &b2);
00446     friend INVENTOR_API int          operator !=(const SbBox2f &b1, const SbBox2f &b2)
00447         { return !(b1 == b2); }
00448 
00449   private:
00451     SbVec2f     min, max;
00452 };
00453 
00456 
00468 
00469 
00470 class INVENTOR_API SbBox2s {
00471   public:
00472 
00474     SbBox2s()                                   { makeEmpty(); };
00475 
00478     SbBox2s(short xmin, short ymin, short xmax, short ymax)
00479         { min.setValue(xmin, ymin); max.setValue(xmax, ymax); }
00480 
00483     SbBox2s(const SbVec2s &min, const SbVec2s &max)
00484         { this->min = min; this->max = max; }
00485 
00487     ~SbBox2s()                                          { }
00488 
00490     const SbVec2s &     getMin() const                  { return min; }
00492     const SbVec2s &     getMax() const                  { return max; }
00493 
00495     void        extendBy(const SbVec2s &pt);
00496 
00498     void        extendBy(const SbBox2s &r);
00499 
00501     SbBool      intersect(const SbVec2s &pt) const;
00502 
00504     SbBool      intersect(const SbBox2s &bb) const;
00505 
00507     void        setBounds(short xmin, short ymin, short xmax, short ymax)
00508         { min.setValue(xmin, ymin); max.setValue(xmax, ymax); }
00509 
00511     void        setBounds(const SbVec2s &_min, const SbVec2s &_max)
00512         { min = _min; max = _max; }
00513 
00514     void        getBounds(short &xmin, short &ymin,
00515                           short &xmax, short &ymax) const
00516         { min.getValue(xmin, ymin); max.getValue(xmax, ymax); }
00517 
00518     void        getBounds(SbVec2s &_min, SbVec2s &_max) const
00519         { _min = min; _max = max; }
00520 
00522     void        getOrigin(short &originX, short &originY) const
00523         { originX = min[0]; originY = min[1]; }
00524 
00526     void        getSize(short &sizeX, short &sizeY) const
00527         { sizeX = max[0] - min[0]; sizeY = max[1] - min[1]; }
00528 
00530     float       getAspectRatio() const
00531         { return float(max[0] - min[0]) / float(max[1] - min[1]); }
00532 
00534     void        makeEmpty();
00535 
00537     friend INVENTOR_API int          operator ==(const SbBox2s &b1, const SbBox2s &b2);
00538     friend INVENTOR_API int          operator !=(const SbBox2s &b1, const SbBox2s &b2)
00539         { return !(b1 == b2); }
00540 
00541   private:
00543     SbVec2s     min, max;
00544 };
00545 
00546 #endif /* _SB_BOX_ */