PolyVox  0.2.0
Open source voxel management library
ConstVolumeProxy.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_ConstVolumeProxy_H__
25 #define __PolyVox_ConstVolumeProxy_H__
26 
27 #include "PolyVoxCore/Region.h"
28 #include "PolyVoxCore/Vector.h"
29 
30 namespace PolyVox
31 {
32  template <typename VoxelType>
34  {
35  //LargeVolume is a friend so it can call the constructor.
36  friend class LargeVolume<VoxelType>;
37  public:
38  VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
39  {
40  assert(m_regValid.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)));
41  return m_pVolume.getVoxelAt(uXPos, uYPos, uZPos);
42  }
43 
44  VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const
45  {
46  assert(m_regValid.containsPoint(v3dPos));
47  return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
48  }
49 
50  void setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const
51  {
52  assert(m_regValid.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)));
53  m_pVolume.setVoxelAtConst(uXPos, uYPos, uZPos, tValue);
54  }
55 
56  void setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue) const
57  {
58  assert(m_regValid.containsPoint(v3dPos));
59  setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
60  }
61  private:
62  //Private constructor, so client code can't abuse this class.
63  ConstVolumeProxy(const LargeVolume<VoxelType>& pVolume, const Region& regValid)
64  :m_pVolume(pVolume)
65  ,m_regValid(regValid)
66  {
67  }
68 
69  //Private assignment operator, so client code can't abuse this class.
70  ConstVolumeProxy& operator=(const ConstVolumeProxy& rhs)
71  {
72  }
73 
74  const LargeVolume<VoxelType>& m_pVolume;
75  const Region& m_regValid;
76  };
77 }
78 
79 #endif //__PolyVox_ConstVolumeProxy_H__