utSplitLargeMeshes.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #include "UnitTestPCH.h"
  2. #include <assimp/scene.h>
  3. #include <SplitLargeMeshes.h>
  4. using namespace std;
  5. using namespace Assimp;
  6. class SplitLargeMeshesTest : public ::testing::Test
  7. {
  8. public:
  9. virtual void SetUp();
  10. virtual void TearDown();
  11. protected:
  12. SplitLargeMeshesProcess_Triangle* piProcessTriangle;
  13. SplitLargeMeshesProcess_Vertex* piProcessVertex;
  14. aiMesh* pcMesh1;
  15. aiMesh* pcMesh2;
  16. };
  17. // ------------------------------------------------------------------------------------------------
  18. void SplitLargeMeshesTest::SetUp()
  19. {
  20. // construct the processes
  21. this->piProcessTriangle = new SplitLargeMeshesProcess_Triangle();
  22. this->piProcessVertex = new SplitLargeMeshesProcess_Vertex();
  23. this->piProcessTriangle->SetLimit(1000);
  24. this->piProcessVertex->SetLimit(1000);
  25. this->pcMesh1 = new aiMesh();
  26. pcMesh1->mNumVertices = 2100; // quersumme: 3
  27. pcMesh1->mVertices = new aiVector3D[pcMesh1->mNumVertices];
  28. pcMesh1->mNormals = new aiVector3D[pcMesh1->mNumVertices];
  29. pcMesh1->mNumFaces = pcMesh1->mNumVertices / 3;
  30. pcMesh1->mFaces = new aiFace[pcMesh1->mNumFaces];
  31. unsigned int qq = 0;
  32. for (unsigned int i = 0; i < pcMesh1->mNumFaces;++i)
  33. {
  34. aiFace& face = pcMesh1->mFaces[i];
  35. face.mNumIndices = 3;
  36. face.mIndices = new unsigned int[3];
  37. face.mIndices[0] = qq++;
  38. face.mIndices[1] = qq++;
  39. face.mIndices[2] = qq++;
  40. }
  41. // generate many, many faces with randomized indices for
  42. // the second mesh
  43. this->pcMesh2 = new aiMesh();
  44. pcMesh2->mNumVertices = 3000;
  45. pcMesh2->mVertices = new aiVector3D[pcMesh2->mNumVertices];
  46. pcMesh2->mNormals = new aiVector3D[pcMesh2->mNumVertices];
  47. pcMesh2->mNumFaces = 10000;
  48. pcMesh2->mFaces = new aiFace[pcMesh2->mNumFaces];
  49. for (unsigned int i = 0; i < pcMesh2->mNumFaces;++i)
  50. {
  51. aiFace& face = pcMesh2->mFaces[i];
  52. face.mNumIndices = 3;
  53. face.mIndices = new unsigned int[3];
  54. face.mIndices[0] = (unsigned int)((rand() / (float)RAND_MAX) * pcMesh2->mNumVertices);
  55. face.mIndices[1] = (unsigned int)((rand() / (float)RAND_MAX) * pcMesh2->mNumVertices);
  56. face.mIndices[2] = (unsigned int)((rand() / (float)RAND_MAX) * pcMesh2->mNumVertices);
  57. }
  58. }
  59. // ------------------------------------------------------------------------------------------------
  60. void SplitLargeMeshesTest::TearDown()
  61. {
  62. delete this->piProcessTriangle;
  63. delete this->piProcessVertex;
  64. }
  65. // ------------------------------------------------------------------------------------------------
  66. TEST_F(SplitLargeMeshesTest, testVertexSplit)
  67. {
  68. std::vector< std::pair<aiMesh*, unsigned int> > avOut;
  69. int iOldFaceNum = (int)pcMesh1->mNumFaces;
  70. piProcessVertex->SplitMesh(0,pcMesh1,avOut);
  71. for (std::vector< std::pair<aiMesh*, unsigned int> >::const_iterator
  72. iter = avOut.begin(), end = avOut.end();
  73. iter != end; ++iter)
  74. {
  75. aiMesh* mesh = (*iter).first;
  76. EXPECT_LT(mesh->mNumVertices, 1000U);
  77. EXPECT_TRUE(NULL != mesh->mNormals);
  78. EXPECT_TRUE(NULL != mesh->mVertices);
  79. iOldFaceNum -= mesh->mNumFaces;
  80. delete mesh;
  81. }
  82. EXPECT_EQ(0, iOldFaceNum);
  83. }
  84. // ------------------------------------------------------------------------------------------------
  85. TEST_F(SplitLargeMeshesTest, testTriangleSplit)
  86. {
  87. std::vector< std::pair<aiMesh*, unsigned int> > avOut;
  88. // the number of faces shouldn't change
  89. int iOldFaceNum = (int)pcMesh2->mNumFaces;
  90. piProcessTriangle->SplitMesh(0,pcMesh2,avOut);
  91. for (std::vector< std::pair<aiMesh*, unsigned int> >::const_iterator
  92. iter = avOut.begin(), end = avOut.end();
  93. iter != end; ++iter)
  94. {
  95. aiMesh* mesh = (*iter).first;
  96. EXPECT_LT(mesh->mNumFaces, 1000U);
  97. EXPECT_TRUE(NULL != mesh->mNormals);
  98. EXPECT_TRUE(NULL != mesh->mVertices);
  99. iOldFaceNum -= mesh->mNumFaces;
  100. delete mesh;
  101. }
  102. EXPECT_EQ(0, iOldFaceNum);
  103. }