Added new accessors to volume. getVoxel() and getVoxelWithWrapping() will probably replace getVoxelAt, which will be deprecated.

This commit is contained in:
Daviw Williams
2012-12-06 16:17:21 +01:00
parent 93958998f6
commit d19f16ef64
9 changed files with 386 additions and 6 deletions

View File

@@ -73,6 +73,40 @@ namespace PolyVox
assert(false); // See function comment above.
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
{
assert(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)));
const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner();
int32_t iLocalXPos = uXPos - v3dLowerCorner.getX();
int32_t iLocalYPos = uYPos - v3dLowerCorner.getY();
int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ();
return m_pData
[
iLocalXPos +
iLocalYPos * this->getWidth() +
iLocalZPos * this->getWidth() * this->getHeight()
];
}
////////////////////////////////////////////////////////////////////////////////
/// \param v3dPos The 3D position of the voxel
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxel(const Vector3DInt32& v3dPos) const
{
return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
@@ -112,6 +146,62 @@ namespace PolyVox
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel
/// \param uZPos The \c z position of the voxel
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const
{
switch(eWrapMode)
{
case WrapModes::Clamp:
{
//Perform clamping
uXPos = (std::max)(uXPos, m_regValidRegion.getLowerX());
uYPos = (std::max)(uYPos, m_regValidRegion.getLowerY());
uZPos = (std::max)(uZPos, m_regValidRegion.getLowerZ());
uXPos = (std::min)(uXPos, m_regValidRegion.getUpperX());
uYPos = (std::min)(uYPos, m_regValidRegion.getUpperY());
uZPos = (std::min)(uZPos, m_regValidRegion.getUpperZ());
//Get the voxel value
return getVoxel(uXPos, uYPos, uZPos);
//No need to break as we've returned
}
case WrapModes::Border:
{
if(m_regValidRegion.containsPoint(uXPos, uYPos, uZPos))
{
return getVoxel(uXPos, uYPos, uZPos);
}
else
{
return tBorder;
}
//No need to break as we've returned
}
default:
{
//Should never happen
assert(false);
return VoxelType(0);
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// \param v3dPos The 3D position of the voxel
/// \return The voxel value
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const
{
return getVoxelWithWrapping(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder);
}
////////////////////////////////////////////////////////////////////////////////
/// \param uXPos the \c x position of the voxel
/// \param uYPos the \c y position of the voxel