From 85829e004f2a5bc5b0125c187c94205a3afc0759 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 20 May 2009 20:09:34 +0000 Subject: [PATCH] Work on refactoring surface extractor. --- examples/OpenGL/OpenGLWidget.cpp | 2 +- library/PolyVoxCore/include/VolumeIterator.h | 1 + .../PolyVoxCore/include/VolumeIterator.inl | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/examples/OpenGL/OpenGLWidget.cpp b/examples/OpenGL/OpenGLWidget.cpp index 851c8124..d2f33202 100644 --- a/examples/OpenGL/OpenGLWidget.cpp +++ b/examples/OpenGL/OpenGLWidget.cpp @@ -64,7 +64,7 @@ void OpenGLWidget::setVolume(PolyVox::Volume* volData) Vector3DInt32 regUpperCorner(regionEndX, regionEndY, regionEndZ); //Extract the surface for this region - extractSurface(m_volData, 1, PolyVox::Region(regLowerCorner, regUpperCorner), ispCurrent); + extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), ispCurrent); //computeNormalsForVertices(m_volData, *ispCurrent, SOBEL_SMOOTHED); //*ispCurrent = getSmoothedSurface(*ispCurrent); diff --git a/library/PolyVoxCore/include/VolumeIterator.h b/library/PolyVoxCore/include/VolumeIterator.h index 79fcdbaf..e47e00e6 100644 --- a/library/PolyVoxCore/include/VolumeIterator.h +++ b/library/PolyVoxCore/include/VolumeIterator.h @@ -47,6 +47,7 @@ namespace PolyVox uint16_t getPosY(void) const; uint16_t getPosZ(void) const; VoxelType getSubSampledVoxel(uint8_t uLevel) const; + VoxelType getSubSampledVoxelWithBoundsCheck(uint8_t uLevel) const; const Volume& getVolume(void) const; VoxelType getVoxel(void) const; diff --git a/library/PolyVoxCore/include/VolumeIterator.inl b/library/PolyVoxCore/include/VolumeIterator.inl index d2b9e913..d70e0f58 100644 --- a/library/PolyVoxCore/include/VolumeIterator.inl +++ b/library/PolyVoxCore/include/VolumeIterator.inl @@ -163,6 +163,25 @@ namespace PolyVox } } + template + VoxelType VolumeIterator::getSubSampledVoxelWithBoundsCheck(uint8_t uLevel) const + { + const uint8_t uSize = 1 << uLevel; + + if((mXPosInVolume >= 0) && (mXPosInVolume <= mVolume.getWidth() - uSize) && + (mYPosInVolume >= 0) && (mYPosInVolume <= mVolume.getHeight() - uSize) && + (mZPosInVolume >= 0) && (mZPosInVolume <= mVolume.getDepth() - uSize)) + { + return getSubSampledVoxel(uLevel); + } + else + { + //If any voxel is outside then it's value will be zero, and so the minimum will be zero. + //No need to even look at the rest of the voxels. + return 0; + } + } + template const Volume& VolumeIterator::getVolume(void) const {