PolyVox  0.2.1
Open source voxel management library
Block.h
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 
24 #ifndef __PolyVox_Block_H__
25 #define __PolyVox_Block_H__
26 
28 #include "PolyVoxCore/Vector.h"
29 
30 #include <limits>
31 #include <vector>
32 
33 namespace PolyVox
34 {
35  template <typename VoxelType>
36  class Block
37  {
38  template <typename LengthType>
39  struct RunlengthEntry
40  {
41  LengthType length;
42  VoxelType value;
43 
44  //We can parametise the length on anything up to uint32_t.
45  //This lets us experiment with the optimal size in the future.
46  static uint32_t maxRunlength(void) {return (std::numeric_limits<LengthType>::max)();}
47  };
48 
49  public:
50  Block(uint16_t uSideLength = 0);
51 
52  uint16_t getSideLength(void) const;
53  VoxelType getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const;
54  VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const;
55 
56  void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue);
57  void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);
58 
59  void fill(VoxelType tValue);
60  void initialise(uint16_t uSideLength);
61  uint32_t calculateSizeInBytes(void);
62 
63  public:
64  void compress(void);
65  void uncompress(void);
66 
67  std::vector< RunlengthEntry<uint16_t> > m_vecCompressedData;
68  VoxelType* m_tUncompressedData;
69  uint16_t m_uSideLength;
73  };
74 }
75 
77 
78 #endif