OTB  10.0.0
Orfeo Toolbox
otbTwoNRIBandsImageToNComplexBandsImage.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 otbTwoNRIBandsImageToNComplexBandsImage_hxx
22 #define otbTwoNRIBandsImageToNComplexBandsImage_hxx
23 
24 #include "otbMacro.h" //for
26 
27 #include "itkImageRegionIterator.h"
28 #include "itkImageRegionConstIterator.h"
29 #include "itkProgressReporter.h"
30 #include "itkVariableLengthVector.h"
31 
32 
33 namespace otb
34 {
35 
39 template <class TInputImage, class TOutputImage>
41 {
42  this->DynamicMultiThreadingOn();
43  //this->SetNumberOfWorkUnits(1);
44 }
46 
50 template <class TInputImage, class TOutputImage>
52 {
53  Superclass::GenerateOutputInformation();
54 
55  unsigned int nbCompo = this->GetInput()->GetNumberOfComponentsPerPixel();
56 
57  if ((nbCompo % 2) != 0)
58  {
59  itkExceptionMacro("Number of bands of the input images must be an even number");
60  }
61  else
62  {
63  this->GetOutput()->SetNumberOfComponentsPerPixel(nbCompo / 2);
64  }
65 }
66 
70 template <class TInputImage, class TOutputImage>
72 {
73  unsigned int nbCompo = this->GetInput()->GetNumberOfComponentsPerPixel();
74 
75  if ((nbCompo % 2) != 0)
76  itkExceptionMacro("Number of bands of the input images must be an even number");
77 }
78 
82 template <class TInputImage, class TOutputImage>
84 {
85 
86  unsigned int nbCompo = this->GetInput()->GetNumberOfComponentsPerPixel();
87 
88  itk::VariableLengthVector<std::complex<typename InputPixelType::ValueType>> vlv(nbCompo / 2);
89 
90  itk::ImageRegionConstIterator<TInputImage> inIt;
91  inIt = itk::ImageRegionConstIterator<TInputImage>(this->GetInput(), outputRegionForThread);
92 
93  itk::ImageRegionIterator<OutputImageType> outIt;
94  outIt = itk::ImageRegionIterator<OutputImageType>(this->GetOutput(), outputRegionForThread);
95 
96 
97  inIt.GoToBegin();
98  outIt.GoToBegin();
99 
100  while (!outIt.IsAtEnd())
101  {
102 
103  unsigned int k = 0;
104  for (unsigned int i = 0; i < nbCompo - 1; i = i + 2)
105  {
106  vlv[k] = std::complex<typename InputPixelType::ValueType>(inIt.Get()[i], inIt.Get()[i + 1]);
107  k++;
108  }
109 
110 
111  outIt.Set(vlv);
112 
113 
114  ++inIt;
115  ++outIt;
116 
117  }
118 }
119 
123 template <class TInputImage, class TOutput>
124 void TwoNRIBandsImageToNComplexBandsImage<TInputImage, TOutput>::PrintSelf(std::ostream& os, itk::Indent indent) const
125 {
126  Superclass::PrintSelf(os, indent);
127 }
128 
129 } // end namespace otb
130 
131 #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.