Restructuring computeBitmask code.

This commit is contained in:
David Williams 2015-05-14 11:14:39 +02:00
parent 5974a1de9b
commit 54f235e09a
2 changed files with 45 additions and 53 deletions

View File

@ -160,7 +160,7 @@ namespace PolyVox
private:
//Compute the cell bitmask for a particular slice in z.
template<bool isPrevZAvail>
void computeBitmaskForSlice(Array3DUint8& pBitmask, uint32_t uSlice);
void computeBitmaskForSlice(Array3DUint8& pBitmask);
//Use the cell bitmasks to generate all the vertices needed for that slice
void generateVerticesForSlice(const Array3DUint8& pBitmask,

View File

@ -68,12 +68,7 @@ namespace PolyVox
m_regSlicePrevious.setUpperCorner(v3dUpperCorner);
m_regSliceCurrent = m_regSlicePrevious;
//Process the first slice (previous slice not available)
computeBitmaskForSlice<false>(pBitmask, 0);
for (int32_t uSlice = 1; uSlice <= m_regSizeInVoxels.getUpperZ() - m_regSizeInVoxels.getLowerZ(); uSlice++)
{
computeBitmaskForSlice<true>(pBitmask, uSlice);
}
computeBitmaskForSlice<true>(pBitmask);
generateVerticesForSlice(pBitmask, pIndicesX, pIndicesY, pIndicesZ);
@ -100,28 +95,24 @@ namespace PolyVox
template<typename VolumeType, typename MeshType, typename ControllerType>
template<bool isPrevZAvail>
void MarchingCubesSurfaceExtractor<VolumeType, MeshType, ControllerType>::computeBitmaskForSlice(Array3DUint8& pBitmask, uint32_t uSlice)
void MarchingCubesSurfaceExtractor<VolumeType, MeshType, ControllerType>::computeBitmaskForSlice(Array3DUint8& pBitmask)
{
const int32_t iMaxXVolSpace = m_regSizeInVoxels.getUpperX();
const int32_t iMaxYVolSpace = m_regSizeInVoxels.getUpperY();
const int32_t iMaxZVolSpace = m_regSizeInVoxels.getUpperZ();
//Process the lower left corner
int32_t iYVolSpace = m_regSizeInVoxels.getLowerY();
int32_t iXVolSpace = m_regSizeInVoxels.getLowerX();
int32_t iZVolSpace = m_regSizeInVoxels.getLowerZ() + uSlice;
uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX();
uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY();
uint32_t uZRegSpace = uSlice;
for (int32_t iZVolSpace = m_regSliceCurrent.getLowerZ(); iZVolSpace <= iMaxZVolSpace; iZVolSpace++)
{
uint32_t uZRegSpace = iZVolSpace - m_regSizeInVoxels.getLowerZ();
//Process all remaining elemnents of the slice. In this case, previous x and y values are always available
for(iYVolSpace = m_regSliceCurrent.getLowerY(); iYVolSpace <= iMaxYVolSpace; iYVolSpace++)
for (int32_t iYVolSpace = m_regSliceCurrent.getLowerY(); iYVolSpace <= iMaxYVolSpace; iYVolSpace++)
{
m_sampVolume.setPosition(m_regSliceCurrent.getLowerX(), iYVolSpace, iZVolSpace);
for(iXVolSpace = m_regSliceCurrent.getLowerX(); iXVolSpace <= iMaxXVolSpace; iXVolSpace++)
for (int32_t iXVolSpace = m_regSliceCurrent.getLowerX(); iXVolSpace <= iMaxXVolSpace; iXVolSpace++)
{
uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX();
uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY();
uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX();
uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY();
m_sampVolume.movePositiveX();
@ -163,6 +154,7 @@ namespace PolyVox
}
}
}
}
template<typename VolumeType, typename MeshType, typename ControllerType>
void MarchingCubesSurfaceExtractor<VolumeType, MeshType, ControllerType>::generateVerticesForSlice(const Array3DUint8& pBitmask,