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 #ifndef __PolyVox_SimpleVolume_H__
00025 #define __PolyVox_SimpleVolume_H__
00026
00027 #include "PolyVoxImpl/Utility.h"
00028
00029 #include "PolyVoxCore/BaseVolume.h"
00030 #include "PolyVoxCore/Log.h"
00031 #include "PolyVoxCore/Region.h"
00032 #include "PolyVoxCore/Vector.h"
00033
00034 #include <cassert>
00035 #include <cstdlib>
00036 #include <cstring>
00037 #include <limits>
00038 #include <memory>
00039 #include <stdexcept>
00040
00041 namespace PolyVox
00042 {
00043 template <typename VoxelType>
00044 class SimpleVolume : public BaseVolume<VoxelType>
00045 {
00046 public:
00047 #ifndef SWIG
00048 class Block
00049 {
00050 public:
00051 Block(uint16_t uSideLength = 0);
00052 ~Block();
00053
00054 uint16_t getSideLength(void) const;
00055 VoxelType getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const;
00056 VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const;
00057
00058 void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue);
00059 void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);
00060
00061 void fill(VoxelType tValue);
00062 void initialise(uint16_t uSideLength);
00063 uint32_t calculateSizeInBytes(void);
00064
00065 public:
00066 VoxelType* m_tUncompressedData;
00067 uint16_t m_uSideLength;
00068 uint8_t m_uSideLengthPower;
00069 };
00070
00071
00072
00073
00074
00075
00076
00077
00078 #if defined(_MSC_VER)
00079 class Sampler : public BaseVolume<VoxelType>::Sampler< SimpleVolume<VoxelType> >
00080 #else
00081 class Sampler : public BaseVolume<VoxelType>::template Sampler< SimpleVolume<VoxelType> >
00082 #endif
00083 {
00084 public:
00085 Sampler(SimpleVolume<VoxelType>* volume);
00086 ~Sampler();
00087
00088 Sampler& operator=(const Sampler& rhs) throw();
00089
00090 int32_t getPosX(void) const;
00091 int32_t getPosY(void) const;
00092 int32_t getPosZ(void) const;
00093 VoxelType getSubSampledVoxel(uint8_t uLevel) const;
00094 inline VoxelType getVoxel(void) const;
00095
00096 void setPosition(const Vector3DInt32& v3dNewPos);
00097 void setPosition(int32_t xPos, int32_t yPos, int32_t zPos);
00098 inline bool setVoxel(VoxelType tValue);
00099
00100 void movePositiveX(void);
00101 void movePositiveY(void);
00102 void movePositiveZ(void);
00103
00104 void moveNegativeX(void);
00105 void moveNegativeY(void);
00106 void moveNegativeZ(void);
00107
00108 inline VoxelType peekVoxel1nx1ny1nz(void) const;
00109 inline VoxelType peekVoxel1nx1ny0pz(void) const;
00110 inline VoxelType peekVoxel1nx1ny1pz(void) const;
00111 inline VoxelType peekVoxel1nx0py1nz(void) const;
00112 inline VoxelType peekVoxel1nx0py0pz(void) const;
00113 inline VoxelType peekVoxel1nx0py1pz(void) const;
00114 inline VoxelType peekVoxel1nx1py1nz(void) const;
00115 inline VoxelType peekVoxel1nx1py0pz(void) const;
00116 inline VoxelType peekVoxel1nx1py1pz(void) const;
00117
00118 inline VoxelType peekVoxel0px1ny1nz(void) const;
00119 inline VoxelType peekVoxel0px1ny0pz(void) const;
00120 inline VoxelType peekVoxel0px1ny1pz(void) const;
00121 inline VoxelType peekVoxel0px0py1nz(void) const;
00122 inline VoxelType peekVoxel0px0py0pz(void) const;
00123 inline VoxelType peekVoxel0px0py1pz(void) const;
00124 inline VoxelType peekVoxel0px1py1nz(void) const;
00125 inline VoxelType peekVoxel0px1py0pz(void) const;
00126 inline VoxelType peekVoxel0px1py1pz(void) const;
00127
00128 inline VoxelType peekVoxel1px1ny1nz(void) const;
00129 inline VoxelType peekVoxel1px1ny0pz(void) const;
00130 inline VoxelType peekVoxel1px1ny1pz(void) const;
00131 inline VoxelType peekVoxel1px0py1nz(void) const;
00132 inline VoxelType peekVoxel1px0py0pz(void) const;
00133 inline VoxelType peekVoxel1px0py1pz(void) const;
00134 inline VoxelType peekVoxel1px1py1nz(void) const;
00135 inline VoxelType peekVoxel1px1py0pz(void) const;
00136 inline VoxelType peekVoxel1px1py1pz(void) const;
00137
00138 private:
00139
00140 VoxelType* mCurrentVoxel;
00141 };
00142 #endif
00143
00144 public:
00146 SimpleVolume
00147 (
00148 const Region& regValid,
00149 uint16_t uBlockSideLength = 32
00150 );
00152 SimpleVolume
00153 (
00154 int32_t dont_use_this_constructor_1, int32_t dont_use_this_constructor_2, int32_t dont_use_this_constructor_3
00155 );
00157 ~SimpleVolume();
00158
00160 VoxelType getBorderValue(void) const;
00162 VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
00164 VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const;
00165
00167 void setBorderValue(const VoxelType& tBorder);
00169 bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue);
00171 bool setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue);
00172
00174 uint32_t calculateSizeInBytes(void);
00175
00177 void resize(const Region& regValidRegion, uint16_t uBlockSideLength);
00178
00179 private:
00180 Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const;
00181
00182
00183 Block* m_pBlocks;
00184
00185
00186
00187
00188
00189 VoxelType* m_pUncompressedBorderData;
00190
00191
00192 Region m_regValidRegionInBlocks;
00193
00194
00195 uint32_t m_uNoOfBlocksInVolume;
00196 uint16_t m_uWidthInBlocks;
00197 uint16_t m_uHeightInBlocks;
00198 uint16_t m_uDepthInBlocks;
00199
00200
00201 uint32_t m_uNoOfVoxelsPerBlock;
00202 uint16_t m_uBlockSideLength;
00203 uint8_t m_uBlockSideLengthPower;
00204 };
00205 }
00206
00207 #include "PolyVoxCore/SimpleVolumeBlock.inl"
00208 #include "PolyVoxCore/SimpleVolume.inl"
00209 #include "PolyVoxCore/SimpleVolumeSampler.inl"
00210
00211 #endif //__PolyVox_SimpleVolume_H__