ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkSegmentationLevelSetFunction.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 __itkSegmentationLevelSetFunction_h
00019 #define __itkSegmentationLevelSetFunction_h
00020 
00021 #include "itkLevelSetFunction.h"
00022 #include "itkLinearInterpolateImageFunction.h"
00023 #include "itkVectorLinearInterpolateImageFunction.h"
00024 #include "itkVectorCastImageFilter.h"
00025 
00026 namespace itk
00027 {
00046 template< class TImageType, class TFeatureImageType = TImageType >
00047 class ITK_EXPORT SegmentationLevelSetFunction:
00048   public LevelSetFunction< TImageType >
00049 {
00050 public:
00052   typedef SegmentationLevelSetFunction   Self;
00053   typedef LevelSetFunction< TImageType > Superclass;
00054   typedef SmartPointer< Self >           Pointer;
00055   typedef SmartPointer< const Self >     ConstPointer;
00056 
00058   itkTypeMacro(SegmentationLevelSetFunction, LevelSetFunction);
00059 
00061   typedef typename Superclass::ImageType        ImageType;
00062   typedef typename Superclass::RadiusType       RadiusType;
00063   typedef typename Superclass::PixelRealType    PixelRealType;
00064   typedef TFeatureImageType                     FeatureImageType;
00065   typedef typename Superclass::FloatOffsetType  FloatOffsetType;
00066   typedef typename Superclass::ScalarValueType  ScalarValueType;
00067   typedef typename Superclass::NeighborhoodType NeighborhoodType;
00068   typedef typename FeatureImageType::PixelType  FeatureScalarType;
00069   typedef typename ImageType::IndexType         IndexType;
00070   typedef typename Superclass::VectorType       VectorType;
00071   typedef typename Superclass::GlobalDataStruct GlobalDataStruct;
00072 
00074   itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
00075 
00077   typedef Image< VectorType, itkGetStaticConstMacro(ImageDimension) > VectorImageType;
00078 
00080   typedef LinearInterpolateImageFunction< ImageType > InterpolatorType;
00081 
00083   typedef VectorLinearInterpolateImageFunction< VectorImageType > VectorInterpolatorType;
00084 
00086   typedef typename InterpolatorType::ContinuousIndexType ContinuousIndexType;
00087 
00089   virtual const FeatureImageType * GetFeatureImage() const
00090   { return m_FeatureImage.GetPointer(); }
00091   virtual void SetFeatureImage(const FeatureImageType *f)
00092   {    m_FeatureImage = f;  }
00094 
00096   virtual ImageType * GetSpeedImage()
00097   { return m_SpeedImage.GetPointer(); }
00098   void SetSpeedImage(ImageType *s);
00100 
00102   virtual VectorImageType * GetAdvectionImage() const
00103   { return m_AdvectionImage.GetPointer(); }
00104   void SetAdvectionImage(VectorImageType *s);
00106 
00110   virtual void Initialize(const RadiusType & r);
00111 
00116   virtual void CalculateSpeedImage() {}
00117 
00122   virtual void CalculateAdvectionImage() {}
00123 
00126   virtual void AllocateSpeedImage();
00127 
00130   virtual void AllocateAdvectionImage();
00131 
00142   virtual void ReverseExpansionDirection();
00143 
00144 protected:
00146   typename FeatureImageType::ConstPointer m_FeatureImage;
00147 
00149   typename ImageType::Pointer m_SpeedImage;
00150 
00152   typename VectorImageType::Pointer m_AdvectionImage;
00153 
00155   Functor::VectorCast< typename VectorInterpolatorType::OutputType,
00156                        VectorType > m_VectorCast;
00157 
00159   virtual ScalarValueType PropagationSpeed(const NeighborhoodType &,
00160                                            const FloatOffsetType &, GlobalDataStruct *gd) const;
00161 
00163   virtual VectorType AdvectionField(const NeighborhoodType &,
00164                                     const FloatOffsetType &, GlobalDataStruct *gd) const;
00165 
00166   virtual ~SegmentationLevelSetFunction() {}
00167   SegmentationLevelSetFunction()
00168   {
00169     m_SpeedImage = ImageType::New();
00170     m_AdvectionImage = VectorImageType::New();
00171     m_Interpolator = InterpolatorType::New();
00172     m_VectorInterpolator = VectorInterpolatorType::New();
00173   }
00174 
00175   typename InterpolatorType::Pointer m_Interpolator;
00176 
00177   typename VectorInterpolatorType::Pointer m_VectorInterpolator;
00178 private:
00179   SegmentationLevelSetFunction(const Self &); //purposely not implemented
00180   void operator=(const Self &);               //purposely not implemented
00181 };
00182 } // end namespace
00183 
00184 // Define instantiation macro for this template.
00185 #define ITK_TEMPLATE_SegmentationLevelSetFunction(_, EXPORT, TypeX, TypeY)     \
00186   namespace itk                                                                \
00187   {                                                                            \
00188   _( 2 ( class EXPORT SegmentationLevelSetFunction< ITK_TEMPLATE_2 TypeX > ) ) \
00189   namespace Templates                                                          \
00190   {                                                                            \
00191   typedef SegmentationLevelSetFunction< ITK_TEMPLATE_2 TypeX >                 \
00192   SegmentationLevelSetFunction##TypeY;                                       \
00193   }                                                                            \
00194   }
00195 
00196 #if ITK_TEMPLATE_EXPLICIT
00197 #include "Templates/itkSegmentationLevelSetFunction+-.h"
00198 #endif
00199 
00200 #if ITK_TEMPLATE_TXX
00201 #include "itkSegmentationLevelSetFunction.hxx"
00202 #endif
00203 
00204 #endif
00205