Restructuring code.

This commit is contained in:
David Williams 2015-05-14 11:41:16 +02:00
parent e912950317
commit f53efa1d64
2 changed files with 116 additions and 120 deletions

View File

@ -166,8 +166,7 @@ namespace PolyVox
void generateVerticesForSlice(const Array3DUint8& pBitmask, void generateVerticesForSlice(const Array3DUint8& pBitmask,
Array3DInt32& pIndicesX, Array3DInt32& pIndicesX,
Array3DInt32& pIndicesY, Array3DInt32& pIndicesY,
Array3DInt32& pIndicesZ, Array3DInt32& pIndicesZ);
uint32_t uSlice);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// NOTE: These two functions are in the .h file rather than the .inl due to an apparent bug in VC2010. // NOTE: These two functions are in the .h file rather than the .inl due to an apparent bug in VC2010.

View File

@ -70,7 +70,7 @@ namespace PolyVox
computeBitmaskForSlice<true>(pBitmask); computeBitmaskForSlice<true>(pBitmask);
generateVerticesForSlice(pBitmask, pIndicesX, pIndicesY, pIndicesZ, 0); generateVerticesForSlice(pBitmask, pIndicesX, pIndicesY, pIndicesZ);
m_regSlicePrevious = m_regSliceCurrent; m_regSlicePrevious = m_regSliceCurrent;
m_regSliceCurrent.shift(Vector3DInt32(0,0,1)); m_regSliceCurrent.shift(Vector3DInt32(0,0,1));
@ -78,8 +78,6 @@ namespace PolyVox
//Process the other slices (previous slice is available) //Process the other slices (previous slice is available)
for(int32_t uSlice = 1; uSlice <= m_regSizeInVoxels.getUpperZ() - m_regSizeInVoxels.getLowerZ(); uSlice++) for(int32_t uSlice = 1; uSlice <= m_regSizeInVoxels.getUpperZ() - m_regSizeInVoxels.getLowerZ(); uSlice++)
{ {
generateVerticesForSlice(pBitmask, pIndicesX, pIndicesY, pIndicesZ, uSlice);
generateIndicesForSlice(pBitmask, pIndicesX, pIndicesY, pIndicesZ); generateIndicesForSlice(pBitmask, pIndicesX, pIndicesY, pIndicesZ);
m_regSlicePrevious = m_regSliceCurrent; m_regSlicePrevious = m_regSliceCurrent;
@ -160,19 +158,17 @@ namespace PolyVox
void MarchingCubesSurfaceExtractor<VolumeType, MeshType, ControllerType>::generateVerticesForSlice(const Array3DUint8& pBitmask, void MarchingCubesSurfaceExtractor<VolumeType, MeshType, ControllerType>::generateVerticesForSlice(const Array3DUint8& pBitmask,
Array3DInt32& pIndicesX, Array3DInt32& pIndicesX,
Array3DInt32& pIndicesY, Array3DInt32& pIndicesY,
Array3DInt32& pIndicesZ, Array3DInt32& pIndicesZ)
uint32_t uSlice)
{ {
const uint32_t uZRegSpace = uSlice; for (int32_t iZVolSpace = m_regSliceCurrent.getLowerZ(); iZVolSpace <= m_regSizeInVoxels.getUpperZ(); iZVolSpace++)
{
uint32_t uZRegSpace = iZVolSpace - m_regSizeInVoxels.getLowerZ();
const int32_t iZVolSpace = m_regSizeInVoxels.getLowerZ() + uZRegSpace; for (int32_t iYVolSpace = m_regSliceCurrent.getLowerY(); iYVolSpace <= m_regSizeInVoxels.getUpperY(); iYVolSpace++)
//Iterate over each cell in the region
for(int32_t iYVolSpace = m_regSliceCurrent.getLowerY(); iYVolSpace <= m_regSliceCurrent.getUpperY(); iYVolSpace++)
{ {
const uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY(); const uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY();
for(int32_t iXVolSpace = m_regSliceCurrent.getLowerX(); iXVolSpace <= m_regSliceCurrent.getUpperX(); iXVolSpace++) for (int32_t iXVolSpace = m_regSliceCurrent.getLowerX(); iXVolSpace <= m_regSizeInVoxels.getUpperX(); iXVolSpace++)
{ {
//Current position //Current position
const uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX(); const uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX();
@ -189,7 +185,7 @@ namespace PolyVox
//Check whether the generated vertex will lie on the edge of the region //Check whether the generated vertex will lie on the edge of the region
m_sampVolume.setPosition(iXVolSpace,iYVolSpace,iZVolSpace); m_sampVolume.setPosition(iXVolSpace, iYVolSpace, iZVolSpace);
const typename VolumeType::VoxelType v000 = m_sampVolume.getVoxel(); const typename VolumeType::VoxelType v000 = m_sampVolume.getVoxel();
const Vector3DFloat n000 = computeCentralDifferenceGradient(m_sampVolume); const Vector3DFloat n000 = computeCentralDifferenceGradient(m_sampVolume);
@ -206,11 +202,11 @@ namespace PolyVox
const Vector3DFloat v3dPosition(static_cast<float>(iXVolSpace - m_regSizeInVoxels.getLowerX()) + fInterp, static_cast<float>(iYVolSpace - m_regSizeInVoxels.getLowerY()), static_cast<float>(iZVolSpace - m_regSizeInCells.getLowerZ())); const Vector3DFloat v3dPosition(static_cast<float>(iXVolSpace - m_regSizeInVoxels.getLowerX()) + fInterp, static_cast<float>(iYVolSpace - m_regSizeInVoxels.getLowerY()), static_cast<float>(iZVolSpace - m_regSizeInCells.getLowerZ()));
const Vector3DUint16 v3dScaledPosition(static_cast<uint16_t>(v3dPosition.getX() * 256.0f), static_cast<uint16_t>(v3dPosition.getY() * 256.0f), static_cast<uint16_t>(v3dPosition.getZ() * 256.0f)); const Vector3DUint16 v3dScaledPosition(static_cast<uint16_t>(v3dPosition.getX() * 256.0f), static_cast<uint16_t>(v3dPosition.getY() * 256.0f), static_cast<uint16_t>(v3dPosition.getZ() * 256.0f));
Vector3DFloat v3dNormal = (n100*fInterp) + (n000*(1-fInterp)); Vector3DFloat v3dNormal = (n100*fInterp) + (n000*(1 - fInterp));
// The gradient for a voxel can be zero (e.g. solid voxel surrounded by empty ones) and so // The gradient for a voxel can be zero (e.g. solid voxel surrounded by empty ones) and so
// the interpolated normal can also be zero (e.g. a grid of alternating solid and empty voxels). // the interpolated normal can also be zero (e.g. a grid of alternating solid and empty voxels).
if(v3dNormal.lengthSquared() > 0.000001f) if (v3dNormal.lengthSquared() > 0.000001f)
{ {
v3dNormal.normalise(); v3dNormal.normalise();
} }
@ -240,11 +236,11 @@ namespace PolyVox
const Vector3DFloat v3dPosition(static_cast<float>(iXVolSpace - m_regSizeInVoxels.getLowerX()), static_cast<float>(iYVolSpace - m_regSizeInVoxels.getLowerY()) + fInterp, static_cast<float>(iZVolSpace - m_regSizeInVoxels.getLowerZ())); const Vector3DFloat v3dPosition(static_cast<float>(iXVolSpace - m_regSizeInVoxels.getLowerX()), static_cast<float>(iYVolSpace - m_regSizeInVoxels.getLowerY()) + fInterp, static_cast<float>(iZVolSpace - m_regSizeInVoxels.getLowerZ()));
const Vector3DUint16 v3dScaledPosition(static_cast<uint16_t>(v3dPosition.getX() * 256.0f), static_cast<uint16_t>(v3dPosition.getY() * 256.0f), static_cast<uint16_t>(v3dPosition.getZ() * 256.0f)); const Vector3DUint16 v3dScaledPosition(static_cast<uint16_t>(v3dPosition.getX() * 256.0f), static_cast<uint16_t>(v3dPosition.getY() * 256.0f), static_cast<uint16_t>(v3dPosition.getZ() * 256.0f));
Vector3DFloat v3dNormal = (n010*fInterp) + (n000*(1-fInterp)); Vector3DFloat v3dNormal = (n010*fInterp) + (n000*(1 - fInterp));
// The gradient for a voxel can be zero (e.g. solid voxel surrounded by empty ones) and so // The gradient for a voxel can be zero (e.g. solid voxel surrounded by empty ones) and so
// the interpolated normal can also be zero (e.g. a grid of alternating solid and empty voxels). // the interpolated normal can also be zero (e.g. a grid of alternating solid and empty voxels).
if(v3dNormal.lengthSquared() > 0.000001f) if (v3dNormal.lengthSquared() > 0.000001f)
{ {
v3dNormal.normalise(); v3dNormal.normalise();
} }
@ -274,10 +270,10 @@ namespace PolyVox
const Vector3DFloat v3dPosition(static_cast<float>(iXVolSpace - m_regSizeInVoxels.getLowerX()), static_cast<float>(iYVolSpace - m_regSizeInVoxels.getLowerY()), static_cast<float>(iZVolSpace - m_regSizeInVoxels.getLowerZ()) + fInterp); const Vector3DFloat v3dPosition(static_cast<float>(iXVolSpace - m_regSizeInVoxels.getLowerX()), static_cast<float>(iYVolSpace - m_regSizeInVoxels.getLowerY()), static_cast<float>(iZVolSpace - m_regSizeInVoxels.getLowerZ()) + fInterp);
const Vector3DUint16 v3dScaledPosition(static_cast<uint16_t>(v3dPosition.getX() * 256.0f), static_cast<uint16_t>(v3dPosition.getY() * 256.0f), static_cast<uint16_t>(v3dPosition.getZ() * 256.0f)); const Vector3DUint16 v3dScaledPosition(static_cast<uint16_t>(v3dPosition.getX() * 256.0f), static_cast<uint16_t>(v3dPosition.getY() * 256.0f), static_cast<uint16_t>(v3dPosition.getZ() * 256.0f));
Vector3DFloat v3dNormal = (n001*fInterp) + (n000*(1-fInterp)); Vector3DFloat v3dNormal = (n001*fInterp) + (n000*(1 - fInterp));
// The gradient for a voxel can be zero (e.g. solid voxel surrounded by empty ones) and so // The gradient for a voxel can be zero (e.g. solid voxel surrounded by empty ones) and so
// the interpolated normal can also be zero (e.g. a grid of alternating solid and empty voxels). // the interpolated normal can also be zero (e.g. a grid of alternating solid and empty voxels).
if(v3dNormal.lengthSquared() > 0.000001f) if (v3dNormal.lengthSquared() > 0.000001f)
{ {
v3dNormal.normalise(); v3dNormal.normalise();
} }
@ -298,6 +294,7 @@ namespace PolyVox
}//For each cell }//For each cell
} }
} }
}
template<typename VolumeType, typename MeshType, typename ControllerType> template<typename VolumeType, typename MeshType, typename ControllerType>
void MarchingCubesSurfaceExtractor<VolumeType, MeshType, ControllerType>::generateIndicesForSlice(const Array3DUint8& pBitmask, void MarchingCubesSurfaceExtractor<VolumeType, MeshType, ControllerType>::generateIndicesForSlice(const Array3DUint8& pBitmask,