ITK  4.5.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:
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 
144 private:
145  int m_Axis;
146  };
147 
149  typedef TSpeedImage SpeedImageType;
150 
152  typedef typename SpeedImageType::Pointer SpeedImagePointer;
153  typedef typename SpeedImageType::ConstPointer SpeedImageConstPointer;
154 
156  itkStaticConstMacro(SetDimension, unsigned int,
158  itkStaticConstMacro(SpeedImageDimension, unsigned int,
159  SpeedImageType::ImageDimension);
161 
164 
171 
174 
177 
178  template< typename TPixel >
180  {
181  typedef Image< TPixel, SetDimension > InternalImageType;
183  InternalRegionIterator;
184  InternalRegionIterator b_it( iImage, iImage->GetLargestPossibleRegion() );
185  b_it.GoToBegin();
186 
187  TPixel zero_value = NumericTraits< TPixel >::Zero;
188  size_t NumberOfPoints = 0;
189 
190  NodeType node;
191  node.SetValue( 0. );
192 
193  while( !b_it.IsAtEnd() )
194  {
195  if( b_it.Get() == zero_value )
196  {
197  if( NumberOfPoints == 0 )
198  {
200  }
201  node.SetIndex( b_it.GetIndex() );
202  m_OutsidePoints->InsertElement( NumberOfPoints++, node );
203 
204  }
205  ++b_it;
206  }
207  this->Modified();
208  }
209 
212  {
213  m_OutsidePoints = points;
214  this->Modified();
215  }
217 
221  {
222  m_AlivePoints = points;
223  this->Modified();
224  }
226 
229  {
230  return m_AlivePoints;
231  }
232 
236  {
237  m_TrialPoints = points;
238  this->Modified();
239  }
241 
244  {
245  return m_TrialPoints;
246  }
247 
250  {
251  return m_LabelImage;
252  }
253 
257  void SetSpeedConstant(double value)
258  {
259  m_SpeedConstant = value;
260  m_InverseSpeed = -1.0 * vnl_math_sqr(1.0 / m_SpeedConstant);
261  this->Modified();
262  }
264 
266  itkGetConstReferenceMacro(SpeedConstant, double);
267 
272  itkSetMacro(NormalizationFactor, double);
273  itkGetConstMacro(NormalizationFactor, double);
275 
279  itkSetMacro(StoppingValue, double);
280 
282  itkGetConstReferenceMacro(StoppingValue, double);
283 
288  itkSetMacro(CollectPoints, bool);
289 
291  itkGetConstReferenceMacro(CollectPoints, bool);
292  itkBooleanMacro(CollectPoints);
294 
300  {
301  return m_ProcessedPoints;
302  }
303 
310  virtual void SetOutputSize(const OutputSizeType & size)
311  { m_OutputRegion = size; }
313  { return m_OutputRegion.GetSize(); }
314  itkSetMacro(OutputRegion, OutputRegionType);
315  itkGetConstReferenceMacro(OutputRegion, OutputRegionType);
316  itkSetMacro(OutputSpacing, OutputSpacingType);
317  itkGetConstReferenceMacro(OutputSpacing, OutputSpacingType);
318  itkSetMacro(OutputDirection, OutputDirectionType);
319  itkGetConstReferenceMacro(OutputDirection, OutputDirectionType);
320  itkSetMacro(OutputOrigin, OutputPointType);
321  itkGetConstReferenceMacro(OutputOrigin, OutputPointType);
322  itkSetMacro(OverrideOutputInformation, bool);
323  itkGetConstReferenceMacro(OverrideOutputInformation, bool);
324  itkBooleanMacro(OverrideOutputInformation);
326 
327 #ifdef ITK_USE_CONCEPT_CHECKING
328  // Begin concept checking
329  itkConceptMacro( SameDimensionCheck,
331  itkConceptMacro( SpeedConvertibleToDoubleCheck,
333  itkConceptMacro( DoubleConvertibleToLevelSetCheck,
335  itkConceptMacro( LevelSetOStreamWritableCheck,
337  // End concept checking
338 #endif
339 
340 protected:
343  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 
377 private:
378  FastMarchingImageFilter(const Self &); //purposely not implemented
379  void operator=(const Self &); //purposely not implemented
380 
384 
386 
390 
393 
399 
400  typename LevelSetImageType::PixelType m_LargeValue;
402 
406  typedef std::vector< AxisNodeType > HeapContainer;
407  typedef std::greater< AxisNodeType > NodeComparer;
408  typedef std::priority_queue< AxisNodeType, HeapContainer, NodeComparer >
410 
412 
414 };
415 } // namespace itk
416 
417 #ifndef ITK_MANUAL_INSTANTIATION
418 #include "itkFastMarchingImageFilter.hxx"
419 #endif
420 
421 #endif
void PrintSelf(std::ostream &os, Indent indent) const
virtual void UpdateNeighbors(const IndexType &index, const SpeedImageType *, LevelSetImageType *)
void SetBinaryMask(Image< TPixel, SetDimension > *iImage)
SpeedImageType::ConstPointer SpeedImageConstPointer
void operator=(const Self &)
Light weight base class for most itk classes.
TLevelSet::PixelType PixelType
Definition: itkLevelSet.h:55
virtual void EnlargeOutputRequestedRegion(DataObject *output)
LevelSetImageType::PixelType m_LargeValue
std::greater< AxisNodeType > NodeComparer
std::vector< AxisNodeType > HeapContainer
virtual const RegionType & GetLargestPossibleRegion() const
Definition: itkImageBase.h:253
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
void SetTrialPoints(NodeContainer *points)
A multi-dimensional iterator templated over image type that walks an image region and is specialized ...
virtual void GenerateOutputInformation()
static const unsigned int SpeedImageDimension
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
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()
Define additional traits for native types such as int or float.
Solve an Eikonal equation using Fast Marching.
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