ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkLabelContourImageFilter.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 __itkLabelContourImageFilter_h
00019 #define __itkLabelContourImageFilter_h
00020 
00021 #include "itkInPlaceImageFilter.h"
00022 #include "itkImage.h"
00023 #include "itkConceptChecking.h"
00024 #include <vector>
00025 #include "itkBarrier.h"
00026 
00027 namespace itk
00028 {
00055 template< class TInputImage, class TOutputImage >
00056 class ITK_EXPORT LabelContourImageFilter:
00057   public InPlaceImageFilter< TInputImage, TOutputImage >
00058 {
00059 public:
00063   typedef LabelContourImageFilter                         Self;
00064   typedef InPlaceImageFilter< TInputImage, TOutputImage > Superclass;
00065   typedef SmartPointer< Self >                            Pointer;
00066   typedef SmartPointer< const Self >                      ConstPointer;
00067 
00071   itkNewMacro(Self);
00072 
00076   itkTypeMacro(LabelContourImageFilter, InPlaceImageFilter);
00077 
00078   itkStaticConstMacro(ImageDimension, unsigned int,
00079                       TOutputImage::ImageDimension);
00080 
00081 #ifdef ITK_USE_CONCEPT_CHECKING
00082 
00083   itkStaticConstMacro(InputImageDimension, unsigned int,
00084                       TInputImage::ImageDimension);
00085 
00086   itkStaticConstMacro(OutputImageDimension, unsigned int,
00087                       TOutputImage::ImageDimension);
00088 
00089   itkConceptMacro( SameDimension,
00090     ( Concept::SameDimension< itkGetStaticConstMacro(InputImageDimension),
00091                               itkGetStaticConstMacro(OutputImageDimension) > ) );
00092 
00093 #endif
00094 
00098   typedef TInputImage                                 InputImageType;
00099   typedef typename InputImageType::Pointer            InputImagePointer;
00100   typedef typename InputImageType::IndexType          InputIndexType;
00101   typedef typename InputImageType::SizeType           InputSizeType;
00102   typedef typename InputImageType::OffsetType         InputOffsetType;
00103   typedef typename InputImageType::PixelType          InputImagePixelType;
00104   typedef typename InputImageType::SizeValueType      SizeValueType;
00105   typedef typename InputImageType::OffsetValueType    OffsetValueType;
00106   typedef typename InputImageType::PixelType          InputPixelType;
00107 
00108   typedef TOutputImage                          OutputImageType;
00109   typedef typename OutputImageType::Pointer     OutputImagePointer;
00110   typedef typename OutputImageType::RegionType  OutputRegionType;
00111   typedef typename OutputImageType::IndexType   OutputIndexType;
00112   typedef typename OutputImageType::SizeType    OutputSizeType;
00113   typedef typename OutputImageType::OffsetType  OutputOffsetType;
00114   typedef typename OutputImageType::PixelType   OutputImagePixelType;
00115 
00122   itkSetMacro(FullyConnected, bool);
00123   itkGetConstReferenceMacro(FullyConnected, bool);
00124   itkBooleanMacro(FullyConnected);
00126 
00131   itkSetMacro(BackgroundValue, OutputImagePixelType);
00132   itkGetConstMacro(BackgroundValue, OutputImagePixelType);
00134 
00135 protected:
00136 
00137   LabelContourImageFilter();
00138   virtual ~LabelContourImageFilter() {}
00139 
00140   void PrintSelf(std::ostream & os, Indent indent) const;
00141 
00145   void BeforeThreadedGenerateData();
00146 
00147   void AfterThreadedGenerateData();
00148 
00149   void ThreadedGenerateData(const OutputRegionType & outputRegionForThread,
00150                             ThreadIdType threadId);
00151 
00155   void GenerateInputRequestedRegion();
00156 
00161   void EnlargeOutputRequestedRegion( DataObject * itkNotUsed(output) );
00162 
00163 private:
00164 
00165   LabelContourImageFilter(const Self &);
00166   void operator = ( const Self& );
00167 
00169   struct RunLength
00170   {
00171 
00173     SizeValueType length;
00174 
00176     InputIndexType where;
00177 
00178     InputImagePixelType label;
00179   };
00180 
00181   typedef std::vector< RunLength >                  LineEncodingType;
00182   typedef typename LineEncodingType::iterator       LineEncodingIterator;
00183   typedef typename LineEncodingType::const_iterator LineEncodingConstIterator;
00184 
00185   typedef std::vector< OffsetValueType >            OffsetVectorType;
00186   typedef typename OffsetVectorType::const_iterator OffsetVectorConstIterator;
00187 
00188   // the map storing lines
00189   typedef std::vector< LineEncodingType > LineMapType;
00190 
00191   LineMapType           m_LineMap;
00192   OutputImagePixelType  m_BackgroundValue;
00193   ThreadIdType          m_NumberOfThreads;
00194   bool                  m_FullyConnected;
00195 
00196   bool CheckNeighbors(const OutputIndexType & A,
00197                       const OutputIndexType & B) const;
00198 
00199   void CompareLines(LineEncodingType & current, const LineEncodingType & Neighbour);
00200 
00201   void SetupLineOffsets(OffsetVectorType & LineOffsets);
00202 
00203   void Wait();
00204 
00205   typename Barrier::Pointer m_Barrier;
00206 
00207 };
00208 } // end namespace itk
00209 
00210 #ifndef ITK_MANUAL_INSTANTIATION
00211 #include "itkLabelContourImageFilter.hxx"
00212 #endif
00213 
00214 #endif
00215