Orfeo Toolbox  3.16
itkTernaryFunctorImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkTernaryFunctorImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-18 16:11:14 $
7  Version: $Revision: 1.39 $
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 __itkTernaryFunctorImageFilter_txx
18 #define __itkTernaryFunctorImageFilter_txx
19 
21 #include "itkImageRegionIterator.h"
23 #include "itkProgressReporter.h"
24 
25 namespace itk
26 {
27 
31 template < class TInputImage1, class TInputImage2,
32  class TInputImage3, class TOutputImage, class TFunction >
35 {
36  this->InPlaceOff();
37 }
38 
42 template <class TInputImage1, class TInputImage2,
43  class TInputImage3, class TOutputImage, class TFunction >
44 void
46 ::SetInput1( const TInputImage1 *image1 )
47 {
48  // The ProcessObject is not const-correct so the const_cast is required here
49  this->SetNthInput( 0, const_cast<TInputImage1 *>( image1 ) );
50 }
51 
55 template <class TInputImage1, class TInputImage2,
56  class TInputImage3, class TOutputImage, class TFunction >
57 void
59 ::SetInput2( const TInputImage2 *image2 )
60 {
61  // The ProcessObject is not const-correct so the const_cast is required here
62  this->SetNthInput( 1, const_cast<TInputImage2 *>( image2 ) );
63 }
64 
68 template <class TInputImage1, class TInputImage2,
69  class TInputImage3, class TOutputImage, class TFunction >
70 void
72 ::SetInput3( const TInputImage3 *image3 )
73 {
74  // The ProcessObject is not const-correct so the const_cast is required here
75  this->SetNthInput( 2, const_cast<TInputImage3 *>( image3 ) );
76 }
77 
81 template <class TInputImage1, class TInputImage2,
82  class TInputImage3, class TOutputImage, class TFunction >
83 void
86 {
87  Input1ImagePointer inputPtr1
88  = dynamic_cast<const TInputImage1*>((ProcessObject::GetInput(0)));
89  Input2ImagePointer inputPtr2
90  = dynamic_cast<const TInputImage2*>((ProcessObject::GetInput(1)));
91  Input3ImagePointer inputPtr3
92  = dynamic_cast<const TInputImage3*>((ProcessObject::GetInput(2)));
93  if (inputPtr1.IsNull() || inputPtr2.IsNull() || inputPtr3.IsNull())
94  {
95  itkExceptionMacro(<< "At least one input is missing."
96  << " Input1 is " << inputPtr1.GetPointer() << ", "
97  << " Input2 is " << inputPtr2.GetPointer() << ", "
98  << " Input3 is " << inputPtr3.GetPointer());
99  }
100 }
101 
105 template <class TInputImage1, class TInputImage2,
106  class TInputImage3, class TOutputImage, class TFunction >
107 void
109 ::ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread,
110  int threadId)
111 {
112  // We use dynamic_cast since inputs are stored as DataObjects. The
113  // ImageToImageFilter::GetInput(int) always returns a pointer to a
114  // TInputImage1 so it cannot be used for the second or third input.
115  Input1ImagePointer inputPtr1
116  = dynamic_cast<const TInputImage1*>((ProcessObject::GetInput(0)));
117  Input2ImagePointer inputPtr2
118  = dynamic_cast<const TInputImage2*>((ProcessObject::GetInput(1)));
119  Input3ImagePointer inputPtr3
120  = dynamic_cast<const TInputImage3*>((ProcessObject::GetInput(2)));
121  OutputImagePointer outputPtr = this->GetOutput(0);
122 
123  ImageRegionConstIterator<TInputImage1> inputIt1(inputPtr1, outputRegionForThread);
124  ImageRegionConstIterator<TInputImage2> inputIt2(inputPtr2, outputRegionForThread);
125  ImageRegionConstIterator<TInputImage3> inputIt3(inputPtr3, outputRegionForThread);
126  ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
127 
128  ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
129 
130  inputIt1.GoToBegin();
131  inputIt2.GoToBegin();
132  inputIt3.GoToBegin();
133  outputIt.GoToBegin();
134 
135 
136  while( !inputIt1.IsAtEnd() )
137  {
138  outputIt.Set( m_Functor(inputIt1.Get(), inputIt2.Get(), inputIt3.Get() ) );
139  ++inputIt1;
140  ++inputIt2;
141  ++inputIt3;
142  ++outputIt;
143  progress.CompletedPixel(); // potential exception thrown here
144  }
145 }
146 
147 } // end namespace itk
148 
149 #endif

Generated at Sun May 19 2013 00:10:05 for Orfeo Toolbox with doxygen 1.8.3.1