OTB  9.0.0
Orfeo Toolbox
otbImageToProfileFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 otbImageToProfileFilter_hxx
22 #define otbImageToProfileFilter_hxx
23 
25 
26 namespace otb
27 {
31 template <class TInputImage, class TOutputImage, class TFilter, class TParameter>
33  : m_Filter(FilterType::New()),
34  m_ProfileSize(10),
35  m_InitialValue(0),
36  m_Step(1),
37  m_OutputIndex(0)
38 {
39 }
40 
44 template <class TInputImage, class TOutputImage, class TFilter, class TParameter>
45 void ImageToProfileFilter<TInputImage, TOutputImage, TFilter, TParameter>::GenerateOutputInformation(void)
46 {
47  // Retrieving input/output pointers
48  InputImagePointerType inputPtr = this->GetInput();
49  OutputImageListPointerType outputPtr = this->GetOutput();
50  if (outputPtr)
51  {
52  if (outputPtr->Size() != m_ProfileSize)
53  {
54  // in this case, clear the list
55  outputPtr->Clear();
56  for (unsigned int i = 0; i < m_ProfileSize; ++i)
57  {
58  // Create the output image
59  outputPtr->PushBack(OutputImageType::New());
60  }
61  }
62  // For each output image
63  typename OutputImageListType::Iterator outputListIt = outputPtr->Begin();
64  m_Filter->SetInput(inputPtr);
65  m_Filter->UpdateOutputInformation();
66  while (outputListIt != outputPtr->End())
67  {
68  // Set the image information
69  outputListIt.Get()->CopyInformation(m_Filter->GetOutput(m_OutputIndex));
70  outputListIt.Get()->SetLargestPossibleRegion(m_Filter->GetOutput(m_OutputIndex)->GetLargestPossibleRegion());
71  ++outputListIt;
72  }
73  }
74 }
75 
79 template <class TInputImage, class TOutputImage, class TFilter, class TParameter>
80 void ImageToProfileFilter<TInputImage, TOutputImage, TFilter, TParameter>::GenerateInputRequestedRegion(void)
81 {
82  // Retrieving input/output pointers
83  InputImagePointerType inputPtr = this->GetInput();
84  OutputImageListPointerType outputPtr = this->GetOutput();
86 
87  // For each output image
88  typename OutputImageListType::Iterator outputListIt = outputPtr->Begin();
89 
90  m_Filter->SetInput(inputPtr);
91 
92  // Use the filter to generate input requested region
93  while (outputListIt != outputPtr->End())
94  {
95  m_Filter->GetOutput(m_OutputIndex)->SetRequestedRegion(outputListIt.Get()->GetRequestedRegion());
96  m_Filter->PropagateRequestedRegion(outputListIt.Get());
97  ++outputListIt;
98  }
99 }
103 template <class TInputImage, class TOutputImage, class TFilter, class TParameter>
104 void ImageToProfileFilter<TInputImage, TOutputImage, TFilter, TParameter>::GenerateData(void)
105 {
106  // Retrieving input/output pointers
107  InputImagePointerType inputPtr = this->GetInput();
108  OutputImageListPointerType outputPtr = this->GetOutput();
109  m_Filter->SetInput(inputPtr);
111 
112  for (unsigned int i = 0; i < m_ProfileSize; ++i)
113  {
114  ParameterType profileParameter = m_InitialValue + static_cast<ParameterType>(i) * m_Step;
115  this->SetProfileParameter(profileParameter);
116  m_Filter->GetOutput(m_OutputIndex)->SetRequestedRegion(outputPtr->GetNthElement(i)->GetRequestedRegion());
117  m_Filter->Update();
118  outputPtr->SetNthElement(i, static_cast<OutputImageType*>(m_Filter->GetOutput(m_OutputIndex)));
119  outputPtr->GetNthElement(i)->DisconnectPipeline();
120  }
121 }
122 
otb::ImageToProfileFilter::ImageToProfileFilter
ImageToProfileFilter()
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbImageToProfileFilter.h
otb::Wrapper::ParameterType
ParameterType
Definition: otbWrapperTypes.h:37