ColDopTree.h

00001 
00002 //***************************************************************************
00003 //                              DopTree
00004 //***************************************************************************
00005 //  Copyright (C):
00006 //***************************************************************************
00007 //CVSId: "@(#)$Id: ColDopTree.h,v 1.14 2005/01/10 15:29:28 weller Exp $"
00008 //***************************************************************************
00009 
00010 
00011 #ifndef ColDopTree_H
00012 #define ColDopTree_H
00013 #if defined(__sgi) || defined(_WIN32)
00014 #pragma once
00015 #endif
00016 
00017 
00018 //---------------------------------------------------------------------------
00019 //  Includes
00020 //---------------------------------------------------------------------------
00021 #include <OpenSG/OSGConfig.h>
00022 #include <OpenSG/OSGGeoProperty.h>
00023 #include <OpenSG/OSGVector.h>
00024 #include <OpenSG/OSGQuaternion.h>
00025 
00026 #include <Collision.h>
00027 #include <ColExceptions.h>
00028 #include <ColIntersect.h>                           // for MaxNVertices
00029 
00030 #ifdef _WIN32
00031 #ifdef max
00032 #undef max
00033 #endif
00034 #ifdef min
00035 #undef min
00036 #endif
00037 #endif
00038 
00039 using namespace std;
00040 using osg::Vec3f;
00041 using osg::Pnt3f;
00042 
00043 namespace col {
00044 
00045 //---------------------------------------------------------------------------
00046 //  Forward References
00047 //---------------------------------------------------------------------------
00048 
00049 struct DopTransform;
00050 struct DopNode;
00051 
00052 
00053 //---------------------------------------------------------------------------
00054 //  Constants
00055 //---------------------------------------------------------------------------
00056 
00057 
00058 //***************************************************************************
00059 //  Dop
00060 //***************************************************************************
00061 
00062 struct COL_EXPORTIMPORT Dop
00063 {
00065     static const unsigned int NumOri = 24;
00066 
00067     // This define is only needed for DopTree::init().
00068 #define DOPTREE_NUM_ORI 24
00069 
00070     float d[NumOri];
00071 
00072     Dop();
00073     Dop( const Dop &source );
00074     Dop( const Pnt3f &pnt );
00075     Dop( const Dop *source );
00076     void setValues( float val[NumOri] );
00077 
00078     void    operator += ( const Dop &other );
00079     void    operator += ( const Pnt3f &pnt );
00080     void    operator += ( float delta );
00081     void    operator -= ( const Dop &other );
00082     void    operator  = ( const Pnt3f &pnt );
00083     void    operator  = ( const Dop &other );
00084     void    operator  = ( float f );
00085     float & operator [] ( const unsigned int k );
00086     float   operator [] ( const unsigned int k ) const;
00087     Dop     operator *  ( const DopTransform &tf ) const;
00088     bool    operator == ( const Dop &other ) const;
00089     bool    operator != ( const Dop &other ) const;
00090 
00091     float max( unsigned int *k = NULL ) const;
00092     bool overlap( const Dop &other ) const;
00093     bool isDegenerate( void ) const;
00094     void extend( float delta );
00095 
00096     static unsigned int mostParallelOri( const Vec3f &diag, Vec3f *ori = NULL );
00097 
00098     void print( void ) const;
00099     osg::NodePtr getGeom( void ) const;
00100 
00101 };
00102 
00103 //***************************************************************************
00104 //  ElemDop
00105 //***************************************************************************
00106 
00107 struct COL_EXPORTIMPORT ElemDop
00108 {
00109     Dop d;
00110     const osg::MFPnt3f *points;
00111     unsigned int pgon[MaxNVertices];            // vertices of enclosed polygon
00112     unsigned int nvertices;
00113     osg::GeometryPtr geo;
00114     unsigned int index;                         // OSG index of polygon
00115     Pnt3f center;                               // center of polygon
00116     Dop cc;                                     // center projected onto Ori
00117 
00118     bool operator <  ( const ElemDop &other ) const;
00119     bool operator >  ( const ElemDop &other ) const;
00120     bool operator <= ( const ElemDop &other ) const;
00121     bool operator >= ( const ElemDop &other ) const;
00122     void operator =  ( const ElemDop &other );
00123 
00124     static void setSortIndex( unsigned int index );
00125 
00126     static unsigned int sortindex;
00127 
00128 private:
00129     bool operator == ( const ElemDop &other ) const;
00130 };
00131 
00132 
00133 
00134 //**************************************************************************
00135 // DopTransform
00136 //**************************************************************************
00137 
00138 struct COL_EXPORTIMPORT DopTransform
00139 {
00140     DopTransform();
00141     DopTransform( const osg::Matrix &m );
00142     DopTransform( const osg::Quaternion &q );
00143     void operator = ( const osg::Matrix &m );
00144     void operator = ( const osg::Quaternion &q );
00145     void print( void ) const;
00146 
00147     Dop operator * ( const Dop &dop ) const;
00148 
00150     Vec3f           c[Dop::NumOri];
00152     float           o[Dop::NumOri];
00154     unsigned int    Bb[Dop::NumOri][3];
00155 };
00156 
00157 
00158 
00159 //***************************************************************************
00160 //  DopNode
00161 //***************************************************************************
00162 
00163 typedef std::vector<const DopNode*> DopNodeList;
00164 
00165 struct COL_EXPORTIMPORT DopNode
00166 {
00167                     DopNode();
00168 
00169     bool            check( DopNode &other, Data *data );
00170 
00171     bool check_down( const DopNodeList &other, Data *data, const DopTransform &dt) const;
00172     bool check_stay( const DopNodeList &other, Data *data, const Dop &e, const DopTransform &dt ) const;
00173 
00175     Dop             d;
00178     DopNode*        child[2];
00180     const osg::MFPnt3f *points;
00181     unsigned int    pgon[3];
00182     unsigned int    nvertices;
00184     osg::GeometryPtr geo;
00185     unsigned int    index;
00186 
00187     // for debugging and research
00188     void            print( int depth, bool print_dops ) const;
00189     unsigned int    numFaces( void ) const;
00190     osg::NodePtr    getGeom( int level ) const;
00191 
00192 protected:
00193 
00194     void            getGeom( int level, osg::NodePtr &root ) const;
00195 
00196     static const int MaxPrintRecursions = 80;           // for print()
00197 };
00198 
00199 
00200 // TODO: Klassen DopNode und DopTree mergen!
00201 
00202 
00203 
00204 //***************************************************************************
00205 //  DopTree
00206 //***************************************************************************
00207 
00208 
00209 class COL_EXPORTIMPORT DopTree
00210 {
00211 
00212 friend struct Dop;
00213 friend struct DopTransform;
00214 
00215 //---------------------------------------------------------------------------
00216 //  Public Instance methods
00217 //---------------------------------------------------------------------------
00218 
00219 public:
00220 
00221 /*------------------ constructors & destructors ---------------------------*/
00222 
00223     DopTree( );
00224     DopTree( osg::NodePtr &node, vector<const osg::MFPnt3f *> &points );
00225     virtual ~DopTree() throw();
00226 
00227 //---------------------------------------------------------------------------
00228 //  Class variables
00229 //---------------------------------------------------------------------------
00231     static const unsigned int NumPnts = 2*Dop::NumOri-4;
00232 
00233 /*------------------------ collsion check ---------------------------------*/
00234 
00235     bool check( const DopTree &other, Data *data ) const;
00236 
00237 /*-------------------------- debugging / statistics -----------------------*/
00238 
00239     void printTree( bool print_dops = false ) const;
00240     osg::NodePtr getGeom( int level ) const;
00241 
00242 
00243 //---------------------------------------------------------------------------
00244 //  Public Class methods
00245 //---------------------------------------------------------------------------
00246 
00247     static void init( void );
00248 
00249     static void polyFromHalfspaces( const Vec3f halfspace[Dop::NumOri], const Dop &d,
00250                                     Pnt3f pnt[NumPnts], unsigned int *npnts,
00251                                     unsigned int face[Dop::NumOri][Dop::NumOri],
00252                                     unsigned int face_nv[Dop::NumOri] );
00253 
00254     static int intersectThreePlanes( const Vec3f &a, float da,
00255                                      const Vec3f &b, float db,
00256                                      const Vec3f &c, float dc,
00257                                      Pnt3f *q );
00258 
00259     static void printVtx2Ori( void );
00260     static void printPnt( void );
00261     static void printOri( void );
00262 
00263 
00264 //---------------------------------------------------------------------------
00265 //  Instance variables
00266 //---------------------------------------------------------------------------
00267 
00268     DopNode             m_doptree;
00269 
00270 
00271 protected:
00272 
00274     static const unsigned int M_MaxDepth = 500;
00275 
00277     static Vec3f m_Ori[Dop::NumOri];
00278 
00280     static Pnt3f m_Pnt[NumPnts];
00281 
00283     static unsigned int m_Vtx2Ori[NumPnts][3];
00284 
00285 //---------------------------------------------------------------------------
00286 //  Private Instance methods
00287 //---------------------------------------------------------------------------
00288 
00289 protected:
00290 
00291     void constructHier( osg::NodePtr &node, vector<const osg::MFPnt3f *> &points );
00292     void constructHier( vector<ElemDop> &elem,
00293                         DopNode *bv, unsigned int depth );
00294     void assignElem( const ElemDop &elem,
00295                      vector<ElemDop> &elem1, unsigned int *nelems1, Dop *dop1,
00296                      vector<ElemDop> &elem2, unsigned int *nelems2, Dop *dop2,
00297                      unsigned int index );
00298 
00299     // prohibit copy constructor & assignment
00300     DopTree( const DopTree &source );
00301     DopTree& operator = ( const DopTree &source );
00302 
00303 //---------------------------------------------------------------------------
00304 //  Private Class methods
00305 //---------------------------------------------------------------------------
00306 
00307 };
00308 
00309 
00310 
00311 } // namespace col
00312 
00313 #endif /* ColDopTree_H */
00314 

Generated on Tue Oct 16 18:12:21 2007 for CollDet by  doxygen 1.5.2