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

PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.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 #define BORDER_LOWX(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getX())
00025 #define BORDER_HIGHX(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getX())
00026 #define BORDER_LOWY(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getY())
00027 #define BORDER_HIGHY(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getY())
00028 #define BORDER_LOWZ(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ())
00029 #define BORDER_HIGHZ(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ())
00030 
00031 namespace PolyVox
00032 {
00033     template <typename VoxelType>
00034     RawVolume<VoxelType>::Sampler::Sampler(RawVolume<VoxelType>* volume)
00035         :BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >(volume)
00036         ,mCurrentVoxel(0)
00037         ,m_bIsCurrentPositionValidInX(false)
00038         ,m_bIsCurrentPositionValidInY(false)
00039         ,m_bIsCurrentPositionValidInZ(false)
00040     {
00041     }
00042 
00043     template <typename VoxelType>
00044     RawVolume<VoxelType>::Sampler::~Sampler()
00045     {
00046     }
00047 
00048     template <typename VoxelType>
00049     int32_t RawVolume<VoxelType>::Sampler::getPosX(void) const
00050     {
00051         return this->mXPosInVolume;
00052     }
00053 
00054     template <typename VoxelType>
00055     int32_t RawVolume<VoxelType>::Sampler::getPosY(void) const
00056     {
00057         return this->mYPosInVolume;
00058     }
00059 
00060     template <typename VoxelType>
00061     int32_t RawVolume<VoxelType>::Sampler::getPosZ(void) const
00062     {
00063         return this->mZPosInVolume;
00064     }
00065 
00066     template <typename VoxelType>
00067     VoxelType RawVolume<VoxelType>::Sampler::getVoxel(void) const
00068     {
00069         return (m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ) ? *mCurrentVoxel : this->mVolume->getBorderValue();
00070     }
00071 
00072     template <typename VoxelType>
00073     void RawVolume<VoxelType>::Sampler::setPosition(const Vector3DInt32& v3dNewPos)
00074     {
00075         setPosition(v3dNewPos.getX(), v3dNewPos.getY(), v3dNewPos.getZ());
00076     }
00077 
00078     template <typename VoxelType>
00079     void RawVolume<VoxelType>::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos)
00080     {
00081         this->mXPosInVolume = xPos;
00082         this->mYPosInVolume = yPos;
00083         this->mZPosInVolume = zPos;
00084 
00085         const Vector3DInt32& v3dLowerCorner = this->mVolume->m_regValidRegion.getLowerCorner();
00086         int32_t iLocalXPos = xPos - v3dLowerCorner.getX();
00087         int32_t iLocalYPos = yPos - v3dLowerCorner.getY();
00088         int32_t iLocalZPos = zPos - v3dLowerCorner.getZ();
00089 
00090         const int32_t uVoxelIndex = iLocalXPos + 
00091                 iLocalYPos * this->mVolume->getWidth() + 
00092                 iLocalZPos * this->mVolume->getWidth() * this->mVolume->getHeight();
00093 
00094         mCurrentVoxel = this->mVolume->m_pData + uVoxelIndex;
00095 
00096         m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(xPos);
00097         m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(yPos);
00098         m_bIsCurrentPositionValidInZ = this->mVolume->getEnclosingRegion().containsPointInZ(zPos);
00099     }
00100 
00101     template <typename VoxelType>
00102     bool RawVolume<VoxelType>::Sampler::setVoxel(VoxelType tValue)
00103     {
00104         //return m_bIsCurrentPositionValid ? *mCurrentVoxel : this->mVolume->getBorderValue();
00105         if(m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ)
00106         {
00107             *mCurrentVoxel = tValue;
00108             return true;
00109         }
00110         else
00111         {
00112             return false;
00113         }
00114     }
00115 
00116     template <typename VoxelType>
00117     void RawVolume<VoxelType>::Sampler::movePositiveX(void)
00118     {
00119         this->mXPosInVolume++;
00120         ++mCurrentVoxel;
00121         m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(this->mXPosInVolume);
00122     }
00123 
00124     template <typename VoxelType>
00125     void RawVolume<VoxelType>::Sampler::movePositiveY(void)
00126     {
00127         this->mYPosInVolume++;
00128         mCurrentVoxel += this->mVolume->getWidth();
00129         m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(this->mYPosInVolume);
00130     }
00131 
00132     template <typename VoxelType>
00133     void RawVolume<VoxelType>::Sampler::movePositiveZ(void)
00134     {
00135         this->mZPosInVolume++;
00136         mCurrentVoxel += this->mVolume->getWidth() * this->mVolume->getHeight();
00137         m_bIsCurrentPositionValidInZ = this->mVolume->getEnclosingRegion().containsPointInZ(this->mZPosInVolume);
00138     }
00139 
00140     template <typename VoxelType>
00141     void RawVolume<VoxelType>::Sampler::moveNegativeX(void)
00142     {
00143         this->mXPosInVolume--;
00144         --mCurrentVoxel;
00145         m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(this->mXPosInVolume);
00146     }
00147 
00148     template <typename VoxelType>
00149     void RawVolume<VoxelType>::Sampler::moveNegativeY(void)
00150     {
00151         this->mYPosInVolume--;
00152         mCurrentVoxel -= this->mVolume->getWidth();
00153         m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(this->mYPosInVolume);
00154     }
00155 
00156     template <typename VoxelType>
00157     void RawVolume<VoxelType>::Sampler::moveNegativeZ(void)
00158     {
00159         this->mZPosInVolume--;
00160         mCurrentVoxel -= this->mVolume->getWidth() * this->mVolume->getHeight();
00161         m_bIsCurrentPositionValidInZ = this->mVolume->getEnclosingRegion().containsPointInZ(this->mZPosInVolume);
00162     }
00163 
00164     template <typename VoxelType>
00165     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1ny1nz(void) const
00166     {
00167         if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
00168         {
00169             return *(mCurrentVoxel - 1 - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
00170         }
00171         return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1);
00172     }
00173 
00174     template <typename VoxelType>
00175     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1ny0pz(void) const
00176     {
00177         if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) )
00178         {
00179             return *(mCurrentVoxel - 1 - this->mVolume->getWidth());
00180         }
00181         return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume);
00182     }
00183 
00184     template <typename VoxelType>
00185     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1ny1pz(void) const
00186     {
00187         if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
00188         {
00189             return *(mCurrentVoxel - 1 - this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
00190         }
00191         return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1);
00192     }
00193 
00194     template <typename VoxelType>
00195     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx0py1nz(void) const
00196     {
00197         if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
00198         {
00199             return *(mCurrentVoxel - 1 - this->mVolume->getWidth() * this->mVolume->getHeight());
00200         }
00201         return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1);
00202     }
00203 
00204     template <typename VoxelType>
00205     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx0py0pz(void) const
00206     {
00207         if( BORDER_LOWX(this->mXPosInVolume) )
00208         {
00209             return *(mCurrentVoxel - 1);
00210         }
00211         return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume);
00212     }
00213 
00214     template <typename VoxelType>
00215     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx0py1pz(void) const
00216     {
00217         if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
00218         {
00219             return *(mCurrentVoxel - 1 + this->mVolume->getWidth() * this->mVolume->getHeight());
00220         }
00221         return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1);
00222     }
00223 
00224     template <typename VoxelType>
00225     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1py1nz(void) const
00226     {
00227         if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_LOWZ(this->mYPosInVolume) )
00228         {
00229             return *(mCurrentVoxel - 1 + this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
00230         }
00231         return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1);
00232     }
00233 
00234     template <typename VoxelType>
00235     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1py0pz(void) const
00236     {
00237         if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) )
00238         {
00239             return *(mCurrentVoxel - 1 + this->mVolume->getWidth());
00240         }
00241         return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume);
00242     }
00243 
00244     template <typename VoxelType>
00245     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1nx1py1pz(void) const
00246     {
00247         if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
00248         {
00249             return *(mCurrentVoxel - 1 + this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
00250         }
00251         return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1);
00252     }
00253 
00255 
00256     template <typename VoxelType>
00257     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1ny1nz(void) const
00258     {
00259         if( BORDER_LOWX(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
00260         {
00261             return *(mCurrentVoxel - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
00262         }
00263         return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1);
00264     }
00265 
00266     template <typename VoxelType>
00267     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1ny0pz(void) const
00268     {
00269         if( BORDER_LOWY(this->mYPosInVolume) )
00270         {
00271             return *(mCurrentVoxel - this->mVolume->getWidth());
00272         }
00273         return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume);
00274     }
00275 
00276     template <typename VoxelType>
00277     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1ny1pz(void) const
00278     {
00279         if( BORDER_LOWY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
00280         {
00281             return *(mCurrentVoxel - this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
00282         }
00283         return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1);
00284     }
00285 
00286     template <typename VoxelType>
00287     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px0py1nz(void) const
00288     {
00289         if( BORDER_LOWZ(this->mZPosInVolume) )
00290         {
00291             return *(mCurrentVoxel - this->mVolume->getWidth() * this->mVolume->getHeight());
00292         }
00293         return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1);
00294     }
00295 
00296     template <typename VoxelType>
00297     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px0py0pz(void) const
00298     {
00299             return *mCurrentVoxel;
00300     }
00301 
00302     template <typename VoxelType>
00303     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px0py1pz(void) const
00304     {
00305         if( BORDER_HIGHZ(this->mZPosInVolume) )
00306         {
00307             return *(mCurrentVoxel + this->mVolume->getWidth() * this->mVolume->getHeight());
00308         }
00309         return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1);
00310     }
00311 
00312     template <typename VoxelType>
00313     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1py1nz(void) const
00314     {
00315         if( BORDER_HIGHY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
00316         {
00317             return *(mCurrentVoxel + this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
00318         }
00319         return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1);
00320     }
00321 
00322     template <typename VoxelType>
00323     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1py0pz(void) const
00324     {
00325         if( BORDER_HIGHY(this->mYPosInVolume) )
00326         {
00327             return *(mCurrentVoxel + this->mVolume->getWidth());
00328         }
00329         return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume);
00330     }
00331 
00332     template <typename VoxelType>
00333     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel0px1py1pz(void) const
00334     {
00335         if( BORDER_HIGHY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
00336         {
00337             return *(mCurrentVoxel + this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
00338         }
00339         return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1);
00340     }
00341 
00343 
00344     template <typename VoxelType>
00345     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1ny1nz(void) const
00346     {
00347         if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
00348         {
00349             return *(mCurrentVoxel + 1 - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
00350         }
00351         return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1);
00352     }
00353 
00354     template <typename VoxelType>
00355     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1ny0pz(void) const
00356     {
00357         if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) )
00358         {
00359             return *(mCurrentVoxel + 1 - this->mVolume->getWidth());
00360         }
00361         return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume);
00362     }
00363 
00364     template <typename VoxelType>
00365     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1ny1pz(void) const
00366     {
00367         if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
00368         {
00369             return *(mCurrentVoxel + 1 - this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
00370         }
00371         return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1);
00372     }
00373 
00374     template <typename VoxelType>
00375     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px0py1nz(void) const
00376     {
00377         if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
00378         {
00379             return *(mCurrentVoxel + 1 - this->mVolume->getWidth() * this->mVolume->getHeight());
00380         }
00381         return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1);
00382     }
00383 
00384     template <typename VoxelType>
00385     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px0py0pz(void) const
00386     {
00387         if( BORDER_HIGHX(this->mXPosInVolume) )
00388         {
00389             return *(mCurrentVoxel + 1);
00390         }
00391         return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume);
00392     }
00393 
00394     template <typename VoxelType>
00395     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px0py1pz(void) const
00396     {
00397         if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
00398         {
00399             return *(mCurrentVoxel + 1 + this->mVolume->getWidth() * this->mVolume->getHeight());
00400         }
00401         return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1);
00402     }
00403 
00404     template <typename VoxelType>
00405     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1py1nz(void) const
00406     {
00407         if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) )
00408         {
00409             return *(mCurrentVoxel + 1 + this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight());
00410         }
00411         return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1);
00412     }
00413 
00414     template <typename VoxelType>
00415     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1py0pz(void) const
00416     {
00417         if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) )
00418         {
00419             return *(mCurrentVoxel + 1 + this->mVolume->getWidth());
00420         }
00421         return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume);
00422     }
00423 
00424     template <typename VoxelType>
00425     VoxelType RawVolume<VoxelType>::Sampler::peekVoxel1px1py1pz(void) const
00426     {
00427         if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) )
00428         {
00429             return *(mCurrentVoxel + 1 + this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight());
00430         }
00431         return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1);
00432     }
00433 }
00434 
00435 #undef BORDER_LOWX
00436 #undef BORDER_HIGHX
00437 #undef BORDER_LOWY
00438 #undef BORDER_HIGHY
00439 #undef BORDER_LOWZ
00440 #undef BORDER_HIGHZ

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