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

PolyVoxCore/include/PolyVoxCore/RawVolume.inl

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 namespace PolyVox
00025 {
00034     template <typename VoxelType>
00035     RawVolume<VoxelType>::RawVolume
00036     (
00037         const Region& regValid
00038     )
00039     :BaseVolume<VoxelType>(regValid)
00040     {
00041         setBorderValue(VoxelType());
00042 
00043         //Create a volume of the right size.
00044         resize(regValid);
00045     }
00046 
00050     template <typename VoxelType>
00051     RawVolume<VoxelType>::~RawVolume()
00052     {
00053         delete[] m_pData;
00054         m_pData = 0;
00055     }
00056 
00062     template <typename VoxelType>
00063     VoxelType RawVolume<VoxelType>::getBorderValue(void) const
00064     {
00065         return m_tBorderValue;
00066     }
00067 
00074     template <typename VoxelType>
00075     VoxelType RawVolume<VoxelType>::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
00076     {
00077         if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)))
00078         {
00079             const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner();
00080             int32_t iLocalXPos = uXPos - v3dLowerCorner.getX();
00081             int32_t iLocalYPos = uYPos - v3dLowerCorner.getY();
00082             int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ();
00083 
00084             return m_pData
00085             [
00086                 iLocalXPos + 
00087                 iLocalYPos * this->getWidth() + 
00088                 iLocalZPos * this->getWidth() * this->getHeight()
00089             ];
00090         }
00091         else
00092         {
00093             return this->getBorderValue();
00094         }
00095     }
00096 
00101     template <typename VoxelType>
00102     VoxelType RawVolume<VoxelType>::getVoxelAt(const Vector3DInt32& v3dPos) const
00103     {
00104         return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
00105     }
00106 
00110     template <typename VoxelType>
00111     void RawVolume<VoxelType>::setBorderValue(const VoxelType& tBorder) 
00112     {
00113         m_tBorderValue = tBorder;
00114     }
00115 
00123     template <typename VoxelType>
00124     bool RawVolume<VoxelType>::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue)
00125     {
00126         if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)))
00127         {
00128             const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner();
00129             int32_t iLocalXPos = uXPos - v3dLowerCorner.getX();
00130             int32_t iLocalYPos = uYPos - v3dLowerCorner.getY();
00131             int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ();
00132 
00133             m_pData
00134             [
00135                 iLocalXPos + 
00136                 iLocalYPos * this->getWidth() + 
00137                 iLocalZPos * this->getWidth() * this->getHeight()
00138             ] = tValue;
00139 
00140             //Return true to indicate that we modified a voxel.
00141             return true;
00142         }
00143         else
00144         {
00145             return false;
00146         }
00147     }
00148 
00154     template <typename VoxelType>
00155     bool RawVolume<VoxelType>::setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue)
00156     {
00157         return setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
00158     }
00159 
00163     template <typename VoxelType>
00164     void RawVolume<VoxelType>::resize(const Region& regValidRegion)
00165     {
00166         this->m_regValidRegion = regValidRegion;
00167 
00168         //Ensure dimensions of the specified Region are valid
00169         assert(this->getWidth() > 0);
00170         assert(this->getHeight() > 0);
00171         assert(this->getDepth() > 0);
00172 
00173         //Create the data
00174         m_pData = new VoxelType[this->getWidth() * this->getHeight()* this->getDepth()];
00175 
00176         //Other properties we might find useful later
00177         this->m_uLongestSideLength = (std::max)((std::max)(this->getWidth(),this->getHeight()),this->getDepth());
00178         this->m_uShortestSideLength = (std::min)((std::min)(this->getWidth(),this->getHeight()),this->getDepth());
00179         this->m_fDiagonalLength = sqrtf(static_cast<float>(this->getWidth() * this->getWidth() + this->getHeight() * this->getHeight() + this->getDepth() * this->getDepth()));
00180     }
00181 
00185     template <typename VoxelType>
00186     uint32_t RawVolume<VoxelType>::calculateSizeInBytes(void)
00187     {
00188         return this->getWidth() * this->getHeight() * this->getDepth() * sizeof(VoxelType);
00189     }
00190 
00191 }
00192 

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