Coin Logo http://www.sim.no
http://www.coin3d.org

SbBox3d.h

00001 #ifndef COIN_SBBOX3D_H
00002 #define COIN_SBBOX3D_H
00003 
00004 /**************************************************************************\
00005  *
00006  *  This file is part of the Coin 3D visualization library.
00007  *  Copyright (C) 1998-2007 by Systems in Motion.  All rights reserved.
00008  *
00009  *  This library is free software; you can redistribute it and/or
00010  *  modify it under the terms of the GNU General Public License
00011  *  ("GPL") version 2 as published by the Free Software Foundation.
00012  *  See the file LICENSE.GPL at the root directory of this source
00013  *  distribution for additional information about the GNU GPL.
00014  *
00015  *  For using Coin with software that can not be combined with the GNU
00016  *  GPL, and for taking advantage of the additional benefits of our
00017  *  support services, please contact Systems in Motion about acquiring
00018  *  a Coin Professional Edition License.
00019  *
00020  *  See http://www.coin3d.org/ for more information.
00021  *
00022  *  Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
00023  *  http://www.sim.no/  sales@sim.no  coin-support@coin3d.org
00024  *
00025 \**************************************************************************/
00026 
00027 #include <stdio.h>
00028 
00029 #include <Inventor/SbVec3d.h>
00030 
00031 class SbBox3f;
00032 class SbBox3s;
00033 class SbBox3i32;
00034 
00035 class SbDPMatrix;
00036 
00037 class COIN_DLL_API SbBox3d {
00038 public:
00039   SbBox3d(void) { makeEmpty(); }
00040   SbBox3d(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
00041     : minpt(xmin, ymin, zmin), maxpt(xmax, ymax, zmax) { }
00042   SbBox3d(const SbVec3d & minpoint, const SbVec3d & maxpoint)
00043     : minpt(minpoint), maxpt(maxpoint) { }
00044   explicit SbBox3d(const SbBox3f & box) { setBounds(box); }
00045   explicit SbBox3d(const SbBox3s & box) { setBounds(box); }
00046   explicit SbBox3d(const SbBox3i32 & box) { setBounds(box); }
00047 
00048   SbBox3d & setBounds(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
00049     { minpt.setValue(xmin, ymin, zmin); maxpt.setValue(xmax, ymax, zmax); return *this; }
00050   SbBox3d & setBounds(const SbVec3d & minpoint, const SbVec3d & maxpoint)
00051     { minpt = minpoint; maxpt = maxpoint; return *this; }
00052   SbBox3d & setBounds(const SbBox3f & box);
00053   SbBox3d & setBounds(const SbBox3s & box);
00054   SbBox3d & setBounds(const SbBox3i32 & box);
00055 
00056   void getBounds(double & xmin, double & ymin, double & zmin, double & xmax, double & ymax, double & zmax) const
00057     { minpt.getValue(xmin, ymin, zmin); maxpt.getValue(xmax, ymax, zmax); }
00058   void getBounds(SbVec3d & minpoint, SbVec3d & maxpoint) const
00059     { minpoint = minpt; maxpoint = maxpt; }
00060 
00061   const SbVec3d & getMin(void) const { return minpt; }
00062   SbVec3d & getMin(void) { return minpt; }
00063   const SbVec3d & getMax(void) const { return maxpt; }
00064   SbVec3d & getMax(void) { return maxpt; }
00065 
00066   void extendBy(const SbVec3d & pt);
00067   void extendBy(const SbBox3d & box);
00068   void transform(const SbDPMatrix & matrix);
00069   void makeEmpty(void);
00070   SbBool isEmpty(void) const { return (maxpt[0] < minpt[0]); }
00071   SbBool hasVolume(void) const
00072     { return ((maxpt[0] > minpt[0]) && (maxpt[1] > minpt[1]) && (maxpt[2] > minpt[2])); }
00073   double getVolume(void) const
00074     { double dx = 0.0, dy = 0.0, dz = 0.0; getSize(dx, dy, dz); return (dx * dy * dz); }
00075 
00076   SbBool intersect(const SbVec3d & point) const;
00077   SbBool intersect(const SbBox3d & box) const;
00078   SbVec3d getClosestPoint(const SbVec3d & point) const;
00079   SbBool outside(const SbDPMatrix & mvp, int & cullbits) const;
00080 
00081   SbVec3d getCenter(void) const { return (minpt + maxpt) * 0.5; }
00082   void getOrigin(double & origoX, double & origoY, double & origoZ) const
00083     { minpt.getValue(origoX, origoY, origoZ); }
00084   void getSize(double & sizeX, double & sizeY, double & sizeZ) const
00085     { if (isEmpty()) { sizeX = sizeY = sizeZ = 0.0; }
00086       else { sizeX = maxpt[0] - minpt[0]; sizeY = maxpt[1] - minpt[1]; sizeZ = maxpt[2] - minpt[2]; } }
00087 
00088   void getSpan(const SbVec3d & dir, double & dmin, double & dmax) const;
00089 
00090   void print(FILE * file) const;
00091 
00092 protected:
00093   SbVec3d minpt, maxpt;
00094 
00095 }; // SbBox3d
00096 
00097 COIN_DLL_API inline int operator == (const SbBox3d & b1, const SbBox3d & b2) {
00098   return ((b1.getMin() == b2.getMin()) && (b1.getMax() == b2.getMax()));
00099 }
00100 
00101 COIN_DLL_API inline int operator != (const SbBox3d & b1, const SbBox3d & b2) {
00102   return !(b1 == b2);
00103 }
00104 
00105 #endif // !COIN_SBBOX3D_H

Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.

Generated on Mon Feb 23 16:33:08 2009 for Coin by Doxygen. 1.5.8