ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkSegmentationLevelSetImageFilter.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 __itkSegmentationLevelSetImageFilter_h
00019 #define __itkSegmentationLevelSetImageFilter_h
00020 
00021 #include "itkSparseFieldLevelSetImageFilter.h"
00022 #include "itkSegmentationLevelSetFunction.h"
00023 
00024 namespace itk
00025 {
00142 template< class TInputImage,
00143           class TFeatureImage,
00144           class TOutputPixelType = float >
00145 class ITK_EXPORT SegmentationLevelSetImageFilter:
00146   public SparseFieldLevelSetImageFilter< TInputImage, Image< TOutputPixelType,
00147                                                              ::itk::GetImageDimension< TInputImage >::ImageDimension > >
00148 {
00149 public:
00150 
00152   typedef SegmentationLevelSetImageFilter Self;
00153 
00154   //itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
00155 
00157   typedef Image< TOutputPixelType, itkGetStaticConstMacro(InputImageDimension) > OutputImageType;
00158 
00160   typedef SparseFieldLevelSetImageFilter< TInputImage, OutputImageType > Superclass;
00161   typedef SmartPointer< Self >                                           Pointer;
00162   typedef SmartPointer< const Self >                                     ConstPointer;
00163 
00165   typedef typename Superclass::ValueType      ValueType;
00166   typedef typename Superclass::IndexType      IndexType;
00167   typedef typename Superclass::TimeStepType   TimeStepType;
00168   typedef typename Superclass::InputImageType InputImageType;
00169 
00171   typedef TFeatureImage FeatureImageType;
00172 
00174   typedef SegmentationLevelSetFunction< OutputImageType, FeatureImageType >
00175   SegmentationFunctionType;
00176 
00178   typedef typename SegmentationFunctionType::VectorImageType VectorImageType;
00179   typedef typename SegmentationFunctionType::ImageType       SpeedImageType;
00180 
00182   itkTypeMacro(SegmentationLevelSetImageFilter, SparseFieldLevelSetImageFilter);
00183 
00186   void SetMaximumIterations(unsigned int i)
00187   {
00188     itkWarningMacro("SetMaximumIterations is deprecated.  Please use SetNumberOfIterations instead.");
00189     this->SetNumberOfIterations(i);
00190   }
00192 
00193   unsigned int GetMaximumIterations()
00194   {
00195     itkWarningMacro("GetMaximumIterations is deprecated. Please use GetNumberOfIterations instead.");
00196     return this->GetNumberOfIterations();
00197   }
00198 
00201   virtual void SetFeatureImage(const FeatureImageType *f)
00202   {
00203     this->ProcessObject::SetNthInput( 1, const_cast< FeatureImageType * >( f ) );
00204     m_SegmentationFunction->SetFeatureImage(f);
00205   }
00207 
00208   virtual FeatureImageType * GetFeatureImage()
00209   { return ( static_cast< FeatureImageType * >( this->ProcessObject::GetInput(1) ) ); }
00210 
00213   virtual void SetInitialImage(InputImageType *f)
00214   {
00215     this->SetInput(f);
00216   }
00217 
00219   void SetInput2(const FeatureImageType *input)
00220   {
00221     this->SetFeatureImage(input);
00222   }
00223 
00227   void SetSpeedImage(SpeedImageType *s)
00228   {  m_SegmentationFunction->SetSpeedImage(s); }
00229 
00233   void SetAdvectionImage(VectorImageType *v)
00234   { m_SegmentationFunction->SetAdvectionImage(v); }
00235 
00238   virtual const SpeedImageType * GetSpeedImage() const
00239   { return m_SegmentationFunction->GetSpeedImage(); }
00240 
00243   virtual const VectorImageType * GetAdvectionImage() const
00244   { return m_SegmentationFunction->GetAdvectionImage(); }
00245 
00249   void SetUseNegativeFeaturesOn()
00250   {
00251     itkWarningMacro(
00252       << "SetUseNegativeFeaturesOn has been deprecated.  Please use ReverseExpansionDirectionOn() instead");
00253     this->ReverseExpansionDirectionOn();
00254   }
00256 
00257   void SetUseNegativeFeaturesOff()
00258   {
00259     itkWarningMacro(
00260       << "SetUseNegativeFeaturesOff has been deprecated.  Please use ReverseExpansionDirectionOff() instead");
00261     this->ReverseExpansionDirectionOff();
00262   }
00263 
00266   void SetUseNegativeFeatures(bool u)
00267   {
00268     itkWarningMacro(<< "SetUseNegativeFeatures has been deprecated.  Please use SetReverseExpansionDirection instead");
00269     if ( u == true )
00270       {
00271       this->SetReverseExpansionDirection(false);
00272       }
00273     else
00274       {
00275       this->SetReverseExpansionDirection(true);
00276       }
00277   }
00279 
00280   bool GetUseNegativeFeatures() const
00281   {
00282     itkWarningMacro(<< "GetUseNegativeFeatures has been deprecated.  Please use GetReverseExpansionDirection() instead");
00283     if ( m_ReverseExpansionDirection == false )
00284       {
00285       return true;
00286       }
00287     else
00288       {
00289       return false;
00290       }
00291   }
00292 
00301   itkSetMacro(ReverseExpansionDirection, bool);
00302   itkGetConstMacro(ReverseExpansionDirection, bool);
00303   itkBooleanMacro(ReverseExpansionDirection);
00305 
00311   itkSetMacro(AutoGenerateSpeedAdvection, bool);
00312   itkGetConstMacro(AutoGenerateSpeedAdvection, bool);
00313   itkBooleanMacro(AutoGenerateSpeedAdvection);
00315 
00320   void SetFeatureScaling(ValueType v)
00321   {
00322     if ( v != m_SegmentationFunction->GetPropagationWeight() )
00323       {
00324       this->SetPropagationScaling(v);
00325       }
00326     if ( v != m_SegmentationFunction->GetAdvectionWeight() )
00327       {
00328       this->SetAdvectionScaling(v);
00329       }
00330   }
00332 
00335   void SetPropagationScaling(ValueType v)
00336   {
00337     if ( v != m_SegmentationFunction->GetPropagationWeight() )
00338       {
00339       m_SegmentationFunction->SetPropagationWeight(v);
00340       this->Modified();
00341       }
00342   }
00344 
00345   ValueType GetPropagationScaling() const
00346   {
00347     return m_SegmentationFunction->GetPropagationWeight();
00348   }
00349 
00352   void SetAdvectionScaling(ValueType v)
00353   {
00354     if ( v != m_SegmentationFunction->GetAdvectionWeight() )
00355       {
00356       m_SegmentationFunction->SetAdvectionWeight(v);
00357       this->Modified();
00358       }
00359   }
00361 
00362   ValueType GetAdvectionScaling() const
00363   {
00364     return m_SegmentationFunction->GetAdvectionWeight();
00365   }
00366 
00371   void SetCurvatureScaling(ValueType v)
00372   {
00373     if ( v != m_SegmentationFunction->GetCurvatureWeight() )
00374       {
00375       m_SegmentationFunction->SetCurvatureWeight(v);
00376       this->Modified();
00377       }
00378   }
00380 
00381   ValueType GetCurvatureScaling() const
00382   {
00383     return m_SegmentationFunction->GetCurvatureWeight();
00384   }
00385 
00387   void SetUseMinimalCurvature(bool b)
00388   {
00389     if ( m_SegmentationFunction->GetUseMinimalCurvature() != b )
00390       {
00391       m_SegmentationFunction->SetUseMinimalCurvature(b);
00392       this->Modified();
00393       }
00394   }
00396 
00397   bool GetUseMinimalCurvature() const
00398   {
00399     return m_SegmentationFunction->GetUseMinimalCurvature();
00400   }
00401 
00402   void UseMinimalCurvatureOn()
00403   {
00404     this->SetUseMinimalCurvature(true);
00405   }
00406 
00407   void UseMinimalCurvatureOff()
00408   {
00409     this->SetUseMinimalCurvature(false);
00410   }
00411 
00417   virtual void SetSegmentationFunction(SegmentationFunctionType *s)
00418   {
00419     m_SegmentationFunction = s;
00420 
00421     typename SegmentationFunctionType::RadiusType r;
00422     r.Fill(1);
00423 
00424     m_SegmentationFunction->Initialize(r);
00425     this->SetDifferenceFunction(m_SegmentationFunction);
00426     this->Modified();
00427   }
00428 
00429   virtual SegmentationFunctionType * GetSegmentationFunction()
00430   { return m_SegmentationFunction; }
00431 
00436   void SetMaximumCurvatureTimeStep(double n)
00437   {
00438     if ( n != m_SegmentationFunction->GetMaximumCurvatureTimeStep() )
00439       {
00440       m_SegmentationFunction->SetMaximumCurvatureTimeStep(n);
00441       this->Modified();
00442       }
00443   }
00445 
00446   double GetMaximumCurvatureTimeStep() const
00447   {
00448     return m_SegmentationFunction->GetMaximumCurvatureTimeStep();
00449   }
00450 
00455   void SetMaximumPropagationTimeStep(double n)
00456   {
00457     if ( n != m_SegmentationFunction->GetMaximumPropagationTimeStep() )
00458       {
00459       m_SegmentationFunction->SetMaximumPropagationTimeStep(n);
00460       this->Modified();
00461       }
00462   }
00464 
00465   double GetMaximumPropagationTimeStep() const
00466   {
00467     return m_SegmentationFunction->GetMaximumPropagationTimeStep();
00468   }
00469 
00473   void GenerateSpeedImage();
00474 
00478   void GenerateAdvectionImage();
00479 
00480 #ifdef ITK_USE_CONCEPT_CHECKING
00481 
00482   itkConceptMacro( OutputHasNumericTraitsCheck,
00483                    ( Concept::HasNumericTraits< TOutputPixelType > ) );
00484 
00486 #endif
00487 protected:
00488   virtual ~SegmentationLevelSetImageFilter() {}
00489   SegmentationLevelSetImageFilter();
00490 
00491   virtual void PrintSelf(std::ostream & os, Indent indent) const;
00492 
00494   virtual void InitializeIteration()
00495   {
00496     Superclass::InitializeIteration();
00497     // Estimate the progress of the filter
00498     this->SetProgress( (float)( (float)this->GetElapsedIterations()
00499                                 / (float)this->GetNumberOfIterations() ) );
00500   }
00502 
00505   void GenerateData();
00506 
00509   bool m_ReverseExpansionDirection;
00510 
00515   bool m_AutoGenerateSpeedAdvection;
00516 private:
00517   SegmentationLevelSetImageFilter(const Self &); //purposely not implemented
00518   void operator=(const Self &);                  //purposely not implemented
00520 
00521   SegmentationFunctionType *m_SegmentationFunction;
00522 };
00523 } // end namespace itk
00524 
00525 #ifndef ITK_MANUAL_INSTANTIATION
00526 #include "itkSegmentationLevelSetImageFilter.hxx"
00527 #endif
00528 
00529 #endif
00530