ITK  4.9.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 #include "itkMath.h"
29 
30 namespace itk
31 {
103 template<
104  typename TLevelSet,
105  typename TSpeedImage = Image< float, TLevelSet ::ImageDimension > >
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:
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,
160  itkStaticConstMacro(SpeedImageDimension, unsigned int,
161  SpeedImageType::ImageDimension);
163 
166 
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  size_t 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  {
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 * vnl_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 
373  LevelSetIndexType m_StartIndex;
374  LevelSetIndexType m_LastIndex;
375 
376  itkGetConstReferenceMacro(StartIndex, LevelSetIndexType);
377  itkGetConstReferenceMacro(LastIndex, LevelSetIndexType);
378 
379 private:
380  FastMarchingImageFilter(const Self &) ITK_DELETE_FUNCTION;
381  void operator=(const Self &) ITK_DELETE_FUNCTION;
382 
386 
388 
392 
395 
401 
402  typename LevelSetImageType::PixelType m_LargeValue;
404 
410  typedef std::priority_queue< AxisNodeType, HeapContainer, NodeComparer >
412 
414 
416 };
417 } // namespace itk
418 
419 #ifndef ITK_MANUAL_INSTANTIATION
420 #include "itkFastMarchingImageFilter.hxx"
421 #endif
422 
423 #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:257
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:665
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