OTB  10.0.0
Orfeo Toolbox
otbVariableLengthVectorConverter.h
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 otbVariableLengthVectorConverter_h
22 #define otbVariableLengthVectorConverter_h
23 
24 #include "itkProcessObject.h"
25 #include "itkVariableLengthVector.h"
26 #include "itkFixedArray.h"
27 #include "itkHistogram.h"
28 #include "itkSmartPointer.h"
29 
30 
31 namespace otb
32 {
44 // Base
45 template <class TInputType, class TPrecisionType = double>
46 class ITK_EXPORT VariableLengthVectorConverter : public itk::ProcessObject
47 {
48 public:
51  typedef itk::ProcessObject Superclass;
52  typedef itk::SmartPointer<Self> Pointer;
53  typedef itk::SmartPointer<const Self> ConstPointer;
54 
56  itkTypeMacro(VariableLengthVectorConverter, ProcessObject);
57 
59  itkNewMacro(Self);
60 
61  typedef TPrecisionType OutputPrecisionType;
62  typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType;
63  typedef TInputType InputType;
64 
66  {
67  OutputType output;
68  output.SetSize(1);
69  output.SetElement(0, static_cast<OutputPrecisionType>(input));
70  return output;
71  }
72 
73 protected:
75  {
76  }
78  {
79  }
80  void PrintSelf(std::ostream& os, itk::Indent indent) const override
81  {
82  Superclass::PrintSelf(os, indent);
83  os << "Attempt to use inexistent implementation of the converter!" << std::endl;
84  }
85 
86 private:
88  void operator=(const Self&) = delete;
89 };
90 
91 // VariableLengthVector
92 template <class TInternalInputType, class TPrecisionType>
93 class ITK_EXPORT VariableLengthVectorConverter<itk::VariableLengthVector<TInternalInputType>, TPrecisionType> : public itk::ProcessObject
94 {
95 public:
98  typedef itk::ProcessObject Superclass;
99  typedef itk::SmartPointer<Self> Pointer;
100  typedef itk::SmartPointer<const Self> ConstPointer;
101 
103  itkTypeMacro(VariableLengthVectorConverter, ProcessObject);
104 
106  itkNewMacro(Self);
107 
108  typedef TPrecisionType OutputPrecisionType;
109  typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType;
110  typedef itk::VariableLengthVector<TInternalInputType> InputType;
111 
113  {
114  return static_cast<OutputType>(input);
115  }
116 
117 protected:
119  {
120  }
122  {
123  }
124  void PrintSelf(std::ostream& os, itk::Indent indent) const override
125  {
126  Superclass::PrintSelf(os, indent);
127  os << "Attempt to use inexistent implementation of the converter!" << std::endl;
128  }
129 
130 private:
132  void operator=(const Self&) = delete;
133 };
134 
135 
136 // Real Matrix
137 template <class TInternalInputType, class TPrecisionType>
138 class ITK_EXPORT VariableLengthVectorConverter<std::vector<std::vector<TInternalInputType>>, TPrecisionType> : public itk::ProcessObject
139 {
140 public:
143  typedef itk::ProcessObject Superclass;
144  typedef itk::SmartPointer<Self> Pointer;
145  typedef itk::SmartPointer<const Self> ConstPointer;
146 
148  itkTypeMacro(VariableLengthVectorConverter, ProcessObject);
149 
151  itkNewMacro(Self);
152 
153  typedef TPrecisionType OutputPrecisionType;
154  typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType;
155  typedef typename std::vector<std::vector<TInternalInputType>> InputType;
156 
157  OutputType Convert(InputType input);
158 
159 protected:
161  {
162  }
164  {
165  }
166  void PrintSelf(std::ostream& os, itk::Indent indent) const override
167  {
168  Superclass::PrintSelf(os, indent);
169  os << "Converter: std::vector<std::vector<RealType>> => VariableLengthVector<RealType>" << std::endl;
170  }
171 
172 private:
174  void operator=(const Self&) = delete;
175 };
176 
177 
178 // Complex Matrix
179 template <class TInternalInputType, class TPrecisionType>
180 class ITK_EXPORT VariableLengthVectorConverter<std::vector<std::vector<std::complex<TInternalInputType>>>, TPrecisionType> : public itk::ProcessObject
181 {
182 public:
185  typedef itk::ProcessObject Superclass;
186  typedef itk::SmartPointer<Self> Pointer;
187  typedef itk::SmartPointer<const Self> ConstPointer;
188 
190  itkTypeMacro(VariableLengthVectorConverter, ProcessObject);
191 
193  itkNewMacro(Self);
194 
195  typedef TPrecisionType OutputPrecisionType;
196  typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType;
197  typedef typename std::vector<std::vector<std::complex<TInternalInputType>>> InputType;
198 
199  OutputType Convert(InputType input);
200 
201 protected:
203  {
204  }
206  {
207  }
208  void PrintSelf(std::ostream& os, itk::Indent indent) const override
209  {
210  Superclass::PrintSelf(os, indent);
211  os << "Converter: std::vector<std::vector<std::complex<RealType>>> => VariableLengthVector<RealType>" << std::endl;
212  }
213 
214 private:
216  void operator=(const Self&) = delete;
217 };
218 
219 
220 // Fixed Array
221 template <class TInternalInputType, unsigned int VArrayDimension, class TPrecisionType>
222 class ITK_EXPORT VariableLengthVectorConverter<itk::FixedArray<TInternalInputType, VArrayDimension>, TPrecisionType> : public itk::ProcessObject
223 {
224 public:
227  typedef itk::ProcessObject Superclass;
228  typedef itk::SmartPointer<Self> Pointer;
229  typedef itk::SmartPointer<const Self> ConstPointer;
230 
232  itkTypeMacro(VariableLengthVectorConverter, ProcessObject);
233 
235  itkNewMacro(Self);
236 
237  typedef TPrecisionType OutputPrecisionType;
238  typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType;
239  typedef typename itk::FixedArray<TInternalInputType, VArrayDimension> InputType;
240 
241  OutputType Convert(InputType input);
242 
243 protected:
245  {
246  }
248  {
249  }
250  void PrintSelf(std::ostream& os, itk::Indent indent) const override
251  {
252  Superclass::PrintSelf(os, indent);
253  os << "Converter: itk::FixedArray<RealType, VArrayDimension> => VariableLengthVector<RealType>" << std::endl;
254  }
255 
256 private:
258  void operator=(const Self&) = delete;
259 };
260 
261 // Histogram
262 template <class TPixel, class TPrecisionType>
263 class ITK_EXPORT VariableLengthVectorConverter<typename itk::SmartPointer<itk::Statistics::Histogram<TPixel>>, TPrecisionType> : public itk::ProcessObject
264 {
265 public:
268  typedef itk::ProcessObject Superclass;
269  typedef itk::SmartPointer<Self> Pointer;
270  typedef itk::SmartPointer<const Self> ConstPointer;
271 
273  itkTypeMacro(VariableLengthVectorConverter, ProcessObject);
274 
276  itkNewMacro(Self);
277 
278  typedef TPrecisionType OutputPrecisionType;
279  typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType;
280  typedef typename itk::SmartPointer<itk::Statistics::Histogram<TPixel>> InputType;
281 
282  OutputType Convert(InputType input);
283 
284 protected:
286  {
287  }
289  {
290  }
291  void PrintSelf(std::ostream& os, itk::Indent indent) const override
292  {
293  Superclass::PrintSelf(os, indent);
294  os << "Converter: itk::Statistics::Histogram<RealType, VMeasurementVectorSize, TFrequencyContainer> => VariableLengthVector<RealType>" << std::endl;
295  }
296 
297 private:
299  void operator=(const Self&) = delete;
300 };
301 
302 } // namespace otb
303 
304 #ifndef OTB_MANUAL_INSTANTIATION
306 #endif
307 
308 #endif
Convert any data container type into a VariableLengthVector.
void operator=(const Self &)=delete
void PrintSelf(std::ostream &os, itk::Indent indent) const override
VariableLengthVectorConverter(const Self &)=delete
itk::VariableLengthVector< OutputPrecisionType > OutputType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.