Refactoring and optimising Marching Cubes algorithm.

This commit is contained in:
David Williams
2009-05-04 10:28:20 +00:00
parent 6da15633e6
commit 03163404df
7 changed files with 480 additions and 367 deletions

View File

@ -131,6 +131,8 @@ namespace PolyVox
float getDiagonalLength(void) const;
VoxelType getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const;
VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const;
VoxelType getVoxelAtWithBoundCheck(int16_t uXPos, int16_t uYPos, int16_t uZPos) const;
VoxelType getVoxelAtWithBoundCheck(const Vector3DInt16& v3dPos) const;
void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue);
void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);

View File

@ -247,12 +247,27 @@ namespace PolyVox
template <typename VoxelType>
VoxelType Volume<VoxelType>::getVoxelAt(const Vector3DUint16& v3dPos) const
{
assert(v3dPos.getX() < m_uWidth);
assert(v3dPos.getY() < m_uHeight);
assert(v3dPos.getZ() < m_uDepth);
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::getVoxelAtWithBoundCheck(int16_t uXPos, int16_t uYPos, int16_t uZPos) const
{
if((uXPos >=0) && (uXPos < m_uWidth) && (uYPos >= 0) && (uYPos < m_uHeight) && (uZPos >= 0) && (uZPos < m_uDepth))
{
return getVoxelAt(uXPos, uYPos, uZPos);
}
else
{
return 0;
}
}
template <typename VoxelType>
VoxelType Volume<VoxelType>::getVoxelAtWithBoundCheck(const Vector3DInt16& v3dPos) const
{
return getVoxelAtWithBoundCheck(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
}
#pragma endregion
#pragma region Setters

View File

@ -57,7 +57,9 @@ namespace PolyVox
bool isValidForRegion(void) const;
bool moveForwardInRegionXYZ(void);
void moveForwardInRegionXYZFast(void);
void moveForwardInRegionXYZFast(void);
void movePositiveX(void);
VoxelType peekVoxel1nx1ny1nz(void) const;
VoxelType peekVoxel1nx1ny0pz(void) const;

View File

@ -382,6 +382,23 @@ namespace PolyVox
return true;
}
template <typename VoxelType>
void VolumeIterator<VoxelType>::movePositiveX(void)
{
++mXPosInVolume;
if(mXPosInVolume % mVolume.m_uBlockSideLength == 0)
{
//We've hit the block boundary. Just calling setPosition() is the easiest weay to resolve this.
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
else
{
//No need to compute new block.
++mVoxelIndexInBlock;
++mCurrentVoxel;
}
}
#pragma endregion
#pragma region Peekers