From 83b2f845293769ba1728b111c9b3c0fef18e9bee Mon Sep 17 00:00:00 2001 From: David Williams Date: Thu, 6 Jan 2011 22:36:25 +0000 Subject: [PATCH] OpenGLExample does decimation now, so so we can check it still compiles. --- examples/OpenGL/OpenGLWidget.cpp | 9 +++++++-- library/PolyVoxCore/include/MeshDecimator.inl | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/OpenGL/OpenGLWidget.cpp b/examples/OpenGL/OpenGLWidget.cpp index 82c283c8..e266666b 100644 --- a/examples/OpenGL/OpenGLWidget.cpp +++ b/examples/OpenGL/OpenGLWidget.cpp @@ -27,6 +27,7 @@ freely, subject to the following restrictions: #include "GradientEstimators.h" #include "MaterialDensityPair.h" +#include "MeshDecimator.h" #include "SurfaceExtractor.h" #include "Mesh.h" @@ -93,6 +94,10 @@ void OpenGLWidget::setVolume(PolyVox::Volume* volData) SurfaceExtractor surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get()); surfaceExtractor.execute(); + polyvox_shared_ptr< SurfaceMesh > decimatedMesh(new SurfaceMesh); + MeshDecimator decimator(mesh.get(), decimatedMesh.get(), 0.95f); + decimator.execute(); + //computeNormalsForVertices(m_volData, *(mesh.get()), SOBEL_SMOOTHED); //*meshCurrent = getSmoothedSurface(*meshCurrent); //mesh->smooth(0.3f); @@ -139,12 +144,12 @@ void OpenGLWidget::setVolume(PolyVox::Volume* volData) Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ); if(m_bUseOpenGLVertexBufferObjects) { - OpenGLSurfaceMesh openGLSurfaceMesh = BuildOpenGLSurfaceMesh(*(mesh.get())); + OpenGLSurfaceMesh openGLSurfaceMesh = BuildOpenGLSurfaceMesh(*(decimatedMesh.get())); m_mapOpenGLSurfaceMeshes.insert(make_pair(v3dRegPos, openGLSurfaceMesh)); } //else //{ - m_mapSurfaceMeshes.insert(make_pair(v3dRegPos, mesh)); + m_mapSurfaceMeshes.insert(make_pair(v3dRegPos, decimatedMesh)); //} //delete meshCurrent; } diff --git a/library/PolyVoxCore/include/MeshDecimator.inl b/library/PolyVoxCore/include/MeshDecimator.inl index 501211f5..1ad48e25 100644 --- a/library/PolyVoxCore/include/MeshDecimator.inl +++ b/library/PolyVoxCore/include/MeshDecimator.inl @@ -366,7 +366,9 @@ namespace PolyVox { //We don't actually use the normal here, because we want to allow face //vertices to collapse onto edge vertices. Simply checking whether anything - //has flipped has proved to be the most robust approach, though rather slow... + //has flipped has proved to be the most robust approach, though rather slow. + //It's not sufficient to just check the normals, there can be holes in the middle + //of the mesh for example. //User specified threshold is not used for cubic surface, any //movement is too much (but allow for floating point error). @@ -455,10 +457,8 @@ namespace PolyVox OldNormal.normalise(); NewNormal.normalise(); - // Note for after holiday - We are still getting faces flipping despite the following test. I tried changing - // the 0.0 to 0.9 (which should still let coplanar faces merge) but oddly nothing then merged. Investigate this. float dotProduct = OldNormal.dot(NewNormal); - //cout << dotProduct << endl; + //NOTE: I don't think we should be using the threshold here, we're just checking for a complete face flip if(dotProduct < fThreshold) { //cout << " Face flipped!!" << endl;