Orfeo Toolbox  3.16
itkBinaryFunctorImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkBinaryFunctorImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-07 17:31:02 $
7  Version: $Revision: 1.40 $
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 __itkBinaryFunctorImageFilter_txx
18 #define __itkBinaryFunctorImageFilter_txx
19 
21 #include "itkImageRegionIterator.h"
23 #include "itkProgressReporter.h"
24 
25 namespace itk
26 {
27 
31 template <class TInputImage1, class TInputImage2,
32  class TOutputImage, class TFunction >
35 {
36  this->SetNumberOfRequiredInputs( 2 );
37  this->InPlaceOff();
38 }
39 
40 
44 template <class TInputImage1, class TInputImage2,
45  class TOutputImage, class TFunction >
46 void
48 ::SetInput1( const TInputImage1 * image1 )
49 {
50  // Process object is not const-correct so the const casting is required.
51  this->SetNthInput(0, const_cast<TInputImage1 *>( image1 ));
52 }
53 
54 
58 template <class TInputImage1, class TInputImage2,
59  class TOutputImage, class TFunction >
60 void
62 ::SetInput2( const TInputImage2 * image2 )
63 {
64  // Process object is not const-correct so the const casting is required.
65  this->SetNthInput(1, const_cast<TInputImage2 *>( image2 ));
66 }
67 
71 template <class TInputImage1, class TInputImage2, class TOutputImage, class TFunction >
72 void
74 ::ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread,
75  int threadId)
76 {
77  // We use dynamic_cast since inputs are stored as DataObjects. The
78  // ImageToImageFilter::GetInput(int) always returns a pointer to a
79  // TInputImage1 so it cannot be used for the second input.
80  Input1ImagePointer inputPtr1
81  = dynamic_cast<const TInputImage1*>(ProcessObject::GetInput(0));
82  Input2ImagePointer inputPtr2
83  = dynamic_cast<const TInputImage2*>(ProcessObject::GetInput(1));
84  OutputImagePointer outputPtr = this->GetOutput(0);
85 
86  ImageRegionConstIterator<TInputImage1> inputIt1(inputPtr1, outputRegionForThread);
87  ImageRegionConstIterator<TInputImage2> inputIt2(inputPtr2, outputRegionForThread);
88 
89  ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
90 
91  ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
92 
93  inputIt1.GoToBegin();
94  inputIt2.GoToBegin();
95  outputIt.GoToBegin();
96 
97  while( !inputIt1.IsAtEnd() )
98  {
99  outputIt.Set( m_Functor( inputIt1.Get(), inputIt2.Get() ) );
100  ++inputIt2;
101  ++inputIt1;
102  ++outputIt;
103  progress.CompletedPixel(); // potential exception thrown here
104  }
105 }
106 
107 } // end namespace itk
108 
109 #endif

Generated at Sat Feb 2 2013 23:26:37 for Orfeo Toolbox with doxygen 1.8.1.1