ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkFastMarchingImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkFastMarchingImageFilter_h
19 #define __itkFastMarchingImageFilter_h
20 
21 #include "itkImageToImageFilter.h"
23 #include "itkLevelSet.h"
24 #include "vnl/vnl_math.h"
25 
26 #include <functional>
27 #include <queue>
28 
29 namespace itk
30 {
102 template<
103  class TLevelSet,
104  class TSpeedImage = Image< float, ::itk::GetImageDimension< TLevelSet >::ImageDimension > >
105 class ITK_EXPORT FastMarchingImageFilter:
106  public ImageToImageFilter< TSpeedImage, TLevelSet >
107 {
108 public:
114 
116  itkNewMacro(Self);
117 
120 
130  typedef typename LevelSetImageType::SizeType OutputSizeType;
131  typedef typename LevelSetImageType::RegionType OutputRegionType;
132  typedef typename LevelSetImageType::SpacingType OutputSpacingType;
133  typedef typename LevelSetImageType::DirectionType OutputDirectionType;
134  typedef typename LevelSetImageType::PointType OutputPointType;
135 
136  class AxisNodeType:public NodeType
137  {
138 public:
139  int GetAxis() const { return m_Axis; }
140  void SetAxis(int axis) { m_Axis = axis; }
141  const AxisNodeType & operator=(const NodeType & node)
142  { this->NodeType::operator=(node); return *this; }
143 private:
144  int m_Axis;
145  };
146 
148  typedef TSpeedImage SpeedImageType;
149 
151  typedef typename SpeedImageType::Pointer SpeedImagePointer;
152  typedef typename SpeedImageType::ConstPointer SpeedImageConstPointer;
153 
155  itkStaticConstMacro(SetDimension, unsigned int,
156  LevelSetType::SetDimension);
157  itkStaticConstMacro(SpeedImageDimension, unsigned int,
158  SpeedImageType::ImageDimension);
160 
163 
168  enum LabelType { FarPoint = 0, AlivePoint,
169  TrialPoint, InitialTrialPoint, OutsidePoint };
170 
173 
176 
177  template< typename TPixel >
178  void SetBinaryMask( Image< TPixel, SetDimension >* iImage )
179  {
180  typedef Image< TPixel, SetDimension > InternalImageType;
182  InternalRegionIterator;
183  InternalRegionIterator b_it( iImage, iImage->GetLargestPossibleRegion() );
184  b_it.GoToBegin();
185 
186  TPixel zero_value = NumericTraits< TPixel >::Zero;
187  size_t NumberOfPoints = 0;
188 
189  NodeType node;
190  node.SetValue( 0. );
191 
192  while( !b_it.IsAtEnd() )
193  {
194  if( b_it.Get() == zero_value )
195  {
196  if( NumberOfPoints == 0 )
197  {
198  m_OutsidePoints = NodeContainer::New();
199  }
200  node.SetIndex( b_it.GetIndex() );
201  m_OutsidePoints->InsertElement( NumberOfPoints++, node );
202 
203  }
204  ++b_it;
205  }
206  this->Modified();
207  }
208 
210  void SetOutsidePoints(NodeContainer *points)
211  {
212  m_OutsidePoints = points;
213  this->Modified();
214  }
216 
219  void SetAlivePoints(NodeContainer *points)
220  {
221  m_AlivePoints = points;
222  this->Modified();
223  }
225 
227  NodeContainerPointer GetAlivePoints()
228  {
229  return m_AlivePoints;
230  }
231 
234  void SetTrialPoints(NodeContainer *points)
235  {
236  m_TrialPoints = points;
237  this->Modified();
238  }
240 
242  NodeContainerPointer GetTrialPoints()
243  {
244  return m_TrialPoints;
245  }
246 
248  LabelImagePointer GetLabelImage() const
249  {
250  return m_LabelImage;
251  }
252 
256  void SetSpeedConstant(double value)
257  {
258  m_SpeedConstant = value;
259  m_InverseSpeed = -1.0 * vnl_math_sqr(1.0 / m_SpeedConstant);
260  this->Modified();
261  }
263 
265  itkGetConstReferenceMacro(SpeedConstant, double);
266 
271  itkSetMacro(NormalizationFactor, double);
272  itkGetConstMacro(NormalizationFactor, double);
274 
278  itkSetMacro(StoppingValue, double);
279 
281  itkGetConstReferenceMacro(StoppingValue, double);
282 
287  itkSetMacro(CollectPoints, bool);
288 
290  itkGetConstReferenceMacro(CollectPoints, bool);
291  itkBooleanMacro(CollectPoints);
293 
298  NodeContainerPointer GetProcessedPoints() const
299  {
300  return m_ProcessedPoints;
301  }
302 
309  virtual void SetOutputSize(const OutputSizeType & size)
310  { m_OutputRegion = size; }
311  virtual OutputSizeType GetOutputSize() const
312  { return m_OutputRegion.GetSize(); }
313  itkSetMacro(OutputRegion, OutputRegionType);
314  itkGetConstReferenceMacro(OutputRegion, OutputRegionType);
315  itkSetMacro(OutputSpacing, OutputSpacingType);
316  itkGetConstReferenceMacro(OutputSpacing, OutputSpacingType);
317  itkSetMacro(OutputDirection, OutputDirectionType);
318  itkGetConstReferenceMacro(OutputDirection, OutputDirectionType);
319  itkSetMacro(OutputOrigin, OutputPointType);
320  itkGetConstReferenceMacro(OutputOrigin, OutputPointType);
321  itkSetMacro(OverrideOutputInformation, bool);
322  itkGetConstReferenceMacro(OverrideOutputInformation, bool);
323  itkBooleanMacro(OverrideOutputInformation);
325 
326 #ifdef ITK_USE_CONCEPT_CHECKING
327 
328  itkConceptMacro( SameDimensionCheck,
330  itkConceptMacro( SpeedConvertibleToDoubleCheck,
332  itkConceptMacro( DoubleConvertibleToLevelSetCheck,
334  itkConceptMacro( LevelSetOStreamWritableCheck,
336 
338 #endif
339 protected:
342  void PrintSelf(std::ostream & os, Indent indent) const;
344 
345  virtual void Initialize(LevelSetImageType *);
346 
347  virtual void UpdateNeighbors(const IndexType & index,
348  const SpeedImageType *, LevelSetImageType *);
349 
350  virtual double UpdateValue(const IndexType & index,
351  const SpeedImageType *, LevelSetImageType *);
352 
353  const AxisNodeType & GetNodeUsedInCalculation(unsigned int idx) const
354  { return m_NodesUsed[idx]; }
355 
356  void GenerateData();
357 
359  virtual void GenerateOutputInformation();
360 
361  virtual void EnlargeOutputRequestedRegion(DataObject *output);
362 
367  itkGetConstReferenceMacro(LargeValue, PixelType);
368 
370  typedef typename LevelSetImageType::IndexType LevelSetIndexType;
373 
374  itkGetConstReferenceMacro(StartIndex, LevelSetIndexType);
375  itkGetConstReferenceMacro(LastIndex, LevelSetIndexType);
376 private:
377  FastMarchingImageFilter(const Self &); //purposely not implemented
378  void operator=(const Self &); //purposely not implemented
379 
383 
385 
389 
392 
398 
399  typename LevelSetImageType::PixelType m_LargeValue;
400  AxisNodeType m_NodesUsed[SetDimension];
401 
405  typedef std::vector< AxisNodeType > HeapContainer;
406  typedef std::greater< AxisNodeType > NodeComparer;
407  typedef std::priority_queue< AxisNodeType, HeapContainer, NodeComparer >
409 
411 
413 };
414 } // namespace itk
415 
416 #ifndef ITK_MANUAL_INSTANTIATION
417 #include "itkFastMarchingImageFilter.hxx"
418 #endif
419 
420 #endif
421