diff --git a/tests/TestCubicSurfaceExtractor.cpp b/tests/TestCubicSurfaceExtractor.cpp index 0b12bb34..7e781e33 100644 --- a/tests/TestCubicSurfaceExtractor.cpp +++ b/tests/TestCubicSurfaceExtractor.cpp @@ -32,6 +32,8 @@ freely, subject to the following restrictions: #include +#include + using namespace PolyVox; template @@ -63,8 +65,9 @@ VolumeType* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, typename Vol //Create empty volume VolumeType* volData = new VolumeType(Region(Vector3DInt32(0, 0, 0), Vector3DInt32(iVolumeSideLength - 1, iVolumeSideLength - 1, iVolumeSideLength - 1))); - // Seed generator for consistency between runs. - srand(12345); + // Set up a random number generator + std::mt19937 rng; + std::uniform_int_distribution dist(minValue, maxValue); //Fill the volume with data for (int32_t z = 0; z < iVolumeSideLength; z++) @@ -81,7 +84,7 @@ VolumeType* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, typename Vol else { // Otherwise we write random voxel values between zero and the requested maximum - int voxelValue = (rand() % (maxValue - minValue + 1)) + minValue; + VolumeType::VoxelType voxelValue = static_cast(dist(rng)); volData->setVoxelAt(x, y, z, static_cast(voxelValue)); } } @@ -98,9 +101,6 @@ VolumeType* createAndFillVolumeRealistic(int32_t iVolumeSideLength) //Create empty volume VolumeType* volData = new VolumeType(Region(Vector3DInt32(0, 0, 0), Vector3DInt32(iVolumeSideLength - 1, iVolumeSideLength - 1, iVolumeSideLength - 1))); - // Seed generator for consistency between runs. - srand(12345); - //Fill the volume with data for (int32_t z = 0; z < iVolumeSideLength; z++) { @@ -130,28 +130,28 @@ void TestCubicSurfaceExtractor::testBehaviour() // Test with default mesh and contoller types. auto uint8Vol = createAndFillVolumeWithNoise< PagedVolume >(32, 0, 2); auto uint8Mesh = extractCubicMesh(uint8Vol, uint8Vol->getEnclosingRegion()); - QCOMPARE(uint8Mesh.getNoOfVertices(), uint32_t(57687)); - QCOMPARE(uint8Mesh.getNoOfIndices(), uint32_t(216234)); + QCOMPARE(uint8Mesh.getNoOfVertices(), uint32_t(57544)); + QCOMPARE(uint8Mesh.getNoOfIndices(), uint32_t(215304)); // Test with default mesh type but user-provided controller. auto int8Vol = createAndFillVolumeWithNoise< PagedVolume >(32, 0, 2); auto int8Mesh = extractCubicMesh(int8Vol, int8Vol->getEnclosingRegion(), CustomIsQuadNeeded()); - QCOMPARE(int8Mesh.getNoOfVertices(), uint32_t(29027)); - QCOMPARE(int8Mesh.getNoOfIndices(), uint32_t(178356)); + QCOMPARE(int8Mesh.getNoOfVertices(), uint32_t(29106)); + QCOMPARE(int8Mesh.getNoOfIndices(), uint32_t(178566)); // Test with default controller but user-provided mesh. auto uint32Vol = createAndFillVolumeWithNoise< PagedVolume >(32, 0, 2); Mesh< CubicVertex< uint32_t >, uint16_t > uint32Mesh; extractCubicMeshCustom(uint32Vol, uint32Vol->getEnclosingRegion(), &uint32Mesh); - QCOMPARE(uint32Mesh.getNoOfVertices(), uint16_t(57687)); - QCOMPARE(uint32Mesh.getNoOfIndices(), uint32_t(216234)); + QCOMPARE(uint32Mesh.getNoOfVertices(), uint16_t(57544)); + QCOMPARE(uint32Mesh.getNoOfIndices(), uint32_t(215304)); // Test with both mesh and controller being provided by the user. auto int32Vol = createAndFillVolumeWithNoise< PagedVolume >(32, 0, 2); Mesh< CubicVertex< int32_t >, uint16_t > int32Mesh; extractCubicMeshCustom(int32Vol, int32Vol->getEnclosingRegion(), &int32Mesh, CustomIsQuadNeeded()); - QCOMPARE(int32Mesh.getNoOfVertices(), uint16_t(29027)); - QCOMPARE(int32Mesh.getNoOfIndices(), uint32_t(178356)); + QCOMPARE(int32Mesh.getNoOfVertices(), uint16_t(29106)); + QCOMPARE(int32Mesh.getNoOfIndices(), uint32_t(178566)); } void TestCubicSurfaceExtractor::testEmptyVolumePerformance() @@ -175,7 +175,7 @@ void TestCubicSurfaceExtractor::testNoiseVolumePerformance() auto noiseVol = createAndFillVolumeWithNoise< PagedVolume >(128, 0, 2); Mesh< CubicVertex< uint32_t >, uint16_t > noiseMesh; QBENCHMARK{ extractCubicMeshCustom(noiseVol, Region(32, 32, 32, 63, 63, 63), &noiseMesh); } - QCOMPARE(noiseMesh.getNoOfVertices(), uint16_t(57729)); + QCOMPARE(noiseMesh.getNoOfVertices(), uint16_t(57905)); } QTEST_MAIN(TestCubicSurfaceExtractor) diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index bbdca389..2848b552 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -32,6 +32,8 @@ freely, subject to the following restrictions: #include +#include + using namespace PolyVox; // Test our ability to modify the behaviour of the MarchingCubesSurfaceExtractor. This simple example only modifies @@ -143,8 +145,9 @@ VolumeType* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, float minVal //Create empty volume VolumeType* volData = new VolumeType(Region(Vector3DInt32(0, 0, 0), Vector3DInt32(iVolumeSideLength - 1, iVolumeSideLength - 1, iVolumeSideLength - 1)), pager); - // Seed generator for consistency between runs. - srand(12345); + // Set up a random number generator + std::mt19937 rng; + std::uniform_real_distribution dist(minValue, maxValue); // Fill for (int32_t z = 0; z < iVolumeSideLength; z++) @@ -153,7 +156,7 @@ VolumeType* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, float minVal { for (int32_t x = 0; x < iVolumeSideLength; x++) { - float voxelValue = randomFloat(minValue, maxValue); + float voxelValue = dist(rng); volData->setVoxelAt(x, y, z, voxelValue); } } @@ -230,7 +233,7 @@ void TestSurfaceExtractor::testNoiseVolumePerformance() auto noiseVol = createAndFillVolumeWithNoise< PagedVolume >(128, -1.0f, 1.0f); Mesh< MarchingCubesVertex< float >, uint16_t > noiseMesh; QBENCHMARK{ extractMarchingCubesMeshCustom(noiseVol, Region(32, 32, 32, 63, 63, 63), &noiseMesh); } - QCOMPARE(noiseMesh.getNoOfVertices(), uint16_t(48967)); + QCOMPARE(noiseMesh.getNoOfVertices(), uint16_t(48704)); } QTEST_MAIN(TestSurfaceExtractor)