Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

194 lignes
5.0 KiB

  1. #include "UnitTestPCH.h"
  2. #include "utVertexTriangleAdjacency.h"
  3. CPPUNIT_TEST_SUITE_REGISTRATION (VTAdjacency);
  4. // ------------------------------------------------------------------------------------------------
  5. void VTAdjacency :: setUp (void)
  6. {
  7. // build a test mesh with randomized input data
  8. // *******************************************************************************
  9. pMesh = new aiMesh();
  10. pMesh->mNumVertices = 500;
  11. pMesh->mNumFaces = 600;
  12. pMesh->mFaces = new aiFace[600];
  13. unsigned int iCurrent = 0;
  14. for (unsigned int i = 0; i < 600;++i)
  15. {
  16. aiFace& face = pMesh->mFaces[i];
  17. face.mNumIndices = 3;
  18. face.mIndices = new unsigned int[3];
  19. if (499 == iCurrent)iCurrent = 0;
  20. face.mIndices[0] = iCurrent++;
  21. while(face.mIndices[0] == ( face.mIndices[1] = (unsigned int)(((float)rand()/RAND_MAX)*499)));
  22. while(face.mIndices[0] == ( face.mIndices[2] = (unsigned int)(((float)rand()/RAND_MAX)*499)) ||
  23. face.mIndices[1] == face.mIndices[2]);
  24. }
  25. // build a second test mesh - this one is extremely small
  26. // *******************************************************************************
  27. pMesh2 = new aiMesh();
  28. pMesh2->mNumVertices = 5;
  29. pMesh2->mNumFaces = 3;
  30. pMesh2->mFaces = new aiFace[3];
  31. pMesh2->mFaces[0].mIndices = new unsigned int[3];
  32. pMesh2->mFaces[1].mIndices = new unsigned int[3];
  33. pMesh2->mFaces[2].mIndices = new unsigned int[3];
  34. pMesh2->mFaces[0].mIndices[0] = 1;
  35. pMesh2->mFaces[0].mIndices[1] = 3;
  36. pMesh2->mFaces[0].mIndices[2] = 2;
  37. pMesh2->mFaces[1].mIndices[0] = 0;
  38. pMesh2->mFaces[1].mIndices[1] = 2;
  39. pMesh2->mFaces[1].mIndices[2] = 3;
  40. pMesh2->mFaces[2].mIndices[0] = 3;
  41. pMesh2->mFaces[2].mIndices[1] = 0;
  42. pMesh2->mFaces[2].mIndices[2] = 4;
  43. // build a third test mesh which does not reference all vertices
  44. // *******************************************************************************
  45. pMesh3 = new aiMesh();
  46. pMesh3->mNumVertices = 500;
  47. pMesh3->mNumFaces = 600;
  48. pMesh3->mFaces = new aiFace[600];
  49. iCurrent = 0;
  50. for (unsigned int i = 0; i < 600;++i)
  51. {
  52. aiFace& face = pMesh3->mFaces[i];
  53. face.mNumIndices = 3;
  54. face.mIndices = new unsigned int[3];
  55. if (499 == iCurrent)iCurrent = 0;
  56. face.mIndices[0] = iCurrent++;
  57. if (499 == iCurrent)iCurrent = 0;
  58. face.mIndices[1] = iCurrent++;
  59. if (499 == iCurrent)iCurrent = 0;
  60. face.mIndices[2] = iCurrent++;
  61. if (rand() > RAND_MAX/2 && face.mIndices[0])
  62. {
  63. face.mIndices[0]--;
  64. }
  65. else if (face.mIndices[1]) face.mIndices[1]--;
  66. }
  67. }
  68. // ------------------------------------------------------------------------------------------------
  69. void VTAdjacency :: tearDown (void)
  70. {
  71. delete pMesh;
  72. pMesh = 0;
  73. delete pMesh2;
  74. pMesh2 = 0;
  75. delete pMesh3;
  76. pMesh3 = 0;
  77. }
  78. // ------------------------------------------------------------------------------------------------
  79. void VTAdjacency :: largeRandomDataSet (void)
  80. {
  81. checkMesh(pMesh);
  82. }
  83. // ------------------------------------------------------------------------------------------------
  84. void VTAdjacency :: smallDataSet (void)
  85. {
  86. checkMesh(pMesh2);
  87. }
  88. // ------------------------------------------------------------------------------------------------
  89. void VTAdjacency :: unreferencedVerticesSet (void)
  90. {
  91. checkMesh(pMesh3);
  92. }
  93. // ------------------------------------------------------------------------------------------------
  94. void VTAdjacency :: checkMesh (aiMesh* pMesh)
  95. {
  96. pAdj = new VertexTriangleAdjacency(pMesh->mFaces,pMesh->mNumFaces,pMesh->mNumVertices,true);
  97. unsigned int* const piNum = pAdj->mLiveTriangles;
  98. // check the primary adjacency table and check whether all faces
  99. // are contained in the list
  100. unsigned int maxOfs = 0;
  101. for (unsigned int i = 0; i < pMesh->mNumFaces;++i)
  102. {
  103. aiFace& face = pMesh->mFaces[i];
  104. for (unsigned int qq = 0; qq < 3 ;++qq)
  105. {
  106. const unsigned int idx = face.mIndices[qq];
  107. const unsigned int num = piNum[idx];
  108. // go to this offset
  109. const unsigned int ofs = pAdj->mOffsetTable[idx];
  110. maxOfs = std::max(ofs+num,maxOfs);
  111. unsigned int* pi = &pAdj->mAdjacencyTable[ofs];
  112. // and search for us ...
  113. unsigned int tt = 0;
  114. for (; tt < num;++tt,++pi)
  115. {
  116. if (i == *pi)
  117. {
  118. // mask our entry in the table. Finally all entries should be masked
  119. *pi = 0xffffffff;
  120. // there shouldn't be two entries for the same face
  121. break;
  122. }
  123. }
  124. // assert if *this* vertex has not been found in the table
  125. CPPUNIT_ASSERT(tt < num);
  126. }
  127. }
  128. // now check whether there are invalid faces
  129. const unsigned int* pi = pAdj->mAdjacencyTable;
  130. for (unsigned int i = 0; i < maxOfs;++i,++pi)
  131. {
  132. CPPUNIT_ASSERT(0xffffffff == *pi);
  133. }
  134. // check the numTrianglesPerVertex table
  135. for (unsigned int i = 0; i < pMesh->mNumFaces;++i)
  136. {
  137. aiFace& face = pMesh->mFaces[i];
  138. for (unsigned int qq = 0; qq < 3 ;++qq)
  139. {
  140. const unsigned int idx = face.mIndices[qq];
  141. // we should not reach 0 here ...
  142. CPPUNIT_ASSERT( 0 != piNum[idx]);
  143. piNum[idx]--;
  144. }
  145. }
  146. // check whether we reached 0 in all entries
  147. for (unsigned int i = 0; i < pMesh->mNumVertices;++i)
  148. {
  149. CPPUNIT_ASSERT(!piNum[i]);
  150. }
  151. delete pAdj;
  152. }