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: 2002/12/10 18:27:15 $
00007   Version:   $Revision: 1.36 $
00008 
00009   Copyright (c) 2002 Insight 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 Size<VDimension> SizeType;
00077   typedef typename SizeType::SizeValueType SizeValueType;
00078   
00080   typedef 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(); }
00150   
00152   unsigned int Size() const
00153     { return m_DataBuffer.size(); }
00154   
00156   TPixel &operator[](unsigned int i)
00157     { return m_DataBuffer[i]; }
00158   const TPixel &operator[](unsigned int i) const
00159   { return m_DataBuffer[i]; }
00160 
00162   TPixel GetCenterValue() const
00163   {    return (this->operator[]((this->Size())>>1)); }
00164 
00167   void SetRadius(const SizeType &);
00168 
00171   void SetRadius(const unsigned long *rad)
00172   {
00173     SizeType s;
00174     memcpy(s.m_Size, rad, sizeof(unsigned long) * VDimension);
00175     this->SetRadius(s);
00176   }
00177   
00181   void SetRadius(const unsigned long);
00182 
00184   void Print(std::ostream& os) const
00185     { this->PrintSelf(os, Indent(0));  }
00186 
00188   AllocatorType &GetBufferReference()
00189     { return m_DataBuffer; }
00190   const AllocatorType &GetBufferReference() const
00191     { return m_DataBuffer; }
00192 
00194   TPixel &operator[](const OffsetType &o)
00195   {    return this->operator[](this->GetNeighborhoodIndex(o)); }
00196   const TPixel &operator[](const OffsetType &o) const
00197   { return this->operator[](this->GetNeighborhoodIndex(o)); }
00198 
00201   virtual OffsetType GetOffset(unsigned int i) const
00202   {    return m_OffsetTable[i];  }
00203 
00204   virtual unsigned int GetNeighborhoodIndex(const OffsetType &) const;
00205 
00206   unsigned int GetCenterNeighborhoodIndex() const
00207   { return  static_cast<unsigned int>(this->Size()/2); }
00208     
00209   std::slice GetSlice(unsigned int) const;
00210   
00211 protected:
00213   void SetSize()
00214   {
00215     for (unsigned int i=0; i<VDimension; ++i)
00216       { m_Size[i] = m_Radius[i]*2+1; }
00217   }
00218 
00220   virtual void Allocate(unsigned int i)
00221     { m_DataBuffer.resize(i); }
00222 
00224   virtual void PrintSelf(std::ostream&, Indent) const;
00225 
00227   virtual void ComputeNeighborhoodStrideTable();
00228 
00231   virtual void ComputeNeighborhoodOffsetTable();
00232 
00233 private:
00236   SizeType m_Radius;
00237 
00240   SizeType m_Size;
00241 
00243   AllocatorType m_DataBuffer;
00244 
00247   unsigned int m_StrideTable[VDimension];
00248 
00250   std::vector<OffsetType> m_OffsetTable;
00251 
00252 };
00253 
00254 template <class TPixel, unsigned int VDimension, class TContainer>
00255 std::ostream & operator<<(std::ostream &os, const Neighborhood<TPixel,VDimension,TContainer> &neighborhood)
00256 {
00257   os << "Neighborhood:" << std::endl;
00258   os << "    Radius:" << neighborhood.GetRadius() << std::endl;
00259   os << "    Size:" << neighborhood.GetSize() << std::endl;
00260   os << "    DataBuffer:" << neighborhood.GetBufferReference() << std::endl;
00261 
00262   return os;
00263 }
00264 
00265 } // namespace itk
00266 
00267 #ifndef ITK_MANUAL_INSTANTIATION
00268 #include "itkNeighborhood.txx"
00269 #endif
00270 
00271 #endif

Generated at Wed Mar 12 11:28:59 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000