OPC_TreeBuilders.h
Go to the documentation of this file.
00001 
00002 /*
00003  *      OPCODE - Optimized Collision Detection
00004  *      Copyright (C) 2001 Pierre Terdiman
00005  *      Homepage: http://www.codercorner.com/Opcode.htm
00006  */
00008 
00010 
00016 
00017 
00019 // Include Guard
00020 #ifndef __OPC_TREEBUILDERS_H__
00021 #define __OPC_TREEBUILDERS_H__
00022 
00024         enum SplittingRules
00025         {
00026                 // Primitive split
00027                 SPLIT_LARGEST_AXIS              = (1<<0),               
00028                 SPLIT_SPLATTER_POINTS   = (1<<1),               
00029                 SPLIT_BEST_AXIS                 = (1<<2),               
00030                 SPLIT_BALANCED                  = (1<<3),               
00031                 SPLIT_FIFTY                             = (1<<4),               
00032                 // Node split
00033                 SPLIT_GEOM_CENTER               = (1<<5),               
00034                 //
00035                 SPLIT_FORCE_DWORD               = 0x7fffffff
00036         };
00037 
00039         struct OPCODE_API BuildSettings
00040         {
00041                 inline_ BuildSettings() : mLimit(1), mRules(SPLIT_FORCE_DWORD)  {}
00042 
00043                 udword  mLimit;         
00044                 udword  mRules;         
00045         };
00046 
00047         class OPCODE_API AABBTreeBuilder
00048         {
00049                 public:
00051                                                                                                         AABBTreeBuilder() :
00052                                                                                                                 mNbPrimitives(0),
00053                                                                                                                 mNodeBase(null),
00054                                                                                                                 mCount(0),
00055                                                                                                                 mNbInvalidSplits(0)             {}
00057                 virtual                                                                         ~AABBTreeBuilder()                      {}
00058 
00060 
00067 
00068                 virtual                                         bool                    ComputeGlobalBox(const udword* primitives, udword nb_prims, AABB& global_box)   const   = 0;
00069 
00071 
00077 
00078                 virtual                                         float                   GetSplittingValue(udword index, udword axis)    const   = 0;
00079 
00081 
00089 
00090                 virtual                                         float                   GetSplittingValue(const udword* primitives, udword nb_prims, const AABB& global_box, udword axis)       const
00091                                                                                                         {
00092                                                                                                                 // Default split value = middle of the axis (using only the box)
00093                                                                                                                 return global_box.GetCenter(axis);
00094                                                                                                         }
00095 
00097 
00104 
00105                 virtual                                         BOOL                    ValidateSubdivision(const udword* primitives, udword nb_prims, const AABB& global_box)
00106                                                                                                         {
00107                                                                                                                 // Check the user-defined limit
00108                                                                                                                 if(nb_prims<=mSettings.mLimit)  return FALSE;
00109 
00110                                                                                                                 return TRUE;
00111                                                                                                         }
00112 
00113                                                                         BuildSettings   mSettings;                      
00114                                                                         udword                  mNbPrimitives;          
00115                                                                         void*                   mNodeBase;                      
00116                 // Stats
00117                 inline_                                         void                    SetCount(udword nb)                             { mCount=nb;                            }
00118                 inline_                                         void                    IncreaseCount(udword nb)                { mCount+=nb;                           }
00119                 inline_                                         udword                  GetCount()                              const   { return mCount;                        }
00120                 inline_                                         void                    SetNbInvalidSplits(udword nb)   { mNbInvalidSplits=nb;          }
00121                 inline_                                         void                    IncreaseNbInvalidSplits()               { mNbInvalidSplits++;           }
00122                 inline_                                         udword                  GetNbInvalidSplits()    const   { return mNbInvalidSplits;      }
00123 
00124                 private:
00125                                                                         udword                  mCount;                         
00126                                                                         udword                  mNbInvalidSplits;       
00127         };
00128 
00129         class OPCODE_API AABBTreeOfVerticesBuilder : public AABBTreeBuilder
00130         {
00131                 public:
00133                                                                                                         AABBTreeOfVerticesBuilder() : mVertexArray(null)        {}
00135                 virtual                                                                         ~AABBTreeOfVerticesBuilder()                                            {}
00136 
00137                 override(AABBTreeBuilder)       bool                    ComputeGlobalBox(const udword* primitives, udword nb_prims, AABB& global_box)   const;
00138                 override(AABBTreeBuilder)       float                   GetSplittingValue(udword index, udword axis)                                                                    const;
00139                 override(AABBTreeBuilder)       float                   GetSplittingValue(const udword* primitives, udword nb_prims, const AABB& global_box, udword axis)       const;
00140 
00141                 const                                           Point*                  mVertexArray;           
00142         };
00143 
00144         class OPCODE_API AABBTreeOfAABBsBuilder : public AABBTreeBuilder
00145         {
00146                 public:
00148                                                                                                         AABBTreeOfAABBsBuilder() : mAABBArray(null)     {}
00150                 virtual                                                                         ~AABBTreeOfAABBsBuilder()                                       {}
00151 
00152                 override(AABBTreeBuilder)       bool                    ComputeGlobalBox(const udword* primitives, udword nb_prims, AABB& global_box)   const;
00153                 override(AABBTreeBuilder)       float                   GetSplittingValue(udword index, udword axis)                                                                    const;
00154 
00155                 const                                           AABB*                   mAABBArray;                     
00156         };
00157 
00158         class OPCODE_API AABBTreeOfTrianglesBuilder : public AABBTreeBuilder
00159         {
00160                 public:
00162                                                                                                         AABBTreeOfTrianglesBuilder() : mIMesh(null)                                                                             {}
00164                 virtual                                                                         ~AABBTreeOfTrianglesBuilder()                                                                                                   {}
00165 
00166                 override(AABBTreeBuilder)       bool                    ComputeGlobalBox(const udword* primitives, udword nb_prims, AABB& global_box)   const;
00167                 override(AABBTreeBuilder)       float                   GetSplittingValue(udword index, udword axis)                                                                    const;
00168                 override(AABBTreeBuilder)       float                   GetSplittingValue(const udword* primitives, udword nb_prims, const AABB& global_box, udword axis)       const;
00169 
00170                 const                           MeshInterface*                  mIMesh;                 
00171         };
00172 
00173 #endif // __OPC_TREEBUILDERS_H__


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:56