Switched to integer naming conventions from C++0x (e.g. uint16_t)

This commit is contained in:
David Williams
2009-03-30 21:44:23 +00:00
parent 47e0e66228
commit 5acbd012cf
44 changed files with 711 additions and 711 deletions

View File

@ -6,7 +6,7 @@ using namespace std;
namespace PolyVox
{
POLYVOX_API void computeNormalsForVertices(Volume<uint8>* volumeData, IndexedSurfacePatch& isp, NormalGenerationMethod normalGenerationMethod)
POLYVOX_API void computeNormalsForVertices(Volume<uint8_t>* volumeData, IndexedSurfacePatch& isp, NormalGenerationMethod normalGenerationMethod)
{
std::vector<SurfaceVertex>& vecVertices = isp.getRawVertexData();
std::vector<SurfaceVertex>::iterator iterSurfaceVertex = vecVertices.begin();
@ -15,7 +15,7 @@ namespace PolyVox
const Vector3DFloat& v3dPos = iterSurfaceVertex->getPosition() + static_cast<Vector3DFloat>(isp.m_v3dRegionPosition);
const Vector3DInt32 v3dFloor = static_cast<Vector3DInt32>(v3dPos);
VolumeIterator<uint8> volIter(*volumeData);
VolumeIterator<uint8_t> volIter(*volumeData);
//Check all corners are within the volume, allowing a boundary for gradient estimation
bool lowerCornerInside = volumeData->getEnclosingRegion().containsPoint(v3dFloor,2);
@ -37,11 +37,11 @@ namespace PolyVox
}
}
Vector3DFloat computeNormal(Volume<uint8>* volumeData, const Vector3DFloat& v3dPos, NormalGenerationMethod normalGenerationMethod)
Vector3DFloat computeNormal(Volume<uint8_t>* volumeData, const Vector3DFloat& v3dPos, NormalGenerationMethod normalGenerationMethod)
{
Vector3DFloat v3dGradient; //To store the result
VolumeIterator<uint8> volIter(*volumeData);
VolumeIterator<uint8_t> volIter(*volumeData);
const Vector3DInt32 v3dFloor = static_cast<Vector3DInt32>(v3dPos);
@ -103,20 +103,20 @@ namespace PolyVox
if(normalGenerationMethod == SIMPLE)
{
volIter.setPosition(static_cast<Vector3DInt16>(v3dFloor));
const uint8 uFloor = volIter.getVoxel() > 0 ? 1 : 0;
const uint8_t uFloor = volIter.getVoxel() > 0 ? 1 : 0;
if((v3dPos.getX() - v3dFloor.getX()) > 0.25) //The result should be 0.0 or 0.5
{
uint8 uCeil = volIter.peekVoxel1px0py0pz() > 0 ? 1 : 0;
uint8_t uCeil = volIter.peekVoxel1px0py0pz() > 0 ? 1 : 0;
v3dGradient = Vector3DFloat(static_cast<float>(uFloor - uCeil),0.0,0.0);
}
else if((v3dPos.getY() - v3dFloor.getY()) > 0.25) //The result should be 0.0 or 0.5
{
uint8 uCeil = volIter.peekVoxel0px1py0pz() > 0 ? 1 : 0;
uint8_t uCeil = volIter.peekVoxel0px1py0pz() > 0 ? 1 : 0;
v3dGradient = Vector3DFloat(0.0,static_cast<float>(uFloor - uCeil),0.0);
}
else if((v3dPos.getZ() - v3dFloor.getZ()) > 0.25) //The result should be 0.0 or 0.5
{
uint8 uCeil = volIter.peekVoxel0px0py1pz() > 0 ? 1 : 0;
uint8_t uCeil = volIter.peekVoxel0px0py1pz() > 0 ? 1 : 0;
v3dGradient = Vector3DFloat(0.0, 0.0,static_cast<float>(uFloor - uCeil));
}
}

View File

@ -34,20 +34,20 @@ namespace PolyVox
{
}
const std::vector<uint32>& IndexedSurfacePatch::getIndices(void) const
const std::vector<uint32_t>& IndexedSurfacePatch::getIndices(void) const
{
return m_vecTriangleIndices;
}
uint32 IndexedSurfacePatch::getNoOfIndices(void) const
uint32_t IndexedSurfacePatch::getNoOfIndices(void) const
{
return m_vecTriangleIndices.size();
}
uint32 IndexedSurfacePatch::getNoOfNonUniformTrianges(void) const
uint32_t IndexedSurfacePatch::getNoOfNonUniformTrianges(void) const
{
uint32 result = 0;
for(uint32 i = 0; i < m_vecTriangleIndices.size() - 2; i += 3)
uint32_t result = 0;
for(uint32_t i = 0; i < m_vecTriangleIndices.size() - 2; i += 3)
{
if((m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+1]].getMaterial())
&& (m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+2]].getMaterial()))
@ -61,10 +61,10 @@ namespace PolyVox
return result;
}
uint32 IndexedSurfacePatch::getNoOfUniformTrianges(void) const
uint32_t IndexedSurfacePatch::getNoOfUniformTrianges(void) const
{
uint32 result = 0;
for(uint32 i = 0; i < m_vecTriangleIndices.size() - 2; i += 3)
uint32_t result = 0;
for(uint32_t i = 0; i < m_vecTriangleIndices.size() - 2; i += 3)
{
if((m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+1]].getMaterial())
&& (m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+2]].getMaterial()))
@ -75,7 +75,7 @@ namespace PolyVox
return result;
}
uint32 IndexedSurfacePatch::getNoOfVertices(void) const
uint32_t IndexedSurfacePatch::getNoOfVertices(void) const
{
return m_vecVertices.size();
}
@ -90,14 +90,14 @@ namespace PolyVox
return m_vecVertices;
}
void IndexedSurfacePatch::addTriangle(uint32 index0, uint32 index1, uint32 index2)
void IndexedSurfacePatch::addTriangle(uint32_t index0, uint32_t index1, uint32_t index2)
{
m_vecTriangleIndices.push_back(index0);
m_vecTriangleIndices.push_back(index1);
m_vecTriangleIndices.push_back(index2);
}
uint32 IndexedSurfacePatch::addVertex(const SurfaceVertex& vertex)
uint32_t IndexedSurfacePatch::addVertex(const SurfaceVertex& vertex)
{
m_vecVertices.push_back(vertex);
return m_vecVertices.size() - 1;

View File

@ -34,12 +34,12 @@ using namespace std;
namespace PolyVox
{
uint32 getDecimatedIndex(uint32 x, uint32 y , uint32 regionWidth)
uint32_t getDecimatedIndex(uint32_t x, uint32_t y , uint32_t regionWidth)
{
return x + (y * (regionWidth+1));
}
void extractDecimatedSurfaceImpl(Volume<uint8>* volumeData, uint8 uLevel, Region region, IndexedSurfacePatch* singleMaterialPatch)
void extractDecimatedSurfaceImpl(Volume<uint8_t>* volumeData, uint8_t uLevel, Region region, IndexedSurfacePatch* singleMaterialPatch)
{
singleMaterialPatch->clear();
@ -48,18 +48,18 @@ namespace PolyVox
//FIXME - Instead of region.width()+2 we used to use POLYVOX_REGION_SIDE_LENGTH+1
//Normally POLYVOX_REGION_SIDE_LENGTH is the same as region.width() (often 32) but at the
//edges of the volume it is 1 smaller. Need to think what values really belong here.
int32* vertexIndicesX0 = new int32[(region.width()+2) * (region.height()+2)];
int32* vertexIndicesY0 = new int32[(region.width()+2) * (region.height()+2)];
int32* vertexIndicesZ0 = new int32[(region.width()+2) * (region.height()+2)];
int32* vertexIndicesX1 = new int32[(region.width()+2) * (region.height()+2)];
int32* vertexIndicesY1 = new int32[(region.width()+2) * (region.height()+2)];
int32* vertexIndicesZ1 = new int32[(region.width()+2) * (region.height()+2)];
int32_t* vertexIndicesX0 = new int32_t[(region.width()+2) * (region.height()+2)];
int32_t* vertexIndicesY0 = new int32_t[(region.width()+2) * (region.height()+2)];
int32_t* vertexIndicesZ0 = new int32_t[(region.width()+2) * (region.height()+2)];
int32_t* vertexIndicesX1 = new int32_t[(region.width()+2) * (region.height()+2)];
int32_t* vertexIndicesY1 = new int32_t[(region.width()+2) * (region.height()+2)];
int32_t* vertexIndicesZ1 = new int32_t[(region.width()+2) * (region.height()+2)];
//Cell bitmasks
uint8* bitmask0 = new uint8[(region.width()+2) * (region.height()+2)];
uint8* bitmask1 = new uint8[(region.width()+2) * (region.height()+2)];
uint8_t* bitmask0 = new uint8_t[(region.width()+2) * (region.height()+2)];
uint8_t* bitmask1 = new uint8_t[(region.width()+2) * (region.height()+2)];
const uint8 uStepSize = uLevel == 0 ? 1 : 1 << uLevel;
const uint8_t uStepSize = uLevel == 0 ? 1 : 1 << uLevel;
//When generating the mesh for a region we actually look outside it in the
// back, bottom, right direction. Protect against access violations by cropping region here
@ -77,22 +77,22 @@ namespace PolyVox
regSlice0.setUpperCorner(v3dUpperCorner);
//Iterator to access the volume data
VolumeIterator<uint8> volIter(*volumeData);
VolumeIterator<uint8_t> volIter(*volumeData);
//Compute bitmask for initial slice
uint32 uNoOfNonEmptyCellsForSlice0 = computeInitialDecimatedBitmaskForSlice(volIter, uLevel, regSlice0, offset, bitmask0);
uint32_t uNoOfNonEmptyCellsForSlice0 = computeInitialDecimatedBitmaskForSlice(volIter, uLevel, regSlice0, offset, bitmask0);
if(uNoOfNonEmptyCellsForSlice0 != 0)
{
//If there were some non-empty cells then generate initial slice vertices for them
generateDecimatedVerticesForSlice(volIter, uLevel, regSlice0, offset, bitmask0, singleMaterialPatch, vertexIndicesX0, vertexIndicesY0, vertexIndicesZ0);
}
for(uint32 uSlice = 1; ((uSlice <= region.depth()) && (uSlice + offset.getZ() <= regVolume.getUpperCorner().getZ())); uSlice += uStepSize)
for(uint32_t uSlice = 1; ((uSlice <= region.depth()) && (uSlice + offset.getZ() <= regVolume.getUpperCorner().getZ())); uSlice += uStepSize)
{
Region regSlice1(regSlice0);
regSlice1.shift(Vector3DInt32(0,0,uStepSize));
uint32 uNoOfNonEmptyCellsForSlice1 = computeDecimatedBitmaskForSliceFromPrevious(volIter, uLevel, regSlice1, offset, bitmask1, bitmask0);
uint32_t uNoOfNonEmptyCellsForSlice1 = computeDecimatedBitmaskForSliceFromPrevious(volIter, uLevel, regSlice1, offset, bitmask1, bitmask0);
if(uNoOfNonEmptyCellsForSlice1 != 0)
{
@ -132,41 +132,41 @@ namespace PolyVox
}*/
}
uint32 computeInitialDecimatedBitmaskForSlice(VolumeIterator<uint8>& volIter, uint8 uLevel, const Region& regSlice, const Vector3DFloat& offset, uint8* bitmask)
uint32_t computeInitialDecimatedBitmaskForSlice(VolumeIterator<uint8_t>& volIter, uint8_t uLevel, const Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask)
{
const uint8 uStepSize = uLevel == 0 ? 1 : 1 << uLevel;
uint32 uNoOfNonEmptyCells = 0;
const uint8_t uStepSize = uLevel == 0 ? 1 : 1 << uLevel;
uint32_t uNoOfNonEmptyCells = 0;
//Iterate over each cell in the region
for(uint16 y = regSlice.getLowerCorner().getY(); y <= regSlice.getUpperCorner().getY(); y += uStepSize)
for(uint16_t y = regSlice.getLowerCorner().getY(); y <= regSlice.getUpperCorner().getY(); y += uStepSize)
{
for(uint16 x = regSlice.getLowerCorner().getX(); x <= regSlice.getUpperCorner().getX(); x += uStepSize)
for(uint16_t x = regSlice.getLowerCorner().getX(); x <= regSlice.getUpperCorner().getX(); x += uStepSize)
{
//Current position
volIter.setPosition(x,y,regSlice.getLowerCorner().getZ());
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8 iCubeIndex = 0;
uint8_t iCubeIndex = 0;
if((x==regSlice.getLowerCorner().getX()) && (y==regSlice.getLowerCorner().getY()))
{
volIter.setPosition(x,y,regSlice.getLowerCorner().getZ());
const uint8 v000 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v000 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y,regSlice.getLowerCorner().getZ());
const uint8 v100 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v100 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x,y+uStepSize,regSlice.getLowerCorner().getZ());
const uint8 v010 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v010 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ());
const uint8 v110 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v110 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x,y,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v001 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v001 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v101 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v101 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v011 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v011 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v111 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
if (v000 == 0) iCubeIndex |= 1;
if (v100 == 0) iCubeIndex |= 2;
@ -180,28 +180,28 @@ namespace PolyVox
else if((x>regSlice.getLowerCorner().getX()) && y==regSlice.getLowerCorner().getY())
{
volIter.setPosition(x+uStepSize,y,regSlice.getLowerCorner().getZ());
const uint8 v100 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v100 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ());
const uint8 v110 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v110 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v101 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v101 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v111 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
//x
uint8 iPreviousCubeIndexX = bitmask[getDecimatedIndex(x- offset.getX()-uStepSize,y- offset.getY(), regSlice.width()+1)];
uint8 srcBit6 = iPreviousCubeIndexX & 64;
uint8 destBit7 = srcBit6 << 1;
uint8_t iPreviousCubeIndexX = bitmask[getDecimatedIndex(x- offset.getX()-uStepSize,y- offset.getY(), regSlice.width()+1)];
uint8_t srcBit6 = iPreviousCubeIndexX & 64;
uint8_t destBit7 = srcBit6 << 1;
uint8 srcBit5 = iPreviousCubeIndexX & 32;
uint8 destBit4 = srcBit5 >> 1;
uint8_t srcBit5 = iPreviousCubeIndexX & 32;
uint8_t destBit4 = srcBit5 >> 1;
uint8 srcBit2 = iPreviousCubeIndexX & 4;
uint8 destBit3 = srcBit2 << 1;
uint8_t srcBit2 = iPreviousCubeIndexX & 4;
uint8_t destBit3 = srcBit2 << 1;
uint8 srcBit1 = iPreviousCubeIndexX & 2;
uint8 destBit0 = srcBit1 >> 1;
uint8_t srcBit1 = iPreviousCubeIndexX & 2;
uint8_t destBit0 = srcBit1 >> 1;
iCubeIndex |= destBit0;
if (v100 == 0) iCubeIndex |= 2;
@ -215,28 +215,28 @@ namespace PolyVox
else if((x==regSlice.getLowerCorner().getX()) && (y>regSlice.getLowerCorner().getY()))
{
volIter.setPosition(x,y+uStepSize,regSlice.getLowerCorner().getZ());
const uint8 v010 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v010 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ());
const uint8 v110 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v110 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v011 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v011 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v111 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
//y
uint8 iPreviousCubeIndexY = bitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY()-uStepSize, regSlice.width()+1)];
uint8 srcBit7 = iPreviousCubeIndexY & 128;
uint8 destBit4 = srcBit7 >> 3;
uint8_t iPreviousCubeIndexY = bitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY()-uStepSize, regSlice.width()+1)];
uint8_t srcBit7 = iPreviousCubeIndexY & 128;
uint8_t destBit4 = srcBit7 >> 3;
uint8 srcBit6 = iPreviousCubeIndexY & 64;
uint8 destBit5 = srcBit6 >> 1;
uint8_t srcBit6 = iPreviousCubeIndexY & 64;
uint8_t destBit5 = srcBit6 >> 1;
uint8 srcBit3 = iPreviousCubeIndexY & 8;
uint8 destBit0 = srcBit3 >> 3;
uint8_t srcBit3 = iPreviousCubeIndexY & 8;
uint8_t destBit0 = srcBit3 >> 3;
uint8 srcBit2 = iPreviousCubeIndexY & 4;
uint8 destBit1 = srcBit2 >> 1;
uint8_t srcBit2 = iPreviousCubeIndexY & 4;
uint8_t destBit1 = srcBit2 >> 1;
iCubeIndex |= destBit0;
iCubeIndex |= destBit1;
@ -250,32 +250,32 @@ namespace PolyVox
else
{
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ());
const uint8 v110 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v110 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v111 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
//y
uint8 iPreviousCubeIndexY = bitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY()-uStepSize, regSlice.width()+1)];
uint8 srcBit7 = iPreviousCubeIndexY & 128;
uint8 destBit4 = srcBit7 >> 3;
uint8_t iPreviousCubeIndexY = bitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY()-uStepSize, regSlice.width()+1)];
uint8_t srcBit7 = iPreviousCubeIndexY & 128;
uint8_t destBit4 = srcBit7 >> 3;
uint8 srcBit6 = iPreviousCubeIndexY & 64;
uint8 destBit5 = srcBit6 >> 1;
uint8_t srcBit6 = iPreviousCubeIndexY & 64;
uint8_t destBit5 = srcBit6 >> 1;
uint8 srcBit3 = iPreviousCubeIndexY & 8;
uint8 destBit0 = srcBit3 >> 3;
uint8_t srcBit3 = iPreviousCubeIndexY & 8;
uint8_t destBit0 = srcBit3 >> 3;
uint8 srcBit2 = iPreviousCubeIndexY & 4;
uint8 destBit1 = srcBit2 >> 1;
uint8_t srcBit2 = iPreviousCubeIndexY & 4;
uint8_t destBit1 = srcBit2 >> 1;
//x
uint8 iPreviousCubeIndexX = bitmask[getDecimatedIndex(x- offset.getX()-uStepSize,y- offset.getY(), regSlice.width()+1)];
uint8_t iPreviousCubeIndexX = bitmask[getDecimatedIndex(x- offset.getX()-uStepSize,y- offset.getY(), regSlice.width()+1)];
srcBit6 = iPreviousCubeIndexX & 64;
uint8 destBit7 = srcBit6 << 1;
uint8_t destBit7 = srcBit6 << 1;
srcBit2 = iPreviousCubeIndexX & 4;
uint8 destBit3 = srcBit2 << 1;
uint8_t destBit3 = srcBit2 << 1;
iCubeIndex |= destBit0;
iCubeIndex |= destBit1;
@ -301,35 +301,35 @@ namespace PolyVox
return uNoOfNonEmptyCells;
}
uint32 computeDecimatedBitmaskForSliceFromPrevious(VolumeIterator<uint8>& volIter, uint8 uLevel, const Region& regSlice, const Vector3DFloat& offset, uint8* bitmask, uint8* previousBitmask)
uint32_t computeDecimatedBitmaskForSliceFromPrevious(VolumeIterator<uint8_t>& volIter, uint8_t uLevel, const Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask, uint8_t* previousBitmask)
{
const uint8 uStepSize = uLevel == 0 ? 1 : 1 << uLevel;
uint32 uNoOfNonEmptyCells = 0;
const uint8_t uStepSize = uLevel == 0 ? 1 : 1 << uLevel;
uint32_t uNoOfNonEmptyCells = 0;
//Iterate over each cell in the region
for(uint16 y = regSlice.getLowerCorner().getY(); y <= regSlice.getUpperCorner().getY(); y += uStepSize)
for(uint16_t y = regSlice.getLowerCorner().getY(); y <= regSlice.getUpperCorner().getY(); y += uStepSize)
{
for(uint16 x = regSlice.getLowerCorner().getX(); x <= regSlice.getUpperCorner().getX(); x += uStepSize)
for(uint16_t x = regSlice.getLowerCorner().getX(); x <= regSlice.getUpperCorner().getX(); x += uStepSize)
{
//Current position
volIter.setPosition(x,y,regSlice.getLowerCorner().getZ());
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8 iCubeIndex = 0;
uint8_t iCubeIndex = 0;
if((x==regSlice.getLowerCorner().getX()) && (y==regSlice.getLowerCorner().getY()))
{
volIter.setPosition(x,y,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v001 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v001 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v101 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v101 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v011 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v011 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v111 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
//z
uint8 iPreviousCubeIndexZ = previousBitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY(), regSlice.width()+1)];
uint8_t iPreviousCubeIndexZ = previousBitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY(), regSlice.width()+1)];
iCubeIndex = iPreviousCubeIndexZ >> 4;
if (v001 == 0) iCubeIndex |= 16;
@ -340,21 +340,21 @@ namespace PolyVox
else if((x>regSlice.getLowerCorner().getX()) && y==regSlice.getLowerCorner().getY())
{
volIter.setPosition(x+uStepSize,y,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v101 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v101 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v111 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
//z
uint8 iPreviousCubeIndexZ = previousBitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY(), regSlice.width()+1)];
uint8_t iPreviousCubeIndexZ = previousBitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY(), regSlice.width()+1)];
iCubeIndex = iPreviousCubeIndexZ >> 4;
//x
uint8 iPreviousCubeIndexX = bitmask[getDecimatedIndex(x- offset.getX()-uStepSize,y- offset.getY(), regSlice.width()+1)];
uint8 srcBit6 = iPreviousCubeIndexX & 64;
uint8 destBit7 = srcBit6 << 1;
uint8_t iPreviousCubeIndexX = bitmask[getDecimatedIndex(x- offset.getX()-uStepSize,y- offset.getY(), regSlice.width()+1)];
uint8_t srcBit6 = iPreviousCubeIndexX & 64;
uint8_t destBit7 = srcBit6 << 1;
uint8 srcBit5 = iPreviousCubeIndexX & 32;
uint8 destBit4 = srcBit5 >> 1;
uint8_t srcBit5 = iPreviousCubeIndexX & 32;
uint8_t destBit4 = srcBit5 >> 1;
iCubeIndex |= destBit4;
if (v101 == 0) iCubeIndex |= 32;
@ -364,21 +364,21 @@ namespace PolyVox
else if((x==regSlice.getLowerCorner().getX()) && (y>regSlice.getLowerCorner().getY()))
{
volIter.setPosition(x,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v011 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v011 = volIter.getSubSampledVoxel(uLevel);
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v111 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
//z
uint8 iPreviousCubeIndexZ = previousBitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY(), regSlice.width()+1)];
uint8_t iPreviousCubeIndexZ = previousBitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY(), regSlice.width()+1)];
iCubeIndex = iPreviousCubeIndexZ >> 4;
//y
uint8 iPreviousCubeIndexY = bitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY()-uStepSize, regSlice.width()+1)];
uint8 srcBit7 = iPreviousCubeIndexY & 128;
uint8 destBit4 = srcBit7 >> 3;
uint8_t iPreviousCubeIndexY = bitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY()-uStepSize, regSlice.width()+1)];
uint8_t srcBit7 = iPreviousCubeIndexY & 128;
uint8_t destBit4 = srcBit7 >> 3;
uint8 srcBit6 = iPreviousCubeIndexY & 64;
uint8 destBit5 = srcBit6 >> 1;
uint8_t srcBit6 = iPreviousCubeIndexY & 64;
uint8_t destBit5 = srcBit6 >> 1;
iCubeIndex |= destBit4;
iCubeIndex |= destBit5;
@ -388,24 +388,24 @@ namespace PolyVox
else
{
volIter.setPosition(x+uStepSize,y+uStepSize,regSlice.getLowerCorner().getZ()+uStepSize);
const uint8 v111 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v111 = volIter.getSubSampledVoxel(uLevel);
//z
uint8 iPreviousCubeIndexZ = previousBitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY(), regSlice.width()+1)];
uint8_t iPreviousCubeIndexZ = previousBitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY(), regSlice.width()+1)];
iCubeIndex = iPreviousCubeIndexZ >> 4;
//y
uint8 iPreviousCubeIndexY = bitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY()-uStepSize, regSlice.width()+1)];
uint8 srcBit7 = iPreviousCubeIndexY & 128;
uint8 destBit4 = srcBit7 >> 3;
uint8_t iPreviousCubeIndexY = bitmask[getDecimatedIndex(x- offset.getX(),y- offset.getY()-uStepSize, regSlice.width()+1)];
uint8_t srcBit7 = iPreviousCubeIndexY & 128;
uint8_t destBit4 = srcBit7 >> 3;
uint8 srcBit6 = iPreviousCubeIndexY & 64;
uint8 destBit5 = srcBit6 >> 1;
uint8_t srcBit6 = iPreviousCubeIndexY & 64;
uint8_t destBit5 = srcBit6 >> 1;
//x
uint8 iPreviousCubeIndexX = bitmask[getDecimatedIndex(x- offset.getX()-uStepSize,y- offset.getY(), regSlice.width()+1)];
uint8_t iPreviousCubeIndexX = bitmask[getDecimatedIndex(x- offset.getX()-uStepSize,y- offset.getY(), regSlice.width()+1)];
srcBit6 = iPreviousCubeIndexX & 64;
uint8 destBit7 = srcBit6 << 1;
uint8_t destBit7 = srcBit6 << 1;
iCubeIndex |= destBit4;
iCubeIndex |= destBit5;
@ -427,23 +427,23 @@ namespace PolyVox
return uNoOfNonEmptyCells;
}
void generateDecimatedVerticesForSlice(VolumeIterator<uint8>& volIter, uint8 uLevel, Region& regSlice, const Vector3DFloat& offset, uint8* bitmask, IndexedSurfacePatch* singleMaterialPatch,int32 vertexIndicesX[],int32 vertexIndicesY[],int32 vertexIndicesZ[])
void generateDecimatedVerticesForSlice(VolumeIterator<uint8_t>& volIter, uint8_t uLevel, Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,int32_t vertexIndicesX[],int32_t vertexIndicesY[],int32_t vertexIndicesZ[])
{
const uint8 uStepSize = uLevel == 0 ? 1 : 1 << uLevel;
const uint8_t uStepSize = uLevel == 0 ? 1 : 1 << uLevel;
//Iterate over each cell in the region
for(uint16 y = regSlice.getLowerCorner().getY(); y <= regSlice.getUpperCorner().getY(); y += uStepSize)
for(uint16_t y = regSlice.getLowerCorner().getY(); y <= regSlice.getUpperCorner().getY(); y += uStepSize)
{
for(uint16 x = regSlice.getLowerCorner().getX(); x <= regSlice.getUpperCorner().getX(); x += uStepSize)
for(uint16_t x = regSlice.getLowerCorner().getX(); x <= regSlice.getUpperCorner().getX(); x += uStepSize)
{
//Current position
const uint16 z = regSlice.getLowerCorner().getZ();
const uint16_t z = regSlice.getLowerCorner().getZ();
volIter.setPosition(x,y,z);
const uint8 v000 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v000 = volIter.getSubSampledVoxel(uLevel);
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8 iCubeIndex = bitmask[getDecimatedIndex(x - offset.getX(),y - offset.getY(), regSlice.width()+1)];
uint8_t iCubeIndex = bitmask[getDecimatedIndex(x - offset.getX(),y - offset.getY(), regSlice.width()+1)];
/* Cube is entirely in/out of the surface */
if (edgeTable[iCubeIndex] == 0)
@ -457,12 +457,12 @@ namespace PolyVox
if(x != regSlice.getUpperCorner().getX())
{
volIter.setPosition(x + uStepSize,y,z);
const uint8 v100 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v100 = volIter.getSubSampledVoxel(uLevel);
const Vector3DFloat v3dPosition(x - offset.getX() + 0.5f * uStepSize, y - offset.getY(), z - offset.getZ());
const Vector3DFloat v3dNormal(v000 > v100 ? 1.0f : -1.0f,0.0,0.0);
const uint8 uMaterial = v000 | v100; //Because one of these is 0, the or operation takes the max.
const uint8_t uMaterial = v000 | v100; //Because one of these is 0, the or operation takes the max.
SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial);
uint32 uLastVertexIndex = singleMaterialPatch->addVertex(surfaceVertex);
uint32_t uLastVertexIndex = singleMaterialPatch->addVertex(surfaceVertex);
vertexIndicesX[getDecimatedIndex(x - offset.getX(),y - offset.getY(), regSlice.width()+1)] = uLastVertexIndex;
}
}
@ -471,12 +471,12 @@ namespace PolyVox
if(y != regSlice.getUpperCorner().getY())
{
volIter.setPosition(x,y + uStepSize,z);
const uint8 v010 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v010 = volIter.getSubSampledVoxel(uLevel);
const Vector3DFloat v3dPosition(x - offset.getX(), y - offset.getY() + 0.5f * uStepSize, z - offset.getZ());
const Vector3DFloat v3dNormal(0.0,v000 > v010 ? 1.0f : -1.0f,0.0);
const uint8 uMaterial = v000 | v010; //Because one of these is 0, the or operation takes the max.
const uint8_t uMaterial = v000 | v010; //Because one of these is 0, the or operation takes the max.
SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial);
uint32 uLastVertexIndex = singleMaterialPatch->addVertex(surfaceVertex);
uint32_t uLastVertexIndex = singleMaterialPatch->addVertex(surfaceVertex);
vertexIndicesY[getDecimatedIndex(x - offset.getX(),y - offset.getY(), regSlice.width()+1)] = uLastVertexIndex;
}
}
@ -485,12 +485,12 @@ namespace PolyVox
//if(z != regSlice.getUpperCorner.getZ())
{
volIter.setPosition(x,y,z + uStepSize);
const uint8 v001 = volIter.getSubSampledVoxel(uLevel);
const uint8_t v001 = volIter.getSubSampledVoxel(uLevel);
const Vector3DFloat v3dPosition(x - offset.getX(), y - offset.getY(), z - offset.getZ() + 0.5f * uStepSize);
const Vector3DFloat v3dNormal(0.0,0.0,v000 > v001 ? 1.0f : -1.0f);
const uint8 uMaterial = v000 | v001; //Because one of these is 0, the or operation takes the max.
const uint8_t uMaterial = v000 | v001; //Because one of these is 0, the or operation takes the max.
const SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial);
uint32 uLastVertexIndex = singleMaterialPatch->addVertex(surfaceVertex);
uint32_t uLastVertexIndex = singleMaterialPatch->addVertex(surfaceVertex);
vertexIndicesZ[getDecimatedIndex(x - offset.getX(),y - offset.getY(), regSlice.width()+1)] = uLastVertexIndex;
}
}
@ -498,20 +498,20 @@ namespace PolyVox
}
}
void generateDecimatedIndicesForSlice(VolumeIterator<uint8>& volIter, uint8 uLevel, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, uint8* bitmask0, uint8* bitmask1, int32 vertexIndicesX0[],int32 vertexIndicesY0[],int32 vertexIndicesZ0[], int32 vertexIndicesX1[],int32 vertexIndicesY1[],int32 vertexIndicesZ1[])
void generateDecimatedIndicesForSlice(VolumeIterator<uint8_t>& volIter, uint8_t uLevel, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, uint8_t* bitmask0, uint8_t* bitmask1, int32_t vertexIndicesX0[],int32_t vertexIndicesY0[],int32_t vertexIndicesZ0[], int32_t vertexIndicesX1[],int32_t vertexIndicesY1[],int32_t vertexIndicesZ1[])
{
const uint8 uStepSize = uLevel == 0 ? 1 : 1 << uLevel;
uint32 indlist[12];
const uint8_t uStepSize = uLevel == 0 ? 1 : 1 << uLevel;
uint32_t indlist[12];
for(uint16 y = regSlice.getLowerCorner().getY() - offset.getY(); y < regSlice.getUpperCorner().getY() - offset.getY(); y += uStepSize)
for(uint16_t y = regSlice.getLowerCorner().getY() - offset.getY(); y < regSlice.getUpperCorner().getY() - offset.getY(); y += uStepSize)
{
for(uint16 x = regSlice.getLowerCorner().getX() - offset.getX(); x < regSlice.getUpperCorner().getX() - offset.getX(); x += uStepSize)
for(uint16_t x = regSlice.getLowerCorner().getX() - offset.getX(); x < regSlice.getUpperCorner().getX() - offset.getX(); x += uStepSize)
{
//Current position
const uint16 z = regSlice.getLowerCorner().getZ() - offset.getZ();
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 iCubeIndex = bitmask0[getDecimatedIndex(x,y, regSlice.width()+1)];
uint8_t iCubeIndex = bitmask0[getDecimatedIndex(x,y, regSlice.width()+1)];
/* Cube is entirely in/out of the surface */
if (edgeTable[iCubeIndex] == 0)
@ -583,9 +583,9 @@ namespace PolyVox
for (int i=0;triTable[iCubeIndex][i]!=-1;i+=3)
{
uint32 ind0 = indlist[triTable[iCubeIndex][i ]];
uint32 ind1 = indlist[triTable[iCubeIndex][i+1]];
uint32 ind2 = indlist[triTable[iCubeIndex][i+2]];
uint32_t ind0 = indlist[triTable[iCubeIndex][i ]];
uint32_t ind1 = indlist[triTable[iCubeIndex][i+1]];
uint32_t ind2 = indlist[triTable[iCubeIndex][i+2]];
singleMaterialPatch->addTriangle(ind0, ind1, ind2);
}//For each triangle

View File

@ -29,21 +29,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
namespace PolyVox
{
void extractFastSurfaceImpl(Volume<uint8>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch)
void extractFastSurfaceImpl(Volume<uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch)
{
singleMaterialPatch->clear();
//For edge indices
int32* vertexIndicesX0 = new int32[(region.width()+2) * (region.height()+2)];
int32* vertexIndicesY0 = new int32[(region.width()+2) * (region.height()+2)];
int32* vertexIndicesZ0 = new int32[(region.width()+2) * (region.height()+2)];
int32* vertexIndicesX1 = new int32[(region.width()+2) * (region.height()+2)];
int32* vertexIndicesY1 = new int32[(region.width()+2) * (region.height()+2)];
int32* vertexIndicesZ1 = new int32[(region.width()+2) * (region.height()+2)];
int32_t* vertexIndicesX0 = new int32_t[(region.width()+2) * (region.height()+2)];
int32_t* vertexIndicesY0 = new int32_t[(region.width()+2) * (region.height()+2)];
int32_t* vertexIndicesZ0 = new int32_t[(region.width()+2) * (region.height()+2)];
int32_t* vertexIndicesX1 = new int32_t[(region.width()+2) * (region.height()+2)];
int32_t* vertexIndicesY1 = new int32_t[(region.width()+2) * (region.height()+2)];
int32_t* vertexIndicesZ1 = new int32_t[(region.width()+2) * (region.height()+2)];
//Cell bitmasks
uint8* bitmask0 = new uint8[(region.width()+2) * (region.height()+2)];
uint8* bitmask1 = new uint8[(region.width()+2) * (region.height()+2)];
uint8_t* bitmask0 = new uint8_t[(region.width()+2) * (region.height()+2)];
uint8_t* bitmask1 = new uint8_t[(region.width()+2) * (region.height()+2)];
//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
@ -59,22 +59,22 @@ namespace PolyVox
regSlice0.setUpperCorner(Vector3DInt32(regSlice0.getUpperCorner().getX(),regSlice0.getUpperCorner().getY(),regSlice0.getLowerCorner().getZ()));
//Iterator to access the volume data
VolumeIterator<uint8> volIter(*volumeData);
VolumeIterator<uint8_t> volIter(*volumeData);
//Compute bitmask for initial slice
uint32 uNoOfNonEmptyCellsForSlice0 = computeInitialRoughBitmaskForSlice(volIter, regSlice0, offset, bitmask0);
uint32_t uNoOfNonEmptyCellsForSlice0 = computeInitialRoughBitmaskForSlice(volIter, regSlice0, offset, bitmask0);
if(uNoOfNonEmptyCellsForSlice0 != 0)
{
//If there were some non-empty cells then generate initial slice vertices for them
generateRoughVerticesForSlice(volIter,regSlice0, offset, bitmask0, singleMaterialPatch, vertexIndicesX0, vertexIndicesY0, vertexIndicesZ0);
}
for(uint32 uSlice = 0; ((uSlice <= region.depth()-1) && (uSlice + offset.getZ() < region.getUpperCorner().getZ())); ++uSlice)
for(uint32_t uSlice = 0; ((uSlice <= region.depth()-1) && (uSlice + offset.getZ() < region.getUpperCorner().getZ())); ++uSlice)
{
Region regSlice1(regSlice0);
regSlice1.shift(Vector3DInt32(0,0,1));
uint32 uNoOfNonEmptyCellsForSlice1 = computeRoughBitmaskForSliceFromPrevious(volIter, regSlice1, offset, bitmask1, bitmask0);
uint32_t uNoOfNonEmptyCellsForSlice1 = computeRoughBitmaskForSliceFromPrevious(volIter, regSlice1, offset, bitmask1, bitmask0);
if(uNoOfNonEmptyCellsForSlice1 != 0)
{
@ -105,14 +105,14 @@ namespace PolyVox
delete[] vertexIndicesZ1;
}
uint32 getIndex(uint32 x, uint32 y, uint32 regionWidth)
uint32_t getIndex(uint32_t x, uint32_t y, uint32_t regionWidth)
{
return x + (y * (regionWidth+1));
}
uint32 computeInitialRoughBitmaskForSlice(VolumeIterator<uint8>& volIter, const Region& regSlice, const Vector3DFloat& offset, uint8* bitmask)
uint32_t computeInitialRoughBitmaskForSlice(VolumeIterator<uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask)
{
uint32 uNoOfNonEmptyCells = 0;
uint32_t uNoOfNonEmptyCells = 0;
//Iterate over each cell in the region
volIter.setPosition(regSlice.getLowerCorner().getX(),regSlice.getLowerCorner().getY(), regSlice.getLowerCorner().getZ());
@ -120,23 +120,23 @@ namespace PolyVox
do
{
//Current position
const uint16 x = volIter.getPosX() - offset.getX();
const uint16 y = volIter.getPosY() - offset.getY();
const uint16_t x = volIter.getPosX() - offset.getX();
const uint16_t y = volIter.getPosY() - offset.getY();
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8 iCubeIndex = 0;
uint8_t iCubeIndex = 0;
if((x==0) && (y==0))
{
const uint8 v000 = volIter.getVoxel();
const uint8 v100 = volIter.peekVoxel1px0py0pz();
const uint8 v010 = volIter.peekVoxel0px1py0pz();
const uint8 v110 = volIter.peekVoxel1px1py0pz();
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 v001 = volIter.peekVoxel0px0py1pz();
const uint8 v101 = volIter.peekVoxel1px0py1pz();
const uint8 v011 = volIter.peekVoxel0px1py1pz();
const uint8 v111 = volIter.peekVoxel1px1py1pz();
const uint8_t v001 = volIter.peekVoxel0px0py1pz();
const uint8_t v101 = volIter.peekVoxel1px0py1pz();
const uint8_t v011 = volIter.peekVoxel0px1py1pz();
const uint8_t v111 = volIter.peekVoxel1px1py1pz();
if (v000 == 0) iCubeIndex |= 1;
if (v100 == 0) iCubeIndex |= 2;
@ -149,25 +149,25 @@ namespace PolyVox
}
else if((x>0) && y==0)
{
const uint8 v100 = volIter.peekVoxel1px0py0pz();
const uint8 v110 = volIter.peekVoxel1px1py0pz();
const uint8_t v100 = volIter.peekVoxel1px0py0pz();
const uint8_t v110 = volIter.peekVoxel1px1py0pz();
const uint8 v101 = volIter.peekVoxel1px0py1pz();
const uint8 v111 = volIter.peekVoxel1px1py1pz();
const uint8_t v101 = volIter.peekVoxel1px0py1pz();
const uint8_t v111 = volIter.peekVoxel1px1py1pz();
//x
uint8 iPreviousCubeIndexX = bitmask[getIndex(x-1,y, regSlice.width()+1)];
uint8 srcBit6 = iPreviousCubeIndexX & 64;
uint8 destBit7 = srcBit6 << 1;
uint8_t iPreviousCubeIndexX = bitmask[getIndex(x-1,y, regSlice.width()+1)];
uint8_t srcBit6 = iPreviousCubeIndexX & 64;
uint8_t destBit7 = srcBit6 << 1;
uint8 srcBit5 = iPreviousCubeIndexX & 32;
uint8 destBit4 = srcBit5 >> 1;
uint8_t srcBit5 = iPreviousCubeIndexX & 32;
uint8_t destBit4 = srcBit5 >> 1;
uint8 srcBit2 = iPreviousCubeIndexX & 4;
uint8 destBit3 = srcBit2 << 1;
uint8_t srcBit2 = iPreviousCubeIndexX & 4;
uint8_t destBit3 = srcBit2 << 1;
uint8 srcBit1 = iPreviousCubeIndexX & 2;
uint8 destBit0 = srcBit1 >> 1;
uint8_t srcBit1 = iPreviousCubeIndexX & 2;
uint8_t destBit0 = srcBit1 >> 1;
iCubeIndex |= destBit0;
if (v100 == 0) iCubeIndex |= 2;
@ -180,25 +180,25 @@ namespace PolyVox
}
else if((x==0) && (y>0))
{
const uint8 v010 = volIter.peekVoxel0px1py0pz();
const uint8 v110 = volIter.peekVoxel1px1py0pz();
const uint8_t v010 = volIter.peekVoxel0px1py0pz();
const uint8_t v110 = volIter.peekVoxel1px1py0pz();
const uint8 v011 = volIter.peekVoxel0px1py1pz();
const uint8 v111 = volIter.peekVoxel1px1py1pz();
const uint8_t v011 = volIter.peekVoxel0px1py1pz();
const uint8_t v111 = volIter.peekVoxel1px1py1pz();
//y
uint8 iPreviousCubeIndexY = bitmask[getIndex(x,y-1, regSlice.width()+1)];
uint8 srcBit7 = iPreviousCubeIndexY & 128;
uint8 destBit4 = srcBit7 >> 3;
uint8_t iPreviousCubeIndexY = bitmask[getIndex(x,y-1, regSlice.width()+1)];
uint8_t srcBit7 = iPreviousCubeIndexY & 128;
uint8_t destBit4 = srcBit7 >> 3;
uint8 srcBit6 = iPreviousCubeIndexY & 64;
uint8 destBit5 = srcBit6 >> 1;
uint8_t srcBit6 = iPreviousCubeIndexY & 64;
uint8_t destBit5 = srcBit6 >> 1;
uint8 srcBit3 = iPreviousCubeIndexY & 8;
uint8 destBit0 = srcBit3 >> 3;
uint8_t srcBit3 = iPreviousCubeIndexY & 8;
uint8_t destBit0 = srcBit3 >> 3;
uint8 srcBit2 = iPreviousCubeIndexY & 4;
uint8 destBit1 = srcBit2 >> 1;
uint8_t srcBit2 = iPreviousCubeIndexY & 4;
uint8_t destBit1 = srcBit2 >> 1;
iCubeIndex |= destBit0;
iCubeIndex |= destBit1;
@ -211,31 +211,31 @@ namespace PolyVox
}
else
{
const uint8 v110 = volIter.peekVoxel1px1py0pz();
const uint8_t v110 = volIter.peekVoxel1px1py0pz();
const uint8 v111 = volIter.peekVoxel1px1py1pz();
const uint8_t v111 = volIter.peekVoxel1px1py1pz();
//y
uint8 iPreviousCubeIndexY = bitmask[getIndex(x,y-1, regSlice.width()+1)];
uint8 srcBit7 = iPreviousCubeIndexY & 128;
uint8 destBit4 = srcBit7 >> 3;
uint8_t iPreviousCubeIndexY = bitmask[getIndex(x,y-1, regSlice.width()+1)];
uint8_t srcBit7 = iPreviousCubeIndexY & 128;
uint8_t destBit4 = srcBit7 >> 3;
uint8 srcBit6 = iPreviousCubeIndexY & 64;
uint8 destBit5 = srcBit6 >> 1;
uint8_t srcBit6 = iPreviousCubeIndexY & 64;
uint8_t destBit5 = srcBit6 >> 1;
uint8 srcBit3 = iPreviousCubeIndexY & 8;
uint8 destBit0 = srcBit3 >> 3;
uint8_t srcBit3 = iPreviousCubeIndexY & 8;
uint8_t destBit0 = srcBit3 >> 3;
uint8 srcBit2 = iPreviousCubeIndexY & 4;
uint8 destBit1 = srcBit2 >> 1;
uint8_t srcBit2 = iPreviousCubeIndexY & 4;
uint8_t destBit1 = srcBit2 >> 1;
//x
uint8 iPreviousCubeIndexX = bitmask[getIndex(x-1,y, regSlice.width()+1)];
uint8_t iPreviousCubeIndexX = bitmask[getIndex(x-1,y, regSlice.width()+1)];
srcBit6 = iPreviousCubeIndexX & 64;
uint8 destBit7 = srcBit6 << 1;
uint8_t destBit7 = srcBit6 << 1;
srcBit2 = iPreviousCubeIndexX & 4;
uint8 destBit3 = srcBit2 << 1;
uint8_t destBit3 = srcBit2 << 1;
iCubeIndex |= destBit0;
iCubeIndex |= destBit1;
@ -260,9 +260,9 @@ namespace PolyVox
return uNoOfNonEmptyCells;
}
uint32 computeRoughBitmaskForSliceFromPrevious(VolumeIterator<uint8>& volIter, const Region& regSlice, const Vector3DFloat& offset, uint8* bitmask, uint8* previousBitmask)
uint32_t computeRoughBitmaskForSliceFromPrevious(VolumeIterator<uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask, uint8_t* previousBitmask)
{
uint32 uNoOfNonEmptyCells = 0;
uint32_t uNoOfNonEmptyCells = 0;
//Iterate over each cell in the region
volIter.setPosition(regSlice.getLowerCorner().getX(),regSlice.getLowerCorner().getY(), regSlice.getLowerCorner().getZ());
@ -270,21 +270,21 @@ namespace PolyVox
do
{
//Current position
const uint16 x = volIter.getPosX() - offset.getX();
const uint16 y = volIter.getPosY() - offset.getY();
const uint16_t x = volIter.getPosX() - offset.getX();
const uint16_t y = volIter.getPosY() - offset.getY();
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8 iCubeIndex = 0;
uint8_t iCubeIndex = 0;
if((x==0) && (y==0))
{
const uint8 v001 = volIter.peekVoxel0px0py1pz();
const uint8 v101 = volIter.peekVoxel1px0py1pz();
const uint8 v011 = volIter.peekVoxel0px1py1pz();
const uint8 v111 = volIter.peekVoxel1px1py1pz();
const uint8_t v001 = volIter.peekVoxel0px0py1pz();
const uint8_t v101 = volIter.peekVoxel1px0py1pz();
const uint8_t v011 = volIter.peekVoxel0px1py1pz();
const uint8_t v111 = volIter.peekVoxel1px1py1pz();
//z
uint8 iPreviousCubeIndexZ = previousBitmask[getIndex(x,y, regSlice.width()+1)];
uint8_t iPreviousCubeIndexZ = previousBitmask[getIndex(x,y, regSlice.width()+1)];
iCubeIndex = iPreviousCubeIndexZ >> 4;
if (v001 == 0) iCubeIndex |= 16;
@ -294,20 +294,20 @@ namespace PolyVox
}
else if((x>0) && y==0)
{
const uint8 v101 = volIter.peekVoxel1px0py1pz();
const uint8 v111 = volIter.peekVoxel1px1py1pz();
const uint8_t v101 = volIter.peekVoxel1px0py1pz();
const uint8_t v111 = volIter.peekVoxel1px1py1pz();
//z
uint8 iPreviousCubeIndexZ = previousBitmask[getIndex(x,y, regSlice.width()+1)];
uint8_t iPreviousCubeIndexZ = previousBitmask[getIndex(x,y, regSlice.width()+1)];
iCubeIndex = iPreviousCubeIndexZ >> 4;
//x
uint8 iPreviousCubeIndexX = bitmask[getIndex(x-1,y, regSlice.width()+1)];
uint8 srcBit6 = iPreviousCubeIndexX & 64;
uint8 destBit7 = srcBit6 << 1;
uint8_t iPreviousCubeIndexX = bitmask[getIndex(x-1,y, regSlice.width()+1)];
uint8_t srcBit6 = iPreviousCubeIndexX & 64;
uint8_t destBit7 = srcBit6 << 1;
uint8 srcBit5 = iPreviousCubeIndexX & 32;
uint8 destBit4 = srcBit5 >> 1;
uint8_t srcBit5 = iPreviousCubeIndexX & 32;
uint8_t destBit4 = srcBit5 >> 1;
iCubeIndex |= destBit4;
if (v101 == 0) iCubeIndex |= 32;
@ -316,20 +316,20 @@ namespace PolyVox
}
else if((x==0) && (y>0))
{
const uint8 v011 = volIter.peekVoxel0px1py1pz();
const uint8 v111 = volIter.peekVoxel1px1py1pz();
const uint8_t v011 = volIter.peekVoxel0px1py1pz();
const uint8_t v111 = volIter.peekVoxel1px1py1pz();
//z
uint8 iPreviousCubeIndexZ = previousBitmask[getIndex(x,y, regSlice.width()+1)];
uint8_t iPreviousCubeIndexZ = previousBitmask[getIndex(x,y, regSlice.width()+1)];
iCubeIndex = iPreviousCubeIndexZ >> 4;
//y
uint8 iPreviousCubeIndexY = bitmask[getIndex(x,y-1, regSlice.width()+1)];
uint8 srcBit7 = iPreviousCubeIndexY & 128;
uint8 destBit4 = srcBit7 >> 3;
uint8_t iPreviousCubeIndexY = bitmask[getIndex(x,y-1, regSlice.width()+1)];
uint8_t srcBit7 = iPreviousCubeIndexY & 128;
uint8_t destBit4 = srcBit7 >> 3;
uint8 srcBit6 = iPreviousCubeIndexY & 64;
uint8 destBit5 = srcBit6 >> 1;
uint8_t srcBit6 = iPreviousCubeIndexY & 64;
uint8_t destBit5 = srcBit6 >> 1;
iCubeIndex |= destBit4;
iCubeIndex |= destBit5;
@ -338,24 +338,24 @@ namespace PolyVox
}
else
{
const uint8 v111 = volIter.peekVoxel1px1py1pz();
const uint8_t v111 = volIter.peekVoxel1px1py1pz();
//z
uint8 iPreviousCubeIndexZ = previousBitmask[getIndex(x,y, regSlice.width()+1)];
uint8_t iPreviousCubeIndexZ = previousBitmask[getIndex(x,y, regSlice.width()+1)];
iCubeIndex = iPreviousCubeIndexZ >> 4;
//y
uint8 iPreviousCubeIndexY = bitmask[getIndex(x,y-1, regSlice.width()+1)];
uint8 srcBit7 = iPreviousCubeIndexY & 128;
uint8 destBit4 = srcBit7 >> 3;
uint8_t iPreviousCubeIndexY = bitmask[getIndex(x,y-1, regSlice.width()+1)];
uint8_t srcBit7 = iPreviousCubeIndexY & 128;
uint8_t destBit4 = srcBit7 >> 3;
uint8 srcBit6 = iPreviousCubeIndexY & 64;
uint8 destBit5 = srcBit6 >> 1;
uint8_t srcBit6 = iPreviousCubeIndexY & 64;
uint8_t destBit5 = srcBit6 >> 1;
//x
uint8 iPreviousCubeIndexX = bitmask[getIndex(x-1,y, regSlice.width()+1)];
uint8_t iPreviousCubeIndexX = bitmask[getIndex(x-1,y, regSlice.width()+1)];
srcBit6 = iPreviousCubeIndexX & 64;
uint8 destBit7 = srcBit6 << 1;
uint8_t destBit7 = srcBit6 << 1;
iCubeIndex |= destBit4;
iCubeIndex |= destBit5;
@ -376,7 +376,7 @@ namespace PolyVox
return uNoOfNonEmptyCells;
}
void generateRoughVerticesForSlice(VolumeIterator<uint8>& volIter, Region& regSlice, const Vector3DFloat& offset, uint8* bitmask, IndexedSurfacePatch* singleMaterialPatch,int32 vertexIndicesX[],int32 vertexIndicesY[],int32 vertexIndicesZ[])
void generateRoughVerticesForSlice(VolumeIterator<uint8_t>& volIter, Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,int32_t vertexIndicesX[],int32_t vertexIndicesY[],int32_t vertexIndicesZ[])
{
//Iterate over each cell in the region
volIter.setPosition(regSlice.getLowerCorner().getX(),regSlice.getLowerCorner().getY(), regSlice.getLowerCorner().getZ());
@ -385,14 +385,14 @@ namespace PolyVox
do
{
//Current position
const uint16 x = volIter.getPosX() - offset.getX();
const uint16 y = volIter.getPosY() - offset.getY();
const uint16 z = volIter.getPosZ() - offset.getZ();
const uint16_t x = volIter.getPosX() - offset.getX();
const uint16_t y = volIter.getPosY() - offset.getY();
const uint16_t z = volIter.getPosZ() - offset.getZ();
const uint8 v000 = volIter.getVoxel();
const uint8_t v000 = volIter.getVoxel();
//Determine the index into the edge table which tells us which vertices are inside of the surface
uint8 iCubeIndex = bitmask[getIndex(x,y, regSlice.width()+1)];
uint8_t iCubeIndex = bitmask[getIndex(x,y, regSlice.width()+1)];
/* Cube is entirely in/out of the surface */
if (edgeTable[iCubeIndex] == 0)
@ -405,12 +405,12 @@ namespace PolyVox
{
if((x + offset.getX()) != regSlice.getUpperCorner().getX())
{
const uint8 v100 = volIter.peekVoxel1px0py0pz();
const uint8_t v100 = volIter.peekVoxel1px0py0pz();
const Vector3DFloat v3dPosition(x + 0.5f, y, z);
const Vector3DFloat v3dNormal(v000 > v100 ? 1.0f : -1.0f, 0.0f, 0.0f);
const uint8 uMaterial = v000 | v100; //Because one of these is 0, the or operation takes the max.
const uint8_t uMaterial = v000 | v100; //Because one of these is 0, the or operation takes the max.
const SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial);
uint32 uLastVertexIndex = singleMaterialPatch->addVertex(surfaceVertex);
uint32_t uLastVertexIndex = singleMaterialPatch->addVertex(surfaceVertex);
vertexIndicesX[getIndex(x,y, regSlice.width()+1)] = uLastVertexIndex;
}
}
@ -418,12 +418,12 @@ namespace PolyVox
{
if((y + offset.getY()) != regSlice.getUpperCorner().getY())
{
const uint8 v010 = volIter.peekVoxel0px1py0pz();
const uint8_t v010 = volIter.peekVoxel0px1py0pz();
const Vector3DFloat v3dPosition(x, y + 0.5f, z);
const Vector3DFloat v3dNormal(0.0f, v000 > v010 ? 1.0f : -1.0f, 0.0f);
const uint8 uMaterial = v000 | v010;
const uint8_t uMaterial = v000 | v010;
SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial);
uint32 uLastVertexIndex = singleMaterialPatch->addVertex(surfaceVertex);
uint32_t uLastVertexIndex = singleMaterialPatch->addVertex(surfaceVertex);
vertexIndicesY[getIndex(x,y, regSlice.width()+1)] = uLastVertexIndex;
}
}
@ -431,21 +431,21 @@ namespace PolyVox
{
//if((z + offset.getZ()) != upperCorner.getZ())
{
const uint8 v001 = volIter.peekVoxel0px0py1pz();
const uint8_t v001 = volIter.peekVoxel0px0py1pz();
const Vector3DFloat v3dPosition(x, y, z + 0.5f);
const Vector3DFloat v3dNormal(0.0f, 0.0f, v000 > v001 ? 1.0f : -1.0f);
const uint8 uMaterial = v000 | v001;
const uint8_t uMaterial = v000 | v001;
SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial);
uint32 uLastVertexIndex = singleMaterialPatch->addVertex(surfaceVertex);
uint32_t uLastVertexIndex = singleMaterialPatch->addVertex(surfaceVertex);
vertexIndicesZ[getIndex(x,y, regSlice.width()+1)] = uLastVertexIndex;
}
}
}while(volIter.moveForwardInRegionXYZ());//For each cell
}
void generateRoughIndicesForSlice(VolumeIterator<uint8>& volIter, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, uint8* bitmask0, uint8* bitmask1, int32 vertexIndicesX0[],int32 vertexIndicesY0[],int32 vertexIndicesZ0[], int32 vertexIndicesX1[],int32 vertexIndicesY1[],int32 vertexIndicesZ1[])
void generateRoughIndicesForSlice(VolumeIterator<uint8_t>& volIter, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, uint8_t* bitmask0, uint8_t* bitmask1, int32_t vertexIndicesX0[],int32_t vertexIndicesY0[],int32_t vertexIndicesZ0[], int32_t vertexIndicesX1[],int32_t vertexIndicesY1[],int32_t vertexIndicesZ1[])
{
uint32 indlist[12];
uint32_t indlist[12];
Region regCroppedSlice(regSlice);
regCroppedSlice.setUpperCorner(regCroppedSlice.getUpperCorner() - Vector3DInt32(1,1,0));
@ -455,12 +455,12 @@ namespace PolyVox
do
{
//Current position
const uint16 x = volIter.getPosX() - offset.getX();
const uint16 y = volIter.getPosY() - offset.getY();
const uint16 z = volIter.getPosZ() - offset.getZ();
const uint16_t x = volIter.getPosX() - offset.getX();
const uint16_t y = volIter.getPosY() - offset.getY();
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 iCubeIndex = bitmask0[getIndex(x,y, regSlice.width()+1)];
uint8_t iCubeIndex = bitmask0[getIndex(x,y, regSlice.width()+1)];
/* Cube is entirely in/out of the surface */
if (edgeTable[iCubeIndex] == 0)
@ -532,9 +532,9 @@ namespace PolyVox
for (int i=0;triTable[iCubeIndex][i]!=-1;i+=3)
{
uint32 ind0 = indlist[triTable[iCubeIndex][i ]];
uint32 ind1 = indlist[triTable[iCubeIndex][i+1]];
uint32 ind2 = indlist[triTable[iCubeIndex][i+2]];
uint32_t ind0 = indlist[triTable[iCubeIndex][i ]];
uint32_t ind1 = indlist[triTable[iCubeIndex][i+1]];
uint32_t ind2 = indlist[triTable[iCubeIndex][i+2]];
singleMaterialPatch->addTriangle(ind0, ind1, ind2);
}//For each triangle

View File

@ -31,16 +31,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
namespace PolyVox
{
void extractReferenceSurfaceImpl(Volume<uint8>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch)
void extractReferenceSurfaceImpl(Volume<uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch)
{
/*static int32 vertexIndicesX[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];
static int32 vertexIndicesY[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];
static int32 vertexIndicesZ[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];*/
/*static int32_t vertexIndicesX[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];
static int32_t vertexIndicesY[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];
static int32_t vertexIndicesZ[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];*/
Vector3DInt32 regionDimensions = region.dimensions() + Vector3DInt32(1,1,1);
std::vector<int32> vertexIndicesX(regionDimensions.getX() * regionDimensions.getY() * regionDimensions.getZ());
std::vector<int32> vertexIndicesY(regionDimensions.getX() * regionDimensions.getY() * regionDimensions.getZ());
std::vector<int32> vertexIndicesZ(regionDimensions.getX() * regionDimensions.getY() * regionDimensions.getZ());
std::vector<int32_t> vertexIndicesX(regionDimensions.getX() * regionDimensions.getY() * regionDimensions.getZ());
std::vector<int32_t> vertexIndicesY(regionDimensions.getX() * regionDimensions.getY() * regionDimensions.getZ());
std::vector<int32_t> vertexIndicesZ(regionDimensions.getX() * regionDimensions.getY() * regionDimensions.getZ());
memset(&vertexIndicesX[0],0xFF,sizeof(vertexIndicesX[0]) * vertexIndicesX.size()); //0xFF is -1 as two's complement - this may not be portable...
memset(&vertexIndicesY[0],0xFF,sizeof(vertexIndicesY[0]) * vertexIndicesY.size()); //FIXME - can we just use sizeof(vertexIndicesY)?
@ -58,8 +58,8 @@ namespace PolyVox
Vector3DFloat vertlist[12];
Vector3DFloat normlist[12];
uint8 vertMaterials[12];
VolumeIterator<uint8> volIter(*volumeData);
uint8_t vertMaterials[12];
VolumeIterator<uint8_t> volIter(*volumeData);
volIter.setValidRegion(region);
//////////////////////////////////////////////////////////////////////////
@ -71,22 +71,22 @@ namespace PolyVox
while(volIter.moveForwardInRegionXYZ())
{
//Current position
const uint16 x = volIter.getPosX();
const uint16 y = volIter.getPosY();
const uint16 z = volIter.getPosZ();
const uint16_t x = volIter.getPosX();
const uint16_t y = volIter.getPosY();
const uint16_t z = volIter.getPosZ();
//Voxels values
const uint8 v000 = volIter.getVoxel();
const uint8 v100 = volIter.peekVoxel1px0py0pz();
const uint8 v010 = volIter.peekVoxel0px1py0pz();
const uint8 v110 = volIter.peekVoxel1px1py0pz();
const uint8 v001 = volIter.peekVoxel0px0py1pz();
const uint8 v101 = volIter.peekVoxel1px0py1pz();
const uint8 v011 = volIter.peekVoxel0px1py1pz();
const uint8 v111 = volIter.peekVoxel1px1py1pz();
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 iCubeIndex = 0;
uint8_t iCubeIndex = 0;
if (v000 == 0) iCubeIndex |= 1;
if (v100 == 0) iCubeIndex |= 2;
@ -241,30 +241,30 @@ namespace PolyVox
//const Vector3DFloat vertex1AsFloat = (static_cast<Vector3DFloat>(vertex1) / 2.0f) - offset;
//const Vector3DFloat vertex2AsFloat = (static_cast<Vector3DFloat>(vertex2) / 2.0f) - offset;
const uint8 material0 = vertMaterials[triTable[iCubeIndex][i ]];
const uint8 material1 = vertMaterials[triTable[iCubeIndex][i+1]];
const uint8 material2 = vertMaterials[triTable[iCubeIndex][i+2]];
const uint8_t material0 = vertMaterials[triTable[iCubeIndex][i ]];
const uint8_t material1 = vertMaterials[triTable[iCubeIndex][i+1]];
const uint8_t material2 = vertMaterials[triTable[iCubeIndex][i+2]];
//If all the materials are the same, we just need one triangle for that material with all the alphas set high.
SurfaceVertex v0(vertex0, normal0, material0 + 0.1f);
SurfaceVertex v1(vertex1, normal1, material1 + 0.1f);
SurfaceVertex v2(vertex2, normal2, material2 + 0.1f);
int32 index0 = getIndexFor(v0.getPosition(), regionDimensions, vertexIndicesX, vertexIndicesY, vertexIndicesZ);
int32_t index0 = getIndexFor(v0.getPosition(), regionDimensions, vertexIndicesX, vertexIndicesY, vertexIndicesZ);
if(index0 == -1)
{
index0 = singleMaterialPatch->addVertex(v0);
setIndexFor(v0.getPosition(), regionDimensions, index0, vertexIndicesX, vertexIndicesY, vertexIndicesZ);
}
int32 index1 = getIndexFor(v1.getPosition(), regionDimensions, vertexIndicesX, vertexIndicesY, vertexIndicesZ);
int32_t index1 = getIndexFor(v1.getPosition(), regionDimensions, vertexIndicesX, vertexIndicesY, vertexIndicesZ);
if(index1 == -1)
{
index1 = singleMaterialPatch->addVertex(v1);
setIndexFor(v1.getPosition(), regionDimensions, index1, vertexIndicesX, vertexIndicesY, vertexIndicesZ);
}
int32 index2 = getIndexFor(v2.getPosition(), regionDimensions, vertexIndicesX, vertexIndicesY, vertexIndicesZ);
int32_t index2 = getIndexFor(v2.getPosition(), regionDimensions, vertexIndicesX, vertexIndicesY, vertexIndicesZ);
if(index2 == -1)
{
index2 = singleMaterialPatch->addVertex(v2);
@ -276,7 +276,7 @@ namespace PolyVox
}//For each cell
}
int32 getIndexFor(const Vector3DFloat& pos, const Vector3DInt32& regionDimensions, const std::vector<int32>& vertexIndicesX, const std::vector<int32>& vertexIndicesY, const std::vector<int32>& vertexIndicesZ)
int32_t getIndexFor(const Vector3DFloat& pos, const Vector3DInt32& regionDimensions, const std::vector<int32_t>& vertexIndicesX, const std::vector<int32_t>& vertexIndicesY, const std::vector<int32_t>& vertexIndicesZ)
{
float xIntPartAsFloat;
float xFracPart = std::modf(pos.getX(), &xIntPartAsFloat);
@ -285,9 +285,9 @@ namespace PolyVox
float zIntPartAsFloat;
float zFracPart = std::modf(pos.getZ(), &zIntPartAsFloat);
uint16 xIntPart = static_cast<uint16>(xIntPartAsFloat);
uint16 yIntPart = static_cast<uint16>(yIntPartAsFloat);
uint16 zIntPart = static_cast<uint16>(zIntPartAsFloat);
uint16_t xIntPart = static_cast<uint16_t>(xIntPartAsFloat);
uint16_t yIntPart = static_cast<uint16_t>(yIntPartAsFloat);
uint16_t zIntPart = static_cast<uint16_t>(zIntPartAsFloat);
//Of all the fractional parts, two should be zero and one should be 0.5.
if(xFracPart > 0.25f)
@ -304,7 +304,7 @@ namespace PolyVox
}
}
void setIndexFor(const Vector3DFloat& pos, const Vector3DInt32& regionDimensions, int32 newIndex, std::vector<int32>& vertexIndicesX, std::vector<int32>& vertexIndicesY, std::vector<int32>& vertexIndicesZ)
void setIndexFor(const Vector3DFloat& pos, const Vector3DInt32& regionDimensions, int32_t newIndex, std::vector<int32_t>& vertexIndicesX, std::vector<int32_t>& vertexIndicesY, std::vector<int32_t>& vertexIndicesZ)
{
float xIntPartAsFloat;
float xFracPart = std::modf(pos.getX(), &xIntPartAsFloat);
@ -313,9 +313,9 @@ namespace PolyVox
float zIntPartAsFloat;
float zFracPart = std::modf(pos.getZ(), &zIntPartAsFloat);
uint16 xIntPart = static_cast<uint16>(xIntPartAsFloat);
uint16 yIntPart = static_cast<uint16>(yIntPartAsFloat);
uint16 zIntPart = static_cast<uint16>(zIntPartAsFloat);
uint16_t xIntPart = static_cast<uint16_t>(xIntPartAsFloat);
uint16_t yIntPart = static_cast<uint16_t>(yIntPartAsFloat);
uint16_t zIntPart = static_cast<uint16_t>(zIntPartAsFloat);
//Of all the fractional parts, two should be zero and one should be 0.5.
if(xFracPart > 0.25f)

View File

@ -44,7 +44,7 @@ namespace PolyVox
&& (pos.getZ() >= m_v3dLowerCorner.getZ() + boundary);
}
bool Region::containsPoint(const Vector3DInt32& pos, uint8 boundary) const
bool Region::containsPoint(const Vector3DInt32& pos, uint8_t boundary) const
{
return (pos.getX() <= m_v3dUpperCorner.getX() - boundary)
&& (pos.getY() <= m_v3dUpperCorner.getY() - boundary)
@ -64,12 +64,12 @@ namespace PolyVox
m_v3dUpperCorner.setZ((std::min)(m_v3dUpperCorner.getZ(), other.m_v3dUpperCorner.getZ()));
}
int32 Region::depth(void) const
int32_t Region::depth(void) const
{
return m_v3dUpperCorner.getZ() - m_v3dLowerCorner.getZ();
}
int32 Region::height(void) const
int32_t Region::height(void) const
{
return m_v3dUpperCorner.getY() - m_v3dLowerCorner.getY();
}
@ -95,7 +95,7 @@ namespace PolyVox
return m_v3dUpperCorner - m_v3dLowerCorner;
}
int32 Region::width(void) const
int32_t Region::width(void) const
{
return m_v3dUpperCorner.getX() - m_v3dLowerCorner.getX();
}

View File

@ -12,12 +12,12 @@ using namespace std;
namespace PolyVox
{
void smoothRegionGeometry(Volume<uint8>* volumeData, IndexedSurfacePatch& isp)
void smoothRegionGeometry(Volume<uint8_t>* volumeData, IndexedSurfacePatch& isp)
{
const uint8 uSmoothingFactor = 2;
const uint8_t uSmoothingFactor = 2;
const float fThreshold = 0.5f;
VolumeIterator<uint8> volIter(*volumeData);
VolumeIterator<uint8_t> volIter(*volumeData);
std::vector<SurfaceVertex>& vecVertices = isp.getRawVertexData();
std::vector<SurfaceVertex>::iterator iterSurfaceVertex = vecVertices.begin();
@ -76,9 +76,9 @@ namespace PolyVox
} //while(iterSurfaceVertex != vecVertices.end())
}
void adjustDecimatedGeometry(Volume<uint8>* volumeData, IndexedSurfacePatch& isp, uint8 val)
void adjustDecimatedGeometry(Volume<uint8_t>* volumeData, IndexedSurfacePatch& isp, uint8_t val)
{
VolumeIterator<uint8> volIter(*volumeData);
VolumeIterator<uint8_t> volIter(*volumeData);
std::vector<SurfaceVertex>& vecVertices = isp.getRawVertexData();
std::vector<SurfaceVertex>::iterator iterSurfaceVertex = vecVertices.begin();
@ -87,7 +87,7 @@ namespace PolyVox
Vector3DFloat v3dPos = iterSurfaceVertex->getPosition() + static_cast<Vector3DFloat>(isp.m_v3dRegionPosition);
Vector3DInt32 v3dFloor = static_cast<Vector3DInt32>(v3dPos);
VolumeIterator<uint8> volIter(*volumeData);
VolumeIterator<uint8_t> volIter(*volumeData);
//Check all corners are within the volume, allowing a boundary for gradient estimation
bool lowerCornerInside = volumeData->getEnclosingRegion().containsPoint(v3dFloor,1);
@ -96,7 +96,7 @@ namespace PolyVox
if(lowerCornerInside && upperCornerInside) //If this test fails the vertex will be left as it was
{
//volIter.setPosition(static_cast<Vector3DInt16>(v3dFloor));
//const uint8 uFloor = volIter.getVoxel();
//const uint8_t uFloor = volIter.getVoxel();
if(((v3dPos.getX() - v3dFloor.getX()) < 0.001) && ((v3dPos.getY() - v3dFloor.getY()) < 0.001) && ((v3dPos.getZ() - v3dFloor.getZ()) < 0.001))
//int x = v3dPos.getX();
//if(x % 2 != 0)
@ -104,7 +104,7 @@ namespace PolyVox
{
//exit(0);
//volIter.setPosition(static_cast<Vector3DInt16>(v3dFloor+Vector3DInt32(1,0,0)));
//const uint8 uCeil = volIter.getVoxel();
//const uint8_t uCeil = volIter.getVoxel();
//if(uFloor == uCeil) //In this case they must both be zero
{
//if(iterSurfaceVertex->getNormal().getX() > 0)
@ -114,9 +114,9 @@ namespace PolyVox
v3dFloor = static_cast<Vector3DInt32>(v3dPos);
volIter.setPosition(static_cast<Vector3DInt16>(v3dFloor));
const uint8 uFloor = volIter.getVoxel();
const uint8_t uFloor = volIter.getVoxel();
uint8 uCeil;
uint8_t uCeil;
if((iterSurfaceVertex->getNormal().getX() > 0.5f) || (iterSurfaceVertex->getNormal().getX() < -0.5f))
{
volIter.setPosition(static_cast<Vector3DInt16>(v3dFloor+Vector3DInt32(1,0,0)));

View File

@ -18,7 +18,7 @@ using namespace std;
namespace PolyVox
{
void extractSurface(Volume<uint8>* volumeData, uint8 uLevel, Region region, IndexedSurfacePatch* singleMaterialPatch)
void extractSurface(Volume<uint8_t>* volumeData, uint8_t uLevel, Region region, IndexedSurfacePatch* singleMaterialPatch)
{
if(uLevel == 0)
{
@ -32,7 +32,7 @@ namespace PolyVox
singleMaterialPatch->m_v3dRegionPosition = region.getLowerCorner();
}
void extractReferenceSurface(Volume<uint8>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch)
void extractReferenceSurface(Volume<uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch)
{
extractReferenceSurfaceImpl(volumeData, region, singleMaterialPatch);

View File

@ -28,7 +28,7 @@ namespace PolyVox
{
//Note: this function only works for inputs which are a power of two and not zero
//If this is not the case then the output is undefined.
uint8 logBase2(uint32 uInput)
uint8_t logBase2(uint32_t uInput)
{
//Debug mode validation
assert(uInput != 0);
@ -44,16 +44,16 @@ namespace PolyVox
throw std::invalid_argument("Input must be a power of two in order to compute the log.");
}
uint32 uResult = 0;
uint32_t uResult = 0;
while( (uInput >> uResult) != 0)
{
++uResult;
}
return static_cast<uint8>(uResult-1);
return static_cast<uint8_t>(uResult-1);
}
bool isPowerOf2(uint32 uInput)
bool isPowerOf2(uint32_t uInput)
{
if(uInput == 0)
return false;

View File

@ -4,7 +4,7 @@
namespace PolyVox
{
float computeSmoothedVoxel(VolumeIterator<uint8>& volIter)
float computeSmoothedVoxel(VolumeIterator<uint8_t>& volIter)
{
assert(volIter.getPosX() >= 1);
assert(volIter.getPosY() >= 1);