ITK  4.3.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, 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 
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,
157  LevelSetType::SetDimension);
158  itkStaticConstMacro(SpeedImageDimension, unsigned int,
159  SpeedImageType::ImageDimension);
161 
164 
169  enum LabelType { FarPoint = 0, AlivePoint,
170  TrialPoint, InitialTrialPoint, OutsidePoint };
171 
174 
177 
178  template< typename TPixel >
179  void SetBinaryMask( Image< TPixel, SetDimension >* iImage )
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  {
199  m_OutsidePoints = NodeContainer::New();
200  }
201  node.SetIndex( b_it.GetIndex() );
202  m_OutsidePoints->InsertElement( NumberOfPoints++, node );
203 
204  }
205  ++b_it;
206  }
207  this->Modified();
208  }
209 
211  void SetOutsidePoints(NodeContainer *points)
212  {
213  m_OutsidePoints = points;
214  this->Modified();
215  }
217 
220  void SetAlivePoints(NodeContainer *points)
221  {
222  m_AlivePoints = points;
223  this->Modified();
224  }
226 
228  NodeContainerPointer GetAlivePoints()
229  {
230  return m_AlivePoints;
231  }
232 
235  void SetTrialPoints(NodeContainer *points)
236  {
237  m_TrialPoints = points;
238  this->Modified();
239  }
241 
243  NodeContainerPointer GetTrialPoints()
244  {
245  return m_TrialPoints;
246  }
247 
249  LabelImagePointer GetLabelImage() const
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 
299  NodeContainerPointer GetProcessedPoints() const
300  {
301  return m_ProcessedPoints;
302  }
303 
310  virtual void SetOutputSize(const OutputSizeType & size)
311  { m_OutputRegion = size; }
312  virtual OutputSizeType GetOutputSize() const
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 
329  itkConceptMacro( SameDimensionCheck,
331  itkConceptMacro( SpeedConvertibleToDoubleCheck,
333  itkConceptMacro( DoubleConvertibleToLevelSetCheck,
335  itkConceptMacro( LevelSetOStreamWritableCheck,
337 
339 #endif
340 
341 protected:
344  void PrintSelf(std::ostream & os, Indent indent) const;
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();
358 
360  virtual void GenerateOutputInformation();
361 
362  virtual void EnlargeOutputRequestedRegion(DataObject *output);
363 
368  itkGetConstReferenceMacro(LargeValue, PixelType);
369 
371  typedef typename LevelSetImageType::IndexType LevelSetIndexType;
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;
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 
413 
415 };
416 } // namespace itk
417 
418 #ifndef ITK_MANUAL_INSTANTIATION
419 #include "itkFastMarchingImageFilter.hxx"
420 #endif
421 
422 #endif
423