Added another function for backwards compatibility.

This commit is contained in:
David Williams 2015-04-05 12:03:12 +02:00
parent c887d1444f
commit 4c24d61408
2 changed files with 25 additions and 0 deletions

View File

@ -134,6 +134,7 @@ namespace PolyVox
void setVoxel(const Vector3DUint16& v3dPos, VoxelType tValue); void setVoxel(const Vector3DUint16& v3dPos, VoxelType tValue);
void changeLinearOrderingToMorton(void); void changeLinearOrderingToMorton(void);
void changeMortonOrderingToLinear(void);
private: private:
/// Private copy constructor to prevent accisdental copying /// Private copy constructor to prevent accisdental copying

View File

@ -178,4 +178,28 @@ namespace PolyVox
delete[] pTempBuffer; delete[] pTempBuffer;
} }
// Like the above function, this is provided fot easing backwards compatibility. In Cubiquity we have some
// old databases which use linear ordering, and we need to continue to save such data in linear order.
template <typename VoxelType>
void PagedVolume<VoxelType>::Chunk::changeMortonOrderingToLinear(void)
{
VoxelType* pTempBuffer = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
for (uint16_t z = 0; z < m_uSideLength; z++)
{
for (uint16_t y = 0; y < m_uSideLength; y++)
{
for (uint16_t x = 0; x < m_uSideLength; x++)
{
uint32_t uLinearIndex = x + y * m_uSideLength + z * m_uSideLength * m_uSideLength;
uint32_t uMortonIndex = morton256_x[x] | morton256_y[y] | morton256_z[z];
pTempBuffer[uLinearIndex] = m_tData[uMortonIndex];
}
}
}
std::memcpy(m_tData, pTempBuffer, getDataSizeInBytes());
delete[] pTempBuffer;
}
} }