ITK  4.11.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 "itkMath.h"
25 
26 #include <functional>
27 #include <queue>
28 #include "itkMath.h"
29 
30 namespace itk
31 {
103 template<
104  typename TLevelSet,
105  typename TSpeedImage = Image< float, TLevelSet ::ImageDimension > >
106 class ITK_TEMPLATE_EXPORT FastMarchingImageFilter:
107  public ImageToImageFilter< TSpeedImage, TLevelSet >
108 {
109 public:
115 
117  itkNewMacro(Self);
118 
121 
131  typedef typename LevelSetImageType::SizeType OutputSizeType;
132  typedef typename LevelSetImageType::RegionType OutputRegionType;
133  typedef typename LevelSetImageType::SpacingType OutputSpacingType;
134  typedef typename LevelSetImageType::DirectionType OutputDirectionType;
135  typedef typename LevelSetImageType::PointType OutputPointType;
136 
137  class AxisNodeType:public NodeType
138  {
139 public:
140  AxisNodeType() : m_Axis(0) {}
141  int GetAxis() const { return m_Axis; }
142  void SetAxis(int axis) { m_Axis = axis; }
143  const AxisNodeType & operator=(const NodeType & node)
144  { this->NodeType::operator=(node); return *this; }
145 
146 private:
147  int m_Axis;
148  };
149 
151  typedef TSpeedImage SpeedImageType;
152 
154  typedef typename SpeedImageType::Pointer SpeedImagePointer;
155  typedef typename SpeedImageType::ConstPointer SpeedImageConstPointer;
156 
158  itkStaticConstMacro(SetDimension, unsigned int,
159  LevelSetType::SetDimension);
160  itkStaticConstMacro(SpeedImageDimension, unsigned int,
161  SpeedImageType::ImageDimension);
163 
166 
171  enum LabelType { FarPoint = 0, AlivePoint,
172  TrialPoint, InitialTrialPoint, OutsidePoint };
173 
176 
179 
180  template< typename TPixel >
182  {
183  typedef Image< TPixel, SetDimension > InternalImageType;
185  InternalRegionIterator;
186  InternalRegionIterator b_it( iImage, iImage->GetLargestPossibleRegion() );
187  b_it.GoToBegin();
188 
189  TPixel zero_value = NumericTraits< TPixel >::ZeroValue();
190  typename NodeContainer::ElementIdentifier NumberOfPoints = 0;
191 
192  NodeType node;
193  node.SetValue( 0. );
194 
195  while( !b_it.IsAtEnd() )
196  {
197  if( Math::ExactlyEquals(b_it.Get(), zero_value) )
198  {
199  if( NumberOfPoints == 0 )
200  {
201  m_OutsidePoints = NodeContainer::New();
202  }
203  node.SetIndex( b_it.GetIndex() );
204  m_OutsidePoints->InsertElement( NumberOfPoints++, node );
205 
206  }
207  ++b_it;
208  }
209  this->Modified();
210  }
211 
214  {
215  m_OutsidePoints = points;
216  this->Modified();
217  }
219 
223  {
224  m_AlivePoints = points;
225  this->Modified();
226  }
228 
231  {
232  return m_AlivePoints;
233  }
234 
238  {
239  m_TrialPoints = points;
240  this->Modified();
241  }
243 
246  {
247  return m_TrialPoints;
248  }
249 
252  {
253  return m_LabelImage;
254  }
255 
259  void SetSpeedConstant(double value)
260  {
261  m_SpeedConstant = value;
262  m_InverseSpeed = -1.0 * itk::Math::sqr(1.0 / m_SpeedConstant);
263  this->Modified();
264  }
266 
268  itkGetConstReferenceMacro(SpeedConstant, double);
269 
274  itkSetMacro(NormalizationFactor, double);
275  itkGetConstMacro(NormalizationFactor, double);
277 
281  itkSetMacro(StoppingValue, double);
282 
284  itkGetConstReferenceMacro(StoppingValue, double);
285 
290  itkSetMacro(CollectPoints, bool);
291 
293  itkGetConstReferenceMacro(CollectPoints, bool);
294  itkBooleanMacro(CollectPoints);
296 
302  {
303  return m_ProcessedPoints;
304  }
305 
312  virtual void SetOutputSize(const OutputSizeType & size)
313  { m_OutputRegion = size; }
315  { return m_OutputRegion.GetSize(); }
316  itkSetMacro(OutputRegion, OutputRegionType);
317  itkGetConstReferenceMacro(OutputRegion, OutputRegionType);
318  itkSetMacro(OutputSpacing, OutputSpacingType);
319  itkGetConstReferenceMacro(OutputSpacing, OutputSpacingType);
320  itkSetMacro(OutputDirection, OutputDirectionType);
321  itkGetConstReferenceMacro(OutputDirection, OutputDirectionType);
322  itkSetMacro(OutputOrigin, OutputPointType);
323  itkGetConstReferenceMacro(OutputOrigin, OutputPointType);
324  itkSetMacro(OverrideOutputInformation, bool);
325  itkGetConstReferenceMacro(OverrideOutputInformation, bool);
326  itkBooleanMacro(OverrideOutputInformation);
328 
329 #ifdef ITK_USE_CONCEPT_CHECKING
330  // Begin concept checking
331  itkConceptMacro( SameDimensionCheck,
333  itkConceptMacro( SpeedConvertibleToDoubleCheck,
335  itkConceptMacro( DoubleConvertibleToLevelSetCheck,
337  itkConceptMacro( LevelSetOStreamWritableCheck,
339  // End concept checking
340 #endif
341 
342 protected:
345  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
346 
347  virtual void Initialize(LevelSetImageType *);
348 
349  virtual void UpdateNeighbors(const IndexType & index,
350  const SpeedImageType *, LevelSetImageType *);
351 
352  virtual double UpdateValue(const IndexType & index,
353  const SpeedImageType *, LevelSetImageType *);
354 
355  const AxisNodeType & GetNodeUsedInCalculation(unsigned int idx) const
356  { return m_NodesUsed[idx]; }
357 
358  void GenerateData() ITK_OVERRIDE;
359 
361  virtual void GenerateOutputInformation() ITK_OVERRIDE;
362 
363  virtual void EnlargeOutputRequestedRegion(DataObject *output) ITK_OVERRIDE;
364 
369  itkGetConstReferenceMacro(LargeValue, PixelType);
370 
371  OutputRegionType m_BufferedRegion;
373  LevelSetIndexType m_StartIndex;
374  LevelSetIndexType m_LastIndex;
375 
376  itkGetConstReferenceMacro(StartIndex, LevelSetIndexType);
377  itkGetConstReferenceMacro(LastIndex, LevelSetIndexType);
378 
379 private:
380  ITK_DISALLOW_COPY_AND_ASSIGN(FastMarchingImageFilter);
381 
382  NodeContainerPointer m_AlivePoints;
383  NodeContainerPointer m_TrialPoints;
384  NodeContainerPointer m_OutsidePoints;
385 
386  LabelImagePointer m_LabelImage;
387 
388  double m_SpeedConstant;
389  double m_InverseSpeed;
390  double m_StoppingValue;
391 
392  bool m_CollectPoints;
393  NodeContainerPointer m_ProcessedPoints;
394 
395  OutputRegionType m_OutputRegion;
396  OutputPointType m_OutputOrigin;
397  OutputSpacingType m_OutputSpacing;
398  OutputDirectionType m_OutputDirection;
399  bool m_OverrideOutputInformation;
400 
401  typename LevelSetImageType::PixelType m_LargeValue;
402  AxisNodeType m_NodesUsed[SetDimension];
403 
407  typedef std::vector< AxisNodeType > HeapContainer;
408  typedef std::greater< AxisNodeType > NodeComparer;
409  typedef std::priority_queue< AxisNodeType, HeapContainer, NodeComparer >
411 
412  HeapType m_TrialHeap;
413 
414  double m_NormalizationFactor;
415 };
416 } // namespace itk
417 
418 #ifndef ITK_MANUAL_INSTANTIATION
419 #include "itkFastMarchingImageFilter.hxx"
420 #endif
421 
422 #endif
void SetBinaryMask(Image< TPixel, SetDimension > *iImage)
SpeedImageType::ConstPointer SpeedImageConstPointer
Light weight base class for most itk classes.
TLevelSet::PixelType PixelType
Definition: itkLevelSet.h:55
std::greater< AxisNodeType > NodeComparer
TElementIdentifier ElementIdentifier
std::vector< AxisNodeType > HeapContainer
virtual const RegionType & GetLargestPossibleRegion() const
Definition: itkImageBase.h:260
void SetValue(const PixelType &input)
LevelSetImageType::RegionType OutputRegionType
LabelImageType::Pointer LabelImagePointer
virtual void SetOutputSize(const OutputSizeType &size)
LevelSetImageType::IndexType LevelSetIndexType
void SetOutsidePoints(NodeContainer *points)
std::priority_queue< AxisNodeType, HeapContainer, NodeComparer > HeapType
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potetially different types...
Definition: itkMath.h:710
void SetTrialPoints(NodeContainer *points)
A multi-dimensional iterator templated over image type that walks an image region and is specialized ...
virtual OutputSizeType GetOutputSize() const
SmartPointer< const Self > ConstPointer
void SetIndex(const IndexType &input)
LevelSetImageType::DirectionType OutputDirectionType
LevelSetImageType::SpacingType OutputSpacingType
Image< unsigned char, itkGetStaticConstMacro(SetDimension) > LabelImageType
bool sqr(const bool x)
Definition: itkMath.h:824
Represent a node in a level set.
LevelSetTypeDefault< TLevelSet > LevelSetType
const AxisNodeType & GetNodeUsedInCalculation(unsigned int idx) const
LevelSetType::NodeContainer NodeContainer
const AxisNodeType & operator=(const NodeType &node)
LevelSetType::LevelSetPointer LevelSetPointer
LabelImagePointer GetLabelImage() const
Base class for filters that take an image as input and produce an image as output.
Define a front-end to the STL &quot;vector&quot; container that conforms to the IndexedContainerInterface.
LevelSetType::LevelSetImageType LevelSetImageType
SpeedImageType::Pointer SpeedImagePointer
Control indentation during Print() invocation.
Definition: itkIndent.h:49
LevelSetImageType::PointType OutputPointType
Solve an Eikonal equation using Fast Marching.
LevelSetImageType::SizeType OutputSizeType
#define itkConceptMacro(name, concept)
Level set type information.
Definition: itkLevelSet.h:40
Index< itkGetStaticConstMacro(SetDimension) > IndexType
Base class for all data objects in ITK.
Templated n-dimensional image class.
Definition: itkImage.h:75
void SetAlivePoints(NodeContainer *points)
LevelSetType::NodeContainerPointer NodeContainerPointer
NodeContainerPointer GetProcessedPoints() const
TLevelSet::Pointer LevelSetPointer
Definition: itkLevelSet.h:51