Removed setVoxel() function from BlockVolumeIterator and added setVoxelAt() function to BlockVolume.h

Improved OpenGL example.
This commit is contained in:
David Williams
2009-03-12 21:48:14 +00:00
parent 7100e558f3
commit 0f4a4c0e2b
7 changed files with 148 additions and 114 deletions

View File

@ -50,6 +50,9 @@ namespace PolyVox
VoxelType getVoxelAt(uint16 uXPos, uint16 uYPos, uint16 uZPos) const;
VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const;
void setVoxelAt(uint16 uXPos, uint16 uYPos, uint16 uZPos, VoxelType tValue);
void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);
bool containsPoint(const Vector3DFloat& pos, float boundary) const;
bool containsPoint(const Vector3DInt32& pos, uint16 boundary) const;
BlockVolumeIterator<VoxelType> firstVoxel(void);

View File

@ -169,6 +169,50 @@ namespace PolyVox
}
#pragma endregion
#pragma region Setters
template <typename VoxelType>
void BlockVolume<VoxelType>::setVoxelAt(uint16 uXPos, uint16 uYPos, uint16 uZPos, VoxelType tValue)
{
const uint16 blockX = uXPos >> m_uBlockSideLengthPower;
const uint16 blockY = uYPos >> m_uBlockSideLengthPower;
const uint16 blockZ = uZPos >> m_uBlockSideLengthPower;
const uint16 xOffset = uXPos - (blockX << m_uBlockSideLengthPower);
const uint16 yOffset = uYPos - (blockY << m_uBlockSideLengthPower);
const uint16 zOffset = uZPos - (blockZ << m_uBlockSideLengthPower);
const uint32 uBlockIndex =
blockX +
blockY * m_uSideLengthInBlocks +
blockZ * m_uSideLengthInBlocks * m_uSideLengthInBlocks;
const bool bIsShared = m_pIsShared[uBlockIndex];
const VoxelType tHomogenousValue = m_pHomogenousValue[uBlockIndex];
if(bIsShared)
{
if(tHomogenousValue != tValue)
{
m_pBlocks[uBlockIndex] = new Block<VoxelType>(m_uBlockSideLengthPower);
m_pIsShared[uBlockIndex] = false;
m_pBlocks[uBlockIndex]->fill(tHomogenousValue);
m_pBlocks[uBlockIndex]->setVoxelAt(xOffset,yOffset,zOffset, tValue);
}
}
else
{
//There is a chance that setting this voxel makes the block homogenous and therefore shareable.
m_pIsPotentiallySharable[uBlockIndex] = true;
m_pBlocks[uBlockIndex]->setVoxelAt(xOffset,yOffset,zOffset, tValue);
}
}
template <typename VoxelType>
void BlockVolume<VoxelType>::setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue)
{
setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
}
#pragma endregion
#pragma region Other
template <typename VoxelType>
bool BlockVolume<VoxelType>::containsPoint(const Vector3DFloat& pos, float boundary) const

View File

@ -53,8 +53,7 @@ namespace PolyVox
void setPosition(const Vector3DInt16& v3dNewPos);
void setPosition(uint16 xPos, uint16 yPos, uint16 zPos);
void setValidRegion(const Region& region);
void setValidRegion(uint16 xFirst, uint16 yFirst, uint16 zFirst, uint16 xLast, uint16 yLast, uint16 zLast);
void setVoxel(VoxelType tValue);
void setValidRegion(uint16 xFirst, uint16 yFirst, uint16 zFirst, uint16 xLast, uint16 yLast, uint16 zLast);
bool isValidForRegion(void) const;
void moveForwardInRegionFast(void);

View File

