ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkChainCodePath.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkChainCodePath_h
00019 #define __itkChainCodePath_h
00020 
00021 #include "itkPath.h"
00022 #include "itkOffset.h"
00023 #include "itkObjectFactory.h"
00024 
00025 #include <vector>
00026 
00027 namespace itk
00028 {
00048 template< unsigned int VDimension >
00049 class ITK_EXPORT ChainCodePath:public
00050   Path< unsigned int, Offset< VDimension >, VDimension >
00051 {
00052 public:
00054   itkStaticConstMacro(Dimension, unsigned int, VDimension);
00055 
00057   typedef ChainCodePath< VDimension >                            Self;
00058   typedef Path< unsigned int, Offset< VDimension >, VDimension > Superclass;
00059 
00060   typedef SmartPointer< Self >       Pointer;
00061   typedef SmartPointer< const Self > ConstPointer;
00062 
00064   itkTypeMacro(ChainCodePath, Path);
00065 
00067   typedef typename Superclass::OutputType OutputType;
00068   typedef typename Superclass::InputType  InputType;
00069 
00071   typedef OutputType          OffsetType;
00072   typedef Index< VDimension > IndexType;
00073 
00074   typedef std::vector< OffsetType > ChainCodeType;
00075 
00076   typedef typename ChainCodeType::size_type ChainCodeSizeType;
00077 
00078   // Functions inherited from Path
00079 
00081   virtual OutputType Evaluate(const InputType & input) const
00082   {
00083     return m_Chain[input];
00084   }
00085 
00087   virtual IndexType EvaluateToIndex(const InputType & input) const;
00088 
00093   virtual OffsetType IncrementInput(InputType & input) const;
00094 
00096   virtual inline InputType EndOfInput() const
00097   {
00098     return NumberOfSteps();  // 0 is before the first step, 1 is after it
00099   }
00100 
00102   itkNewMacro(Self);
00103 
00105   itkSetMacro(Start, IndexType);
00106   itkGetConstReferenceMacro(Start, IndexType);
00108 
00110   virtual inline void InsertStep(InputType position, OffsetType step)
00111   {
00112     m_Chain.insert(m_Chain.begin() + position, step);
00113     this->Modified();
00114   }
00116 
00118   virtual inline void ChangeStep(InputType position, OffsetType step)
00119   {
00120     m_Chain[position] = step;
00121     this->Modified();
00122   }
00124 
00126   virtual inline void Clear()
00127   {
00128     m_Chain.clear();
00129     this->Modified();
00130   }
00132 
00134   virtual inline ChainCodeSizeType NumberOfSteps() const
00135   {
00136     return m_Chain.size();
00137   }
00138 
00140   virtual void Initialize(void)
00141   {
00142     m_Start = this->GetZeroIndex();
00143     this->Clear();
00144   }
00146 
00147 protected:
00148   ChainCodePath();
00149   ~ChainCodePath() {}
00150   void PrintSelf(std::ostream & os, Indent indent) const;
00151 
00152 private:
00153   ChainCodePath(const Self &);  //purposely not implemented
00154   void operator=(const Self &); //purposely not implemented
00155 
00156   IndexType     m_Start;            // origin image index for the path
00157   ChainCodeType m_Chain;            // the chain code (vector of offsets)
00158 };
00159 } // end namespace itk
00160 
00161 // Define instantiation macro for this template.
00162 #define ITK_TEMPLATE_ChainCodePath(_, EXPORT, TypeX, TypeY)     \
00163   namespace itk                                                 \
00164   {                                                             \
00165   _( 1 ( class EXPORT ChainCodePath< ITK_TEMPLATE_1 TypeX > ) ) \
00166   namespace Templates                                           \
00167   {                                                             \
00168   typedef ChainCodePath< ITK_TEMPLATE_1 TypeX >                 \
00169   ChainCodePath##TypeY;                                       \
00170   }                                                             \
00171   }
00172 
00173 #if ITK_TEMPLATE_EXPLICIT
00174 #include "Templates/itkChainCodePath+-.h"
00175 #endif
00176 
00177 #if ITK_TEMPLATE_TXX
00178 #include "itkChainCodePath.hxx"
00179 #endif
00180 
00181 #endif
00182