From 52a104470369bf73e142bbad9fb6766f59a0c140 Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 28 Sep 2007 10:59:26 +0000 Subject: [PATCH] Cleaning up decimation. --- include/SurfacePatch.h | 9 ++-- source/PolyVoxSceneManager.cpp | 6 +-- source/SurfacePatch.cpp | 98 ++++++---------------------------- 3 files changed, 23 insertions(+), 90 deletions(-) diff --git a/include/SurfacePatch.h b/include/SurfacePatch.h index 40dcd795..1fddafbe 100644 --- a/include/SurfacePatch.h +++ b/include/SurfacePatch.h @@ -42,8 +42,6 @@ namespace Ogre void getVertexAndIndexData(std::vector& vertexData, std::vector& indexData); - void computeNormalsFromVolume(VolumeIterator volIter); - bool canRemoveVertexFrom(SurfaceVertexIterator vertexIter, std::list listConnectedIter, bool isEdge); std::list findConnectedVertices(SurfaceVertexIterator vertexIter, bool& isEdge); @@ -51,10 +49,13 @@ namespace Ogre void triangulate(std::list listVertices); bool isPolygonConvex(std::list listVertices, Vector3 normal); + SurfaceVertexIterator getVerticesBegin(void); + SurfaceVertexIterator getVerticesEnd(void); - UIntVector3 m_v3dOffset; + uint getNoOfTriangles(void); - public: + + private: std::set m_listVertices; std::set m_listTriangles; std::set m_listEdges; diff --git a/source/PolyVoxSceneManager.cpp b/source/PolyVoxSceneManager.cpp index 8af01ea4..e8a70bcb 100644 --- a/source/PolyVoxSceneManager.cpp +++ b/source/PolyVoxSceneManager.cpp @@ -359,7 +359,7 @@ namespace Ogre std::vector vertexData; std::vector indexData; iterSurfacePatch->second.getVertexAndIndexData(vertexData, indexData); - triangleCounter += iterSurfacePatch->second.m_listTriangles.size(); + triangleCounter += iterSurfacePatch->second.getNoOfTriangles(); std::map::iterator iterSurface = m_mapSurfaces[regionX][regionY][regionZ].find(iterSurfacePatch->first); if(iterSurface == m_mapSurfaces[regionX][regionY][regionZ].end()) @@ -781,8 +781,8 @@ namespace Ogre for(std::map::iterator iterPatch = result.begin(); iterPatch != result.end(); ++iterPatch) { - SurfaceVertexIterator iterSurfaceVertex = iterPatch->second.m_listVertices.begin(); - while(iterSurfaceVertex != iterPatch->second.m_listVertices.end()) + SurfaceVertexIterator iterSurfaceVertex = iterPatch->second.getVerticesBegin(); + while(iterSurfaceVertex != iterPatch->second.getVerticesEnd()) { Vector3 tempNormal = computeNormal((iterSurfaceVertex->getPosition() + offset).toOgreVector3()/2.0f, CENTRAL_DIFFERENCE); iterSurfaceVertex->setNormal(tempNormal); diff --git a/source/SurfacePatch.cpp b/source/SurfacePatch.cpp index c7a36db9..0b51f385 100644 --- a/source/SurfacePatch.cpp +++ b/source/SurfacePatch.cpp @@ -156,89 +156,6 @@ namespace Ogre return edgeIter; } - void SurfacePatch::computeNormalsFromVolume(VolumeIterator volIter) - { - //LogManager::getSingleton().logMessage("In SurfacePatch::computeNormalsFromVolume"); - for(SurfaceVertexIterator vertexIter = m_listVertices.begin(); vertexIter != m_listVertices.end(); ++vertexIter) - { - //LogManager::getSingleton().logMessage("In Loop"); - const float posX = (vertexIter->getPosition().x + m_v3dOffset.x) / 2.0f; - const float posY = (vertexIter->getPosition().y + m_v3dOffset.y) / 2.0f; - const float posZ = (vertexIter->getPosition().z + m_v3dOffset.z) / 2.0f; - - const uint floorX = static_cast(posX); - const uint floorY = static_cast(posY); - const uint floorZ = static_cast(posZ); - - NormalGenerationMethod normalGenerationMethod = CENTRAL_DIFFERENCE; - - switch(normalGenerationMethod) - { - case SIMPLE: - { - volIter.setPosition(static_cast(posX),static_cast(posY),static_cast(posZ)); - const uchar uFloor = volIter.getVoxel() > 0 ? 1 : 0; - if((posX - floorX) > 0.25) //The result should be 0.0 or 0.5 - { - uchar uCeil = volIter.peekVoxel1px0py0pz() > 0 ? 1 : 0; - vertexIter->setNormal(Vector3(uFloor - uCeil,0.0,0.0)); - } - else if((posY - floorY) > 0.25) //The result should be 0.0 or 0.5 - { - uchar uCeil = volIter.peekVoxel0px1py0pz() > 0 ? 1 : 0; - vertexIter->setNormal(Vector3(0.0,uFloor - uCeil,0.0)); - } - else if((posZ - floorZ) > 0.25) //The result should be 0.0 or 0.5 - { - uchar uCeil = volIter.peekVoxel0px0py1pz() > 0 ? 1 : 0; - vertexIter->setNormal(Vector3(0.0, 0.0,uFloor - uCeil)); - } - break; - } - case CENTRAL_DIFFERENCE: - { - volIter.setPosition(static_cast(posX),static_cast(posY),static_cast(posZ)); - const Vector3 gradFloor = volIter.getCentralDifferenceGradient(); - if((posX - floorX) > 0.25) //The result should be 0.0 or 0.5 - { - volIter.setPosition(static_cast(posX+1.0),static_cast(posY),static_cast(posZ)); - } - if((posY - floorY) > 0.25) //The result should be 0.0 or 0.5 - { - volIter.setPosition(static_cast(posX),static_cast(posY+1.0),static_cast(posZ)); - } - if((posZ - floorZ) > 0.25) //The result should be 0.0 or 0.5 - { - volIter.setPosition(static_cast(posX),static_cast(posY),static_cast(posZ+1.0)); - } - const Vector3 gradCeil = volIter.getCentralDifferenceGradient(); - vertexIter->setNormal((gradFloor + gradCeil) * -1.0); - break; - } - case SOBEL: - { - volIter.setPosition(static_cast(posX),static_cast(posY),static_cast(posZ)); - const Vector3 gradFloor = volIter.getSobelGradient(); - if((posX - floorX) > 0.25) //The result should be 0.0 or 0.5 - { - volIter.setPosition(static_cast(posX+1.0),static_cast(posY),static_cast(posZ)); - } - if((posY - floorY) > 0.25) //The result should be 0.0 or 0.5 - { - volIter.setPosition(static_cast(posX),static_cast(posY+1.0),static_cast(posZ)); - } - if((posZ - floorZ) > 0.25) //The result should be 0.0 or 0.5 - { - volIter.setPosition(static_cast(posX),static_cast(posY),static_cast(posZ+1.0)); - } - const Vector3 gradCeil = volIter.getSobelGradient(); - vertexIter->setNormal((gradFloor + gradCeil) * -1.0); - break; - } - } - } - } - void SurfacePatch::getVertexAndIndexData(std::vector& vertexData, std::vector& indexData) { vertexData.clear(); @@ -539,4 +456,19 @@ namespace Ogre return true; } + + SurfaceVertexIterator SurfacePatch::getVerticesBegin(void) + { + return m_listVertices.begin(); + } + + SurfaceVertexIterator SurfacePatch::getVerticesEnd(void) + { + return m_listVertices.end(); + } + + uint SurfacePatch::getNoOfTriangles(void) + { + return m_listTriangles.size(); + } }