From 358d07b2348fd0936c0252d28f18686214086980 Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 29 May 2009 22:16:51 +0000 Subject: [PATCH] SurfaceExtractor now returns shared pointer to surface. --- examples/OpenGL/OpenGLWidget.cpp | 15 ++++++--------- examples/OpenGL/OpenGLWidget.h | 2 +- library/PolyVoxCore/include/SurfaceExtractor.h | 2 +- library/PolyVoxCore/source/SurfaceExtractor.cpp | 12 ++++++++---- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/examples/OpenGL/OpenGLWidget.cpp b/examples/OpenGL/OpenGLWidget.cpp index 16148e4b..ef8c0483 100644 --- a/examples/OpenGL/OpenGLWidget.cpp +++ b/examples/OpenGL/OpenGLWidget.cpp @@ -49,9 +49,6 @@ void OpenGLWidget::setVolume(PolyVox::Volume* volData) { for(PolyVox::uint16_t uRegionX = 0; uRegionX < m_uVolumeWidthInRegions; ++uRegionX) { - //Create a new surface patch (which is basiaclly the PolyVox term for a mesh). - IndexedSurfacePatch* ispCurrent = new IndexedSurfacePatch(); - //Compute the extents of the current region //FIXME - This is a little complex? PolyVox could //provide more functions for dealing with regions? @@ -68,23 +65,23 @@ void OpenGLWidget::setVolume(PolyVox::Volume* volData) //Extract the surface for this region //extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), ispCurrent); - surfaceExtractor.extractSurfaceForRegion(PolyVox::Region(regLowerCorner, regUpperCorner), ispCurrent); + POLYVOX_SHARED_PTR isp = surfaceExtractor.extractSurfaceForRegion(PolyVox::Region(regLowerCorner, regUpperCorner)); - computeNormalsForVertices(m_volData, *ispCurrent, SOBEL_SMOOTHED); + computeNormalsForVertices(m_volData, *(isp.get()), SOBEL_SMOOTHED); //*ispCurrent = getSmoothedSurface(*ispCurrent); - ispCurrent->smooth(0.3f); + isp->smooth(0.3f); //ispCurrent->generateAveragedFaceNormals(true); Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ); if(m_bUseOpenGLVertexBufferObjects) { - OpenGLSurfacePatch openGLSurfacePatch = BuildOpenGLSurfacePatch(*ispCurrent); + OpenGLSurfacePatch openGLSurfacePatch = BuildOpenGLSurfacePatch(*(isp.get())); m_mapOpenGLSurfacePatches.insert(make_pair(v3dRegPos, openGLSurfacePatch)); } else { - m_mapIndexedSurfacePatches.insert(make_pair(v3dRegPos, ispCurrent)); + m_mapIndexedSurfacePatches.insert(make_pair(v3dRegPos, isp)); } //delete ispCurrent; } @@ -170,7 +167,7 @@ void OpenGLWidget::paintGL() } else { - IndexedSurfacePatch* ispCurrent = m_mapIndexedSurfacePatches[v3dRegPos]; + POLYVOX_SHARED_PTR ispCurrent = m_mapIndexedSurfacePatches[v3dRegPos]; renderRegionImmediateMode(*ispCurrent); } diff --git a/examples/OpenGL/OpenGLWidget.h b/examples/OpenGL/OpenGLWidget.h index 6cf8d12f..33248f51 100644 --- a/examples/OpenGL/OpenGLWidget.h +++ b/examples/OpenGL/OpenGLWidget.h @@ -51,7 +51,7 @@ class OpenGLWidget : public QGLWidget //Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region std::map m_mapOpenGLSurfacePatches; - std::map m_mapIndexedSurfacePatches; + std::map > m_mapIndexedSurfacePatches; unsigned int m_uRegionSideLength; unsigned int m_uVolumeWidthInRegions; diff --git a/library/PolyVoxCore/include/SurfaceExtractor.h b/library/PolyVoxCore/include/SurfaceExtractor.h index 2135d2b6..c3e8bd00 100644 --- a/library/PolyVoxCore/include/SurfaceExtractor.h +++ b/library/PolyVoxCore/include/SurfaceExtractor.h @@ -41,7 +41,7 @@ namespace PolyVox void setLodLevel(uint8_t uLodLevel); - void extractSurfaceForRegion(Region region, IndexedSurfacePatch* singleMaterialPatch); + POLYVOX_SHARED_PTR extractSurfaceForRegion(Region region); private: uint8_t m_uLodLevel; diff --git a/library/PolyVoxCore/source/SurfaceExtractor.cpp b/library/PolyVoxCore/source/SurfaceExtractor.cpp index 843691d2..3fa12fda 100644 --- a/library/PolyVoxCore/source/SurfaceExtractor.cpp +++ b/library/PolyVoxCore/source/SurfaceExtractor.cpp @@ -23,17 +23,21 @@ namespace PolyVox m_uLodLevel = uLodLevel; } - void SurfaceExtractor::extractSurfaceForRegion(Region region, IndexedSurfacePatch* singleMaterialPatch) + POLYVOX_SHARED_PTR SurfaceExtractor::extractSurfaceForRegion(Region region) { + POLYVOX_SHARED_PTR result(new IndexedSurfacePatch()); + if(m_uLodLevel == 0) { - extractSurfaceForRegionLevel0(&m_volData, region, singleMaterialPatch); + extractSurfaceForRegionLevel0(&m_volData, region, result.get()); } else { - extractDecimatedSurfaceImpl(&m_volData, m_uLodLevel, region, singleMaterialPatch); + extractDecimatedSurfaceImpl(&m_volData, m_uLodLevel, region, result.get()); } - singleMaterialPatch->m_Region = region; + result->m_Region = region; + + return result; } uint32_t SurfaceExtractor::getIndex(uint32_t x, uint32_t y, uint32_t regionWidth)