![]() |
http://www.sim.no/ http://www.coin3d.org/ |
00001 #ifndef COIN_SBBOX3F_H 00002 #define COIN_SBBOX3F_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 <stdio.h> 00028 00029 #include <Inventor/SbVec3f.h> 00030 00031 class SbBox3d; 00032 class SbBox3i32; 00033 class SbBox3s; 00034 00035 class SbMatrix; 00036 00037 class COIN_DLL_API SbBox3f { 00038 public: 00039 SbBox3f(void) { makeEmpty(); } 00040 SbBox3f(float xmin, float ymin, float zmin, float xmax, float ymax, float zmax) 00041 : minpt(xmin, ymin, zmin), maxpt(xmax, ymax, zmax) { } 00042 SbBox3f(const SbVec3f & minpoint, const SbVec3f & maxpoint) 00043 : minpt(minpoint), maxpt(maxpoint) { } 00044 explicit SbBox3f(const SbBox3d & box) { setBounds(box); } 00045 explicit SbBox3f(const SbBox3s & box) { setBounds(box); } 00046 explicit SbBox3f(const SbBox3i32 & box) { setBounds(box); } 00047 00048 SbBox3f & setBounds(float xmin, float ymin, float zmin, float xmax, float ymax, float zmax) 00049 { minpt.setValue(xmin, ymin, zmin); maxpt.setValue(xmax, ymax, zmax); return *this; } 00050 SbBox3f & setBounds(const SbVec3f & minpoint, const SbVec3f & maxpoint) 00051 { minpt = minpoint; maxpt = maxpoint; return *this; } 00052 SbBox3f & setBounds(const SbBox3d & box); 00053 SbBox3f & setBounds(const SbBox3s & box); 00054 SbBox3f & setBounds(const SbBox3i32 & box); 00055 00056 void getBounds(float & xmin, float & ymin, float & zmin, float & xmax, float & ymax, float & zmax) const 00057 { minpt.getValue(xmin, ymin, zmin); maxpt.getValue(xmax, ymax, zmax); } 00058 void getBounds(SbVec3f & minpoint, SbVec3f & maxpoint) const 00059 { minpoint = minpt; maxpoint = maxpt; } 00060 00061 const SbVec3f & getMin(void) const { return minpt; } 00062 SbVec3f & getMin(void) { return minpt; } 00063 const SbVec3f & getMax(void) const { return maxpt; } 00064 SbVec3f & getMax(void) { return maxpt; } 00065 00066 void extendBy(const SbVec3f & pt); 00067 void extendBy(const SbBox3f & box); 00068 void transform(const SbMatrix & 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 float getVolume(void) const 00074 { float dx = 0.0f, dy = 0.0f, dz = 0.0f; getSize(dx, dy, dz); return (dx * dy * dz); } 00075 00076 SbBool intersect(const SbVec3f & pt) const; 00077 SbBool intersect(const SbBox3f & box) const; 00078 SbVec3f getClosestPoint(const SbVec3f & point) const; 00079 SbBool outside(const SbMatrix & mvp, int & cullbits) const; 00080 00081 SbVec3f getCenter(void) const { return (minpt + maxpt) * 0.5f; } 00082 void getOrigin(float & originX, float & originY, float & originZ) const 00083 { minpt.getValue(originX, originY, originZ); } 00084 void getSize(float & sizeX, float & sizeY, float & sizeZ) const 00085 { if (isEmpty()) { sizeX = sizeY = sizeZ = 0; } 00086 else { sizeX = maxpt[0] - minpt[0]; sizeY = maxpt[1] - minpt[1]; sizeZ = maxpt[2] - minpt[2]; } } 00087 00088 SbVec3f getSize(void) const { 00089 SbVec3f v; 00090 this->getSize(v[0], v[1], v[2]); 00091 return v; 00092 } 00093 void getSpan(const SbVec3f & dir, float & dmin, float & dmax) const; 00094 00095 void print(FILE * file) const; 00096 00097 private: 00098 SbVec3f minpt, maxpt; 00099 00100 }; // SbBox3f 00101 00102 COIN_DLL_API inline int operator == (const SbBox3f & b1, const SbBox3f & b2) { 00103 return ((b1.getMin() == b2.getMin()) && (b1.getMax() == b2.getMax())); 00104 } 00105 00106 COIN_DLL_API inline int operator != (const SbBox3f & b1, const SbBox3f & b2) { 00107 return !(b1 == b2); 00108 } 00109 00110 #endif // !COIN_SBBOX3F_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.