From 4f9c93a454e76a37f3446d4ccaa88cb819a7c145 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 3 Jun 2009 21:48:26 +0000 Subject: [PATCH] Work on templatizing surface extractor. --- examples/OpenGL/OpenGLWidget.cpp | 2 +- .../PolyVoxCore/include/SurfaceExtractor.h | 14 ++++++-- .../PolyVoxCore/source/SurfaceExtractor.cpp | 35 +++++++++++++------ 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/examples/OpenGL/OpenGLWidget.cpp b/examples/OpenGL/OpenGLWidget.cpp index 42023770..efa11726 100644 --- a/examples/OpenGL/OpenGLWidget.cpp +++ b/examples/OpenGL/OpenGLWidget.cpp @@ -38,7 +38,7 @@ void OpenGLWidget::setVolume(PolyVox::Volume* volData) m_uVolumeDepthInRegions = volData->getDepth() / m_uRegionSideLength; SurfaceExtractor surfaceExtractor(*volData); - surfaceExtractor.setLodLevel(0); + surfaceExtractor.setLodLevel(1); //Our volume is broken down into cuboid regions, and we create one mesh for each region. //This three-level for loop iterates over each region. diff --git a/library/PolyVoxCore/include/SurfaceExtractor.h b/library/PolyVoxCore/include/SurfaceExtractor.h index b6ecc5fe..98dd30f9 100644 --- a/library/PolyVoxCore/include/SurfaceExtractor.h +++ b/library/PolyVoxCore/include/SurfaceExtractor.h @@ -92,12 +92,20 @@ namespace PolyVox Region regSlice1; uint16_t m_uRegionWidth; + //uint16_t m_uRegionWidthOverStepSize; + //uint16_t m_uRegionHeightOverStepSize; //void extractSurfaceForRegionLevel0(Volume* volumeData, Region region, IndexedSurfacePatch* m_ispCurrent); - void extractSurfaceImpl(Region region, uint8_t uLodLevel); - uint32_t computeBitmaskForSlice(bool isPrevZAvail, uint8_t uLodLevel); - void computeBitmaskForCell(bool isPrevXAvail, bool isPrevYAvail, bool isPrevZAvail, uint8_t uLodLevel); + template + void extractSurfaceImpl(Region region); + + template + uint32_t computeBitmaskForSlice(void); + + template + void computeBitmaskForCell(void); + void generateIndicesForSlice(); void generateVerticesForSlice(); }; diff --git a/library/PolyVoxCore/source/SurfaceExtractor.cpp b/library/PolyVoxCore/source/SurfaceExtractor.cpp index 548c140a..4965ed1f 100644 --- a/library/PolyVoxCore/source/SurfaceExtractor.cpp +++ b/library/PolyVoxCore/source/SurfaceExtractor.cpp @@ -31,14 +31,27 @@ namespace PolyVox //POLYVOX_SHARED_PTR result(new IndexedSurfacePatch()); m_ispCurrent = new IndexedSurfacePatch(); - extractSurfaceImpl(region, m_uLodLevel); + switch(m_uLodLevel) + { + case 0: + extractSurfaceImpl<0>(region); + break; + case 1: + extractSurfaceImpl<1>(region); + break; + case 2: + extractSurfaceImpl<2>(region); + break; + } + m_ispCurrent->m_Region = region; return POLYVOX_SHARED_PTR(m_ispCurrent); } - void SurfaceExtractor::extractSurfaceImpl(Region region, uint8_t uLodLevel) + template + void SurfaceExtractor::extractSurfaceImpl(Region region) { m_ispCurrent->clear(); @@ -80,7 +93,7 @@ namespace PolyVox uint32_t uNoOfNonEmptyCellsForSlice1 = 0; //Process the first slice (previous slice not available) - computeBitmaskForSlice(false, uLodLevel); + computeBitmaskForSlice(); uNoOfNonEmptyCellsForSlice1 = m_uNoOfOccupiedCells; if(uNoOfNonEmptyCellsForSlice1 != 0) @@ -100,7 +113,7 @@ namespace PolyVox //Process the first slice (previous slice is available) for(uint32_t uSlice = 1; ((uSlice <= region.depth()) && (uSlice + m_v3dRegionOffset.getZ() <= regVolume.getUpperCorner().getZ())); uSlice += m_uStepSize) { - computeBitmaskForSlice(true, uLodLevel); + computeBitmaskForSlice(); uNoOfNonEmptyCellsForSlice1 = m_uNoOfOccupiedCells; if(uNoOfNonEmptyCellsForSlice1 != 0) @@ -133,7 +146,8 @@ namespace PolyVox delete[] m_pCurrentVertexIndicesZ; } - uint32_t SurfaceExtractor::computeBitmaskForSlice(bool isPrevZAvail, uint8_t uLodLevel) + template + uint32_t SurfaceExtractor::computeBitmaskForSlice(void) { m_uNoOfOccupiedCells = 0; @@ -151,7 +165,7 @@ namespace PolyVox uYRegSpace = uYVolSpace - m_v3dRegionOffset.getY(); m_sampVolume.setPosition(uXVolSpace,uYVolSpace,uZVolSpace); - computeBitmaskForCell(false, false, isPrevZAvail, uLodLevel); + computeBitmaskForCell(); //Process the edge where x is minimal. @@ -162,7 +176,7 @@ namespace PolyVox uYRegSpace = uYVolSpace - m_v3dRegionOffset.getY(); m_sampVolume.setPosition(uXVolSpace,uYVolSpace,uZVolSpace); - computeBitmaskForCell(false, true, isPrevZAvail, uLodLevel); + computeBitmaskForCell(); } //Process the edge where y is minimal. @@ -173,7 +187,7 @@ namespace PolyVox uYRegSpace = uYVolSpace - m_v3dRegionOffset.getY(); m_sampVolume.setPosition(uXVolSpace,uYVolSpace,uZVolSpace); - computeBitmaskForCell(true, false, isPrevZAvail, uLodLevel); + computeBitmaskForCell(); } //Process all remaining elemnents of the slice. In this case, previous x and y values are always available @@ -185,14 +199,15 @@ namespace PolyVox uYRegSpace = uYVolSpace - m_v3dRegionOffset.getY(); m_sampVolume.setPosition(uXVolSpace,uYVolSpace,uZVolSpace); - computeBitmaskForCell(true, true, isPrevZAvail, uLodLevel); + computeBitmaskForCell(); } } return m_uNoOfOccupiedCells; } - void SurfaceExtractor::computeBitmaskForCell(bool isPrevXAvail, bool isPrevYAvail, bool isPrevZAvail, uint8_t uLodLevel) + template + void SurfaceExtractor::computeBitmaskForCell(void) { uint8_t iCubeIndex = 0;