diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index 1c417eb4..d9bde4a7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -38,14 +38,12 @@ namespace PolyVox { public: #ifndef SWIG - class Sampler + class Sampler : public Volume::Sampler { public: Sampler(RawVolume* volume); ~Sampler(); - Sampler& operator=(const Sampler& rhs) throw(); - int32_t getPosX(void) const; int32_t getPosY(void) const; int32_t getPosZ(void) const; @@ -95,18 +93,18 @@ namespace PolyVox private: //The current volume - RawVolume* mVolume; + RawVolume* mRawVolume; //The current position in the volume - int32_t mXPosInVolume; + /*int32_t mXPosInVolume; int32_t mYPosInVolume; - int32_t mZPosInVolume; + int32_t mZPosInVolume;*/ //Other current position information VoxelType* mCurrentVoxel; //Whether the current position is inside the volume - bool m_bIsCurrentPositionValid; + //bool m_bIsCurrentPositionValid; }; #endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index 570ea47a..b5f10b37 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -31,12 +31,13 @@ namespace PolyVox { template RawVolume::Sampler::Sampler(RawVolume* volume) - :mVolume(volume) - ,mXPosInVolume(0) - ,mYPosInVolume(0) - ,mZPosInVolume(0) + :Volume::Sampler(volume) + //,mXPosInVolume(0) + //,mYPosInVolume(0) + //,mZPosInVolume(0) + ,mRawVolume(volume) ,mCurrentVoxel(0) - ,m_bIsCurrentPositionValid(false) + //,m_bIsCurrentPositionValid(false) { } @@ -45,21 +46,6 @@ namespace PolyVox { } - template - typename RawVolume::Sampler& RawVolume::Sampler::operator=(const typename RawVolume::Sampler& rhs) throw() - { - if(this == &rhs) - { - return *this; - } - mVolume = rhs.mVolume; - mXPosInVolume = rhs.mXPosInVolume; - mYPosInVolume = rhs.mYPosInVolume; - mZPosInVolume = rhs.mZPosInVolume; - mCurrentVoxel = rhs.mCurrentVoxel; - return *this; - } - template int32_t RawVolume::Sampler::getPosX(void) const { @@ -87,7 +73,7 @@ namespace PolyVox template VoxelType RawVolume::Sampler::getVoxel(void) const { - return m_bIsCurrentPositionValid ? *mCurrentVoxel : mVolume->m_tBorderValue; + return m_bIsCurrentPositionValid ? *mCurrentVoxel : mVolume->getBorderValue(); } template @@ -107,9 +93,9 @@ namespace PolyVox yPos * mVolume->getWidth() + zPos * mVolume->getWidth() * mVolume->getHeight(); - mCurrentVoxel = mVolume->m_pData + uVoxelIndex; + mCurrentVoxel = mRawVolume->m_pData + uVoxelIndex; - m_bIsCurrentPositionValid = mVolume->m_regValidRegion.containsPoint(Vector3DInt32(xPos, yPos, zPos)); + m_bIsCurrentPositionValid = mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos)); } template @@ -131,7 +117,7 @@ namespace PolyVox template void RawVolume::Sampler::movePositiveZ(void) { - mZPosInVolume--; + mZPosInVolume++; mCurrentVoxel += mVolume->getWidth() * mVolume->getHeight(); m_bIsCurrentPositionValid = mZPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getZ(); } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Volume.h b/library/PolyVoxCore/include/PolyVoxCore/Volume.h index 855d1173..4ffe5046 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Volume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Volume.h @@ -35,6 +35,75 @@ namespace PolyVox template class Volume { + public: + #ifndef SWIG + class Sampler + { + public: + Sampler(Volume* volume); + ~Sampler(); + + int32_t getPosX(void) const; + int32_t getPosY(void) const; + int32_t getPosZ(void) const; + const Volume* getVolume(void) const; + inline VoxelType getVoxel(void) const; + + void setPosition(const Vector3DInt32& v3dNewPos); + void setPosition(int32_t xPos, int32_t yPos, int32_t zPos); + + void movePositiveX(void); + void movePositiveY(void); + void movePositiveZ(void); + + void moveNegativeX(void); + void moveNegativeY(void); + void moveNegativeZ(void); + + 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; + + 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; + + 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; + + protected: + //The current volume + Volume* mVolume; + + //The current position in the volume + int32_t mXPosInVolume; + int32_t mYPosInVolume; + int32_t mZPosInVolume; + + //Whether the current position is inside the volume + bool m_bIsCurrentPositionValid; + }; + #endif + public: /// Constructor for creating a fixed size volume. Volume @@ -46,7 +115,7 @@ namespace PolyVox /// Gets the value used for voxels which are outside the volume VoxelType getBorderValue(void) const; - /// Gets a Region representing the extents of the RawVolume. + /// Gets a Region representing the extents of the Volume. Region getEnclosingRegion(void) const; /// Gets the width of the volume in voxels. int32_t getWidth(void) const; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Volume.inl b/library/PolyVoxCore/include/PolyVoxCore/Volume.inl index 2b2251cc..5dd05be7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Volume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Volume.inl @@ -140,7 +140,7 @@ namespace PolyVox VoxelType Volume::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const { assert(false); - return VoxelType; //Default constructor + return VoxelType(); } //////////////////////////////////////////////////////////////////////////////// @@ -151,7 +151,7 @@ namespace PolyVox VoxelType Volume::getVoxelAt(const Vector3DInt32& v3dPos) const { assert(false); - return VoxelType; //Default constructor + return VoxelType(); } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl index e69de29b..2638561a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl @@ -0,0 +1,304 @@ +/******************************************************************************* +Copyright (c) 2005-2009 David Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#include "PolyVoxImpl/Block.h" +#include "PolyVoxCore/Volume.h" +#include "PolyVoxCore/Vector.h" +#include "PolyVoxCore/Region.h" + +#include +namespace PolyVox +{ + template + Volume::Sampler::Sampler(Volume* volume) + :mVolume(volume) + ,mXPosInVolume(0) + ,mYPosInVolume(0) + ,mZPosInVolume(0) + ,m_bIsCurrentPositionValid(false) + { + } + + template + Volume::Sampler::~Sampler() + { + } + + template + int32_t Volume::Sampler::getPosX(void) const + { + return mXPosInVolume; + } + + template + int32_t Volume::Sampler::getPosY(void) const + { + return mYPosInVolume; + } + + template + int32_t Volume::Sampler::getPosZ(void) const + { + return mZPosInVolume; + } + + template + const Volume* Volume::Sampler::getVolume(void) const + { + return mVolume; + } + + template + VoxelType Volume::Sampler::getVoxel(void) const + { + return m_bIsCurrentPositionValid ? mVolume->getVoxelAt(mXPosInVolume, mYPosInVolume, mZPosInVolume) : mVolume->m_tBorderValue; + } + + template + void Volume::Sampler::setPosition(const Vector3DInt32& v3dNewPos) + { + setPosition(v3dNewPos.getX(), v3dNewPos.getY(), v3dNewPos.getZ()); + } + + template + void Volume::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos) + { + mXPosInVolume = xPos; + mYPosInVolume = yPos; + mZPosInVolume = zPos; + + const uint32_t uVoxelIndex = xPos + + yPos * mVolume->getWidth() + + zPos * mVolume->getWidth() * mVolume->getHeight(); + + m_bIsCurrentPositionValid = mVolume->m_regValidRegion.containsPoint(Vector3DInt32(xPos, yPos, zPos)); + } + + template + void Volume::Sampler::movePositiveX(void) + { + mXPosInVolume++; + m_bIsCurrentPositionValid = mXPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getX(); + } + + template + void Volume::Sampler::movePositiveY(void) + { + mYPosInVolume++; + m_bIsCurrentPositionValid = mYPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getY(); + } + + template + void Volume::Sampler::movePositiveZ(void) + { + mZPosInVolume++; + m_bIsCurrentPositionValid = mZPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getZ(); + } + + template + void Volume::Sampler::moveNegativeX(void) + { + mXPosInVolume--; + m_bIsCurrentPositionValid = mXPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getX(); + } + + template + void Volume::Sampler::moveNegativeY(void) + { + mYPosInVolume--; + m_bIsCurrentPositionValid = mYPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getY(); + } + + template + void Volume::Sampler::moveNegativeZ(void) + { + mZPosInVolume--; + m_bIsCurrentPositionValid =mZPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getZ(); + } + + template + VoxelType Volume::Sampler::peekVoxel1nx1ny1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume-1); + } + + template + VoxelType Volume::Sampler::peekVoxel1nx1ny0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume); + } + + template + VoxelType Volume::Sampler::peekVoxel1nx1ny1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume+1); + } + + template + VoxelType Volume::Sampler::peekVoxel1nx0py1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume-1); + } + + template + VoxelType Volume::Sampler::peekVoxel1nx0py0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume); + } + + template + VoxelType Volume::Sampler::peekVoxel1nx0py1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume+1); + } + + template + VoxelType Volume::Sampler::peekVoxel1nx1py1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume-1); + } + + template + VoxelType Volume::Sampler::peekVoxel1nx1py0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume); + } + + template + VoxelType Volume::Sampler::peekVoxel1nx1py1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume+1); + } + + ////////////////////////////////////////////////////////////////////////// + + template + VoxelType Volume::Sampler::peekVoxel0px1ny1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume-1); + } + + template + VoxelType Volume::Sampler::peekVoxel0px1ny0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume); + } + + template + VoxelType Volume::Sampler::peekVoxel0px1ny1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume+1); + } + + template + VoxelType Volume::Sampler::peekVoxel0px0py1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume,mZPosInVolume-1); + } + + template + VoxelType Volume::Sampler::peekVoxel0px0py0pz(void) const + { + return *mCurrentVoxel; + } + + template + VoxelType Volume::Sampler::peekVoxel0px0py1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume,mZPosInVolume+1); + } + + template + VoxelType Volume::Sampler::peekVoxel0px1py1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume-1); + } + + template + VoxelType Volume::Sampler::peekVoxel0px1py0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume); + } + + template + VoxelType Volume::Sampler::peekVoxel0px1py1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume+1); + } + + ////////////////////////////////////////////////////////////////////////// + + template + VoxelType Volume::Sampler::peekVoxel1px1ny1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume-1); + } + + template + VoxelType Volume::Sampler::peekVoxel1px1ny0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume); + } + + template + VoxelType Volume::Sampler::peekVoxel1px1ny1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume+1); + } + + template + VoxelType Volume::Sampler::peekVoxel1px0py1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume-1); + } + + template + VoxelType Volume::Sampler::peekVoxel1px0py0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume); + } + + template + VoxelType Volume::Sampler::peekVoxel1px0py1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume+1); + } + + template + VoxelType Volume::Sampler::peekVoxel1px1py1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume-1); + } + + template + VoxelType Volume::Sampler::peekVoxel1px1py0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume); + } + + template + VoxelType Volume::Sampler::peekVoxel1px1py1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume+1); + } +}