PolyVox  0.3.0-dev
Open source voxel management library
SimpleVolumeBlock.inl
Go to the documentation of this file.
1 /*******************************************************************************
2 Copyright (c) 2005-2009 David Williams
3 
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7 
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11 
12  1. The origin of this software must not be misrepresented; you must not
13  claim that you wrote the original software. If you use this software
14  in a product, an acknowledgment in the product documentation would be
15  appreciated but is not required.
16 
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19 
20  3. This notice may not be removed or altered from any source
21  distribution.
22 *******************************************************************************/
23 
25 
26 namespace PolyVox
27 {
28  template <typename VoxelType>
30  :m_tUncompressedData(0)
31  ,m_uSideLength(0)
32  ,m_uSideLengthPower(0)
33  {
34  if(uSideLength != 0)
35  {
36  initialise(uSideLength);
37  }
38  }
39 
40  template <typename VoxelType>
42  {
43  delete[] m_tUncompressedData;
44  }
45 
46  template <typename VoxelType>
48  {
49  return m_uSideLength;
50  }
51 
52  template <typename VoxelType>
54  {
55  POLYVOX_ASSERT(uXPos < m_uSideLength, "Position is outside of the block.");
56  POLYVOX_ASSERT(uYPos < m_uSideLength, "Position is outside of the block.");
57  POLYVOX_ASSERT(uZPos < m_uSideLength, "Position is outside of the block.");
58 
59  POLYVOX_ASSERT(m_tUncompressedData, "No uncompressed data available");
60 
61  return m_tUncompressedData
62  [
63  uXPos +
64  uYPos * m_uSideLength +
65  uZPos * m_uSideLength * m_uSideLength
66  ];
67  }
68 
69  template <typename VoxelType>
71  {
72  return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
73  }
74 
75  template <typename VoxelType>
77  {
78  POLYVOX_ASSERT(uXPos < m_uSideLength, "Position is outside of the block.");
79  POLYVOX_ASSERT(uYPos < m_uSideLength, "Position is outside of the block.");
80  POLYVOX_ASSERT(uZPos < m_uSideLength, "Position is outside of the block.");
81 
82  POLYVOX_ASSERT(m_tUncompressedData, "No uncompressed data available");
83 
84  m_tUncompressedData
85  [
86  uXPos +
87  uYPos * m_uSideLength +
88  uZPos * m_uSideLength * m_uSideLength
89  ] = tValue;
90  }
91 
92  template <typename VoxelType>
94  {
95  setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
96  }
97 
98  template <typename VoxelType>
100  {
101  const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
102  std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, tValue);
103  }
104 
105  template <typename VoxelType>
107  {
108  //Debug mode validation
109  POLYVOX_ASSERT(isPowerOf2(uSideLength), "Block side length must be a power of two.");
110 
111  //Release mode validation
112  if(!isPowerOf2(uSideLength))
113  {
114  POLYVOX_THROW(std::invalid_argument, "Block side length must be a power of two.");
115  }
116 
117  //Compute the side length
118  m_uSideLength = uSideLength;
119  m_uSideLengthPower = logBase2(uSideLength);
120 
121  m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
122 
124  }
125 
126  template <typename VoxelType>
128  {
129  uint32_t uSizeInBytes = sizeof(Block);
130  uSizeInBytes += sizeof(VoxelType) * m_uSideLength * m_uSideLength * m_uSideLength;
131  return uSizeInBytes;
132  }
133 }