Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

box.h

Go to the documentation of this file.
00001 #ifndef H_BOX
00002 #define H_BOX
00003 
00004 #include <vector>
00005 #include "math3d.h"
00006 #include "sysdep.h"
00007 
00008 __CD__BEGIN
00009 
00012 class RotationState
00013 {
00014 public:
00015   RotationState(const Matrix3D& transform);
00016   Vector3D N[3];
00017   Matrix3D t;
00018 };
00019 
00021 class Box
00022 {
00023 public:
00025   Box() {}
00027   Box(float x, float y, float z, float sx, float sy, float sz) 
00028     : m_Pos(x,y,z), m_Size(sx,sy,sz), 
00029       m_Center(x+0.5f*sx,y+0.5f*sy,z+0.5f*sz) {}
00031   Box(const Vector3D& pos, const Vector3D& size) 
00032     : m_Pos(pos), m_Size(size), m_Center(pos+0.5f*size) {}
00034   Box(const Box& b) : m_Pos(b.m_Pos), m_Size(b.m_Size), m_Center(b.m_Center) {}
00035   virtual ~Box() {}
00037   const Vector3D& getPosition() const { return m_Pos; }
00039   const Vector3D& getSize() const { return m_Size; }
00041   const Vector3D& getCenter() const { return m_Center; }
00043   float getVolume() const { return m_Size.x*m_Size.y*m_Size.z; }
00045   bool intersect(const Vector3D& O, const Vector3D& D);
00047   bool intersect(const Vector3D& O, const Vector3D& D, float segmax);
00049   bool intersect(const Vector3D& O, float radius);
00051   bool intersect(const Vector3D& p) const;
00053   bool intersect(const Box& b);
00055   bool intersect(const Box& b, RotationState& rs);
00056 
00058   Vector3D m_Pos;
00060   Vector3D m_Size;
00062   Vector3D m_Center;
00063 };
00064 
00066 class Triangle
00067 {
00068 public:
00070   Triangle() {}
00072   Triangle(const Vector3D& _1, const Vector3D& _2, const Vector3D& _3);
00074   bool intersect(const Triangle& t) const;
00084   bool intersect(const Vector3D& O, const Vector3D& D, Vector3D& cp, 
00085                  float& tparm, float segmax);
00090   bool intersect(const Vector3D& O, float radius, Vector3D& cp);
00091 
00092   Vector3D v1,v2,v3;
00093   Vector3D center;
00094 };
00095 
00096 class BoxedTriangle;
00097 
00099 class BoxTreeNode : public Box
00100 {
00101 public:
00103   BoxTreeNode() : Box() {}
00105   BoxTreeNode(const Vector3D& pos, const Vector3D& size) 
00106     : Box(pos,size) {}
00108   virtual bool isLeaf() const  = 0;
00110   virtual int            getSonsNumber() = 0; 
00112   virtual BoxTreeNode*   getSon(int which) = 0;
00115   virtual int            getTrianglesNumber() = 0;
00119   virtual BoxedTriangle* getTriangle(int which) = 0;
00120 };
00121 
00123 class BoxTreeInnerNode : public BoxTreeNode
00124 {
00125 public:
00126   BoxTreeInnerNode(const Vector3D& pos, const Vector3D& size, int logdepth) 
00127     : BoxTreeNode(pos,size), m_First(NULL), m_Second(NULL), 
00128       m_logdepth(logdepth) {};
00129   virtual bool isLeaf() const { return false; }
00131   int  createSons(const Vector3D& center);
00135   void recalcBounds(Vector3D& center);
00137   int  divide(int p_depth);
00138 
00139   int getSonsNumber()
00140   {
00141     int n=0;
00142     if (m_First!=NULL) n++;
00143     if (m_Second!=NULL) n++;
00144     return n;
00145   }
00146 
00147   int getTrianglesNumber();
00148   BoxedTriangle* getTriangle(int which);
00149 
00150   BoxTreeNode* getSon(int which)
00151   {
00152     if (which==0) return m_First;
00153     if (which==1) return m_Second;
00154     return NULL;
00155   }
00156 
00157   BoxTreeNode*                m_First;
00158   BoxTreeNode*                m_Second;
00159   int                         m_logdepth;
00160   std::vector<BoxedTriangle*> m_Boxes;
00161 };
00162 
00164 class BoxedTriangle : public BoxTreeNode, public Triangle
00165 {
00166 public:
00167   BoxedTriangle(const Vector3D& _1, const Vector3D& _2, const Vector3D& _3);
00168   virtual bool isLeaf() const { return true; }
00169   int getSonsNumber() { return 0; }
00170   BoxTreeNode* getSon(int which) { return NULL; }
00171   int getTrianglesNumber() { return 1; }
00172   BoxedTriangle* getTriangle(int which)
00173   {
00174     if (which==0) return this;
00175     return NULL;
00176   }
00177 
00178 };
00179 
00180 __CD__END
00181 
00182 #endif // H_BOX

Generated at Sat Nov 18 00:15:14 2000 for coldet by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000