2009-01-12 22:06:54 +00:00
|
|
|
#include "UnitTestPCH.h"
|
2008-07-29 20:36:27 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
#include "assimp/types.h"
|
|
|
|
#include "assimp/mesh.h"
|
|
|
|
|
|
|
|
#include <VertexTriangleAdjacency.h>
|
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Assimp;
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
class VTAdjacencyTest : public ::testing::Test
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void checkMesh(const aiMesh& mesh);
|
|
|
|
};
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2009-01-12 22:06:54 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2014-09-07 23:52:03 +00:00
|
|
|
TEST_F(VTAdjacencyTest, largeRandomDataSet)
|
2008-07-22 22:52:16 +00:00
|
|
|
{
|
|
|
|
// build a test mesh with randomized input data
|
|
|
|
// *******************************************************************************
|
2014-09-07 23:52:03 +00:00
|
|
|
aiMesh mesh;
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
mesh.mNumVertices = 500;
|
|
|
|
mesh.mNumFaces = 600;
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
mesh.mFaces = new aiFace[600];
|
2008-07-22 22:52:16 +00:00
|
|
|
unsigned int iCurrent = 0;
|
|
|
|
for (unsigned int i = 0; i < 600;++i)
|
|
|
|
{
|
2014-09-07 23:52:03 +00:00
|
|
|
aiFace& face = mesh.mFaces[i];
|
2008-07-22 22:52:16 +00:00
|
|
|
face.mNumIndices = 3;
|
|
|
|
face.mIndices = new unsigned int[3];
|
|
|
|
|
|
|
|
if (499 == iCurrent)iCurrent = 0;
|
|
|
|
face.mIndices[0] = iCurrent++;
|
|
|
|
|
|
|
|
|
2008-08-13 23:46:46 +00:00
|
|
|
while(face.mIndices[0] == ( face.mIndices[1] = (unsigned int)(((float)rand()/RAND_MAX)*499)));
|
|
|
|
while(face.mIndices[0] == ( face.mIndices[2] = (unsigned int)(((float)rand()/RAND_MAX)*499)) ||
|
2008-07-22 22:52:16 +00:00
|
|
|
face.mIndices[1] == face.mIndices[2]);
|
|
|
|
}
|
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
checkMesh(mesh);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
TEST_F(VTAdjacencyTest, smallDataSet)
|
|
|
|
{
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
// build a test mesh - this one is extremely small
|
2008-07-22 22:52:16 +00:00
|
|
|
// *******************************************************************************
|
2014-09-07 23:52:03 +00:00
|
|
|
aiMesh mesh;
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
mesh.mNumVertices = 5;
|
|
|
|
mesh.mNumFaces = 3;
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
mesh.mFaces = new aiFace[3];
|
|
|
|
mesh.mFaces[0].mIndices = new unsigned int[3];
|
|
|
|
mesh.mFaces[1].mIndices = new unsigned int[3];
|
|
|
|
mesh.mFaces[2].mIndices = new unsigned int[3];
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
mesh.mFaces[0].mIndices[0] = 1;
|
|
|
|
mesh.mFaces[0].mIndices[1] = 3;
|
|
|
|
mesh.mFaces[0].mIndices[2] = 2;
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
mesh.mFaces[1].mIndices[0] = 0;
|
|
|
|
mesh.mFaces[1].mIndices[1] = 2;
|
|
|
|
mesh.mFaces[1].mIndices[2] = 3;
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
mesh.mFaces[2].mIndices[0] = 3;
|
|
|
|
mesh.mFaces[2].mIndices[1] = 0;
|
|
|
|
mesh.mFaces[2].mIndices[2] = 4;
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
checkMesh(mesh);
|
|
|
|
}
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
TEST_F(VTAdjacencyTest, unreferencedVerticesSet)
|
|
|
|
{
|
|
|
|
// build a test mesh which does not reference all vertices
|
2008-07-22 22:52:16 +00:00
|
|
|
// *******************************************************************************
|
2014-09-07 23:52:03 +00:00
|
|
|
aiMesh mesh;
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
mesh.mNumVertices = 500;
|
|
|
|
mesh.mNumFaces = 600;
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
mesh.mFaces = new aiFace[600];
|
|
|
|
unsigned int iCurrent = 0;
|
2008-07-22 22:52:16 +00:00
|
|
|
for (unsigned int i = 0; i < 600;++i)
|
|
|
|
{
|
2014-09-07 23:52:03 +00:00
|
|
|
aiFace& face = mesh.mFaces[i];
|
2008-07-22 22:52:16 +00:00
|
|
|
face.mNumIndices = 3;
|
|
|
|
face.mIndices = new unsigned int[3];
|
|
|
|
|
|
|
|
if (499 == iCurrent)iCurrent = 0;
|
|
|
|
face.mIndices[0] = iCurrent++;
|
|
|
|
|
|
|
|
if (499 == iCurrent)iCurrent = 0;
|
|
|
|
face.mIndices[1] = iCurrent++;
|
|
|
|
|
|
|
|
if (499 == iCurrent)iCurrent = 0;
|
|
|
|
face.mIndices[2] = iCurrent++;
|
|
|
|
|
|
|
|
if (rand() > RAND_MAX/2 && face.mIndices[0])
|
|
|
|
{
|
|
|
|
face.mIndices[0]--;
|
|
|
|
}
|
|
|
|
else if (face.mIndices[1]) face.mIndices[1]--;
|
|
|
|
}
|
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
checkMesh(mesh);
|
2008-07-22 22:52:16 +00:00
|
|
|
}
|
|
|
|
|
2009-01-12 22:06:54 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2014-09-07 23:52:03 +00:00
|
|
|
void VTAdjacencyTest::checkMesh(const aiMesh& mesh)
|
2008-07-22 22:52:16 +00:00
|
|
|
{
|
2014-09-07 23:52:03 +00:00
|
|
|
VertexTriangleAdjacency adj(mesh.mFaces,mesh.mNumFaces,mesh.mNumVertices,true);
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
unsigned int* const piNum = adj.mLiveTriangles;
|
2008-07-22 22:52:16 +00:00
|
|
|
|
|
|
|
// check the primary adjacency table and check whether all faces
|
|
|
|
// are contained in the list
|
|
|
|
unsigned int maxOfs = 0;
|
2014-09-07 23:52:03 +00:00
|
|
|
for (unsigned int i = 0; i < mesh.mNumFaces;++i)
|
2008-07-22 22:52:16 +00:00
|
|
|
{
|
2014-09-07 23:52:03 +00:00
|
|
|
aiFace& face = mesh.mFaces[i];
|
2008-07-22 22:52:16 +00:00
|
|
|
for (unsigned int qq = 0; qq < 3 ;++qq)
|
|
|
|
{
|
|
|
|
const unsigned int idx = face.mIndices[qq];
|
|
|
|
const unsigned int num = piNum[idx];
|
|
|
|
|
|
|
|
// go to this offset
|
2014-09-07 23:52:03 +00:00
|
|
|
const unsigned int ofs = adj.mOffsetTable[idx];
|
2008-07-22 22:52:16 +00:00
|
|
|
maxOfs = std::max(ofs+num,maxOfs);
|
2014-09-07 23:52:03 +00:00
|
|
|
unsigned int* pi = &adj.mAdjacencyTable[ofs];
|
2008-07-22 22:52:16 +00:00
|
|
|
|
|
|
|
// and search for us ...
|
|
|
|
unsigned int tt = 0;
|
|
|
|
for (; tt < num;++tt,++pi)
|
|
|
|
{
|
|
|
|
if (i == *pi)
|
|
|
|
{
|
|
|
|
// mask our entry in the table. Finally all entries should be masked
|
|
|
|
*pi = 0xffffffff;
|
|
|
|
|
|
|
|
// there shouldn't be two entries for the same face
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// assert if *this* vertex has not been found in the table
|
2014-09-07 23:52:03 +00:00
|
|
|
EXPECT_LT(tt, num);
|
2008-07-22 22:52:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now check whether there are invalid faces
|
2014-09-07 23:52:03 +00:00
|
|
|
const unsigned int* pi = adj.mAdjacencyTable;
|
2008-07-22 22:52:16 +00:00
|
|
|
for (unsigned int i = 0; i < maxOfs;++i,++pi)
|
|
|
|
{
|
2014-09-07 23:52:03 +00:00
|
|
|
EXPECT_EQ(0xffffffff, *pi);
|
2008-07-22 22:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check the numTrianglesPerVertex table
|
2014-09-07 23:52:03 +00:00
|
|
|
for (unsigned int i = 0; i < mesh.mNumFaces;++i)
|
2008-07-22 22:52:16 +00:00
|
|
|
{
|
2014-09-07 23:52:03 +00:00
|
|
|
aiFace& face = mesh.mFaces[i];
|
2008-07-22 22:52:16 +00:00
|
|
|
for (unsigned int qq = 0; qq < 3 ;++qq)
|
|
|
|
{
|
|
|
|
const unsigned int idx = face.mIndices[qq];
|
|
|
|
|
|
|
|
// we should not reach 0 here ...
|
2014-09-07 23:52:03 +00:00
|
|
|
EXPECT_NE(0U, piNum[idx]);
|
2008-07-22 22:52:16 +00:00
|
|
|
piNum[idx]--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check whether we reached 0 in all entries
|
2014-09-07 23:52:03 +00:00
|
|
|
for (unsigned int i = 0; i < mesh.mNumVertices;++i)
|
2008-07-22 22:52:16 +00:00
|
|
|
{
|
2014-09-07 23:52:03 +00:00
|
|
|
EXPECT_FALSE(piNum[i]);
|
2008-07-22 22:52:16 +00:00
|
|
|
}
|
|
|
|
}
|