@ -235,35 +235,6 @@ namespace PolyVox
mYRegionLastBlock = mYRegionLast >> mVolume.m_uBlockSideLengthPower;
mZRegionLastBlock = mZRegionLast >> mVolume.m_uBlockSideLengthPower;
}
template <typename VoxelType>
void BlockVolumeIterator<VoxelType>::setVoxel(VoxelType tValue)
{
const uint32 uBlockIndex =
mXBlock +
mYBlock * mVolume.m_uSideLengthInBlocks +
mZBlock * mVolume.m_uSideLengthInBlocks * mVolume.m_uSideLengthInBlocks;
const bool bIsShared = mVolume.m_pIsShared[uBlockIndex];
const VoxelType tHomogenousValue = mVolume.m_pHomogenousValue[uBlockIndex];
if(bIsShared)
{
if(tHomogenousValue != tValue)
{
mVolume.m_pBlocks[uBlockIndex] = new Block<VoxelType>(mVolume.m_uBlockSideLengthPower);
mVolume.m_pIsShared[uBlockIndex] = false;
mVolume.m_pBlocks[uBlockIndex]->fill(tHomogenousValue);
mCurrentVoxel = mVolume.m_pBlocks[uBlockIndex]->m_tData + mVoxelIndexInBlock;
*mCurrentVoxel = tValue;
}
}
else
{
//There is a chance that setting this voxel makes the block homogenous and therefore shareable.
mVolume.m_pIsPotentiallySharable[uBlockIndex] = true;
*mCurrentVoxel = tValue;
}
}
#pragma endregion
#pragma region Other

View File

@ -28,7 +28,6 @@ namespace PolyVox
uint16 volumeDepth = 0x0001 << volumeDepthPower;
//Read data
BlockVolumeIterator<uint8> volIter(*volume);
for(uint16 z = 0; z < volumeDepth; ++z)
{
for(uint16 y = 0; y < volumeHeight; ++y)
@ -38,8 +37,7 @@ namespace PolyVox
uint8 value = 0;
stream.read(reinterpret_cast<char*>(&value), sizeof(value));
volIter.setPosition(x,y,z);
volIter.setVoxel(value);
volume->setVoxelAt(x,y,z,value);
}
}
}
@ -98,7 +96,6 @@ namespace PolyVox
uint16 volumeDepth = 0x0001 << volumeDepthPower;
//Read data
BlockVolumeIterator<uint8> volIter(*volume);
bool firstTime = true;
uint32 runLength = 0;
uint8 value = 0;
@ -110,10 +107,9 @@ namespace PolyVox
{
for(uint16 x = 0; x < volumeWidth; ++x)
{
volIter.setPosition(x,y,z);
if(runLength != 0)
{
volIter.setVoxel(value);
volume->setVoxelAt(x,y,z,value);
runLength--;
}
else
@ -121,7 +117,7 @@ namespace PolyVox
stream.read(reinterpret_cast<char*>(&value), sizeof(value));
stream.read(reinterpret_cast<char*>(&runLength), sizeof(runLength));
volIter.setVoxel(value);
volume->setVoxelAt(x,y,z,value);
runLength--;
}
}

View File

@ -117,9 +117,11 @@ namespace PolyVox
{
++m_iCurrentTime;
//FIXME - rather than creating a iterator each time we should have one stored
BlockVolumeIterator<uint8> iterVol(*volumeData);
iterVol.setPosition(x,y,z);
iterVol.setVoxel(value);
//BlockVolumeIterator<uint8> iterVol(*volumeData);
/*iterVol.setPosition(x,y,z);
iterVol.setVoxel(value);*/
volumeData->setVoxelAt(x,y,z,value);
//If we are not on a boundary, just mark one region.
if((x % POLYVOX_REGION_SIDE_LENGTH != 0) &&
@ -164,9 +166,10 @@ namespace PolyVox
assert(m_bIsLocked);
//FIXME - rather than creating a iterator each time we should have one stored
BlockVolumeIterator<uint8> iterVol(*volumeData);
/*BlockVolumeIterator<uint8> iterVol(*volumeData);
iterVol.setPosition(x,y,z);
iterVol.setVoxel(value);
iterVol.setVoxel(value);*/
volumeData->setVoxelAt(x,y,z,value);
}
void VolumeChangeTracker::lockRegion(const Region& regToLock)