From 5974a1de9bd5093d0091b9e3cc87ecb2e43165ba Mon Sep 17 00:00:00 2001 From: David Williams Date: Thu, 14 May 2015 10:52:07 +0200 Subject: [PATCH] Restructuring loops... --- .../PolyVox/MarchingCubesSurfaceExtractor.h | 2 +- .../PolyVox/MarchingCubesSurfaceExtractor.inl | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/PolyVox/MarchingCubesSurfaceExtractor.h b/include/PolyVox/MarchingCubesSurfaceExtractor.h index 2a0c800e..926e47df 100644 --- a/include/PolyVox/MarchingCubesSurfaceExtractor.h +++ b/include/PolyVox/MarchingCubesSurfaceExtractor.h @@ -160,7 +160,7 @@ namespace PolyVox private: //Compute the cell bitmask for a particular slice in z. template - void computeBitmaskForSlice(Array3DUint8& pBitmask); + void computeBitmaskForSlice(Array3DUint8& pBitmask, uint32_t uSlice); //Use the cell bitmasks to generate all the vertices needed for that slice void generateVerticesForSlice(const Array3DUint8& pBitmask, diff --git a/include/PolyVox/MarchingCubesSurfaceExtractor.inl b/include/PolyVox/MarchingCubesSurfaceExtractor.inl index ac5e31f2..5e193744 100644 --- a/include/PolyVox/MarchingCubesSurfaceExtractor.inl +++ b/include/PolyVox/MarchingCubesSurfaceExtractor.inl @@ -69,7 +69,11 @@ namespace PolyVox m_regSliceCurrent = m_regSlicePrevious; //Process the first slice (previous slice not available) - computeBitmaskForSlice(pBitmask); + computeBitmaskForSlice(pBitmask, 0); + for (int32_t uSlice = 1; uSlice <= m_regSizeInVoxels.getUpperZ() - m_regSizeInVoxels.getLowerZ(); uSlice++) + { + computeBitmaskForSlice(pBitmask, uSlice); + } generateVerticesForSlice(pBitmask, pIndicesX, pIndicesY, pIndicesZ); @@ -78,9 +82,7 @@ namespace PolyVox //Process the other slices (previous slice is available) for(int32_t uSlice = 1; uSlice <= m_regSizeInVoxels.getUpperZ() - m_regSizeInVoxels.getLowerZ(); uSlice++) - { - computeBitmaskForSlice(pBitmask); - + { generateVerticesForSlice(pBitmask, pIndicesX, pIndicesY, pIndicesZ); generateIndicesForSlice(pBitmask, pIndicesX, pIndicesY, pIndicesZ); @@ -98,19 +100,19 @@ namespace PolyVox template template - void MarchingCubesSurfaceExtractor::computeBitmaskForSlice(Array3DUint8& pBitmask) + void MarchingCubesSurfaceExtractor::computeBitmaskForSlice(Array3DUint8& pBitmask, uint32_t uSlice) { - const int32_t iMaxXVolSpace = m_regSliceCurrent.getUpperX(); - const int32_t iMaxYVolSpace = m_regSliceCurrent.getUpperY(); + const int32_t iMaxXVolSpace = m_regSizeInVoxels.getUpperX(); + const int32_t iMaxYVolSpace = m_regSizeInVoxels.getUpperY(); //Process the lower left corner - int32_t iYVolSpace = m_regSliceCurrent.getLowerY(); - int32_t iXVolSpace = m_regSliceCurrent.getLowerX(); - int32_t iZVolSpace = m_regSliceCurrent.getLowerZ(); + int32_t iYVolSpace = m_regSizeInVoxels.getLowerY(); + int32_t iXVolSpace = m_regSizeInVoxels.getLowerX(); + int32_t iZVolSpace = m_regSizeInVoxels.getLowerZ() + uSlice; uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX(); uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY(); - uint32_t uZRegSpace = iZVolSpace - m_regSizeInVoxels.getLowerZ(); + uint32_t uZRegSpace = uSlice; //Process all remaining elemnents of the slice. In this case, previous x and y values are always available for(iYVolSpace = m_regSliceCurrent.getLowerY(); iYVolSpace <= iMaxYVolSpace; iYVolSpace++)