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 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
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
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
00169 assert(this->getWidth() > 0);
00170 assert(this->getHeight() > 0);
00171 assert(this->getDepth() > 0);
00172
00173
00174 m_pData = new VoxelType[this->getWidth() * this->getHeight()* this->getDepth()];
00175
00176
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