Orfeo Toolbox  3.16
itkNaryFunctorImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkNaryFunctorImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2009-03-05 09:46:31 $
7  Version: $Revision: 1.24 $
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 __itkNaryFunctorImageFilter_txx
18 #define __itkNaryFunctorImageFilter_txx
19 
21 #include "itkImageRegionIterator.h"
22 #include "itkProgressReporter.h"
23 
24 namespace itk
25 {
26 
30 template <class TInputImage, class TOutputImage, class TFunction >
33 {
34  // This number will be incremented each time an image
35  // is added over the two minimum required
36  this->SetNumberOfRequiredInputs( 2 );
37  this->InPlaceOff();
38 }
39 
40 
44 template <class TInputImage, class TOutputImage, class TFunction>
45 void
47 ::ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread,
48  int threadId)
49 {
50 
51  const unsigned int numberOfInputImages =
52  static_cast< unsigned int >( this->GetNumberOfInputs() );
53 
54  typedef ImageRegionConstIterator<TInputImage> ImageRegionConstIteratorType;
55  std::vector< ImageRegionConstIteratorType * > inputItrVector;
56  inputItrVector.reserve( numberOfInputImages );
57 
58  // support progress methods/callbacks.
59  // count the number of inputs that are non-null
60  for (unsigned int i=0; i < numberOfInputImages; ++i)
61  {
62  InputImagePointer inputPtr =
63  dynamic_cast<TInputImage*>( ProcessObject::GetInput( i ) );
64 
65  if (inputPtr)
66  {
67  inputItrVector.push_back( new ImageRegionConstIteratorType(inputPtr,outputRegionForThread) );
68  }
69  }
70  ProgressReporter progress(this, threadId,
71  outputRegionForThread.GetNumberOfPixels());
72 
73  const unsigned int numberOfValidInputImages = inputItrVector.size();
74 
75  if( numberOfValidInputImages==0 )
76  {
77  //No valid regions in the thread
78  //(and no region iterators to delete)
79  return;
80  }
81 
82 
83  NaryArrayType naryInputArray( numberOfValidInputImages );
84 
85  OutputImagePointer outputPtr = this->GetOutput(0);
86  ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
87 
88  typename std::vector< ImageRegionConstIteratorType * >::iterator regionIterators;
89  const typename std::vector< ImageRegionConstIteratorType * >::const_iterator regionItEnd
90  = inputItrVector.end();
91 
92  typename NaryArrayType::iterator arrayIt;
93 
94  while( !outputIt.IsAtEnd() )
95  {
96  arrayIt = naryInputArray.begin();
97  regionIterators = inputItrVector.begin();
98  while ( regionIterators != regionItEnd )
99  {
100  *arrayIt++ = (*regionIterators)->Get();
101  ++(*(*regionIterators));
102  ++regionIterators;
103  }
104  outputIt.Set( m_Functor( naryInputArray ) );
105  ++outputIt;
106  progress.CompletedPixel();
107  }
108 
109  // Free memory
110  regionIterators = inputItrVector.begin();
111  while ( regionIterators != regionItEnd )
112  {
113  delete (*regionIterators++);
114  }
115 }
116 
117 } // end namespace itk
118 
119 #endif

Generated at Sat Feb 2 2013 23:55:40 for Orfeo Toolbox with doxygen 1.8.1.1