Work on cubic extractor tests.

This commit is contained in:
David Williams 2014-08-18 16:48:32 +02:00
parent ec9b06ef0f
commit c0added385

View File

@ -26,6 +26,7 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/Density.h" #include "PolyVoxCore/Density.h"
#include "PolyVoxCore/Material.h" #include "PolyVoxCore/Material.h"
#include "PolyVoxCore/MaterialDensityPair.h" #include "PolyVoxCore/MaterialDensityPair.h"
#include "PolyVoxCore/RawVolume.h"
#include "PolyVoxCore/SimpleVolume.h" #include "PolyVoxCore/SimpleVolume.h"
#include "PolyVoxCore/CubicSurfaceExtractor.h" #include "PolyVoxCore/CubicSurfaceExtractor.h"
@ -56,11 +57,11 @@ public:
}; };
// Runs the surface extractor for a given type. // Runs the surface extractor for a given type.
template <typename VoxelType> template <typename VolumeType>
SimpleVolume<VoxelType>* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, VoxelType minValue, VoxelType maxValue) VolumeType* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, typename VolumeType::VoxelType minValue, typename VolumeType::VoxelType maxValue)
{ {
//Create empty volume //Create empty volume
SimpleVolume<VoxelType>* volData = new SimpleVolume<VoxelType>(Region(Vector3DInt32(0, 0, 0), Vector3DInt32(iVolumeSideLength - 1, iVolumeSideLength - 1, iVolumeSideLength - 1)), 32); VolumeType* volData = new VolumeType(Region(Vector3DInt32(0, 0, 0), Vector3DInt32(iVolumeSideLength - 1, iVolumeSideLength - 1, iVolumeSideLength - 1)));
srand(12345); srand(12345);
@ -80,7 +81,7 @@ SimpleVolume<VoxelType>* createAndFillVolumeWithNoise(int32_t iVolumeSideLength,
{ {
// Otherwise we write random voxel values between zero and the requested maximum // Otherwise we write random voxel values between zero and the requested maximum
int voxelValue = (rand() % (maxValue - minValue + 1)) + minValue; int voxelValue = (rand() % (maxValue - minValue + 1)) + minValue;
volData->setVoxelAt(x, y, z, static_cast<VoxelType>(voxelValue)); volData->setVoxelAt(x, y, z, static_cast<typename VolumeType::VoxelType>(voxelValue));
} }
} }
} }
@ -92,26 +93,26 @@ SimpleVolume<VoxelType>* createAndFillVolumeWithNoise(int32_t iVolumeSideLength,
void TestCubicSurfaceExtractor::testBehaviour() void TestCubicSurfaceExtractor::testBehaviour()
{ {
// Test with default mesh and contoller types. // Test with default mesh and contoller types.
auto uint8Vol = createAndFillVolumeWithNoise<uint8_t>(32, 0, 2); auto uint8Vol = createAndFillVolumeWithNoise< SimpleVolume<uint8_t> >(32, 0, 2);
auto uint8Mesh = extractCubicMesh(uint8Vol, uint8Vol->getEnclosingRegion()); auto uint8Mesh = extractCubicMesh(uint8Vol, uint8Vol->getEnclosingRegion());
QCOMPARE(uint8Mesh.getNoOfVertices(), uint32_t(57687)); QCOMPARE(uint8Mesh.getNoOfVertices(), uint32_t(57687));
QCOMPARE(uint8Mesh.getNoOfIndices(), uint32_t(216234)); QCOMPARE(uint8Mesh.getNoOfIndices(), uint32_t(216234));
// Test with default mesh type but user-provided controller. // Test with default mesh type but user-provided controller.
auto int8Vol = createAndFillVolumeWithNoise<int8_t>(32, 0, 2); auto int8Vol = createAndFillVolumeWithNoise< SimpleVolume<int8_t> >(32, 0, 2);
auto int8Mesh = extractCubicMesh(int8Vol, int8Vol->getEnclosingRegion(), CustomIsQuadNeeded<int8_t>()); auto int8Mesh = extractCubicMesh(int8Vol, int8Vol->getEnclosingRegion(), CustomIsQuadNeeded<int8_t>());
QCOMPARE(int8Mesh.getNoOfVertices(), uint32_t(29027)); QCOMPARE(int8Mesh.getNoOfVertices(), uint32_t(29027));
QCOMPARE(int8Mesh.getNoOfIndices(), uint32_t(178356)); QCOMPARE(int8Mesh.getNoOfIndices(), uint32_t(178356));
// Test with default controller but user-provided mesh. // Test with default controller but user-provided mesh.
auto uint32Vol = createAndFillVolumeWithNoise<uint32_t>(32, 0, 2); auto uint32Vol = createAndFillVolumeWithNoise< SimpleVolume<uint32_t> >(32, 0, 2);
CubicMesh< uint32_t, uint16_t > uint32Mesh; CubicMesh< uint32_t, uint16_t > uint32Mesh;
extractCubicMeshCustom(uint32Vol, uint32Vol->getEnclosingRegion(), &uint32Mesh); extractCubicMeshCustom(uint32Vol, uint32Vol->getEnclosingRegion(), &uint32Mesh);
QCOMPARE(uint32Mesh.getNoOfVertices(), uint16_t(57687)); QCOMPARE(uint32Mesh.getNoOfVertices(), uint16_t(57687));
QCOMPARE(uint32Mesh.getNoOfIndices(), uint32_t(216234)); QCOMPARE(uint32Mesh.getNoOfIndices(), uint32_t(216234));
// Test with both mesh and controller being provided by the user. // Test with both mesh and controller being provided by the user.
auto int32Vol = createAndFillVolumeWithNoise<int32_t>(32, 0, 2); auto int32Vol = createAndFillVolumeWithNoise< SimpleVolume<int32_t> >(32, 0, 2);
CubicMesh< int32_t, uint16_t > int32Mesh; CubicMesh< int32_t, uint16_t > int32Mesh;
extractCubicMeshCustom(int32Vol, int32Vol->getEnclosingRegion(), &int32Mesh, CustomIsQuadNeeded<int32_t>()); extractCubicMeshCustom(int32Vol, int32Vol->getEnclosingRegion(), &int32Mesh, CustomIsQuadNeeded<int32_t>());
QCOMPARE(int32Mesh.getNoOfVertices(), uint16_t(29027)); QCOMPARE(int32Mesh.getNoOfVertices(), uint16_t(29027));
@ -120,7 +121,7 @@ void TestCubicSurfaceExtractor::testBehaviour()
void TestCubicSurfaceExtractor::testEmptyVolumePerformance() void TestCubicSurfaceExtractor::testEmptyVolumePerformance()
{ {
auto emptyVol = createAndFillVolumeWithNoise<uint32_t>(32, 0, 0); auto emptyVol = createAndFillVolumeWithNoise< RawVolume<uint32_t> >(32, 0, 0);
CubicMesh< uint32_t, uint16_t > emptyMesh; CubicMesh< uint32_t, uint16_t > emptyMesh;
QBENCHMARK{ extractCubicMeshCustom(emptyVol, emptyVol->getEnclosingRegion(), &emptyMesh); } QBENCHMARK{ extractCubicMeshCustom(emptyVol, emptyVol->getEnclosingRegion(), &emptyMesh); }
QCOMPARE(emptyMesh.getNoOfVertices(), uint16_t(0)); QCOMPARE(emptyMesh.getNoOfVertices(), uint16_t(0));
@ -128,7 +129,7 @@ void TestCubicSurfaceExtractor::testEmptyVolumePerformance()
void TestCubicSurfaceExtractor::testNoiseVolumePerformance() void TestCubicSurfaceExtractor::testNoiseVolumePerformance()
{ {
auto noiseVol = createAndFillVolumeWithNoise<uint32_t>(32, 0, 1); auto noiseVol = createAndFillVolumeWithNoise< RawVolume<uint32_t> >(32, 0, 1);
CubicMesh< uint32_t, uint16_t > noiseMesh; CubicMesh< uint32_t, uint16_t > noiseMesh;
QBENCHMARK{ extractCubicMeshCustom(noiseVol, noiseVol->getEnclosingRegion(), &noiseMesh); } QBENCHMARK{ extractCubicMeshCustom(noiseVol, noiseVol->getEnclosingRegion(), &noiseMesh); }
QCOMPARE(noiseMesh.getNoOfVertices(), uint16_t(28429)); QCOMPARE(noiseMesh.getNoOfVertices(), uint16_t(28429));