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/09/11 19:57:13 $
00007   Version:   $Revision: 1.33 $
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 
00027 namespace itk {
00028   
00050 template<class TPixel, unsigned int VDimension = 2,
00051          class TAllocator = NeighborhoodAllocator<TPixel> >
00052 class ITK_EXPORT Neighborhood 
00053 {
00054 public:
00056   typedef Neighborhood Self;
00057 
00059   typedef TAllocator AllocatorType;
00060 
00062   itkStaticConstMacro(NeighborhoodDimension, unsigned int, VDimension);
00063   
00065   typedef TPixel PixelType;
00066   
00070   typedef typename AllocatorType::iterator Iterator;
00071   typedef typename AllocatorType::const_iterator ConstIterator;
00072   
00074   typedef Size<VDimension> SizeType;
00075   typedef typename SizeType::SizeValueType SizeValueType;
00076   
00078   typedef Size<VDimension> RadiusType;
00079 
00081   typedef SliceIterator<TPixel, Self> SliceIteratorType;
00082   
00084   Neighborhood() { m_Radius.Fill(0); m_Size.Fill(0);  }
00085 
00087   virtual ~Neighborhood() {}
00088     
00090   Neighborhood(const Self& other)
00091   {
00092     m_Radius     = other.m_Radius;
00093     m_Size       = other.m_Size;
00094     m_DataBuffer = other.m_DataBuffer;
00095   }
00096 
00098   Self &operator=(const Self& other)
00099   {
00100     m_Radius     = other.m_Radius;
00101     m_Size       = other.m_Size;
00102     m_DataBuffer = other.m_DataBuffer;
00103     return *this;
00104   }
00105 
00108   bool
00109   operator==(const Self& other) const
00110   {
00111     return (m_Radius == other.m_Radius &&
00112             m_Size   == other.m_Size &&
00113             m_DataBuffer == other.m_DataBuffer);
00114   }
00115 
00117   bool operator!=(const Self& other) const
00118   {
00119     return (m_Radius != other.m_Radius ||
00120             m_Size   != other.m_Size ||
00121             m_DataBuffer != other.m_DataBuffer);
00122   }
00123 
00125   const SizeType GetRadius() const
00126     { return m_Radius; }
00127 
00130   unsigned long GetRadius(const unsigned long n) const
00131     { return m_Radius[n]; }
00132 
00135   unsigned long GetSize(const unsigned long n) const
00136     { return m_Size[n]; }
00137 
00139   SizeType GetSize() const
00140     { return m_Size; }
00141   
00145   unsigned long GetStride(const unsigned long) const;
00146   
00148   Iterator End()
00149     { return m_DataBuffer.end(); }
00150   Iterator Begin()
00151     { return m_DataBuffer.begin(); }
00152   ConstIterator End() const
00153     { return m_DataBuffer.end(); }
00154   ConstIterator Begin() const
00155     { return m_DataBuffer.begin(); }
00156   
00158   unsigned int Size() const
00159     { return m_DataBuffer.size(); }
00160   
00162   TPixel &operator[](unsigned int i)
00163     { return m_DataBuffer[i]; }
00164   const TPixel &operator[](unsigned int i) const
00165   { return m_DataBuffer[i]; }
00166 
00168   TPixel GetCenterValue() const
00169   {    return (this->operator[]((this->Size())>>1)); }
00170 
00173   void SetRadius(const SizeType &);
00174 
00177   void SetRadius(const unsigned long *rad)
00178   {
00179     SizeType s;
00180     memcpy(s.m_Size, rad, sizeof(unsigned long) * VDimension);
00181     this->SetRadius(s);
00182   }
00183   
00187   void SetRadius(const unsigned long);
00188 
00190   void Print(std::ostream& os) const
00191     { this->PrintSelf(os, Indent(0));  }
00192 
00194   AllocatorType &GetBufferReference()
00195     { return m_DataBuffer; }
00196   const AllocatorType &GetBufferReference() const
00197     { return m_DataBuffer; }
00198   
00199 protected:
00201   void SetSize()
00202   {
00203     for (unsigned int i=0; i<VDimension; ++i)
00204       { m_Size[i] = m_Radius[i]*2+1; }
00205   }
00206 
00208   virtual void Allocate(unsigned int i)
00209     { m_DataBuffer.resize(i); }
00210 
00212   virtual void PrintSelf(std::ostream&, Indent) const;
00213   
00214 private:
00217   SizeType m_Radius;
00218 
00221   SizeType m_Size;
00222 
00224   AllocatorType m_DataBuffer;
00225 };
00226 
00227 template <class TPixel, unsigned int VDimension, class TContainer>
00228 std::ostream & operator<<(std::ostream &os, const Neighborhood<TPixel,VDimension,TContainer> &neighborhood)
00229 {
00230   os << "Neighborhood:" << std::endl;
00231   os << "    Radius:" << neighborhood.GetRadius() << std::endl;
00232   os << "    Size:" << neighborhood.GetSize() << std::endl;
00233   os << "    DataBuffer:" << neighborhood.GetBufferReference() << std::endl;
00234 
00235   return os;
00236 }
00237 
00238 } // namespace itk
00239 
00240 #ifndef ITK_MANUAL_INSTANTIATION
00241 #include "itkNeighborhood.txx"
00242 #endif
00243 
00244 #endif

Generated at Wed Mar 12 01:13:08 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000