Orfeo Toolbox  3.16
itkApproximateSignedDistanceMapImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkApproximateSignedDistanceMapImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-07 14:49:30 $
7  Version: $Revision: 1.3 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkApproximateSignedDistanceMapImageFilter_txx
18 #define __itkApproximateSignedDistanceMapImageFilter_txx
19 
21 
22 #include "itkNumericTraits.h"
23 #include "itkImageRegionIterator.h"
24 #include "itkProgressAccumulator.h"
25 #include "vcl_cmath.h"
26 
27 namespace itk {
28 
32 template <class TInputImage, class TOutputImage>
35  m_IsoContourFilter( IsoContourType::New() ),
36  m_ChamferFilter( ChamferType::New() ),
37  m_InsideValue( NumericTraits<InputPixelType>::min() ),
38  m_OutsideValue( NumericTraits<InputPixelType>::max() )
39 {
40 // I'm not setting any of the ReleaseDataFlag values for the mini-pipeline
41 // filters. Should I be?
42 }
43 
47 template <class TInputImage, class TOutputImage>
48 void
51 {
52  // calculate the largest possible distance in the output image.
53  // this maximum is the distance from one corner of the image to the other.
54  OutputSizeType outputSize = this->GetOutput()->GetRequestedRegion().GetSize();
55  OutputSizeValueType maximumDistance = 0;
56  for (unsigned int i = 0; i < InputImageDimension; i++)
57  {
58  maximumDistance += outputSize[i]*outputSize[i];
59  }
60  // cast to float and back because there's no sqrt defined for unsigned long double,
61  // which is the general SizeValueType.
62  maximumDistance =
63  static_cast<OutputSizeValueType>(vcl_sqrt(static_cast<float>(maximumDistance)));
64 
65  // Allocate the output
66  this->AllocateOutputs();
67 
68  // Create a process accumulator for tracking the progress of this minipipeline
70  progress->SetMiniPipelineFilter(this);
71  progress->RegisterInternalFilter(m_IsoContourFilter, 0.5f);
72  progress->RegisterInternalFilter(m_ChamferFilter, 0.5f);
73 
74  // set up the isocontour filter
75  m_IsoContourFilter->SetInput(this->GetInput());
76  m_IsoContourFilter->SetFarValue(maximumDistance + 1);
77  InputPixelType levelSetValue = (m_InsideValue + m_OutsideValue) / 2;
78  m_IsoContourFilter->SetLevelSetValue(levelSetValue);
79 
80  // set up the chamfer filter
81  m_ChamferFilter->SetInput(m_IsoContourFilter->GetOutput());
82  m_ChamferFilter->SetMaximumDistance(maximumDistance);
83 
84  // graft our output to the chamfer filter to force the proper regions
85  // to be generated
86  m_ChamferFilter->GraftOutput( this->GetOutput() );
87 
88  // create the distance map
89  m_ChamferFilter->Update();
90 
91  // graft the output of the chamfer filter back onto this filter's
92  // output. this is needed to get the appropriate regions passed
93  // back.
94  this->GraftOutput( m_ChamferFilter->GetOutput() );
95 
96  // Recall that we set the isocontour value to halfway between the inside and
97  // oustide value. The above filters assume that regions "inside" objects are
98  // those with values *less* than the isocontour. This assumption is violated
99  // if the "inside" intensity value is greater than the "outside" value.
100  // (E.g. in the case that we're computing the distance from a mask where the
101  // background is zero and the objects are colored 255.)
102  // In this case, the distance will be calculated negative, so we need to
103  // flip the sign of the output image.
104  if (m_InsideValue > m_OutsideValue)
105  {
106  ImageRegionIterator< OutputImageType > ot( this->GetOutput(),
107  this->GetOutput()->GetRequestedRegion() );
108  ot.GoToBegin();
109  while( !ot.IsAtEnd() )
110  {
111  ot.Set(ot.Get() * -1);
112  ++ot;
113  }
114  }
115 }
116 
117 template<class TInputImage, class TOutputImage>
118 void
120 ::PrintSelf(std::ostream &os, Indent indent) const
121 {
122  Superclass::PrintSelf(os, indent);
123 
124  os << indent << "Inside intensity value: " << m_InsideValue << std::endl;
125  os << indent << "Outside intensity value: " << m_OutsideValue << std::endl;
126  os << indent << "IsoContourDistanceImageFilter (used internally): "
127  << m_IsoContourFilter << std::endl;
128  os << indent << "FastChamferDistanceImageFilter (used internally): "
129  << m_ChamferFilter << std::endl;
130 
131 }
132 
133 
134 } // end of namespace itk
135 
136 #endif

Generated at Sat Feb 2 2013 23:24:10 for Orfeo Toolbox with doxygen 1.8.1.1