Renamed some stuff in SurfaceExtractor.

Added functions to move samplers to adjacent voxels.
This commit is contained in:
David Williams
2009-06-06 11:52:56 +00:00
parent 6fdb11ebf4
commit 19e860d291
4 changed files with 195 additions and 92 deletions

View File

@ -44,16 +44,43 @@ namespace PolyVox
POLYVOX_SHARED_PTR<IndexedSurfacePatch> extractSurfaceForRegion(Region region);
private:
//Extract the surface for a particular LOD level
template<uint8_t uLodLevel>
void extractSurfaceImpl(void);
//Compute the cell bitmask for a particular slice in z.
template<bool isPrevZAvail, uint8_t uLodLevel>
uint32_t computeBitmaskForSlice(void);
//Compute the cell bitmask for a given cell.
template<bool isPrevXAvail, bool isPrevYAvail, bool isPrevZAvail, uint8_t uLodLevel>
void computeBitmaskForCell(void);
//Use the cell bitmasks to generate all the vertices needed for that slice
void generateVerticesForSlice();
//Use the cell bitmasks to generate all the indices needed for that slice
void generateIndicesForSlice();
//Converts a position into an index for accessing scratch areas.
inline uint32_t getIndex(uint32_t x, uint32_t y)
{
return x + (y * m_uScratchPadWidth);
}
//The lod level can step size.
uint8_t m_uLodLevel;
uint8_t m_uStepSize;
//The volume data and a sampler to access it.
Volume<uint8_t> m_volData;
VolumeSampler<uint8_t> m_sampVolume;
//Cell bitmasks for the current and previous slices.
uint8_t* m_pPreviousBitmask;
uint8_t* m_pCurrentBitmask;
//Used to keep track of where generated vertices have been placed.
int32_t* m_pPreviousVertexIndicesX;
int32_t* m_pPreviousVertexIndicesY;
int32_t* m_pPreviousVertexIndicesZ;
@ -61,57 +88,40 @@ namespace PolyVox
int32_t* m_pCurrentVertexIndicesY;
int32_t* m_pCurrentVertexIndicesZ;
uint8_t v000;
uint8_t v100;
uint8_t v010;
uint8_t v110;
uint8_t v001;
uint8_t v101;
uint8_t v011;
uint8_t v111;
//Holds a position in volume space.
uint16_t uXVolSpace;
uint16_t uYVolSpace;
uint16_t uZVolSpace;
//Holds a position in region space.
uint16_t uXRegSpace;
uint16_t uYRegSpace;
uint16_t uZRegSpace;
//Used to return the number of cells in a slice which contain triangles.
uint32_t m_uNoOfOccupiedCells;
//The surface patch we are currently filling.
IndexedSurfacePatch* m_ispCurrent;
//Remove this?
Vector3DFloat m_v3dRegionOffset;
uint16_t m_uScratchPadWidth;
uint16_t m_uScratchPadHeight;
//Information about the region we a re currently processing
Region m_Region;
Region m_UncroppedRegion;
Region m_croppedVolume;
Region regSlice0;
Region regSlice1;
Region m_regSlicePrevious;
Region m_regSliceCurrent;
//Store the width and height because they are frequently
//used and have some overhead to compute.
uint16_t m_uRegionWidth;
uint16_t m_uRegionHeight;
inline uint32_t getIndex(uint32_t x, uint32_t y)
{
return x + (y * m_uScratchPadWidth);
}
template<uint8_t uLodLevel>
void extractSurfaceImpl(void);
template<bool isPrevZAvail, uint8_t uLodLevel>
uint32_t computeBitmaskForSlice(void);
template<bool isPrevXAvail, bool isPrevYAvail, bool isPrevZAvail, uint8_t uLodLevel>
void computeBitmaskForCell(void);
void generateIndicesForSlice();
void generateVerticesForSlice();
//These are used in several places so best stored.
uint16_t m_uScratchPadWidth;
uint16_t m_uScratchPadHeight;
};
}

View File

@ -54,6 +54,12 @@ namespace PolyVox
void setPosition(uint16_t xPos, uint16_t yPos, uint16_t zPos);
void movePositiveX(void);
void movePositiveY(void);
void movePositiveZ(void);
void moveNegativeX(void);
void moveNegativeY(void);
void moveNegativeZ(void);
inline VoxelType peekVoxel1nx1ny1nz(void) const;
inline VoxelType peekVoxel1nx1ny0pz(void) const;
@ -95,20 +101,8 @@ namespace PolyVox
uint16_t mYPosInVolume;
uint16_t mZPosInVolume;
//The position of the current block
uint16_t mXBlock;
uint16_t mYBlock;
uint16_t mZBlock;
//The offset into the current block
uint16_t mXPosInBlock;
uint16_t mYPosInBlock;
uint16_t mZPosInBlock;
//Other current position information
VoxelType* mCurrentVoxel;
uint32_t mBlockIndexInVolume;
uint32_t mVoxelIndexInBlock;
};
}

View File

