diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index 72294e2c..d3f7f7a8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -79,11 +79,11 @@ namespace PolyVox { uint32_t regY = y - m_regSizeInVoxels.getLowerCorner().getY(); + volumeSampler.setPosition(m_regSizeInVoxels.getLowerCorner().getX(),y,z); + for(int32_t x = m_regSizeInVoxels.getLowerCorner().getX(); x <= m_regSizeInVoxels.getUpperCorner().getX(); x++) { - uint32_t regX = x - m_regSizeInVoxels.getLowerCorner().getX(); - - volumeSampler.setPosition(x,y,z); + uint32_t regX = x - m_regSizeInVoxels.getLowerCorner().getX(); uint32_t material; //Filled in by callback typename VolumeType::VoxelType currentVoxel = volumeSampler.getVoxel(); @@ -153,6 +153,8 @@ namespace PolyVox m_vecQuads[PositiveZ][regZ].push_back(Quad(v0, v3, v2, v1)); } + + volumeSampler.movePositiveX(); } } diff --git a/tests/TestCubicSurfaceExtractor.cpp b/tests/TestCubicSurfaceExtractor.cpp index d03b74c4..45919e85 100644 --- a/tests/TestCubicSurfaceExtractor.cpp +++ b/tests/TestCubicSurfaceExtractor.cpp @@ -27,7 +27,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Material.h" #include "PolyVoxCore/MaterialDensityPair.h" #include "PolyVoxCore/SimpleVolume.h" -#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h" +#include "PolyVoxCore/CubicSurfaceExtractor.h" #include @@ -70,13 +70,14 @@ void writeMaterialValueToVoxel(int valueToWrite, MaterialDensityPair88& voxel) // Runs the surface extractor for a given type. template -void testForType(SurfaceMesh& result) +uint32_t testForType(void) { - const int32_t uVolumeSideLength = 32; + const int32_t uVolumeSideLength = 256; //Create empty volume - SimpleVolume volData(Region(Vector3DInt32(0,0,0), Vector3DInt32(uVolumeSideLength-1, uVolumeSideLength-1, uVolumeSideLength-1))); + SimpleVolume volData(Region(Vector3DInt32(0,0,0), Vector3DInt32(uVolumeSideLength-1, uVolumeSideLength-1, uVolumeSideLength-1)), 128); + //Fill the volume with data for (int32_t z = 0; z < uVolumeSideLength; z++) { for (int32_t y = 0; y < uVolumeSideLength; y++) @@ -94,20 +95,43 @@ void testForType(SurfaceMesh& result) } } - CubicSurfaceExtractorWithNormals< SimpleVolume > extractor(&volData, volData.getEnclosingRegion(), &result); - extractor.execute(); + uint32_t uTotalVertices = 0; + uint32_t uTotalIndices = 0; + + //Run the surface extractor a number of times over differnt regions of the volume. + const int32_t uRegionSideLength = 64; + for (int32_t z = 0; z < uVolumeSideLength; z += uRegionSideLength) + { + for (int32_t y = 0; y < uVolumeSideLength; y += uRegionSideLength) + { + for (int32_t x = 0; x < uVolumeSideLength; x += uRegionSideLength) + { + SurfaceMesh result; + Region regionToExtract(x, y, z, x + uRegionSideLength - 1, y + uRegionSideLength - 1, z + uRegionSideLength - 1); + CubicSurfaceExtractor< SimpleVolume > extractor(&volData, regionToExtract, &result); + extractor.execute(); + + uTotalVertices += result.getNoOfVertices(); + uTotalIndices += result.getNoOfIndices(); + } + } + } + + // Just some value which is representative of the work we've done. It doesn't + // matter what it is, just that it should be the same every time we run the test. + return uTotalVertices + uTotalIndices; } void TestCubicSurfaceExtractor::testExecute() { - const static uint32_t uExpectedVertices = 6624; + /*const static uint32_t uExpectedVertices = 6624; const static uint32_t uExpectedIndices = 9936; const static uint32_t uMaterialToCheck = 3000; const static float fExpectedMaterial = 42.0f; const static uint32_t uIndexToCheck = 2000; const static uint32_t uExpectedIndex = 1334; - SurfaceMesh mesh; + SurfaceMesh mesh;*/ /*testForType(mesh); QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices); @@ -154,13 +178,13 @@ void TestCubicSurfaceExtractor::testExecute() QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices); QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);*/ + const static uint32_t uExpectedSumOfVerticesAndIndices = 704668; + //const static uint32_t uExpectedSumOfVerticesAndIndices = 2792332; + uint32_t result = 0; QBENCHMARK { - testForType(mesh); + result = testForType(); } - QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices); - QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices); - QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fExpectedMaterial); - QCOMPARE(mesh.getIndices()[uIndexToCheck], uExpectedIndex); + QCOMPARE(result, uExpectedSumOfVerticesAndIndices); } QTEST_MAIN(TestCubicSurfaceExtractor)