OPC_MeshInterface.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 
29 
32 
115 
118 // Precompiled Header
119 #include "Stdafx.h"
120 
121 using namespace Opcode;
122 
124 
126 
131  mNbTris (0),
132  mNbVerts (0),
133 #ifdef OPC_USE_CALLBACKS
134  mUserData (null),
135  mObjCallback (null),
136 #else
137  mTris (null),
138  mVerts (null),
139  #ifdef OPC_USE_STRIDE
140  mTriStride (sizeof(IndexedTriangle)),
141  mVertexStride (sizeof(Point)),
142  #endif
143 #endif
144 
145  Single(true)
146 {
147 }
148 
150 
155 {
156 }
157 
159 
163 bool MeshInterface::IsValid() const
165 {
166  if(!mNbTris || !mNbVerts) return false;
167 #ifdef OPC_USE_CALLBACKS
168  if(!mObjCallback) return false;
169 #else
170  if(!mTris || !mVerts) return false;
171 #endif
172  return true;
173 }
174 
176 
183 {
184  // Check topology. If the model contains degenerate faces, collision report can be wrong in some cases.
185  // e.g. it happens with the standard MAX teapot. So clean your meshes first... If you don't have a mesh cleaner
186  // you can try this: www.codercorner.com/Consolidation.zip
187 
188  udword NbDegenerate = 0;
189 
190  VertexPointers VP;
191 
192  // Using callbacks, we don't have access to vertex indices. Nevertheless we still can check for
193  // redundant vertex pointers, which cover all possibilities (callbacks/pointers/strides).
194  for(udword i=0;i<mNbTris;i++)
195  {
196  GetTriangle(VP, i);
197 
198  if( (VP.Vertex[0]==VP.Vertex[1])
199  || (VP.Vertex[1]==VP.Vertex[2])
200  || (VP.Vertex[2]==VP.Vertex[0])) NbDegenerate++;
201  }
202 
203  return NbDegenerate;
204 }
205 
206 #ifdef OPC_USE_CALLBACKS
207 
214 bool MeshInterface::SetCallback(RequestCallback callback, void* user_data)
216 {
217  if(!callback) return SetIceError("MeshInterface::SetCallback: callback pointer is null");
218 
219  mObjCallback = callback;
220  mUserData = user_data;
221  return true;
222 }
223 #else
224 
231 bool MeshInterface::SetPointers(const IndexedTriangle* tris, const Point* verts)
233 {
234  if(!tris || !verts) return SetIceError("MeshInterface::SetPointers: pointer is null", null);
235 
236  mTris = tris;
237  mVerts = verts;
238  return true;
239 }
240 #ifdef OPC_USE_STRIDE
241 
248 bool MeshInterface::SetStrides(udword tri_stride, udword vertex_stride)
250 {
251  if(tri_stride<sizeof(IndexedTriangle)) return SetIceError("MeshInterface::SetStrides: invalid triangle stride", null);
252  if(vertex_stride<sizeof(Point)) return SetIceError("MeshInterface::SetStrides: invalid vertex stride", null);
253 
254  mTriStride = tri_stride;
255  mVertexStride = vertex_stride;
256  return true;
257 }
258 #endif
259 #endif
260 
262 
268 bool MeshInterface::RemapClient(udword nb_indices, const udword* permutation) const
270 {
271  // Checkings
272  if(!nb_indices || !permutation) return false;
273  if(nb_indices!=mNbTris) return false;
274 
275 #ifdef OPC_USE_CALLBACKS
276  // We can't really do that using callbacks
277  return false;
278 #else
280  CHECKALLOC(Tmp);
281 
282  #ifdef OPC_USE_STRIDE
283  udword Stride = mTriStride;
284  #else
285  udword Stride = sizeof(IndexedTriangle);
286  #endif
287 
288  for(udword i=0;i<mNbTris;i++)
289  {
290  const IndexedTriangle* T = (const IndexedTriangle*)(((ubyte*)mTris) + i * Stride);
291  Tmp[i] = *T;
292  }
293 
294  for(udword i=0;i<mNbTris;i++)
295  {
296  IndexedTriangle* T = (IndexedTriangle*)(((ubyte*)mTris) + i * Stride);
297  *T = Tmp[permutation[i]];
298  }
299 
300  DELETEARRAY(Tmp);
301 #endif
302  return true;
303 }
CHECKALLOC
#define CHECKALLOC(x)
Definition: IceMemoryMacros.h:103
i
png_uint_32 i
Definition: png.h:2732
VertexPointers
Definition: OPC_MeshInterface.h:23
MeshInterface::GetTriangle
inline_ void GetTriangle(VertexPointers &vp, udword index) const
Definition: OPC_MeshInterface.h:118
MeshInterface::MeshInterface
MeshInterface()
Definition: OPC_MeshInterface.cpp:130
MeshInterface::RemapClient
bool RemapClient(udword nb_indices, const udword *permutation) const
Definition: OPC_MeshInterface.cpp:269
udword
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
MeshInterface::mNbVerts
udword mNbVerts
Number of vertices in the input model.
Definition: OPC_MeshInterface.h:179
MeshInterface::~MeshInterface
~MeshInterface()
Definition: OPC_MeshInterface.cpp:154
ubyte
unsigned char ubyte
sizeof(ubyte) must be 1
Definition: IceTypes.h:61
Stdafx.h
MeshInterface::mVerts
const Point * mVerts
Array of vertices.
Definition: OPC_MeshInterface.h:187
MeshInterface::IsValid
bool IsValid() const
Definition: OPC_MeshInterface.cpp:164
MeshInterface::CheckTopology
udword CheckTopology() const
Definition: OPC_MeshInterface.cpp:182
VertexPointers::Vertex
const Point * Vertex[3]
Definition: OPC_MeshInterface.h:25
IndexedTriangle
Definition: IceIndexedTriangle.h:23
MeshInterface::SetPointers
bool SetPointers(const IndexedTriangle *tris, const Point *verts)
Definition: OPC_MeshInterface.cpp:232
DELETEARRAY
#define DELETEARRAY(x)
Deletes an array.
Definition: IceMemoryMacros.h:96
SetIceError
#define SetIceError(a, b)
Definition: OPC_IceHook.h:29
MeshInterface::mTris
const IndexedTriangle * mTris
Array of indexed triangles.
Definition: OPC_MeshInterface.h:186
MeshInterface::VertexCache
static Point VertexCache[3]
Definition: OPC_MeshInterface.h:195
Opcode
Definition: CollisionPairInserterBase.h:18
MeshInterface::mNbTris
udword mNbTris
Number of triangles in the input model.
Definition: OPC_MeshInterface.h:178
null
#define null
our own NULL pointer
Definition: IceTypes.h:57


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Wed Sep 7 2022 02:51:03