Public Member Functions | Public Attributes | Private Attributes | Static Private Attributes | List of all members
MeshInterface Class Reference

#include <OPC_MeshInterface.h>

Public Member Functions

udword CheckTopology () const
 
inline_ udword GetNbTriangles () const
 
inline_ udword GetNbVertices () const
 
inline_ void GetTriangle (VertexPointers &vp, udword index) const
 
inline_ const IndexedTriangleGetTris () const
 
inline_ const PointGetVerts () const
 
bool IsValid () const
 
 MeshInterface ()
 
bool RemapClient (udword nb_indices, const udword *permutation) const
 
inline_ void SetNbTriangles (udword nb)
 
inline_ void SetNbVertices (udword nb)
 
bool SetPointers (const IndexedTriangle *tris, const Point *verts)
 
 ~MeshInterface ()
 

Public Attributes

bool Single
 Use single or double precision vertices. More...
 

Private Attributes

udword mNbTris
 Number of triangles in the input model. More...
 
udword mNbVerts
 Number of vertices in the input model. More...
 
const IndexedTrianglemTris
 Array of indexed triangles. More...
 
const PointmVerts
 Array of vertices. More...
 

Static Private Attributes

static Point VertexCache [3]
 

Detailed Description

This class is an interface between us and user-defined meshes. Meshes can be defined in a lot of ways, and here we try to support most of them.

Basically you have two options:

If using pointers, you can also use strides or not. Strides are used when OPC_USE_STRIDE is defined.

CALLBACKS:

Using callbacks is the most generic way to feed OPCODE with your meshes. Indeed, you just have to give access to three vertices at the end of the day. It's up to you to fetch them from your database, using whatever method you want. Hence your meshes can lie in system memory or AGP, be indexed or not, use 16 or 32-bits indices, you can decompress them on-the-fly if needed, etc. On the other hand, a callback is called each time OPCODE needs access to a particular triangle, so there might be a slight overhead.

To make things clear: geometry & topology are NOT stored in the collision system, in order to save some ram. So, when the system needs them to perform accurate intersection tests, you're requested to provide the triangle-vertices corresponding to a given face index.

Ex:

static void ColCallback(udword triangle_index, VertexPointers& triangle, udword user_data)
{
// Get back Mesh0 or Mesh1 (you also can use 2 different callbacks)
Mesh* MyMesh = (Mesh*)user_data;
// Get correct triangle in the app-controlled database
const Triangle* Tri = MyMesh->GetTriangle(triangle_index);
// Setup pointers to vertices for the collision system
triangle.Vertex[0] = MyMesh->GetVertex(Tri->mVRef[0]);
triangle.Vertex[1] = MyMesh->GetVertex(Tri->mVRef[1]);
triangle.Vertex[2] = MyMesh->GetVertex(Tri->mVRef[2]);
}
// Setup callbacks
MeshInterface0->SetCallback(ColCallback, udword(Mesh0));
MeshInterface1->SetCallback(ColCallback, udword(Mesh1));

Of course, you should make this callback as fast as possible. And you're also not supposed to modify the geometry after the collision trees have been built. The alternative was to store the geometry & topology in the collision system as well (as in RAPID) but we have found this approach to waste a lot of ram in many cases.

POINTERS:

If you're internally using the following canonical structures:

Ex:

// Setup pointers
MeshInterface0->SetPointers(Mesh0->GetFaces(), Mesh0->GetVerts());
MeshInterface1->SetPointers(Mesh1->GetFaces(), Mesh1->GetVerts());

STRIDES:

If your vertices are D3D-like entities interleaving a position, a normal and/or texture coordinates (i.e. if your vertices are FVFs), you might want to use a vertex stride to skip extra data OPCODE doesn't need. Using a stride shouldn't be notably slower than not using it, but it might increase cache misses. Please also note that you shouldn't read from AGP or video-memory buffers !

In any case, compilation flags are here to select callbacks/pointers/strides at compile time, so choose what's best for your application. All of this has been wrapped into this MeshInterface.

Author
Pierre Terdiman
Version
1.3
Date
November, 27, 2002

Definition at line 53 of file OPC_MeshInterface.h.

Constructor & Destructor Documentation

MeshInterface::MeshInterface ( )
MeshInterface::~MeshInterface ( )

Member Function Documentation

udword MeshInterface::CheckTopology ( ) const

Checks the mesh itself is valid. Currently we only look for degenerate faces.

Returns
number of degenerate faces
inline_ udword MeshInterface::GetNbTriangles ( ) const
inline

Definition at line 60 of file OPC_MeshInterface.h.

inline_ udword MeshInterface::GetNbVertices ( ) const
inline

Definition at line 61 of file OPC_MeshInterface.h.

inline_ void MeshInterface::GetTriangle ( VertexPointers vp,
udword  index 
) const
inline

Fetches a triangle given a triangle index.

Parameters
vp[out] required triangle's vertex pointers
index[in] triangle index

Definition at line 118 of file OPC_MeshInterface.h.

inline_ const IndexedTriangle* MeshInterface::GetTris ( ) const
inline

Definition at line 91 of file OPC_MeshInterface.h.

inline_ const Point* MeshInterface::GetVerts ( ) const
inline

Definition at line 92 of file OPC_MeshInterface.h.

bool MeshInterface::IsValid ( ) const

Checks the mesh interface is valid, i.e. things have been setup correctly.

Returns
true if valid
bool MeshInterface::RemapClient ( udword  nb_indices,
const udword permutation 
) const

Remaps client's mesh according to a permutation.

Parameters
nb_indices[in] number of indices in the permutation (will be checked against number of triangles)
permutation[in] list of triangle indices
Returns
true if success
inline_ void MeshInterface::SetNbTriangles ( udword  nb)
inline

Definition at line 62 of file OPC_MeshInterface.h.

inline_ void MeshInterface::SetNbVertices ( udword  nb)
inline

Definition at line 63 of file OPC_MeshInterface.h.

bool MeshInterface::SetPointers ( const IndexedTriangle tris,
const Point verts 
)

Pointers control: setups object pointers. Must provide access to faces and vertices for a given object.

Parameters
tris[in] pointer to triangles
verts[in] pointer to vertices
Returns
true if success

Member Data Documentation

udword MeshInterface::mNbTris
private

Number of triangles in the input model.

Definition at line 178 of file OPC_MeshInterface.h.

udword MeshInterface::mNbVerts
private

Number of vertices in the input model.

Definition at line 179 of file OPC_MeshInterface.h.

const IndexedTriangle* MeshInterface::mTris
private

Array of indexed triangles.

Definition at line 186 of file OPC_MeshInterface.h.

const Point* MeshInterface::mVerts
private

Array of vertices.

Definition at line 187 of file OPC_MeshInterface.h.

bool MeshInterface::Single

Use single or double precision vertices.

Definition at line 193 of file OPC_MeshInterface.h.

Point MeshInterface::VertexCache[3]
staticprivate

Definition at line 195 of file OPC_MeshInterface.h.


The documentation for this class was generated from the following file:


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:43