OTB  6.7.0
Orfeo Toolbox
otbVariableLengthVectorConverter.h
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_h
22 #define otbVariableLengthVectorConverter_h
23 
24 #include "itkProcessObject.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 >
47 public itk::ProcessObject
48 {
49 public:
55 
57  itkTypeMacro(VariableLengthVectorConverter, ProcessObject);
58 
60  itkNewMacro(Self);
61 
62  typedef TPrecisionType OutputPrecisionType;
64  typedef TInputType InputType;
65 
67  {
68  OutputType output;
69  output.SetSize(1);
70  output.SetElement(0, static_cast<OutputPrecisionType>(input));
71  return output;
72  }
73 
74 protected:
77  void PrintSelf(std::ostream& os, itk::Indent indent) const override
78  {
79  Superclass::PrintSelf(os, indent);
80  os << "Attempt to use inexistant implementation of the converter!"
81  << std::endl;
82  }
83 
84 private:
85  VariableLengthVectorConverter(const Self&) = delete;
86  void operator=(const Self&) = delete;
87 };
88 
89 // VariableLengthVector
90 template< class TInternalInputType, class TPrecisionType>
91 class ITK_EXPORT VariableLengthVectorConverter< itk::VariableLengthVector< TInternalInputType > ,
92  TPrecisionType > :
93 public itk::ProcessObject
94 {
95 public:
101 
103  itkTypeMacro(VariableLengthVectorConverter, ProcessObject);
104 
106  itkNewMacro(Self);
107 
108  typedef TPrecisionType OutputPrecisionType;
111 
113  {
114  return static_cast<OutputType>(input);
115  }
116 
117 protected:
120  void PrintSelf(std::ostream& os, itk::Indent indent) const override
121  {
122  Superclass::PrintSelf(os, indent);
123  os << "Attempt to use inexistant implementation of the converter!"
124  << std::endl;
125  }
126 
127 private:
128  VariableLengthVectorConverter(const Self&) = delete;
129  void operator=(const Self&) = delete;
130 };
131 
132 
133 // Real Matrix
134 template< class TInternalInputType, class TPrecisionType >
135 class ITK_EXPORT VariableLengthVectorConverter<std::vector<std::vector<TInternalInputType> >,
136  TPrecisionType> :
137 public itk::ProcessObject
138 {
139 public:
145 
147  itkTypeMacro(VariableLengthVectorConverter, ProcessObject);
148 
150  itkNewMacro(Self);
151 
152  typedef TPrecisionType OutputPrecisionType;
154  typedef typename std::vector<std::vector<TInternalInputType> > InputType;
155 
156  OutputType Convert(InputType input);
157 
158 protected:
161  void PrintSelf(std::ostream& os, itk::Indent indent) const override
162  {
163  Superclass::PrintSelf(os, indent);
164  os << "Converter: std::vector<std::vector<RealType>> => VariableLengthVector<RealType>"
165  << std::endl;
166  }
167 
168 private:
169  VariableLengthVectorConverter(const Self&) = delete;
170  void operator=(const Self&) = delete;
171 };
172 
173 
174 //Complex Matrix
175 template< class TInternalInputType, class TPrecisionType >
176 class ITK_EXPORT VariableLengthVectorConverter<std::vector<std::vector<std::complex<TInternalInputType> > >,
177  TPrecisionType> :
178 public itk::ProcessObject
179 {
180 public:
186 
188  itkTypeMacro(VariableLengthVectorConverter, ProcessObject);
189 
191  itkNewMacro(Self);
192 
193  typedef TPrecisionType OutputPrecisionType;
195  typedef typename std::vector<std::vector<std::complex<TInternalInputType> > > InputType;
196 
197  OutputType Convert(InputType input);
198 
199 protected:
202  void PrintSelf(std::ostream& os, itk::Indent indent) const override
203  {
204  Superclass::PrintSelf(os, indent);
205  os << "Converter: std::vector<std::vector<std::complex<RealType>>> => VariableLengthVector<RealType>"
206  << std::endl;
207  }
208 
209 private:
210  VariableLengthVectorConverter(const Self&) = delete;
211  void operator=(const Self&) = delete;
212 };
213 
214 
215 //Fixed Array
216 template< class TInternalInputType, unsigned int VArrayDimension, class TPrecisionType >
217 class ITK_EXPORT VariableLengthVectorConverter<itk::FixedArray<TInternalInputType, VArrayDimension>,
218  TPrecisionType> :
219 public itk::ProcessObject
220 {
221 public:
227 
229  itkTypeMacro(VariableLengthVectorConverter, ProcessObject);
230 
232  itkNewMacro(Self);
233 
234  typedef TPrecisionType OutputPrecisionType;
237 
238  OutputType Convert(InputType input);
239 
240 protected:
243  void PrintSelf(std::ostream& os, itk::Indent indent) const override
244  {
245  Superclass::PrintSelf(os, indent);
246  os << "Converter: itk::FixedArray<RealType, VArrayDimension> => VariableLengthVector<RealType>"
247  << std::endl;
248  }
249 
250 private:
251  VariableLengthVectorConverter(const Self&) = delete;
252  void operator=(const Self&) = delete;
253 };
254 
255 //Histogram
256 template< class TPixel, class TPrecisionType >
257 class ITK_EXPORT VariableLengthVectorConverter<typename itk::SmartPointer< itk::Statistics::Histogram<TPixel> >,
258  TPrecisionType> :
259 public itk::ProcessObject
260 {
261 public:
267 
269  itkTypeMacro(VariableLengthVectorConverter, ProcessObject);
270 
272  itkNewMacro(Self);
273 
274  typedef TPrecisionType OutputPrecisionType;
277 
278  OutputType Convert(InputType input);
279 
280 protected:
283  void PrintSelf(std::ostream& os, itk::Indent indent) const override
284  {
285  Superclass::PrintSelf(os, indent);
286  os << "Converter: itk::Statistics::Histogram<RealType, VMeasurementVectorSize, TFrequencyContainer> => VariableLengthVector<RealType>"
287  << std::endl;
288  }
289 
290 private:
291  VariableLengthVectorConverter(const Self&) = delete;
292  void operator=(const Self&) = delete;
293 };
294 
295 }// namespace otb
296 
297 #ifndef OTB_MANUAL_INSTANTIATION
299 #endif
300 
301 #endif
void SetElement(unsigned int i, const TValue &value) noexcept
Convert any data container type into a VariableLengthVector.
itk::VariableLengthVector< OutputPrecisionType > OutputType
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void SetSize(unsigned int sz, TReallocatePolicy reallocatePolicy, TKeepValuesPolicy keepValues)