ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkBinaryContourImageFilter.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 __itkBinaryContourImageFilter_h
00019 #define __itkBinaryContourImageFilter_h
00020 
00021 #include "itkInPlaceImageFilter.h"
00022 #include "itkConceptChecking.h"
00023 #include "itkBarrier.h"
00024 #include <vector>
00025 
00026 namespace itk
00027 {
00053 template< class TInputImage, class TOutputImage >
00054 class ITK_EXPORT BinaryContourImageFilter:
00055   public InPlaceImageFilter< TInputImage, TOutputImage >
00056 {
00057 public:
00061   typedef BinaryContourImageFilter                        Self;
00062   typedef InPlaceImageFilter< TInputImage, TOutputImage > Superclass;
00063   typedef SmartPointer< Self >                            Pointer;
00064   typedef SmartPointer< const Self >                      ConstPointer;
00065 
00069   itkTypeMacro(BinaryContourImageFilter, ImageToImageFilter);
00070 
00074   itkNewMacro(Self);
00075 
00079   typedef TInputImage                                 InputImageType;
00080   typedef typename InputImageType::Pointer            InputImagePointer;
00081   typedef typename InputImageType::ConstPointer       InputImageConstPointer;
00082   typedef typename InputImageType::IndexType          IndexType;
00083   typedef typename InputImageType::SizeType           SizeType;
00084   typedef typename InputImageType::OffsetType         OffsetType;
00085   typedef typename InputImageType::PixelType          InputImagePixelType;
00086   typedef typename InputImageType::InternalPixelType  InputInternalPixelType;
00087 
00088   typedef TOutputImage                                OutputImageType;
00089   typedef typename OutputImageType::Pointer           OutputImagePointer;
00090   typedef typename OutputImageType::RegionType        RegionType;
00091   typedef typename OutputImageType::IndexType         OutputIndexType;
00092   typedef typename OutputImageType::SizeType          OutputSizeType;
00093   typedef typename OutputImageType::OffsetType        OutputOffsetType;
00094   typedef typename OutputImageType::PixelType         OutputImagePixelType;
00095   typedef typename OutputImageType::InternalPixelType OutputInternalPixelType;
00096 
00097   itkStaticConstMacro(ImageDimension, unsigned int,
00098                       OutputImageType::ImageDimension);
00099 
00100 #ifdef ITK_USE_CONCEPT_CHECKING
00101   itkStaticConstMacro(InputImageDimension, unsigned int,
00102                       InputImageType::ImageDimension);
00103 
00104   // Concept checking -- input and output dimensions must be the same
00105   itkConceptMacro( SameDimension,
00106                    ( Concept::SameDimension< itkGetStaticConstMacro(ImageDimension),
00107                                              itkGetStaticConstMacro(OutputImageDimension) > ) );
00108 #endif
00109 
00116   itkSetMacro(FullyConnected, bool);
00117   itkGetConstReferenceMacro(FullyConnected, bool);
00118   itkBooleanMacro(FullyConnected);
00120 
00125   itkSetMacro(BackgroundValue, OutputImagePixelType);
00126   itkGetConstMacro(BackgroundValue, OutputImagePixelType);
00128 
00133   itkSetMacro(ForegroundValue, InputImagePixelType);
00134   itkGetConstMacro(ForegroundValue, InputImagePixelType);
00136 
00137 protected:
00138 
00139   BinaryContourImageFilter();
00140   virtual ~BinaryContourImageFilter() {}
00141 
00142   void PrintSelf(std::ostream & os, Indent indent) const;
00143 
00147   void BeforeThreadedGenerateData();
00148 
00149   void AfterThreadedGenerateData();
00150 
00151   void ThreadedGenerateData(const RegionType & outputRegionForThread,
00152                             ThreadIdType threadId);
00153 
00157   void GenerateInputRequestedRegion();
00158 
00163   void EnlargeOutputRequestedRegion( DataObject * itkNotUsed(output) );
00164 
00165 private:
00166   BinaryContourImageFilter(const Self &); //Purposefully not implemented
00167   void operator = ( const Self &);        //Purposefully not implemented
00168 
00169   // types to support the run length encoding of lines
00170   struct runLength
00171   {
00172     runLength( const OffsetValueType& iLength, const IndexType& iWhere ) :
00173       m_Length( iLength ), m_Where( iWhere ) {}
00174 
00175     // run length information - may be a more type safe way of doing this
00176     OffsetValueType m_Length;
00177 
00178     // Index of the start of the run
00179     IndexType       m_Where;
00180   };
00181 
00182   typedef std::vector< runLength >                  LineEncodingType;
00183   typedef typename LineEncodingType::iterator       LineEncodingIterator;
00184   typedef typename LineEncodingType::const_iterator LineEncodingConstIterator;
00185 
00186   // the map storing lines
00187   typedef std::vector< LineEncodingType > LineMapType;
00188 
00189   typedef std::vector< OffsetValueType > OffsetVec;
00190 
00191   bool CheckNeighbors(const OutputIndexType & A,
00192                       const OutputIndexType & B);
00193 
00194   void CompareLines(LineEncodingType & current,
00195                     const LineEncodingType & Neighbour);
00196 
00197   void SetupLineOffsets(OffsetVec & LineOffsets);
00198 
00199   void Wait();
00200 
00201   Barrier::Pointer m_Barrier;
00202 
00203   LineMapType   m_ForegroundLineMap;
00204   LineMapType   m_BackgroundLineMap;
00205   ThreadIdType  m_NumberOfThreads;
00206 
00207   InputImagePixelType  m_ForegroundValue;
00208   OutputImagePixelType m_BackgroundValue;
00209   bool                 m_FullyConnected;
00210 };
00211 } // end namespace itk
00212 
00213 #ifndef ITK_MANUAL_INSTANTIATION
00214 #include "itkBinaryContourImageFilter.hxx"
00215 #endif
00216 
00217 #endif
00218