From 4c24d6140845c3e88c279f727944c67133b4f5bc Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 5 Apr 2015 12:03:12 +0200 Subject: [PATCH] Added another function for backwards compatibility. --- include/PolyVox/PagedVolume.h | 1 + include/PolyVox/PagedVolumeChunk.inl | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/PolyVox/PagedVolume.h b/include/PolyVox/PagedVolume.h index 35443154..a3eb271d 100644 --- a/include/PolyVox/PagedVolume.h +++ b/include/PolyVox/PagedVolume.h @@ -134,6 +134,7 @@ namespace PolyVox void setVoxel(const Vector3DUint16& v3dPos, VoxelType tValue); void changeLinearOrderingToMorton(void); + void changeMortonOrderingToLinear(void); private: /// Private copy constructor to prevent accisdental copying diff --git a/include/PolyVox/PagedVolumeChunk.inl b/include/PolyVox/PagedVolumeChunk.inl index d06a21cc..4684c65b 100644 --- a/include/PolyVox/PagedVolumeChunk.inl +++ b/include/PolyVox/PagedVolumeChunk.inl @@ -178,4 +178,28 @@ namespace PolyVox 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 + void PagedVolume::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; + } }