From 96171978932302ed999f6a14212ed7f6757d2066 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 8 Dec 2015 23:29:38 +0000 Subject: [PATCH] Refactoring CubicSurfaceExtractor to free functions rather than just wrapping a class. --- include/PolyVox/CubicSurfaceExtractor.h | 31 +++++++++++++++++++++- include/PolyVox/CubicSurfaceExtractor.inl | 32 +---------------------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/include/PolyVox/CubicSurfaceExtractor.h b/include/PolyVox/CubicSurfaceExtractor.h index f8a640ca..993857b7 100644 --- a/include/PolyVox/CubicSurfaceExtractor.h +++ b/include/PolyVox/CubicSurfaceExtractor.h @@ -125,6 +125,36 @@ namespace PolyVox //Quads cannot be merged. return false; } + + template + bool performQuadMerging(std::list& quads, MeshType* m_meshCurrent) + { + bool bDidMerge = false; + for (typename std::list::iterator outerIter = quads.begin(); outerIter != quads.end(); outerIter++) + { + typename std::list::iterator innerIter = outerIter; + innerIter++; + while (innerIter != quads.end()) + { + Quad& q1 = *outerIter; + Quad& q2 = *innerIter; + + bool result = mergeQuads(q1, q2, m_meshCurrent); + + if (result) + { + bDidMerge = true; + innerIter = quads.erase(innerIter); + } + else + { + innerIter++; + } + } + } + + return bDidMerge; + } /// Do not use this class directly. Use the 'extractCubicSurface' function instead (see examples). template @@ -154,7 +184,6 @@ namespace PolyVox private: int32_t addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, typename VolumeType::VoxelType uMaterial, Array<3, IndexAndMaterial>& existingVertices); - bool performQuadMerging(std::list& quads); IsQuadNeeded m_funcIsQuadNeededCallback; diff --git a/include/PolyVox/CubicSurfaceExtractor.inl b/include/PolyVox/CubicSurfaceExtractor.inl index 7160da75..2a7d6b71 100644 --- a/include/PolyVox/CubicSurfaceExtractor.inl +++ b/include/PolyVox/CubicSurfaceExtractor.inl @@ -182,7 +182,7 @@ namespace PolyVox { //Repeatedly call this function until it returns //false to indicate nothing more can be done. - while(performQuadMerging(listQuads)){} + while (performQuadMerging(listQuads, m_meshCurrent)){} } typename std::list::iterator iterEnd = listQuads.end(); @@ -234,34 +234,4 @@ namespace PolyVox POLYVOX_THROW(std::runtime_error, "All slots full but no matches during cubic surface extraction. This is probably a bug in PolyVox"); return -1; //Should never happen. } - - template - bool CubicSurfaceExtractor::performQuadMerging(std::list& quads) - { - bool bDidMerge = false; - for(typename std::list::iterator outerIter = quads.begin(); outerIter != quads.end(); outerIter++) - { - typename std::list::iterator innerIter = outerIter; - innerIter++; - while(innerIter != quads.end()) - { - Quad& q1 = *outerIter; - Quad& q2 = *innerIter; - - bool result = mergeQuads(q1, q2, m_meshCurrent); - - if(result) - { - bDidMerge = true; - innerIter = quads.erase(innerIter); - } - else - { - innerIter++; - } - } - } - - return bDidMerge; - } }