TypeMapping.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package VisionX::Tools
19 * @author Jan Issac (jan dot issac at gmx dot net)
20 * @date 2011
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#pragma once
26
27#include <string>
28
29// Eigen
30#include <Eigen/Core>
31
32// IVT
33#include <Image/ImageProcessor.h>
34#include <Interfaces/VideoCaptureInterface.h>
35#include <Structs/ObjectDefinitions.h>
36#include <Structs/Structs.h>
37
38// VisionXInterface
39#include <VisionX/interface/components/Calibration.h>
40#include <VisionX/interface/core/DataTypes.h>
41#include <VisionX/interface/units/ObjectRecognitionUnit.h>
42
46
47class CByteImage;
48class CCalibration;
49class CStereoCalibration;
50
51namespace visionx::tools
52{
53 /*
54 * Converts a vector of the type T into an array of the Type T
55 *
56 * @param data Data vector
57 *
58 * @return T* filled with the elements taken from <em>data</em>
59 */
60 template <typename T>
61 T*
62 vectorToArray(const std::vector<T>& dataVector)
63 {
64 T* dataArray = new T[dataVector.size()];
65
66 memcpy(dataArray, &dataVector[0], sizeof(T) * dataVector.size());
67
68 return dataArray;
69 }
70
71 /*
72 * Converts an array of the type T into a vector of the type T
73 *
74 * @param data Input data array
75 * @param data Output vec
76 */
77 template <typename T>
78 void
79 arrayToVector(const T* dataArray, const int size, std::vector<T>& vec)
80 {
81 vec.clear();
82 vec.resize(size);
83
84 memcpy(&vec[0], dataArray, sizeof(T) * size);
85 }
86
87 /**
88 * Converts an image type name as string into an ImageType
89 * integer.
90 *
91 * @param imageTypeName Image type string
92 *
93 * @return VisionX::ImageType if the image type name is valid
94 */
95 ImageType typeNameToImageType(const std::string& imageTypeName);
96
97 /**
98 * Converts an image type into a string
99 * integer.
100 *
101 * @param imageType Image type
102 *
103 * @return Type name string
104 */
105 std::string imageTypeToTypeName(const ImageType imageType);
106
107
108 /**
109 * Converts a VisionX image type into an image type of IVT's
110 * ByteImage.
111 *
112 * @param visionXImageType VisionX image type
113 *
114 * @return ByteImage::ImageType
115 */
116 CByteImage::ImageType convert(const ImageType visionxImageType);
117
118 /**
119 * Converts a VisionX BayerPatternType into a IVT's image processor BayerPatternType
120 *
121 * @param visionxBayerPatternType VisionX Bayer pattern type
122 *
123 * @return ImageProcessor::BayerPatternType
124 */
125 ::ImageProcessor::BayerPatternType convert(const BayerPatternType visionxBayerPatternType);
126
127 /**
128 * Converts a VisionX image dimension object into an IVT VideoMode of IVT's
129 * CVideoCaptureInterface.
130 *
131 * @param imageDimension VisionX image dimension which consist of image width and height
132 *
133 * @return According CVideoCaptureInterface::VideoMode if a valid dimension was passed
134 * otherwise CVideoCaptureInterface::eNone is returned.
135 */
136 CVideoCaptureInterface::VideoMode convert(const ImageDimension& imageDimension);
137
138 /**
139 * Converts frame rate floats into distinct IVT FrameRates by applying quantization.
140 *
141 * @param frameRate frame rate
142 *
143 * @return Closest CVideoCaptureInterface::FrameRate
144 */
145 CVideoCaptureInterface::FrameRate convert(const float frameRate);
146
147 /**
148 * Converts a VisionX Vector (float STL Vector) into an IVT Vec2d
149 *
150 * @param vec VisionX vector <em>pointer</em>!
151 *
152 * @return IVT 2D Vector
153 */
154 Vec2d convert(const visionx::types::Vec* pVec);
155
156 /**
157 * Converts a VisionX Vector (float STL Vector) into an IVT Vec3d
158 *
159 * @param vec VisionX vector <em>reference</em>
160 *
161 * @return IVT 3D Vector
162 */
163 Vec3d convert(const visionx::types::Vec& vec);
164
165 /**
166 * Converts a VisionX Matrix (float STL Vectors) into an IVT Mat3d
167 *
168 * @param vec VisionX matrix
169 *
170 * @return IVT 3D Matrix
171 */
172 Mat3d convert(const visionx::types::Mat& mat);
173
174 /**
175 * Converts a VisionX StereoCalibration object into an IVT CStereoCalibration
176 *
177 * @param stereoCalibration VisionX Stereo Calibration struct
178 *
179 * @return IVT CStereoCalibration
180 */
181 CStereoCalibration* convert(const visionx::StereoCalibration& stereoCalibration);
182
183 /**
184 * Converts a VisionX MonocularCalibration object into an IVT CCalibration
185 *
186 * @param calibration VisionX Stereo Calibration struct
187 *
188 * @return IVT CCalibration
189 */
190 CCalibration* convert(const visionx::MonocularCalibration& calibration);
191
192 /**
193 * Mapps an IVT Object type id onto a VisionX object type id.
194 *
195 * @param objectType VisionX object type id
196 *
197 * @return IVT object type id
198 */
199 ObjectType convert(const visionx::types::ObjectType& objectType);
200
201 /**
202 * Mapps an IVT Object color id onto a VisionX object color id.
203 *
204 * @param objectColor VisionX object color id
205 *
206 * @return IVT object color id
207 */
208 ObjectColor convert(const visionx::types::ObjectColor& objectColor);
209
210 /**
211 * Converts a VisionX MyRegion object into an IVT MyRegion instance
212 *
213 * @parma region VisionX MyRegion object
214 *
215 * @return IVT MyRegion instance
216 */
217 MyRegion convert(const visionx::types::Region& region);
218
219 /**
220 * Converts a VisionX Transformation3d object into an IVT Transformation3d object
221 *
222 * @parma transformation3d VisionX Transformation3d object
223 *
224 * @return IVT Transformation3d instance
225 */
226 Transformation3d convert(const visionx::types::Transformation3d& transformation3d);
227
228 /**
229 * Converts a VisionX ObjectEntry object into an IVT Object3DEntry instance
230 *
231 * @param objectEntry VisionX ObjectEntry object
232 *
233 * @return IVT Object3DEntry object
234 */
235 Object3DEntry convert(const visionx::types::Object3DEntry& object3DEntry);
236
237 /**
238 * Converts an IVT Object3DList object into a VisionX Object3DEntry instance
239 *
240 * @param objectList VisionX Object3DEntry instance
241 *
242 * @return IVT Object3DList instance
243 */
244 Object3DList convert(const visionx::types::Object3DList& object3DList);
245
246 /**
247 * Converts an IVT Vec2d Vector into VisionX Vector (float STL Vector)
248 *
249 * @param vec IVT 2D Vector
250 *
251 * @return VisionX vector
252 */
253 visionx::types::Vec convert(const Vec2d& vec);
254
255 /**
256 * Converts an IVT Vec3d Vector into VisionX Vector (float STL Vector)
257 *
258 * @param vec IVT 3D Vector
259 *
260 * @return VisionX vector
261 */
262 visionx::types::Vec convert(const Vec3d& vec);
263
264 /**
265 * Converts an IVT Mat3d into VisionX Matrix (float STL Vectors)
266 *
267 * @param vec IVT 3D Matrix
268 *
269 * @return VisionX matrix
270 */
271 visionx::types::Mat convert(const Mat3d& mat);
272
273 /**
274 * Converts an IVT CStereoCalibration into a VisionX StereoCalibration struct
275 *
276 * @param ivtStereoCalibration IVT StereoCalibration
277 *
278 * @return VisionX StereoCalibration object
279 */
280 visionx::StereoCalibration convert(const CStereoCalibration& ivtStereoCalibration);
281
282 /**
283 * Converts an IVT CCalibration into a VisionX MonocularCalibration struct
284 *
285 * @param ivtCalibration IVT Calibration
286 *
287 * @return VisionX StereoCalibration object
288 */
289 visionx::MonocularCalibration convert(const CCalibration& ivtCalibration);
290
291 /**
292 * Converts an IVT MyRegion into a VisionX MyRegion
293 *
294 * @param ivtRegion IVT MyRegion struct instance
295 *
296 * @return VisionX MyRegion object
297 */
298 visionx::types::Region convert(const MyRegion& ivtRegion);
299
300 /**
301 * Converts an IVT Transformation3d into a VisionX Transformation3d
302 *
303 * @param ivtTransformation3d IVT Transformation3d struct instance
304 *
305 * @return VisionX Transformation3d object
306 */
307 visionx::types::Transformation3d convert(const Transformation3d& ivtTransformation3d);
308
309 /**
310 * Mapps an IVT Object color id onto a VisionX object color id.
311 *
312 * @param ivtObjectColor IVT Object color id
313 *
314 * @return VisionX Object color id
315 */
316 visionx::types::ObjectColor convert(const ObjectColor& ivtObjectColor);
317
318 /**
319 * Mapps an IVT Object type id onto a VisionX object type id.
320 *
321 * @param ivtObjectType IVT Object type id
322 *
323 * @return VisionX Object type id
324 */
325 visionx::types::ObjectType convert(const ObjectType& ivtObjectType);
326
327 /**
328 * Converts an IVT Object3DEntry id into a VisionX ObjectEntry
329 *
330 * @param ivtObject3DEntry IVT Object3DEntry
331 *
332 * @return VisionX ObjectEntry
333 */
334 visionx::types::Object3DEntry convert(const Object3DEntry& ivtObject3DEntry);
335
336 /**
337 * Converts an IVT Object3DList object into an VisionX ObjectList
338 *
339 * @param ivtObject3DList IVT Object3DList instance
340 *
341 * @return VisionX ObjectList
342 */
343 visionx::types::Object3DList convert(const Object3DList& ivtObject3DList);
344
345 Eigen::Matrix3f convertIVTtoEigen(const Mat3d& m);
346 Eigen::Vector3f convertIVTtoEigen(const Vec3d& v);
347
348 visionx::types::Vec convertEigenVecToVisionX(Eigen::VectorXf v);
349
350 Eigen::VectorXf convertVisionXVecToEigen(visionx::types::Vec v);
351
352 visionx::types::Mat convertEigenMatToVisionX(Eigen::MatrixXf m);
353
354 Eigen::MatrixXf convertVisionXMatToEigen(visionx::types::Mat m);
355} // namespace visionx::tools
void arrayToVector(const T *dataArray, const int size, std::vector< T > &vec)
Definition TypeMapping.h:79
Eigen::Matrix3f convertIVTtoEigen(const Mat3d &m)
ImageType typeNameToImageType(const std::string &imageTypeName)
Converts an image type name as string into an ImageType integer.
Eigen::MatrixXf convertVisionXMatToEigen(visionx::types::Mat m)
visionx::types::Vec convertEigenVecToVisionX(Eigen::VectorXf v)
T * vectorToArray(const std::vector< T > &dataVector)
Definition TypeMapping.h:62
std::string imageTypeToTypeName(const ImageType imageType)
Converts an image type into a string integer.
Eigen::VectorXf convertVisionXVecToEigen(visionx::types::Vec v)
visionx::types::Mat convertEigenMatToVisionX(Eigen::MatrixXf m)
CByteImage::ImageType convert(const ImageType visionxImageType)
Converts a VisionX image type into an image type of IVT's ByteImage.