Renamed BlockData to Block
This commit is contained in:
parent
ed5bff9ee1
commit
b7ea308897
@ -31,16 +31,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
class BlockData
|
class Block
|
||||||
{
|
{
|
||||||
//Make VolumeIterator a friend
|
//Make VolumeIterator a friend
|
||||||
friend class VolumeIterator<VoxelType>;
|
friend class VolumeIterator<VoxelType>;
|
||||||
public:
|
public:
|
||||||
BlockData(uint16_t uSideLength);
|
Block(uint16_t uSideLength);
|
||||||
BlockData(const BlockData& rhs);
|
Block(const Block& rhs);
|
||||||
~BlockData();
|
~Block();
|
||||||
|
|
||||||
BlockData& operator=(const BlockData& rhs);
|
Block& operator=(const Block& rhs);
|
||||||
|
|
||||||
uint16_t getSideLength(void) const;
|
uint16_t getSideLength(void) const;
|
||||||
VoxelType getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const;
|
VoxelType getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const;
|
||||||
|
@ -33,7 +33,7 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
#pragma region Constructors/Destructors
|
#pragma region Constructors/Destructors
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
BlockData<VoxelType>::BlockData(uint16_t uSideLength)
|
Block<VoxelType>::Block(uint16_t uSideLength)
|
||||||
:m_tData(0)
|
:m_tData(0)
|
||||||
{
|
{
|
||||||
//Debug mode validation
|
//Debug mode validation
|
||||||
@ -42,7 +42,7 @@ namespace PolyVox
|
|||||||
//Release mode validation
|
//Release mode validation
|
||||||
if(!isPowerOf2(uSideLength))
|
if(!isPowerOf2(uSideLength))
|
||||||
{
|
{
|
||||||
throw std::invalid_argument("BlockData side length must be a power of two.");
|
throw std::invalid_argument("Block side length must be a power of two.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Compute the side length
|
//Compute the side length
|
||||||
@ -55,13 +55,13 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
BlockData<VoxelType>::BlockData(const BlockData<VoxelType>& rhs)
|
Block<VoxelType>::Block(const Block<VoxelType>& rhs)
|
||||||
{
|
{
|
||||||
*this = rhs;
|
*this = rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
BlockData<VoxelType>::~BlockData()
|
Block<VoxelType>::~Block()
|
||||||
{
|
{
|
||||||
delete[] m_tData;
|
delete[] m_tData;
|
||||||
m_tData = 0;
|
m_tData = 0;
|
||||||
@ -70,7 +70,7 @@ namespace PolyVox
|
|||||||
|
|
||||||
#pragma region Operators
|
#pragma region Operators
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
BlockData<VoxelType>& BlockData<VoxelType>::operator=(const BlockData<VoxelType>& rhs)
|
Block<VoxelType>& Block<VoxelType>::operator=(const Block<VoxelType>& rhs)
|
||||||
{
|
{
|
||||||
if (this == &rhs)
|
if (this == &rhs)
|
||||||
{
|
{
|
||||||
@ -92,13 +92,13 @@ namespace PolyVox
|
|||||||
|
|
||||||
#pragma region Getters
|
#pragma region Getters
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
uint16_t BlockData<VoxelType>::getSideLength(void) const
|
uint16_t Block<VoxelType>::getSideLength(void) const
|
||||||
{
|
{
|
||||||
return m_uSideLength;
|
return m_uSideLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType BlockData<VoxelType>::getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const
|
VoxelType Block<VoxelType>::getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const
|
||||||
{
|
{
|
||||||
assert(uXPos < m_uSideLength);
|
assert(uXPos < m_uSideLength);
|
||||||
assert(uYPos < m_uSideLength);
|
assert(uYPos < m_uSideLength);
|
||||||
@ -113,7 +113,7 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
VoxelType BlockData<VoxelType>::getVoxelAt(const Vector3DUint16& v3dPos) const
|
VoxelType Block<VoxelType>::getVoxelAt(const Vector3DUint16& v3dPos) const
|
||||||
{
|
{
|
||||||
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
|
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ namespace PolyVox
|
|||||||
|
|
||||||
#pragma region Setters
|
#pragma region Setters
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void BlockData<VoxelType>::setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue)
|
void Block<VoxelType>::setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue)
|
||||||
{
|
{
|
||||||
assert(uXPos < m_uSideLength);
|
assert(uXPos < m_uSideLength);
|
||||||
assert(uYPos < m_uSideLength);
|
assert(uYPos < m_uSideLength);
|
||||||
@ -136,7 +136,7 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void BlockData<VoxelType>::setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue)
|
void Block<VoxelType>::setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue)
|
||||||
{
|
{
|
||||||
setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
|
setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
|
||||||
}
|
}
|
||||||
@ -144,13 +144,13 @@ namespace PolyVox
|
|||||||
|
|
||||||
#pragma region Other
|
#pragma region Other
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void BlockData<VoxelType>::fill(VoxelType tValue)
|
void Block<VoxelType>::fill(VoxelType tValue)
|
||||||
{
|
{
|
||||||
memset(m_tData, (int)tValue, m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType));
|
memset(m_tData, (int)tValue, m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
bool BlockData<VoxelType>::isHomogeneous(void)
|
bool Block<VoxelType>::isHomogeneous(void)
|
||||||
{
|
{
|
||||||
const VoxelType tFirstVoxel = m_tData[0];
|
const VoxelType tFirstVoxel = m_tData[0];
|
||||||
const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
|
const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
|
||||||
|
@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
template <typename VoxelType> class BlockData;
|
template <typename VoxelType> class Block;
|
||||||
|
|
||||||
//---------- Volume ----------
|
//---------- Volume ----------
|
||||||
template <typename VoxelType> class Volume;
|
template <typename VoxelType> class Volume;
|
||||||
|
@ -66,9 +66,9 @@ namespace PolyVox
|
|||||||
bool isRegionHomogenous(const Region& region);
|
bool isRegionHomogenous(const Region& region);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
POLYVOX_SHARED_PTR< BlockData<VoxelType> > getHomogenousBlockData(VoxelType tHomogenousValue) const;
|
POLYVOX_SHARED_PTR< Block<VoxelType> > getHomogenousBlock(VoxelType tHomogenousValue) const;
|
||||||
|
|
||||||
std::vector< POLYVOX_SHARED_PTR< BlockData<VoxelType> > > m_pBlocks;
|
std::vector< POLYVOX_SHARED_PTR< Block<VoxelType> > > m_pBlocks;
|
||||||
std::vector<bool> m_vecBlockIsPotentiallyHomogenous;
|
std::vector<bool> m_vecBlockIsPotentiallyHomogenous;
|
||||||
|
|
||||||
//Note: We were once storing weak_ptr's in this map, so that the blocks would be deleted once they
|
//Note: We were once storing weak_ptr's in this map, so that the blocks would be deleted once they
|
||||||
@ -76,7 +76,7 @@ namespace PolyVox
|
|||||||
//shared. A call to shared_ptr::unique() from within setVoxel was not sufficient as weak_ptr's did
|
//shared. A call to shared_ptr::unique() from within setVoxel was not sufficient as weak_ptr's did
|
||||||
//not contribute to the reference count. Instead we store shared_ptr's here, and check if they
|
//not contribute to the reference count. Instead we store shared_ptr's here, and check if they
|
||||||
//are used by anyone else (i.e are non-unique) when we tidy the volume.
|
//are used by anyone else (i.e are non-unique) when we tidy the volume.
|
||||||
static std::map<VoxelType, POLYVOX_SHARED_PTR< BlockData<VoxelType> > > m_pHomogenousBlockData;
|
static std::map<VoxelType, POLYVOX_SHARED_PTR< Block<VoxelType> > > m_pHomogenousBlock;
|
||||||
|
|
||||||
uint32_t m_uNoOfBlocksInVolume;
|
uint32_t m_uNoOfBlocksInVolume;
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ namespace PolyVox
|
|||||||
};
|
};
|
||||||
|
|
||||||
//Required for the static member
|
//Required for the static member
|
||||||
template <class VoxelType> std::map<VoxelType, POLYVOX_SHARED_PTR< BlockData<VoxelType> > > Volume<VoxelType>::m_pHomogenousBlockData;
|
template <class VoxelType> std::map<VoxelType, POLYVOX_SHARED_PTR< Block<VoxelType> > > Volume<VoxelType>::m_pHomogenousBlock;
|
||||||
|
|
||||||
|
|
||||||
//Some handy typedefs
|
//Some handy typedefs
|
||||||
|
@ -109,7 +109,7 @@ namespace PolyVox
|
|||||||
m_vecBlockIsPotentiallyHomogenous.resize(m_uNoOfBlocksInVolume);
|
m_vecBlockIsPotentiallyHomogenous.resize(m_uNoOfBlocksInVolume);
|
||||||
for(uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i)
|
for(uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i)
|
||||||
{
|
{
|
||||||
m_pBlocks[i] = getHomogenousBlockData(0);
|
m_pBlocks[i] = getHomogenousBlock(0);
|
||||||
m_vecBlockIsPotentiallyHomogenous[i] = false;
|
m_vecBlockIsPotentiallyHomogenous[i] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ namespace PolyVox
|
|||||||
const uint16_t yOffset = uYPos - (blockY << m_uBlockSideLengthPower);
|
const uint16_t yOffset = uYPos - (blockY << m_uBlockSideLengthPower);
|
||||||
const uint16_t zOffset = uZPos - (blockZ << m_uBlockSideLengthPower);
|
const uint16_t zOffset = uZPos - (blockZ << m_uBlockSideLengthPower);
|
||||||
|
|
||||||
const POLYVOX_SHARED_PTR< BlockData< VoxelType > >& block = m_pBlocks
|
const POLYVOX_SHARED_PTR< Block< VoxelType > >& block = m_pBlocks
|
||||||
[
|
[
|
||||||
blockX +
|
blockX +
|
||||||
blockY * m_uWidthInBlocks +
|
blockY * m_uWidthInBlocks +
|
||||||
@ -235,7 +235,7 @@ namespace PolyVox
|
|||||||
blockY * m_uWidthInBlocks +
|
blockY * m_uWidthInBlocks +
|
||||||
blockZ * m_uWidthInBlocks * m_uHeightInBlocks;
|
blockZ * m_uWidthInBlocks * m_uHeightInBlocks;
|
||||||
|
|
||||||
POLYVOX_SHARED_PTR< BlockData<VoxelType> >& block = m_pBlocks[uBlockIndex];
|
POLYVOX_SHARED_PTR< Block<VoxelType> >& block = m_pBlocks[uBlockIndex];
|
||||||
|
|
||||||
//It's quite possible that the user might attempt to set a voxel to it's current value.
|
//It's quite possible that the user might attempt to set a voxel to it's current value.
|
||||||
//We test for this case firstly because it could help performance, but more importantly
|
//We test for this case firstly because it could help performance, but more importantly
|
||||||
@ -251,8 +251,8 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
POLYVOX_SHARED_PTR< BlockData<VoxelType> > pNewBlockData(new BlockData<VoxelType>(*(block)));
|
POLYVOX_SHARED_PTR< Block<VoxelType> > pNewBlock(new Block<VoxelType>(*(block)));
|
||||||
block = pNewBlockData;
|
block = pNewBlock;
|
||||||
m_vecBlockIsPotentiallyHomogenous[uBlockIndex] = false;
|
m_vecBlockIsPotentiallyHomogenous[uBlockIndex] = false;
|
||||||
block->setVoxelAt(xOffset,yOffset,zOffset, tValue);
|
block->setVoxelAt(xOffset,yOffset,zOffset, tValue);
|
||||||
}
|
}
|
||||||
@ -291,7 +291,7 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
//If so, replace is with a block from out homogeneous collection.
|
//If so, replace is with a block from out homogeneous collection.
|
||||||
VoxelType homogeneousValue = m_pBlocks[m_uCurrentBlockForTidying]->getVoxelAt(0,0,0);
|
VoxelType homogeneousValue = m_pBlocks[m_uCurrentBlockForTidying]->getVoxelAt(0,0,0);
|
||||||
m_pBlocks[m_uCurrentBlockForTidying] = getHomogenousBlockData(homogeneousValue);
|
m_pBlocks[m_uCurrentBlockForTidying] = getHomogenousBlock(homogeneousValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Either way, we have now determined whether the block was sharable. So it's not *potentially* sharable.
|
//Either way, we have now determined whether the block was sharable. So it's not *potentially* sharable.
|
||||||
@ -307,12 +307,12 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Identify and remove any homogeneous blocks which are not actually in use.
|
//Identify and remove any homogeneous blocks which are not actually in use.
|
||||||
typename std::map<VoxelType, POLYVOX_SHARED_PTR< BlockData<VoxelType> > >::iterator iter = m_pHomogenousBlockData.begin();
|
typename std::map<VoxelType, POLYVOX_SHARED_PTR< Block<VoxelType> > >::iterator iter = m_pHomogenousBlock.begin();
|
||||||
while(iter != m_pHomogenousBlockData.end())
|
while(iter != m_pHomogenousBlock.end())
|
||||||
{
|
{
|
||||||
if(iter->second.unique())
|
if(iter->second.unique())
|
||||||
{
|
{
|
||||||
m_pHomogenousBlockData.erase(iter++); //Increments the iterator and returns the previous position to be erased.
|
m_pHomogenousBlock.erase(iter++); //Increments the iterator and returns the previous position to be erased.
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -346,23 +346,23 @@ namespace PolyVox
|
|||||||
|
|
||||||
#pragma region Private Implementation
|
#pragma region Private Implementation
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
POLYVOX_SHARED_PTR< BlockData<VoxelType> > Volume<VoxelType>::getHomogenousBlockData(VoxelType tHomogenousValue) const
|
POLYVOX_SHARED_PTR< Block<VoxelType> > Volume<VoxelType>::getHomogenousBlock(VoxelType tHomogenousValue) const
|
||||||
{
|
{
|
||||||
typename std::map<VoxelType, POLYVOX_SHARED_PTR< BlockData<VoxelType> > >::iterator iterResult = m_pHomogenousBlockData.find(tHomogenousValue);
|
typename std::map<VoxelType, POLYVOX_SHARED_PTR< Block<VoxelType> > >::iterator iterResult = m_pHomogenousBlock.find(tHomogenousValue);
|
||||||
if(iterResult == m_pHomogenousBlockData.end())
|
if(iterResult == m_pHomogenousBlock.end())
|
||||||
{
|
{
|
||||||
//Block<VoxelType> block;
|
//Block<VoxelType> block;
|
||||||
POLYVOX_SHARED_PTR< BlockData<VoxelType> > pHomogeneousBlock(new BlockData<VoxelType>(m_uBlockSideLength));
|
POLYVOX_SHARED_PTR< Block<VoxelType> > pHomogeneousBlock(new Block<VoxelType>(m_uBlockSideLength));
|
||||||
//block.m_pBlockData = temp;
|
//block.m_pBlock = temp;
|
||||||
//block.m_uReferenceCount++;
|
//block.m_uReferenceCount++;
|
||||||
pHomogeneousBlock->fill(tHomogenousValue);
|
pHomogeneousBlock->fill(tHomogenousValue);
|
||||||
m_pHomogenousBlockData.insert(std::make_pair(tHomogenousValue, pHomogeneousBlock));
|
m_pHomogenousBlock.insert(std::make_pair(tHomogenousValue, pHomogeneousBlock));
|
||||||
return pHomogeneousBlock;
|
return pHomogeneousBlock;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//iterResult->second.m_uReferenceCount++;
|
//iterResult->second.m_uReferenceCount++;
|
||||||
//POLYVOX_SHARED_PTR< BlockData<VoxelType> > result(iterResult->second);
|
//POLYVOX_SHARED_PTR< Block<VoxelType> > result(iterResult->second);
|
||||||
return iterResult->second;
|
return iterResult->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ namespace PolyVox
|
|||||||
mBlockIndexInVolume = mXBlock +
|
mBlockIndexInVolume = mXBlock +
|
||||||
mYBlock * mVolume.m_uWidthInBlocks +
|
mYBlock * mVolume.m_uWidthInBlocks +
|
||||||
mZBlock * mVolume.m_uWidthInBlocks * mVolume.m_uHeightInBlocks;
|
mZBlock * mVolume.m_uWidthInBlocks * mVolume.m_uHeightInBlocks;
|
||||||
POLYVOX_SHARED_PTR< BlockData<VoxelType> > currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
|
POLYVOX_SHARED_PTR< Block<VoxelType> > currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
|
||||||
|
|
||||||
mVoxelIndexInBlock = mXPosInBlock +
|
mVoxelIndexInBlock = mXPosInBlock +
|
||||||
mYPosInBlock * mVolume.m_uBlockSideLength +
|
mYPosInBlock * mVolume.m_uBlockSideLength +
|
||||||
@ -257,7 +257,7 @@ namespace PolyVox
|
|||||||
mVoxelIndexInBlock = mXPosInBlock +
|
mVoxelIndexInBlock = mXPosInBlock +
|
||||||
mYPosInBlock * mVolume.m_uBlockSideLength +
|
mYPosInBlock * mVolume.m_uBlockSideLength +
|
||||||
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
|
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
|
||||||
boost::shared_ptr< BlockData<VoxelType> > currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
|
boost::shared_ptr< Block<VoxelType> > currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
|
||||||
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
|
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
|
||||||
|
|
||||||
mYPosInBlock++;
|
mYPosInBlock++;
|
||||||
@ -270,7 +270,7 @@ namespace PolyVox
|
|||||||
mVoxelIndexInBlock = mXPosInBlock +
|
mVoxelIndexInBlock = mXPosInBlock +
|
||||||
mYPosInBlock * mVolume.m_uBlockSideLength +
|
mYPosInBlock * mVolume.m_uBlockSideLength +
|
||||||
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
|
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
|
||||||
BlockData<VoxelType>* currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
|
Block<VoxelType>* currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
|
||||||
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
|
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
|
||||||
|
|
||||||
mZPosInBlock++;
|
mZPosInBlock++;
|
||||||
@ -309,7 +309,7 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockData<VoxelType>* currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
|
Block<VoxelType>* currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
|
||||||
//mCurrentBlock = mVolume->m_pBlocks[mBlockIndexInVolume];
|
//mCurrentBlock = mVolume->m_pBlocks[mBlockIndexInVolume];
|
||||||
|
|
||||||
mXPosInVolume = (std::max)(mXRegionFirst,uint16_t(mXBlock * mVolume.m_uBlockSideLength));
|
mXPosInVolume = (std::max)(mXRegionFirst,uint16_t(mXBlock * mVolume.m_uBlockSideLength));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user