diff --git a/tests/TestCubicSurfaceExtractor.cpp b/tests/TestCubicSurfaceExtractor.cpp index c8283af4..6acd3222 100644 --- a/tests/TestCubicSurfaceExtractor.cpp +++ b/tests/TestCubicSurfaceExtractor.cpp @@ -57,21 +57,19 @@ public: // Runs the surface extractor for a given type. template -SimpleVolume* createAndFillVolumeWithNoise(VoxelType minValue, VoxelType maxValue) +SimpleVolume* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, VoxelType minValue, VoxelType maxValue) { - const int32_t uVolumeSideLength = 32; - //Create empty volume - SimpleVolume* volData = new SimpleVolume(Region(Vector3DInt32(0, 0, 0), Vector3DInt32(uVolumeSideLength - 1, uVolumeSideLength - 1, uVolumeSideLength - 1)), 16); + SimpleVolume* volData = new SimpleVolume(Region(Vector3DInt32(0, 0, 0), Vector3DInt32(iVolumeSideLength - 1, iVolumeSideLength - 1, iVolumeSideLength - 1)), 32); srand(12345); //Fill the volume with data - for (int32_t z = 0; z < uVolumeSideLength; z++) + for (int32_t z = 0; z < iVolumeSideLength; z++) { - for (int32_t y = 0; y < uVolumeSideLength; y++) + for (int32_t y = 0; y < iVolumeSideLength; y++) { - for (int32_t x = 0; x < uVolumeSideLength; x++) + for (int32_t x = 0; x < iVolumeSideLength; x++) { if (minValue == maxValue) { @@ -91,43 +89,49 @@ SimpleVolume* createAndFillVolumeWithNoise(VoxelType minValue, VoxelT return volData; } -void TestCubicSurfaceExtractor::testExecute() +void TestCubicSurfaceExtractor::testBehaviour() { - // Behavioural tests - // Test with default mesh and contoller types. - auto uint8Vol = createAndFillVolumeWithNoise(0, 2); + auto uint8Vol = createAndFillVolumeWithNoise(32, 0, 2); auto uint8Mesh = extractCubicMesh(uint8Vol, uint8Vol->getEnclosingRegion()); QCOMPARE(uint8Mesh.getNoOfVertices(), uint32_t(57687)); QCOMPARE(uint8Mesh.getNoOfIndices(), uint32_t(216234)); // Test with default mesh type but user-provided controller. - auto int8Vol = createAndFillVolumeWithNoise(0, 2); + auto int8Vol = createAndFillVolumeWithNoise(32, 0, 2); auto int8Mesh = extractCubicMesh(int8Vol, int8Vol->getEnclosingRegion(), CustomIsQuadNeeded()); QCOMPARE(int8Mesh.getNoOfVertices(), uint32_t(29027)); QCOMPARE(int8Mesh.getNoOfIndices(), uint32_t(178356)); // Test with default controller but user-provided mesh. - auto uint32Vol = createAndFillVolumeWithNoise(0, 2); + auto uint32Vol = createAndFillVolumeWithNoise(32, 0, 2); CubicMesh< uint32_t, uint16_t > uint32Mesh; extractCubicMeshCustom(uint32Vol, uint32Vol->getEnclosingRegion(), &uint32Mesh); QCOMPARE(uint32Mesh.getNoOfVertices(), uint16_t(57687)); QCOMPARE(uint32Mesh.getNoOfIndices(), uint32_t(216234)); // Test with both mesh and controller being provided by the user. - auto int32Vol = createAndFillVolumeWithNoise(0, 2); + auto int32Vol = createAndFillVolumeWithNoise(32, 0, 2); CubicMesh< int32_t, uint16_t > int32Mesh; extractCubicMeshCustom(int32Vol, int32Vol->getEnclosingRegion(), &int32Mesh, CustomIsQuadNeeded()); QCOMPARE(int32Mesh.getNoOfVertices(), uint16_t(29027)); QCOMPARE(int32Mesh.getNoOfIndices(), uint32_t(178356)); +} - // Performance tests - - auto emptyVol = createAndFillVolumeWithNoise(0, 0); +void TestCubicSurfaceExtractor::testEmptyVolumePerformance() +{ + auto emptyVol = createAndFillVolumeWithNoise(32, 0, 0); CubicMesh< uint32_t, uint16_t > emptyMesh; QBENCHMARK{ extractCubicMeshCustom(emptyVol, emptyVol->getEnclosingRegion(), &emptyMesh); } QCOMPARE(emptyMesh.getNoOfVertices(), uint16_t(0)); +} +void TestCubicSurfaceExtractor::testNoiseVolumePerformance() +{ + auto noiseVol = createAndFillVolumeWithNoise(32, 0, 1); + CubicMesh< uint32_t, uint16_t > noiseMesh; + QBENCHMARK{ extractCubicMeshCustom(noiseVol, noiseVol->getEnclosingRegion(), &noiseMesh); } + QCOMPARE(noiseMesh.getNoOfVertices(), uint16_t(28429)); } QTEST_MAIN(TestCubicSurfaceExtractor) diff --git a/tests/TestCubicSurfaceExtractor.h b/tests/TestCubicSurfaceExtractor.h index 1ea815d8..15e0da5f 100644 --- a/tests/TestCubicSurfaceExtractor.h +++ b/tests/TestCubicSurfaceExtractor.h @@ -31,7 +31,9 @@ class TestCubicSurfaceExtractor: public QObject Q_OBJECT private slots: - void testExecute(); + void testBehaviour(); + void testEmptyVolumePerformance(); + void testNoiseVolumePerformance(); }; #endif