OTB  7.1.0
Orfeo Toolbox
otbFunctionToImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbFunctionToImageFilter_hxx
23 #define otbFunctionToImageFilter_hxx
24 
26 #include "itkImageRegionConstIterator.h"
27 #include "itkProgressReporter.h"
28 
29 namespace otb
30 {
31 
35 template <class TInputImage, class TOutputImage, class TFunction>
37 {
38  this->InPlaceOff();
39  m_PixelFunction = FunctionType::New();
40 }
42 
46 // template<class TInputImage, class TOutputImage, class TFunction >
47 // void
48 // FunctionToImageFilter<TInputImage, TOutputImage, TFunction>
49 // ::SetInput( const TInputImage *image )
50 // {
51 // // The ProcessObject is not const-correct so the const_cast is required here
52 // SetNthInput( 0, const_cast<TInputImage *>( image ) );
53 // }
54 
58 template <class TInputImage, class TOutputImage, class TFunction>
60 {
61  InputImagePointer inputPtr = dynamic_cast<const TInputImage*>((itk::ProcessObject::GetInput(0)));
62  if (inputPtr.IsNull())
63  {
64  itkExceptionMacro(<< "At least one input is missing."
65  << " Input is missing :" << inputPtr.GetPointer();)
66  }
67  m_PixelFunction->SetInputImage(inputPtr);
68 }
70 
74 template <class TInputImage, class TOutputImage, class TFunction>
76  itk::ThreadIdType threadId)
77 {
78 
79  // We use dynamic_cast since inputs are stored as DataObjects.
80  InputImagePointer inputPtr = dynamic_cast<const TInputImage*>((itk::ProcessObject::GetInput(0)));
81 
82  OutputImagePointer outputPtr = this->GetOutput(0);
83 
84  itk::ImageRegionConstIterator<TInputImage> inputIt(inputPtr, outputRegionForThread);
85  itk::ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
86 
87  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
88 
89  inputIt.GoToBegin();
90  outputIt.GoToBegin();
91 
92 
93  while (!inputIt.IsAtEnd())
94  {
95  outputIt.Set(static_cast<OutputImagePixelType>(m_PixelFunction->EvaluateAtIndex(inputIt.GetIndex())));
96  ++inputIt;
97  ++outputIt;
98  progress.CompletedPixel(); // potential exception thrown here
99  }
100 }
101 } // end namespace otb
102 
103 #endif
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.