Improved Array class for multidimensional arrays.
This commit is contained in:
parent
f39c2afcb2
commit
5746a80517
@ -33,146 +33,128 @@ freely, subject to the following restrictions:
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template<uint32_t dimensions, typename ElementType>
|
||||
class POLYVOXCORE_API Array
|
||||
template <uint32_t noOfDims, typename ElementType>
|
||||
class Array
|
||||
{
|
||||
friend class Array<noOfDims+1, ElementType>;
|
||||
|
||||
public:
|
||||
Array()
|
||||
:m_uWidth(0)
|
||||
,m_uHeight(0)
|
||||
,m_pData(0)
|
||||
Array<noOfDims, ElementType>(const uint32_t (&Dimensions)[noOfDims])
|
||||
: m_pElements(0)
|
||||
,m_pDimensions(0)
|
||||
,m_pOffsets(0)
|
||||
,m_uNoOfElements(0)
|
||||
{
|
||||
}
|
||||
|
||||
Array(uint32_t width)
|
||||
:m_uWidth(width)
|
||||
,m_uHeight(0)
|
||||
,m_pData(0)
|
||||
{
|
||||
m_pData = new ElementType[width];
|
||||
assert(m_pData);
|
||||
}
|
||||
|
||||
Array(uint32_t width, uint32_t height)
|
||||
:m_uWidth(width)
|
||||
,m_uHeight(height)
|
||||
,m_pData(0)
|
||||
{
|
||||
m_pData = new ElementType[width * height];
|
||||
assert(m_pData);
|
||||
}
|
||||
|
||||
/*Array2D(const Array2D& rhs)
|
||||
:m_uWidth(0)
|
||||
,m_uHeight(0)
|
||||
,m_pData(0)
|
||||
{
|
||||
*this = rhs;
|
||||
}*/
|
||||
|
||||
~Array()
|
||||
{
|
||||
if(m_pData)
|
||||
m_pDimensions = new uint32_t[noOfDims];
|
||||
m_pOffsets = new uint32_t[noOfDims];
|
||||
|
||||
// Calculate all the information you need to use the array
|
||||
m_uNoOfElements=1;
|
||||
for (uint32_t i=0; i<noOfDims; i++)
|
||||
{
|
||||
delete[] m_pData;
|
||||
}
|
||||
m_pData = 0;
|
||||
assert(Dimensions[i] != 0);
|
||||
|
||||
m_uNoOfElements*=Dimensions[i];
|
||||
m_pDimensions[i]=Dimensions[i];
|
||||
m_pOffsets[i]=1;
|
||||
for (int k=noOfDims-1; k>i; k--)
|
||||
m_pOffsets[i]*=Dimensions[k];
|
||||
}
|
||||
// Allocate new elements, let exception propagate
|
||||
m_pElements=new ElementType[m_uNoOfElements];
|
||||
}
|
||||
|
||||
Array<noOfDims-1, ElementType> operator [](uint32_t uIndex)
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return
|
||||
Array<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||
m_pDimensions+1, m_pOffsets+1);
|
||||
}
|
||||
const Array<noOfDims-1, ElementType>
|
||||
operator [](uint32_t uIndex) const
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return
|
||||
Array<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||
m_pDimensions+1, m_pOffsets+1);
|
||||
}
|
||||
|
||||
/*Array2D& operator=(const Array2D& rhs)
|
||||
ElementType* getRawData(void)
|
||||
{
|
||||
if(this == &rhs)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
if((m_uWidth != rhs.m_uWidth) || (m_uHeight != rhs.m_uHeight))
|
||||
{
|
||||
if(m_pData)
|
||||
{
|
||||
delete m_pData;
|
||||
}
|
||||
m_pData = 0;
|
||||
|
||||
m_uWidth = rhs.m_uWidth;
|
||||
m_uHeight = rhs.m_uHeight;
|
||||
|
||||
m_pData = new ElementType[m_uWidth * m_uHeight];
|
||||
}
|
||||
|
||||
std::memcpy(m_pData, rhs.m_pData, sizeof(ElementType) * m_uWidth * m_uHeight);
|
||||
return *this;
|
||||
}*/
|
||||
|
||||
/*ElementType& operator() (uint32_t x, uint32_t y)
|
||||
{
|
||||
assert(x < m_uWidth);
|
||||
assert(y < m_uHeight);
|
||||
return m_pData[x * m_uWidth + y];
|
||||
return m_pElements;
|
||||
}
|
||||
|
||||
ElementType operator() (uint32_t x, uint32_t y) const
|
||||
uint32_t getNoOfElements(void)
|
||||
{
|
||||
assert(x < m_uWidth);
|
||||
assert(y < m_uHeight);
|
||||
return m_pData[x * m_uWidth + y];
|
||||
}*/
|
||||
|
||||
ElementType& getElement(uint32_t x) const
|
||||
{
|
||||
assert(x < m_uWidth);
|
||||
return m_pData[x];
|
||||
}
|
||||
|
||||
ElementType& getElement(uint32_t x, uint32_t y) const
|
||||
{
|
||||
assert(x < m_uWidth);
|
||||
assert(y < m_uHeight);
|
||||
return m_pData[x + y * m_uWidth];
|
||||
}
|
||||
|
||||
void setElement(uint32_t x, ElementType value)
|
||||
{
|
||||
assert(x < m_uWidth);
|
||||
m_pData[x] = value;
|
||||
}
|
||||
|
||||
void setElement(uint32_t x, uint32_t y, ElementType value)
|
||||
{
|
||||
assert(x < m_uWidth);
|
||||
assert(y < m_uHeight);
|
||||
m_pData[x + y * m_uWidth] = value;
|
||||
}
|
||||
|
||||
void swap(Array& rhs)
|
||||
{
|
||||
assert(m_uWidth == rhs.m_uWidth);
|
||||
assert(m_uHeight == rhs.m_uHeight);
|
||||
|
||||
ElementType* temp = m_pData;
|
||||
m_pData = rhs.m_pData;
|
||||
rhs.m_pData = temp;
|
||||
}
|
||||
|
||||
void fillWithUint8(uint8_t value)
|
||||
{
|
||||
memset(m_pData, value, m_uWidth * m_uHeight * sizeof(ElementType));
|
||||
return m_uNoOfElements;
|
||||
}
|
||||
|
||||
private:
|
||||
//Dimensions
|
||||
uint32_t m_uWidth;
|
||||
uint32_t m_uHeight;
|
||||
Array<noOfDims, ElementType>(ElementType * pElements, uint32_t * pDimensions, uint32_t * pOffsets)
|
||||
:m_pElements(pElements)
|
||||
,m_pDimensions(pDimensions)
|
||||
,m_pOffsets(pOffsets)
|
||||
,m_uNoOfElements(0)
|
||||
{
|
||||
}
|
||||
|
||||
//Data
|
||||
ElementType* m_pData;
|
||||
uint32_t * m_pDimensions;
|
||||
uint32_t * m_pOffsets;
|
||||
uint32_t m_uNoOfElements;
|
||||
ElementType * m_pElements;
|
||||
};
|
||||
|
||||
template <typename ElementType>
|
||||
class Array<1, ElementType>
|
||||
{
|
||||
friend class Array<2, ElementType>;
|
||||
|
||||
public:
|
||||
ElementType & operator [] (uint32_t uIndex)
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return m_pElements[uIndex];
|
||||
}
|
||||
|
||||
const ElementType & operator [] (uint32_t uIndex) const
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return m_pElements[uIndex];
|
||||
}
|
||||
|
||||
ElementType* getRawData(void)
|
||||
{
|
||||
return m_pElements;
|
||||
}
|
||||
|
||||
uint32_t getNoOfElements(void)
|
||||
{
|
||||
return m_pDimensions[0];
|
||||
}
|
||||
|
||||
private:
|
||||
Array<1, ElementType>(ElementType * pElements, uint32_t * pDimensions, uint32_t * /*pOffsets*/)
|
||||
:m_pDimensions(pDimensions)
|
||||
,m_pElements(pElements)
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t * m_pDimensions;
|
||||
ElementType * m_pElements;
|
||||
};
|
||||
|
||||
template <typename ElementType>
|
||||
class Array<0, ElementType>
|
||||
{
|
||||
//Zero dimensional array is meaningless.
|
||||
};
|
||||
|
||||
//Some handy typedefs
|
||||
///A 1D Array of floats.
|
||||
typedef Array<1,float> Array1DFloat;
|
||||
///A 1D Array of doubles.
|
||||
typedef Array<1,double> Array1DDouble;
|
||||
typedef Array<1,double> Array1DDouble;
|
||||
///A 1D Array of signed 8-bit values.
|
||||
typedef Array<1,int8_t> Array1DInt8;
|
||||
///A 1D Array of unsigned 8-bit values.
|
||||
|
@ -65,16 +65,41 @@ namespace PolyVox
|
||||
m_pCurrentVertexIndicesY = new int32_t[m_uScratchPadWidth * m_uScratchPadHeight];
|
||||
m_pCurrentVertexIndicesZ = new int32_t[m_uScratchPadWidth * m_uScratchPadHeight];*/
|
||||
|
||||
Array2DInt32 m_pPreviousVertexIndicesX(m_uScratchPadWidth, m_uScratchPadHeight);
|
||||
uint32_t Size2 [2]= {m_uScratchPadWidth, m_uScratchPadHeight}; // Array dimensions
|
||||
|
||||
/*Array2DInt32 m_pPreviousVertexIndicesX(m_uScratchPadWidth, m_uScratchPadHeight);
|
||||
Array2DInt32 m_pPreviousVertexIndicesY(m_uScratchPadWidth, m_uScratchPadHeight);
|
||||
Array2DInt32 m_pPreviousVertexIndicesZ(m_uScratchPadWidth, m_uScratchPadHeight);
|
||||
Array2DInt32 m_pCurrentVertexIndicesX(m_uScratchPadWidth, m_uScratchPadHeight);
|
||||
Array2DInt32 m_pCurrentVertexIndicesY(m_uScratchPadWidth, m_uScratchPadHeight);
|
||||
Array2DInt32 m_pCurrentVertexIndicesZ(m_uScratchPadWidth, m_uScratchPadHeight);
|
||||
Array2DInt32 m_pCurrentVertexIndicesZ(m_uScratchPadWidth, m_uScratchPadHeight);*/
|
||||
|
||||
Array2DInt32 m_pPreviousVertexIndicesX(Size2);
|
||||
Array2DInt32 m_pPreviousVertexIndicesY(Size2);
|
||||
Array2DInt32 m_pPreviousVertexIndicesZ(Size2);
|
||||
Array2DInt32 m_pCurrentVertexIndicesX(Size2);
|
||||
Array2DInt32 m_pCurrentVertexIndicesY(Size2);
|
||||
Array2DInt32 m_pCurrentVertexIndicesZ(Size2);
|
||||
|
||||
|
||||
|
||||
/*m_pPreviousVertexIndicesX.resize(Size2);
|
||||
m_pPreviousVertexIndicesY.resize(Size2);
|
||||
m_pPreviousVertexIndicesZ.resize(Size2);
|
||||
m_pCurrentVertexIndicesX.resize(Size2);
|
||||
m_pCurrentVertexIndicesY.resize(Size2);
|
||||
m_pCurrentVertexIndicesZ.resize(Size2);*/
|
||||
|
||||
|
||||
//Cell bitmasks
|
||||
Array2DUint8 pPreviousBitmask(m_uScratchPadWidth, m_uScratchPadHeight);
|
||||
Array2DUint8 pCurrentBitmask(m_uScratchPadWidth, m_uScratchPadHeight);
|
||||
/*Array2DUint8 pPreviousBitmask(m_uScratchPadWidth, m_uScratchPadHeight);
|
||||
Array2DUint8 pCurrentBitmask(m_uScratchPadWidth, m_uScratchPadHeight);*/
|
||||
|
||||
Array2DUint8 pPreviousBitmask(Size2);
|
||||
Array2DUint8 pCurrentBitmask(Size2);
|
||||
|
||||
/*pPreviousBitmask.resize(Size2);
|
||||
pCurrentBitmask.resize(Size2);*/
|
||||
|
||||
//Create a region corresponding to the first slice
|
||||
m_regSlicePrevious = m_regInputCropped;
|
||||
@ -92,20 +117,17 @@ namespace PolyVox
|
||||
|
||||
if(uNoOfNonEmptyCellsForSlice1 != 0)
|
||||
{
|
||||
/*memset(m_pCurrentVertexIndicesX, 0xff, m_uScratchPadWidth * m_uScratchPadHeight * 4);
|
||||
memset(m_pCurrentVertexIndicesY, 0xff, m_uScratchPadWidth * m_uScratchPadHeight * 4);
|
||||
memset(m_pCurrentVertexIndicesZ, 0xff, m_uScratchPadWidth * m_uScratchPadHeight * 4);*/
|
||||
m_pCurrentVertexIndicesX.fillWithUint8(0xff);
|
||||
m_pCurrentVertexIndicesY.fillWithUint8(0xff);
|
||||
m_pCurrentVertexIndicesZ.fillWithUint8(0xff);
|
||||
memset(m_pCurrentVertexIndicesX.getRawData(), 0xff, m_pCurrentVertexIndicesX.getNoOfElements() * 4);
|
||||
memset(m_pCurrentVertexIndicesY.getRawData(), 0xff, m_pCurrentVertexIndicesY.getNoOfElements() * 4);
|
||||
memset(m_pCurrentVertexIndicesZ.getRawData(), 0xff, m_pCurrentVertexIndicesZ.getNoOfElements() * 4);
|
||||
generateVerticesForSlice(pCurrentBitmask, m_pCurrentVertexIndicesX, m_pCurrentVertexIndicesY, m_pCurrentVertexIndicesZ);
|
||||
}
|
||||
|
||||
std::swap(uNoOfNonEmptyCellsForSlice0, uNoOfNonEmptyCellsForSlice1);
|
||||
pPreviousBitmask.swap(pCurrentBitmask);
|
||||
m_pPreviousVertexIndicesX.swap(m_pCurrentVertexIndicesX);
|
||||
m_pPreviousVertexIndicesY.swap(m_pCurrentVertexIndicesY);
|
||||
m_pPreviousVertexIndicesZ.swap(m_pCurrentVertexIndicesZ);
|
||||
std::swap(pPreviousBitmask, pCurrentBitmask);
|
||||
std::swap(m_pPreviousVertexIndicesX, m_pCurrentVertexIndicesX);
|
||||
std::swap(m_pPreviousVertexIndicesY, m_pCurrentVertexIndicesY);
|
||||
std::swap(m_pPreviousVertexIndicesZ, m_pCurrentVertexIndicesZ);
|
||||
|
||||
m_regSlicePrevious = m_regSliceCurrent;
|
||||
m_regSliceCurrent.shift(Vector3DInt16(0,0,1));
|
||||
@ -118,12 +140,9 @@ namespace PolyVox
|
||||
|
||||
if(uNoOfNonEmptyCellsForSlice1 != 0)
|
||||
{
|
||||
/*memset(m_pCurrentVertexIndicesX, 0xff, m_uScratchPadWidth * m_uScratchPadHeight * 4);
|
||||
memset(m_pCurrentVertexIndicesY, 0xff, m_uScratchPadWidth * m_uScratchPadHeight * 4);
|
||||
memset(m_pCurrentVertexIndicesZ, 0xff, m_uScratchPadWidth * m_uScratchPadHeight * 4);*/
|
||||
m_pCurrentVertexIndicesX.fillWithUint8(0xff);
|
||||
m_pCurrentVertexIndicesY.fillWithUint8(0xff);
|
||||
m_pCurrentVertexIndicesZ.fillWithUint8(0xff);
|
||||
memset(m_pCurrentVertexIndicesX.getRawData(), 0xff, m_pCurrentVertexIndicesX.getNoOfElements() * 4);
|
||||
memset(m_pCurrentVertexIndicesY.getRawData(), 0xff, m_pCurrentVertexIndicesY.getNoOfElements() * 4);
|
||||
memset(m_pCurrentVertexIndicesZ.getRawData(), 0xff, m_pCurrentVertexIndicesZ.getNoOfElements() * 4);
|
||||
generateVerticesForSlice(pCurrentBitmask, m_pCurrentVertexIndicesX, m_pCurrentVertexIndicesY, m_pCurrentVertexIndicesZ);
|
||||
}
|
||||
|
||||
@ -133,13 +152,10 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
std::swap(uNoOfNonEmptyCellsForSlice0, uNoOfNonEmptyCellsForSlice1);
|
||||
pPreviousBitmask.swap(pCurrentBitmask);
|
||||
m_pPreviousVertexIndicesX.swap(m_pCurrentVertexIndicesX);
|
||||
m_pPreviousVertexIndicesY.swap(m_pCurrentVertexIndicesY);
|
||||
m_pPreviousVertexIndicesZ.swap(m_pCurrentVertexIndicesZ);
|
||||
/*std::swap(m_pPreviousVertexIndicesX, m_pCurrentVertexIndicesX);
|
||||
std::swap(pPreviousBitmask, pCurrentBitmask);
|
||||
std::swap(m_pPreviousVertexIndicesX, m_pCurrentVertexIndicesX);
|
||||
std::swap(m_pPreviousVertexIndicesY, m_pCurrentVertexIndicesY);
|
||||
std::swap(m_pPreviousVertexIndicesZ, m_pCurrentVertexIndicesZ);*/
|
||||
std::swap(m_pPreviousVertexIndicesZ, m_pCurrentVertexIndicesZ);
|
||||
|
||||
m_regSlicePrevious = m_regSliceCurrent;
|
||||
m_regSliceCurrent.shift(Vector3DInt16(0,0,1));
|
||||
@ -149,12 +165,9 @@ namespace PolyVox
|
||||
m_regSliceCurrent.shift(Vector3DInt16(0,0,-1));
|
||||
if(m_regSliceCurrent.getLowerCorner().getZ() == m_regVolumeCropped.getUpperCorner().getZ())
|
||||
{
|
||||
/*memset(m_pCurrentVertexIndicesX, 0xff, m_uScratchPadWidth * m_uScratchPadHeight * 4);
|
||||
memset(m_pCurrentVertexIndicesY, 0xff, m_uScratchPadWidth * m_uScratchPadHeight * 4);
|
||||
memset(m_pCurrentVertexIndicesZ, 0xff, m_uScratchPadWidth * m_uScratchPadHeight * 4);*/
|
||||
m_pCurrentVertexIndicesX.fillWithUint8(0xff);
|
||||
m_pCurrentVertexIndicesY.fillWithUint8(0xff);
|
||||
m_pCurrentVertexIndicesZ.fillWithUint8(0xff);
|
||||
memset(m_pCurrentVertexIndicesX.getRawData(), 0xff, m_pCurrentVertexIndicesX.getNoOfElements() * 4);
|
||||
memset(m_pCurrentVertexIndicesY.getRawData(), 0xff, m_pCurrentVertexIndicesY.getNoOfElements() * 4);
|
||||
memset(m_pCurrentVertexIndicesZ.getRawData(), 0xff, m_pCurrentVertexIndicesZ.getNoOfElements() * 4);
|
||||
generateIndicesForSlice(pPreviousBitmask, m_pPreviousVertexIndicesX, m_pPreviousVertexIndicesY, m_pPreviousVertexIndicesZ, m_pCurrentVertexIndicesX, m_pCurrentVertexIndicesY, m_pCurrentVertexIndicesZ);
|
||||
}
|
||||
|
||||
@ -264,16 +277,16 @@ namespace PolyVox
|
||||
v111 = m_sampVolume.peekVoxel1px1py1pz();
|
||||
|
||||
//z
|
||||
uint8_t iPreviousCubeIndexZ = pPreviousBitmask.getElement(uXRegSpace,uYRegSpace);
|
||||
uint8_t iPreviousCubeIndexZ = pPreviousBitmask[uXRegSpace][uYRegSpace];
|
||||
iPreviousCubeIndexZ >>= 4;
|
||||
|
||||
//y
|
||||
uint8_t iPreviousCubeIndexY = pCurrentBitmask.getElement(uXRegSpace,uYRegSpace-1);
|
||||
uint8_t iPreviousCubeIndexY = pCurrentBitmask[uXRegSpace][uYRegSpace-1];
|
||||
iPreviousCubeIndexY &= 192; //192 = 128 + 64
|
||||
iPreviousCubeIndexY >>= 2;
|
||||
|
||||
//x
|
||||
uint8_t iPreviousCubeIndexX = pCurrentBitmask.getElement(uXRegSpace-1,uYRegSpace);
|
||||
uint8_t iPreviousCubeIndexX = pCurrentBitmask[uXRegSpace-1][uYRegSpace];
|
||||
iPreviousCubeIndexX &= 128;
|
||||
iPreviousCubeIndexX >>= 1;
|
||||
|
||||
@ -287,11 +300,11 @@ namespace PolyVox
|
||||
v111 = m_sampVolume.peekVoxel1px1py1pz();
|
||||
|
||||
//z
|
||||
uint8_t iPreviousCubeIndexZ = pPreviousBitmask.getElement(uXRegSpace,uYRegSpace);
|
||||
uint8_t iPreviousCubeIndexZ = pPreviousBitmask[uXRegSpace][uYRegSpace];
|
||||
iPreviousCubeIndexZ >>= 4;
|
||||
|
||||
//y
|
||||
uint8_t iPreviousCubeIndexY = pCurrentBitmask.getElement(uXRegSpace,uYRegSpace-1);
|
||||
uint8_t iPreviousCubeIndexY = pCurrentBitmask[uXRegSpace][uYRegSpace-1];
|
||||
iPreviousCubeIndexY &= 192; //192 = 128 + 64
|
||||
iPreviousCubeIndexY >>= 2;
|
||||
|
||||
@ -309,11 +322,11 @@ namespace PolyVox
|
||||
v111 = m_sampVolume.peekVoxel1px1py1pz();
|
||||
|
||||
//z
|
||||
uint8_t iPreviousCubeIndexZ = pPreviousBitmask.getElement(uXRegSpace,uYRegSpace);
|
||||
uint8_t iPreviousCubeIndexZ = pPreviousBitmask[uXRegSpace][uYRegSpace];
|
||||
iPreviousCubeIndexZ >>= 4;
|
||||
|
||||
//x
|
||||
uint8_t iPreviousCubeIndexX = pCurrentBitmask.getElement(uXRegSpace-1,uYRegSpace);
|
||||
uint8_t iPreviousCubeIndexX = pCurrentBitmask[uXRegSpace-1][uYRegSpace];
|
||||
iPreviousCubeIndexX &= 160; //160 = 128+32
|
||||
iPreviousCubeIndexX >>= 1;
|
||||
|
||||
@ -330,7 +343,7 @@ namespace PolyVox
|
||||
v111 = m_sampVolume.peekVoxel1px1py1pz();
|
||||
|
||||
//z
|
||||
uint8_t iPreviousCubeIndexZ = pPreviousBitmask.getElement(uXRegSpace,uYRegSpace);
|
||||
uint8_t iPreviousCubeIndexZ = pPreviousBitmask[uXRegSpace][uYRegSpace];
|
||||
iCubeIndex = iPreviousCubeIndexZ >> 4;
|
||||
|
||||
if (v001 == 0) iCubeIndex |= 16;
|
||||
@ -350,12 +363,12 @@ namespace PolyVox
|
||||
v111 = m_sampVolume.peekVoxel1px1py1pz();
|
||||
|
||||
//y
|
||||
uint8_t iPreviousCubeIndexY = pCurrentBitmask.getElement(uXRegSpace,uYRegSpace-1);
|
||||
uint8_t iPreviousCubeIndexY = pCurrentBitmask[uXRegSpace][uYRegSpace-1];
|
||||
iPreviousCubeIndexY &= 204; //204 = 128+64+8+4
|
||||
iPreviousCubeIndexY >>= 2;
|
||||
|
||||
//x
|
||||
uint8_t iPreviousCubeIndexX = pCurrentBitmask.getElement(uXRegSpace-1,uYRegSpace);
|
||||
uint8_t iPreviousCubeIndexX = pCurrentBitmask[uXRegSpace-1][uYRegSpace];
|
||||
iPreviousCubeIndexX &= 170; //170 = 128+32+8+2
|
||||
iPreviousCubeIndexX >>= 1;
|
||||
|
||||
@ -373,7 +386,7 @@ namespace PolyVox
|
||||
v111 = m_sampVolume.peekVoxel1px1py1pz();
|
||||
|
||||
//y
|
||||
uint8_t iPreviousCubeIndexY = pCurrentBitmask.getElement(uXRegSpace,uYRegSpace-1);
|
||||
uint8_t iPreviousCubeIndexY = pCurrentBitmask[uXRegSpace][uYRegSpace-1];
|
||||
iPreviousCubeIndexY &= 204; //204 = 128+64+8+4
|
||||
iPreviousCubeIndexY >>= 2;
|
||||
|
||||
@ -396,7 +409,7 @@ namespace PolyVox
|
||||
v111 = m_sampVolume.peekVoxel1px1py1pz();
|
||||
|
||||
//x
|
||||
uint8_t iPreviousCubeIndexX = pCurrentBitmask.getElement(uXRegSpace-1,uYRegSpace);
|
||||
uint8_t iPreviousCubeIndexX = pCurrentBitmask[uXRegSpace-1][uYRegSpace];
|
||||
iPreviousCubeIndexX &= 170; //170 = 128+32+8+2
|
||||
iPreviousCubeIndexX >>= 1;
|
||||
|
||||
@ -432,7 +445,7 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
//Save the bitmask
|
||||
pCurrentBitmask.setElement(uXRegSpace,uYVolSpace- m_regInputCropped.getLowerCorner().getY(), iCubeIndex);
|
||||
pCurrentBitmask[uXRegSpace][uYVolSpace- m_regInputCropped.getLowerCorner().getY()] = iCubeIndex;
|
||||
|
||||
if(edgeTable[iCubeIndex] != 0)
|
||||
{
|
||||
@ -468,7 +481,7 @@ namespace PolyVox
|
||||
bool isPosXEdge = (uXVolSpace == m_regInputCropped.getUpperCorner().getX());
|
||||
|
||||
//Determine the index into the edge table which tells us which vertices are inside of the surface
|
||||
uint8_t iCubeIndex = pCurrentBitmask.getElement(uXRegSpace,uYRegSpace);
|
||||
uint8_t iCubeIndex = pCurrentBitmask[uXRegSpace][uYRegSpace];
|
||||
|
||||
/* Cube is entirely in/out of the surface */
|
||||
if (edgeTable[iCubeIndex] == 0)
|
||||
@ -499,7 +512,7 @@ namespace PolyVox
|
||||
surfaceVertex.setOnGeometryEdgeNegZ(isNegZEdge);
|
||||
surfaceVertex.setOnGeometryEdgePosZ(isPosZEdge);
|
||||
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
m_pCurrentVertexIndicesX.setElement(uXVolSpace - m_regInputCropped.getLowerCorner().getX(),uYVolSpace - m_regInputCropped.getLowerCorner().getY(), uLastVertexIndex);
|
||||
m_pCurrentVertexIndicesX[uXVolSpace - m_regInputCropped.getLowerCorner().getX()][uYVolSpace - m_regInputCropped.getLowerCorner().getY()] = uLastVertexIndex;
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 8)
|
||||
{
|
||||
@ -517,7 +530,7 @@ namespace PolyVox
|
||||
surfaceVertex.setOnGeometryEdgeNegZ(isNegZEdge);
|
||||
surfaceVertex.setOnGeometryEdgePosZ(isPosZEdge);
|
||||
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
m_pCurrentVertexIndicesY.setElement(uXVolSpace - m_regInputCropped.getLowerCorner().getX(),uYVolSpace - m_regInputCropped.getLowerCorner().getY(), uLastVertexIndex);
|
||||
m_pCurrentVertexIndicesY[uXVolSpace - m_regInputCropped.getLowerCorner().getX()][uYVolSpace - m_regInputCropped.getLowerCorner().getY()] = uLastVertexIndex;
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 256)
|
||||
{
|
||||
@ -535,7 +548,7 @@ namespace PolyVox
|
||||
surfaceVertex.setOnGeometryEdgeNegZ(isNegZEdge);
|
||||
surfaceVertex.setOnGeometryEdgePosZ(isPosZEdge);
|
||||
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
m_pCurrentVertexIndicesZ.setElement(uXVolSpace - m_regInputCropped.getLowerCorner().getX(),uYVolSpace - m_regInputCropped.getLowerCorner().getY(), uLastVertexIndex);
|
||||
m_pCurrentVertexIndicesZ[uXVolSpace - m_regInputCropped.getLowerCorner().getX()][uYVolSpace - m_regInputCropped.getLowerCorner().getY()] = uLastVertexIndex;
|
||||
}
|
||||
}//For each cell
|
||||
}
|
||||
@ -568,7 +581,7 @@ namespace PolyVox
|
||||
const uint16_t uZRegSpace = m_sampVolume.getPosZ() - m_regInputCropped.getLowerCorner().getZ();
|
||||
|
||||
//Determine the index into the edge table which tells us which vertices are inside of the surface
|
||||
uint8_t iCubeIndex = pPreviousBitmask.getElement(uXRegSpace,uYRegSpace);
|
||||
uint8_t iCubeIndex = pPreviousBitmask[uXRegSpace][uYRegSpace];
|
||||
|
||||
/* Cube is entirely in/out of the surface */
|
||||
if (edgeTable[iCubeIndex] == 0)
|
||||
@ -579,62 +592,62 @@ namespace PolyVox
|
||||
/* Find the vertices where the surface intersects the cube */
|
||||
if (edgeTable[iCubeIndex] & 1)
|
||||
{
|
||||
indlist[0] = m_pPreviousVertexIndicesX.getElement(uXRegSpace,uYRegSpace);
|
||||
indlist[0] = m_pPreviousVertexIndicesX[uXRegSpace][uYRegSpace];
|
||||
//assert(indlist[0] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 2)
|
||||
{
|
||||
indlist[1] = m_pPreviousVertexIndicesY.getElement(uXRegSpace+1,uYRegSpace);
|
||||
indlist[1] = m_pPreviousVertexIndicesY[uXRegSpace+1][uYRegSpace];
|
||||
//assert(indlist[1] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 4)
|
||||
{
|
||||
indlist[2] = m_pPreviousVertexIndicesX.getElement(uXRegSpace,uYRegSpace+1);
|
||||
indlist[2] = m_pPreviousVertexIndicesX[uXRegSpace][uYRegSpace+1];
|
||||
//assert(indlist[2] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 8)
|
||||
{
|
||||
indlist[3] = m_pPreviousVertexIndicesY.getElement(uXRegSpace,uYRegSpace);
|
||||
indlist[3] = m_pPreviousVertexIndicesY[uXRegSpace][uYRegSpace];
|
||||
//assert(indlist[3] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 16)
|
||||
{
|
||||
indlist[4] = m_pCurrentVertexIndicesX.getElement(uXRegSpace,uYRegSpace);
|
||||
indlist[4] = m_pCurrentVertexIndicesX[uXRegSpace][uYRegSpace];
|
||||
//assert(indlist[4] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 32)
|
||||
{
|
||||
indlist[5] = m_pCurrentVertexIndicesY.getElement(uXRegSpace+1,uYRegSpace);
|
||||
indlist[5] = m_pCurrentVertexIndicesY[uXRegSpace+1][uYRegSpace];
|
||||
//assert(indlist[5] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 64)
|
||||
{
|
||||
indlist[6] = m_pCurrentVertexIndicesX.getElement(uXRegSpace,uYRegSpace+1);
|
||||
indlist[6] = m_pCurrentVertexIndicesX[uXRegSpace][uYRegSpace+1];
|
||||
//assert(indlist[6] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 128)
|
||||
{
|
||||
indlist[7] = m_pCurrentVertexIndicesY.getElement(uXRegSpace,uYRegSpace);
|
||||
indlist[7] = m_pCurrentVertexIndicesY[uXRegSpace][uYRegSpace];
|
||||
//assert(indlist[7] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 256)
|
||||
{
|
||||
indlist[8] = m_pPreviousVertexIndicesZ.getElement(uXRegSpace,uYRegSpace);
|
||||
indlist[8] = m_pPreviousVertexIndicesZ[uXRegSpace][uYRegSpace];
|
||||
//assert(indlist[8] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 512)
|
||||
{
|
||||
indlist[9] = m_pPreviousVertexIndicesZ.getElement(uXRegSpace+1,uYRegSpace);
|
||||
indlist[9] = m_pPreviousVertexIndicesZ[uXRegSpace+1][uYRegSpace];
|
||||
//assert(indlist[9] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 1024)
|
||||
{
|
||||
indlist[10] = m_pPreviousVertexIndicesZ.getElement(uXRegSpace+1,uYRegSpace+1);
|
||||
indlist[10] = m_pPreviousVertexIndicesZ[uXRegSpace+1][uYRegSpace+1];
|
||||
//assert(indlist[10] != -1);
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 2048)
|
||||
{
|
||||
indlist[11] = m_pPreviousVertexIndicesZ.getElement(uXRegSpace,uYRegSpace+1);
|
||||
indlist[11] = m_pPreviousVertexIndicesZ[uXRegSpace][uYRegSpace+1];
|
||||
//assert(indlist[11] != -1);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user