1 #ifndef COIN_SBBOX3S_H 2 #define COIN_SBBOX3S_H 3 4 /**************************************************************************\ 5 * Copyright (c) Kongsberg Oil & Gas Technologies AS 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are 10 * met: 11 * 12 * Redistributions of source code must retain the above copyright notice, 13 * this list of conditions and the following disclaimer. 14 * 15 * Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * Neither the name of the copyright holder nor the names of its 20 * contributors may be used to endorse or promote products derived from 21 * this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 \**************************************************************************/ 35 36 #include <Inventor/SbVec3s.h> 37 #include <Inventor/SbVec3f.h> 38 39 class SbBox3i32; 40 class SbBox3f; 41 class SbBox3d; 42 43 class COIN_DLL_API SbBox3s { 44 public: SbBox3s(void)45 SbBox3s(void) { makeEmpty(); } SbBox3s(short xmin,short ymin,short zmin,short xmax,short ymax,short zmax)46 SbBox3s(short xmin, short ymin, short zmin, short xmax, short ymax, short zmax) 47 : minpt(xmin, ymin, zmin), maxpt(xmax, ymax, zmax) { } SbBox3s(const SbVec3s & minpoint,const SbVec3s & maxpoint)48 SbBox3s(const SbVec3s & minpoint, const SbVec3s & maxpoint) 49 : minpt(minpoint), maxpt(maxpoint) { } SbBox3s(const SbBox3i32 & box)50 explicit SbBox3s(const SbBox3i32 & box) { setBounds(box); } SbBox3s(const SbBox3f & box)51 explicit SbBox3s(const SbBox3f & box) { setBounds(box); } SbBox3s(const SbBox3d & box)52 explicit SbBox3s(const SbBox3d & box) { setBounds(box); } 53 setBounds(short xmin,short ymin,short zmin,short xmax,short ymax,short zmax)54 SbBox3s & setBounds(short xmin, short ymin, short zmin, short xmax, short ymax, short zmax) 55 { minpt.setValue(xmin, ymin, zmin); maxpt.setValue(xmax, ymax, zmax); return *this; } setBounds(const SbVec3s & minpoint,const SbVec3s & maxpoint)56 SbBox3s & setBounds(const SbVec3s & minpoint, const SbVec3s & maxpoint) 57 { minpt = minpoint; maxpt = maxpoint; return *this; } 58 SbBox3s & setBounds(const SbBox3i32 & box); 59 SbBox3s & setBounds(const SbBox3f & box); 60 SbBox3s & setBounds(const SbBox3d & box); 61 getBounds(short & xmin,short & ymin,short & zmin,short & xmax,short & ymax,short & zmax)62 void getBounds(short & xmin, short & ymin, short & zmin, 63 short & xmax, short & ymax, short & zmax) const 64 { minpt.getValue(xmin, ymin, zmin); maxpt.getValue(xmax, ymax, zmax); } getBounds(SbVec3s & minpoint,SbVec3s & maxpoint)65 void getBounds(SbVec3s & minpoint, SbVec3s & maxpoint) const 66 { minpoint = minpt; maxpoint = maxpt; } 67 getMin(void)68 const SbVec3s & getMin(void) const { return minpt; } getMin(void)69 SbVec3s & getMin(void) { return minpt; } getMax(void)70 const SbVec3s & getMax(void) const { return maxpt; } getMax(void)71 SbVec3s & getMax(void) { return maxpt; } 72 73 void extendBy(const SbVec3s & pt); 74 void extendBy(const SbBox3s & box); 75 void makeEmpty(void); isEmpty(void)76 SbBool isEmpty(void) const { return (maxpt[0] < minpt[0]); } hasVolume(void)77 SbBool hasVolume(void) const 78 { return ((maxpt[0] > minpt[0]) && (maxpt[1] > minpt[1]) && (maxpt[2] > minpt[2])); } getVolume(void)79 int getVolume(void) const 80 { short dx = 0, dy = 0, dz = 0; getSize(dx, dy, dz); return (dx * dy * dz); } 81 82 SbBool intersect(const SbVec3s & pt) const; 83 SbBool intersect(const SbBox3s & box) const; 84 SbVec3f getClosestPoint(const SbVec3f & pt) const; 85 getCenter(void)86 SbVec3f getCenter(void) const 87 { return SbVec3f((minpt[0]+maxpt[0])*0.5f, (minpt[1]+maxpt[1])*0.5f, (minpt[2]+maxpt[2])*0.5f); } getOrigin(short & originX,short & originY,short & originZ)88 void getOrigin(short & originX, short & originY, short & originZ) const 89 { minpt.getValue(originX, originY, originZ); } getSize(short & sizeX,short & sizeY,short & sizeZ)90 void getSize(short & sizeX, short & sizeY, short & sizeZ) const 91 { if (isEmpty()) { sizeX = sizeY = sizeZ = 0; } 92 else { sizeX = maxpt[0] - minpt[0]; sizeY = maxpt[1] - minpt[1]; sizeZ = maxpt[2] - minpt[2]; } } getSize(void)93 SbVec3s getSize(void) const { 94 SbVec3s v; 95 this->getSize(v[0], v[1],v[2]); 96 return v; 97 } 98 99 protected: 100 SbVec3s minpt, maxpt; 101 102 }; // SbBox3s 103 104 COIN_DLL_API inline int operator == (const SbBox3s & b1, const SbBox3s & b2) { 105 return ((b1.getMin() == b2.getMin()) && (b1.getMax() == b2.getMax())); 106 } 107 108 COIN_DLL_API inline int operator != (const SbBox3s & b1, const SbBox3s & b2) { 109 return !(b1 == b2); 110 } 111 112 #endif // !COIN_SBBOX3S_H 113