You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

108 line
3.4 KiB

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