00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _itkFastMarchingImageFilter_h
00018 #define _itkFastMarchingImageFilter_h
00019
00020 #include "itkImageToImageFilter.h"
00021 #include "itkLevelSet.h"
00022 #include "itkIndex.h"
00023 #include "vnl/vnl_math.h"
00024
00025 #include <functional>
00026 #include <queue>
00027
00028 namespace itk
00029 {
00030
00095 template <
00096 class TLevelSet,
00097 class TSpeedImage = Image<float,::itk::GetImageDimension<TLevelSet>::ImageDimension> >
00098 class ITK_EXPORT FastMarchingImageFilter :
00099 public ImageToImageFilter<TSpeedImage,TLevelSet>
00100 {
00101 public:
00103 typedef FastMarchingImageFilter Self;
00104 typedef ImageSource<TLevelSet> Superclass;
00105 typedef SmartPointer<Self> Pointer;
00106 typedef SmartPointer<const Self> ConstPointer;
00107
00109 itkNewMacro(Self);
00110
00112 itkTypeMacro(FastMarchingImageFilter, ImageSource);
00113
00115 typedef LevelSetTypeDefault<TLevelSet> LevelSetType;
00116 typedef typename LevelSetType::LevelSetImageType LevelSetImageType;
00117 typedef typename LevelSetType::LevelSetPointer LevelSetPointer;
00118 typedef typename LevelSetType::PixelType PixelType;
00119 typedef typename LevelSetType::NodeType NodeType;
00120 typedef typename LevelSetType::NodeContainer NodeContainer;
00121 typedef typename LevelSetType::NodeContainerPointer NodeContainerPointer;
00122 typedef typename LevelSetImageType::SizeType OutputSizeType;
00123 typedef typename LevelSetImageType::RegionType OutputRegionType;
00124 typedef typename LevelSetImageType::SpacingType OutputSpacingType;
00125 typedef typename LevelSetImageType::PointType OutputPointType;
00126
00127 class AxisNodeType : public NodeType
00128 {
00129 public:
00130 int GetAxis() const { return m_Axis; }
00131 void SetAxis( int axis ) { m_Axis = axis; }
00132 const AxisNodeType & operator=(const NodeType & node)
00133 { this->NodeType::operator=(node); return *this; }
00134 private:
00135 int m_Axis;
00136 };
00137
00139 typedef TSpeedImage SpeedImageType;
00140
00142 typedef typename SpeedImageType::Pointer SpeedImagePointer;
00143 typedef typename SpeedImageType::ConstPointer SpeedImageConstPointer;
00144
00146 itkStaticConstMacro(SetDimension, unsigned int,
00147 LevelSetType::SetDimension);
00148 itkStaticConstMacro(SpeedImageDimension, unsigned int,
00149 SpeedImageType::ImageDimension);
00151
00153 typedef Index<itkGetStaticConstMacro(SetDimension)> IndexType;
00154
00159 enum LabelType { FarPoint, AlivePoint, TrialPoint };
00160
00162 typedef Image<unsigned char, itkGetStaticConstMacro(SetDimension)> LabelImageType;
00163
00165 typedef typename LabelImageType::Pointer LabelImagePointer;
00166
00169 void SetAlivePoints( NodeContainer * points )
00170 {
00171 m_AlivePoints = points;
00172 this->Modified();
00173 };
00175
00177 NodeContainerPointer GetAlivePoints( )
00178 { return m_AlivePoints; };
00179
00182 void SetTrialPoints( NodeContainer * points )
00183 {
00184 m_TrialPoints = points;
00185 this->Modified();
00186 };
00188
00190 NodeContainerPointer GetTrialPoints( )
00191 { return m_TrialPoints; };
00192
00194 LabelImagePointer GetLabelImage() const
00195 { return m_LabelImage; };
00196
00200 void SetSpeedConstant( double value )
00201 {
00202 m_SpeedConstant = value;
00203 m_InverseSpeed = -1.0 * vnl_math_sqr( 1.0 / m_SpeedConstant );
00204 this->Modified();
00205 }
00207
00209 itkGetConstReferenceMacro( SpeedConstant, double );
00210
00215 itkSetMacro( NormalizationFactor, double );
00216 itkGetMacro( NormalizationFactor, double );
00218
00222 itkSetMacro( StoppingValue, double );
00223
00225 itkGetConstReferenceMacro( StoppingValue, double );
00226
00231 itkSetMacro( CollectPoints, bool );
00232
00234 itkGetConstReferenceMacro( CollectPoints, bool );
00235 itkBooleanMacro( CollectPoints );
00237
00242 NodeContainerPointer GetProcessedPoints() const
00243 { return m_ProcessedPoints; }
00244
00245
00252 virtual void SetOutputSize( const OutputSizeType& size )
00253 { m_OutputRegion = size; }
00254 virtual OutputSizeType GetOutputSize() const
00255 { return m_OutputRegion.GetSize(); }
00256 itkSetMacro( OutputRegion, OutputRegionType );
00257 itkGetConstReferenceMacro( OutputRegion, OutputRegionType );
00258 itkSetMacro( OutputSpacing, OutputSpacingType );
00259 itkGetConstReferenceMacro( OutputSpacing, OutputSpacingType );
00260 itkSetMacro( OutputOrigin, OutputPointType );
00261 itkGetConstReferenceMacro( OutputOrigin, OutputPointType );
00262 itkSetMacro( OverrideOutputInformation, bool );
00263 itkGetConstReferenceMacro( OverrideOutputInformation, bool );
00264 itkBooleanMacro( OverrideOutputInformation );
00266
00267 #ifdef ITK_USE_CONCEPT_CHECKING
00268
00269 itkConceptMacro(SameDimensionCheck,
00270 (Concept::SameDimension<SetDimension, SpeedImageDimension>));
00271 itkConceptMacro(SpeedConvertibleToDoubleCheck,
00272 (Concept::Convertible<typename TSpeedImage::PixelType, double>));
00273 itkConceptMacro(DoubleConvertibleToLevelSetCheck,
00274 (Concept::Convertible<double, PixelType>));
00275 itkConceptMacro(LevelSetOStreamWritableCheck,
00276 (Concept::OStreamWritable<PixelType>));
00277
00279 #endif
00280
00281 protected:
00282 FastMarchingImageFilter();
00283 ~FastMarchingImageFilter(){};
00284 void PrintSelf( std::ostream& os, Indent indent ) const;
00285
00286 virtual void Initialize( LevelSetImageType * );
00287 virtual void UpdateNeighbors( const IndexType& index,
00288 const SpeedImageType *, LevelSetImageType * );
00289 virtual double UpdateValue( const IndexType& index,
00290 const SpeedImageType *, LevelSetImageType * );
00291
00292
00293 const AxisNodeType& GetNodeUsedInCalculation(unsigned int idx) const
00294 { return m_NodesUsed[idx]; }
00295
00296 void GenerateData();
00297
00299 virtual void GenerateOutputInformation();
00300 virtual void EnlargeOutputRequestedRegion(DataObject *output);
00302
00307 itkGetConstReferenceMacro( LargeValue, PixelType );
00308
00309 OutputRegionType m_BufferedRegion;
00310 typedef typename LevelSetImageType::IndexType LevelSetIndexType;
00311 LevelSetIndexType m_StartIndex;
00312 LevelSetIndexType m_LastIndex;
00313
00314 itkGetConstReferenceMacro( StartIndex, LevelSetIndexType );
00315 itkGetConstReferenceMacro( LastIndex, LevelSetIndexType );
00316
00317 private:
00318 FastMarchingImageFilter(const Self&);
00319 void operator=(const Self&);
00320
00321 NodeContainerPointer m_AlivePoints;
00322 NodeContainerPointer m_TrialPoints;
00323
00324 LabelImagePointer m_LabelImage;
00325
00326 double m_SpeedConstant;
00327 double m_InverseSpeed;
00328 double m_StoppingValue;
00329
00330 bool m_CollectPoints;
00331 NodeContainerPointer m_ProcessedPoints;
00332
00333 OutputRegionType m_OutputRegion;
00334 OutputSpacingType m_OutputSpacing;
00335 OutputPointType m_OutputOrigin;
00336 bool m_OverrideOutputInformation;
00337
00338
00339 typename LevelSetImageType::PixelType m_LargeValue;
00340 AxisNodeType m_NodesUsed[SetDimension];
00341
00345 typedef std::vector<AxisNodeType> HeapContainer;
00346 typedef std::greater<AxisNodeType> NodeComparer;
00347 typedef std::priority_queue< AxisNodeType, HeapContainer, NodeComparer > HeapType;
00348
00349 HeapType m_TrialHeap;
00350
00351 double m_NormalizationFactor;
00352 };
00353
00354 }
00355
00356
00357 #ifndef ITK_MANUAL_INSTANTIATION
00358 #include "itkFastMarchingImageFilter.txx"
00359 #endif
00360
00361 #endif
00362