Decimation now handles level 0 and level 1. Crashes on level 2...
This commit is contained in:
parent
e019c92dc2
commit
eed6d56cb6
@ -44,7 +44,7 @@ namespace PolyVox
|
||||
bool operator>=(const BlockVolumeIterator& rhs);
|
||||
|
||||
float getAveragedVoxel(boost::uint16_t size) const;
|
||||
VoxelType getMaxedVoxel(boost::uint8_t level) const;
|
||||
VoxelType getMaxedVoxel(boost::uint8_t uLevel) const;
|
||||
boost::uint16_t getPosX(void) const;
|
||||
boost::uint16_t getPosY(void) const;
|
||||
boost::uint16_t getPosZ(void) const;
|
||||
|
@ -137,13 +137,13 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
VoxelType BlockVolumeIterator<VoxelType>::getMaxedVoxel(boost::uint8_t level) const
|
||||
VoxelType BlockVolumeIterator<VoxelType>::getMaxedVoxel(boost::uint8_t uLevel) const
|
||||
{
|
||||
if(level == 0)
|
||||
if(uLevel == 0)
|
||||
{
|
||||
return getVoxel();
|
||||
}
|
||||
else if(level == 1)
|
||||
else if(uLevel == 1)
|
||||
{
|
||||
VoxelType tValue = getVoxel();
|
||||
tValue = (std::max)(tValue, peekVoxel1px0py0pz());
|
||||
@ -155,8 +155,23 @@ namespace PolyVox
|
||||
tValue = (std::max)(tValue, peekVoxel1px1py1pz());
|
||||
return tValue;
|
||||
}
|
||||
assert(false);
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
const boost::uint8_t uSize = 1 << uLevel;
|
||||
|
||||
VoxelType tValue = 0;
|
||||
for(boost::uint8_t z = 0; z < uSize; ++z)
|
||||
{
|
||||
for(boost::uint8_t y = 0; y < uSize; ++y)
|
||||
{
|
||||
for(boost::uint8_t x = 0; x < uSize; ++x)
|
||||
{
|
||||
tValue = (std::max)(tValue, mVolume.getVoxelAt(mXPosInVolume + x, mYPosInVolume + y, mZPosInVolume + z));
|
||||
}
|
||||
}
|
||||
}
|
||||
return tValue;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
|
@ -39,8 +39,8 @@ namespace PolyVox
|
||||
POLYVOX_API void generateDecimatedMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, boost::uint8_t uLevel, Region region, IndexedSurfacePatch* singleMaterialPatch);
|
||||
POLYVOX_API boost::uint32_t computeInitialDecimatedBitmaskForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, boost::uint8_t uLevel, const Region& regSlice, const Vector3DFloat& offset, boost::uint8_t *bitmask);
|
||||
POLYVOX_API boost::uint32_t computeDecimatedBitmaskForSliceFromPrevious(BlockVolumeIterator<boost::uint8_t>& volIter, boost::uint8_t uLevel, const Region& regSlice, const Vector3DFloat& offset, boost::uint8_t *bitmask, boost::uint8_t *previousBitmask);
|
||||
POLYVOX_API void generateDecimatedIndicesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, boost::uint8_t* bitmask0, boost::uint8_t* bitmask1, boost::int32_t vertexIndicesX0[],boost::int32_t vertexIndicesY0[],boost::int32_t vertexIndicesZ0[], boost::int32_t vertexIndicesX1[],boost::int32_t vertexIndicesY1[],boost::int32_t vertexIndicesZ1[]);
|
||||
POLYVOX_API void generateDecimatedVerticesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, Region& regSlice, const Vector3DFloat& offset, boost::uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,boost::int32_t vertexIndicesX[],boost::int32_t vertexIndicesY[],boost::int32_t vertexIndicesZ[]);
|
||||
POLYVOX_API void generateDecimatedIndicesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, boost::uint8_t uLevel, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, boost::uint8_t* bitmask0, boost::uint8_t* bitmask1, boost::int32_t vertexIndicesX0[],boost::int32_t vertexIndicesY0[],boost::int32_t vertexIndicesZ0[], boost::int32_t vertexIndicesX1[],boost::int32_t vertexIndicesY1[],boost::int32_t vertexIndicesZ1[]);
|
||||
POLYVOX_API void generateDecimatedVerticesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, boost::uint8_t uLevel, Region& regSlice, const Vector3DFloat& offset, boost::uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,boost::int32_t vertexIndicesX[],boost::int32_t vertexIndicesY[],boost::int32_t vertexIndicesZ[]);
|
||||
|
||||
POLYVOX_API void generateDecimatedMeshDataForRegionSlow(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
|
||||
|
||||
|
@ -29,7 +29,7 @@ namespace PolyVox
|
||||
regionGeometry.m_patchSingleMaterial = new IndexedSurfacePatch(false);
|
||||
regionGeometry.m_v3dRegionPosition = iterChangedRegions->getLowerCorner();
|
||||
|
||||
generateDecimatedMeshDataForRegion(volume.getVolumeData(), 1, *iterChangedRegions, regionGeometry.m_patchSingleMaterial);
|
||||
generateDecimatedMeshDataForRegion(volume.getVolumeData(), 0, *iterChangedRegions, regionGeometry.m_patchSingleMaterial);
|
||||
|
||||
//genMultiFromSingle(regionGeometry.m_patchSingleMaterial, regionGeometry.m_patchMultiMaterial);
|
||||
|
||||
|
@ -37,7 +37,7 @@ namespace PolyVox
|
||||
boost::uint8_t* bitmask0 = new boost::uint8_t[(POLYVOX_REGION_SIDE_LENGTH+1) * (POLYVOX_REGION_SIDE_LENGTH+1)];
|
||||
boost::uint8_t* bitmask1 = new boost::uint8_t[(POLYVOX_REGION_SIDE_LENGTH+1) * (POLYVOX_REGION_SIDE_LENGTH+1)];
|
||||
|
||||
const uint8_t uStepSize = 1 << uLevel;
|
||||
const uint8_t uStepSize = uLevel == 0 ? 1 : 1 << uLevel;
|
||||
|
||||
//When generating the mesh for a region we actually look one voxel outside it in the
|
||||
// back, bottom, right direction. Protect against access violations by cropping region here
|
||||
@ -62,24 +62,24 @@ namespace PolyVox
|
||||
if(uNoOfNonEmptyCellsForSlice0 != 0)
|
||||
{
|
||||
//If there were some non-empty cells then generate initial slice vertices for them
|
||||
generateDecimatedVerticesForSlice(volIter,regSlice0, offset, bitmask0, singleMaterialPatch, vertexIndicesX0, vertexIndicesY0, vertexIndicesZ0);
|
||||
generateDecimatedVerticesForSlice(volIter, uLevel, regSlice0, offset, bitmask0, singleMaterialPatch, vertexIndicesX0, vertexIndicesY0, vertexIndicesZ0);
|
||||
}
|
||||
|
||||
for(boost::uint32_t uSlice = 0; ((uSlice <= POLYVOX_REGION_SIDE_LENGTH-1) && (uSlice + offset.getZ() < region.getUpperCorner().getZ())); uSlice += 2)
|
||||
for(boost::uint32_t uSlice = 0; ((uSlice <= POLYVOX_REGION_SIDE_LENGTH-1) && (uSlice + offset.getZ() < region.getUpperCorner().getZ())); uSlice += uStepSize)
|
||||
{
|
||||
Region regSlice1(regSlice0);
|
||||
regSlice1.shift(Vector3DInt32(0,0,2));
|
||||
regSlice1.shift(Vector3DInt32(0,0,uStepSize));
|
||||
|
||||
boost::uint32_t uNoOfNonEmptyCellsForSlice1 = computeDecimatedBitmaskForSliceFromPrevious(volIter, uLevel, regSlice1, offset, bitmask1, bitmask0);
|
||||
|
||||
if(uNoOfNonEmptyCellsForSlice1 != 0)
|
||||
{
|
||||
generateDecimatedVerticesForSlice(volIter,regSlice1, offset, bitmask1, singleMaterialPatch, vertexIndicesX1, vertexIndicesY1, vertexIndicesZ1);
|
||||
generateDecimatedVerticesForSlice(volIter, uLevel, regSlice1, offset, bitmask1, singleMaterialPatch, vertexIndicesX1, vertexIndicesY1, vertexIndicesZ1);
|
||||
}
|
||||
|
||||
if((uNoOfNonEmptyCellsForSlice0 != 0) || (uNoOfNonEmptyCellsForSlice1 != 0))
|
||||
{
|
||||
generateDecimatedIndicesForSlice(volIter, regSlice0, singleMaterialPatch, offset, bitmask0, bitmask1, vertexIndicesX0, vertexIndicesY0, vertexIndicesZ0, vertexIndicesX1, vertexIndicesY1, vertexIndicesZ1);
|
||||
generateDecimatedIndicesForSlice(volIter, uLevel, regSlice0, singleMaterialPatch, offset, bitmask0, bitmask1, vertexIndicesX0, vertexIndicesY0, vertexIndicesZ0, vertexIndicesX1, vertexIndicesY1, vertexIndicesZ1);
|
||||
}
|
||||
|
||||
std::swap(uNoOfNonEmptyCellsForSlice0, uNoOfNonEmptyCellsForSlice1);
|
||||
@ -112,7 +112,7 @@ namespace PolyVox
|
||||
|
||||
boost::uint32_t computeInitialDecimatedBitmaskForSlice(BlockVolumeIterator<uint8_t>& volIter, uint8_t uLevel, const Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask)
|
||||
{
|
||||
const uint8_t uStepSize = 1 << uLevel;
|
||||
const uint8_t uStepSize = uLevel == 0 ? 1 : 1 << uLevel;
|
||||
boost::uint32_t uNoOfNonEmptyCells = 0;
|
||||
|
||||
//Iterate over each cell in the region
|
||||
@ -281,7 +281,7 @@ namespace PolyVox
|
||||
|
||||
boost::uint32_t computeDecimatedBitmaskForSliceFromPrevious(BlockVolumeIterator<uint8_t>& volIter, uint8_t uLevel, const Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask, uint8_t* previousBitmask)
|
||||
{
|
||||
const uint8_t uStepSize = 1 << uLevel;
|
||||
const uint8_t uStepSize = uLevel == 0 ? 1 : 1 << uLevel;
|
||||
boost::uint32_t uNoOfNonEmptyCells = 0;
|
||||
|
||||
//Iterate over each cell in the region
|
||||
@ -405,179 +405,168 @@ namespace PolyVox
|
||||
return uNoOfNonEmptyCells;
|
||||
}
|
||||
|
||||
void generateDecimatedVerticesForSlice(BlockVolumeIterator<uint8_t>& volIter, Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,boost::int32_t vertexIndicesX[],boost::int32_t vertexIndicesY[],boost::int32_t vertexIndicesZ[])
|
||||
void generateDecimatedVerticesForSlice(BlockVolumeIterator<uint8_t>& volIter, uint8_t uLevel, Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,boost::int32_t vertexIndicesX[],boost::int32_t vertexIndicesY[],boost::int32_t vertexIndicesZ[])
|
||||
{
|
||||
const uint8_t uStepSize = uLevel == 0 ? 1 : 1 << uLevel;
|
||||
|
||||
//Iterate over each cell in the region
|
||||
//volIter.setPosition(regSlice.getLowerCorner().getX(),regSlice.getLowerCorner().getY(), regSlice.getLowerCorner().getZ());
|
||||
//volIter.setValidRegion(regSlice);
|
||||
//while(volIter.moveForwardInRegionXYZ())
|
||||
//do
|
||||
for(uint16_t y = regSlice.getLowerCorner().getY(); y < regSlice.getUpperCorner().getY()+1; y += 2)
|
||||
for(uint16_t y = regSlice.getLowerCorner().getY(); y <= regSlice.getUpperCorner().getY(); y += uStepSize)
|
||||
{
|
||||
for(uint16_t x = regSlice.getLowerCorner().getX(); x < regSlice.getUpperCorner().getX()+1; x += 2)
|
||||
{
|
||||
//Current position
|
||||
//const uint16_t x = volIter.getPosX() - offset.getX();
|
||||
//const uint16_t y = volIter.getPosY() - offset.getY();
|
||||
const uint16_t z = regSlice.getLowerCorner().getZ();
|
||||
for(uint16_t x = regSlice.getLowerCorner().getX(); x <= regSlice.getUpperCorner().getX(); x += uStepSize)
|
||||
{
|
||||
//Current position
|
||||
const uint16_t z = regSlice.getLowerCorner().getZ();
|
||||
|
||||
volIter.setPosition(x,y,z);
|
||||
const uint8_t v000 = volIter.getMaxedVoxel(1);
|
||||
volIter.setPosition(x,y,z);
|
||||
const uint8_t v000 = volIter.getMaxedVoxel(uLevel);
|
||||
|
||||
//Determine the index into the edge table which tells us which vertices are inside of the surface
|
||||
uint8_t iCubeIndex = bitmask[getDecimatedIndex(x - offset.getX(),y - offset.getY())];
|
||||
//Determine the index into the edge table which tells us which vertices are inside of the surface
|
||||
uint8_t iCubeIndex = bitmask[getDecimatedIndex(x - offset.getX(),y - offset.getY())];
|
||||
|
||||
/* Cube is entirely in/out of the surface */
|
||||
if (edgeTable[iCubeIndex] == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Find the vertices where the surface intersects the cube */
|
||||
if (edgeTable[iCubeIndex] & 1)
|
||||
{
|
||||
if((x) != regSlice.getUpperCorner().getX())
|
||||
/* Cube is entirely in/out of the surface */
|
||||
if (edgeTable[iCubeIndex] == 0)
|
||||
{
|
||||
const Vector3DFloat v3dPosition(x - offset.getX() + 0.5f * 2.0f, y - offset.getY(), z - offset.getZ());
|
||||
const Vector3DFloat v3dNormal(1.0,0.0,0.0);
|
||||
volIter.setPosition(x+2,y,z);
|
||||
const uint8_t uMaterial = v000 | volIter.getMaxedVoxel(1); //Because one of these is 0, the or operation takes the max.
|
||||
SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial, 1.0);
|
||||
singleMaterialPatch->m_vecVertices.push_back(surfaceVertex);
|
||||
vertexIndicesX[getDecimatedIndex(x - offset.getX(),y - offset.getY())] = singleMaterialPatch->m_vecVertices.size()-1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 8)
|
||||
{
|
||||
if((y) != regSlice.getUpperCorner().getY())
|
||||
|
||||
/* Find the vertices where the surface intersects the cube */
|
||||
if (edgeTable[iCubeIndex] & 1)
|
||||
{
|
||||
const Vector3DFloat v3dPosition(x - offset.getX(), y - offset.getY() + 0.5f * 2.0f, z - offset.getZ());
|
||||
const Vector3DFloat v3dNormal(0.0,1.0,0.0);
|
||||
volIter.setPosition(x,y+2,z);
|
||||
const uint8_t uMaterial = v000 | volIter.getMaxedVoxel(1); //Because one of these is 0, the or operation takes the max.
|
||||
SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial, 1.0);
|
||||
singleMaterialPatch->m_vecVertices.push_back(surfaceVertex);
|
||||
vertexIndicesY[getDecimatedIndex(x - offset.getX(),y - offset.getY())] = singleMaterialPatch->m_vecVertices.size()-1;
|
||||
if(x != regSlice.getUpperCorner().getX())
|
||||
{
|
||||
const Vector3DFloat v3dPosition(x - offset.getX() + 0.5f * uStepSize, y - offset.getY(), z - offset.getZ());
|
||||
const Vector3DFloat v3dNormal(1.0,0.0,0.0);
|
||||
volIter.setPosition(x+uStepSize,y,z);
|
||||
const uint8_t uMaterial = v000 | volIter.getMaxedVoxel(uLevel); //Because one of these is 0, the or operation takes the max.
|
||||
SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial, 1.0);
|
||||
singleMaterialPatch->m_vecVertices.push_back(surfaceVertex);
|
||||
vertexIndicesX[getDecimatedIndex(x - offset.getX(),y - offset.getY())] = singleMaterialPatch->m_vecVertices.size()-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 256)
|
||||
{
|
||||
//if((z + offset.getZ()) != upperCorner.getZ())
|
||||
if (edgeTable[iCubeIndex] & 8)
|
||||
{
|
||||
const Vector3DFloat v3dPosition(x - offset.getX(), y - offset.getY(), z - offset.getZ() + 0.5f * 2.0f);
|
||||
const Vector3DFloat v3dNormal(0.0,0.0,1.0);
|
||||
volIter.setPosition(x,y,z+2);
|
||||
const uint8_t uMaterial = v000 | volIter.getMaxedVoxel(1); //Because one of these is 0, the or operation takes the max.
|
||||
const SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial, 1.0);
|
||||
singleMaterialPatch->m_vecVertices.push_back(surfaceVertex);
|
||||
vertexIndicesZ[getDecimatedIndex(x - offset.getX(),y - offset.getY())] = singleMaterialPatch->m_vecVertices.size()-1;
|
||||
if(y != regSlice.getUpperCorner().getY())
|
||||
{
|
||||
const Vector3DFloat v3dPosition(x - offset.getX(), y - offset.getY() + 0.5f * uStepSize, z - offset.getZ());
|
||||
const Vector3DFloat v3dNormal(0.0,1.0,0.0);
|
||||
volIter.setPosition(x,y+uStepSize,z);
|
||||
const uint8_t uMaterial = v000 | volIter.getMaxedVoxel(uLevel); //Because one of these is 0, the or operation takes the max.
|
||||
SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial, 1.0);
|
||||
singleMaterialPatch->m_vecVertices.push_back(surfaceVertex);
|
||||
vertexIndicesY[getDecimatedIndex(x - offset.getX(),y - offset.getY())] = singleMaterialPatch->m_vecVertices.size()-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}//while(volIter.moveForwardInRegionXYZ());//For each cell
|
||||
if (edgeTable[iCubeIndex] & 256)
|
||||
{
|
||||
//if(z != regSlice.getUpperCorner.getZ())
|
||||
{
|
||||
const Vector3DFloat v3dPosition(x - offset.getX(), y - offset.getY(), z - offset.getZ() + 0.5f * uStepSize);
|
||||
const Vector3DFloat v3dNormal(0.0,0.0,1.0);
|
||||
volIter.setPosition(x,y,z+uStepSize);
|
||||
const uint8_t uMaterial = v000 | volIter.getMaxedVoxel(uLevel); //Because one of these is 0, the or operation takes the max.
|
||||
const SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial, 1.0);
|
||||
singleMaterialPatch->m_vecVertices.push_back(surfaceVertex);
|
||||
vertexIndicesZ[getDecimatedIndex(x - offset.getX(),y - offset.getY())] = singleMaterialPatch->m_vecVertices.size()-1;
|
||||
}
|
||||
}
|
||||
}//For each cell
|
||||
}
|
||||
}
|
||||
|
||||
void generateDecimatedIndicesForSlice(BlockVolumeIterator<uint8_t>& volIter, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, uint8_t* bitmask0, uint8_t* bitmask1, boost::int32_t vertexIndicesX0[],boost::int32_t vertexIndicesY0[],boost::int32_t vertexIndicesZ0[], boost::int32_t vertexIndicesX1[],boost::int32_t vertexIndicesY1[],boost::int32_t vertexIndicesZ1[])
|
||||
void generateDecimatedIndicesForSlice(BlockVolumeIterator<uint8_t>& volIter, uint8_t uLevel, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, uint8_t* bitmask0, uint8_t* bitmask1, boost::int32_t vertexIndicesX0[],boost::int32_t vertexIndicesY0[],boost::int32_t vertexIndicesZ0[], boost::int32_t vertexIndicesX1[],boost::int32_t vertexIndicesY1[],boost::int32_t vertexIndicesZ1[])
|
||||
{
|
||||
const uint8_t uStepSize = uLevel == 0 ? 1 : 1 << uLevel;
|
||||
boost::uint32_t indlist[12];
|
||||
|
||||
Region regCroppedSlice(regSlice);
|
||||
regCroppedSlice.setUpperCorner(regCroppedSlice.getUpperCorner() - Vector3DInt32(2,2,0));
|
||||
|
||||
//volIter.setPosition(regCroppedSlice.getLowerCorner().getX(),regCroppedSlice.getLowerCorner().getY(), regCroppedSlice.getLowerCorner().getZ());
|
||||
//volIter.setValidRegion(regCroppedSlice);
|
||||
//do
|
||||
for(uint16_t y = regCroppedSlice.getLowerCorner().getY() - offset.getY(); y <= regCroppedSlice.getUpperCorner().getY() - offset.getY(); y += 2)
|
||||
for(uint16_t y = regSlice.getLowerCorner().getY() - offset.getY(); y < regSlice.getUpperCorner().getY() - offset.getY(); y += uStepSize)
|
||||
{
|
||||
for(uint16_t x = regCroppedSlice.getLowerCorner().getX() - offset.getX(); x <= regCroppedSlice.getUpperCorner().getX() - offset.getX(); x += 2)
|
||||
{
|
||||
//Current position
|
||||
//const uint16_t x = volIter.getPosX() - offset.getX();
|
||||
//const uint16_t y = volIter.getPosY() - offset.getY();
|
||||
const uint16_t z = regCroppedSlice.getLowerCorner().getZ() - offset.getZ();
|
||||
for(uint16_t x = regSlice.getLowerCorner().getX() - offset.getX(); x < regSlice.getUpperCorner().getX() - offset.getX(); x += uStepSize)
|
||||
{
|
||||
//Current position
|
||||
const uint16_t z = regSlice.getLowerCorner().getZ() - offset.getZ();
|
||||
|
||||
//Determine the index into the edge table which tells us which vertices are inside of the surface
|
||||
uint8_t iCubeIndex = bitmask0[getDecimatedIndex(x,y)];
|
||||
//Determine the index into the edge table which tells us which vertices are inside of the surface
|
||||
uint8_t iCubeIndex = bitmask0[getDecimatedIndex(x,y)];
|
||||
|
||||
/* Cube is entirely in/out of the surface */
|
||||
if (edgeTable[iCubeIndex] == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
/* Cube is entirely in/out of the surface */
|
||||
if (edgeTable[iCubeIndex] == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Find the vertices where the surface intersects the cube */
|
||||
if (edgeTable[iCubeIndex] & 1)
|
||||
{
|
||||
indlist[0] = vertexIndicesX0[getDecimatedIndex(x,y)];
|
||||
assert(indlist[0] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 2)
|
||||
{
|
||||
indlist[1] = vertexIndicesY0[getDecimatedIndex(x+2,y)];
|
||||
assert(indlist[1] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 4)
|
||||
{
|
||||
indlist[2] = vertexIndicesX0[getDecimatedIndex(x,y+2)];
|
||||
assert(indlist[2] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 8)
|
||||
{
|
||||
indlist[3] = vertexIndicesY0[getDecimatedIndex(x,y)];
|
||||
assert(indlist[3] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 16)
|
||||
{
|
||||
indlist[4] = vertexIndicesX1[getDecimatedIndex(x,y)];
|
||||
assert(indlist[4] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 32)
|
||||
{
|
||||
indlist[5] = vertexIndicesY1[getDecimatedIndex(x+2,y)];
|
||||
assert(indlist[5] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 64)
|
||||
{
|
||||
indlist[6] = vertexIndicesX1[getDecimatedIndex(x,y+2)];
|
||||
assert(indlist[6] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 128)
|
||||
{
|
||||
indlist[7] = vertexIndicesY1[getDecimatedIndex(x,y)];
|
||||
assert(indlist[7] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 256)
|
||||
{
|
||||
indlist[8] = vertexIndicesZ0[getDecimatedIndex(x,y)];
|
||||
assert(indlist[8] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 512)
|
||||
{
|
||||
indlist[9] = vertexIndicesZ0[getDecimatedIndex(x+2,y)];
|
||||
assert(indlist[9] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 1024)
|
||||
{
|
||||
indlist[10] = vertexIndicesZ0[getDecimatedIndex(x+2,y+2)];
|
||||
assert(indlist[10] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 2048)
|
||||
{
|
||||
indlist[11] = vertexIndicesZ0[getDecimatedIndex(x,y+2)];
|
||||
assert(indlist[11] != -1);
|
||||
}
|
||||
/* Find the vertices where the surface intersects the cube */
|
||||
if (edgeTable[iCubeIndex] & 1)
|
||||
{
|
||||
indlist[0] = vertexIndicesX0[getDecimatedIndex(x,y)];
|
||||
assert(indlist[0] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 2)
|
||||
{
|
||||
indlist[1] = vertexIndicesY0[getDecimatedIndex(x+uStepSize,y)];
|
||||
assert(indlist[1] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 4)
|
||||
{
|
||||
indlist[2] = vertexIndicesX0[getDecimatedIndex(x,y+uStepSize)];
|
||||
assert(indlist[2] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 8)
|
||||
{
|
||||
indlist[3] = vertexIndicesY0[getDecimatedIndex(x,y)];
|
||||
assert(indlist[3] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 16)
|
||||
{
|
||||
indlist[4] = vertexIndicesX1[getDecimatedIndex(x,y)];
|
||||
assert(indlist[4] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 32)
|
||||
{
|
||||
indlist[5] = vertexIndicesY1[getDecimatedIndex(x+uStepSize,y)];
|
||||
assert(indlist[5] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 64)
|
||||
{
|
||||
indlist[6] = vertexIndicesX1[getDecimatedIndex(x,y+uStepSize)];
|
||||
assert(indlist[6] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 128)
|
||||
{
|
||||
indlist[7] = vertexIndicesY1[getDecimatedIndex(x,y)];
|
||||
assert(indlist[7] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 256)
|
||||
{
|
||||
indlist[8] = vertexIndicesZ0[getDecimatedIndex(x,y)];
|
||||
assert(indlist[8] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 512)
|
||||
{
|
||||
indlist[9] = vertexIndicesZ0[getDecimatedIndex(x+uStepSize,y)];
|
||||
assert(indlist[9] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 1024)
|
||||
{
|
||||
indlist[10] = vertexIndicesZ0[getDecimatedIndex(x+uStepSize,y+uStepSize)];
|
||||
assert(indlist[10] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 2048)
|
||||
{
|
||||
indlist[11] = vertexIndicesZ0[getDecimatedIndex(x,y+uStepSize)];
|
||||
assert(indlist[11] != -1);
|
||||
}
|
||||
|
||||
for (int i=0;triTable[iCubeIndex][i]!=-1;i+=3)
|
||||
{
|
||||
boost::uint32_t ind0 = indlist[triTable[iCubeIndex][i ]];
|
||||
boost::uint32_t ind1 = indlist[triTable[iCubeIndex][i+1]];
|
||||
boost::uint32_t ind2 = indlist[triTable[iCubeIndex][i+2]];
|
||||
for (int i=0;triTable[iCubeIndex][i]!=-1;i+=3)
|
||||
{
|
||||
boost::uint32_t ind0 = indlist[triTable[iCubeIndex][i ]];
|
||||
boost::uint32_t ind1 = indlist[triTable[iCubeIndex][i+1]];
|
||||
boost::uint32_t ind2 = indlist[triTable[iCubeIndex][i+2]];
|
||||
|
||||
singleMaterialPatch->m_vecTriangleIndices.push_back(ind0);
|
||||
singleMaterialPatch->m_vecTriangleIndices.push_back(ind1);
|
||||
singleMaterialPatch->m_vecTriangleIndices.push_back(ind2);
|
||||
}//For each triangle
|
||||
}//while(volIter.moveForwardInRegionXYZ());//For each cell
|
||||
singleMaterialPatch->m_vecTriangleIndices.push_back(ind0);
|
||||
singleMaterialPatch->m_vecTriangleIndices.push_back(ind1);
|
||||
singleMaterialPatch->m_vecTriangleIndices.push_back(ind2);
|
||||
}//For each triangle
|
||||
}//For each cell
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user