From 882798ccb8f17c5749eb5ed7cc7c4bd6be6c3a1e Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 12 Sep 2014 00:02:06 +0200 Subject: [PATCH] Modifying surface extractor test to work with LargeVolume. --- tests/TestSurfaceExtractor.cpp | 37 +++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index 496c39ac..440e8a73 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -24,9 +24,12 @@ freely, subject to the following restrictions: #include "TestSurfaceExtractor.h" #include "PolyVoxCore/Density.h" +#include "PolyVoxCore/FilePager.h" +#include "PolyVoxCore/MinizBlockCompressor.h" #include "PolyVoxCore/MaterialDensityPair.h" #include "PolyVoxCore/RawVolume.h" #include "PolyVoxCore/SimpleVolume.h" +#include "PolyVoxCore/LargeVolume.h" #include "PolyVoxCore/MarchingCubesSurfaceExtractor.h" #include @@ -95,13 +98,16 @@ void writeMaterialValueToVoxel(int valueToWrite, MaterialDensityPair88& voxel) voxel.setMaterial(valueToWrite); } -template -SimpleVolume* createAndFillVolume(void) +template +VolumeType* createAndFillVolume(void) { const int32_t uVolumeSideLength = 64; + MinizBlockCompressor* compressor = new MinizBlockCompressor(); + FilePager* pager = new FilePager("./"); + //Create empty volume - SimpleVolume* volData = new SimpleVolume(Region(Vector3DInt32(0, 0, 0), Vector3DInt32(uVolumeSideLength - 1, uVolumeSideLength - 1, uVolumeSideLength - 1))); + VolumeType* volData = new VolumeType(Region(Vector3DInt32(0, 0, 0), Vector3DInt32(uVolumeSideLength - 1, uVolumeSideLength - 1, uVolumeSideLength - 1)), compressor, pager); // Fill for (int32_t z = 0; z < uVolumeSideLength; z++) @@ -112,9 +118,9 @@ SimpleVolume* createAndFillVolume(void) { // Create a density field which changes throughout the volume. It's // zero in the lower corner and increasing as the coordinates increase. - VoxelType voxelValue; - writeDensityValueToVoxel(x + y + z, voxelValue); - writeMaterialValueToVoxel(z > uVolumeSideLength / 2 ? 42 : 79, voxelValue); + VolumeType::VoxelType voxelValue; + writeDensityValueToVoxel(x + y + z, voxelValue); + writeMaterialValueToVoxel(z > uVolumeSideLength / 2 ? 42 : 79, voxelValue); volData->setVoxelAt(x, y, z, voxelValue); } } @@ -135,8 +141,11 @@ float randomFloat(float a, float b) template VolumeType* createAndFillVolumeWithNoise(int32_t iVolumeSideLength, float minValue, float maxValue) { + MinizBlockCompressor* compressor = new MinizBlockCompressor(); + FilePager* pager = new FilePager("./"); + //Create empty volume - VolumeType* volData = new VolumeType(Region(Vector3DInt32(0, 0, 0), Vector3DInt32(iVolumeSideLength - 1, iVolumeSideLength - 1, iVolumeSideLength - 1))); + VolumeType* volData = new VolumeType(Region(Vector3DInt32(0, 0, 0), Vector3DInt32(iVolumeSideLength - 1, iVolumeSideLength - 1, iVolumeSideLength - 1)), compressor, pager); // Seed generator for consistency between runs. srand(12345); @@ -167,7 +176,7 @@ void TestSurfaceExtractor::testBehaviour() // Of course, the use of a custom controller will also make a significant diference, but this probably does need investigating further in the future. // This basic test just uses the default controller and automatically generates a mesh of the appropriate type. - auto uintVol = createAndFillVolume(); + auto uintVol = createAndFillVolume< LargeVolume >(); auto uintMesh = extractMarchingCubesMesh(uintVol, uintVol->getEnclosingRegion()); QCOMPARE(uintMesh.getNoOfVertices(), uint32_t(12096)); // Verifies size of mesh and that we have 32-bit indices QCOMPARE(uintMesh.getNoOfIndices(), uint32_t(35157)); // Verifies size of mesh @@ -175,7 +184,7 @@ void TestSurfaceExtractor::testBehaviour() QCOMPARE(uintMesh.getVertex(100).data, uint8_t(1)); // Not really meaningful for a primative type // This test makes use of a custom controller - auto floatVol = createAndFillVolume(); + auto floatVol = createAndFillVolume< LargeVolume >(); CustomMarchingCubesController floatCustomController; auto floatMesh = extractMarchingCubesMesh(floatVol, floatVol->getEnclosingRegion(), floatCustomController); QCOMPARE(floatMesh.getNoOfVertices(), uint32_t(16113)); // Verifies size of mesh and that we have 32-bit indices @@ -185,7 +194,7 @@ void TestSurfaceExtractor::testBehaviour() // This test makes use of a user provided mesh. It uses the default controller, but we have to explicitly provide this because C++ won't let us // use a default for the second-to-last parameter but noot use a default for the last parameter. - auto intVol = createAndFillVolume(); + auto intVol = createAndFillVolume< LargeVolume >(); Mesh< MarchingCubesVertex< int8_t >, uint16_t > intMesh; extractMarchingCubesMeshCustom(intVol, intVol->getEnclosingRegion(), &intMesh); QCOMPARE(intMesh.getNoOfVertices(), uint16_t(11718)); // Verifies size of mesh and that we have 16-bit indices @@ -194,7 +203,7 @@ void TestSurfaceExtractor::testBehaviour() QCOMPARE(intMesh.getVertex(100).data, int8_t(1)); // Not really meaningful for a primative type // This test makes use of a user-provided mesh and also a custom controller. - auto doubleVol = createAndFillVolume(); + auto doubleVol = createAndFillVolume< LargeVolume >(); CustomMarchingCubesController doubleCustomController; Mesh< MarchingCubesVertex< double >, uint16_t > doubleMesh; extractMarchingCubesMeshCustom(doubleVol, doubleVol->getEnclosingRegion(), &doubleMesh, doubleCustomController); @@ -204,7 +213,7 @@ void TestSurfaceExtractor::testBehaviour() QCOMPARE(doubleMesh.getVertex(100).data, double(1.0f)); // Not really meaningful for a primative type // This test ensures the extractor works on a non-primitive voxel type. - auto materialVol = createAndFillVolume(); + auto materialVol = createAndFillVolume< LargeVolume >(); auto materialMesh = extractMarchingCubesMesh(materialVol, materialVol->getEnclosingRegion()); QCOMPARE(materialMesh.getNoOfVertices(), uint32_t(12096)); // Verifies size of mesh and that we have 32-bit indices QCOMPARE(materialMesh.getNoOfIndices(), uint32_t(35157)); // Verifies size of mesh @@ -214,7 +223,7 @@ void TestSurfaceExtractor::testBehaviour() void TestSurfaceExtractor::testEmptyVolumePerformance() { - auto emptyVol = createAndFillVolumeWithNoise< SimpleVolume >(128, -2.0f, -1.0f); + auto emptyVol = createAndFillVolumeWithNoise< LargeVolume >(128, -2.0f, -1.0f); Mesh< MarchingCubesVertex< float >, uint16_t > emptyMesh; QBENCHMARK{ extractMarchingCubesMeshCustom(emptyVol, Region(32, 32, 32, 63, 63, 63), &emptyMesh); } QCOMPARE(emptyMesh.getNoOfVertices(), uint16_t(0)); @@ -222,7 +231,7 @@ void TestSurfaceExtractor::testEmptyVolumePerformance() void TestSurfaceExtractor::testNoiseVolumePerformance() { - auto noiseVol = createAndFillVolumeWithNoise< SimpleVolume >(128, -1.0f, 1.0f); + auto noiseVol = createAndFillVolumeWithNoise< LargeVolume >(128, -1.0f, 1.0f); Mesh< MarchingCubesVertex< float >, uint16_t > noiseMesh; QBENCHMARK{ extractMarchingCubesMeshCustom(noiseVol, Region(32, 32, 32, 63, 63, 63), &noiseMesh); } QCOMPARE(noiseMesh.getNoOfVertices(), uint16_t(48967));