From ccc9a3c158ab45f9c70942db7a057e71dab84935 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 12 Aug 2014 15:53:30 +0200 Subject: [PATCH] More work on surface extraction tests. --- .../MarchingCubesSurfaceExtractor.h | 10 ++++----- .../PolyVoxCore/include/PolyVoxCore/Mesh.h | 4 ++-- tests/TestSurfaceExtractor.cpp | 21 ++++++++++--------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h index 3ecf78fb..3c370d5a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h @@ -90,8 +90,8 @@ namespace PolyVox // floats into two bytes and store them in a single uint16_t // Move from range [-1.0f, 1.0f] to [0.0f, 255.0f] - px = (px + 1.0) * 127.5f; - py = (py + 1.0) * 127.5f; + px = (px + 1.0f) * 127.5f; + py = (py + 1.0f) * 127.5f; // Convert to uints uint16_t resultX = static_cast(px + 0.5f); @@ -300,7 +300,7 @@ namespace PolyVox uint32_t m_uNoOfOccupiedCells; //The surface patch we are currently filling. - Mesh >* m_meshCurrent; + MeshType* m_meshCurrent; //Information about the region we are currently processing Region m_regSizeInVoxels; @@ -327,10 +327,10 @@ namespace PolyVox extractor.execute(); } - template< typename VolumeType, typename Controller = DefaultMarchingCubesController, typename IndexType = DefaultIndexType > + template< typename VolumeType, typename Controller = DefaultMarchingCubesController > Mesh > extractMarchingCubesMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), Controller controller = Controller()) { - Mesh, IndexType > result; + Mesh, DefaultIndexType > result; extractMarchingCubesMesh(volData, region, eWrapMode, tBorderValue, controller, &result); return result; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Mesh.h b/library/PolyVoxCore/include/PolyVoxCore/Mesh.h index 2143133f..802b0656 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Mesh.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Mesh.h @@ -81,13 +81,13 @@ namespace PolyVox { Mesh< Vertex< typename MeshType::VertexType::DataType >, typename MeshType::IndexType > decodedMesh; - for (auto ct = 0; ct < encodedMesh.getNoOfVertices(); ct++) + for (MeshType::IndexType ct = 0; ct < encodedMesh.getNoOfVertices(); ct++) { decodedMesh.addVertex(decodeVertex(encodedMesh.getVertex(ct))); } POLYVOX_ASSERT(encodedMesh.getNoOfIndices() % 3 == 0, "The number of indices must always be a multiple of three."); - for (auto ct = 0; ct < encodedMesh.getNoOfIndices(); ct += 3) + for (uint32_t ct = 0; ct < encodedMesh.getNoOfIndices(); ct += 3) { decodedMesh.addTriangle(encodedMesh.getIndex(ct), encodedMesh.getIndex(ct + 1), encodedMesh.getIndex(ct + 2)); } diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index d15e8fed..0c494d93 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -251,22 +251,23 @@ void TestSurfaceExtractor::testExecute() auto uintVol = createAndFillVolume(); auto uintMesh = extractMarchingCubesMesh(uintVol, uintVol->getEnclosingRegion()); - QCOMPARE(uintMesh.getNoOfVertices(), 12096u); // Verifies size of mesh - QCOMPARE(uintMesh.getNoOfIndices(), 35157u); // Verifies size of mesh - QCOMPARE(uintMesh.getIndex(100), uint32_t(44)); // Verifies that we have 32-bit index buffer + 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 + QCOMPARE(uintMesh.getIndex(100), uint32_t(44)); // Verifies that we have 32-bit indices auto floatVol = createAndFillVolume(); CustomMarchingCubesController floatCustomController; auto floatMesh = extractMarchingCubesMesh(floatVol, floatVol->getEnclosingRegion(), WrapModes::Border, float(0), floatCustomController); - QCOMPARE(floatMesh.getNoOfVertices(), 16113u); // Verifies size of mesh - QCOMPARE(floatMesh.getNoOfIndices(), 22053u); // Verifies size of mesh - QCOMPARE(floatMesh.getIndex(100), uint32_t(26)); // Verifies that we have 32-bit index buffer + QCOMPARE(floatMesh.getNoOfVertices(), uint32_t(16113)); // Verifies size of mesh and that we have 32-bit indices + QCOMPARE(floatMesh.getNoOfIndices(), uint32_t(22053)); // Verifies size of mesh + QCOMPARE(floatMesh.getIndex(100), uint32_t(26)); // Verifies that we have 32-bit indices auto intVol = createAndFillVolume(); - auto intMesh = extractMarchingCubesMesh(intVol, intVol->getEnclosingRegion(), WrapModes::Border, int8_t(0), DefaultMarchingCubesController()); - QCOMPARE(intMesh.getNoOfVertices(), 11718u); // Verifies size of mesh - QCOMPARE(intMesh.getNoOfIndices(), 34041u); // Verifies size of mesh - QCOMPARE(intMesh.getIndex(100), uint32_t(29)); // Verifies that we have 32-bit index buffer + Mesh< MarchingCubesVertex< int8_t >, uint16_t > intMesh; + extractMarchingCubesMesh(intVol, intVol->getEnclosingRegion(), WrapModes::Border, int8_t(0), DefaultMarchingCubesController(), &intMesh); + QCOMPARE(intMesh.getNoOfVertices(), uint16_t(11718)); // Verifies size of mesh and that we have 16-bit indices + QCOMPARE(intMesh.getNoOfIndices(), uint32_t(34041)); // Verifies size of mesh + QCOMPARE(intMesh.getIndex(100), uint16_t(29)); // Verifies that we have 16-bit indices } QTEST_MAIN(TestSurfaceExtractor)