OPC_TreeBuilders.cpp
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 
00027 
00028 
00030 
00038 
00039 
00041 
00049 
00050 
00052 // Precompiled Header
00053 #include "Stdafx.h"
00054 
00055 using namespace Opcode;
00056 
00058 
00065 
00066 bool AABBTreeOfAABBsBuilder::ComputeGlobalBox(const udword* primitives, udword nb_prims, AABB& global_box) const
00067 {
00068         // Checkings
00069         if(!primitives || !nb_prims)    return false;
00070 
00071         // Initialize global box
00072         global_box = mAABBArray[primitives[0]];
00073 
00074         // Loop through boxes
00075         for(udword i=1;i<nb_prims;i++)
00076         {
00077                 // Update global box
00078                 global_box.Add(mAABBArray[primitives[i]]);
00079         }
00080         return true;
00081 }
00082 
00084 
00090 
00091 float AABBTreeOfAABBsBuilder::GetSplittingValue(udword index, udword axis) const
00092 {
00093         // For an AABB, the splitting value is the middle of the given axis,
00094         // i.e. the corresponding component of the center point
00095         return mAABBArray[index].GetCenter(axis);
00096 }
00097 
00099 
00106 
00107 bool AABBTreeOfTrianglesBuilder::ComputeGlobalBox(const udword* primitives, udword nb_prims, AABB& global_box) const
00108 {
00109         // Checkings
00110         if(!primitives || !nb_prims)    return false;
00111 
00112         // Initialize global box
00113         Point Min(MAX_FLOAT, MAX_FLOAT, MAX_FLOAT);
00114         Point Max(MIN_FLOAT, MIN_FLOAT, MIN_FLOAT);
00115 
00116         // Loop through triangles
00117         VertexPointers VP;
00118         while(nb_prims--)
00119         {
00120                 // Get current triangle-vertices
00121                 mIMesh->GetTriangle(VP, *primitives++);
00122                 // Update global box
00123                 Min.Min(*VP.Vertex[0]).Min(*VP.Vertex[1]).Min(*VP.Vertex[2]);
00124                 Max.Max(*VP.Vertex[0]).Max(*VP.Vertex[1]).Max(*VP.Vertex[2]);
00125         }
00126         global_box.SetMinMax(Min, Max);
00127         return true;
00128 }
00129 
00131 
00137 
00138 float AABBTreeOfTrianglesBuilder::GetSplittingValue(udword index, udword axis) const
00139 {
00140 /*      // Compute center of triangle
00141         Point Center;
00142         mTriList[index].Center(mVerts, Center);
00143         // Return value
00144         return Center[axis];*/
00145 
00146         // Compute correct component from center of triangle
00147 //      return  (mVerts[mTriList[index].mVRef[0]][axis]
00148 //                      +mVerts[mTriList[index].mVRef[1]][axis]
00149 //                      +mVerts[mTriList[index].mVRef[2]][axis])*INV3;
00150 
00151         VertexPointers VP;
00152         mIMesh->GetTriangle(VP, index);
00153 
00154         // Compute correct component from center of triangle
00155         return  ((*VP.Vertex[0])[axis]
00156                         +(*VP.Vertex[1])[axis]
00157                         +(*VP.Vertex[2])[axis])*INV3;
00158 }
00159 
00161 
00169 
00170 float AABBTreeOfTrianglesBuilder::GetSplittingValue(const udword* primitives, udword nb_prims, const AABB& global_box, udword axis)     const
00171 {
00172         if(mSettings.mRules&SPLIT_GEOM_CENTER)
00173         {
00174                 // Loop through triangles
00175                 float SplitValue = 0.0f;
00176                 VertexPointers VP;
00177                 for(udword i=0;i<nb_prims;i++)
00178                 {
00179                         // Get current triangle-vertices
00180                         mIMesh->GetTriangle(VP, primitives[i]);
00181                         // Update split value
00182                         SplitValue += (*VP.Vertex[0])[axis];
00183                         SplitValue += (*VP.Vertex[1])[axis];
00184                         SplitValue += (*VP.Vertex[2])[axis];
00185                 }
00186                 return SplitValue / float(nb_prims*3);
00187         }
00188         else return AABBTreeBuilder::GetSplittingValue(primitives, nb_prims, global_box, axis);
00189 }
00190 
00192 
00199 
00200 bool AABBTreeOfVerticesBuilder::ComputeGlobalBox(const udword* primitives, udword nb_prims, AABB& global_box) const
00201 {
00202         // Checkings
00203         if(!primitives || !nb_prims)    return false;
00204 
00205         // Initialize global box
00206         global_box.SetEmpty();
00207 
00208         // Loop through vertices
00209         for(udword i=0;i<nb_prims;i++)
00210         {
00211                 // Update global box
00212                 global_box.Extend(mVertexArray[primitives[i]]);
00213         }
00214         return true;
00215 }
00216 
00218 
00224 
00225 float AABBTreeOfVerticesBuilder::GetSplittingValue(udword index, udword axis) const
00226 {
00227         // For a vertex, the splitting value is simply the vertex coordinate.
00228         return mVertexArray[index][axis];
00229 }
00230 
00232 
00240 
00241 float AABBTreeOfVerticesBuilder::GetSplittingValue(const udword* primitives, udword nb_prims, const AABB& global_box, udword axis)      const
00242 {
00243         if(mSettings.mRules&SPLIT_GEOM_CENTER)
00244         {
00245                 // Loop through vertices
00246                 float SplitValue = 0.0f;
00247                 for(udword i=0;i<nb_prims;i++)
00248                 {
00249                         // Update split value
00250                         SplitValue += mVertexArray[primitives[i]][axis];
00251                 }
00252                 return SplitValue / float(nb_prims);
00253         }
00254         else return AABBTreeBuilder::GetSplittingValue(primitives, nb_prims, global_box, axis);
00255 }


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