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

SbBox3s.h
00001 #ifndef COIN_SBBOX3S_H
00002 #define COIN_SBBOX3S_H
00003 
00004 /**************************************************************************\
00005  *
00006  *  This file is part of the Coin 3D visualization library.
00007  *  Copyright (C) by Kongsberg Oil & Gas Technologies.
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 Kongsberg Oil & Gas Technologies
00018  *  about acquiring a Coin Professional Edition License.
00019  *
00020  *  See http://www.coin3d.org/ for more information.
00021  *
00022  *  Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
00023  *  http://www.sim.no/  sales@sim.no  coin-support@coin3d.org
00024  *
00025 \**************************************************************************/
00026 
00027 #include <Inventor/SbVec3s.h>
00028 #include <Inventor/SbVec3f.h>
00029 
00030 class SbBox3i32;
00031 class SbBox3f;
00032 class SbBox3d;
00033 
00034 class COIN_DLL_API SbBox3s {
00035 public:
00036   SbBox3s(void) { makeEmpty(); }
00037   SbBox3s(short xmin, short ymin, short zmin, short xmax, short ymax, short zmax)
00038     : minpt(xmin, ymin, zmin), maxpt(xmax, ymax, zmax) { }
00039   SbBox3s(const SbVec3s & minpoint, const SbVec3s & maxpoint)
00040     : minpt(minpoint), maxpt(maxpoint) { }
00041   explicit SbBox3s(const SbBox3i32 & box) { setBounds(box); }
00042   explicit SbBox3s(const SbBox3f & box) { setBounds(box); }
00043   explicit SbBox3s(const SbBox3d & box) { setBounds(box); }
00044 
00045   SbBox3s & setBounds(short xmin, short ymin, short zmin, short xmax, short ymax, short zmax)
00046     { minpt.setValue(xmin, ymin, zmin); maxpt.setValue(xmax, ymax, zmax); return *this; }
00047   SbBox3s & setBounds(const SbVec3s & minpoint, const SbVec3s & maxpoint)
00048     { minpt = minpoint; maxpt = maxpoint; return *this; }
00049   SbBox3s & setBounds(const SbBox3i32 & box);
00050   SbBox3s & setBounds(const SbBox3f & box);
00051   SbBox3s & setBounds(const SbBox3d & box);
00052 
00053   void getBounds(short & xmin, short & ymin, short & zmin,
00054                  short & xmax, short & ymax, short & zmax) const
00055     { minpt.getValue(xmin, ymin, zmin); maxpt.getValue(xmax, ymax, zmax); }
00056   void getBounds(SbVec3s & minpoint, SbVec3s & maxpoint) const
00057     { minpoint = minpt; maxpoint = maxpt; }
00058 
00059   const SbVec3s & getMin(void) const { return minpt; }
00060   SbVec3s & getMin(void) { return minpt; }
00061   const SbVec3s & getMax(void) const { return maxpt; }
00062   SbVec3s & getMax(void) { return maxpt; }
00063 
00064   void extendBy(const SbVec3s & pt);
00065   void extendBy(const SbBox3s & box);
00066   void makeEmpty(void);
00067   SbBool isEmpty(void) const { return (maxpt[0] < minpt[0]); }
00068   SbBool hasVolume(void) const
00069     { return ((maxpt[0] > minpt[0]) && (maxpt[1] > minpt[1]) && (maxpt[2] > minpt[2])); }
00070   int getVolume(void) const
00071     { short dx = 0, dy = 0, dz = 0; getSize(dx, dy, dz); return (dx * dy * dz); }
00072 
00073   SbBool intersect(const SbVec3s & pt) const;
00074   SbBool intersect(const SbBox3s & box) const;
00075   SbVec3f getClosestPoint(const SbVec3f & pt) const;
00076 
00077   SbVec3f getCenter(void) const
00078     { return SbVec3f((minpt[0]+maxpt[0])*0.5f, (minpt[1]+maxpt[1])*0.5f, (minpt[2]+maxpt[2])*0.5f); }
00079   void getOrigin(short & originX, short & originY, short & originZ) const
00080     { minpt.getValue(originX, originY, originZ); }
00081   void getSize(short & sizeX, short & sizeY, short & sizeZ) const
00082     { if (isEmpty()) { sizeX = sizeY = sizeZ = 0; }
00083       else { sizeX = maxpt[0] - minpt[0]; sizeY = maxpt[1] - minpt[1]; sizeZ = maxpt[2] - minpt[2]; } }
00084 
00085 protected:
00086   SbVec3s minpt, maxpt;
00087 
00088 }; // SbBox3s
00089 
00090 COIN_DLL_API inline int operator == (const SbBox3s & b1, const SbBox3s & b2) {
00091   return ((b1.getMin() == b2.getMin()) && (b1.getMax() == b2.getMax()));
00092 }
00093 
00094 COIN_DLL_API inline int operator != (const SbBox3s & b1, const SbBox3s & b2) {
00095   return !(b1 == b2);
00096 }
00097 
00098 #endif // !COIN_SBBOX3S_H

Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.

Generated on Thu Apr 28 2011 03:43:02 for Coin by Doxygen 1.7.4.