31 template <
typename VoxelType>
36 initialise(regValid,uBlockSideLength);
46 template <
typename VoxelType>
55 template <
typename VoxelType>
59 delete[] m_pUncompressedBorderData;
69 template <
typename VoxelType>
80 template <
typename VoxelType>
83 return *m_pUncompressedBorderData;
92 template <
typename VoxelType>
95 if(this->m_regValidRegion.containsPoint(
Vector3DInt32(uXPos, uYPos, uZPos)))
97 const int32_t blockX = uXPos >> m_uBlockSideLengthPower;
98 const int32_t blockY = uYPos >> m_uBlockSideLengthPower;
99 const int32_t blockZ = uZPos >> m_uBlockSideLengthPower;
101 const uint16_t xOffset =
static_cast<uint16_t
>(uXPos - (blockX << m_uBlockSideLengthPower));
102 const uint16_t yOffset =
static_cast<uint16_t
>(uYPos - (blockY << m_uBlockSideLengthPower));
103 const uint16_t zOffset =
static_cast<uint16_t
>(uZPos - (blockZ << m_uBlockSideLengthPower));
107 return pUncompressedBlock->
getVoxelAt(xOffset,yOffset,zOffset);
111 return getBorderValue();
119 template <
typename VoxelType>
122 return getVoxelAt(v3dPos.
getX(), v3dPos.
getY(), v3dPos.
getZ());
128 template <
typename VoxelType>
133 std::fill(m_pUncompressedBorderData, m_pUncompressedBorderData + m_uNoOfVoxelsPerBlock, tBorder);
143 template <
typename VoxelType>
146 assert(this->m_regValidRegion.containsPoint(
Vector3DInt32(uXPos, uYPos, uZPos)));
148 const int32_t blockX = uXPos >> m_uBlockSideLengthPower;
149 const int32_t blockY = uYPos >> m_uBlockSideLengthPower;
150 const int32_t blockZ = uZPos >> m_uBlockSideLengthPower;
152 const uint16_t xOffset = uXPos - (blockX << m_uBlockSideLengthPower);
153 const uint16_t yOffset = uYPos - (blockY << m_uBlockSideLengthPower);
154 const uint16_t zOffset = uZPos - (blockZ << m_uBlockSideLengthPower);
158 pUncompressedBlock->setVoxelAt(xOffset,yOffset,zOffset, tValue);
169 template <
typename VoxelType>
178 template <
typename VoxelType>
182 assert(uBlockSideLength >= 8);
183 assert(uBlockSideLength <= 256);
187 if(uBlockSideLength < 8)
189 throw std::invalid_argument(
"Block side length should be at least 8");
191 if(uBlockSideLength > 256)
193 throw std::invalid_argument(
"Block side length should not be more than 256");
197 throw std::invalid_argument(
"Block side length must be a power of two.");
202 m_pUncompressedBorderData = 0;
204 this->m_regValidRegion = regValidRegion;
210 m_uBlockSideLength = uBlockSideLength;
211 m_uBlockSideLengthPower =
logBase2(m_uBlockSideLength);
212 m_uNoOfVoxelsPerBlock = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength;
217 m_regValidRegionInBlocks.setLowerCorner(
Vector3DInt32(this->m_regValidRegion.getLowerCorner().getX() >> m_uBlockSideLengthPower, this->m_regValidRegion.getLowerCorner().getY() >> m_uBlockSideLengthPower, this->m_regValidRegion.getLowerCorner().getZ() >> m_uBlockSideLengthPower));
221 m_regValidRegionInBlocks.setUpperCorner(
Vector3DInt32(this->m_regValidRegion.getUpperCorner().getX() >> m_uBlockSideLengthPower, this->m_regValidRegion.getUpperCorner().getY() >> m_uBlockSideLengthPower, this->m_regValidRegion.getUpperCorner().getZ() >> m_uBlockSideLengthPower));
224 m_uWidthInBlocks = m_regValidRegionInBlocks.getUpperCorner().getX() - m_regValidRegionInBlocks.getLowerCorner().getX() + 1;
225 m_uHeightInBlocks = m_regValidRegionInBlocks.getUpperCorner().getY() - m_regValidRegionInBlocks.getLowerCorner().getY() + 1;
226 m_uDepthInBlocks = m_regValidRegionInBlocks.getUpperCorner().getZ() - m_regValidRegionInBlocks.getLowerCorner().getZ() + 1;
227 m_uNoOfBlocksInVolume = m_uWidthInBlocks * m_uHeightInBlocks * m_uDepthInBlocks;
230 m_pBlocks =
new Block[m_uNoOfBlocksInVolume];
231 for(uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i)
233 m_pBlocks[i].initialise(m_uBlockSideLength);
237 m_pUncompressedBorderData =
new VoxelType[m_uNoOfVoxelsPerBlock];
238 std::fill(m_pUncompressedBorderData, m_pUncompressedBorderData + m_uNoOfVoxelsPerBlock, VoxelType());
241 this->m_uLongestSideLength = (std::max)((std::max)(this->getWidth(),this->getHeight()),this->getDepth());
242 this->m_uShortestSideLength = (std::min)((std::min)(this->getWidth(),this->getHeight()),this->getDepth());
243 this->m_fDiagonalLength = sqrtf(static_cast<float>(this->getWidth() * this->getWidth() + this->getHeight() * this->getHeight() + this->getDepth() * this->getDepth()));
246 template <
typename VoxelType>
247 typename SimpleVolume<VoxelType>::Block* SimpleVolume<VoxelType>::getUncompressedBlock(
int32_t uBlockX,
int32_t uBlockY,
int32_t uBlockZ)
const
251 uBlockX -= m_regValidRegionInBlocks.getLowerCorner().getX();
252 uBlockY -= m_regValidRegionInBlocks.getLowerCorner().getY();
253 uBlockZ -= m_regValidRegionInBlocks.getLowerCorner().getZ();
256 uint32_t uBlockIndex =
258 uBlockY * m_uWidthInBlocks +
259 uBlockZ * m_uWidthInBlocks * m_uHeightInBlocks;
262 return &(m_pBlocks[uBlockIndex]);
270 template <
typename VoxelType>
275 uint32_t uSizeOfBlockInBytes = m_uNoOfVoxelsPerBlock *
sizeof(VoxelType);
278 uSizeInBytes += uSizeOfBlockInBytes * (m_uNoOfBlocksInVolume + 1);