Improvements and fixes to RawVolume.

This commit is contained in:
David Williams 2011-06-18 11:55:07 +01:00
parent d4de479b7c
commit e98e1c2a0d
2 changed files with 27 additions and 72 deletions

View File

@ -103,6 +103,9 @@ namespace PolyVox
//Other current position information //Other current position information
VoxelType* mCurrentVoxel; VoxelType* mCurrentVoxel;
//Whether the current position is inside the volume
bool m_bIsCurrentPositionValid;
}; };
#endif #endif

View File

@ -32,6 +32,11 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
RawVolume<VoxelType>::Sampler::Sampler(RawVolume<VoxelType>* volume) RawVolume<VoxelType>::Sampler::Sampler(RawVolume<VoxelType>* volume)
:mVolume(volume) :mVolume(volume)
,mXPosInVolume(0)
,mYPosInVolume(0)
,mZPosInVolume(0)
,mCurrentVoxel(0)
,m_bIsCurrentPositionValid(false)
{ {
} }
@ -82,7 +87,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
VoxelType RawVolume<VoxelType>::Sampler::getVoxel(void) const VoxelType RawVolume<VoxelType>::Sampler::getVoxel(void) const
{ {
return *mCurrentVoxel; return m_bIsCurrentPositionValid ? *mCurrentVoxel : mVolume->m_tBorderValue;
} }
template <typename VoxelType> template <typename VoxelType>
@ -98,114 +103,61 @@ namespace PolyVox
mYPosInVolume = yPos; mYPosInVolume = yPos;
mZPosInVolume = zPos; mZPosInVolume = zPos;
const uint32_t uVoxelIndex = uXPos + const uint32_t uVoxelIndex = xPos +
uYPos * mVolume->getWidth() + yPos * mVolume->getWidth() +
uZPos * mVolume->getWidth() * mVolume->getHeight(); zPos * mVolume->getWidth() * mVolume->getHeight();
if(mVolume->m_regValidRegionInBlocks.containsPoint(Vector3DInt32(uXBlock, uYBlock, uZBlock)))
{
mCurrentVoxel = mVolume->m_pData + uVoxelIndex; mCurrentVoxel = mVolume->m_pData + uVoxelIndex;
}
else m_bIsCurrentPositionValid = mVolume->m_regValidRegion.containsPoint(Vector3DInt32(xPos, yPos, zPos));
{
mCurrentVoxel = mVolume->m_tBorderValue;
}
} }
template <typename VoxelType> template <typename VoxelType>
void RawVolume<VoxelType>::Sampler::movePositiveX(void) void RawVolume<VoxelType>::Sampler::movePositiveX(void)
{ {
mXPosInVolume++; mXPosInVolume++;
if(mXPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getX())
{
++mCurrentVoxel; ++mCurrentVoxel;
} m_bIsCurrentPositionValid = mXPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getX();
else
{
//We've hit the volume boundary.
mCurrentVoxel = &mVolume->m_tBorderValue;
}
} }
template <typename VoxelType> template <typename VoxelType>
void RawVolume<VoxelType>::Sampler::movePositiveY(void) void RawVolume<VoxelType>::Sampler::movePositiveY(void)
{ {
mYPosInVolume++; mYPosInVolume++;
if(mYPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getY())
{
mCurrentVoxel += mVolume->getWidth(); mCurrentVoxel += mVolume->getWidth();
} m_bIsCurrentPositionValid = mYPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getY();
else
{
//We've hit the volume boundary.
mCurrentVoxel = &mVolume->m_tBorderValue;
}
} }
template <typename VoxelType> template <typename VoxelType>
void RawVolume<VoxelType>::Sampler::movePositiveZ(void) void RawVolume<VoxelType>::Sampler::movePositiveZ(void)
{ {
mZPosInVolume--; mZPosInVolume--;
if(mZPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getZ())
{
mCurrentVoxel += mVolume->getWidth() * mVolume->getHeight(); mCurrentVoxel += mVolume->getWidth() * mVolume->getHeight();
} m_bIsCurrentPositionValid = mZPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getZ();
else
{
//We've hit the volume boundary.
mCurrentVoxel = &mVolume->m_tBorderValue;
}
} }
template <typename VoxelType> template <typename VoxelType>
void RawVolume<VoxelType>::Sampler::moveNegativeX(void) void RawVolume<VoxelType>::Sampler::moveNegativeX(void)
{ {
mXPosInVolume--; mXPosInVolume--;
if(mXPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getX())
{
--mCurrentVoxel; --mCurrentVoxel;
} m_bIsCurrentPositionValid = mXPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getX();
else
{
//We've hit the volume boundary.
mCurrentVoxel = &mVolume->m_tBorderValue;
}
} }
template <typename VoxelType> template <typename VoxelType>
void RawVolume<VoxelType>::Sampler::moveNegativeY(void) void RawVolume<VoxelType>::Sampler::moveNegativeY(void)
{ {
mYPosInVolume--; mYPosInVolume--;
if(mYPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getY())
{
mCurrentVoxel -= mVolume->getWidth(); mCurrentVoxel -= mVolume->getWidth();
} m_bIsCurrentPositionValid = mYPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getY();
else
{
//We've hit the volume boundary.
mCurrentVoxel = &mVolume->m_tBorderValue;
}
} }
template <typename VoxelType> template <typename VoxelType>
void RawVolume<VoxelType>::Sampler::moveNegativeZ(void) void RawVolume<VoxelType>::Sampler::moveNegativeZ(void)
{ {
mZPosInVolume--; mZPosInVolume--;
if(mZPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getZ())
{
mCurrentVoxel -= mVolume->getWidth() * mVolume->getHeight(); mCurrentVoxel -= mVolume->getWidth() * mVolume->getHeight();
} m_bIsCurrentPositionValid =mZPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getZ();
else
{
//We've hit the volume boundary.
mCurrentVoxel = &mVolume->m_tBorderValue;
}
} }
template <typename VoxelType> template <typename VoxelType>