ITK  4.8.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  typename TLevelSet,
104  typename TSpeedImage = Image< float, TLevelSet ::ImageDimension > >
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:
140  int GetAxis() const { return m_Axis; }
141  void SetAxis(int axis) { m_Axis = axis; }
142  const AxisNodeType & operator=(const NodeType & node)
143  { this->NodeType::operator=(node); return *this; }
144 
145 private:
146  int m_Axis;
147  };
148 
150  typedef TSpeedImage SpeedImageType;
151 
153  typedef typename SpeedImageType::Pointer SpeedImagePointer;
154  typedef typename SpeedImageType::ConstPointer SpeedImageConstPointer;
155 
157  itkStaticConstMacro(SetDimension, unsigned int,
159  itkStaticConstMacro(SpeedImageDimension, unsigned int,
160  SpeedImageType::ImageDimension);
162 
165 
172 
175 
178 
179  template< typename TPixel >
181  {
182  typedef Image< TPixel, SetDimension > InternalImageType;
184  InternalRegionIterator;
185  InternalRegionIterator b_it( iImage, iImage->GetLargestPossibleRegion() );
186  b_it.GoToBegin();
187 
188  TPixel zero_value = NumericTraits< TPixel >::ZeroValue();
189  size_t NumberOfPoints = 0;
190 
191  NodeType node;
192  node.SetValue( 0. );
193 
194  while( !b_it.IsAtEnd() )
195  {
196  if( b_it.Get() == zero_value )
197  {
198  if( NumberOfPoints == 0 )
199  {
201  }
202  node.SetIndex( b_it.GetIndex() );
203  m_OutsidePoints->InsertElement( NumberOfPoints++, node );
204 
205  }
206  ++b_it;
207  }
208  this->Modified();
209  }
210 
213  {
214  m_OutsidePoints = points;
215  this->Modified();
216  }
218 
222  {
223  m_AlivePoints = points;
224  this->Modified();
225  }
227 
230  {
231  return m_AlivePoints;
232  }
233 
237  {
238  m_TrialPoints = points;
239  this->Modified();
240  }
242 
245  {
246  return m_TrialPoints;
247  }
248 
251  {
252  return m_LabelImage;
253  }
254 
258  void SetSpeedConstant(double value)
259  {
260  m_SpeedConstant = value;
261  m_InverseSpeed = -1.0 * vnl_math_sqr(1.0 / m_SpeedConstant);
262  this->Modified();
263  }
265 
267  itkGetConstReferenceMacro(SpeedConstant, double);
268 
273  itkSetMacro(NormalizationFactor, double);
274  itkGetConstMacro(NormalizationFactor, double);
276 
280  itkSetMacro(StoppingValue, double);
281 
283  itkGetConstReferenceMacro(StoppingValue, double);
284 
289  itkSetMacro(CollectPoints, bool);
290 
292  itkGetConstReferenceMacro(CollectPoints, bool);
293  itkBooleanMacro(CollectPoints);
295 
301  {
302  return m_ProcessedPoints;
303  }
304 
311  virtual void SetOutputSize(const OutputSizeType & size)
312  { m_OutputRegion = size; }
314  { return m_OutputRegion.GetSize(); }
315  itkSetMacro(OutputRegion, OutputRegionType);
316  itkGetConstReferenceMacro(OutputRegion, OutputRegionType);
317  itkSetMacro(OutputSpacing, OutputSpacingType);
318  itkGetConstReferenceMacro(OutputSpacing, OutputSpacingType);
319  itkSetMacro(OutputDirection, OutputDirectionType);
320  itkGetConstReferenceMacro(OutputDirection, OutputDirectionType);
321  itkSetMacro(OutputOrigin, OutputPointType);
322  itkGetConstReferenceMacro(OutputOrigin, OutputPointType);
323  itkSetMacro(OverrideOutputInformation, bool);
324  itkGetConstReferenceMacro(OverrideOutputInformation, bool);
325  itkBooleanMacro(OverrideOutputInformation);
327 
328 #ifdef ITK_USE_CONCEPT_CHECKING
329  // Begin concept checking
330  itkConceptMacro( SameDimensionCheck,
332  itkConceptMacro( SpeedConvertibleToDoubleCheck,
334  itkConceptMacro( DoubleConvertibleToLevelSetCheck,
336  itkConceptMacro( LevelSetOStreamWritableCheck,
338  // End concept checking
339 #endif
340 
341 protected:
344  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
345 
346  virtual void Initialize(LevelSetImageType *);
347 
348  virtual void UpdateNeighbors(const IndexType & index,
349  const SpeedImageType *, LevelSetImageType *);
350 
351  virtual double UpdateValue(const IndexType & index,
352  const SpeedImageType *, LevelSetImageType *);
353 
354  const AxisNodeType & GetNodeUsedInCalculation(unsigned int idx) const
355  { return m_NodesUsed[idx]; }
356 
357  void GenerateData() ITK_OVERRIDE;
358 
360  virtual void GenerateOutputInformation() ITK_OVERRIDE;
361 
362  virtual void EnlargeOutputRequestedRegion(DataObject *output) ITK_OVERRIDE;
363 
368  itkGetConstReferenceMacro(LargeValue, PixelType);
369 
372  LevelSetIndexType m_StartIndex;
373  LevelSetIndexType m_LastIndex;
374 
375  itkGetConstReferenceMacro(StartIndex, LevelSetIndexType);
376  itkGetConstReferenceMacro(LastIndex, LevelSetIndexType);
377 
378 private:
379  FastMarchingImageFilter(const Self &); //purposely not implemented
380  void operator=(const Self &); //purposely not implemented
381 
385 
387 
391 
394 
400 
401  typename LevelSetImageType::PixelType m_LargeValue;
403 
409  typedef std::priority_queue< AxisNodeType, HeapContainer, NodeComparer >
411 
413 
415 };
416 } // namespace itk
417 
418 #ifndef ITK_MANUAL_INSTANTIATION
419 #include "itkFastMarchingImageFilter.hxx"
420 #endif
421 
422 #endif
void PrintSelf(std::ostream &os, Indent indent) const override
virtual void UpdateNeighbors(const IndexType &index, const SpeedImageType *, LevelSetImageType *)
void SetBinaryMask(Image< TPixel, SetDimension > *iImage)
SpeedImageType::ConstPointer SpeedImageConstPointer
Light weight base class for most itk classes.
TLevelSet::PixelType PixelType
Definition: itkLevelSet.h:55
LevelSetImageType::PixelType m_LargeValue
std::greater< AxisNodeType > NodeComparer
std::vector< AxisNodeType > HeapContainer
virtual const RegionType & GetLargestPossibleRegion() const
Definition: itkImageBase.h:254
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
virtual void GenerateOutputInformation() override
void SetTrialPoints(NodeContainer *points)
A multi-dimensional iterator templated over image type that walks an image region and is specialized ...
static const unsigned int SpeedImageDimension
virtual OutputSizeType GetOutputSize() const
SmartPointer< const Self > ConstPointer
void SetIndex(const IndexType &input)
LevelSetImageType::DirectionType OutputDirectionType
LevelSetImageType::SpacingType OutputSpacingType
typedef(Concept::SameDimension< SetDimension, SpeedImageDimension >) SameDimensionCheck
virtual void EnlargeOutputRequestedRegion(DataObject *output) override
Image< unsigned char, itkGetStaticConstMacro(SetDimension) > LabelImageType
Represent a node in a level set.
LevelSetTypeDefault< TLevelSet > LevelSetType
virtual double UpdateValue(const IndexType &index, const SpeedImageType *, LevelSetImageType *)
const AxisNodeType & GetNodeUsedInCalculation(unsigned int idx) const
LevelSetType::NodeContainer NodeContainer
const AxisNodeType & operator=(const NodeType &node)
virtual void Modified() const
LevelSetType::LevelSetPointer LevelSetPointer
AxisNodeType m_NodesUsed[SetDimension]
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.
virtual void Initialize(LevelSetImageType *)
LevelSetType::LevelSetImageType LevelSetImageType
Self & operator=(const Self &rhs)
SpeedImageType::Pointer SpeedImagePointer
Control indentation during Print() invocation.
Definition: itkIndent.h:49
LevelSetImageType::PointType OutputPointType
static Pointer New()
Solve an Eikonal equation using Fast Marching.
void GenerateData() override
LevelSetImageType::SizeType OutputSizeType
#define itkConceptMacro(name, concept)
Level set type information.
Definition: itkLevelSet.h:40
static const unsigned int SetDimension
Definition: itkLevelSet.h:48
static const unsigned int SetDimension
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