More work on multidimensional Array class.
This commit is contained in:
parent
834b747171
commit
3e1c07550b
@ -39,12 +39,58 @@ namespace PolyVox
|
||||
class Array
|
||||
{
|
||||
public:
|
||||
Array<noOfDims, ElementType>()
|
||||
:m_pElements(0)
|
||||
,m_pDimensions(0)
|
||||
,m_pOffsets(0)
|
||||
,m_uNoOfElements(0)
|
||||
{
|
||||
}
|
||||
|
||||
Array<noOfDims, ElementType>(const uint32_t (&pDimensions)[noOfDims])
|
||||
:m_pElements(0)
|
||||
,m_pDimensions(0)
|
||||
,m_pOffsets(0)
|
||||
,m_uNoOfElements(0)
|
||||
{
|
||||
resize(pDimensions);
|
||||
}
|
||||
|
||||
~Array<noOfDims, ElementType>()
|
||||
{
|
||||
deallocate();
|
||||
}
|
||||
|
||||
SubArray<noOfDims-1, ElementType> operator[](uint32_t uIndex)
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return
|
||||
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||
m_pDimensions+1, m_pOffsets+1);
|
||||
}
|
||||
|
||||
const SubArray<noOfDims-1, ElementType> operator[](uint32_t uIndex) const
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return
|
||||
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||
m_pDimensions+1, m_pOffsets+1);
|
||||
}
|
||||
|
||||
uint32_t getNoOfElements(void) const
|
||||
{
|
||||
return m_uNoOfElements;
|
||||
}
|
||||
|
||||
ElementType* getRawData(void) const
|
||||
{
|
||||
return m_pElements;
|
||||
}
|
||||
|
||||
void resize(const uint32_t (&pDimensions)[noOfDims])
|
||||
{
|
||||
deallocate();
|
||||
|
||||
m_pDimensions = new uint32_t[noOfDims];
|
||||
m_pOffsets = new uint32_t[noOfDims];
|
||||
|
||||
@ -64,42 +110,59 @@ namespace PolyVox
|
||||
}
|
||||
// Allocate new elements, let exception propagate
|
||||
m_pElements = new ElementType[m_uNoOfElements];
|
||||
}
|
||||
|
||||
~Array<noOfDims, ElementType>()
|
||||
{
|
||||
delete[] m_pDimensions;
|
||||
delete[] m_pOffsets;
|
||||
delete[] m_pElements;
|
||||
}
|
||||
|
||||
SubArray<noOfDims-1, ElementType> operator [](uint32_t uIndex)
|
||||
void swap(Array<noOfDims, ElementType>& rhs)
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return
|
||||
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||
m_pDimensions+1, m_pOffsets+1);
|
||||
}
|
||||
//Implement this function without temporary 'Array'
|
||||
//objects, as the destructors will free the memory...
|
||||
uint32_t* m_pTempDimensions = m_pDimensions;
|
||||
uint32_t* m_pTempOffsets = m_pOffsets;
|
||||
uint32_t m_uTempNoOfElements = m_uNoOfElements;
|
||||
ElementType* m_pTempElements = m_pElements;
|
||||
|
||||
const SubArray<noOfDims-1, ElementType> operator [](uint32_t uIndex) const
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return
|
||||
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||
m_pDimensions+1, m_pOffsets+1);
|
||||
}
|
||||
m_pDimensions = rhs.m_pDimensions;
|
||||
m_pOffsets = rhs.m_pOffsets;
|
||||
m_uNoOfElements = rhs.m_uNoOfElements;
|
||||
m_pElements = rhs.m_pElements;
|
||||
|
||||
ElementType* getRawData(void)
|
||||
{
|
||||
return m_pElements;
|
||||
}
|
||||
|
||||
uint32_t getNoOfElements(void)
|
||||
{
|
||||
return m_uNoOfElements;
|
||||
rhs.m_pDimensions = m_pTempDimensions;
|
||||
rhs.m_pOffsets = m_pTempOffsets;
|
||||
rhs.m_uNoOfElements = m_uTempNoOfElements;
|
||||
rhs.m_pElements = m_pTempElements;
|
||||
}
|
||||
|
||||
private:
|
||||
Array<noOfDims, ElementType>(const Array<noOfDims, ElementType>& rhs)
|
||||
:m_pElements(0)
|
||||
,m_pDimensions(0)
|
||||
,m_pOffsets(0)
|
||||
,m_uNoOfElements(0)
|
||||
{
|
||||
//Not implemented
|
||||
assert(false);
|
||||
}
|
||||
|
||||
Array<noOfDims, ElementType>& Array<noOfDims, ElementType>::operator=(const Array<noOfDims, ElementType>& rhs)
|
||||
{
|
||||
//Not implemented
|
||||
assert(false);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void deallocate(void)
|
||||
{
|
||||
delete[] m_pDimensions;
|
||||
m_pDimensions = 0;
|
||||
delete[] m_pOffsets;
|
||||
m_pOffsets = 0;
|
||||
delete[] m_pElements;
|
||||
m_pElements = 0;
|
||||
|
||||
m_uNoOfElements = 0;
|
||||
}
|
||||
|
||||
uint32_t * m_pDimensions;
|
||||
uint32_t * m_pOffsets;
|
||||
uint32_t m_uNoOfElements;
|
||||
@ -110,40 +173,96 @@ namespace PolyVox
|
||||
class Array<1, ElementType>
|
||||
{
|
||||
public:
|
||||
Array<1, ElementType>()
|
||||
: m_pElements(0)
|
||||
,m_pDimensions(0)
|
||||
{
|
||||
}
|
||||
|
||||
Array<1, ElementType>(const uint32_t (&pDimensions)[1])
|
||||
: m_pElements(0)
|
||||
,m_pDimensions(0)
|
||||
{
|
||||
resize(pDimensions);
|
||||
}
|
||||
|
||||
~Array<1, ElementType>()
|
||||
{
|
||||
deallocate();
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
uint32_t getNoOfElements(void) const
|
||||
{
|
||||
return m_pDimensions[0];
|
||||
}
|
||||
|
||||
ElementType* getRawData(void) const
|
||||
{
|
||||
return m_pElements;
|
||||
}
|
||||
|
||||
void resize(const uint32_t (&pDimensions)[1])
|
||||
{
|
||||
deallocate();
|
||||
|
||||
m_pDimensions = new uint32_t[1];
|
||||
m_pDimensions[0] = pDimensions[0];
|
||||
|
||||
// Allocate new elements, let exception propagate
|
||||
m_pElements = new ElementType[m_pDimensions[0]];
|
||||
}
|
||||
|
||||
ElementType & operator [] (uint32_t uIndex)
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return m_pElements[uIndex];
|
||||
}
|
||||
|
||||
const ElementType & operator [] (uint32_t uIndex) const
|
||||
void swap(Array<1, ElementType>& rhs)
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return m_pElements[uIndex];
|
||||
}
|
||||
//Implement this function without temporary 'Array'
|
||||
//objects, as the destructors will free the memory...
|
||||
uint32_t* m_pTempDimensions = m_pDimensions;
|
||||
ElementType* m_pTempElements = m_pElements;
|
||||
|
||||
ElementType* getRawData(void)
|
||||
{
|
||||
return m_pElements;
|
||||
}
|
||||
m_pDimensions = rhs.m_pDimensions;
|
||||
m_pElements = rhs.m_pElements;
|
||||
|
||||
uint32_t getNoOfElements(void)
|
||||
{
|
||||
return m_pDimensions[0];
|
||||
rhs.m_pDimensions = m_pTempDimensions;
|
||||
rhs.m_pElements = m_pTempElements;
|
||||
}
|
||||
|
||||
private:
|
||||
Array<1, ElementType>(const Array<1, ElementType>& rhs)
|
||||
: m_pElements(0)
|
||||
,m_pDimensions(0)
|
||||
{
|
||||
//Not implemented
|
||||
assert(false);
|
||||
}
|
||||
|
||||
Array<1, ElementType>& Array<1, ElementType>::operator=(const Array<1, ElementType>& rhs)
|
||||
{
|
||||
//Not implemented
|
||||
assert(false);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void deallocate(void)
|
||||
{
|
||||
delete[] m_pDimensions;
|
||||
m_pDimensions = 0;
|
||||
delete[] m_pElements;
|
||||
m_pElements = 0;
|
||||
}
|
||||
|
||||
uint32_t * m_pDimensions;
|
||||
ElementType * m_pElements;
|
||||
};
|
||||
|
@ -27,50 +27,50 @@ namespace PolyVox
|
||||
{
|
||||
template <uint32_t noOfDims, typename ElementType>
|
||||
SubArray<noOfDims-1, ElementType> SubArray<noOfDims, ElementType>::operator[](uint32_t uIndex)
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return
|
||||
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||
m_pDimensions+1, m_pOffsets+1);
|
||||
}
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return
|
||||
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||
m_pDimensions+1, m_pOffsets+1);
|
||||
}
|
||||
|
||||
template <uint32_t noOfDims, typename ElementType>
|
||||
const SubArray<noOfDims-1, ElementType> SubArray<noOfDims, ElementType>::operator[](uint32_t uIndex) const
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return
|
||||
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||
m_pDimensions+1, m_pOffsets+1);
|
||||
}
|
||||
template <uint32_t noOfDims, typename ElementType>
|
||||
const SubArray<noOfDims-1, ElementType> SubArray<noOfDims, ElementType>::operator[](uint32_t uIndex) const
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return
|
||||
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||
m_pDimensions+1, m_pOffsets+1);
|
||||
}
|
||||
|
||||
template <uint32_t noOfDims, typename ElementType>
|
||||
SubArray<noOfDims, ElementType>::SubArray<noOfDims, ElementType>(ElementType * pElements, uint32_t * pDimensions, uint32_t * pOffsets)
|
||||
:m_pElements(pElements)
|
||||
,m_pDimensions(pDimensions)
|
||||
,m_pOffsets(pOffsets)
|
||||
,m_uNoOfElements(0)
|
||||
{
|
||||
}
|
||||
template <uint32_t noOfDims, typename ElementType>
|
||||
SubArray<noOfDims, ElementType>::SubArray<noOfDims, ElementType>(ElementType * pElements, uint32_t * pDimensions, uint32_t * pOffsets)
|
||||
:m_pElements(pElements)
|
||||
,m_pDimensions(pDimensions)
|
||||
,m_pOffsets(pOffsets)
|
||||
,m_uNoOfElements(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template <typename ElementType>
|
||||
ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex)
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return m_pElements[uIndex];
|
||||
}
|
||||
template <typename ElementType>
|
||||
ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex)
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return m_pElements[uIndex];
|
||||
}
|
||||
|
||||
template <typename ElementType>
|
||||
const ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex) const
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return m_pElements[uIndex];
|
||||
}
|
||||
|
||||
template <typename ElementType>
|
||||
SubArray<1, ElementType>::SubArray<1, ElementType>(ElementType * pElements, uint32_t * pDimensions, uint32_t * /*pOffsets*/)
|
||||
:m_pDimensions(pDimensions)
|
||||
,m_pElements(pElements)
|
||||
{
|
||||
}
|
||||
template <typename ElementType>
|
||||
const ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex) const
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return m_pElements[uIndex];
|
||||
}
|
||||
|
||||
template <typename ElementType>
|
||||
SubArray<1, ElementType>::SubArray<1, ElementType>(ElementType * pElements, uint32_t * pDimensions, uint32_t * /*pOffsets*/)
|
||||
:m_pDimensions(pDimensions)
|
||||
,m_pElements(pElements)
|
||||
{
|
||||
}
|
||||
}//namespace PolyVox
|
@ -57,53 +57,18 @@ namespace PolyVox
|
||||
m_uScratchPadWidth = m_uRegionWidth+1;
|
||||
m_uScratchPadHeight = m_uRegionHeight+1;
|
||||
|
||||
uint32_t arraySizes[2]= {m_uScratchPadWidth, m_uScratchPadHeight}; // Array dimensions
|
||||
|
||||
//For edge indices
|
||||
/*m_pPreviousVertexIndicesX = new int32_t[m_uScratchPadWidth * m_uScratchPadHeight];
|
||||
m_pPreviousVertexIndicesY = new int32_t[m_uScratchPadWidth * m_uScratchPadHeight];
|
||||
m_pPreviousVertexIndicesZ = new int32_t[m_uScratchPadWidth * m_uScratchPadHeight];
|
||||
m_pCurrentVertexIndicesX = 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];*/
|
||||
Array2DInt32 m_pPreviousVertexIndicesX(arraySizes);
|
||||
Array2DInt32 m_pPreviousVertexIndicesY(arraySizes);
|
||||
Array2DInt32 m_pPreviousVertexIndicesZ(arraySizes);
|
||||
Array2DInt32 m_pCurrentVertexIndicesX(arraySizes);
|
||||
Array2DInt32 m_pCurrentVertexIndicesY(arraySizes);
|
||||
Array2DInt32 m_pCurrentVertexIndicesZ(arraySizes);
|
||||
|
||||
//uint32_t Size1 [1]= {m_uScratchPadWidth}; // Array dimensions
|
||||
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_pPreviousVertexIndicesX(ArraySizes(m_uScratchPadWidth)(m_uScratchPadHeight));
|
||||
Array2DInt32 m_pPreviousVertexIndicesY(Size2);
|
||||
Array2DInt32 m_pPreviousVertexIndicesZ(Size2);
|
||||
Array2DInt32 m_pCurrentVertexIndicesX(Size2);
|
||||
Array2DInt32 m_pCurrentVertexIndicesY(Size2);
|
||||
Array2DInt32 m_pCurrentVertexIndicesZ(Size2);
|
||||
|
||||
//Array1DFloat test1d(ArraySizes(10));
|
||||
//Array2DFloat test2d(ArraySizes(10)(20));
|
||||
|
||||
|
||||
|
||||
/*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(Size2);
|
||||
Array2DUint8 pCurrentBitmask(Size2);
|
||||
|
||||
/*pPreviousBitmask.resize(Size2);
|
||||
pCurrentBitmask.resize(Size2);*/
|
||||
Array2DUint8 pPreviousBitmask(arraySizes);
|
||||
Array2DUint8 pCurrentBitmask(arraySizes);
|
||||
|
||||
//Create a region corresponding to the first slice
|
||||
m_regSlicePrevious = m_regInputCropped;
|
||||
@ -128,10 +93,10 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
std::swap(uNoOfNonEmptyCellsForSlice0, uNoOfNonEmptyCellsForSlice1);
|
||||
std::swap(pPreviousBitmask, pCurrentBitmask);
|
||||
std::swap(m_pPreviousVertexIndicesX, m_pCurrentVertexIndicesX);
|
||||
std::swap(m_pPreviousVertexIndicesY, m_pCurrentVertexIndicesY);
|
||||
std::swap(m_pPreviousVertexIndicesZ, m_pCurrentVertexIndicesZ);
|
||||
pPreviousBitmask.swap(pCurrentBitmask);
|
||||
m_pPreviousVertexIndicesX.swap(m_pCurrentVertexIndicesX);
|
||||
m_pPreviousVertexIndicesY.swap(m_pCurrentVertexIndicesY);
|
||||
m_pPreviousVertexIndicesZ.swap(m_pCurrentVertexIndicesZ);
|
||||
|
||||
m_regSlicePrevious = m_regSliceCurrent;
|
||||
m_regSliceCurrent.shift(Vector3DInt16(0,0,1));
|
||||
@ -156,10 +121,10 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
std::swap(uNoOfNonEmptyCellsForSlice0, uNoOfNonEmptyCellsForSlice1);
|
||||
std::swap(pPreviousBitmask, pCurrentBitmask);
|
||||
std::swap(m_pPreviousVertexIndicesX, m_pCurrentVertexIndicesX);
|
||||
std::swap(m_pPreviousVertexIndicesY, m_pCurrentVertexIndicesY);
|
||||
std::swap(m_pPreviousVertexIndicesZ, m_pCurrentVertexIndicesZ);
|
||||
pPreviousBitmask.swap(pCurrentBitmask);
|
||||
m_pPreviousVertexIndicesX.swap(m_pCurrentVertexIndicesX);
|
||||
m_pPreviousVertexIndicesY.swap(m_pCurrentVertexIndicesY);
|
||||
m_pPreviousVertexIndicesZ.swap(m_pCurrentVertexIndicesZ);
|
||||
|
||||
m_regSlicePrevious = m_regSliceCurrent;
|
||||
m_regSliceCurrent.shift(Vector3DInt16(0,0,1));
|
||||
@ -175,13 +140,6 @@ namespace PolyVox
|
||||
generateIndicesForSlice(pPreviousBitmask, m_pPreviousVertexIndicesX, m_pPreviousVertexIndicesY, m_pPreviousVertexIndicesZ, m_pCurrentVertexIndicesX, m_pCurrentVertexIndicesY, m_pCurrentVertexIndicesZ);
|
||||
}
|
||||
|
||||
/*delete[] m_pPreviousVertexIndicesX;
|
||||
delete[] m_pCurrentVertexIndicesX;
|
||||
delete[] m_pPreviousVertexIndicesY;
|
||||
delete[] m_pCurrentVertexIndicesY;
|
||||
delete[] m_pPreviousVertexIndicesZ;
|
||||
delete[] m_pCurrentVertexIndicesZ; */
|
||||
|
||||
m_meshCurrent->m_Region = m_regInputUncropped;
|
||||
|
||||
m_meshCurrent->m_vecLodRecords.clear();
|
||||
|
Loading…
x
Reference in New Issue
Block a user