ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkAnchorErodeDilateLine.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 __itkAnchorErodeDilateLine_h
00019 #define __itkAnchorErodeDilateLine_h
00020 
00021 #include "itkMovingHistogramMorphologyImageFilter.h"
00022 
00023 namespace itk
00024 {
00036 template< class TInputPix, class TCompare >
00037 class ITK_EXPORT AnchorErodeDilateLine
00038 {
00039 public:
00040 
00042   typedef TInputPix InputImagePixelType;
00043 
00044   void DoLine(std::vector<TInputPix> & buffer, std::vector<TInputPix> & inbuffer,
00045               unsigned bufflength);
00046 
00047   void SetSize(unsigned int size)
00048   {
00049     m_Size = size;
00050   }
00051 
00052   void PrintSelf(std::ostream & os, Indent indent) const;
00053 
00054   AnchorErodeDilateLine();
00055   ~AnchorErodeDilateLine()
00056   {
00057   }
00058 
00059 private:
00060   unsigned int m_Size;
00061 
00062   typedef Function::MorphologyHistogram< InputImagePixelType, TCompare >              HistogramType;
00063 
00064   bool StartLine(std::vector<TInputPix> & buffer,
00065                  std::vector<TInputPix> & inbuffer,
00066                  InputImagePixelType & Extreme,
00067                  int & outLeftP,
00068                  int & outRightP,
00069                  int & inLeftP,
00070                  int & inRightP,
00071                  int middle);
00072 
00073   void FinishLine(std::vector<TInputPix> & buffer,
00074                   std::vector<TInputPix> & inbuffer,
00075                   InputImagePixelType & Extreme,
00076                   int & outLeftP,
00077                   int & outRightP,
00078                   int & inLeftP,
00079                   int & inRightP,
00080                   int middle);
00081 
00082   bool UseVectorBasedHistogram()
00083   {
00084     // bool, short and char are acceptable for vector based algorithm: they do
00085     // not require
00086     // too much memory. Other types are not usable with that algorithm
00087     return typeid( InputImagePixelType ) == typeid( unsigned char )
00088            || typeid( InputImagePixelType ) == typeid( signed char )
00089            || typeid( InputImagePixelType ) == typeid( unsigned short )
00090            || typeid( InputImagePixelType ) == typeid( signed short )
00091            || typeid( InputImagePixelType ) == typeid( bool );
00092   }
00093 
00094   inline bool StrictCompare( const InputImagePixelType & a, const InputImagePixelType & b )
00095     {
00096     TCompare compare;
00097     return compare( a, b );
00098     }
00099 
00100   inline bool Compare( const InputImagePixelType & a, const InputImagePixelType & b )
00101     {
00102     TCompare compare;
00103     return compare( a, b ) || a == b;
00104     }
00105 
00106 }; // end of class
00107 } // end namespace itk
00108 
00109 #ifndef ITK_MANUAL_INSTANTIATION
00110 #include "itkAnchorErodeDilateLine.hxx"
00111 #endif
00112 
00113 #endif
00114