OTB  10.0.0
Orfeo Toolbox
otbNRIBandImagesToOneNComplexBandsImage.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 otbNRIBandImagesToOneNComplexBandsImage_hxx
22 #define otbNRIBandImagesToOneNComplexBandsImage_hxx
23 
25 
26 #include "itkImageRegionIterator.h"
27 #include "itkImageRegionConstIterator.h"
28 #include "itkProgressReporter.h"
29 #include "itkVariableLengthVector.h"
30 
31 
32 namespace otb
33 {
34 
38 template <class TInputImage, class TOutputImage>
40 {
41  // this->SetNumberOfWorkUnits(1);
42  this->DynamicMultiThreadingOn();
43 }
45 
49 template <class TInputImage, class TOutputImage>
51 {
52  Superclass::GenerateOutputInformation();
53 
54  unsigned int nbInputs = this->GetNumberOfInputs();
55  this->GetOutput()->SetNumberOfComponentsPerPixel(nbInputs);
56 }
57 
61 template <class TInputImage, class TOutputImage>
63 {
64  unsigned int nbInputs = this->GetNumberOfInputs();
65 
66  for (unsigned int i = 0; i < nbInputs; i++)
67  if (this->GetInput(i)->GetNumberOfComponentsPerPixel() != 2)
68  itkExceptionMacro("Input images must be made of two bands and only two (see input #" << i << ").");
69 }
70 
74 template <class TInputImage, class TOutputImage>
76 {
77 
78  unsigned int nbInputs = this->GetNumberOfInputs();
79 
80  itk::VariableLengthVector<std::complex<typename InputPixelType::ValueType>> vlv(nbInputs);
81 
82  std::vector<typename itk::ImageRegionConstIterator<TInputImage>> vInIt;
83  for (unsigned int i = 0; i < nbInputs; i++)
84  vInIt.push_back(itk::ImageRegionConstIterator<TInputImage>(this->GetInput(i), outputRegionForThread));
85 
86 
87  itk::ImageRegionIterator<OutputImageType> outIt;
88  outIt = itk::ImageRegionIterator<OutputImageType>(this->GetOutput(), outputRegionForThread);
89 
90  for (unsigned int i = 0; i < nbInputs; i++)
91  vInIt[i].GoToBegin();
92  outIt.GoToBegin();
93 
94  while (!outIt.IsAtEnd())
95  {
96 
97 
98  for (unsigned int i = 0; i < nbInputs; i++)
99  {
100  vlv[i] = std::complex<typename InputPixelType::ValueType>(vInIt[i].Get()[0], vInIt[i].Get()[1]);
101  // std::cout << "i = " << i << " " << vInIt[i].Get()[0] << " " << vInIt[i].Get()[1] << std::endl;
102  }
103 
104 
105  outIt.Set(vlv);
106 
107  // std::cout << "outIt.Get() = " << outIt.Get() << std::endl;
108 
109  for (unsigned int i = 0; i < nbInputs; i++)
110  ++vInIt[i];
111  ++outIt;
112 
113  }
114 }
115 
119 template <class TInputImage, class TOutput>
120 void NRIBandImagesToOneNComplexBandsImage<TInputImage, TOutput>::PrintSelf(std::ostream& os, itk::Indent indent) const
121 {
122  Superclass::PrintSelf(os, indent);
123 }
124 
125 } // end namespace otb
126 
127 #endif
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
void PrintSelf(std::ostream &os, itk::Indent indent) const override
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.