OTB  9.0.0
Orfeo Toolbox
otbPerBandVectorImageFilter.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 otbPerBandVectorImageFilter_hxx
22 #define otbPerBandVectorImageFilter_hxx
23 
25 
26 namespace otb
27 {
31 template <class TInputImage, class TOutputImage, class TFilter>
33 {
34  m_Filter = FilterType::New();
35  m_OutputIndex = 0;
36 }
38 
39 template <class TInputImage, class TOutputImage, class TFilter>
41 {
42  if (this->GetInput())
43  {
44  // Create a false monoband image
45  typename InputImageType::Pointer dummyInputImage = InputImageType::New();
46  dummyInputImage->CopyInformation(this->GetInput());
47  dummyInputImage->SetNumberOfComponentsPerPixel(1);
48  m_Filter->SetInput(dummyInputImage);
49  m_Filter->UpdateOutputInformation();
50  this->GetOutput()->CopyInformation(m_Filter->GetOutput(m_OutputIndex));
51  this->GetOutput()->SetNumberOfComponentsPerPixel(this->GetInput()->GetNumberOfComponentsPerPixel());
52 
53  // Override default metadata copying behavior and copy all metadata from input to output.
54  this->GetOutput()->SetImageMetadata(this->GetInput()->GetImageMetadata());
55  }
56 }
57 
58 template <class TInputImage, class TOutputImage, class TFilter>
60 {
61  InputVectorImageType* inputPtr = const_cast<InputVectorImageType*>(this->GetInput());
62  typename InputImageType::Pointer dummyInputImage = InputImageType::New();
63  dummyInputImage->CopyInformation(this->GetInput());
64  dummyInputImage->SetNumberOfComponentsPerPixel(1);
65  m_Filter->SetInput(dummyInputImage);
66  m_Filter->GetOutput(m_OutputIndex)->SetRequestedRegion(this->GetOutput()->GetRequestedRegion());
67  m_Filter->PropagateRequestedRegion(this->GetOutput());
68  inputPtr->SetRequestedRegion(m_Filter->GetInput()->GetRequestedRegion());
69 }
73 template <class TInputImage, class TOutputImage, class TFilter>
75 {
76  InputVectorImageType* inputPtr = const_cast<InputVectorImageType*>(this->GetInput());
77  OutputVectorImagePointerType outputPtr = this->GetOutput();
78  DecompositionFilterPointerType decomposer = DecompositionFilterType::New();
79  ProcessingFilterPointerType processor = ProcessingFilterType::New();
80  RecompositionFilterPointerType recomposer = RecompositionFilterType::New();
82 
83  inputPtr->UpdateOutputData();
84 
85  decomposer->SetInput(this->GetInput());
86  processor->SetInput(decomposer->GetOutput());
87  processor->SetFilter(m_Filter);
88  processor->SetOutputIndex(m_OutputIndex);
89  recomposer->SetInput(processor->GetOutput());
90  recomposer->GetOutput()->SetRequestedRegion(this->GetOutput()->GetRequestedRegion());
91 
92  recomposer->GraftOutput(this->GetOutput());
93  recomposer->Update();
94  this->GraftOutput(recomposer->GetOutput());
95 }
otb::PerBandVectorImageFilter::GenerateOutputInformation
void GenerateOutputInformation(void) override
otb::PerBandVectorImageFilter::GenerateInputRequestedRegion
void GenerateInputRequestedRegion(void) override
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbPerBandVectorImageFilter.h
otb::PerBandVectorImageFilter::PerBandVectorImageFilter
PerBandVectorImageFilter()
otb::PerBandVectorImageFilter::GenerateData
void GenerateData(void) override