Orfeo Toolbox  3.16
itkConvolutionImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: itkConvolutionImageFilter.txx,v $
5 Language: C++
6 Date: $Date: 2009-10-29 15:03:32 $
7 Version: $Revision: 1.10 $
8 
9 Copyright (c) Insight Software Consortium. All rights reser
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for detail.
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 __itkConvolutionImageFilter_txx
18 #define __itkConvolutionImageFilter_txx
19 
21 
22 #include "itkImageBase.h"
23 #include "itkImageKernelOperator.h"
24 #include "itkImageRegionIterator.h"
28 #include "itkProgressReporter.h"
29 
30 #include "vnl/vnl_math.h"
31 
32 namespace itk {
33 
34 template<class TInputImage, class TOutputImage>
37 {
38  this->SetNumberOfRequiredInputs( 2 );
39  m_Normalize = false;
40 }
41 
42 template<class TInputImage, class TOutputImage>
45 {
46 }
47 
48 template<class TInputImage, class TOutputImage>
49 void
51 ::ThreadedGenerateData(const OutputRegionType& outputRegionForThread, int threadId)
52 {
53 
54  // setup the progress reporter
55  ProgressReporter progress( this, threadId, outputRegionForThread.GetNumberOfPixels() );
56 
57  typedef ConstNeighborhoodIterator<InputImageType> NeighborhoodIteratorType;
58  typedef typename NeighborhoodIteratorType::RadiusType RadiusType;
59  typedef typename RadiusType::SizeValueType SizeValueType;
60  RadiusType radius;
61  for( unsigned int i = 0; i < ImageDimension; i++ )
62  {
63  radius[i] = Math::Floor< SizeValueType >( 0.5 *
64  this->GetImageKernelInput()->GetLargestPossibleRegion().GetSize()[i] );
65  }
66 
67  double scalingFactor = 1.0;
68  if( this->GetNormalize() )
69  {
70  double sum = 0.0;
71  ImageRegionConstIterator<InputImageType> It( this->GetImageKernelInput(),
72  this->GetImageKernelInput()->GetLargestPossibleRegion() );
73  for( It.GoToBegin(); !It.IsAtEnd(); ++It )
74  {
75  sum += static_cast<double>( It.Get() );
76  }
77  if( sum != 0.0 )
78  {
79  scalingFactor = 1.0 / sum;
80  }
81  }
82 
83  typedef typename NeighborhoodAlgorithm
85  FaceCalculatorType faceCalculator;
86 
88 
90  imageKernelOperator.SetImageKernel( const_cast<InputImageType*>(
91  static_cast<const InputImageType*>(
92  this->ProcessObject::GetInput( 1 ) ) ) );
93  imageKernelOperator.CreateToRadius( radius );
94 
95  typename FaceCalculatorType::FaceListType faceList = faceCalculator(
96  this->GetInput( 0 ), outputRegionForThread, radius );
97  typename FaceCalculatorType::FaceListType::iterator fit;
98 
99  for( fit = faceList.begin(); fit != faceList.end(); ++fit )
100  {
101  NeighborhoodIteratorType inIt( radius, this->GetInput( 0 ), *fit );
102  ImageRegionIterator<OutputImageType> outIt( this->GetOutput(), *fit );
103 
104  for( inIt.GoToBegin(), outIt.GoToBegin(); !inIt.IsAtEnd();
105  ++inIt, ++outIt )
106  {
107  outIt.Set( static_cast<OutputPixelType>(
108  scalingFactor * innerProduct( inIt, imageKernelOperator ) ) );
109  progress.CompletedPixel();
110  }
111  }
112 }
113 
122 template <class TInputImage, class TOutputImage>
123 void
126 {
127  // Simply copy the GenerateInputRequestedRegion() function and
128  // deal with the image kernel as a special case.
129  for( unsigned int idx = 0; idx < 2; ++idx )
130  {
131  if( this->GetInput( idx ) )
132  {
133  // Check whether the input is an image of the appropriate
134  // dimension (use ProcessObject's version of the GetInput()
135  // method since it returns the input as a pointer to a
136  // DataObject as opposed to the subclass version which
137  // static_casts the input to an TInputImage).
138  typedef ImageBase<ImageDimension> ImageBaseType;
139  typename ImageBaseType::ConstPointer constInput
140  = dynamic_cast<ImageBaseType const *>(
141  this->ProcessObject::GetInput( idx ) );
142 
143  if ( constInput.IsNull() )
144  {
145  itkExceptionMacro( "Input image " << idx
146  << " not correctly specified." );
147  }
148 
149  // Input is an image, cast away the constness so we can set
150  // the requested region.
151  typename InputImageType::Pointer input =
152  const_cast<TInputImage *>( this->GetInput( idx ) );
153 
154  typename InputImageType::RegionType inputRegion;
155  if( idx == 0 )
156  {
157  Superclass::CallCopyOutputRegionToInputRegion( inputRegion,
158  this->GetOutput()->GetRequestedRegion() );
159  }
160  else // the input is the image kernel
161  {
162  typename InputImageType::RegionType::SizeType inputSize;
163  typename InputImageType::RegionType::IndexType inputIndex;
164  inputSize = this->GetInput(
165  idx )->GetLargestPossibleRegion().GetSize();
166  inputIndex = this->GetInput(
167  idx )->GetLargestPossibleRegion().GetIndex();
168  inputRegion.SetSize(inputSize);
169  inputRegion.SetIndex(inputIndex);
170  }
171  input->SetRequestedRegion( inputRegion );
172  }
173  }
174 
175 }
176 
177 
178 template <class TInputImage, class TOutputImage>
179 void
181 ::PrintSelf(std::ostream &os, Indent indent) const
182 {
183  Superclass::PrintSelf(os, indent);
184 
185  os << indent << "Normalize: " << m_Normalize << std::endl;
186  // NOT REALLY MEMBER DATA. Need to fool PrintSelf check
187  // os << indent << "ImageKernel: " << m_ImageKernel << std::e0ndl;
188 
189 }
190 
191 
192 }
193 #endif

Generated at Sat May 18 2013 23:34:58 for Orfeo Toolbox with doxygen 1.8.3.1