From e5aab77cda3bb97d4f547f3dec96a60bfca327f3 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 1 Dec 2012 23:49:13 +0100 Subject: [PATCH] Moved getVoxelAt into base sampler. --- .../include/PolyVoxCore/BaseVolume.h | 1 + .../include/PolyVoxCore/BaseVolumeSampler.inl | 95 +++++++++++++------ .../include/PolyVoxCore/RawVolume.h | 1 - .../include/PolyVoxCore/RawVolumeSampler.inl | 40 -------- 4 files changed, 69 insertions(+), 68 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index d33d6b4c..0622a823 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -109,6 +109,7 @@ namespace PolyVox inline VoxelType peekVoxel1px1py1pz(void) const; protected: + VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; bool isCurrentPositionValid(void) const; DerivedVolumeType* mVolume; diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl index f4590196..b82aff5e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl @@ -21,6 +21,8 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +#include "PolyVoxCore\Impl\Utility.h" + namespace PolyVox { template @@ -145,63 +147,63 @@ namespace PolyVox template VoxelType BaseVolume::Sampler::peekVoxel1nx1ny1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume - 1); + return getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx1ny0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume ); + return getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx1ny1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume + 1); + return getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume + 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx0py1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume - 1); + return getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx0py0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume ); + return getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx0py1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume + 1); + return getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume + 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx1py1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume - 1); + return getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx1py0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume ); + return getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx1py1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume + 1); + return getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume + 1); } ////////////////////////////////////////////////////////////////////////// @@ -210,63 +212,63 @@ namespace PolyVox template VoxelType BaseVolume::Sampler::peekVoxel0px1ny1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume - 1); + return getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel0px1ny0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume ); + return getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel0px1ny1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume + 1); + return getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume + 1); } template template VoxelType BaseVolume::Sampler::peekVoxel0px0py1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume - 1); + return getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel0px0py0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume ); + return getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel0px0py1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume + 1); + return getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume + 1); } template template VoxelType BaseVolume::Sampler::peekVoxel0px1py1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume - 1); + return getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel0px1py0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume ); + return getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel0px1py1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume + 1); + return getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume + 1); } ////////////////////////////////////////////////////////////////////////// @@ -275,63 +277,102 @@ namespace PolyVox template VoxelType BaseVolume::Sampler::peekVoxel1px1ny1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume - 1); + return getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1px1ny0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume ); + return getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel1px1ny1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume + 1); + return getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume + 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1px0py1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume - 1); + return getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1px0py0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume ); + return getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel1px0py1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume + 1); + return getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume + 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1px1py1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume - 1); + return getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1px1py0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume ); + return getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel1px1py1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume + 1); + return getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume + 1); + } + + template + template + VoxelType BaseVolume::Sampler::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const + { + if(mVolume->getEnclosingRegion().containsPoint(uXPos, uYPos, uZPos)) + { + return mVolume->getVoxelAt(uXPos, uYPos, uZPos); + } + else + { + switch(m_eWrapMode) + { + case WrapModes::Clamp: + { + const Vector3DInt32& lowerCorner = mVolume->m_regValidRegion.getLowerCorner(); + const Vector3DInt32& upperCorner = mVolume->m_regValidRegion.getUpperCorner(); + + int32_t iClampedX = clamp(uXPos, lowerCorner.getX(), upperCorner.getX()); + int32_t iClampedY = clamp(uYPos, lowerCorner.getY(), upperCorner.getY()); + int32_t iClampedZ = clamp(uZPos, lowerCorner.getZ(), upperCorner.getZ()); + + return mVolume->getVoxelAt(iClampedX, iClampedY, iClampedZ); + //No need to break as we've returned + } + case WrapModes::Border: + { + return m_tBorder; + //No need to break as we've returned + } + default: + { + //Should never happen + assert(false); + return VoxelType(0); + } + } + } } template diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index a3660e7c..3c7a5c36 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -104,7 +104,6 @@ namespace PolyVox inline VoxelType peekVoxel1px1py1pz(void) const; private: - VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; //Other current position information VoxelType* mCurrentVoxel; diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index 290346a7..6dbffedd 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -21,8 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore\Impl\Utility.h" - #define CAN_GO_NEG_X(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) #define CAN_GO_POS_X(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) #define CAN_GO_NEG_Y(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) @@ -430,44 +428,6 @@ namespace PolyVox } return this->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1); } - - template - VoxelType RawVolume::Sampler::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const - { - if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) //Would be better if we didn't have to build the Vector but could pass seperate params. - { - return this->mVolume->getVoxelAt(uXPos, uYPos, uZPos); - } - else - { - switch(m_eWrapMode) - { - case WrapModes::Clamp: - { - const Vector3DInt32& lowerCorner = this->mVolume->m_regValidRegion.getLowerCorner(); - const Vector3DInt32& upperCorner = this->mVolume->m_regValidRegion.getUpperCorner(); - - int32_t iClampedX = clamp(uXPos, lowerCorner.getX(), upperCorner.getX()); - int32_t iClampedY = clamp(uYPos, lowerCorner.getY(), upperCorner.getY()); - int32_t iClampedZ = clamp(uZPos, lowerCorner.getZ(), upperCorner.getZ()); - - return this->mVolume->getVoxelAt(iClampedX, iClampedY, iClampedZ); - //No need to break as we've returned - } - case WrapModes::Border: - { - return this->m_tBorder; - //No need to break as we've returned - } - default: - { - //Should never happen - assert(false); - return VoxelType(0); - } - } - } - } } #undef CAN_GO_NEG_X