OTB  6.7.0
Orfeo Toolbox
otbImageListToImageListApplyFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbImageListToImageListApplyFilter_hxx
22 #define otbImageListToImageListApplyFilter_hxx
23 
25 
26 namespace otb
27 {
31 template <class TInputImageList, class TOutputImageList, class TFilter>
34 {
35  m_Filter = FilterType::New();
36  m_OutputIndex = 0;
37 }
38 
41 template <class TInputImageList, class TOutputImageList, class TFilter>
42 void
45 {
46  // Retrieving input/output pointers
47  InputImageListPointerType inputPtr = this->GetInput();
48  OutputImageListPointerType outputPtr = this->GetOutput();
49  if (outputPtr)
50  {
51  if (outputPtr->Size() != inputPtr->Size())
52  {
53  // in this case, clear the list
54  outputPtr->Clear();
55  typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
56  while (inputListIt != inputPtr->End())
57  {
58  outputPtr->PushBack(OutputImageType::New());
59  ++inputListIt;
60  }
61  }
63 
64  // For each input image
65  typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
66  typename OutputImageListType::Iterator outputListIt = outputPtr->Begin();
67 
68  while (inputListIt != inputPtr->End() && outputListIt != outputPtr->End())
69  {
70  // Create the output image and set its information
71 
72  m_Filter->SetInput(inputListIt.Get());
73  m_Filter->UpdateOutputInformation();
74  outputListIt.Get()->CopyInformation(m_Filter->GetOutput(m_OutputIndex));
75  outputListIt.Get()->SetLargestPossibleRegion(m_Filter->GetOutput(m_OutputIndex)->GetLargestPossibleRegion());
76  ++inputListIt;
77  ++outputListIt;
78  }
79  }
80 }
82 template <class TInputImageList, class TOutputImageList, class TFilter>
83 void
86 {
87  // Retrieving input/output pointers
88  InputImageListPointerType inputPtr = this->GetInput();
89  OutputImageListPointerType outputPtr = this->GetOutput();
91 
92  // For each input image and corresponding output image
93  typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
94  typename OutputImageListType::Iterator outputListIt = outputPtr->Begin();
95 
96  // Use the filter to generate input requested region
97  while (inputListIt != inputPtr->End() && outputListIt != outputPtr->End())
98  {
99  m_Filter->SetInput(inputListIt.Get());
100  m_Filter->GetOutput(m_OutputIndex)->SetRequestedRegion(outputListIt.Get()->GetRequestedRegion());
101  m_Filter->PropagateRequestedRegion(outputListIt.Get());
102  ++inputListIt;
103  ++outputListIt;
104  }
105 }
107 template <class TInputImageList, class TOutputImageList, class TFilter>
108 void
111 {
112  // Retrieving input/output pointers
113  InputImageListPointerType inputPtr = this->GetInput();
114  OutputImageListPointerType outputPtr = this->GetOutput();
116 
117  // For each input image and corresponding output image
118  typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
119  typename OutputImageListType::Iterator outputListIt = outputPtr->Begin();
120  unsigned int counter = 0;
121 
122  while (inputListIt != inputPtr->End() && outputListIt != outputPtr->End())
123  {
124  m_Filter->SetInput(inputListIt.Get());
125  m_Filter->GetOutput(m_OutputIndex)->SetRequestedRegion(outputListIt.Get()->GetRequestedRegion());
126  m_Filter->Update();
127  outputPtr->SetNthElement(counter, static_cast<OutputImageType *>(m_Filter->GetOutput(m_OutputIndex)));
128  outputListIt.Get()->DisconnectPipeline();
129  ++inputListIt;
130  ++outputListIt;
131  ++counter;
132  }
133 }
void GenerateInputRequestedRegion(void) override
void GenerateOutputInformation(void) override