Code-style consistency improvement:
Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files. make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type. This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
@@ -4,13 +4,12 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#pragma warning(disable:4786)
|
||||
#pragma warning(disable : 4786)
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Copyright (c) 2004 Open Dynamics Framework Group
|
||||
www.physicstools.org
|
||||
@@ -107,55 +106,50 @@
|
||||
// You could easily modify this code to support other vertex
|
||||
// formats with any number of interpolants.
|
||||
|
||||
|
||||
|
||||
|
||||
#include "vlookup.h"
|
||||
|
||||
namespace Vlookup
|
||||
{
|
||||
|
||||
class VertexPosition
|
||||
{
|
||||
public:
|
||||
VertexPosition(void) { };
|
||||
VertexPosition(const float *p)
|
||||
{
|
||||
mPos[0] = p[0];
|
||||
mPos[1] = p[1];
|
||||
mPos[2] = p[2];
|
||||
};
|
||||
|
||||
void Set(int index,const float *pos)
|
||||
VertexPosition(void){};
|
||||
VertexPosition(const float *p)
|
||||
{
|
||||
const float * p = &pos[index*3];
|
||||
|
||||
mPos[0] = p[0];
|
||||
mPos[1] = p[1];
|
||||
mPos[2] = p[2];
|
||||
|
||||
mPos[0] = p[0];
|
||||
mPos[1] = p[1];
|
||||
mPos[2] = p[2];
|
||||
};
|
||||
|
||||
float GetX(void) const { return mPos[0]; };
|
||||
float GetY(void) const { return mPos[1]; };
|
||||
float GetZ(void) const { return mPos[2]; };
|
||||
void Set(int index, const float *pos)
|
||||
{
|
||||
const float *p = &pos[index * 3];
|
||||
|
||||
mPos[0] = p[0];
|
||||
mPos[1] = p[1];
|
||||
mPos[2] = p[2];
|
||||
};
|
||||
|
||||
float GetX(void) const { return mPos[0]; };
|
||||
float GetY(void) const { return mPos[1]; };
|
||||
float GetZ(void) const { return mPos[2]; };
|
||||
|
||||
float mPos[3];
|
||||
};
|
||||
|
||||
typedef std::vector< VertexPosition > VertexVector;
|
||||
typedef std::vector<VertexPosition> VertexVector;
|
||||
|
||||
struct Tracker
|
||||
{
|
||||
VertexPosition mFind; // vertice to locate.
|
||||
VertexVector *mList;
|
||||
VertexPosition mFind; // vertice to locate.
|
||||
VertexVector *mList;
|
||||
|
||||
Tracker()
|
||||
{
|
||||
mList = 0;
|
||||
}
|
||||
|
||||
void SetSearch(const VertexPosition& match,VertexVector *list)
|
||||
void SetSearch(const VertexPosition &match, VertexVector *list)
|
||||
{
|
||||
mFind = match;
|
||||
mList = list;
|
||||
@@ -165,9 +159,9 @@ struct Tracker
|
||||
struct VertexID
|
||||
{
|
||||
int mID;
|
||||
Tracker* mTracker;
|
||||
Tracker *mTracker;
|
||||
|
||||
VertexID(int ID, Tracker* Tracker)
|
||||
VertexID(int ID, Tracker *Tracker)
|
||||
{
|
||||
mID = ID;
|
||||
mTracker = Tracker;
|
||||
@@ -177,46 +171,45 @@ struct VertexID
|
||||
class VertexLess
|
||||
{
|
||||
public:
|
||||
|
||||
bool operator()(VertexID v1,VertexID v2) const;
|
||||
bool operator()(VertexID v1, VertexID v2) const;
|
||||
|
||||
private:
|
||||
const VertexPosition& Get(VertexID index) const
|
||||
const VertexPosition &Get(VertexID index) const
|
||||
{
|
||||
if ( index.mID == -1 ) return index.mTracker->mFind;
|
||||
if (index.mID == -1) return index.mTracker->mFind;
|
||||
VertexVector &vlist = *index.mTracker->mList;
|
||||
return vlist[index.mID];
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type> class VertexPool
|
||||
template <class Type>
|
||||
class VertexPool
|
||||
{
|
||||
public:
|
||||
typedef std::set<VertexID, VertexLess > VertexSet;
|
||||
typedef std::vector< Type > VertexVector;
|
||||
typedef std::set<VertexID, VertexLess> VertexSet;
|
||||
typedef std::vector<Type> VertexVector;
|
||||
|
||||
int getVertex(const Type& vtx)
|
||||
int getVertex(const Type &vtx)
|
||||
{
|
||||
mTracker.SetSearch(vtx,&mVtxs);
|
||||
mTracker.SetSearch(vtx, &mVtxs);
|
||||
VertexSet::iterator found;
|
||||
found = mVertSet.find( VertexID(-1,&mTracker) );
|
||||
if ( found != mVertSet.end() )
|
||||
found = mVertSet.find(VertexID(-1, &mTracker));
|
||||
if (found != mVertSet.end())
|
||||
{
|
||||
return found->mID;
|
||||
}
|
||||
int idx = (int)mVtxs.size();
|
||||
mVtxs.push_back( vtx );
|
||||
mVertSet.insert( VertexID(idx,&mTracker) );
|
||||
mVtxs.push_back(vtx);
|
||||
mVertSet.insert(VertexID(idx, &mTracker));
|
||||
return idx;
|
||||
};
|
||||
|
||||
|
||||
const float * GetPos(int idx) const
|
||||
const float *GetPos(int idx) const
|
||||
{
|
||||
return mVtxs[idx].mPos;
|
||||
}
|
||||
|
||||
const Type& Get(int idx) const
|
||||
const Type &Get(int idx) const
|
||||
{
|
||||
return mVtxs[idx];
|
||||
};
|
||||
@@ -233,9 +226,9 @@ public:
|
||||
mVtxs.reserve(reservesize);
|
||||
};
|
||||
|
||||
const VertexVector& GetVertexList(void) const { return mVtxs; };
|
||||
const VertexVector &GetVertexList(void) const { return mVtxs; };
|
||||
|
||||
void Set(const Type& vtx)
|
||||
void Set(const Type &vtx)
|
||||
{
|
||||
mVtxs.push_back(vtx);
|
||||
}
|
||||
@@ -245,82 +238,74 @@ public:
|
||||
return mVtxs.size();
|
||||
};
|
||||
|
||||
|
||||
Type * getBuffer(void)
|
||||
Type *getBuffer(void)
|
||||
{
|
||||
return &mVtxs[0];
|
||||
};
|
||||
|
||||
private:
|
||||
VertexSet mVertSet; // ordered list.
|
||||
VertexVector mVtxs; // set of vertices.
|
||||
Tracker mTracker;
|
||||
VertexSet mVertSet; // ordered list.
|
||||
VertexVector mVtxs; // set of vertices.
|
||||
Tracker mTracker;
|
||||
};
|
||||
|
||||
|
||||
bool VertexLess::operator()(VertexID v1,VertexID v2) const
|
||||
bool VertexLess::operator()(VertexID v1, VertexID v2) const
|
||||
{
|
||||
const VertexPosition &a = Get(v1);
|
||||
const VertexPosition &b = Get(v2);
|
||||
|
||||
const VertexPosition& a = Get(v1);
|
||||
const VertexPosition& b = Get(v2);
|
||||
int ixA = (int)(a.GetX() * 10000.0f);
|
||||
int ixB = (int)(b.GetX() * 10000.0f);
|
||||
|
||||
int ixA = (int) (a.GetX()*10000.0f);
|
||||
int ixB = (int) (b.GetX()*10000.0f);
|
||||
if (ixA < ixB) return true;
|
||||
if (ixA > ixB) return false;
|
||||
|
||||
if ( ixA < ixB ) return true;
|
||||
if ( ixA > ixB ) return false;
|
||||
int iyA = (int)(a.GetY() * 10000.0f);
|
||||
int iyB = (int)(b.GetY() * 10000.0f);
|
||||
|
||||
int iyA = (int) (a.GetY()*10000.0f);
|
||||
int iyB = (int) (b.GetY()*10000.0f);
|
||||
if (iyA < iyB) return true;
|
||||
if (iyA > iyB) return false;
|
||||
|
||||
if ( iyA < iyB ) return true;
|
||||
if ( iyA > iyB ) return false;
|
||||
|
||||
int izA = (int) (a.GetZ()*10000.0f);
|
||||
int izB = (int) (b.GetZ()*10000.0f);
|
||||
|
||||
if ( izA < izB ) return true;
|
||||
if ( izA > izB ) return false;
|
||||
int izA = (int)(a.GetZ() * 10000.0f);
|
||||
int izB = (int)(b.GetZ() * 10000.0f);
|
||||
|
||||
if (izA < izB) return true;
|
||||
if (izA > izB) return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
} // namespace Vlookup
|
||||
|
||||
using namespace Vlookup;
|
||||
|
||||
VertexLookup Vl_createVertexLookup(void)
|
||||
{
|
||||
VertexLookup ret = new VertexPool< VertexPosition >;
|
||||
return ret;
|
||||
VertexLookup ret = new VertexPool<VertexPosition>;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Vl_releaseVertexLookup(VertexLookup vlook)
|
||||
void Vl_releaseVertexLookup(VertexLookup vlook)
|
||||
{
|
||||
VertexPool< VertexPosition > *vp = (VertexPool< VertexPosition > *) vlook;
|
||||
delete vp;
|
||||
VertexPool<VertexPosition> *vp = (VertexPool<VertexPosition> *)vlook;
|
||||
delete vp;
|
||||
}
|
||||
|
||||
unsigned int Vl_getIndex(VertexLookup vlook,const float *pos) // get index.
|
||||
unsigned int Vl_getIndex(VertexLookup vlook, const float *pos) // get index.
|
||||
{
|
||||
VertexPool< VertexPosition > *vp = (VertexPool< VertexPosition > *) vlook;
|
||||
VertexPosition p(pos);
|
||||
return vp->getVertex(p);
|
||||
VertexPool<VertexPosition> *vp = (VertexPool<VertexPosition> *)vlook;
|
||||
VertexPosition p(pos);
|
||||
return vp->getVertex(p);
|
||||
}
|
||||
|
||||
const float * Vl_getVertices(VertexLookup vlook)
|
||||
const float *Vl_getVertices(VertexLookup vlook)
|
||||
{
|
||||
VertexPool< VertexPosition > *vp = (VertexPool< VertexPosition > *) vlook;
|
||||
return vp->GetPos(0);
|
||||
VertexPool<VertexPosition> *vp = (VertexPool<VertexPosition> *)vlook;
|
||||
return vp->GetPos(0);
|
||||
}
|
||||
|
||||
|
||||
unsigned int Vl_getVcount(VertexLookup vlook)
|
||||
unsigned int Vl_getVcount(VertexLookup vlook)
|
||||
{
|
||||
VertexPool< VertexPosition > *vp = (VertexPool< VertexPosition > *) vlook;
|
||||
return vp->GetVertexCount();
|
||||
VertexPool<VertexPosition> *vp = (VertexPool<VertexPosition> *)vlook;
|
||||
return vp->GetVertexCount();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user