Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 namespace PolyVox
00025 {
00026 template <typename VoxelType>
00027 SimpleVolume<VoxelType>::Block::Block(uint16_t uSideLength)
00028 :m_tUncompressedData(0)
00029 ,m_uSideLength(0)
00030 ,m_uSideLengthPower(0)
00031 {
00032 if(uSideLength != 0)
00033 {
00034 initialise(uSideLength);
00035 }
00036 }
00037
00038 template <typename VoxelType>
00039 SimpleVolume<VoxelType>::Block::~Block()
00040 {
00041 delete[] m_tUncompressedData;
00042 }
00043
00044 template <typename VoxelType>
00045 uint16_t SimpleVolume<VoxelType>::Block::getSideLength(void) const
00046 {
00047 return m_uSideLength;
00048 }
00049
00050 template <typename VoxelType>
00051 VoxelType SimpleVolume<VoxelType>::Block::getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const
00052 {
00053 assert(uXPos < m_uSideLength);
00054 assert(uYPos < m_uSideLength);
00055 assert(uZPos < m_uSideLength);
00056
00057 assert(m_tUncompressedData);
00058
00059 return m_tUncompressedData
00060 [
00061 uXPos +
00062 uYPos * m_uSideLength +
00063 uZPos * m_uSideLength * m_uSideLength
00064 ];
00065 }
00066
00067 template <typename VoxelType>
00068 VoxelType SimpleVolume<VoxelType>::Block::getVoxelAt(const Vector3DUint16& v3dPos) const
00069 {
00070 return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
00071 }
00072
00073 template <typename VoxelType>
00074 void SimpleVolume<VoxelType>::Block::setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue)
00075 {
00076 assert(uXPos < m_uSideLength);
00077 assert(uYPos < m_uSideLength);
00078 assert(uZPos < m_uSideLength);
00079
00080 assert(m_tUncompressedData);
00081
00082 m_tUncompressedData
00083 [
00084 uXPos +
00085 uYPos * m_uSideLength +
00086 uZPos * m_uSideLength * m_uSideLength
00087 ] = tValue;
00088 }
00089
00090 template <typename VoxelType>
00091 void SimpleVolume<VoxelType>::Block::setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue)
00092 {
00093 setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
00094 }
00095
00096 template <typename VoxelType>
00097 void SimpleVolume<VoxelType>::Block::fill(VoxelType tValue)
00098 {
00099 const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
00100 std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, tValue);
00101 }
00102
00103 template <typename VoxelType>
00104 void SimpleVolume<VoxelType>::Block::initialise(uint16_t uSideLength)
00105 {
00106
00107 assert(isPowerOf2(uSideLength));
00108
00109
00110 if(!isPowerOf2(uSideLength))
00111 {
00112 throw std::invalid_argument("Block side length must be a power of two.");
00113 }
00114
00115
00116 m_uSideLength = uSideLength;
00117 m_uSideLengthPower = logBase2(uSideLength);
00118
00119 m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
00120
00121 SimpleVolume<VoxelType>::Block::fill(VoxelType());
00122 }
00123
00124 template <typename VoxelType>
00125 uint32_t SimpleVolume<VoxelType>::Block::calculateSizeInBytes(void)
00126 {
00127 uint32_t uSizeInBytes = sizeof(Block);
00128 uSizeInBytes += sizeof(VoxelType) * m_uSideLength * m_uSideLength * m_uSideLength;
00129 return uSizeInBytes;
00130 }
00131 }