Added setWrapMode to BaseVolume::Sampler.
Added initial border/clamping to RawVolumeSampler.
This commit is contained in:
parent
7636b6fb55
commit
c98f65c9a5
@ -38,6 +38,16 @@ namespace PolyVox
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// More details to come...
|
/// More details to come...
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
namespace WrapModes
|
||||||
|
{
|
||||||
|
enum WrapMode
|
||||||
|
{
|
||||||
|
Clamp = 0,
|
||||||
|
Border = 1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
typedef WrapModes::WrapMode WrapMode;
|
||||||
|
|
||||||
template <typename _VoxelType>
|
template <typename _VoxelType>
|
||||||
class BaseVolume
|
class BaseVolume
|
||||||
{
|
{
|
||||||
@ -58,6 +68,7 @@ namespace PolyVox
|
|||||||
void setPosition(const Vector3DInt32& v3dNewPos);
|
void setPosition(const Vector3DInt32& v3dNewPos);
|
||||||
void setPosition(int32_t xPos, int32_t yPos, int32_t zPos);
|
void setPosition(int32_t xPos, int32_t yPos, int32_t zPos);
|
||||||
inline bool setVoxel(VoxelType tValue);
|
inline bool setVoxel(VoxelType tValue);
|
||||||
|
void setWrapMode(WrapMode eWrapMode, VoxelType tBorder = VoxelType(0));
|
||||||
|
|
||||||
void movePositiveX(void);
|
void movePositiveX(void);
|
||||||
void movePositiveY(void);
|
void movePositiveY(void);
|
||||||
@ -104,6 +115,9 @@ namespace PolyVox
|
|||||||
int32_t mXPosInVolume;
|
int32_t mXPosInVolume;
|
||||||
int32_t mYPosInVolume;
|
int32_t mYPosInVolume;
|
||||||
int32_t mZPosInVolume;
|
int32_t mZPosInVolume;
|
||||||
|
|
||||||
|
WrapMode m_eWrapMode;
|
||||||
|
VoxelType m_tBorder;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -30,6 +30,8 @@ namespace PolyVox
|
|||||||
,mXPosInVolume(0)
|
,mXPosInVolume(0)
|
||||||
,mYPosInVolume(0)
|
,mYPosInVolume(0)
|
||||||
,mZPosInVolume(0)
|
,mZPosInVolume(0)
|
||||||
|
,m_eWrapMode(WrapModes::Clamp/*CHANGE*/) //FIXME - Default to border as it's faster?
|
||||||
|
,m_tBorder(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +80,14 @@ namespace PolyVox
|
|||||||
return mVolume->setVoxelAt(mXPosInVolume, mYPosInVolume, mZPosInVolume, tValue);
|
return mVolume->setVoxelAt(mXPosInVolume, mYPosInVolume, mZPosInVolume, tValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename VoxelType>
|
||||||
|
template <typename DerivedVolumeType>
|
||||||
|
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::setWrapMode(WrapMode eWrapMode, VoxelType tBorder)
|
||||||
|
{
|
||||||
|
m_eWrapMode = eWrapMode;
|
||||||
|
m_tBorder = tBorder;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
template <typename DerivedVolumeType>
|
template <typename DerivedVolumeType>
|
||||||
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveX(void)
|
void BaseVolume<VoxelType>::Sampler<DerivedVolumeType>::movePositiveX(void)
|
||||||
|
@ -35,6 +35,8 @@ namespace PolyVox
|
|||||||
|
|
||||||
int32_t roundTowardsNegInf(float r);
|
int32_t roundTowardsNegInf(float r);
|
||||||
int32_t roundToInteger(float r);
|
int32_t roundToInteger(float r);
|
||||||
|
template <typename Type>
|
||||||
|
Type clamp(const Type& value, const Type& low, const Type& high);
|
||||||
|
|
||||||
inline int32_t roundTowardsNegInf(float r)
|
inline int32_t roundTowardsNegInf(float r)
|
||||||
{
|
{
|
||||||
@ -45,6 +47,12 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
return (r > 0.0) ? static_cast<int32_t>(r + 0.5f) : static_cast<int32_t>(r - 0.5f);
|
return (r > 0.0) ? static_cast<int32_t>(r + 0.5f) : static_cast<int32_t>(r - 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Type>
|
||||||
|
inline Type clamp(const Type& value, const Type& low, const Type& high)
|
||||||
|
{
|
||||||
|
return std::min(high, std::max(low, value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -42,6 +42,10 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MaterialDensityPair() : m_uMaterial(0), m_uDensity(0) {}
|
MaterialDensityPair() : m_uMaterial(0), m_uDensity(0) {}
|
||||||
|
|
||||||
|
// FIXME - This is a bit odd... we need to allow the MaterialDensityPair to be initialised with a single integer
|
||||||
|
// and PolyVox often initialises voxels by calling VoxelType(0). Is there a better way we should handle this?
|
||||||
|
MaterialDensityPair(Type tValue) : m_uMaterial(tValue), m_uDensity(tValue) {}
|
||||||
MaterialDensityPair(Type uMaterial, Type uDensity) : m_uMaterial(uMaterial), m_uDensity(uDensity) {}
|
MaterialDensityPair(Type uMaterial, Type uDensity) : m_uMaterial(uMaterial), m_uDensity(uDensity) {}
|
||||||
|
|
||||||
bool operator==(const MaterialDensityPair& rhs) const
|
bool operator==(const MaterialDensityPair& rhs) const
|
||||||
|
@ -104,6 +104,10 @@ namespace PolyVox
|
|||||||
inline VoxelType peekVoxel1px1py1pz(void) const;
|
inline VoxelType peekVoxel1px1py1pz(void) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
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;
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@ freely, subject to the following restrictions:
|
|||||||
distribution.
|
distribution.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "PolyVoxCore\Impl\Utility.h"
|
||||||
|
|
||||||
#define BORDER_LOWX(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getX())
|
#define BORDER_LOWX(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getX())
|
||||||
#define BORDER_HIGHX(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getX())
|
#define BORDER_HIGHX(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getX())
|
||||||
#define BORDER_LOWY(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getY())
|
#define BORDER_LOWY(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getY())
|
||||||
@ -48,7 +50,14 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::getVoxel(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::getVoxel(void) const
|
||||||
{
|
{
|
||||||
return (m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ) ? *mCurrentVoxel : this->mVolume->getBorderValue();
|
if(isCurrentPositionValid())
|
||||||
|
{
|
||||||
|
return *mCurrentVoxel;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return getVoxelAt(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
@ -146,91 +155,91 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1ny1nz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1ny1nz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel - 1 - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel - 1 - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1);
|
return this->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1ny0pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1ny0pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel - 1 - this->mVolume->getWidth());
|
return *(mCurrentVoxel - 1 - this->mVolume->getWidth());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume);
|
return this->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1ny1pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1ny1pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel - 1 - this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel - 1 - this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1);
|
return this->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx0py1nz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx0py1nz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel - 1 - this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel - 1 - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1);
|
return this->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx0py0pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx0py0pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_LOWX(this->mXPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_LOWX(this->mXPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel - 1);
|
return *(mCurrentVoxel - 1);
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume);
|
return this->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx0py1pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx0py1pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel - 1 + this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel - 1 + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1);
|
return this->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1py1nz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1py1nz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel - 1 + this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel - 1 + this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1);
|
return this->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1py0pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1py0pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel - 1 + this->mVolume->getWidth());
|
return *(mCurrentVoxel - 1 + this->mVolume->getWidth());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume);
|
return this->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1py1pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1py1pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel - 1 + this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel - 1 + this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1);
|
return this->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@ -238,87 +247,91 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1ny1nz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1ny1nz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_LOWX(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_LOWX(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1);
|
return this->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1ny0pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1ny0pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_LOWY(this->mYPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_LOWY(this->mYPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel - this->mVolume->getWidth());
|
return *(mCurrentVoxel - this->mVolume->getWidth());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume);
|
return this->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1ny1pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1ny1pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_LOWY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_LOWY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel - this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel - this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1);
|
return this->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px0py1nz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px0py1nz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_LOWZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_LOWZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel - this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1);
|
return this->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px0py0pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px0py0pz(void) const
|
||||||
|
{
|
||||||
|
if((this->isCurrentPositionValid()))
|
||||||
{
|
{
|
||||||
return *mCurrentVoxel;
|
return *mCurrentVoxel;
|
||||||
}
|
}
|
||||||
|
return this->getVoxelAt(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px0py1pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px0py1pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_HIGHZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_HIGHZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel + this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1);
|
return this->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1py1nz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1py1nz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_HIGHY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel + this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel + this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1);
|
return this->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1py0pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1py0pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_HIGHY(this->mYPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_HIGHY(this->mYPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel + this->mVolume->getWidth());
|
return *(mCurrentVoxel + this->mVolume->getWidth());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume);
|
return this->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1py1pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1py1pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_HIGHY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel + this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel + this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1);
|
return this->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@ -326,91 +339,135 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1ny1nz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1ny1nz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel + 1 - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel + 1 - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1);
|
return this->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1ny0pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1ny0pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel + 1 - this->mVolume->getWidth());
|
return *(mCurrentVoxel + 1 - this->mVolume->getWidth());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume);
|
return this->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1ny1pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1ny1pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel + 1 - this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel + 1 - this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1);
|
return this->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px0py1nz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px0py1nz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel + 1 - this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel + 1 - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1);
|
return this->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px0py0pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px0py0pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_HIGHX(this->mXPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_HIGHX(this->mXPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel + 1);
|
return *(mCurrentVoxel + 1);
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume);
|
return this->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px0py1pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px0py1pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel + 1 + this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel + 1 + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1);
|
return this->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1py1nz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1py1nz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel + 1 + this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel + 1 + this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1);
|
return this->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1py0pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1py0pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel + 1 + this->mVolume->getWidth());
|
return *(mCurrentVoxel + 1 + this->mVolume->getWidth());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume);
|
return this->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1py1pz(void) const
|
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1py1pz(void) const
|
||||||
{
|
{
|
||||||
if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
if((this->isCurrentPositionValid()) && BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
|
||||||
{
|
{
|
||||||
return *(mCurrentVoxel + 1 + this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
return *(mCurrentVoxel + 1 + this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
|
||||||
}
|
}
|
||||||
return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1);
|
return this->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename VoxelType>
|
||||||
|
VoxelType RawVolume<VoxelType>::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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename VoxelType>
|
||||||
|
bool RawVolume<VoxelType>::Sampler::isCurrentPositionValid(void) const
|
||||||
|
{
|
||||||
|
return m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user