Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkNeighborhood.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkNeighborhood.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-02-07 23:09:24 $
00007   Version:   $Revision: 1.46 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkNeighborhood_h
00018 #define __itkNeighborhood_h
00019 
00020 #include <iostream>
00021 #include "itkNeighborhoodAllocator.h"
00022 #include "itkSize.h"
00023 #include "itkIndent.h"
00024 #include "itkSliceIterator.h"
00025 #include "vnl/vnl_vector.h"
00026 #include "itkOffset.h"
00027 #include <vector>
00028 
00029 namespace itk {
00030 
00052 template<class TPixel, unsigned int VDimension = 2,
00053          class TAllocator = NeighborhoodAllocator<TPixel> >
00054 class ITK_EXPORT Neighborhood
00055 {
00056 public:
00058   typedef Neighborhood Self;
00059 
00061   typedef TAllocator AllocatorType;
00062 
00064   itkStaticConstMacro(NeighborhoodDimension, unsigned int, VDimension);
00065 
00067   typedef TPixel PixelType;
00068 
00072   typedef typename AllocatorType::iterator       Iterator;
00073   typedef typename AllocatorType::const_iterator ConstIterator;
00074 
00076   typedef ::itk::Size<VDimension>          SizeType;
00077   typedef typename SizeType::SizeValueType SizeValueType;
00078 
00080   typedef ::itk::Size<VDimension> RadiusType;
00081 
00083   typedef Offset<VDimension> OffsetType;
00084 
00086   typedef SliceIterator<TPixel, Self> SliceIteratorType;
00087 
00089   Neighborhood() { m_Radius.Fill(0); m_Size.Fill(0);  }
00090 
00092   virtual ~Neighborhood() {}
00093 
00095   Neighborhood(const Self& other);
00096 
00098   Self &operator=(const Self& other);
00099 
00101   bool
00102   operator==(const Self& other) const
00103     {
00104     return (m_Radius == other.m_Radius &&
00105             m_Size   == other.m_Size &&
00106             m_DataBuffer == other.m_DataBuffer);
00107     }
00108 
00110   bool operator!=(const Self& other) const
00111     {
00112     return (m_Radius != other.m_Radius ||
00113             m_Size   != other.m_Size ||
00114             m_DataBuffer != other.m_DataBuffer);
00115     }
00116 
00118   const SizeType GetRadius() const
00119     { return m_Radius; }
00120 
00123   unsigned long GetRadius(const unsigned long n) const
00124     { return m_Radius[n]; }
00125 
00128   unsigned long GetSize(const unsigned long n) const
00129     { return m_Size[n]; }
00130 
00132   SizeType GetSize() const
00133     { return m_Size; }
00134 
00138   unsigned GetStride(const unsigned axis) const
00139   {     return m_StrideTable[axis];  }
00140 
00142   Iterator End()
00143     { return m_DataBuffer.end(); }
00144   Iterator Begin()
00145     { return m_DataBuffer.begin(); }
00146   ConstIterator End() const
00147     { return m_DataBuffer.end(); }
00148   ConstIterator Begin() const
00149     { return m_DataBuffer.begin(); }
00151 
00153   unsigned int Size() const
00154     { return m_DataBuffer.size(); }
00155 
00157   TPixel &operator[](unsigned int i)
00158     { return m_DataBuffer[i]; }
00159   const TPixel &operator[](unsigned int i) const
00160     { return m_DataBuffer[i]; }
00161   TPixel &GetElement(unsigned int i)
00162     { return m_DataBuffer[i]; }
00164 
00166   TPixel GetCenterValue() const
00167     { return (this->operator[]((this->Size())>>1)); }
00168 
00171   void SetRadius(const SizeType &);
00172 
00175   void SetRadius(const unsigned long *rad)
00176     {
00177     SizeType s;
00178     memcpy(s.m_Size, rad, sizeof(unsigned long) * VDimension);
00179     this->SetRadius(s);
00180     }
00182 
00186   void SetRadius(const unsigned long);
00187 
00189   void Print(std::ostream& os) const
00190     { this->PrintSelf(os, Indent(0));  }
00191 
00193   AllocatorType &GetBufferReference()
00194     { return m_DataBuffer; }
00195   const AllocatorType &GetBufferReference() const
00196     { return m_DataBuffer; }
00198 
00200   TPixel &operator[](const OffsetType &o)
00201     { return this->operator[](this->GetNeighborhoodIndex(o)); }
00202   const TPixel &operator[](const OffsetType &o) const
00203     { return this->operator[](this->GetNeighborhoodIndex(o)); }
00205 
00208   OffsetType GetOffset(unsigned int i) const
00209     { return m_OffsetTable[i]; }
00210 
00211   virtual unsigned int GetNeighborhoodIndex(const OffsetType &) const;
00212 
00213   unsigned int GetCenterNeighborhoodIndex() const
00214     {
00215     return  static_cast<unsigned int>(this->Size()/2);
00216     }
00217 
00218   std::slice GetSlice(unsigned int) const;
00219 
00220 protected:
00222   void SetSize()
00223     {
00224     for (unsigned int i=0; i<VDimension; ++i)
00225       {
00226       m_Size[i] = m_Radius[i]*2+1;
00227       }
00228     }
00230 
00232   virtual void Allocate(unsigned int i)
00233     { m_DataBuffer.set_size(i); }
00234 
00236   virtual void PrintSelf(std::ostream&, Indent) const;
00237 
00239   virtual void ComputeNeighborhoodStrideTable();
00240 
00243   virtual void ComputeNeighborhoodOffsetTable();
00244 
00245 private:
00248   SizeType m_Radius;
00249 
00252   SizeType m_Size;
00253 
00255   AllocatorType m_DataBuffer;
00256 
00259   unsigned int m_StrideTable[VDimension];
00260 
00262   std::vector<OffsetType> m_OffsetTable;
00263 
00264 };
00265 
00266 template <class TPixel, unsigned int VDimension, class TContainer>
00267 std::ostream & operator<<(std::ostream &os, const Neighborhood<TPixel,VDimension,TContainer> &neighborhood)
00268 {
00269   os << "Neighborhood:" << std::endl;
00270   os << "    Radius:" << neighborhood.GetRadius() << std::endl;
00271   os << "    Size:" << neighborhood.GetSize() << std::endl;
00272   os << "    DataBuffer:" << neighborhood.GetBufferReference() << std::endl;
00273 
00274   return os;
00275 }
00276 
00277 } // namespace itk
00278 
00279 // Define instantiation macro for this template.
00280 #define ITK_TEMPLATE_Neighborhood(_, EXPORT, x, y) namespace itk { \
00281   _(2(class EXPORT Neighborhood< ITK_TEMPLATE_2 x >)) \
00282   namespace Templates { typedef Neighborhood< ITK_TEMPLATE_2 x > \
00283                                                   Neighborhood##y; } \
00284   }
00285 
00286 #if ITK_TEMPLATE_EXPLICIT
00287 # include "Templates/itkNeighborhood+-.h"
00288 #endif
00289 
00290 #if ITK_TEMPLATE_TXX
00291 # include "itkNeighborhood.txx"
00292 #endif
00293 
00294 /*
00295 #ifndef ITK_MANUAL_INSTANTIATION
00296 #include "itkNeighborhood.txx"
00297 #endif
00298 */
00299 
00300 #endif
00301 

Generated at Sat Feb 28 13:07:15 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000