您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

99 行
2.2 KiB

  1. #include "UnitTestPCH.h"
  2. #include "utTriangulate.h"
  3. CPPUNIT_TEST_SUITE_REGISTRATION (TriangulateProcessTest);
  4. void TriangulateProcessTest :: setUp (void)
  5. {
  6. piProcess = new TriangulateProcess();
  7. pcMesh = new aiMesh();
  8. pcMesh->mNumFaces = 1000;
  9. pcMesh->mFaces = new aiFace[1000];
  10. pcMesh->mVertices = new aiVector3D[10000];
  11. pcMesh->mPrimitiveTypes = aiPrimitiveType_POINT | aiPrimitiveType_LINE |
  12. aiPrimitiveType_LINE | aiPrimitiveType_POLYGON;
  13. for (unsigned int m = 0, t = 0, q = 4; m < 1000; ++m)
  14. {
  15. ++t;
  16. aiFace& face = pcMesh->mFaces[m];
  17. face.mNumIndices = t;
  18. if (4 == t)
  19. {
  20. face.mNumIndices = q++;
  21. t = 0;
  22. if (10 == q)q = 4;
  23. }
  24. face.mIndices = new unsigned int[face.mNumIndices];
  25. for (unsigned int p = 0; p < face.mNumIndices; ++p)
  26. {
  27. face.mIndices[p] = pcMesh->mNumVertices;
  28. // construct fully convex input data in ccw winding, xy plane
  29. aiVector3D& v = pcMesh->mVertices[pcMesh->mNumVertices++];
  30. v.z = 0.f;
  31. v.x = cos (p * (float)(AI_MATH_TWO_PI)/face.mNumIndices);
  32. v.y = sin (p * (float)(AI_MATH_TWO_PI)/face.mNumIndices);
  33. }
  34. }
  35. }
  36. void TriangulateProcessTest :: tearDown (void)
  37. {
  38. delete piProcess;
  39. delete pcMesh;
  40. }
  41. void TriangulateProcessTest :: testTriangulation (void)
  42. {
  43. piProcess->TriangulateMesh(pcMesh);
  44. for (unsigned int m = 0, t = 0, q = 4, max = 1000, idx = 0; m < max;++m)
  45. {
  46. ++t;
  47. aiFace& face = pcMesh->mFaces[m];
  48. if (4 == t)
  49. {
  50. t = 0;
  51. max += q-3;
  52. std::vector<bool> ait(q,false);
  53. for (unsigned int i = 0, tt = q-2; i < tt; ++i,++m)
  54. {
  55. aiFace& face = pcMesh->mFaces[m];
  56. CPPUNIT_ASSERT(face.mNumIndices == 3);
  57. for (unsigned int qqq = 0; qqq < face.mNumIndices; ++qqq)
  58. {
  59. ait[face.mIndices[qqq]-idx] = true;
  60. }
  61. }
  62. for (std::vector<bool>::const_iterator it = ait.begin(); it != ait.end(); ++it)
  63. {
  64. CPPUNIT_ASSERT(*it);
  65. }
  66. --m;
  67. idx+=q;
  68. if(++q == 10)q = 4;
  69. }
  70. else
  71. {
  72. CPPUNIT_ASSERT(face.mNumIndices == t);
  73. for (unsigned int i = 0; i < face.mNumIndices; ++i,++idx)
  74. {
  75. CPPUNIT_ASSERT(face.mIndices[i] == idx);
  76. }
  77. }
  78. }
  79. // we should have no valid normal vectors now necause we aren't a pure polygon mesh
  80. CPPUNIT_ASSERT(pcMesh->mNormals == NULL);
  81. }