ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkWatershedImageFilter.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 __itkWatershedImageFilter_h
00019 #define __itkWatershedImageFilter_h
00020 
00021 
00022 #include "itkImageToImageFilter.h"
00023 #include "itkWatershedSegmentTreeGenerator.h"
00024 #include "itkWatershedRelabeler.h"
00025 #include "itkWatershedMiniPipelineProgressCommand.h"
00026 
00027 namespace itk
00028 {
00149 template< class TInputImage >
00150 class ITK_EXPORT WatershedImageFilter:
00151   public ImageToImageFilter< TInputImage, Image< IdentifierType,
00152                                                  ::itk::GetImageDimension< TInputImage >::ImageDimension > >
00153 {
00154 public:
00156   typedef WatershedImageFilter Self;
00157 
00159   typedef TInputImage InputImageType;
00160 
00162   itkStaticConstMacro (ImageDimension, unsigned int,
00163                        TInputImage::ImageDimension);
00164 
00166   typedef Image< IdentifierType, itkGetStaticConstMacro(ImageDimension) > OutputImageType;
00167 
00169   typedef typename InputImageType::RegionType RegionType;
00170   typedef typename InputImageType::SizeType   SizeType;
00171   typedef typename InputImageType::IndexType  IndexType;
00172 
00174   typedef ImageToImageFilter< InputImageType, OutputImageType > Superclass;
00175 
00177   typedef typename InputImageType::PixelType ScalarType;
00178 
00180   typedef SmartPointer< Self > Pointer;
00181 
00183   itkTypeMacro(WatershedImageFilter, ImageToImageFilter);
00184 
00186   itkNewMacro(Self);
00187 
00189   void GenerateData();
00190 
00193   using Superclass::SetInput;
00194   void SetInput(const InputImageType *input)
00195   {
00196     // if the input is changed, we'll need to clear the cached tree
00197     // when we execute
00198     if ( input != this->GetInput(0) )
00199       {
00200       m_InputChanged = true;
00201       }
00203 
00204     // processObject is not const-correct so a const_cast is needed here
00205     this->ProcessObject::SetNthInput( 0, const_cast< InputImageType * >( input ) );
00206     m_Segmenter->SetInputImage( const_cast< InputImageType * >( input ) );
00207   }
00208 
00209   virtual void SetInput(unsigned int i, const TInputImage *image)
00210   {
00211     if ( i != 0 )
00212                   { itkExceptionMacro(<< "Filter has only one input."); }
00213     else
00214                   { this->SetInput(image); }
00215   }
00216 
00219   void SetThreshold(double);
00220 
00221   itkGetConstMacro(Threshold, double);
00222 
00225   void SetLevel(double);
00226 
00227   itkGetConstMacro(Level, double);
00228 
00230   typename watershed::Segmenter< InputImageType >::OutputImageType *
00231   GetBasicSegmentation()
00232   {
00233     m_Segmenter->Update();
00234     return m_Segmenter->GetOutputImage();
00235   }
00237 
00239   typename watershed::SegmentTreeGenerator< ScalarType >::SegmentTreeType *
00240   GetSegmentTree()
00241   {
00242     return m_TreeGenerator->GetOutputSegmentTree();
00243   }
00244 
00245   // Override since the filter produces all of its output
00246   void EnlargeOutputRequestedRegion(DataObject *data);
00247 
00248 #ifdef ITK_USE_CONCEPT_CHECKING
00249 
00250   itkConceptMacro( InputEqualityComparableCheck,
00251                    ( Concept::EqualityComparable< ScalarType > ) );
00252   itkConceptMacro( InputAdditiveOperatorsCheck,
00253                    ( Concept::AdditiveOperators< ScalarType > ) );
00254   itkConceptMacro( DoubleInputMultiplyOperatorCheck,
00255                    ( Concept::MultiplyOperator< double, ScalarType, ScalarType > ) );
00256   itkConceptMacro( InputLessThanComparableCheck,
00257                    ( Concept::LessThanComparable< ScalarType > ) );
00258 
00260 #endif
00261 protected:
00262   WatershedImageFilter();
00263   virtual ~WatershedImageFilter() {}
00264   void PrintSelf(std::ostream & os, Indent indent) const;
00266 
00269   virtual void PrepareOutputs();
00270 
00271 private:
00272   WatershedImageFilter(const Self &);  //purposely not implemented
00273   void operator=(const Self &); //purposely not implemented
00274 
00278   double m_Threshold;
00279 
00284   double m_Level;
00285 
00290   typename watershed::Segmenter< InputImageType >::Pointer m_Segmenter;
00291 
00292   typename watershed::SegmentTreeGenerator< ScalarType >::Pointer m_TreeGenerator;
00293 
00294   typename watershed::Relabeler< ScalarType, itkGetStaticConstMacro(ImageDimension) >::Pointer m_Relabeler;
00295 
00296   unsigned long m_ObserverTag;
00297 
00298   bool m_LevelChanged;
00299   bool m_ThresholdChanged;
00300   bool m_InputChanged;
00301 
00302   TimeStamp m_GenerateDataMTime;
00303 };
00304 } // end namespace itk
00305 
00306 #ifndef ITK_MANUAL_INSTANTIATION
00307 #include "itkWatershedImageFilter.hxx"
00308 #endif
00309 
00310 #endif
00311