• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

PolyVoxCore/include/PolyVoxCore/SimpleVolume.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 Copyright (c) 2005-2009 David Williams
00003 
00004 This software is provided 'as-is', without any express or implied
00005 warranty. In no event will the authors be held liable for any damages
00006 arising from the use of this software.
00007 
00008 Permission is granted to anyone to use this software for any purpose,
00009 including commercial applications, and to alter it and redistribute it
00010 freely, subject to the following restrictions:
00011 
00012     1. The origin of this software must not be misrepresented; you must not
00013     claim that you wrote the original software. If you use this software
00014     in a product, an acknowledgment in the product documentation would be
00015     appreciated but is not required.
00016 
00017     2. Altered source versions must be plainly marked as such, and must not be
00018     misrepresented as being the original software.
00019 
00020     3. This notice may not be removed or altered from any source
00021     distribution.   
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> //For abort()
00036 #include <cstring> //For memcpy
00037 #include <limits>
00038 #include <memory>
00039 #include <stdexcept> //For invalid_argument
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         //There seems to be some descrepency between Visual Studio and GCC about how the following class should be declared.
00072         //There is a work around (see also See http://goo.gl/qu1wn) given below which appears to work on VS2010 and GCC, but
00073         //which seems to cause internal compiler errors on VS2008 when building with the /Gm 'Enable Minimal Rebuild' compiler
00074         //option. For now it seems best to 'fix' it with the preprocessor insstead, but maybe the workaround can be reinstated
00075         //in the future
00076         //typedef Volume<VoxelType> VolumeOfVoxelType; //Workaround for GCC/VS2010 differences.
00077         //class Sampler : public VolumeOfVoxelType::template Sampler< SimpleVolume<VoxelType> >
00078 #if defined(_MSC_VER)
00079         class Sampler : public BaseVolume<VoxelType>::Sampler< SimpleVolume<VoxelType> > //This line works on VS2010
00080 #else
00081                 class Sampler : public BaseVolume<VoxelType>::template Sampler< SimpleVolume<VoxelType> > //This line works on GCC
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             //Other current position information
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         //The block data
00183         Block* m_pBlocks;
00184 
00185         //We don't store an actual Block for the border, just the uncompressed data. This is partly because the border
00186         //block does not have a position (so can't be passed to getUncompressedBlock()) and partly because there's a
00187         //good chance we'll often hit it anyway. It's a chunk of homogenous data (rather than a single value) so that
00188         //the VolumeIterator can do it's usual pointer arithmetic without needing to know it's gone outside the volume.
00189         VoxelType* m_pUncompressedBorderData;
00190 
00191         //The size of the volume in vlocks
00192         Region m_regValidRegionInBlocks;
00193 
00194         //Volume size measured in blocks.
00195         uint32_t m_uNoOfBlocksInVolume;
00196         uint16_t m_uWidthInBlocks;
00197         uint16_t m_uHeightInBlocks;
00198         uint16_t m_uDepthInBlocks;
00199 
00200         //The size of the blocks
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__

Generated on Sat Nov 19 2011 00:27:31 for PolyVox by  doxygen 1.7.1