From 5a99101341518736281f5ae27a069fd5f8dbd1e5 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 2 Jun 2009 22:51:00 +0000 Subject: [PATCH] Optimising SurfaceExtractor. --- examples/OpenGL/OpenGLWidget.cpp | 2 +- library/PolyVoxCore/include/Volume.h | 2 - library/PolyVoxCore/include/Volume.inl | 19 ------- library/PolyVoxCore/include/VolumeSampler.h | 57 +++++++++---------- library/PolyVoxCore/include/VolumeSampler.inl | 19 ------- 5 files changed, 29 insertions(+), 70 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/Volume.h b/library/PolyVoxCore/include/Volume.h index fe4fe524..131502d2 100644 --- a/library/PolyVoxCore/include/Volume.h +++ b/library/PolyVoxCore/include/Volume.h @@ -131,8 +131,6 @@ namespace PolyVox float getDiagonalLength(void) const; VoxelType getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const; VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const; - VoxelType getVoxelAtWithBoundCheck(int16_t uXPos, int16_t uYPos, int16_t uZPos) const; - VoxelType getVoxelAtWithBoundCheck(const Vector3DInt16& v3dPos) const; void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue); void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue); diff --git a/library/PolyVoxCore/include/Volume.inl b/library/PolyVoxCore/include/Volume.inl index 898d7281..c74f87e1 100644 --- a/library/PolyVoxCore/include/Volume.inl +++ b/library/PolyVoxCore/include/Volume.inl @@ -249,25 +249,6 @@ namespace PolyVox { return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } - - template - VoxelType Volume::getVoxelAtWithBoundCheck(int16_t uXPos, int16_t uYPos, int16_t uZPos) const - { - if((uXPos >=0) && (uXPos < m_uWidth) && (uYPos >= 0) && (uYPos < m_uHeight) && (uZPos >= 0) && (uZPos < m_uDepth)) - { - return getVoxelAt(uXPos, uYPos, uZPos); - } - else - { - return 0; - } - } - - template - VoxelType Volume::getVoxelAtWithBoundCheck(const Vector3DInt16& v3dPos) const - { - return getVoxelAtWithBoundCheck(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); - } #pragma endregion #pragma region Setters diff --git a/library/PolyVoxCore/include/VolumeSampler.h b/library/PolyVoxCore/include/VolumeSampler.h index 5795df5d..8a886b54 100644 --- a/library/PolyVoxCore/include/VolumeSampler.h +++ b/library/PolyVoxCore/include/VolumeSampler.h @@ -47,44 +47,43 @@ 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; + inline VoxelType getVoxel(void) const; void setPosition(const Vector3DInt16& v3dNewPos); void setPosition(uint16_t xPos, uint16_t yPos, uint16_t zPos); void movePositiveX(void); - VoxelType peekVoxel1nx1ny1nz(void) const; - VoxelType peekVoxel1nx1ny0pz(void) const; - VoxelType peekVoxel1nx1ny1pz(void) const; - VoxelType peekVoxel1nx0py1nz(void) const; - VoxelType peekVoxel1nx0py0pz(void) const; - VoxelType peekVoxel1nx0py1pz(void) const; - VoxelType peekVoxel1nx1py1nz(void) const; - VoxelType peekVoxel1nx1py0pz(void) const; - VoxelType peekVoxel1nx1py1pz(void) const; + inline VoxelType peekVoxel1nx1ny1nz(void) const; + inline VoxelType peekVoxel1nx1ny0pz(void) const; + inline VoxelType peekVoxel1nx1ny1pz(void) const; + inline VoxelType peekVoxel1nx0py1nz(void) const; + inline VoxelType peekVoxel1nx0py0pz(void) const; + inline VoxelType peekVoxel1nx0py1pz(void) const; + inline VoxelType peekVoxel1nx1py1nz(void) const; + inline VoxelType peekVoxel1nx1py0pz(void) const; + inline VoxelType peekVoxel1nx1py1pz(void) const; - VoxelType peekVoxel0px1ny1nz(void) const; - VoxelType peekVoxel0px1ny0pz(void) const; - VoxelType peekVoxel0px1ny1pz(void) const; - VoxelType peekVoxel0px0py1nz(void) const; - VoxelType peekVoxel0px0py0pz(void) const; - VoxelType peekVoxel0px0py1pz(void) const; - VoxelType peekVoxel0px1py1nz(void) const; - VoxelType peekVoxel0px1py0pz(void) const; - VoxelType peekVoxel0px1py1pz(void) const; + inline VoxelType peekVoxel0px1ny1nz(void) const; + inline VoxelType peekVoxel0px1ny0pz(void) const; + inline VoxelType peekVoxel0px1ny1pz(void) const; + inline VoxelType peekVoxel0px0py1nz(void) const; + inline VoxelType peekVoxel0px0py0pz(void) const; + inline VoxelType peekVoxel0px0py1pz(void) const; + inline VoxelType peekVoxel0px1py1nz(void) const; + inline VoxelType peekVoxel0px1py0pz(void) const; + inline VoxelType peekVoxel0px1py1pz(void) const; - VoxelType peekVoxel1px1ny1nz(void) const; - VoxelType peekVoxel1px1ny0pz(void) const; - VoxelType peekVoxel1px1ny1pz(void) const; - VoxelType peekVoxel1px0py1nz(void) const; - VoxelType peekVoxel1px0py0pz(void) const; - VoxelType peekVoxel1px0py1pz(void) const; - VoxelType peekVoxel1px1py1nz(void) const; - VoxelType peekVoxel1px1py0pz(void) const; - VoxelType peekVoxel1px1py1pz(void) const; + inline VoxelType peekVoxel1px1ny1nz(void) const; + inline VoxelType peekVoxel1px1ny0pz(void) const; + inline VoxelType peekVoxel1px1ny1pz(void) const; + inline VoxelType peekVoxel1px0py1nz(void) const; + inline VoxelType peekVoxel1px0py0pz(void) const; + inline VoxelType peekVoxel1px0py1pz(void) const; + inline VoxelType peekVoxel1px1py1nz(void) const; + inline VoxelType peekVoxel1px1py0pz(void) const; + inline VoxelType peekVoxel1px1py1pz(void) const; private: diff --git a/library/PolyVoxCore/include/VolumeSampler.inl b/library/PolyVoxCore/include/VolumeSampler.inl index ce363db1..46f00031 100644 --- a/library/PolyVoxCore/include/VolumeSampler.inl +++ b/library/PolyVoxCore/include/VolumeSampler.inl @@ -163,25 +163,6 @@ namespace PolyVox } } - template - VoxelType VolumeSampler::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& VolumeSampler::getVolume(void) const {