Moved some functionality into Sampler base class.
This commit is contained in:
parent
f310e51318
commit
ff3395643d
@ -109,6 +109,8 @@ namespace PolyVox
|
|||||||
inline VoxelType peekVoxel1px1py1pz(void) const;
|
inline VoxelType peekVoxel1px1py1pz(void) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool isCurrentPositionValid(void) const;
|
||||||
|
|
||||||
DerivedVolumeType* mVolume;
|
DerivedVolumeType* mVolume;
|
||||||
|
|
||||||
//The current position in the volume
|
//The current position in the volume
|
||||||
@ -118,6 +120,12 @@ namespace PolyVox
|
|||||||
|
|
||||||
WrapMode m_eWrapMode;
|
WrapMode m_eWrapMode;
|
||||||
VoxelType m_tBorder;
|
VoxelType m_tBorder;
|
||||||
|
|
||||||
|
//Whether the current position is inside the volume
|
||||||
|
//FIXME - Replace these with flags
|
||||||
|
bool m_bIsCurrentPositionValidInX;
|
||||||
|
bool m_bIsCurrentPositionValidInY;
|
||||||
|
bool m_bIsCurrentPositionValidInZ;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -32,6 +32,9 @@ namespace PolyVox
|
|||||||
,mZPosInVolume(0)
|
,mZPosInVolume(0)
|
||||||
,m_eWrapMode(WrapModes::Border)
|
,m_eWrapMode(WrapModes::Border)
|
||||||
,m_tBorder(0)
|
,m_tBorder(0)
|
||||||
|
,m_bIsCurrentPositionValidInX(false)
|
||||||
|
,m_bIsCurrentPositionValidInY(false)
|
||||||
|
,m_bIsCurrentPositionValidInZ(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,9 +62,7 @@ namespace PolyVox
|
|||||||
template <typename DerivedVolumeType>
|
template <typename DerivedVolumeType>
|
||||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::setPosition(const Vector3DInt32& v3dNewPos)
|
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::setPosition(const Vector3DInt32& v3dNewPos)
|
||||||
{
|
{
|
||||||
mXPosInVolume = v3dNewPos.getX();
|
setPosition(v3dNewPos.getX(), v3dNewPos.getY(), v3dNewPos.getZ());
|
||||||
mYPosInVolume = v3dNewPos.getY();
|
|
||||||
mZPosInVolume = v3dNewPos.getZ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
@ -71,6 +72,10 @@ namespace PolyVox
|
|||||||
mXPosInVolume = xPos;
|
mXPosInVolume = xPos;
|
||||||
mYPosInVolume = yPos;
|
mYPosInVolume = yPos;
|
||||||
mZPosInVolume = zPos;
|
mZPosInVolume = zPos;
|
||||||
|
|
||||||
|
m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(xPos);
|
||||||
|
m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(yPos);
|
||||||
|
m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(zPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
@ -93,6 +98,7 @@ namespace PolyVox
|
|||||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveX(void)
|
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveX(void)
|
||||||
{
|
{
|
||||||
mXPosInVolume++;
|
mXPosInVolume++;
|
||||||
|
m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(mXPosInVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
@ -100,6 +106,7 @@ namespace PolyVox
|
|||||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveY(void)
|
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveY(void)
|
||||||
{
|
{
|
||||||
mYPosInVolume++;
|
mYPosInVolume++;
|
||||||
|
m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(mYPosInVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
@ -107,6 +114,7 @@ namespace PolyVox
|
|||||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveZ(void)
|
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveZ(void)
|
||||||
{
|
{
|
||||||
mZPosInVolume++;
|
mZPosInVolume++;
|
||||||
|
m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(mZPosInVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
@ -114,6 +122,7 @@ namespace PolyVox
|
|||||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::moveNegativeX(void)
|
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::moveNegativeX(void)
|
||||||
{
|
{
|
||||||
mXPosInVolume--;
|
mXPosInVolume--;
|
||||||
|
m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(mXPosInVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
@ -121,6 +130,7 @@ namespace PolyVox
|
|||||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::moveNegativeY(void)
|
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::moveNegativeY(void)
|
||||||
{
|
{
|
||||||
mYPosInVolume--;
|
mYPosInVolume--;
|
||||||
|
m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(mYPosInVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
@ -128,6 +138,7 @@ namespace PolyVox
|
|||||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::moveNegativeZ(void)
|
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::moveNegativeZ(void)
|
||||||
{
|
{
|
||||||
mZPosInVolume--;
|
mZPosInVolume--;
|
||||||
|
m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(mZPosInVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
@ -322,4 +333,11 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume + 1);
|
return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename VoxelType>
|
||||||
|
template <typename DerivedVolumeType>
|
||||||
|
bool inline BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::isCurrentPositionValid(void) const
|
||||||
|
{
|
||||||
|
return m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,17 +105,9 @@ namespace PolyVox
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||||
bool isCurrentPositionValid(void) const;
|
|
||||||
|
|
||||||
|
|
||||||
//Other current position information
|
//Other current position information
|
||||||
VoxelType* mCurrentVoxel;
|
VoxelType* mCurrentVoxel;
|
||||||
|
|
||||||
//Whether the current position is inside the volume
|
|
||||||
//FIXME - Replace these with flags
|
|
||||||
bool m_bIsCurrentPositionValidInX;
|
|
||||||
bool m_bIsCurrentPositionValidInY;
|
|
||||||
bool m_bIsCurrentPositionValidInZ;
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -36,9 +36,6 @@ namespace PolyVox
|
|||||||
RawVolume<VoxelType>::Sampler::Sampler(RawVolume<VoxelType>* volume)
|
RawVolume<VoxelType>::Sampler::Sampler(RawVolume<VoxelType>* volume)
|
||||||
:BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >(volume)
|
:BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >(volume)
|
||||||
,mCurrentVoxel(0)
|
,mCurrentVoxel(0)
|
||||||
,m_bIsCurrentPositionValidInX(false)
|
|
||||||
,m_bIsCurrentPositionValidInY(false)
|
|
||||||
,m_bIsCurrentPositionValidInZ(false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,10 +66,10 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void RawVolume<VoxelType>::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos)
|
void RawVolume<VoxelType>::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos)
|
||||||
{
|
{
|
||||||
this->mXPosInVolume = xPos;
|
// Base version updates position and validity flags.
|
||||||
this->mYPosInVolume = yPos;
|
BaseVolume<VoxelType>::Sampler< RawVolume<VoxelType> >::setPosition(xPos, yPos, zPos);
|
||||||
this->mZPosInVolume = zPos;
|
|
||||||
|
|
||||||
|
// Then we update the voxel pointer
|
||||||
const Vector3DInt32& v3dLowerCorner = this->mVolume->m_regValidRegion.getLowerCorner();
|
const Vector3DInt32& v3dLowerCorner = this->mVolume->m_regValidRegion.getLowerCorner();
|
||||||
int32_t iLocalXPos = xPos - v3dLowerCorner.getX();
|
int32_t iLocalXPos = xPos - v3dLowerCorner.getX();
|
||||||
int32_t iLocalYPos = yPos - v3dLowerCorner.getY();
|
int32_t iLocalYPos = yPos - v3dLowerCorner.getY();
|
||||||
@ -83,10 +80,6 @@ namespace PolyVox
|
|||||||
iLocalZPos * this->mVolume->getWidth() * this->mVolume->getHeight();
|
iLocalZPos * this->mVolume->getWidth() * this->mVolume->getHeight();
|
||||||
|
|
||||||
mCurrentVoxel = this->mVolume->m_pData + uVoxelIndex;
|
mCurrentVoxel = this->mVolume->m_pData + uVoxelIndex;
|
||||||
|
|
||||||
m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(xPos);
|
|
||||||
m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(yPos);
|
|
||||||
m_bIsCurrentPositionValidInZ = this->mVolume->getEnclosingRegion().containsPointInZ(zPos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
@ -107,49 +100,61 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void RawVolume<VoxelType>::Sampler::movePositiveX(void)
|
void RawVolume<VoxelType>::Sampler::movePositiveX(void)
|
||||||
{
|
{
|
||||||
this->mXPosInVolume++;
|
// Base version updates position and validity flags.
|
||||||
|
BaseVolume<VoxelType>::Sampler< RawVolume<VoxelType> >::movePositiveX();
|
||||||
|
|
||||||
|
// Then we update the voxel pointer
|
||||||
++mCurrentVoxel;
|
++mCurrentVoxel;
|
||||||
m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(this->mXPosInVolume);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void RawVolume<VoxelType>::Sampler::movePositiveY(void)
|
void RawVolume<VoxelType>::Sampler::movePositiveY(void)
|
||||||
{
|
{
|
||||||
this->mYPosInVolume++;
|
// Base version updates position and validity flags.
|
||||||
|
BaseVolume<VoxelType>::Sampler< RawVolume<VoxelType> >::movePositiveY();
|
||||||
|
|
||||||
|
// Then we update the voxel pointer
|
||||||
mCurrentVoxel += this->mVolume->getWidth();
|
mCurrentVoxel += this->mVolume->getWidth();
|
||||||
m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(this->mYPosInVolume);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void RawVolume<VoxelType>::Sampler::movePositiveZ(void)
|
void RawVolume<VoxelType>::Sampler::movePositiveZ(void)
|
||||||
{
|
{
|
||||||
this->mZPosInVolume++;
|
// Base version updates position and validity flags.
|
||||||
|
BaseVolume<VoxelType>::Sampler< RawVolume<VoxelType> >::movePositiveZ();
|
||||||
|
|
||||||
|
// Then we update the voxel pointer
|
||||||
mCurrentVoxel += this->mVolume->getWidth() * this->mVolume->getHeight();
|
mCurrentVoxel += this->mVolume->getWidth() * this->mVolume->getHeight();
|
||||||
m_bIsCurrentPositionValidInZ = this->mVolume->getEnclosingRegion().containsPointInZ(this->mZPosInVolume);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void RawVolume<VoxelType>::Sampler::moveNegativeX(void)
|
void RawVolume<VoxelType>::Sampler::moveNegativeX(void)
|
||||||
{
|
{
|
||||||
this->mXPosInVolume--;
|
// Base version updates position and validity flags.
|
||||||
|
BaseVolume<VoxelType>::Sampler< RawVolume<VoxelType> >::moveNegativeX();
|
||||||
|
|
||||||
|
// Then we update the voxel pointer
|
||||||
--mCurrentVoxel;
|
--mCurrentVoxel;
|
||||||
m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(this->mXPosInVolume);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void RawVolume<VoxelType>::Sampler::moveNegativeY(void)
|
void RawVolume<VoxelType>::Sampler::moveNegativeY(void)
|
||||||
{
|
{
|
||||||
this->mYPosInVolume--;
|
// Base version updates position and validity flags.
|
||||||
|
BaseVolume<VoxelType>::Sampler< RawVolume<VoxelType> >::moveNegativeY();
|
||||||
|
|
||||||
|
// Then we update the voxel pointer
|
||||||
mCurrentVoxel -= this->mVolume->getWidth();
|
mCurrentVoxel -= this->mVolume->getWidth();
|
||||||
m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(this->mYPosInVolume);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void RawVolume<VoxelType>::Sampler::moveNegativeZ(void)
|
void RawVolume<VoxelType>::Sampler::moveNegativeZ(void)
|
||||||
{
|
{
|
||||||
this->mZPosInVolume--;
|
// Base version updates position and validity flags.
|
||||||
|
BaseVolume<VoxelType>::Sampler< RawVolume<VoxelType> >::moveNegativeZ();
|
||||||
|
|
||||||
|
// Then we update the voxel pointer
|
||||||
mCurrentVoxel -= this->mVolume->getWidth() * this->mVolume->getHeight();
|
mCurrentVoxel -= this->mVolume->getWidth() * this->mVolume->getHeight();
|
||||||
m_bIsCurrentPositionValidInZ = this->mVolume->getEnclosingRegion().containsPointInZ(this->mZPosInVolume);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
@ -463,12 +468,6 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
|
||||||
bool RawVolume<VoxelType>::Sampler::isCurrentPositionValid(void) const
|
|
||||||
{
|
|
||||||
return m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef CAN_GO_NEG_X
|
#undef CAN_GO_NEG_X
|
||||||
|
Loading…
x
Reference in New Issue
Block a user