From 33c5fe752634709b6d94c5265df653ae1c201750 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 19 Aug 2014 21:36:08 +0200 Subject: [PATCH] More cubic surface extractor tests. --- tests/TestCubicSurfaceExtractor.cpp | 42 +++++++++++++++++++++++++++++ tests/TestCubicSurfaceExtractor.h | 1 + 2 files changed, 43 insertions(+) diff --git a/tests/TestCubicSurfaceExtractor.cpp b/tests/TestCubicSurfaceExtractor.cpp index ac7ac1b3..906a2e80 100644 --- a/tests/TestCubicSurfaceExtractor.cpp +++ b/tests/TestCubicSurfaceExtractor.cpp @@ -91,6 +91,40 @@ VolumeType* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, typename Vol return volData; } +// Runs the surface extractor for a given type. +template +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++) + { + for (int32_t y = 0; y < iVolumeSideLength; y++) + { + for (int32_t x = 0; x < iVolumeSideLength; x++) + { + // Should create a checker board pattern stretched along z? This is 'realistic' in the sense + // that it's not empty/random data, and should allow significant decimation to be performed. + if ((x ^ y) & 0x01) + { + volData->setVoxelAt(x, y, z, 0); + } + else + { + volData->setVoxelAt(x, y, z, 1); + } + } + } + } + + return volData; +} + void TestCubicSurfaceExtractor::testBehaviour() { // Test with default mesh and contoller types. @@ -128,6 +162,14 @@ void TestCubicSurfaceExtractor::testEmptyVolumePerformance() QCOMPARE(emptyMesh.getNoOfVertices(), uint16_t(0)); } +void TestCubicSurfaceExtractor::testRealisticVolumePerformance() +{ + auto realisticVol = createAndFillVolumeRealistic< SimpleVolume >(128); + Mesh< CubicVertex< uint32_t >, uint16_t > realisticMesh; + QBENCHMARK{ extractCubicMeshCustom(realisticVol, Region(32, 32, 32, 63, 63, 63), &realisticMesh); } + QCOMPARE(realisticMesh.getNoOfVertices(), uint16_t(2176)); +} + void TestCubicSurfaceExtractor::testNoiseVolumePerformance() { auto noiseVol = createAndFillVolumeWithNoise< SimpleVolume >(128, 0, 2); diff --git a/tests/TestCubicSurfaceExtractor.h b/tests/TestCubicSurfaceExtractor.h index 15e0da5f..31fb1cc4 100644 --- a/tests/TestCubicSurfaceExtractor.h +++ b/tests/TestCubicSurfaceExtractor.h @@ -33,6 +33,7 @@ class TestCubicSurfaceExtractor: public QObject private slots: void testBehaviour(); void testEmptyVolumePerformance(); + void testRealisticVolumePerformance(); void testNoiseVolumePerformance(); };