ColBoxtree.h

00001 
00002 //***************************************************************************
00003 //                              Boxtree
00004 //***************************************************************************
00005 //  Copyright (C):
00006 //***************************************************************************
00007 //CVSId: "@(#)$Id$"
00008 //***************************************************************************
00009 
00010 
00011 #ifndef Boxtree_H
00012 #define Boxtree_H
00013 #if defined(__sgi) || defined(_WIN32)
00014 #pragma once
00015 #endif
00016 
00017 //---------------------------------------------------------------------------
00018 //  Includes
00019 //---------------------------------------------------------------------------
00020 
00021 #include <limits>
00022 #include <vector>
00023 
00024 #include <OpenSG/OSGConfig.h>
00025 #include <OpenSG/OSGGeoProperty.h>
00026 #include <OpenSG/OSGGeometry.h>
00027 #include <OpenSG/OSGVector.h>
00028 
00029 #include <Collision.h>
00030 
00031 using namespace std;
00032 using osg::Pnt3f;
00033 
00034 
00035 namespace col {
00036 
00037 //---------------------------------------------------------------------------
00038 //  Forward Declarations
00039 //---------------------------------------------------------------------------
00040 
00041 struct ElemBox;
00042 struct BoxtreePrecomp;
00043 
00044 
00045 
00046 //***************************************************************************
00047 //  Boxtree
00048 //***************************************************************************
00049 
00050 class COL_EXPORTIMPORT Boxtree
00051 {
00052 
00053 public:
00054 
00055 //---------------------------------------------------------------------------
00056 //  Public Class methods and constants
00057 //---------------------------------------------------------------------------
00058 
00060     static const unsigned int M_MaxNVertices = 4;
00061 
00063     static const unsigned int M_MaxDepth = 100;
00064 
00073     static const float M_EmptyGood /*=0.15*/;
00074     
00076     static const unsigned int M_InnerNode = 0x8000;
00077 
00078 //---------------------------------------------------------------------------
00079 //  Public Instance methods
00080 //---------------------------------------------------------------------------
00081 
00082     Boxtree( const osg::NodePtr &node,
00083              vector<const osg::MFPnt3f *> &points,
00084              unsigned int maxdepth = M_MaxDepth,
00085              float emptygood = M_EmptyGood );
00086 
00087     bool check( const Boxtree &other,
00088                 const osg::NodePtr &e, const osg::NodePtr &f,
00089                 Data *data) const;
00090 
00091     typedef enum { PRINT_HUMAN, PRINT_DOT } FormatE;
00092 
00093     void printTree( osg::NodePtr node, FILE * outf = NULL,
00094                     const FormatE format = PRINT_HUMAN ) const;
00095 
00096     void stats( const osg::NodePtr &node, 
00097                 unsigned int *n_leaves, unsigned int *n_nodes,
00098                 unsigned int *n_shrinks,
00099                 unsigned int *emptyborder, unsigned int emptyb_size,
00100                 unsigned int depthhistogram[M_MaxDepth] ) const;
00101 
00102 //---------------------------------------------------------------------------
00103 //  Instance variables
00104 //---------------------------------------------------------------------------
00105 
00106 protected:
00107 
00112     unsigned int m_cutplane;
00113     osg::GeometryPtr geom;   // can't put that in a union :(
00114     union
00115     {
00116         // Data for inner nodes
00117         struct
00118         {
00122             Boxtree *m_left, *m_right;
00123             float m_cutp;               
00124             float m_cutr;               
00125         } ;
00126 
00127         // Data for leaves
00128         struct
00129         {
00135             unsigned int    m_index;
00139             const osg::MFPnt3f *points;
00140             unsigned int    m_pgon[M_MaxNVertices];
00141         } ;
00142     };
00143 
00144 //---------------------------------------------------------------------------
00145 //  Private Instance methods
00146 //---------------------------------------------------------------------------
00147 
00148 protected:
00149 
00150     Boxtree( vector<ElemBox> elems[3],
00151              const unsigned int in, const unsigned int left, const unsigned int right,
00152              const Pnt3f &low, const Pnt3f &high,
00153              unsigned int depth, float emptygood,
00154              unsigned int *max_depth_reached,
00155              unsigned int *brute_force_splits );
00156     void build( vector<ElemBox> elems[3],
00157                 const unsigned int in, const unsigned int left, const unsigned int right,
00158                 const Pnt3f &low, const Pnt3f &high,
00159                 unsigned int depth, float emptygood,
00160                 unsigned int *max_depth_reached,
00161                 unsigned int *brute_force_splits );
00162     float trySplit( vector<ElemBox> & elem,
00163                    const int left, const int right,
00164                    const Pnt3f &low, const Pnt3f &high, int coord,
00165                    float *c, float *cr, int *splitindex ) const;
00166 
00167     bool check( const BoxtreePrecomp &precomp, const Boxtree *other,
00168                      float const * const e, float const * const f,
00169                 // const float *elow, const float *ehigh,
00170                 // const float *flow, const float *fhigh,
00171                 Data *data ) const;
00172 
00173     bool check( const BoxtreePrecomp &precomp, const Boxtree *other,
00174                      float const * const e, float const * const f, bool allpolygons,
00175                 // const float *elow, const float *ehigh,
00176                 // const float *flow, const float *fhigh,
00177                 Data *data ) const;
00178 
00179     void printTree( Pnt3f low, Pnt3f high, unsigned int depth,
00180                     FILE * outf, const FormatE format ) const;
00181     void stats( const Pnt3f low, const Pnt3f high,
00182                 unsigned int *n_leaves, unsigned int *n_nodes,
00183                 unsigned int *n_shrinks,
00184                 unsigned int *emptyborder, unsigned int emptyb_size,
00185                 float truevol[6], const osg::MFPnt3f *points,
00186                 unsigned int depthhistogram[M_MaxDepth],
00187                 unsigned int depth ) const;
00188 
00189 private:
00190 
00191     // prohibit certain methods
00192     ~Boxtree() throw();
00193     Boxtree( const Boxtree &source );
00194     Boxtree& operator = ( const Boxtree &source );
00195     //explicit Boxtree( const OTHER_Boxtree &source );
00196     bool operator == ( const Boxtree &other ) const;
00197     bool operator != ( const Boxtree &other ) const;
00198 
00199 };
00200 
00201 //***************************************************************************
00202 //  BoxtreePrecomp
00203 //***************************************************************************
00204 
00205 
00206 struct COL_EXPORTIMPORT BoxtreePrecomp
00207 {
00211     float m_b[3][3];
00212     bool m_b_gt_0[3][3];                
00213 
00214     BoxtreePrecomp( const osg::Matrix &m );
00215 };
00216 
00217 
00218 
00219 //***************************************************************************
00220 //  ElemBox
00221 //***************************************************************************
00222 
00223 struct COL_EXPORTIMPORT ElemBox
00224 {
00225     Pnt3f m_low, m_high;                        // low and high of box
00226     const osg::MFPnt3f *points;
00227     unsigned int m_pgon[Boxtree::M_MaxNVertices];// vertices of enclosed polygon
00228     unsigned int m_nvertices;
00229     osg::GeometryPtr geom;
00230     unsigned int m_index;                       // OSG index of polygon
00231     Pnt3f m_center;                             // center of polygon
00232 
00233     ElemBox();
00234     ElemBox( const osg::FaceIterator &fi, const osg::MFPnt3f *points );
00235     void set( const osg::FaceIterator &fi, const osg::MFPnt3f *points );
00236 
00237     void operator =  ( const ElemBox &source );
00238     bool operator == ( const ElemBox &other ) const;
00239 
00240     static
00241     void calcBox( const vector<ElemBox> &elem, const int left, const int right,
00242                   Pnt3f *low, Pnt3f *high );
00243 };
00244 
00245 
00246 
00247 
00248 } // namespace col
00249 
00250 #endif /* Boxtree_H */
00251 

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