OTB  9.0.0
Orfeo Toolbox
otbVariableLengthVectorConverter.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 otbVariableLengthVectorConverter_hxx
22 #define otbVariableLengthVectorConverter_hxx
23 
25 #include <complex>
26 
27 
28 namespace otb
29 {
30 
31 // Real Matrix
32 template <class TInternalInputType, class TPrecisionType>
33 typename VariableLengthVectorConverter<std::vector<std::vector<TInternalInputType>>, TPrecisionType>::OutputType
35 {
36  unsigned int p, q;
37  unsigned int count = 0;
38  unsigned int rsltIdx = 0;
39 
40  OutputType result;
41 
42  p = input.size();
43 
44  for (unsigned int l = 0; l < p; ++l)
45  {
46  count += input.at(l).size();
47  }
48 
49  result.SetSize(count);
50 
51  for (unsigned int i = 0; i < p; ++i)
52  {
53  q = input.at(i).size();
54  for (unsigned int j = 0; j < q; ++j)
55  {
56  result[rsltIdx] = static_cast<OutputPrecisionType>(input.at(i).at(j));
57  rsltIdx++;
58  }
59  }
60 
61  return result;
62 }
63 
64 // Complex Matrix
65 template <class TInternalInputType, class TPrecisionType>
68 {
69  unsigned int p, q;
70  unsigned int count = 0;
71  unsigned int rsltIdx = 0;
72  OutputType result;
73 
74  p = input.size();
75 
76  for (unsigned int l = 0; l < p; ++l)
77  {
78  count += input.at(l).size();
79  }
80 
81  result.SetSize(count * 2);
82 
83  for (unsigned int i = 0; i < p; ++i)
84  {
85  q = input.at(i).size();
86  for (unsigned int j = 0; j < q; ++j)
87  {
88  result[rsltIdx] = static_cast<OutputPrecisionType>(input.at(i).at(j).real());
89  rsltIdx++;
90  result[rsltIdx] = static_cast<OutputPrecisionType>(input.at(i).at(j).imag());
91  rsltIdx++;
92  }
93  }
94  return result;
95 }
96 
97 // Fixed Array
98 template <class TInternalInputType, unsigned int VArrayDimension, class TPrecisionType>
101 {
102  unsigned int rsltIdx = 0;
103  OutputType result;
104 
105  result.SetSize(VArrayDimension);
106 
107  for (unsigned int i = 0; i < VArrayDimension; ++i)
108  {
109  result[rsltIdx] = static_cast<OutputPrecisionType>(input[i]);
110  rsltIdx++;
111  }
112  return result;
113 }
114 
115 // Histogram
116 template <class TPixel, class TPrecisionType>
119 {
120  unsigned int rsltIdx = 0;
121  itk::Size<1> nbBins;
122  OutputType result;
123 
124  nbBins[0] = input->GetSize()[0];
125 
126  result.SetSize(nbBins[0]);
127 
128  for (unsigned int i = 0; i < nbBins[0]; ++i)
129  {
130  result[rsltIdx] = static_cast<OutputPrecisionType>(input->GetFrequency(i));
131  rsltIdx++;
132  }
133  return result;
134 }
135 
136 } // namespace otb
137 
138 #endif
otb::VariableLengthVectorConverter< itk::SmartPointer< itk::Statistics::Histogram< TPixel > >, TPrecisionType >::InputType
itk::SmartPointer< itk::Statistics::Histogram< TPixel > > InputType
Definition: otbVariableLengthVectorConverter.h:280
otb::VariableLengthVectorConverter< itk::SmartPointer< itk::Statistics::Histogram< TPixel > >, TPrecisionType >::OutputType
itk::VariableLengthVector< OutputPrecisionType > OutputType
Definition: otbVariableLengthVectorConverter.h:279
otb::VariableLengthVectorConverter
Convert any data container type into a VariableLengthVector.
Definition: otbVariableLengthVectorConverter.h:46
otb::VariableLengthVectorConverter< itk::FixedArray< TInternalInputType, VArrayDimension >, TPrecisionType >::OutputType
itk::VariableLengthVector< OutputPrecisionType > OutputType
Definition: otbVariableLengthVectorConverter.h:238
otb::VariableLengthVectorConverter< std::vector< std::vector< TInternalInputType > >, TPrecisionType >::OutputPrecisionType
TPrecisionType OutputPrecisionType
Definition: otbVariableLengthVectorConverter.h:151
otb::VariableLengthVectorConverter< std::vector< std::vector< TInternalInputType > >, TPrecisionType >::InputType
std::vector< std::vector< TInternalInputType > > InputType
Definition: otbVariableLengthVectorConverter.h:155
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::VariableLengthVectorConverter< std::vector< std::vector< std::complex< TInternalInputType > > >, TPrecisionType >::OutputType
itk::VariableLengthVector< OutputPrecisionType > OutputType
Definition: otbVariableLengthVectorConverter.h:196
otb::VariableLengthVectorConverter< std::vector< std::vector< std::complex< TInternalInputType > > >, TPrecisionType >::InputType
std::vector< std::vector< std::complex< TInternalInputType > > > InputType
Definition: otbVariableLengthVectorConverter.h:197
otb::VariableLengthVectorConverter< itk::FixedArray< TInternalInputType, VArrayDimension >, TPrecisionType >::InputType
itk::FixedArray< TInternalInputType, VArrayDimension > InputType
Definition: otbVariableLengthVectorConverter.h:239
otb::VariableLengthVectorConverter< itk::FixedArray< TInternalInputType, VArrayDimension >, TPrecisionType >::OutputPrecisionType
TPrecisionType OutputPrecisionType
Definition: otbVariableLengthVectorConverter.h:235
otb::VariableLengthVectorConverter< std::vector< std::vector< std::complex< TInternalInputType > > >, TPrecisionType >::OutputPrecisionType
TPrecisionType OutputPrecisionType
Definition: otbVariableLengthVectorConverter.h:193
otbVariableLengthVectorConverter.h
otb::VariableLengthVectorConverter< std::vector< std::vector< TInternalInputType > >, TPrecisionType >::OutputType
itk::VariableLengthVector< OutputPrecisionType > OutputType
Definition: otbVariableLengthVectorConverter.h:154
otb::VariableLengthVectorConverter< itk::SmartPointer< itk::Statistics::Histogram< TPixel > >, TPrecisionType >::OutputPrecisionType
TPrecisionType OutputPrecisionType
Definition: otbVariableLengthVectorConverter.h:276