OTB  10.0.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-2024 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 
28 namespace otb
29 {
30 
34 template <class TInputImage, class TOutputImage, class TFunction>
36 {
37  this->InPlaceOff();
38  m_PixelFunction = FunctionType::New();
39  this->DynamicMultiThreadingOn();
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 {
77 
78  // We use dynamic_cast since inputs are stored as DataObjects.
79  InputImagePointer inputPtr = dynamic_cast<const TInputImage*>((itk::ProcessObject::GetInput(0)));
80 
81  OutputImagePointer outputPtr = this->GetOutput(0);
82 
83  itk::ImageRegionConstIterator<TInputImage> inputIt(inputPtr, outputRegionForThread);
84  itk::ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
85 
86  inputIt.GoToBegin();
87  outputIt.GoToBegin();
88 
89 
90  while (!inputIt.IsAtEnd())
91  {
92  outputIt.Set(static_cast<OutputImagePixelType>(m_PixelFunction->EvaluateAtIndex(inputIt.GetIndex())));
93  ++inputIt;
94  ++outputIt;
95  }
96 }
97 } // end namespace otb
98 
99 #endif
OutputImageType::RegionType OutputImageRegionType
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
InputImageType::ConstPointer InputImagePointer
OutputImageType::PixelType OutputImagePixelType
OutputImageType::Pointer OutputImagePointer
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.