@ -190,24 +190,23 @@ namespace PolyVox
mYPosInVolume = yPos;
mZPosInVolume = zPos;
mXBlock = mXPosInVolume >> mVolume.m_uBlockSideLengthPower;
mYBlock = mYPosInVolume >> mVolume.m_uBlockSideLengthPower;
mZBlock = mZPosInVolume >> mVolume.m_uBlockSideLengthPower;
uint16_t uXBlock = mXPosInVolume >> mVolume.m_uBlockSideLengthPower;
uint16_t uYBlock = mYPosInVolume >> mVolume.m_uBlockSideLengthPower;
uint16_t uZBlock = mZPosInVolume >> mVolume.m_uBlockSideLengthPower;
mXPosInBlock = mXPosInVolume - (mXBlock << mVolume.m_uBlockSideLengthPower);
mYPosInBlock = mYPosInVolume - (mYBlock << mVolume.m_uBlockSideLengthPower);
mZPosInBlock = mZPosInVolume - (mZBlock << mVolume.m_uBlockSideLengthPower);
uint16_t uXPosInBlock = mXPosInVolume - (uXBlock << mVolume.m_uBlockSideLengthPower);
uint16_t uYPosInBlock = mYPosInVolume - (uYBlock << mVolume.m_uBlockSideLengthPower);
uint16_t uZPosInBlock = mZPosInVolume - (uZBlock << mVolume.m_uBlockSideLengthPower);
mBlockIndexInVolume = mXBlock +
mYBlock * mVolume.m_uWidthInBlocks +
mZBlock * mVolume.m_uWidthInBlocks * mVolume.m_uHeightInBlocks;
POLYVOX_SHARED_PTR< Block<VoxelType> > currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
uint32_t uBlockIndexInVolume = uXBlock +
uYBlock * mVolume.m_uWidthInBlocks +
uZBlock * mVolume.m_uWidthInBlocks * mVolume.m_uHeightInBlocks;
POLYVOX_SHARED_PTR< Block<VoxelType> > currentBlock = mVolume.m_pBlocks[uBlockIndexInVolume];
mVoxelIndexInBlock = mXPosInBlock +
mYPosInBlock * mVolume.m_uBlockSideLength +
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
uint32_t uVoxelIndexInBlock = uXPosInBlock +
uYPosInBlock * mVolume.m_uBlockSideLength +
uZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
mCurrentVoxel = currentBlock->m_tData + uVoxelIndexInBlock;
}
#pragma endregion
@ -215,17 +214,108 @@ namespace PolyVox
template <typename VoxelType>
void VolumeSampler<VoxelType>::movePositiveX(void)
{
++mXPosInVolume;
if(mXPosInVolume % mVolume.m_uBlockSideLength == 0)
assert(mXPosInVolume < mVolume.m_uWidth - 1);
//Note the *post* increament here
if((mXPosInVolume++) % mVolume.m_uBlockSideLength == 0)
{
//No need to compute new block.
++mCurrentVoxel;
}
else
{
//We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this.
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
else
}
template <typename VoxelType>
void VolumeSampler<VoxelType>::movePositiveY(void)
{
assert(mYPosInVolume < mVolume.m_uHeight - 1);
//Note the *post* increament here
if((mYPosInVolume++) % mVolume.m_uBlockSideLength == 0)
{
//No need to compute new block.
++mVoxelIndexInBlock;
++mCurrentVoxel;
mCurrentVoxel += mVolume.m_uBlockSideLength;
}
else
{
//We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this.
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
}
template <typename VoxelType>
void VolumeSampler<VoxelType>::movePositiveZ(void)
{
assert(mZPosInVolume < mVolume.m_uDepth - 1);
//Note the *post* increament here
if((mZPosInVolume++) % mVolume.m_uBlockSideLength == 0)
{
//No need to compute new block.
mCurrentVoxel += mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
}
else
{
//We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this.
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
}
template <typename VoxelType>
void VolumeSampler<VoxelType>::moveNegativeX(void)
{
assert(mXPosInVolume > 0);
//Note the *pre* increament here
if((--mXPosInVolume) % mVolume.m_uBlockSideLength == 0)
{
//No need to compute new block.
++mCurrentVoxel;
}
else
{
//We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this.
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
}
template <typename VoxelType>
void VolumeSampler<VoxelType>::moveNegativeY(void)
{
assert(mYPosInVolume > 0);
//Note the *pre* increament here
if((--mYPosInVolume) % mVolume.m_uBlockSideLength == 0)
{
//No need to compute new block.
mCurrentVoxel += mVolume.m_uBlockSideLength;
}
else
{
//We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this.
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
}
template <typename VoxelType>
void VolumeSampler<VoxelType>::moveNegativeZ(void)
{
assert(mZPosInVolume > 0);
//Note the *pre* increament here
if((--mZPosInVolume) % mVolume.m_uBlockSideLength == 0)
{
//No need to compute new block.
mCurrentVoxel += mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
}
else
{
//We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this.
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
}
#pragma endregion