Improvements and fixes to RawVolume.
This commit is contained in:
parent
d4de479b7c
commit
e98e1c2a0d
@ -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
|
||||||
|
|
||||||
|
@ -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;
|
m_bIsCurrentPositionValid = mVolume->m_regValidRegion.containsPoint(Vector3DInt32(xPos, yPos, zPos));
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mCurrentVoxel = mVolume->m_tBorderValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void RawVolume<VoxelType>::Sampler::movePositiveX(void)
|
void RawVolume<VoxelType>::Sampler::movePositiveX(void)
|
||||||
{
|
{
|
||||||
mXPosInVolume++;
|
mXPosInVolume++;
|
||||||
|
++mCurrentVoxel;
|
||||||
if(mXPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getX())
|
m_bIsCurrentPositionValid = mXPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getX();
|
||||||
{
|
|
||||||
++mCurrentVoxel;
|
|
||||||
}
|
|
||||||
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++;
|
||||||
|
mCurrentVoxel += mVolume->getWidth();
|
||||||
if(mYPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getY())
|
m_bIsCurrentPositionValid = mYPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getY();
|
||||||
{
|
|
||||||
mCurrentVoxel += mVolume->getWidth();
|
|
||||||
}
|
|
||||||
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--;
|
||||||
|
mCurrentVoxel += mVolume->getWidth() * mVolume->getHeight();
|
||||||
if(mZPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getZ())
|
m_bIsCurrentPositionValid = mZPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getZ();
|
||||||
{
|
|
||||||
mCurrentVoxel += mVolume->getWidth() * mVolume->getHeight();
|
|
||||||
}
|
|
||||||
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--;
|
||||||
|
--mCurrentVoxel;
|
||||||
if(mXPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getX())
|
m_bIsCurrentPositionValid = mXPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getX();
|
||||||
{
|
|
||||||
--mCurrentVoxel;
|
|
||||||
}
|
|
||||||
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--;
|
||||||
|
mCurrentVoxel -= mVolume->getWidth();
|
||||||
if(mYPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getY())
|
m_bIsCurrentPositionValid = mYPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getY();
|
||||||
{
|
|
||||||
mCurrentVoxel -= mVolume->getWidth();
|
|
||||||
}
|
|
||||||
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--;
|
||||||
|
mCurrentVoxel -= mVolume->getWidth() * mVolume->getHeight();
|
||||||
if(mZPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getZ())
|
m_bIsCurrentPositionValid =mZPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getZ();
|
||||||
{
|
|
||||||
mCurrentVoxel -= mVolume->getWidth() * mVolume->getHeight();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//We've hit the volume boundary.
|
|
||||||
mCurrentVoxel = &mVolume->m_tBorderValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user