00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkWatershedImageFilter_h
00018 #define __itkWatershedImageFilter_h
00019
00020 #if defined(_MSC_VER)
00021 #pragma warning ( disable : 4786 )
00022 #endif
00023
00024 #include "itkImageToImageFilter.h"
00025 #include "itkImage.h"
00026 #include "itkWatershedSegmenter.h"
00027 #include "itkWatershedSegmentTreeGenerator.h"
00028 #include "itkWatershedRelabeler.h"
00029 #include "itkWatershedMiniPipelineProgressCommand.h"
00030
00031 namespace itk
00032 {
00151 template <class TInputImage>
00152 class ITK_EXPORT WatershedImageFilter :
00153 public ImageToImageFilter< TInputImage, Image<unsigned long,
00154 ::itk::GetImageDimension<TInputImage>::ImageDimension> >
00155 {
00156 public:
00158 typedef WatershedImageFilter Self;
00159
00161 typedef TInputImage InputImageType;
00162
00164 itkStaticConstMacro (ImageDimension, unsigned int,
00165 TInputImage::ImageDimension);
00166
00168 typedef Image<unsigned long, itkGetStaticConstMacro(ImageDimension)> OutputImageType;
00169
00171 typedef typename InputImageType::RegionType RegionType;
00172 typedef typename InputImageType::SizeType SizeType;
00173 typedef typename InputImageType::IndexType IndexType;
00174
00176 typedef ImageToImageFilter< InputImageType, OutputImageType > Superclass;
00177
00179 typedef typename InputImageType::PixelType ScalarType;
00180
00182 typedef SmartPointer<Self> Pointer;
00183
00185 itkTypeMacro(WatershedImageFilter, ImageToImageFilter);
00186
00188 itkNewMacro(Self);
00189
00191 void GenerateData();
00192
00195 void SetInput(const InputImageType *input)
00196 {
00197
00198
00199 if (input != this->GetInput(0))
00200 {
00201 m_InputChanged = true;
00202 }
00203
00204
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 }
00218 void SetThreshold(double);
00219 itkGetMacro(Threshold, double);
00221
00224 void SetLevel(double);
00225 itkGetMacro(Level, double);
00227
00229 typename watershed::Segmenter<InputImageType>::OutputImageType *
00230 GetBasicSegmentation()
00231 {
00232 m_Segmenter->Update();
00233 return m_Segmenter->GetOutputImage();
00234 }
00236
00238 typename watershed::SegmentTreeGenerator<ScalarType>::SegmentTreeType *
00239 GetSegmentTree()
00240 {
00241 return m_TreeGenerator->GetOutputSegmentTree();
00242 }
00243
00244
00245 void EnlargeOutputRequestedRegion(DataObject *data);
00246
00247 #ifdef ITK_USE_CONCEPT_CHECKING
00248
00249 itkConceptMacro(InputEqualityComparableCheck,
00250 (Concept::EqualityComparable<ScalarType>));
00251 itkConceptMacro(InputAdditiveOperatorsCheck,
00252 (Concept::AdditiveOperators<ScalarType>));
00253 itkConceptMacro(DoubleInputMultiplyOperatorCheck,
00254 (Concept::MultiplyOperator<double, ScalarType, ScalarType>));
00255 itkConceptMacro(InputLessThanComparableCheck,
00256 (Concept::LessThanComparable<ScalarType>));
00257
00259 #endif
00260
00261 protected:
00262 WatershedImageFilter();
00263 virtual ~WatershedImageFilter() {}
00264 WatershedImageFilter(const Self&) {}
00265 void operator=(const Self&) {}
00266 void PrintSelf(std::ostream& os, Indent indent) const;
00267
00270 virtual void PrepareOutputs();
00271
00272 private:
00276 double m_Threshold;
00277
00281 double m_Level;
00282
00287 typename watershed::Segmenter<InputImageType>::Pointer m_Segmenter;
00288 typename watershed::SegmentTreeGenerator<ScalarType>::Pointer m_TreeGenerator;
00289 typename watershed::Relabeler<ScalarType, itkGetStaticConstMacro(ImageDimension)>::Pointer m_Relabeler;
00291
00292 unsigned long m_ObserverTag;
00293
00294 bool m_LevelChanged;
00295 bool m_ThresholdChanged;
00296 bool m_InputChanged;
00297 TimeStamp m_GenerateDataMTime;
00298 };
00299
00300 }
00301
00302 #ifndef ITK_MANUAL_INSTANTIATION
00303 #include "itkWatershedImageFilter.txx"
00304 #endif
00305
00306 #endif
00307