PolyVox  0.3.0-dev
Open source voxel management library
RawVolume.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_RawVolume_H__
25 #define __PolyVox_RawVolume_H__
26 
27 #include "PolyVoxCore/BaseVolume.h"
28 #include "PolyVoxCore/Log.h"
29 #include "PolyVoxCore/Region.h"
30 #include "PolyVoxCore/Vector.h"
31 
32 #include <cstdlib> //For abort()
33 #include <limits>
34 #include <memory>
35 #include <stdexcept> //For invalid_argument
36 
37 namespace PolyVox
38 {
39  template <typename VoxelType>
40  class RawVolume : public BaseVolume<VoxelType>
41  {
42  public:
43  #ifndef SWIG
44  //There seems to be some descrepency between Visual Studio and GCC about how the following class should be declared.
45  //There is a work around (see also See http://goo.gl/qu1wn) given below which appears to work on VS2010 and GCC, but
46  //which seems to cause internal compiler errors on VS2008 when building with the /Gm 'Enable Minimal Rebuild' compiler
47  //option. For now it seems best to 'fix' it with the preprocessor insstead, but maybe the workaround can be reinstated
48  //in the future
49  //typedef Volume<VoxelType> VolumeOfVoxelType; //Workaround for GCC/VS2010 differences.
50  //class Sampler : public VolumeOfVoxelType::template Sampler< RawVolume<VoxelType> >
51 #if defined(_MSC_VER)
52  class Sampler : public BaseVolume<VoxelType>::Sampler< RawVolume<VoxelType> > //This line works on VS2010
53 #else
54  class Sampler : public BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> > //This line works on GCC
55 #endif
56  {
57  public:
59  ~Sampler();
60 
61  inline VoxelType getVoxel(void) const;
62 
63  void setPosition(const Vector3DInt32& v3dNewPos);
64  void setPosition(int32_t xPos, int32_t yPos, int32_t zPos);
65  inline bool setVoxel(VoxelType tValue);
66 
67  void movePositiveX(void);
68  void movePositiveY(void);
69  void movePositiveZ(void);
70 
71  void moveNegativeX(void);
72  void moveNegativeY(void);
73  void moveNegativeZ(void);
74 
75  inline VoxelType peekVoxel1nx1ny1nz(void) const;
76  inline VoxelType peekVoxel1nx1ny0pz(void) const;
77  inline VoxelType peekVoxel1nx1ny1pz(void) const;
78  inline VoxelType peekVoxel1nx0py1nz(void) const;
79  inline VoxelType peekVoxel1nx0py0pz(void) const;
80  inline VoxelType peekVoxel1nx0py1pz(void) const;
81  inline VoxelType peekVoxel1nx1py1nz(void) const;
82  inline VoxelType peekVoxel1nx1py0pz(void) const;
83  inline VoxelType peekVoxel1nx1py1pz(void) const;
84 
85  inline VoxelType peekVoxel0px1ny1nz(void) const;
86  inline VoxelType peekVoxel0px1ny0pz(void) const;
87  inline VoxelType peekVoxel0px1ny1pz(void) const;
88  inline VoxelType peekVoxel0px0py1nz(void) const;
89  inline VoxelType peekVoxel0px0py0pz(void) const;
90  inline VoxelType peekVoxel0px0py1pz(void) const;
91  inline VoxelType peekVoxel0px1py1nz(void) const;
92  inline VoxelType peekVoxel0px1py0pz(void) const;
93  inline VoxelType peekVoxel0px1py1pz(void) const;
94 
95  inline VoxelType peekVoxel1px1ny1nz(void) const;
96  inline VoxelType peekVoxel1px1ny0pz(void) const;
97  inline VoxelType peekVoxel1px1ny1pz(void) const;
98  inline VoxelType peekVoxel1px0py1nz(void) const;
99  inline VoxelType peekVoxel1px0py0pz(void) const;
100  inline VoxelType peekVoxel1px0py1pz(void) const;
101  inline VoxelType peekVoxel1px1py1nz(void) const;
102  inline VoxelType peekVoxel1px1py0pz(void) const;
103  inline VoxelType peekVoxel1px1py1pz(void) const;
104 
105  private:
106 
107  //Other current position information
108  VoxelType* mCurrentVoxel;
109  };
110  #endif
111 
112  public:
114  RawVolume(const Region& regValid);
115 
117  ~RawVolume();
118 
120  VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
122  VoxelType getVoxel(const Vector3DInt32& v3dPos) const;
124  VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
126  VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
128  VoxelType getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType()) const;
130  VoxelType getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType()) const;
131 
133  bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue);
135  bool setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue);
136 
139 
140  protected:
142  RawVolume(const RawVolume& rhs);
143 
145  RawVolume& operator=(const RawVolume& rhs);
146 
147  private:
148  void initialise(const Region& regValidRegion);
149 
150  //The block data
151  VoxelType* m_pData;
152  };
153 }
154 
155 #include "PolyVoxCore/RawVolume.inl"
157 
158 #endif //__PolyVox_RawVolume_H__