Initial version of new experimental marching cubes algorithm. Currently about half as fast.

This commit is contained in:
David Williams
2008-06-03 19:14:27 +00:00
parent 72a4e9902c
commit e49859fc40
5 changed files with 454 additions and 12 deletions

View File

@ -55,7 +55,8 @@ namespace PolyVox
void setVoxel(VoxelType tValue);
bool isValidForRegion(void) const;
void moveForwardInRegion(void);
void moveForwardInRegionFast(void);
bool moveForwardInRegionXYZ(void);
VoxelType peekVoxel1nx1ny1nz(void) const;
VoxelType peekVoxel1nx1ny0pz(void) const;

View File

@ -253,7 +253,7 @@ namespace PolyVox
}
template <typename VoxelType>
void BlockVolumeIterator<VoxelType>::moveForwardInRegion(void)
void BlockVolumeIterator<VoxelType>::moveForwardInRegionFast(void)
{
mXPosInBlock++;
mCurrentVoxel++;
@ -337,6 +337,59 @@ namespace PolyVox
}
}
}
template <typename VoxelType>
bool BlockVolumeIterator<VoxelType>::moveForwardInRegionXYZ(void)
{
if(mXPosInVolume < mXRegionLast)
{
++mXPosInVolume;
if(mXPosInVolume % mVolume.m_uBlockSideLength != 0)
{
//No need to compute new block.
++mVoxelIndexInBlock;
++mCurrentVoxel;
}
else
{
//A more complex situation. Just call setPosition().
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
}
else
{
mXPosInVolume = mXRegionFirst;
if(mYPosInVolume < mYRegionLast)
{
++mYPosInVolume;
//In the case of 'X' we used a trick to avoid calling this evey time. It's hard to use the same
//trick here because the x position has been reset and so is likely to be in a different block.
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
else
{
mYPosInVolume = mYRegionFirst;
if(mZPosInVolume < mZRegionLast)
{
++mZPosInVolume;
//In the case of 'X' we used a trick to avoid calling this evey time. It's hard to use the same
//trick here because the x position has been reset and so is likely to be in a different block.
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
else
{
//We've hit the end of the region. Reset x and y positions to where they were.
mXPosInVolume = mXRegionLast;
mYPosInVolume = mYRegionLast;
//Return false to indicate we failed to move forward.
return false;
}
}
}
return true;
}
#pragma endregion
#pragma region Peekers

View File

@ -35,6 +35,7 @@ namespace PolyVox
{
POLYVOX_API std::list<RegionGeometry> getChangedRegionGeometry(VolumeChangeTracker& volume);
POLYVOX_API void generateExperimentalMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
POLYVOX_API void generateRoughMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
POLYVOX_API Vector3DFloat computeNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);