Added new accessors to volume. getVoxel() and getVoxelWithWrapping() will probably replace getVoxelAt, which will be deprecated.
This commit is contained in:
parent
93958998f6
commit
d19f16ef64
@ -149,9 +149,17 @@ namespace PolyVox
|
|||||||
/// Gets the length of the diagonal in voxels
|
/// Gets the length of the diagonal in voxels
|
||||||
float getDiagonalLength(void) const;
|
float getDiagonalLength(void) const;
|
||||||
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||||
|
VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||||
|
/// Gets a voxel at the position given by a 3D vector
|
||||||
|
VoxelType getVoxel(const Vector3DInt32& v3dPos) const;
|
||||||
|
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||||
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||||
/// Gets a voxel at the position given by a 3D vector
|
/// Gets a voxel at the position given by a 3D vector
|
||||||
VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
|
VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
|
||||||
|
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||||
|
VoxelType getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType(0)) const;
|
||||||
|
/// Gets a voxel at the position given by a 3D vector
|
||||||
|
VoxelType getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType(0)) const;
|
||||||
|
|
||||||
/// Sets the value used for voxels which are outside the volume
|
/// Sets the value used for voxels which are outside the volume
|
||||||
void setBorderValue(const VoxelType& tBorder);
|
void setBorderValue(const VoxelType& tBorder);
|
||||||
|
@ -153,6 +153,30 @@ namespace PolyVox
|
|||||||
return m_fDiagonalLength;
|
return m_fDiagonalLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// \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 BaseVolume<VoxelType>::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/) const
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
return VoxelType();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// \param v3dPos The 3D position of the voxel
|
||||||
|
/// \return The voxel value
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename VoxelType>
|
||||||
|
VoxelType BaseVolume<VoxelType>::getVoxel(const Vector3DInt32& /*v3dPos*/) const
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
return VoxelType();
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// \param uXPos The \c x position of the voxel
|
/// \param uXPos The \c x position of the voxel
|
||||||
/// \param uYPos The \c y position of the voxel
|
/// \param uYPos The \c y position of the voxel
|
||||||
@ -177,6 +201,30 @@ namespace PolyVox
|
|||||||
return VoxelType();
|
return VoxelType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// \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 BaseVolume<VoxelType>::getVoxelWithWrapping(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
return VoxelType();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// \param v3dPos The 3D position of the voxel
|
||||||
|
/// \return The voxel value
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename VoxelType>
|
||||||
|
VoxelType BaseVolume<VoxelType>::getVoxelWithWrapping(const Vector3DInt32& /*v3dPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
return VoxelType();
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// \param tBorder The value to use for voxels outside the volume.
|
/// \param tBorder The value to use for voxels outside the volume.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -267,10 +267,18 @@ namespace PolyVox
|
|||||||
/// Destructor
|
/// Destructor
|
||||||
~LargeVolume();
|
~LargeVolume();
|
||||||
|
|
||||||
|
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||||
|
VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||||
|
/// Gets a voxel at the position given by a 3D vector
|
||||||
|
VoxelType getVoxel(const Vector3DInt32& v3dPos) const;
|
||||||
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||||
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||||
/// Gets a voxel at the position given by a 3D vector
|
/// Gets a voxel at the position given by a 3D vector
|
||||||
VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
|
VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
|
||||||
|
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||||
|
VoxelType getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType(0)) const;
|
||||||
|
/// Gets a voxel at the position given by a 3D vector
|
||||||
|
VoxelType getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType(0)) const;
|
||||||
|
|
||||||
//Sets whether or not blocks are compressed in memory
|
//Sets whether or not blocks are compressed in memory
|
||||||
void setCompressionEnabled(bool bCompressionEnabled);
|
void setCompressionEnabled(bool bCompressionEnabled);
|
||||||
|
@ -110,6 +110,40 @@ namespace PolyVox
|
|||||||
assert(false); // See function comment above.
|
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 LargeVolume<VoxelType>::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
|
||||||
|
{
|
||||||
|
assert(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)));
|
||||||
|
|
||||||
|
const int32_t blockX = uXPos >> m_uBlockSideLengthPower;
|
||||||
|
const int32_t blockY = uYPos >> m_uBlockSideLengthPower;
|
||||||
|
const int32_t blockZ = uZPos >> m_uBlockSideLengthPower;
|
||||||
|
|
||||||
|
const uint16_t xOffset = static_cast<uint16_t>(uXPos - (blockX << m_uBlockSideLengthPower));
|
||||||
|
const uint16_t yOffset = static_cast<uint16_t>(uYPos - (blockY << m_uBlockSideLengthPower));
|
||||||
|
const uint16_t zOffset = static_cast<uint16_t>(uZPos - (blockZ << m_uBlockSideLengthPower));
|
||||||
|
|
||||||
|
Block<VoxelType>* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ);
|
||||||
|
|
||||||
|
return pUncompressedBlock->getVoxelAt(xOffset,yOffset,zOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// \param v3dPos The 3D position of the voxel
|
||||||
|
/// \return The voxel value
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename VoxelType>
|
||||||
|
VoxelType LargeVolume<VoxelType>::getVoxel(const Vector3DInt32& v3dPos) const
|
||||||
|
{
|
||||||
|
return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// \param uXPos The \c x position of the voxel
|
/// \param uXPos The \c x position of the voxel
|
||||||
/// \param uYPos The \c y position of the voxel
|
/// \param uYPos The \c y position of the voxel
|
||||||
@ -149,6 +183,62 @@ namespace PolyVox
|
|||||||
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
|
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 LargeVolume<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 LargeVolume<VoxelType>::getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const
|
||||||
|
{
|
||||||
|
return getVoxelWithWrapping(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// Enabling compression allows significantly more data to be stored in memory.
|
/// Enabling compression allows significantly more data to be stored in memory.
|
||||||
/// \param bCompressionEnabled Specifies whether compression is enabled.
|
/// \param bCompressionEnabled Specifies whether compression is enabled.
|
||||||
|
@ -117,10 +117,18 @@ namespace PolyVox
|
|||||||
/// Destructor
|
/// Destructor
|
||||||
~RawVolume();
|
~RawVolume();
|
||||||
|
|
||||||
|
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||||
|
VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||||
|
/// Gets a voxel at the position given by a 3D vector
|
||||||
|
VoxelType getVoxel(const Vector3DInt32& v3dPos) const;
|
||||||
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||||
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||||
/// Gets a voxel at the position given by a 3D vector
|
/// Gets a voxel at the position given by a 3D vector
|
||||||
VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
|
VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
|
||||||
|
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||||
|
VoxelType getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType(0)) const;
|
||||||
|
/// Gets a voxel at the position given by a 3D vector
|
||||||
|
VoxelType getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType(0)) const;
|
||||||
|
|
||||||
/// Sets the voxel at the position given by <tt>x,y,z</tt> coordinates
|
/// Sets the voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||||
bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue);
|
bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue);
|
||||||
|
@ -73,6 +73,40 @@ namespace PolyVox
|
|||||||
assert(false); // See function comment above.
|
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 uXPos The \c x position of the voxel
|
||||||
/// \param uYPos The \c y 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());
|
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 uXPos the \c x position of the voxel
|
||||||
/// \param uYPos the \c y position of the voxel
|
/// \param uYPos the \c y position of the voxel
|
||||||
|
@ -158,10 +158,18 @@ namespace PolyVox
|
|||||||
/// Destructor
|
/// Destructor
|
||||||
~SimpleVolume();
|
~SimpleVolume();
|
||||||
|
|
||||||
|
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||||
|
VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||||
|
/// Gets a voxel at the position given by a 3D vector
|
||||||
|
VoxelType getVoxel(const Vector3DInt32& v3dPos) const;
|
||||||
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||||
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
|
||||||
/// Gets a voxel at the position given by a 3D vector
|
/// Gets a voxel at the position given by a 3D vector
|
||||||
VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
|
VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
|
||||||
|
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||||
|
VoxelType getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType(0)) const;
|
||||||
|
/// Gets a voxel at the position given by a 3D vector
|
||||||
|
VoxelType getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType(0)) const;
|
||||||
|
|
||||||
/// Sets the voxel at the position given by <tt>x,y,z</tt> coordinates
|
/// Sets the voxel at the position given by <tt>x,y,z</tt> coordinates
|
||||||
bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue);
|
bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue);
|
||||||
|
@ -71,6 +71,40 @@ namespace PolyVox
|
|||||||
assert(false); // See function comment above.
|
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 SimpleVolume<VoxelType>::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
|
||||||
|
{
|
||||||
|
assert(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)));
|
||||||
|
|
||||||
|
const int32_t blockX = uXPos >> m_uBlockSideLengthPower;
|
||||||
|
const int32_t blockY = uYPos >> m_uBlockSideLengthPower;
|
||||||
|
const int32_t blockZ = uZPos >> m_uBlockSideLengthPower;
|
||||||
|
|
||||||
|
const uint16_t xOffset = static_cast<uint16_t>(uXPos - (blockX << m_uBlockSideLengthPower));
|
||||||
|
const uint16_t yOffset = static_cast<uint16_t>(uYPos - (blockY << m_uBlockSideLengthPower));
|
||||||
|
const uint16_t zOffset = static_cast<uint16_t>(uZPos - (blockZ << m_uBlockSideLengthPower));
|
||||||
|
|
||||||
|
typename SimpleVolume<VoxelType>::Block* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ);
|
||||||
|
|
||||||
|
return pUncompressedBlock->getVoxelAt(xOffset,yOffset,zOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// \param v3dPos The 3D position of the voxel
|
||||||
|
/// \return The voxel value
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename VoxelType>
|
||||||
|
VoxelType SimpleVolume<VoxelType>::getVoxel(const Vector3DInt32& v3dPos) const
|
||||||
|
{
|
||||||
|
return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// \param uXPos The \c x position of the voxel
|
/// \param uXPos The \c x position of the voxel
|
||||||
/// \param uYPos The \c y position of the voxel
|
/// \param uYPos The \c y position of the voxel
|
||||||
@ -110,6 +144,62 @@ namespace PolyVox
|
|||||||
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
|
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 SimpleVolume<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 SimpleVolume<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 uXPos the \c x position of the voxel
|
||||||
/// \param uYPos the \c y position of the voxel
|
/// \param uYPos the \c y position of the voxel
|
||||||
|
@ -34,7 +34,10 @@ using namespace PolyVox;
|
|||||||
template <typename VolumeType>
|
template <typename VolumeType>
|
||||||
int32_t complexVolumeTest(void)
|
int32_t complexVolumeTest(void)
|
||||||
{
|
{
|
||||||
|
//Create the volume
|
||||||
VolumeType testVolume(Region(-57, -31, 12, 64, 96, 131)); // Deliberatly awkward size
|
VolumeType testVolume(Region(-57, -31, 12, 64, 96, 131)); // Deliberatly awkward size
|
||||||
|
|
||||||
|
//Fill the volume with some data
|
||||||
for(int z = testVolume.getEnclosingRegion().getLowerZ(); z <= testVolume.getEnclosingRegion().getUpperZ(); z++)
|
for(int z = testVolume.getEnclosingRegion().getLowerZ(); z <= testVolume.getEnclosingRegion().getUpperZ(); z++)
|
||||||
{
|
{
|
||||||
for(int y = testVolume.getEnclosingRegion().getLowerY(); y <= testVolume.getEnclosingRegion().getUpperY(); y++)
|
for(int y = testVolume.getEnclosingRegion().getLowerY(); y <= testVolume.getEnclosingRegion().getUpperY(); y++)
|
||||||
@ -46,38 +49,65 @@ int32_t complexVolumeTest(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sum = 0;
|
int32_t result = 0;
|
||||||
|
|
||||||
|
//Test the getVoxel function
|
||||||
for(int z = testVolume.getEnclosingRegion().getLowerZ(); z <= testVolume.getEnclosingRegion().getUpperZ(); z++)
|
for(int z = testVolume.getEnclosingRegion().getLowerZ(); z <= testVolume.getEnclosingRegion().getUpperZ(); z++)
|
||||||
{
|
{
|
||||||
for(int y = testVolume.getEnclosingRegion().getLowerY(); y <= testVolume.getEnclosingRegion().getUpperY(); y++)
|
for(int y = testVolume.getEnclosingRegion().getLowerY(); y <= testVolume.getEnclosingRegion().getUpperY(); y++)
|
||||||
{
|
{
|
||||||
for(int x = testVolume.getEnclosingRegion().getLowerX(); x <= testVolume.getEnclosingRegion().getUpperX(); x++)
|
for(int x = testVolume.getEnclosingRegion().getLowerX(); x <= testVolume.getEnclosingRegion().getUpperX(); x++)
|
||||||
{
|
{
|
||||||
sum += testVolume.getVoxelAt(x, y, z);
|
result += testVolume.getVoxel(x, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sum;
|
//Test border wrap mode
|
||||||
|
for(int z = testVolume.getEnclosingRegion().getLowerZ(); z <= testVolume.getEnclosingRegion().getUpperZ(); z++)
|
||||||
|
{
|
||||||
|
//Just a few slices from y
|
||||||
|
for(int y = testVolume.getEnclosingRegion().getLowerY() - 3; y <= testVolume.getEnclosingRegion().getUpperY() + 5; y++)
|
||||||
|
{
|
||||||
|
for(int x = testVolume.getEnclosingRegion().getLowerX(); x <= testVolume.getEnclosingRegion().getUpperX(); x++)
|
||||||
|
{
|
||||||
|
result += testVolume.getVoxelWithWrapping(x, y, z, WrapModes::Border, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Test clamp wrap mode
|
||||||
|
for(int z = testVolume.getEnclosingRegion().getLowerZ(); z <= testVolume.getEnclosingRegion().getUpperZ(); z++)
|
||||||
|
{
|
||||||
|
for(int y = testVolume.getEnclosingRegion().getLowerY(); y <= testVolume.getEnclosingRegion().getUpperY(); y++)
|
||||||
|
{
|
||||||
|
//Just a few slices from y
|
||||||
|
for(int x = testVolume.getEnclosingRegion().getLowerX() - 2; x <= testVolume.getEnclosingRegion().getUpperX() + 4; x++)
|
||||||
|
{
|
||||||
|
result += testVolume.getVoxelWithWrapping(x, y, z, WrapModes::Clamp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestVolume::testLargeVolume()
|
void TestVolume::testLargeVolume()
|
||||||
{
|
{
|
||||||
int32_t result = complexVolumeTest< LargeVolume<int32_t> >();
|
int32_t result = complexVolumeTest< LargeVolume<int32_t> >();
|
||||||
QCOMPARE(result, static_cast<int32_t>(201446400));
|
QCOMPARE(result, static_cast<int32_t>(616456320));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestVolume::testRawVolume()
|
void TestVolume::testRawVolume()
|
||||||
{
|
{
|
||||||
int32_t result = complexVolumeTest< RawVolume<int32_t> >();
|
int32_t result = complexVolumeTest< RawVolume<int32_t> >();
|
||||||
QCOMPARE(result, static_cast<int32_t>(201446400));
|
QCOMPARE(result, static_cast<int32_t>(616456320));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestVolume::testSimpleVolume()
|
void TestVolume::testSimpleVolume()
|
||||||
{
|
{
|
||||||
int32_t result = complexVolumeTest< SimpleVolume<int32_t> >();
|
int32_t result = complexVolumeTest< SimpleVolume<int32_t> >();
|
||||||
QCOMPARE(result, static_cast<int32_t>(201446400));
|
QCOMPARE(result, static_cast<int32_t>(616456320));
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(TestVolume)
|
QTEST_MAIN(TestVolume)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user