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

itkChainCodePath2D.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkChainCodePath2D.h,v $
00005   Language:  C++
00006   Date:      $Date: 2006/03/18 20:14:09 $
00007   Version:   $Revision: 1.8 $
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 __itkChainCodePath2D_h
00018 #define __itkChainCodePath2D_h
00019 
00020 #include "itkChainCodePath.h"
00021 #include "itkObjectFactory.h"
00022 #include "itkIndex.h"
00023 #include "itkOffset.h"
00024 
00025 #include <vector>
00026 #include <string>
00027 
00028 
00029 namespace itk
00030 {
00031 
00032 
00053 class ITKCommon_EXPORT ChainCodePath2D : public
00054 ChainCodePath<2>
00055 {
00056 public:
00058   itkStaticConstMacro(Dimension, unsigned int, 2);
00059 
00061   typedef ChainCodePath2D   Self;
00062   typedef ChainCodePath<2>  Superclass;
00063 
00064   typedef SmartPointer<Self>        Pointer;
00065   typedef SmartPointer<const Self>  ConstPointer;
00066   
00068   itkTypeMacro(ChainCodePath2D, ChainCodePath);
00069 
00071   typedef Superclass::OutputType   OutputType;
00072   typedef Superclass::InputType    InputType;
00073 
00075   typedef OutputType  OffsetType;
00076   typedef Index<2>    IndexType;
00077 
00079   typedef std::vector<OffsetType>  ChainCodeType;
00080 
00082   typedef std::vector<int>         ChainCode2DType;
00083 
00084   // Functions inherited from Path
00085   
00087   virtual OutputType Evaluate( const InputType & input ) const;
00088 
00090   virtual IndexType EvaluateToIndex( const InputType & input ) const;
00091 
00096   virtual OffsetType IncrementInput(InputType & input) const;
00097 
00098   // Functions specific to ChainCodePath and its descendents
00099 
00101   itkNewMacro( Self );
00102 
00104   inline unsigned int NumberOfSteps() const { return m_Chain2D.size(); }
00105 
00106   
00108   inline void InsertStep( InputType position, int encodedStep )
00109     {
00110     m_Chain2D.insert( m_Chain2D.begin()+position, encodedStep );
00111     this->Modified();
00112     }
00113   inline void InsertStep( InputType position, OffsetType step )
00114     {
00115     m_Chain2D.insert( m_Chain2D.begin()+position, EncodeOffset(step) );
00116     this->Modified();
00117     }
00119 
00121   inline void ChangeStep( InputType position, int encodedStep )
00122     {
00123     m_Chain2D[position]=encodedStep;
00124     this->Modified();
00125     }
00126   inline void ChangeStep( InputType position, OffsetType step )
00127     {
00128     m_Chain2D[position]=EncodeOffset(step);
00129     this->Modified();
00130     }
00132 
00134   virtual inline void Clear()
00135     {
00136     m_Chain2D.clear();
00137     this->Modified();
00138     }
00140 
00141   std::string GetChainCodeAsString(void) const;
00142 
00143 protected:
00144   ChainCodePath2D();
00145   ~ChainCodePath2D();
00146   void PrintSelf(std::ostream& os, Indent indent) const;
00147 
00149   inline int EncodeOffset( OffsetType  step ) const
00150     {
00151     return m_FreemanCode[  step[0] + 1  ][  step[1] + 1  ];
00152     }
00153   inline OffsetType DecodeOffset( int encodedStep ) const
00154     {
00155     return m_ReverseFreemanCode[ encodedStep ];
00156     }
00158 
00159 
00160 private:
00161   ChainCodePath2D(const Self&); //purposely not implemented
00162   void operator=(const Self&);  //purposely not implemented
00163   
00164   ChainCode2DType  m_Chain2D;   // the Freeman-encoded chain code
00165   
00166   // FreemanCode[][] implements a lookup table for converting offsets to a
00167   // Freeman code.  Within each dimension, the only allowable offset values are
00168   // { -1, 0, 1 }.  The y-axis is assumed to point up.  It is initialized in the
00169   // constructor.  Use it as follows:
00170   //
00171   //   encodedValue = m_FreemanCode[ x offset + 1 ][ y offset + 1 ]
00172   //
00173   int m_FreemanCode[3][3];
00174 
00175   // m_ReverseFreemanCode[ encodedValue ] implements a lookup table for the
00176   // inverse of m_FreemanCode[][].  It is initialized in the constructor.
00177   OffsetType m_ReverseFreemanCode[9];
00178 };
00179 
00180 } // end namespace itk
00181 
00182 #endif
00183 

Generated at Sun Sep 23 12:09:48 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000