OTB  7.1.0
Orfeo Toolbox
otbVariableLengthVectorConverter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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>
100 VariableLengthVectorConverter<itk::FixedArray<TInternalInputType, VArrayDimension>, TPrecisionType>::Convert(InputType input)
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
Convert any data container type into a VariableLengthVector.
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.