diff --git a/examples/OpenGL/OpenGLWidget.cpp b/examples/OpenGL/OpenGLWidget.cpp index e266666b..0a7a248e 100644 --- a/examples/OpenGL/OpenGLWidget.cpp +++ b/examples/OpenGL/OpenGLWidget.cpp @@ -30,8 +30,6 @@ freely, subject to the following restrictions: #include "MeshDecimator.h" #include "SurfaceExtractor.h" -#include "Mesh.h" - //Some namespaces we need using namespace std; using namespace PolyVox; @@ -98,47 +96,15 @@ void OpenGLWidget::setVolume(PolyVox::Volume* volData) MeshDecimator decimator(mesh.get(), decimatedMesh.get(), 0.95f); decimator.execute(); - //computeNormalsForVertices(m_volData, *(mesh.get()), SOBEL_SMOOTHED); + decimatedMesh->generateAveragedFaceNormals(true); + + //computeNormalsForVertices(m_volData, *(decimatedMesh.get()), SOBEL_SMOOTHED); //*meshCurrent = getSmoothedSurface(*meshCurrent); //mesh->smooth(0.3f); //meshCurrent->generateAveragedFaceNormals(true); if(mesh->m_vecTriangleIndices.size() > 0) { - //mesh->makeProgressiveMesh(); - - /*RenderDynamicMesh rdm; - rdm.buildFromSurfaceMesh(*mesh);*/ - - //computeNormalsForVertices(m_volData, *(mesh.get()), SOBEL_SMOOTHED); - - //mesh->smoothPositions(0.3f); - //mesh->generateAveragedFaceNormals(true); - - /*for(int ct = 0; ct < 20; ct ++) - { - //cout << "Before: " << mesh->noOfDegenerateTris() << endl; - mesh->decimate(); - //cout << "After: " << mesh->noOfDegenerateTris() << endl; - mesh->removeDegenerateTris(); - //cout << "After Remove: " << mesh->noOfDegenerateTris() << endl << endl; - }*/ - - //////////////////////////////////////////////////////////////////////////////// - //For decimation built into Mesh - //mesh->generateAveragedFaceNormals(true); - - //mesh->decimate(0.999f); - - //mesh->generateAveragedFaceNormals(true); - //////////////////////////////////////////////////////////////////////////////// - - /*mesh->generateAveragedFaceNormals(true); - Mesh mesh; - mesh.buildFromMesh(mesh.get()); - //mesh.removeEdge(*(mesh.m_edges.begin())); - mesh.decimateAll(); - mesh.fillMesh(mesh.get());*/ Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ); diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index f483964c..de9c4fbe 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -8,10 +8,6 @@ SET(CORE_SRC_FILES source/AStarPathfinder.cpp source/GradientEstimators.cpp source/Log.cpp - source/Mesh.cpp - source/MeshEdge.cpp - source/MeshFace.cpp - source/MeshVertex.cpp source/Region.cpp source/VertexTypes.cpp source/VoxelFilters.cpp @@ -35,12 +31,8 @@ SET(CORE_INC_FILES include/Log.h include/Material.h include/MaterialDensityPair.h - include/Mesh.h include/MeshDecimator.h include/MeshDecimator.inl - include/MeshEdge.h - include/MeshFace.h - include/MeshVertex.h include/PolyVoxForwardDeclarations.h include/Region.h include/SurfaceExtractor.h diff --git a/library/PolyVoxCore/include/Mesh.h b/library/PolyVoxCore/include/Mesh.h deleted file mode 100644 index 688da8ae..00000000 --- a/library/PolyVoxCore/include/Mesh.h +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* -Copyright (c) 2005-2009 David Williams - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*******************************************************************************/ - -#ifndef __PolyVox_Mesh_H__ -#define __PolyVox_Mesh_H__ - -#include "MeshEdge.h" -#include "MeshFace.h" -#include "MeshVertex.h" - -#include "PolyVoxImpl/TypeDef.h" - -#include - -namespace PolyVox -{ - class POLYVOXCORE_API Mesh - { - public: - - void buildFromMesh(SurfaceMesh* pMesh); - void fillMesh(SurfaceMesh* pMesh); - void matchEdgePairs(void); - void computeEdgeCosts(void); - - void removeEdge(MeshEdge* pMeshEdge); - - void decimateAll(void); - bool decimateOne(void); - - bool isSane(void); - - std::set m_edges; - std::set m_faces; - std::set m_vertices; - }; -} - -#endif \ No newline at end of file diff --git a/library/PolyVoxCore/include/MeshEdge.h b/library/PolyVoxCore/include/MeshEdge.h deleted file mode 100644 index f4619cf8..00000000 --- a/library/PolyVoxCore/include/MeshEdge.h +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* -Copyright (c) 2005-2009 David Williams - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*******************************************************************************/ - -#ifndef __PolyVox_MeshEdge_H__ -#define __PolyVox_MeshEdge_H__ - -#include "PolyVoxForwardDeclarations.h" - -#include "PolyVoxImpl/TypeDef.h" - -namespace PolyVox -{ - class POLYVOXCORE_API MeshEdge - { - public: - MeshEdge(); - - bool isSane(void); - - void computeEdgeCost(Mesh* pParentMesh); - - MeshEdge* m_pOtherEdge; - MeshEdge* m_pNextEdge; - MeshEdge* m_pPreviousEdge; - - MeshVertex* m_pSrc; - MeshVertex* m_pDest; - - MeshFace* m_pFace; - - float m_fCost; - }; - - //FIXME - Rather than being global, these should just be used to sort within the set. - bool operator==(const MeshEdge& lhs, const MeshEdge& rhs); - bool operator<(const MeshEdge& lhs, const MeshEdge& rhs); -} - -#endif \ No newline at end of file diff --git a/library/PolyVoxCore/include/MeshFace.h b/library/PolyVoxCore/include/MeshFace.h deleted file mode 100644 index 207383da..00000000 --- a/library/PolyVoxCore/include/MeshFace.h +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* -Copyright (c) 2005-2009 David Williams - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*******************************************************************************/ - -#ifndef __PolyVox_MeshFace_H__ -#define __PolyVox_MeshFace_H__ - -#include "MeshEdge.h" - -#include "PolyVoxImpl/TypeDef.h" - -namespace PolyVox -{ - class POLYVOXCORE_API MeshFace - { - public: - MeshFace(); - bool isSane(void); - - MeshEdge* m_pEdge; - - Vector3DFloat getNormal(void); - bool collapseFlipsFace(MeshEdge* pEdgeToCollapse); - bool collapseFlipsFaceImpl(Vector3DFloat fixed0, Vector3DFloat fixed1, Vector3DFloat oldPos, Vector3DFloat newPos); - }; -} - -#endif \ No newline at end of file diff --git a/library/PolyVoxCore/include/MeshVertex.h b/library/PolyVoxCore/include/MeshVertex.h deleted file mode 100644 index 66c85a4a..00000000 --- a/library/PolyVoxCore/include/MeshVertex.h +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* -Copyright (c) 2005-2009 David Williams - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*******************************************************************************/ - -#ifndef __PolyVox_MeshVertex_H__ -#define __PolyVox_MeshVertex_H__ - -#include "PolyVoxForwardDeclarations.h" -#include "VertexTypes.h" - -#include "PolyVoxImpl/TypeDef.h" - -#include - -namespace PolyVox -{ - class POLYVOXCORE_API MeshVertex - { - public: - MeshVertex(); - PositionMaterialNormal m_vertexData; - //MeshEdge* m_pEdge; - //std::set m_faces; - //std::set m_edges; //Edges which have this vertex as the src - long int m_index; //Bit wasteful to store this the whle time, as it's only used when converting to Meshs? - - bool isSane(void); - }; -} - -#endif \ No newline at end of file diff --git a/library/PolyVoxCore/source/Mesh.cpp b/library/PolyVoxCore/source/Mesh.cpp deleted file mode 100644 index d81f6cac..00000000 --- a/library/PolyVoxCore/source/Mesh.cpp +++ /dev/null @@ -1,446 +0,0 @@ -/******************************************************************************* -Copyright (c) 2005-2009 David Williams - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*******************************************************************************/ - -#include "Mesh.h" - -#include "SurfaceMesh.h" - -#include - -namespace PolyVox -{ - void Mesh::buildFromMesh(SurfaceMesh* pMesh) - { - //First we copy the vertices across. - //We also keep track of where each vertex went - std::vector< std::set::iterator > vertexMapper(pMesh->getNoOfVertices()); - - for(int ct = 0; ct < pMesh->getNoOfVertices(); ct++) - { - MeshVertex* pMeshVertex = new MeshVertex; - pMeshVertex->m_vertexData = pMesh->m_vecVertices[ct]; - vertexMapper[ct] = m_vertices.insert(pMeshVertex).first; - } - - //Next, we add each triangle to the mesh - for(int triCt = 0; triCt < pMesh->getNoOfIndices() / 3; triCt++) - { - int index0 = pMesh->m_vecTriangleIndices[triCt * 3]; - int index1 = pMesh->m_vecTriangleIndices[triCt * 3 + 1]; - int index2 = pMesh->m_vecTriangleIndices[triCt * 3 + 2]; - - MeshVertex* meshVertex0 = *(vertexMapper[index0]); - MeshVertex* meshVertex1 = *(vertexMapper[index1]); - MeshVertex* meshVertex2 = *(vertexMapper[index2]); - - MeshEdge* v0v1 = new MeshEdge; - v0v1->m_pSrc = meshVertex0; - v0v1->m_pDest = meshVertex1; - //meshVertex0->m_edges.insert(v0v1); - - MeshEdge* v1v2 = new MeshEdge; - v1v2->m_pSrc = meshVertex1; - v1v2->m_pDest = meshVertex2; - //meshVertex1->m_edges.insert(v1v2); - - MeshEdge* v2v0 = new MeshEdge; - v2v0->m_pSrc = meshVertex2; - v2v0->m_pDest = meshVertex0; - //meshVertex2->m_edges.insert(v2v0); - - v0v1->m_pNextEdge = v1v2; - v1v2->m_pNextEdge = v2v0; - v2v0->m_pNextEdge = v0v1; - - v0v1->m_pPreviousEdge = v2v0; - v1v2->m_pPreviousEdge = v0v1; - v2v0->m_pPreviousEdge = v1v2; - - v0v1->m_pOtherEdge = 0; - v1v2->m_pOtherEdge = 0; - v2v0->m_pOtherEdge = 0; - - m_edges.insert(v0v1); - m_edges.insert(v1v2); - m_edges.insert(v2v0); - - //Create the face - MeshFace* meshFace = new MeshFace; - - v0v1->m_pFace = meshFace; - v1v2->m_pFace = meshFace; - v2v0->m_pFace = meshFace; - - meshFace->m_pEdge = v0v1; //Just use the first edge - - m_faces.insert(meshFace); - - //The the vertices they are used by the face - //meshVertex0->m_faces.insert(meshFace); - //meshVertex1->m_faces.insert(meshFace); - //meshVertex2->m_faces.insert(meshFace); - } - - //Loop over the edges and try to match up any pairs. - /*for(std::set::iterator edgeIter = m_edges.begin(); edgeIter != m_edges.end(); edgeIter++) - { - MeshEdge* pMeshEdge = *edgeIter; - - if(pMeshEdge->m_pOtherEdge == 0) - { - //Let's see if we can find the other edge somewhere. - //Create an example of what we are looking for... - MeshEdge otherEdgeExample; - otherEdgeExample.m_pSrc = pMeshEdge->m_pDest; - otherEdgeExample.m_pDest = pMeshEdge->m_pSrc; - - m_edges.find( - } - }*/ - - /*int counter = 0; - - //Lastly, we loop over the edges and determine all those which should be adjacent - for(std::set::iterator outerIter = m_edges.begin(); outerIter != m_edges.end(); outerIter++) - { - std::cout << counter++ << std::endl; - - for(std::set::iterator innerIter = m_edges.begin(); innerIter != m_edges.end(); innerIter++) - { - MeshEdge* edge0 = *outerIter; - MeshEdge* edge1 = *innerIter; - - if((edge0->m_pSrc == edge1->m_pDest) && (edge0->m_pDest == edge1->m_pSrc)) - { - edge0->m_pOtherEdge = edge1; - edge1->m_pOtherEdge = edge0; - } - } - }*/ - - //Match up the edge pains - matchEdgePairs(); - - //Compute the edge costs - computeEdgeCosts(); - - //Check sanity - isSane(); - } - - void Mesh::matchEdgePairs(void) - { - std::set matchedEdges; - while(m_edges.empty() == false) - { - std::set::iterator firstEdgeIter = m_edges.begin(); - MeshEdge* firstEdgePtr = *firstEdgeIter; - m_edges.erase(firstEdgeIter); - matchedEdges.insert(firstEdgePtr); - - //Attempt to find the opposite edge - for(std::set::iterator edgeIter = m_edges.begin(); edgeIter != m_edges.end(); edgeIter++) - { - MeshEdge* candidate = *edgeIter; - if((firstEdgePtr->m_pSrc == candidate->m_pDest) && (firstEdgePtr->m_pDest == candidate->m_pSrc)) - { - m_edges.erase(edgeIter); - matchedEdges.insert(candidate); - - firstEdgePtr->m_pOtherEdge = candidate; - candidate->m_pOtherEdge = firstEdgePtr; - - break; - } - } - } - - m_edges = matchedEdges; - } - - void Mesh::computeEdgeCosts(void) - { - for(std::set::iterator edgeIter = m_edges.begin(); edgeIter != m_edges.end(); edgeIter++) - { - (*edgeIter)->computeEdgeCost(this); - } - } - - void Mesh::fillMesh(SurfaceMesh* pMesh) - { - pMesh->clear(); - - for(std::set::iterator vertItor = m_vertices.begin(); vertItor != m_vertices.end(); vertItor++) - { - MeshVertex* meshVertex = *vertItor; - meshVertex->m_index = pMesh->addVertex(meshVertex->m_vertexData); - } - - for(std::set::iterator faceItor = m_faces.begin(); faceItor != m_faces.end(); faceItor++) - { - MeshFace* meshFace = *faceItor; - MeshVertex* v0 = meshFace->m_pEdge->m_pSrc; - MeshVertex* v1 = meshFace->m_pEdge->m_pNextEdge->m_pSrc; - MeshVertex* v2 = meshFace->m_pEdge->m_pNextEdge->m_pNextEdge->m_pSrc; - - pMesh->addTriangle(v0->m_index, v1->m_index, v2->m_index); - } - - pMesh->m_vecLodRecords.clear(); - LodRecord lodRecord; - lodRecord.beginIndex = 0; - lodRecord.endIndex = pMesh->getNoOfIndices(); - pMesh->m_vecLodRecords.push_back(lodRecord); - } - - void Mesh::removeEdge(MeshEdge* pMeshEdge) - { - //Get the src and dest vertices - MeshVertex* pSrc = pMeshEdge->m_pSrc; - MeshVertex* pDest = pMeshEdge->m_pDest; - - //Get the other half of the edge - MeshEdge* pOtherEdge = pMeshEdge->m_pOtherEdge; - - //Get the faces - MeshFace* pMeshFace = pMeshEdge->m_pFace; - MeshFace* pOtherFace = 0; - if(pOtherEdge != 0) - { - pOtherFace = pOtherEdge->m_pFace; - } - - //Remove the faces (the edges keep pointers to the faces, but those edges will be deleted soon anyway...) - m_faces.erase(pMeshFace); - delete pMeshFace; - pMeshFace = 0; - - if(pOtherFace) - { - m_faces.erase(pOtherFace); - delete pOtherFace; - pOtherFace = 0; - } - - //Erase the edges - m_edges.erase(pMeshEdge); - m_edges.erase(pMeshEdge->m_pNextEdge); - m_edges.erase(pMeshEdge->m_pPreviousEdge); - - /*pMeshEdge->m_pSrc->m_edges.erase(pMeshEdge); - pMeshEdge->m_pNextEdge->m_pSrc->m_edges.erase(pMeshEdge->m_pNextEdge); - pMeshEdge->m_pPreviousEdge->m_pSrc->m_edges.erase(pMeshEdge->m_pPreviousEdge);*/ - - delete pMeshEdge->m_pNextEdge; - pMeshEdge->m_pNextEdge = 0; - delete pMeshEdge->m_pPreviousEdge; - pMeshEdge->m_pPreviousEdge = 0; - delete pMeshEdge; - //pMeshEdge = 0; - - - if(pOtherEdge) - { - m_edges.erase(pOtherEdge); - m_edges.erase(pOtherEdge->m_pNextEdge); - m_edges.erase(pOtherEdge->m_pPreviousEdge); - - /*pOtherEdge->m_pSrc->m_edges.erase(pOtherEdge); - pOtherEdge->m_pNextEdge->m_pSrc->m_edges.erase(pOtherEdge->m_pNextEdge); - pOtherEdge->m_pPreviousEdge->m_pSrc->m_edges.erase(pOtherEdge->m_pPreviousEdge);*/ - - delete pOtherEdge->m_pNextEdge; - pOtherEdge->m_pNextEdge = 0; - delete pOtherEdge->m_pPreviousEdge; - pOtherEdge->m_pPreviousEdge = 0; - delete pOtherEdge; - //pOtherEdge = 0; - } - - //Find the affected edges - /*std::set affectedEdges = edgesStartingatEitherVertex; - for(std::set::iterator edgeIter = edgesStartingatEitherVertex.begin(); edgeIter != edgesStartingatEitherVertex.end(); edgeIter++) - { - affectedEdges.insert((*edgeIter)->m_pNextEdge); - affectedEdges.insert((*edgeIter)->m_pPreviousEdge); - //if((*edgeIter)->m_pOtherEdge != 0) - //{ - // affectedEdges.insert((*edgeIter)->m_pOtherEdge); - //} - }*/ - - //Update the source and destinations - for(std::set::iterator edgeIter = m_edges.begin(); edgeIter != m_edges.end(); edgeIter++) - { - MeshEdge* pEdge = *edgeIter; - if(pEdge->m_pSrc == pSrc) - { - pEdge->m_pSrc = pDest; - } - if(pEdge->m_pDest == pSrc) - { - pEdge->m_pDest = pDest; - } - } - - /*for(std::set::iterator vertexIter = m_vertices.begin(); vertexIter != m_vertices.end(); vertexIter++) - { - (*vertexIter)->m_edges.clear(); - } - - for(std::set::iterator edgeIter = m_edges.begin(); edgeIter != m_edges.end(); edgeIter++) - { - MeshEdge* pEdge = *edgeIter; - pEdge->m_pSrc->m_edges.insert(pEdge); - }*/ - - - /*for(std::set::iterator edgeIter = affectedEdges.begin(); edgeIter != affectedEdges.end(); edgeIter++) - { - MeshEdge* pEdge = *edgeIter; - if(pEdge->m_pSrc == pSrc) - { - pEdge->m_pSrc = pDest; - } - if(pEdge->m_pDest == pSrc) - { - pEdge->m_pDest = pDest; - } - }*/ - - //Deal with the vertices - /*pSrc->m_edges.erase(pMeshEdge); - if(pOtherEdge) - { - pDest->m_edges.erase(pOtherEdge); - }*/ - - //Find the edges starting at either vertex - /*std::set edgesStartingatEitherVertex; - std::set_union(pSrc->m_edges.begin(), pSrc->m_edges.end(), - pDest->m_edges.begin(), pDest->m_edges.end(), - std::inserter(edgesStartingatEitherVertex, edgesStartingatEitherVertex.begin()));*/ - - //Remove the old vertex - //pDest->m_edges = edgesStartingatEitherVertex; - m_vertices.erase(pSrc); - delete pSrc; //Don't set to 0 yet as we will use the value - - //Update any pairings - matchEdgePairs(); - /*for(std::set::iterator outerIter = affectedEdges.begin(); outerIter != affectedEdges.end(); outerIter++) - { - for(std::set::iterator innerIter = affectedEdges.begin(); innerIter != affectedEdges.end(); innerIter++) - { - MeshEdge* edge0 = *outerIter; - MeshEdge* edge1 = *innerIter; - - if((edge0->m_pSrc == edge1->m_pDest) && (edge0->m_pDest == edge1->m_pSrc)) - { - edge0->m_pOtherEdge = edge1; - edge1->m_pOtherEdge = edge0; - } - } - }*/ - - //Recompute the affected edge costs - computeEdgeCosts(); - /*for(std::set::iterator edgeIter = affectedEdges.begin(); edgeIter != affectedEdges.end(); edgeIter++) - { - (*edgeIter)->computeEdgeCost(); - }*/ - } - - void Mesh::decimateAll(void) - { - for(int ct = 0; ct < 100; ct++) - { - std::cout << ct << std::endl; - decimateOne(); - //isSane(); - } - /*int ct = 0; - while(decimateOne()) - { - std::cout << ct++ << std::endl; - }*/ - - //decimateOne(); - } - - bool Mesh::decimateOne(void) - { - for(std::set::iterator edgeIter = m_edges.begin(); edgeIter != m_edges.end(); edgeIter++) - { - /*for(int ct = 0; ct < 30; ct++) - { - edgeIter++; - }*/ - - MeshEdge* pMeshEdge = *edgeIter; - if(pMeshEdge->m_fCost < 1.0) - { - removeEdge(pMeshEdge); - return true; - } - } - - return false; - } - - bool Mesh::isSane(void) - { - for(std::set::iterator vertexIter = m_vertices.begin(); vertexIter != m_vertices.end(); vertexIter++) - { - //This would be eaiser if we just propergated exceptions? - if((*vertexIter)->isSane() == false) - { - std::cout << "SANITY CHECK FAIL: Problem found in vertex set" << std::endl; - return false; - } - } - - for(std::set::iterator faceIter = m_faces.begin(); faceIter != m_faces.end(); faceIter++) - { - //This would be eaiser if we just propergated exceptions? - if((*faceIter)->isSane() == false) - { - std::cout << "SANITY CHECK FAIL: Problem found in face set" << std::endl; - return false; - } - } - - for(std::set::iterator edgeIter = m_edges.begin(); edgeIter != m_edges.end(); edgeIter++) - { - //This would be eaiser if we just propergated exceptions? - if((*edgeIter)->isSane() == false) - { - std::cout << "SANITY CHECK FAIL: Problem found in edge set" << std::endl; - return false; - } - } - - std::cout << "SANITY CHECK SUCCESS" << std::endl; - return true; - } -} \ No newline at end of file diff --git a/library/PolyVoxCore/source/MeshEdge.cpp b/library/PolyVoxCore/source/MeshEdge.cpp deleted file mode 100644 index 5158ea4e..00000000 --- a/library/PolyVoxCore/source/MeshEdge.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* -Copyright (c) 2005-2009 David Williams - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*******************************************************************************/ - -#include "MeshEdge.h" - -#include "Mesh.h" -#include "MeshFace.h" -#include "MeshVertex.h" -#include "VertexTypes.h" - -#include - -namespace PolyVox -{ - - bool operator==(const MeshEdge& lhs, const MeshEdge& rhs) - { - return lhs.m_pSrc == rhs.m_pSrc && lhs.m_pDest == rhs.m_pDest; - } - - bool operator<(const MeshEdge& lhs, const MeshEdge& rhs) - { - if(lhs == rhs) - return false; - - if (lhs.m_pSrc < rhs.m_pSrc) - return true; - if (rhs.m_pSrc < lhs.m_pSrc) - return false; - - if (lhs.m_pDest < rhs.m_pDest) - return true; - if (rhs.m_pDest < lhs.m_pDest) - return false; - - return false; - } - - MeshEdge::MeshEdge() - { - m_pOtherEdge = 0; - m_pNextEdge = 0; - m_pPreviousEdge = 0; - - m_pSrc = 0; - m_pDest = 0; - - m_pFace = 0; - - m_fCost = 1000000.0f; - } - - void MeshEdge::computeEdgeCost(Mesh* pParentMesh) - { - PositionMaterialNormal v0Data = m_pSrc->m_vertexData; - PositionMaterialNormal v1Data = m_pDest->m_vertexData; - - m_fCost = 1000000.0f; - - //For now, don't collapse vertices on material edges... - if(v0Data.isOnMaterialEdge() || v1Data.isOnMaterialEdge()) - { - return; - } - - //...or those on geometry (region) edges. - if(v0Data.isOnGeometryEdge() || v1Data.isOnGeometryEdge()) - { - return; - } - - //Check the normals are within the threshold. - if(v0Data.getNormal().dot(v1Data.getNormal()) < 0.999) - { - return; - } - - //Test for face flips - for(std::set::iterator faceIter = pParentMesh->m_faces.begin(); faceIter != pParentMesh->m_faces.end(); faceIter++) - { - if((*faceIter)->collapseFlipsFace(this)) - { - return; - } - } - - m_fCost = 0.0f; - return; - } - - bool MeshEdge::isSane(void) - { - if(m_pSrc == 0) - { - std::cout << "SANITY CHECK FAIL: Edge has no source vertex" << std::endl; - return false; - } - - if(m_pDest == 0) - { - std::cout << "SANITY CHECK FAIL: Edge has no destination vertex" << std::endl; - return false; - } - - if(m_pFace == 0) - { - std::cout << "SANITY CHECK FAIL: Edge has no face attached" << std::endl; - return false; - } - - //Check loops - if(this != m_pNextEdge->m_pNextEdge->m_pNextEdge) - { - std::cout << "SANITY CHECK FAIL: Next edge loop is broken" << std::endl; - return false; - } - - if(this != m_pPreviousEdge->m_pPreviousEdge->m_pPreviousEdge) - { - std::cout << "SANITY CHECK FAIL: Previous edge loop is broken" << std::endl; - return false; - } - - //Make sure the other edge points back here - if(m_pOtherEdge != 0) - { - if(this != m_pOtherEdge->m_pOtherEdge) - { - std::cout << "SANITY CHECK FAIL: Other edge exists but does not point back here." << std::endl; - return false; - } - } - - return true; - } -} \ No newline at end of file diff --git a/library/PolyVoxCore/source/MeshFace.cpp b/library/PolyVoxCore/source/MeshFace.cpp deleted file mode 100644 index a1a0ce1d..00000000 --- a/library/PolyVoxCore/source/MeshFace.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* -Copyright (c) 2005-2009 David Williams - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*******************************************************************************/ - -#include "MeshFace.h" - -#include "MeshEdge.h" -#include "MeshVertex.h" - -#include "Vector.h" - -#include - -namespace PolyVox -{ - MeshFace::MeshFace() - { - m_pEdge = 0; - } - - bool MeshFace::isSane(void) - { - if(m_pEdge == 0) - { - std::cout << "SANITY CHECK FAIL: Face has no edge attached" << std::endl; - return false; - } - - return true; - } - - Vector3DFloat MeshFace::getNormal(void) - { - //Find the three vertices - Vector3DFloat pV0 = m_pEdge->m_pSrc->m_vertexData.getPosition(); - Vector3DFloat pV1 = m_pEdge->m_pNextEdge->m_pSrc->m_vertexData.getPosition(); - Vector3DFloat pV2 = m_pEdge->m_pNextEdge->m_pNextEdge->m_pSrc->m_vertexData.getPosition(); - - Vector3DFloat crossProduct = (pV1 - pV0).cross(pV2 - pV0); - - assert(crossProduct.length() > 0.001); - - crossProduct.normalise(); - - return crossProduct; - } - - bool MeshFace::collapseFlipsFace(MeshEdge* pEdgeToCollapse) - { - MeshVertex* pSrc = pEdgeToCollapse->m_pSrc; - MeshVertex* pDest = pEdgeToCollapse->m_pDest; - - MeshVertex* pV0 = m_pEdge->m_pSrc; - MeshVertex* pV1 = m_pEdge->m_pNextEdge->m_pSrc; - MeshVertex* pV2 = m_pEdge->m_pNextEdge->m_pNextEdge->m_pSrc; - - if(pSrc == pV0) - { - return collapseFlipsFaceImpl(pV1->m_vertexData.getPosition(), pV2->m_vertexData.getPosition(), pSrc->m_vertexData.getPosition(), pDest->m_vertexData.getPosition()); - } - if(pSrc == pV1) - { - return collapseFlipsFaceImpl(pV0->m_vertexData.getPosition(), pV2->m_vertexData.getPosition(), pSrc->m_vertexData.getPosition(), pDest->m_vertexData.getPosition()); - } - if(pSrc == pV2) - { - return collapseFlipsFaceImpl(pV0->m_vertexData.getPosition(), pV1->m_vertexData.getPosition(), pSrc->m_vertexData.getPosition(), pDest->m_vertexData.getPosition()); - } - - return false; - } - - bool MeshFace::collapseFlipsFaceImpl(Vector3DFloat fixed0, Vector3DFloat fixed1, Vector3DFloat oldPos, Vector3DFloat newPos) - { - Vector3DFloat oldCrossProduct = (fixed0 - oldPos).cross(fixed1 - oldPos); - Vector3DFloat newCrossProduct = (fixed0 - newPos).cross(fixed1 - newPos); - - if(oldCrossProduct.length() < 0.001f) - { - return false; - } - - if(newCrossProduct.length() < 0.001f) - { - return false; - } - - oldCrossProduct.normalise(); - newCrossProduct.normalise(); - - return oldCrossProduct.dot(newCrossProduct) < 0.999f; - } -} \ No newline at end of file diff --git a/library/PolyVoxCore/source/MeshVertex.cpp b/library/PolyVoxCore/source/MeshVertex.cpp deleted file mode 100644 index 2fddd5ad..00000000 --- a/library/PolyVoxCore/source/MeshVertex.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* -Copyright (c) 2005-2009 David Williams - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*******************************************************************************/ - -#include "MeshVertex.h" - -namespace PolyVox -{ - MeshVertex::MeshVertex() - { - m_index = -1; - } - - bool MeshVertex::isSane(void) - { - /*if(m_edges.empty()) - { - std::cout << "SANITY CHECK FAIL: Vertex has no edges attached" << std::endl; - return false; - }*/ - - return true; - } -} \ No newline at end of file