Separated gradient estimation code.

This commit is contained in:
David Williams
2008-04-20 21:58:14 +00:00
parent 286ba35b42
commit 83d6a7327b
6 changed files with 152 additions and 157 deletions

View File

@ -131,161 +131,19 @@ namespace PolyVox
}
template <typename VoxelType>
Vector3DFloat VolumeIterator<VoxelType>::getCentralDifferenceGradient(void) const
{
//FIXME - should this test be here?
if((mXPosInVolume < 1) || (mXPosInVolume > POLYVOX_VOLUME_SIDE_LENGTH-2) ||
(mYPosInVolume < 1) || (mYPosInVolume > POLYVOX_VOLUME_SIDE_LENGTH-2) ||
(mZPosInVolume < 1) || (mZPosInVolume > POLYVOX_VOLUME_SIDE_LENGTH-2))
{
//LogManager::getSingleton().logMessage("Out of range");
return Vector3DFloat(0.0,0.0,0.0);
}
//FIXME - bitwise way of doing this?
VoxelType voxel1nx = peekVoxel1nx0py0pz() > 0 ? 1: 0;
VoxelType voxel1px = peekVoxel1px0py0pz() > 0 ? 1: 0;
VoxelType voxel1ny = peekVoxel0px1ny0pz() > 0 ? 1: 0;
VoxelType voxel1py = peekVoxel0px1py0pz() > 0 ? 1: 0;
VoxelType voxel1nz = peekVoxel0px0py1nz() > 0 ? 1: 0;
VoxelType voxel1pz = peekVoxel0px0py1pz() > 0 ? 1: 0;
return Vector3DFloat(int(voxel1px) - int(voxel1nx),int(voxel1py) - int(voxel1ny),int(voxel1pz) - int(voxel1nz));
}
template <typename VoxelType>
Vector3DFloat VolumeIterator<VoxelType>::getAveragedCentralDifferenceGradient(void) const
{
//FIXME - should this test be here?
if((mXPosInVolume < 2) || (mXPosInVolume > POLYVOX_VOLUME_SIDE_LENGTH-3) ||
(mYPosInVolume < 2) || (mYPosInVolume > POLYVOX_VOLUME_SIDE_LENGTH-3) ||
(mZPosInVolume < 2) || (mZPosInVolume > POLYVOX_VOLUME_SIDE_LENGTH-3))
{
//LogManager::getSingleton().logMessage("Out of range");
return Vector3DFloat(0.0,0.0,0.0);
}
//FIXME - bitwise way of doing this?
float voxel1nx = getAveragedVoxelAt(mXPosInVolume-1,mYPosInVolume ,mZPosInVolume, 2);
float voxel1px = getAveragedVoxelAt(mXPosInVolume+1,mYPosInVolume ,mZPosInVolume, 2);
float voxel1ny = getAveragedVoxelAt(mXPosInVolume ,mYPosInVolume-1,mZPosInVolume, 2);
float voxel1py = getAveragedVoxelAt(mXPosInVolume ,mYPosInVolume+1,mZPosInVolume, 2);
float voxel1nz = getAveragedVoxelAt(mXPosInVolume ,mYPosInVolume ,mZPosInVolume-1,2);
float voxel1pz = getAveragedVoxelAt(mXPosInVolume ,mYPosInVolume ,mZPosInVolume+1,2);
return Vector3DFloat(voxel1px - voxel1nx,voxel1py - voxel1ny,voxel1pz - voxel1nz);
}
template <typename VoxelType>
Vector3DFloat VolumeIterator<VoxelType>::getSobelGradient(void) const
{
//FIXME - should this test be here?
if((mXPosInVolume < 1) || (mXPosInVolume > POLYVOX_VOLUME_SIDE_LENGTH-2) ||
(mYPosInVolume < 1) || (mYPosInVolume > POLYVOX_VOLUME_SIDE_LENGTH-2) ||
(mZPosInVolume < 1) || (mZPosInVolume > POLYVOX_VOLUME_SIDE_LENGTH-2))
{
//LogManager::getSingleton().logMessage("Out of range");
return Vector3DFloat(0.0,0.0,0.0);
}
static const int weights[3][3][3] = { { {2,3,2}, {3,6,3}, {2,3,2} }, {
{3,6,3}, {6,0,6}, {3,6,3} }, { {2,3,2}, {3,6,3}, {2,3,2} } };
const VoxelType pVoxel1nx1ny1nz = peekVoxel1nx1ny1nz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1ny0pz = peekVoxel1nx1ny0pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1ny1pz = peekVoxel1nx1ny1pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx0py1nz = peekVoxel1nx0py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1nx0py0pz = peekVoxel1nx0py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx0py1pz = peekVoxel1nx0py1pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1py1nz = peekVoxel1nx1py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1py0pz = peekVoxel1nx1py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1py1pz = peekVoxel1nx1py1pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1ny1nz = peekVoxel0px1ny1nz() > 0 ? 1: 0;
const VoxelType pVoxel0px1ny0pz = peekVoxel0px1ny0pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1ny1pz = peekVoxel0px1ny1pz() > 0 ? 1: 0;
const VoxelType pVoxel0px0py1nz = peekVoxel0px0py1nz() > 0 ? 1: 0;
//const VoxelType pVoxel0px0py0pz = peekVoxel0px0py0pz() > 0 ? 1: 0;
const VoxelType pVoxel0px0py1pz = peekVoxel0px0py1pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1py1nz = peekVoxel0px1py1nz() > 0 ? 1: 0;
const VoxelType pVoxel0px1py0pz = peekVoxel0px1py0pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1py1pz = peekVoxel0px1py1pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1ny1nz = peekVoxel1px1ny1nz() > 0 ? 1: 0;
const VoxelType pVoxel1px1ny0pz = peekVoxel1px1ny0pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1ny1pz = peekVoxel1px1ny1pz() > 0 ? 1: 0;
const VoxelType pVoxel1px0py1nz = peekVoxel1px0py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1px0py0pz = peekVoxel1px0py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1px0py1pz = peekVoxel1px0py1pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1py1nz = peekVoxel1px1py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1px1py0pz = peekVoxel1px1py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1py1pz = peekVoxel1px1py1pz() > 0 ? 1: 0;
const int xGrad(- weights[0][0][0] * ( pVoxel1nx1ny1nz) -
weights[1][0][0] * ( pVoxel1nx1ny0pz) - weights[2][0][0] *
( pVoxel1nx1ny1pz) - weights[0][1][0] * ( pVoxel1nx0py1nz) -
weights[1][1][0] * ( pVoxel1nx0py0pz) - weights[2][1][0] *
( pVoxel1nx0py1pz) - weights[0][2][0] * ( pVoxel1nx1py1nz) -
weights[1][2][0] * ( pVoxel1nx1py0pz) - weights[2][2][0] *
( pVoxel1nx1py1pz) + weights[0][0][2] * ( pVoxel1px1ny1nz) +
weights[1][0][2] * ( pVoxel1px1ny0pz) + weights[2][0][2] *
( pVoxel1px1ny1pz) + weights[0][1][2] * ( pVoxel1px0py1nz) +
weights[1][1][2] * ( pVoxel1px0py0pz) + weights[2][1][2] *
( pVoxel1px0py1pz) + weights[0][2][2] * ( pVoxel1px1py1nz) +
weights[1][2][2] * ( pVoxel1px1py0pz) + weights[2][2][2] *
( pVoxel1px1py1pz));
const int yGrad(- weights[0][0][0] * ( pVoxel1nx1ny1nz) -
weights[1][0][0] * ( pVoxel1nx1ny0pz) - weights[2][0][0] *
( pVoxel1nx1ny1pz) + weights[0][2][0] * ( pVoxel1nx1py1nz) +
weights[1][2][0] * ( pVoxel1nx1py0pz) + weights[2][2][0] *
( pVoxel1nx1py1pz) - weights[0][0][1] * ( pVoxel0px1ny1nz) -
weights[1][0][1] * ( pVoxel0px1ny0pz) - weights[2][0][1] *
( pVoxel0px1ny1pz) + weights[0][2][1] * ( pVoxel0px1py1nz) +
weights[1][2][1] * ( pVoxel0px1py0pz) + weights[2][2][1] *
( pVoxel0px1py1pz) - weights[0][0][2] * ( pVoxel1px1ny1nz) -
weights[1][0][2] * ( pVoxel1px1ny0pz) - weights[2][0][2] *
( pVoxel1px1ny1pz) + weights[0][2][2] * ( pVoxel1px1py1nz) +
weights[1][2][2] * ( pVoxel1px1py0pz) + weights[2][2][2] *
( pVoxel1px1py1pz));
const int zGrad(- weights[0][0][0] * ( pVoxel1nx1ny1nz) +
weights[2][0][0] * ( pVoxel1nx1ny1pz) - weights[0][1][0] *
( pVoxel1nx0py1nz) + weights[2][1][0] * ( pVoxel1nx0py1pz) -
weights[0][2][0] * ( pVoxel1nx1py1nz) + weights[2][2][0] *
( pVoxel1nx1py1pz) - weights[0][0][1] * ( pVoxel0px1ny1nz) +
weights[2][0][1] * ( pVoxel0px1ny1pz) - weights[0][1][1] *
( pVoxel0px0py1nz) + weights[2][1][1] * ( pVoxel0px0py1pz) -
weights[0][2][1] * ( pVoxel0px1py1nz) + weights[2][2][1] *
( pVoxel0px1py1pz) - weights[0][0][2] * ( pVoxel1px1ny1nz) +
weights[2][0][2] * ( pVoxel1px1ny1pz) - weights[0][1][2] *
( pVoxel1px0py1nz) + weights[2][1][2] * ( pVoxel1px0py1pz) -
weights[0][2][2] * ( pVoxel1px1py1nz) + weights[2][2][2] *
( pVoxel1px1py1pz));
return Vector3DFloat(xGrad,yGrad,zGrad);
}
template <typename VoxelType>
uint16_t VolumeIterator<VoxelType>::getPosX(void)
uint16_t VolumeIterator<VoxelType>::getPosX(void) const
{
return mXPosInVolume;
}
template <typename VoxelType>
uint16_t VolumeIterator<VoxelType>::getPosY(void)
uint16_t VolumeIterator<VoxelType>::getPosY(void) const
{
return mYPosInVolume;
}
template <typename VoxelType>
uint16_t VolumeIterator<VoxelType>::getPosZ(void)
uint16_t VolumeIterator<VoxelType>::getPosZ(void) const
{
return mZPosInVolume;
}