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_RawVolume_H__ 00025 #define __PolyVox_RawVolume_H__ 00026 00027 #include "PolyVoxCore/BaseVolume.h" 00028 #include "PolyVoxCore/Log.h" 00029 #include "PolyVoxCore/Region.h" 00030 #include "PolyVoxCore/Vector.h" 00031 00032 #include <cassert> 00033 #include <cstdlib> //For abort() 00034 #include <limits> 00035 #include <memory> 00036 #include <stdexcept> //For invalid_argument 00037 00038 namespace PolyVox 00039 { 00040 template <typename VoxelType> 00041 class RawVolume : public BaseVolume<VoxelType> 00042 { 00043 public: 00044 #ifndef SWIG 00045 //There seems to be some descrepency between Visual Studio and GCC about how the following class should be declared. 00046 //There is a work around (see also See http://goo.gl/qu1wn) given below which appears to work on VS2010 and GCC, but 00047 //which seems to cause internal compiler errors on VS2008 when building with the /Gm 'Enable Minimal Rebuild' compiler 00048 //option. For now it seems best to 'fix' it with the preprocessor insstead, but maybe the workaround can be reinstated 00049 //in the future 00050 //typedef Volume<VoxelType> VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. 00051 //class Sampler : public VolumeOfVoxelType::template Sampler< RawVolume<VoxelType> > 00052 #if defined(_MSC_VER) 00053 class Sampler : public BaseVolume<VoxelType>::Sampler< RawVolume<VoxelType> > //This line works on VS2010 00054 #else 00055 class Sampler : public BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> > //This line works on GCC 00056 #endif 00057 { 00058 public: 00059 Sampler(RawVolume<VoxelType>* volume); 00060 ~Sampler(); 00061 00062 int32_t getPosX(void) const; 00063 int32_t getPosY(void) const; 00064 int32_t getPosZ(void) const; 00065 inline VoxelType getVoxel(void) const; 00066 00067 void setPosition(const Vector3DInt32& v3dNewPos); 00068 void setPosition(int32_t xPos, int32_t yPos, int32_t zPos); 00069 inline bool setVoxel(VoxelType tValue); 00070 00071 void movePositiveX(void); 00072 void movePositiveY(void); 00073 void movePositiveZ(void); 00074 00075 void moveNegativeX(void); 00076 void moveNegativeY(void); 00077 void moveNegativeZ(void); 00078 00079 inline VoxelType peekVoxel1nx1ny1nz(void) const; 00080 inline VoxelType peekVoxel1nx1ny0pz(void) const; 00081 inline VoxelType peekVoxel1nx1ny1pz(void) const; 00082 inline VoxelType peekVoxel1nx0py1nz(void) const; 00083 inline VoxelType peekVoxel1nx0py0pz(void) const; 00084 inline VoxelType peekVoxel1nx0py1pz(void) const; 00085 inline VoxelType peekVoxel1nx1py1nz(void) const; 00086 inline VoxelType peekVoxel1nx1py0pz(void) const; 00087 inline VoxelType peekVoxel1nx1py1pz(void) const; 00088 00089 inline VoxelType peekVoxel0px1ny1nz(void) const; 00090 inline VoxelType peekVoxel0px1ny0pz(void) const; 00091 inline VoxelType peekVoxel0px1ny1pz(void) const; 00092 inline VoxelType peekVoxel0px0py1nz(void) const; 00093 inline VoxelType peekVoxel0px0py0pz(void) const; 00094 inline VoxelType peekVoxel0px0py1pz(void) const; 00095 inline VoxelType peekVoxel0px1py1nz(void) const; 00096 inline VoxelType peekVoxel0px1py0pz(void) const; 00097 inline VoxelType peekVoxel0px1py1pz(void) const; 00098 00099 inline VoxelType peekVoxel1px1ny1nz(void) const; 00100 inline VoxelType peekVoxel1px1ny0pz(void) const; 00101 inline VoxelType peekVoxel1px1ny1pz(void) const; 00102 inline VoxelType peekVoxel1px0py1nz(void) const; 00103 inline VoxelType peekVoxel1px0py0pz(void) const; 00104 inline VoxelType peekVoxel1px0py1pz(void) const; 00105 inline VoxelType peekVoxel1px1py1nz(void) const; 00106 inline VoxelType peekVoxel1px1py0pz(void) const; 00107 inline VoxelType peekVoxel1px1py1pz(void) const; 00108 00109 private: 00110 //Other current position information 00111 VoxelType* mCurrentVoxel; 00112 00113 //Whether the current position is inside the volume 00114 //FIXME - Replace these with flags 00115 bool m_bIsCurrentPositionValidInX; 00116 bool m_bIsCurrentPositionValidInY; 00117 bool m_bIsCurrentPositionValidInZ; 00118 }; 00119 #endif 00120 00121 public: 00123 RawVolume 00124 ( 00125 const Region& regValid 00126 ); 00128 ~RawVolume(); 00129 00131 VoxelType getBorderValue(void) const; 00133 VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; 00135 VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; 00136 00138 void setBorderValue(const VoxelType& tBorder); 00140 bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); 00142 bool setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue); 00143 00145 uint32_t calculateSizeInBytes(void); 00146 00148 void resize(const Region& regValidRegion); 00149 00150 private: 00151 //The block data 00152 VoxelType* m_pData; 00153 00154 //The border value 00155 VoxelType m_tBorderValue; 00156 }; 00157 } 00158 00159 #include "PolyVoxCore/RawVolume.inl" 00160 #include "PolyVoxCore/RawVolumeSampler.inl" 00161 00162 #endif //__PolyVox_RawVolume_H__