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