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
00101 template <
00102 class TLevelSet,
00103 class TSpeedImage = Image<float,::itk::GetImageDimension<TLevelSet>::ImageDimension> >
00104 class ITK_EXPORT FastMarchingImageFilter :
00105 public ImageToImageFilter<TSpeedImage,TLevelSet>
00106 {
00107 public:
00109 typedef FastMarchingImageFilter Self;
00110 typedef ImageSource<TLevelSet> Superclass;
00111 typedef SmartPointer<Self> Pointer;
00112 typedef SmartPointer<const Self> ConstPointer;
00113
00115 itkNewMacro(Self);
00116
00118 itkTypeMacro(FastMarchingImageFilter, ImageSource);
00119
00121 typedef LevelSetTypeDefault<TLevelSet> LevelSetType;
00122 typedef typename LevelSetType::LevelSetImageType LevelSetImageType;
00123 typedef typename LevelSetType::LevelSetPointer LevelSetPointer;
00124 typedef typename LevelSetType::PixelType PixelType;
00125 typedef typename LevelSetType::NodeType NodeType;
00126 typedef typename LevelSetType::NodeContainer NodeContainer;
00127 typedef typename LevelSetType::NodeContainerPointer NodeContainerPointer;
00128 typedef typename LevelSetImageType::SizeType OutputSizeType;
00129 typedef typename LevelSetImageType::RegionType OutputRegionType;
00130 typedef typename LevelSetImageType::SpacingType OutputSpacingType;
00131 typedef typename LevelSetImageType::DirectionType OutputDirectionType;
00132 typedef typename LevelSetImageType::PointType OutputPointType;
00133
00134 class AxisNodeType : public NodeType
00135 {
00136 public:
00137 int GetAxis() const { return m_Axis; }
00138 void SetAxis( int axis ) { m_Axis = axis; }
00139 const AxisNodeType & operator=(const NodeType & node)
00140 { this->NodeType::operator=(node); return *this; }
00141 private:
00142 int m_Axis;
00143 };
00144
00146 typedef TSpeedImage SpeedImageType;
00147
00149 typedef typename SpeedImageType::Pointer SpeedImagePointer;
00150 typedef typename SpeedImageType::ConstPointer SpeedImageConstPointer;
00151
00153 itkStaticConstMacro(SetDimension, unsigned int,
00154 LevelSetType::SetDimension);
00155 itkStaticConstMacro(SpeedImageDimension, unsigned int,
00156 SpeedImageType::ImageDimension);
00158
00160 typedef Index<itkGetStaticConstMacro(SetDimension)> IndexType;
00161
00166 enum LabelType { FarPoint, AlivePoint, TrialPoint };
00167
00169 typedef Image<unsigned char, itkGetStaticConstMacro(SetDimension)> LabelImageType;
00170
00172 typedef typename LabelImageType::Pointer LabelImagePointer;
00173
00176 void SetAlivePoints( NodeContainer * points )
00177 {
00178 m_AlivePoints = points;
00179 this->Modified();
00180 }
00182
00184 NodeContainerPointer GetAlivePoints( )
00185 {
00186 return m_AlivePoints;
00187 }
00188
00191 void SetTrialPoints( NodeContainer * points )
00192 {
00193 m_TrialPoints = points;
00194 this->Modified();
00195 }
00197
00199 NodeContainerPointer GetTrialPoints( )
00200 {
00201 return m_TrialPoints;
00202 }
00203
00205 LabelImagePointer GetLabelImage() const
00206 {
00207 return m_LabelImage;
00208 }
00209
00213 void SetSpeedConstant( double value )
00214 {
00215 m_SpeedConstant = value;
00216 m_InverseSpeed = -1.0 * vnl_math_sqr( 1.0 / m_SpeedConstant );
00217 this->Modified();
00218 }
00220
00222 itkGetConstReferenceMacro( SpeedConstant, double );
00223
00228 itkSetMacro( NormalizationFactor, double );
00229 itkGetMacro( NormalizationFactor, double );
00231
00235 itkSetMacro( StoppingValue, double );
00236
00238 itkGetConstReferenceMacro( StoppingValue, double );
00239
00244 itkSetMacro( CollectPoints, bool );
00245
00247 itkGetConstReferenceMacro( CollectPoints, bool );
00248 itkBooleanMacro( CollectPoints );
00250
00255 NodeContainerPointer GetProcessedPoints() const
00256 {
00257 return m_ProcessedPoints;
00258 }
00259
00266 virtual void SetOutputSize( const OutputSizeType& size )
00267 { m_OutputRegion = size; }
00268 virtual OutputSizeType GetOutputSize() const
00269 { return m_OutputRegion.GetSize(); }
00270 itkSetMacro( OutputRegion, OutputRegionType );
00271 itkGetConstReferenceMacro( OutputRegion, OutputRegionType );
00272 itkSetMacro( OutputSpacing, OutputSpacingType );
00273 itkGetConstReferenceMacro( OutputSpacing, OutputSpacingType );
00274 itkSetMacro( OutputDirection, OutputDirectionType );
00275 itkGetConstReferenceMacro( OutputDirection, OutputDirectionType );
00276 itkSetMacro( OutputOrigin, OutputPointType );
00277 itkGetConstReferenceMacro( OutputOrigin, OutputPointType );
00278 itkSetMacro( OverrideOutputInformation, bool );
00279 itkGetConstReferenceMacro( OverrideOutputInformation, bool );
00280 itkBooleanMacro( OverrideOutputInformation );
00282
00283 #ifdef ITK_USE_CONCEPT_CHECKING
00284
00285 itkConceptMacro(SameDimensionCheck,
00286 (Concept::SameDimension<SetDimension, SpeedImageDimension>));
00287 itkConceptMacro(SpeedConvertibleToDoubleCheck,
00288 (Concept::Convertible<typename TSpeedImage::PixelType, double>));
00289 itkConceptMacro(DoubleConvertibleToLevelSetCheck,
00290 (Concept::Convertible<double, PixelType>));
00291 itkConceptMacro(LevelSetOStreamWritableCheck,
00292 (Concept::OStreamWritable<PixelType>));
00293
00295 #endif
00296
00297 protected:
00298 FastMarchingImageFilter();
00299 ~FastMarchingImageFilter(){};
00300 void PrintSelf( std::ostream& os, Indent indent ) const;
00301
00302 virtual void Initialize( LevelSetImageType * );
00303 virtual void UpdateNeighbors( const IndexType& index,
00304 const SpeedImageType *, LevelSetImageType * );
00305 virtual double UpdateValue( const IndexType& index,
00306 const SpeedImageType *, LevelSetImageType * );
00307
00308
00309 const AxisNodeType& GetNodeUsedInCalculation(unsigned int idx) const
00310 { return m_NodesUsed[idx]; }
00311
00312 void GenerateData();
00313
00315 virtual void GenerateOutputInformation();
00316 virtual void EnlargeOutputRequestedRegion(DataObject *output);
00318
00323 itkGetConstReferenceMacro( LargeValue, PixelType );
00324
00325 OutputRegionType m_BufferedRegion;
00326 typedef typename LevelSetImageType::IndexType LevelSetIndexType;
00327 LevelSetIndexType m_StartIndex;
00328 LevelSetIndexType m_LastIndex;
00329
00330 itkGetConstReferenceMacro( StartIndex, LevelSetIndexType );
00331 itkGetConstReferenceMacro( LastIndex, LevelSetIndexType );
00332
00333 private:
00334 FastMarchingImageFilter(const Self&);
00335 void operator=(const Self&);
00336
00337 NodeContainerPointer m_AlivePoints;
00338 NodeContainerPointer m_TrialPoints;
00339
00340 LabelImagePointer m_LabelImage;
00341
00342 double m_SpeedConstant;
00343 double m_InverseSpeed;
00344 double m_StoppingValue;
00345
00346 bool m_CollectPoints;
00347 NodeContainerPointer m_ProcessedPoints;
00348
00349 OutputRegionType m_OutputRegion;
00350 OutputPointType m_OutputOrigin;
00351 OutputSpacingType m_OutputSpacing;
00352 OutputDirectionType m_OutputDirection;
00353 bool m_OverrideOutputInformation;
00354
00355
00356 typename LevelSetImageType::PixelType m_LargeValue;
00357 AxisNodeType m_NodesUsed[SetDimension];
00358
00362 typedef std::vector<AxisNodeType> HeapContainer;
00363 typedef std::greater<AxisNodeType> NodeComparer;
00364 typedef std::priority_queue< AxisNodeType, HeapContainer, NodeComparer >
00365 HeapType;
00366
00367 HeapType m_TrialHeap;
00368
00369 double m_NormalizationFactor;
00370 };
00371
00372 }
00373
00374
00375 #ifndef ITK_MANUAL_INSTANTIATION
00376 #include "itkFastMarchingImageFilter.txx"
00377 #endif
00378
00379 #endif
00380