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.
 
 
 
 
 
 

93 lines
2.5 KiB

  1. #include "UnitTestPCH.h"
  2. #include "utFindDegenerates.h"
  3. CPPUNIT_TEST_SUITE_REGISTRATION (FindDegeneratesProcessTest);
  4. // ------------------------------------------------------------------------------------------------
  5. void FindDegeneratesProcessTest :: setUp (void)
  6. {
  7. mesh = new aiMesh();
  8. process = new FindDegeneratesProcess();
  9. mesh->mNumFaces = 1000;
  10. mesh->mFaces = new aiFace[1000];
  11. mesh->mNumVertices = 5000*2;
  12. mesh->mVertices = new aiVector3D[5000*2];
  13. for (unsigned int i = 0; i < 5000; ++i) {
  14. mesh->mVertices[i] = mesh->mVertices[i+5000] = aiVector3D((float)i);
  15. }
  16. mesh->mPrimitiveTypes = aiPrimitiveType_LINE | aiPrimitiveType_POINT |
  17. aiPrimitiveType_POLYGON | aiPrimitiveType_TRIANGLE;
  18. unsigned int numOut = 0, numFaces = 0;
  19. for (unsigned int i = 0; i < 1000; ++i) {
  20. aiFace& f = mesh->mFaces[i];
  21. f.mNumIndices = (i % 5)+1; // between 1 and 5
  22. f.mIndices = new unsigned int[f.mNumIndices];
  23. bool had = false;
  24. for (unsigned int n = 0; n < f.mNumIndices;++n) {
  25. // FIXME
  26. #if 0
  27. // some duplicate indices
  28. if ( n && n == (i / 200)+1) {
  29. f.mIndices[n] = f.mIndices[n-1];
  30. had = true;
  31. }
  32. // and some duplicate vertices
  33. #endif
  34. if (n && i % 2 && 0 == n % 2) {
  35. f.mIndices[n] = f.mIndices[n-1]+5000;
  36. had = true;
  37. }
  38. else {
  39. f.mIndices[n] = numOut++;
  40. }
  41. }
  42. if (!had)
  43. ++numFaces;
  44. }
  45. mesh->mNumUVComponents[0] = numOut;
  46. mesh->mNumUVComponents[1] = numFaces;
  47. }
  48. // ------------------------------------------------------------------------------------------------
  49. void FindDegeneratesProcessTest :: tearDown (void)
  50. {
  51. delete mesh;
  52. delete process;
  53. }
  54. // ------------------------------------------------------------------------------------------------
  55. void FindDegeneratesProcessTest :: testDegeneratesDetection( void )
  56. {
  57. process->EnableInstantRemoval(false);
  58. process->ExecuteOnMesh(mesh);
  59. unsigned int out = 0;
  60. for (unsigned int i = 0; i < 1000; ++i) {
  61. aiFace& f = mesh->mFaces[i];
  62. out += f.mNumIndices;
  63. }
  64. CPPUNIT_ASSERT(mesh->mNumFaces == 1000 && mesh->mNumVertices == 10000);
  65. CPPUNIT_ASSERT(mesh->mNumUVComponents[0] == out);
  66. CPPUNIT_ASSERT(mesh->mPrimitiveTypes == (aiPrimitiveType_LINE | aiPrimitiveType_POINT |
  67. aiPrimitiveType_POLYGON | aiPrimitiveType_TRIANGLE));
  68. }
  69. // ------------------------------------------------------------------------------------------------
  70. void FindDegeneratesProcessTest :: testDegeneratesRemoval( void )
  71. {
  72. process->EnableInstantRemoval(true);
  73. process->ExecuteOnMesh(mesh);
  74. CPPUNIT_ASSERT(mesh->mNumUVComponents[1] == mesh->mNumFaces);
  75. }