More work on new marching cubes implementation, including addition of 'computeBitmaskForSlice()' function.

This commit is contained in:
David Williams
2008-06-05 17:45:53 +00:00
parent 1c23f2d1dd
commit 63b2c5ccb0
2 changed files with 52 additions and 80 deletions

View File

@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define __PolyVox_SurfaceExtractors_H__
#pragma region Headers
#include "Constants.h"
#include "PolyVoxForwardDeclarations.h"
#include "TypeDef.h"
@ -37,6 +38,7 @@ namespace PolyVox
POLYVOX_API void generateExperimentalMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
POLYVOX_API void generateExperimentalMeshDataForRegionSlice(BlockVolumeIterator<boost::uint8_t>& volIter, Region regTwoSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset);
POLYVOX_API void computeBitmaskForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, Region& regSlice, const Vector3DFloat& offset, boost::uint8_t bitmask[][POLYVOX_REGION_SIDE_LENGTH+1]);
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);

View File

@ -85,8 +85,10 @@ namespace PolyVox
memset(vertexIndicesZ,0xFF,sizeof(vertexIndicesZ));
//Cell bitmasks
boost::uint8_t bitmask[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][2];
memset(bitmask, 0x00, sizeof(bitmask));
boost::uint8_t bitmask0[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];
boost::uint8_t bitmask1[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];
memset(bitmask0, 0x00, sizeof(bitmask0));
memset(bitmask1, 0x00, sizeof(bitmask1));
Region regFirstSlice(regTwoSlice);
regFirstSlice.setUpperCorner(regFirstSlice.getUpperCorner() - Vector3DInt32(0,0,1));
@ -97,81 +99,8 @@ namespace PolyVox
// Compute bitmasks
//////////////////////////////////////////////////////////////////////////
//Iterate over each cell in the region
volIter.setPosition(regFirstSlice.getLowerCorner().getX(),regFirstSlice.getLowerCorner().getY(), regFirstSlice.getLowerCorner().getZ());
volIter.setValidRegion(regFirstSlice);
do
//while(volIter.moveForwardInRegionXYZ())
{
//Current position
const uint16_t x = volIter.getPosX() - offset.getX();
const uint16_t y = volIter.getPosY() - offset.getY();
const uint16_t z = volIter.getPosZ() - offset.getZ();
//Voxels values
const uint8_t v000 = volIter.getVoxel();
const uint8_t v100 = volIter.peekVoxel1px0py0pz();
const uint8_t v010 = volIter.peekVoxel0px1py0pz();
const uint8_t v110 = volIter.peekVoxel1px1py0pz();
const uint8_t v001 = volIter.peekVoxel0px0py1pz();
const uint8_t v101 = volIter.peekVoxel1px0py1pz();
const uint8_t v011 = volIter.peekVoxel0px1py1pz();
const uint8_t v111 = volIter.peekVoxel1px1py1pz();
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8_t iCubeIndex = 0;
if (v000 == 0) iCubeIndex |= 1;
if (v100 == 0) iCubeIndex |= 2;
if (v110 == 0) iCubeIndex |= 4;
if (v010 == 0) iCubeIndex |= 8;
if (v001 == 0) iCubeIndex |= 16;
if (v101 == 0) iCubeIndex |= 32;
if (v111 == 0) iCubeIndex |= 64;
if (v011 == 0) iCubeIndex |= 128;
//Save the bitmask
bitmask[x][y][0] = iCubeIndex;
}while(volIter.moveForwardInRegionXYZ());//For each cell
//Iterate over each cell in the region
volIter.setPosition(regSecondSlice.getLowerCorner().getX(),regSecondSlice.getLowerCorner().getY(), regSecondSlice.getLowerCorner().getZ());
volIter.setValidRegion(regSecondSlice);
do
//while(volIter.moveForwardInRegionXYZ())
{
//Current position
const uint16_t x = volIter.getPosX() - offset.getX();
const uint16_t y = volIter.getPosY() - offset.getY();
const uint16_t z = volIter.getPosZ() - offset.getZ();
//Voxels values
const uint8_t v000 = volIter.getVoxel();
const uint8_t v100 = volIter.peekVoxel1px0py0pz();
const uint8_t v010 = volIter.peekVoxel0px1py0pz();
const uint8_t v110 = volIter.peekVoxel1px1py0pz();
const uint8_t v001 = volIter.peekVoxel0px0py1pz();
const uint8_t v101 = volIter.peekVoxel1px0py1pz();
const uint8_t v011 = volIter.peekVoxel0px1py1pz();
const uint8_t v111 = volIter.peekVoxel1px1py1pz();
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8_t iCubeIndex = 0;
if (v000 == 0) iCubeIndex |= 1;
if (v100 == 0) iCubeIndex |= 2;
if (v110 == 0) iCubeIndex |= 4;
if (v010 == 0) iCubeIndex |= 8;
if (v001 == 0) iCubeIndex |= 16;
if (v101 == 0) iCubeIndex |= 32;
if (v111 == 0) iCubeIndex |= 64;
if (v011 == 0) iCubeIndex |= 128;
//Save the bitmask
bitmask[x][y][1] = iCubeIndex;
}while(volIter.moveForwardInRegionXYZ());//For each cell
computeBitmaskForSlice(volIter, regFirstSlice, offset, bitmask0);
computeBitmaskForSlice(volIter, regSecondSlice, offset, bitmask1);
//////////////////////////////////////////////////////////////////////////
//Get mesh data
@ -194,7 +123,7 @@ namespace PolyVox
const uint8_t v000 = volIter.getVoxel();
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8_t iCubeIndex = bitmask[x][y][0];
uint8_t iCubeIndex = bitmask0[x][y];
/* Cube is entirely in/out of the surface */
if (edgeTable[iCubeIndex] == 0)
@ -258,7 +187,7 @@ namespace PolyVox
const uint8_t v000 = volIter.getVoxel();
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8_t iCubeIndex = bitmask[x][y][1];
uint8_t iCubeIndex = bitmask1[x][y];
/* Cube is entirely in/out of the surface */
if (edgeTable[iCubeIndex] == 0)
@ -326,7 +255,7 @@ namespace PolyVox
const uint16_t z = volIter.getPosZ() - offset.getZ();
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8_t iCubeIndex = bitmask[x][y][0];
uint8_t iCubeIndex = bitmask0[x][y];
/* Cube is entirely in/out of the surface */
if (edgeTable[iCubeIndex] == 0)
@ -409,6 +338,47 @@ namespace PolyVox
}while(volIter.moveForwardInRegionXYZ());//For each cell
}
void computeBitmaskForSlice(BlockVolumeIterator<uint8_t>& volIter, Region& regSlice, const Vector3DFloat& offset, uint8_t bitmask[][POLYVOX_REGION_SIDE_LENGTH+1])
{
//Iterate over each cell in the region
volIter.setPosition(regSlice.getLowerCorner().getX(),regSlice.getLowerCorner().getY(), regSlice.getLowerCorner().getZ());
volIter.setValidRegion(regSlice);
do
//while(volIter.moveForwardInRegionXYZ())
{
//Current position
const uint16_t x = volIter.getPosX() - offset.getX();
const uint16_t y = volIter.getPosY() - offset.getY();
const uint16_t z = volIter.getPosZ() - offset.getZ();
//Voxels values
const uint8_t v000 = volIter.getVoxel();
const uint8_t v100 = volIter.peekVoxel1px0py0pz();
const uint8_t v010 = volIter.peekVoxel0px1py0pz();
const uint8_t v110 = volIter.peekVoxel1px1py0pz();
const uint8_t v001 = volIter.peekVoxel0px0py1pz();
const uint8_t v101 = volIter.peekVoxel1px0py1pz();
const uint8_t v011 = volIter.peekVoxel0px1py1pz();
const uint8_t v111 = volIter.peekVoxel1px1py1pz();
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8_t iCubeIndex = 0;
if (v000 == 0) iCubeIndex |= 1;
if (v100 == 0) iCubeIndex |= 2;
if (v110 == 0) iCubeIndex |= 4;
if (v010 == 0) iCubeIndex |= 8;
if (v001 == 0) iCubeIndex |= 16;
if (v101 == 0) iCubeIndex |= 32;
if (v111 == 0) iCubeIndex |= 64;
if (v011 == 0) iCubeIndex |= 128;
//Save the bitmask
bitmask[x][y] = iCubeIndex;
}while(volIter.moveForwardInRegionXYZ());//For each cell
}
void generateRoughMeshDataForRegion(BlockVolume<uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch)
{
//When generating the mesh for a region we actually look one voxel outside it in the