OPC_TreeBuilders.cpp
Go to the documentation of this file.
1 /*
3  * OPCODE - Optimized Collision Detection
4  * Copyright (C) 2001 Pierre Terdiman
5  * Homepage: http://www.codercorner.com/Opcode.htm
6  */
8 
10 
16 
19 
27 
30 
38 
41 
49 
52 // Precompiled Header
53 #include "Stdafx.h"
54 
55 using namespace Opcode;
56 
58 
65 bool AABBTreeOfAABBsBuilder::ComputeGlobalBox(const udword* primitives, udword nb_prims, AABB& global_box) const
67 {
68  // Checkings
69  if(!primitives || !nb_prims) return false;
70 
71  // Initialize global box
72  global_box = mAABBArray[primitives[0]];
73 
74  // Loop through boxes
75  for(udword i=1;i<nb_prims;i++)
76  {
77  // Update global box
78  global_box.Add(mAABBArray[primitives[i]]);
79  }
80  return true;
81 }
82 
84 
92 {
93  // For an AABB, the splitting value is the middle of the given axis,
94  // i.e. the corresponding component of the center point
95  return mAABBArray[index].GetCenter(axis);
96 }
97 
99 
106 bool AABBTreeOfTrianglesBuilder::ComputeGlobalBox(const udword* primitives, udword nb_prims, AABB& global_box) const
108 {
109  // Checkings
110  if(!primitives || !nb_prims) return false;
111 
112  // Initialize global box
115 
116  // Loop through triangles
117  VertexPointers VP;
118  while(nb_prims--)
119  {
120  // Get current triangle-vertices
121  mIMesh->GetTriangle(VP, *primitives++);
122  // Update global box
123  Min.Min(*VP.Vertex[0]).Min(*VP.Vertex[1]).Min(*VP.Vertex[2]);
124  Max.Max(*VP.Vertex[0]).Max(*VP.Vertex[1]).Max(*VP.Vertex[2]);
125  }
126  global_box.SetMinMax(Min, Max);
127  return true;
128 }
129 
131 
139 {
140 /* // Compute center of triangle
141  Point Center;
142  mTriList[index].Center(mVerts, Center);
143  // Return value
144  return Center[axis];*/
145 
146  // Compute correct component from center of triangle
147 // return (mVerts[mTriList[index].mVRef[0]][axis]
148 // +mVerts[mTriList[index].mVRef[1]][axis]
149 // +mVerts[mTriList[index].mVRef[2]][axis])*INV3;
150 
151  VertexPointers VP;
152  mIMesh->GetTriangle(VP, index);
153 
154  // Compute correct component from center of triangle
155  return ((*VP.Vertex[0])[axis]
156  +(*VP.Vertex[1])[axis]
157  +(*VP.Vertex[2])[axis])*INV3;
158 }
159 
161 
169 float AABBTreeOfTrianglesBuilder::GetSplittingValue(const udword* primitives, udword nb_prims, const AABB& global_box, udword axis) const
171 {
173  {
174  // Loop through triangles
175  float SplitValue = 0.0f;
176  VertexPointers VP;
177  for(udword i=0;i<nb_prims;i++)
178  {
179  // Get current triangle-vertices
180  mIMesh->GetTriangle(VP, primitives[i]);
181  // Update split value
182  SplitValue += (*VP.Vertex[0])[axis];
183  SplitValue += (*VP.Vertex[1])[axis];
184  SplitValue += (*VP.Vertex[2])[axis];
185  }
186  return SplitValue / float(nb_prims*3);
187  }
188  else return AABBTreeBuilder::GetSplittingValue(primitives, nb_prims, global_box, axis);
189 }
190 
192 
199 bool AABBTreeOfVerticesBuilder::ComputeGlobalBox(const udword* primitives, udword nb_prims, AABB& global_box) const
201 {
202  // Checkings
203  if(!primitives || !nb_prims) return false;
204 
205  // Initialize global box
206  global_box.SetEmpty();
207 
208  // Loop through vertices
209  for(udword i=0;i<nb_prims;i++)
210  {
211  // Update global box
212  global_box.Extend(mVertexArray[primitives[i]]);
213  }
214  return true;
215 }
216 
218 
226 {
227  // For a vertex, the splitting value is simply the vertex coordinate.
228  return mVertexArray[index][axis];
229 }
230 
232 
240 float AABBTreeOfVerticesBuilder::GetSplittingValue(const udword* primitives, udword nb_prims, const AABB& global_box, udword axis) const
242 {
244  {
245  // Loop through vertices
246  float SplitValue = 0.0f;
247  for(udword i=0;i<nb_prims;i++)
248  {
249  // Update split value
250  SplitValue += mVertexArray[primitives[i]][axis];
251  }
252  return SplitValue / float(nb_prims);
253  }
254  else return AABBTreeBuilder::GetSplittingValue(primitives, nb_prims, global_box, axis);
255 }
inline_ void GetCenter(Point &center) const
Get box center.
Definition: OPC_IceHook.h:354
const AABB * mAABBArray
Shortcut to an app-controlled array of AABBs.
Definition: Opcode.h:156
const Point * Vertex[3]
Definition: Opcode.h:26
png_uint_32 i
Definition: png.h:2735
udword mRules
Building/Splitting rules (a combination of SplittingRules flags)
Definition: Opcode.h:45
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
#define MAX_FLOAT
max possible float value
Definition: IceTypes.h:130
void Extend(const Point &p)
Definition: OPC_IceHook.h:325
void SetMinMax(const Point &min, const Point &max)
Definition: OPC_IceHook.h:286
Split at geometric center (else split in the middle)
Definition: Opcode.h:34
virtual float GetSplittingValue(udword index, udword axis) const =0
#define INV3
1/3
Definition: IceTypes.h:45
virtual bool ComputeGlobalBox(const udword *primitives, udword nb_prims, AABB &global_box) const =0
#define MIN_FLOAT
min possible loat value
Definition: IceTypes.h:131
BuildSettings mSettings
Splitting rules & split limit [Opcode 1.3].
Definition: Opcode.h:114


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:40