From be47aec7f76e6a0446ce358faa7d066ba9f05ca6 Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 18 Aug 2014 15:47:00 +0200 Subject: [PATCH] Work on cubic extractor tests. --- .../PolyVoxCore/CubicSurfaceExtractor.h | 4 ++-- tests/TestCubicSurfaceExtractor.cpp | 22 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h index 586f85d3..45035247 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h @@ -189,7 +189,7 @@ namespace PolyVox }; template > - void extractCubicProvidedMesh(VolumeType* volData, Region region, MeshType* result, IsQuadNeeded isQuadNeeded = IsQuadNeeded(), WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true) + void extractCubicMeshCustom(VolumeType* volData, Region region, MeshType* result, IsQuadNeeded isQuadNeeded = IsQuadNeeded(), WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true) { CubicSurfaceExtractor extractor(volData, region, result, isQuadNeeded, eWrapMode, tBorderValue, bMergeQuads); extractor.execute(); @@ -199,7 +199,7 @@ namespace PolyVox Mesh > extractCubicMesh(VolumeType* volData, Region region, IsQuadNeeded isQuadNeeded = IsQuadNeeded(), WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true) { Mesh< CubicVertex > result; - extractCubicProvidedMesh(volData, region, &result, isQuadNeeded, eWrapMode, tBorderValue, bMergeQuads); + extractCubicMeshCustom(volData, region, &result, isQuadNeeded, eWrapMode, tBorderValue, bMergeQuads); return result; } } diff --git a/tests/TestCubicSurfaceExtractor.cpp b/tests/TestCubicSurfaceExtractor.cpp index 9f8027bf..cbff3e62 100644 --- a/tests/TestCubicSurfaceExtractor.cpp +++ b/tests/TestCubicSurfaceExtractor.cpp @@ -41,7 +41,9 @@ public: bool operator()(VoxelType back, VoxelType front, VoxelType& materialToUse) { - if ((back > 0) && (front == 0)) + // Not a useful test - it just does something different + // to the DefaultIsQuadNeeded so we can check it compiles. + if ((back > 1) && (front <= 1)) { materialToUse = static_cast(back); return true; @@ -241,27 +243,31 @@ void TestCubicSurfaceExtractor::testExecute() } QCOMPARE(result, uExpectedSumOfVerticesAndIndices); + // Test with default mesh and contoller types. auto uint8Vol = createAndFillVolumeWithNoise(0, 2); auto uint8Mesh = extractCubicMesh(uint8Vol, uint8Vol->getEnclosingRegion()); QCOMPARE(uint8Mesh.getNoOfVertices(), uint32_t(57687)); QCOMPARE(uint8Mesh.getNoOfIndices(), uint32_t(216234)); + // Test with default mesh type but user-provided controller. auto int8Vol = createAndFillVolumeWithNoise(0, 2); - auto int8Mesh = extractCubicMesh(int8Vol, int8Vol->getEnclosingRegion(), DefaultIsQuadNeeded()); - QCOMPARE(int8Mesh.getNoOfVertices(), uint32_t(57687)); - QCOMPARE(int8Mesh.getNoOfIndices(), uint32_t(216234)); + auto int8Mesh = extractCubicMesh(int8Vol, int8Vol->getEnclosingRegion(), CustomIsQuadNeeded()); + QCOMPARE(int8Mesh.getNoOfVertices(), uint32_t(29027)); + QCOMPARE(int8Mesh.getNoOfIndices(), uint32_t(178356)); + // Test with default controller but user-provided mesh. auto uint32Vol = createAndFillVolumeWithNoise(0, 2); Mesh< CubicVertex< uint32_t >, uint16_t > uint32Mesh; - extractCubicProvidedMesh(uint32Vol, uint32Vol->getEnclosingRegion(), &uint32Mesh); + extractCubicMeshCustom(uint32Vol, uint32Vol->getEnclosingRegion(), &uint32Mesh); QCOMPARE(uint32Mesh.getNoOfVertices(), uint16_t(57687)); QCOMPARE(uint32Mesh.getNoOfIndices(), uint32_t(216234)); + // Test with both mesh and controller being provided by the user. auto int32Vol = createAndFillVolumeWithNoise(0, 2); Mesh< CubicVertex< int32_t >, uint16_t > int32Mesh; - extractCubicProvidedMesh(int32Vol, int32Vol->getEnclosingRegion(), &int32Mesh, DefaultIsQuadNeeded()); - QCOMPARE(int32Mesh.getNoOfVertices(), uint16_t(57687)); - QCOMPARE(int32Mesh.getNoOfIndices(), uint32_t(216234)); + extractCubicMeshCustom(int32Vol, int32Vol->getEnclosingRegion(), &int32Mesh, CustomIsQuadNeeded()); + QCOMPARE(int32Mesh.getNoOfVertices(), uint16_t(29027)); + QCOMPARE(int32Mesh.getNoOfIndices(), uint32_t(178356)); }