Refactoring the volume unit test code, trying to get some performance benchmarks. Unit tests are currently not passing.
This commit is contained in:
parent
dac0e5449f
commit
d8da6a7b7f
@ -127,6 +127,11 @@ namespace PolyVox
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
class Region;
|
class Region;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// SimpleVolume
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename VoxelType> class SimpleVolume;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// MarchingCubesSurfaceExtractor
|
// MarchingCubesSurfaceExtractor
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -96,9 +96,14 @@ ADD_TEST(VectorEqualityTest ${LATEST_TEST} testEquality)
|
|||||||
|
|
||||||
# Volume tests
|
# Volume tests
|
||||||
CREATE_TEST(testvolume.h testvolume.cpp testvolume)
|
CREATE_TEST(testvolume.h testvolume.cpp testvolume)
|
||||||
ADD_TEST(LargeVolumeTest ${LATEST_TEST} testLargeVolume)
|
|
||||||
ADD_TEST(RawVolumeTest ${LATEST_TEST} testRawVolume)
|
ADD_TEST(RawVolumeDirectAccessTest ${LATEST_TEST} testRawVolumeDirectAccess)
|
||||||
ADD_TEST(SimpleVolumeTest ${LATEST_TEST} testSimpleVolume)
|
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
|
# Volume subclass tests
|
||||||
CREATE_TEST(TestVolumeSubclass.h TestVolumeSubclass.cpp TestVolumeSubclass)
|
CREATE_TEST(TestVolumeSubclass.h TestVolumeSubclass.cpp TestVolumeSubclass)
|
||||||
|
@ -61,6 +61,88 @@ VolumeType* createAndFillVolume(void)
|
|||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename VolumeType>
|
||||||
|
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 <typename VolumeType>
|
||||||
|
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 <typename VolumeType>
|
template <typename VolumeType>
|
||||||
int32_t complexVolumeTest(void)
|
int32_t complexVolumeTest(void)
|
||||||
{
|
{
|
||||||
@ -174,34 +256,100 @@ int32_t complexVolumeTest(void)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestVolume::testLargeVolume()
|
TestVolume::TestVolume()
|
||||||
{
|
{
|
||||||
int32_t result = 0;
|
Region region(-57, -31, 12, 64, 96, 131); // Deliberatly awkward size
|
||||||
QBENCHMARK
|
|
||||||
|
//Create the volumes
|
||||||
|
m_pRawVolume = new RawVolume<int32_t>(region);
|
||||||
|
m_pSimpleVolume = new SimpleVolume<int32_t>(region);
|
||||||
|
m_pLargeVolume = new LargeVolume<int32_t>(region);
|
||||||
|
|
||||||
|
//Fill the volume with some data
|
||||||
|
qsrand(42);
|
||||||
|
for(int z = region.getLowerZ(); z <= region.getUpperZ(); z++)
|
||||||
{
|
{
|
||||||
result = complexVolumeTest< LargeVolume<int32_t> >();
|
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<int32_t>(-928813120));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestVolume::testRawVolume()
|
TestVolume::~TestVolume()
|
||||||
{
|
{
|
||||||
int32_t result = 0;
|
delete m_pRawVolume;
|
||||||
QBENCHMARK
|
delete m_pSimpleVolume;
|
||||||
{
|
delete m_pLargeVolume;
|
||||||
result = complexVolumeTest< RawVolume<int32_t> >();
|
|
||||||
}
|
|
||||||
QCOMPARE(result, static_cast<int32_t>(-928813120));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestVolume::testSimpleVolume()
|
void TestVolume::testRawVolumeDirectAccess()
|
||||||
|
{
|
||||||
|
int32_t result = 0;
|
||||||
|
|
||||||
|
QBENCHMARK
|
||||||
|
{
|
||||||
|
result = testDirectAccessWithWrapping(m_pRawVolume);
|
||||||
|
}
|
||||||
|
QCOMPARE(result, static_cast<int32_t>(-289709888));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestVolume::testRawVolumeSamplers()
|
||||||
|
{
|
||||||
|
int32_t result = 0;
|
||||||
|
|
||||||
|
QBENCHMARK
|
||||||
|
{
|
||||||
|
result = testSamplersWithWrapping(m_pRawVolume);
|
||||||
|
}
|
||||||
|
QCOMPARE(result, static_cast<int32_t>(-289709888));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestVolume::testSimpleVolumeDirectAccess()
|
||||||
{
|
{
|
||||||
int32_t result = 0;
|
int32_t result = 0;
|
||||||
QBENCHMARK
|
QBENCHMARK
|
||||||
{
|
{
|
||||||
result = complexVolumeTest< SimpleVolume<int32_t> >();
|
result = testDirectAccessWithWrapping(m_pSimpleVolume);
|
||||||
}
|
}
|
||||||
QCOMPARE(result, static_cast<int32_t>(-928813120));
|
QCOMPARE(result, static_cast<int32_t>(-289709888));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestVolume::testSimpleVolumeSamplers()
|
||||||
|
{
|
||||||
|
int32_t result = 0;
|
||||||
|
QBENCHMARK
|
||||||
|
{
|
||||||
|
result = testSamplersWithWrapping(m_pSimpleVolume);
|
||||||
|
}
|
||||||
|
QCOMPARE(result, static_cast<int32_t>(-289709888));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestVolume::testLargeVolumeDirectAccess()
|
||||||
|
{
|
||||||
|
int32_t result = 0;
|
||||||
|
QBENCHMARK
|
||||||
|
{
|
||||||
|
result = testDirectAccessWithWrapping(m_pLargeVolume);
|
||||||
|
}
|
||||||
|
QCOMPARE(result, static_cast<int32_t>(-289709888));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestVolume::testLargeVolumeSamplers()
|
||||||
|
{
|
||||||
|
int32_t result = 0;
|
||||||
|
|
||||||
|
QBENCHMARK
|
||||||
|
{
|
||||||
|
result = testSamplersWithWrapping(m_pLargeVolume);
|
||||||
|
}
|
||||||
|
QCOMPARE(result, static_cast<int32_t>(-289709888));
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(TestVolume)
|
QTEST_MAIN(TestVolume)
|
||||||
|
@ -24,16 +24,32 @@ freely, subject to the following restrictions:
|
|||||||
#ifndef __PolyVox_TestVolume_H__
|
#ifndef __PolyVox_TestVolume_H__
|
||||||
#define __PolyVox_TestVolume_H__
|
#define __PolyVox_TestVolume_H__
|
||||||
|
|
||||||
|
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class TestVolume: public QObject
|
class TestVolume: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
TestVolume();
|
||||||
|
~TestVolume();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void testLargeVolume();
|
void testRawVolumeDirectAccess();
|
||||||
void testRawVolume();
|
void testRawVolumeSamplers();
|
||||||
void testSimpleVolume();
|
|
||||||
|
void testSimpleVolumeDirectAccess();
|
||||||
|
void testSimpleVolumeSamplers();
|
||||||
|
|
||||||
|
void testLargeVolumeDirectAccess();
|
||||||
|
void testLargeVolumeSamplers();
|
||||||
|
|
||||||
|
private:
|
||||||
|
PolyVox::RawVolume<int32_t>* m_pRawVolume;
|
||||||
|
PolyVox::SimpleVolume<int32_t>* m_pSimpleVolume;
|
||||||
|
PolyVox::LargeVolume<int32_t>* m_pLargeVolume;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user