diff --git a/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h index 068f379d..addaa962 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h @@ -127,6 +127,11 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// class Region; + //////////////////////////////////////////////////////////////////////////////// + // SimpleVolume + //////////////////////////////////////////////////////////////////////////////// + template class SimpleVolume; + //////////////////////////////////////////////////////////////////////////////// // MarchingCubesSurfaceExtractor //////////////////////////////////////////////////////////////////////////////// diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4a75e10f..2aa52de1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -96,9 +96,14 @@ ADD_TEST(VectorEqualityTest ${LATEST_TEST} testEquality) # Volume tests CREATE_TEST(testvolume.h testvolume.cpp testvolume) -ADD_TEST(LargeVolumeTest ${LATEST_TEST} testLargeVolume) -ADD_TEST(RawVolumeTest ${LATEST_TEST} testRawVolume) -ADD_TEST(SimpleVolumeTest ${LATEST_TEST} testSimpleVolume) + +ADD_TEST(RawVolumeDirectAccessTest ${LATEST_TEST} testRawVolumeDirectAccess) +ADD_TEST(SimpleVolumeDirectAccessTest ${LATEST_TEST} testSimpleVolumeDirectAccess) +ADD_TEST(LargeVolumeDirectAccessTest ${LATEST_TEST} testLargeVolumeDirectAccess) + +ADD_TEST(RawVolumeSamplersTest ${LATEST_TEST} testRawVolumeSamplers) +ADD_TEST(SimpleVolumeSamplersTest ${LATEST_TEST} testSimpleVolumeSamplers) +ADD_TEST(LargeVolumeSamplersTest ${LATEST_TEST} testLargeVolumeSamplers) # Volume subclass tests CREATE_TEST(TestVolumeSubclass.h TestVolumeSubclass.cpp TestVolumeSubclass) diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index 76988e30..27039cbf 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -61,6 +61,88 @@ VolumeType* createAndFillVolume(void) return volume; } +template +int32_t testDirectAccessWithWrapping(const VolumeType* volume) +{ + int32_t result = 0; + + for(int z = volume->getEnclosingRegion().getLowerZ() - 2; z <= volume->getEnclosingRegion().getUpperZ() + 4; z++) + { + for(int y = volume->getEnclosingRegion().getLowerY() - 3; y <= volume->getEnclosingRegion().getUpperY() + 5; y++) + { + for(int x = volume->getEnclosingRegion().getLowerX() - 1; x <= volume->getEnclosingRegion().getUpperX() + 2; x++) + { + //Three level loop now processes 27 voxel neighbourhood + for(int innerZ = -1; innerZ <=1; innerZ++) + { + for(int innerY = -1; innerY <=1; innerY++) + { + for(int innerX = -1; innerX <=1; innerX++) + { + result = cantorTupleFunction(result, volume->getVoxelWithWrapping(x + innerX, y + innerY, z + innerZ, WrapModes::Border, 3)); + } + } + } + //End of inner loops + } + } + } + + return result; +} + +template +int32_t testSamplersWithWrapping(VolumeType* volume) +{ + int32_t result = 0; + + VolumeType::Sampler sampler(volume); + sampler.setWrapMode(WrapModes::Border, 3); + + for(int z = volume->getEnclosingRegion().getLowerZ() - 2; z <= volume->getEnclosingRegion().getUpperZ() + 4; z++) + { + for(int y = volume->getEnclosingRegion().getLowerY() - 3; y <= volume->getEnclosingRegion().getUpperY() + 5; y++) + { + for(int x = volume->getEnclosingRegion().getLowerX() - 1; x <= volume->getEnclosingRegion().getUpperX() + 2; x++) + { + sampler.setPosition(x, y, z); + + result = cantorTupleFunction(result, sampler.peekVoxel1nx1ny1nz()); + result = cantorTupleFunction(result, sampler.peekVoxel0px1ny1nz()); + result = cantorTupleFunction(result, sampler.peekVoxel1px1ny1nz()); + result = cantorTupleFunction(result, sampler.peekVoxel1nx0py1nz()); + result = cantorTupleFunction(result, sampler.peekVoxel0px0py1nz()); + result = cantorTupleFunction(result, sampler.peekVoxel1px0py1nz()); + result = cantorTupleFunction(result, sampler.peekVoxel1nx1py1nz()); + result = cantorTupleFunction(result, sampler.peekVoxel0px1py1nz()); + result = cantorTupleFunction(result, sampler.peekVoxel1px1py1nz()); + + result = cantorTupleFunction(result, sampler.peekVoxel1nx1ny0pz()); + result = cantorTupleFunction(result, sampler.peekVoxel0px1ny0pz()); + result = cantorTupleFunction(result, sampler.peekVoxel1px1ny0pz()); + result = cantorTupleFunction(result, sampler.peekVoxel1nx0py0pz()); + result = cantorTupleFunction(result, sampler.peekVoxel0px0py0pz()); + result = cantorTupleFunction(result, sampler.peekVoxel1px0py0pz()); + result = cantorTupleFunction(result, sampler.peekVoxel1nx1py0pz()); + result = cantorTupleFunction(result, sampler.peekVoxel0px1py0pz()); + result = cantorTupleFunction(result, sampler.peekVoxel1px1py0pz()); + + result = cantorTupleFunction(result, sampler.peekVoxel1nx1ny1pz()); + result = cantorTupleFunction(result, sampler.peekVoxel0px1ny1pz()); + result = cantorTupleFunction(result, sampler.peekVoxel1px1ny1pz()); + result = cantorTupleFunction(result, sampler.peekVoxel1nx0py1pz()); + result = cantorTupleFunction(result, sampler.peekVoxel0px0py1pz()); + result = cantorTupleFunction(result, sampler.peekVoxel1px0py1pz()); + result = cantorTupleFunction(result, sampler.peekVoxel1nx1py1pz()); + result = cantorTupleFunction(result, sampler.peekVoxel0px1py1pz()); + result = cantorTupleFunction(result, sampler.peekVoxel1px1py1pz()); + } + } + } + + return result; +} + template int32_t complexVolumeTest(void) { @@ -174,34 +256,100 @@ int32_t complexVolumeTest(void) return result; } -void TestVolume::testLargeVolume() +TestVolume::TestVolume() { - int32_t result = 0; - QBENCHMARK + Region region(-57, -31, 12, 64, 96, 131); // Deliberatly awkward size + + //Create the volumes + m_pRawVolume = new RawVolume(region); + m_pSimpleVolume = new SimpleVolume(region); + m_pLargeVolume = new LargeVolume(region); + + //Fill the volume with some data + qsrand(42); + for(int z = region.getLowerZ(); z <= region.getUpperZ(); z++) { - result = complexVolumeTest< LargeVolume >(); + for(int y = region.getLowerY(); y <= region.getUpperY(); y++) + { + for(int x = region.getLowerX(); x <= region.getUpperX(); x++) + { + int32_t value = qrand() - (RAND_MAX / 2); + m_pRawVolume->setVoxelAt(x, y, z, value); + m_pSimpleVolume->setVoxelAt(x, y, z, value); + m_pLargeVolume->setVoxelAt(x, y, z, value); + } + } } - QCOMPARE(result, static_cast(-928813120)); } -void TestVolume::testRawVolume() +TestVolume::~TestVolume() { - int32_t result = 0; - QBENCHMARK - { - result = complexVolumeTest< RawVolume >(); - } - QCOMPARE(result, static_cast(-928813120)); + delete m_pRawVolume; + delete m_pSimpleVolume; + delete m_pLargeVolume; } -void TestVolume::testSimpleVolume() +void TestVolume::testRawVolumeDirectAccess() +{ + int32_t result = 0; + + QBENCHMARK + { + result = testDirectAccessWithWrapping(m_pRawVolume); + } + QCOMPARE(result, static_cast(-289709888)); +} + +void TestVolume::testRawVolumeSamplers() +{ + int32_t result = 0; + + QBENCHMARK + { + result = testSamplersWithWrapping(m_pRawVolume); + } + QCOMPARE(result, static_cast(-289709888)); +} + +void TestVolume::testSimpleVolumeDirectAccess() { int32_t result = 0; QBENCHMARK { - result = complexVolumeTest< SimpleVolume >(); + result = testDirectAccessWithWrapping(m_pSimpleVolume); } - QCOMPARE(result, static_cast(-928813120)); + QCOMPARE(result, static_cast(-289709888)); +} + +void TestVolume::testSimpleVolumeSamplers() +{ + int32_t result = 0; + QBENCHMARK + { + result = testSamplersWithWrapping(m_pSimpleVolume); + } + QCOMPARE(result, static_cast(-289709888)); +} + +void TestVolume::testLargeVolumeDirectAccess() +{ + int32_t result = 0; + QBENCHMARK + { + result = testDirectAccessWithWrapping(m_pLargeVolume); + } + QCOMPARE(result, static_cast(-289709888)); +} + +void TestVolume::testLargeVolumeSamplers() +{ + int32_t result = 0; + + QBENCHMARK + { + result = testSamplersWithWrapping(m_pLargeVolume); + } + QCOMPARE(result, static_cast(-289709888)); } QTEST_MAIN(TestVolume) diff --git a/tests/testvolume.h b/tests/testvolume.h index ef15bf26..a714d90e 100644 --- a/tests/testvolume.h +++ b/tests/testvolume.h @@ -24,16 +24,32 @@ freely, subject to the following restrictions: #ifndef __PolyVox_TestVolume_H__ #define __PolyVox_TestVolume_H__ +#include "PolyVoxCore/PolyVoxForwardDeclarations.h" + #include class TestVolume: public QObject { Q_OBJECT + +public: + TestVolume(); + ~TestVolume(); - private slots: - void testLargeVolume(); - void testRawVolume(); - void testSimpleVolume(); +private slots: + void testRawVolumeDirectAccess(); + void testRawVolumeSamplers(); + + void testSimpleVolumeDirectAccess(); + void testSimpleVolumeSamplers(); + + void testLargeVolumeDirectAccess(); + void testLargeVolumeSamplers(); + +private: + PolyVox::RawVolume* m_pRawVolume; + PolyVox::SimpleVolume* m_pSimpleVolume; + PolyVox::LargeVolume* m_pLargeVolume; }; #endif