Moved volume border handling into base class. RawVolume and SimpleVolume updated, LargeVolume still to be done.

This commit is contained in:
David Williams 2012-12-03 23:43:44 +01:00
parent 9a05f04f85
commit 9d79035890
8 changed files with 13 additions and 82 deletions

View File

@ -183,6 +183,9 @@ namespace PolyVox
int32_t m_uLongestSideLength; int32_t m_uLongestSideLength;
int32_t m_uShortestSideLength; int32_t m_uShortestSideLength;
float m_fDiagonalLength; float m_fDiagonalLength;
//The border value
VoxelType m_tBorderValue;
}; };
} }

View File

@ -31,6 +31,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
BaseVolume<VoxelType>::BaseVolume(const Region& regValid) BaseVolume<VoxelType>::BaseVolume(const Region& regValid)
:m_regValidRegion(regValid) :m_regValidRegion(regValid)
,m_tBorderValue(0)
{ {
} }
@ -76,8 +77,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
VoxelType BaseVolume<VoxelType>::getBorderValue(void) const VoxelType BaseVolume<VoxelType>::getBorderValue(void) const
{ {
assert(false); return m_tBorderValue;
return VoxelType();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -181,9 +181,9 @@ namespace PolyVox
/// \param tBorder The value to use for voxels outside the volume. /// \param tBorder The value to use for voxels outside the volume.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> template <typename VoxelType>
void BaseVolume<VoxelType>::setBorderValue(const VoxelType& /*tBorder*/) void BaseVolume<VoxelType>::setBorderValue(const VoxelType& tBorder)
{ {
assert(false); m_tBorderValue = tBorder;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -117,15 +117,11 @@ namespace PolyVox
/// Destructor /// Destructor
~RawVolume(); ~RawVolume();
/// Gets the value used for voxels which are outside the volume
VoxelType getBorderValue(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 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;
/// Sets the value used for voxels which are outside the volume
void setBorderValue(const VoxelType& tBorder);
/// 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);
/// Sets the voxel at the position given by a 3D vector /// Sets the voxel at the position given by a 3D vector
@ -146,9 +142,6 @@ namespace PolyVox
//The block data //The block data
VoxelType* m_pData; VoxelType* m_pData;
//The border value
VoxelType m_tBorderValue;
}; };
} }

View File

@ -73,17 +73,6 @@ namespace PolyVox
assert(false); // See function comment above. assert(false); // See function comment above.
} }
////////////////////////////////////////////////////////////////////////////////
/// The border value is returned whenever an attempt is made to read a voxel which
/// is outside the extents of the volume.
/// \return The value used for voxels outside of the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType RawVolume<VoxelType>::getBorderValue(void) const
{
return m_tBorderValue;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// \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
@ -123,15 +112,6 @@ namespace PolyVox
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
} }
////////////////////////////////////////////////////////////////////////////////
/// \param tBorder The value to use for voxels outside the volume.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void RawVolume<VoxelType>::setBorderValue(const VoxelType& tBorder)
{
m_tBorderValue = 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

View File

@ -249,8 +249,8 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1ny1nz(void) const VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1ny1nz(void) const
{ {
if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) )
{ {
return *(mCurrentVoxel - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight()); return *(mCurrentVoxel - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
} }

View File

@ -158,15 +158,11 @@ namespace PolyVox
/// Destructor /// Destructor
~SimpleVolume(); ~SimpleVolume();
/// Gets the value used for voxels which are outside the volume
VoxelType getBorderValue(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 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;
/// Sets the value used for voxels which are outside the volume
void setBorderValue(const VoxelType& tBorder);
/// 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);
/// Sets the voxel at the position given by a 3D vector /// Sets the voxel at the position given by a 3D vector
@ -190,12 +186,6 @@ namespace PolyVox
//The block data //The block data
Block* m_pBlocks; Block* m_pBlocks;
//We don't store an actual Block for the border, just the uncompressed data. This is partly because the border
//block does not have a position (so can't be passed to getUncompressedBlock()) and partly because there's a
//good chance we'll often hit it anyway. It's a chunk of homogenous data (rather than a single value) so that
//the VolumeIterator can do it's usual pointer arithmetic without needing to know it's gone outside the volume.
VoxelType* m_pUncompressedBorderData;
//The size of the volume in vlocks //The size of the volume in vlocks
Region m_regValidRegionInBlocks; Region m_regValidRegionInBlocks;

View File

@ -56,7 +56,6 @@ namespace PolyVox
SimpleVolume<VoxelType>::~SimpleVolume() SimpleVolume<VoxelType>::~SimpleVolume()
{ {
delete[] m_pBlocks; delete[] m_pBlocks;
delete[] m_pUncompressedBorderData;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -72,17 +71,6 @@ namespace PolyVox
assert(false); // See function comment above. assert(false); // See function comment above.
} }
////////////////////////////////////////////////////////////////////////////////
/// The border value is returned whenever an attempt is made to read a voxel which
/// is outside the extents of the volume.
/// \return The value used for voxels outside of the volume
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::getBorderValue(void) const
{
return *m_pUncompressedBorderData;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// \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
@ -122,17 +110,6 @@ namespace PolyVox
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
} }
////////////////////////////////////////////////////////////////////////////////
/// \param tBorder The value to use for voxels outside the volume.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void SimpleVolume<VoxelType>::setBorderValue(const VoxelType& tBorder)
{
/*Block<VoxelType>* pUncompressedBorderBlock = getUncompressedBlock(&m_pBorderBlock);
return pUncompressedBorderBlock->fill(tBorder);*/
std::fill(m_pUncompressedBorderData, m_pUncompressedBorderData + m_uNoOfVoxelsPerBlock, 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
@ -199,7 +176,6 @@ namespace PolyVox
m_uBlockSideLength = uBlockSideLength; m_uBlockSideLength = uBlockSideLength;
m_uNoOfVoxelsPerBlock = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength; m_uNoOfVoxelsPerBlock = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength;
m_pUncompressedBorderData = 0;
this->m_regValidRegion = regValidRegion; this->m_regValidRegion = regValidRegion;
@ -223,10 +199,6 @@ namespace PolyVox
m_pBlocks[i].initialise(m_uBlockSideLength); m_pBlocks[i].initialise(m_uBlockSideLength);
} }
//Create the border block
m_pUncompressedBorderData = new VoxelType[m_uNoOfVoxelsPerBlock];
std::fill(m_pUncompressedBorderData, m_pUncompressedBorderData + m_uNoOfVoxelsPerBlock, VoxelType());
//Other properties we might find useful later //Other properties we might find useful later
this->m_uLongestSideLength = (std::max)((std::max)(this->getWidth(),this->getHeight()),this->getDepth()); this->m_uLongestSideLength = (std::max)((std::max)(this->getWidth(),this->getHeight()),this->getDepth());
this->m_uShortestSideLength = (std::min)((std::min)(this->getWidth(),this->getHeight()),this->getDepth()); this->m_uShortestSideLength = (std::min)((std::min)(this->getWidth(),this->getHeight()),this->getDepth());
@ -264,8 +236,8 @@ namespace PolyVox
uint32_t uSizeOfBlockInBytes = m_uNoOfVoxelsPerBlock * sizeof(VoxelType); uint32_t uSizeOfBlockInBytes = m_uNoOfVoxelsPerBlock * sizeof(VoxelType);
//Memory used by the blocks ( + 1 is for border) //Memory used by the blocks
uSizeInBytes += uSizeOfBlockInBytes * (m_uNoOfBlocksInVolume + 1); uSizeInBytes += uSizeOfBlockInBytes * (m_uNoOfBlocksInVolume);
return uSizeInBytes; return uSizeInBytes;
} }

View File

@ -144,16 +144,9 @@ namespace PolyVox
uYPosInBlock * this->mVolume->m_uBlockSideLength + uYPosInBlock * this->mVolume->m_uBlockSideLength +
uZPosInBlock * this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength; uZPosInBlock * this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength;
if(this->mVolume->m_regValidRegionInBlocks.containsPoint(Vector3DInt32(uXBlock, uYBlock, uZBlock))) Block* pUncompressedCurrentBlock = this->mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock);
{
Block* pUncompressedCurrentBlock = this->mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock);
mCurrentVoxel = pUncompressedCurrentBlock->m_tUncompressedData + uVoxelIndexInBlock; mCurrentVoxel = pUncompressedCurrentBlock->m_tUncompressedData + uVoxelIndexInBlock;
}
else
{
mCurrentVoxel = this->mVolume->m_pUncompressedBorderData + uVoxelIndexInBlock;
}
} }
/** /**