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 #include <Eigen/Eigen>
30 
31 // IVT
32 #include <Structs/Structs.h>
33 #include <Structs/ObjectDefinitions.h>
34 #include <Image/ImageProcessor.h>
35 #include <Interfaces/VideoCaptureInterface.h>
36 
37 // VisionXInterface
38 #include <VisionX/interface/core/DataTypes.h>
39 #include <VisionX/interface/components/Calibration.h>
40 #include <VisionX/interface/units/ObjectRecognitionUnit.h>
41 
45 
46 class CByteImage;
47 class CCalibration;
48 class CStereoCalibration;
49 
50 namespace visionx::tools
51 {
52  /*
53  * Converts a vector of the type T into an array of the Type T
54  *
55  * @param data Data vector
56  *
57  * @return T* filled with the elements taken from <em>data</em>
58  */
59  template <typename T>
60  T* vectorToArray(const std::vector<T>& dataVector)
61  {
62  T* dataArray = new T[dataVector.size()];
63 
64  memcpy(dataArray, &dataVector[0], sizeof(T) * dataVector.size());
65 
66  return dataArray;
67  }
68 
69  /*
70  * Converts an array of the type T into a vector of the type T
71  *
72  * @param data Input data array
73  * @param data Output vec
74  */
75  template <typename T>
76  void arrayToVector(const T* dataArray, const int size, std::vector<T>& vec)
77  {
78  vec.clear();
79  vec.resize(size);
80 
81  memcpy(&vec[0], dataArray, sizeof(T) * size);
82  }
83 
84  /**
85  * Converts an image type name as string into an ImageType
86  * integer.
87  *
88  * @param imageTypeName Image type string
89  *
90  * @return VisionX::ImageType if the image type name is valid
91  */
92  ImageType typeNameToImageType(const std::string& imageTypeName);
93 
94  /**
95  * Converts an image type into a string
96  * integer.
97  *
98  * @param imageType Image type
99  *
100  * @return Type name string
101  */
102  std::string imageTypeToTypeName(const ImageType imageType);
103 
104 
105  /**
106  * Converts a VisionX image type into an image type of IVT's
107  * ByteImage.
108  *
109  * @param visionXImageType VisionX image type
110  *
111  * @return ByteImage::ImageType
112  */
113  CByteImage::ImageType convert(const ImageType visionxImageType);
114 
115  /**
116  * Converts a VisionX BayerPatternType into a IVT's image processor BayerPatternType
117  *
118  * @param visionxBayerPatternType VisionX Bayer pattern type
119  *
120  * @return ImageProcessor::BayerPatternType
121  */
122  ::ImageProcessor::BayerPatternType convert(const BayerPatternType visionxBayerPatternType);
123 
124  /**
125  * Converts a VisionX image dimension object into an IVT VideoMode of IVT's
126  * CVideoCaptureInterface.
127  *
128  * @param imageDimension VisionX image dimension which consist of image width and height
129  *
130  * @return According CVideoCaptureInterface::VideoMode if a valid dimension was passed
131  * otherwise CVideoCaptureInterface::eNone is returned.
132  */
133  CVideoCaptureInterface::VideoMode convert(const ImageDimension& imageDimension);
134 
135  /**
136  * Converts frame rate floats into distinct IVT FrameRates by applying quantization.
137  *
138  * @param frameRate frame rate
139  *
140  * @return Closest CVideoCaptureInterface::FrameRate
141  */
142  CVideoCaptureInterface::FrameRate convert(const float frameRate);
143 
144  /**
145  * Converts a VisionX Vector (float STL Vector) into an IVT Vec2d
146  *
147  * @param vec VisionX vector <em>pointer</em>!
148  *
149  * @return IVT 2D Vector
150  */
151  Vec2d convert(const visionx::types::Vec* pVec);
152 
153  /**
154  * Converts a VisionX Vector (float STL Vector) into an IVT Vec3d
155  *
156  * @param vec VisionX vector <em>reference</em>
157  *
158  * @return IVT 3D Vector
159  */
160  Vec3d convert(const visionx::types::Vec& vec);
161 
162  /**
163  * Converts a VisionX Matrix (float STL Vectors) into an IVT Mat3d
164  *
165  * @param vec VisionX matrix
166  *
167  * @return IVT 3D Matrix
168  */
169  Mat3d convert(const visionx::types::Mat& mat);
170 
171  /**
172  * Converts a VisionX StereoCalibration object into an IVT CStereoCalibration
173  *
174  * @param stereoCalibration VisionX Stereo Calibration struct
175  *
176  * @return IVT CStereoCalibration
177  */
178  CStereoCalibration* convert(const visionx::StereoCalibration& stereoCalibration);
179 
180  /**
181  * Converts a VisionX MonocularCalibration object into an IVT CCalibration
182  *
183  * @param calibration VisionX Stereo Calibration struct
184  *
185  * @return IVT CCalibration
186  */
187  CCalibration* convert(const visionx::MonocularCalibration& calibration);
188 
189  /**
190  * Mapps an IVT Object type id onto a VisionX object type id.
191  *
192  * @param objectType VisionX object type id
193  *
194  * @return IVT object type id
195  */
196  ObjectType convert(const visionx::types::ObjectType& objectType);
197 
198  /**
199  * Mapps an IVT Object color id onto a VisionX object color id.
200  *
201  * @param objectColor VisionX object color id
202  *
203  * @return IVT object color id
204  */
205  ObjectColor convert(const visionx::types::ObjectColor& objectColor);
206 
207  /**
208  * Converts a VisionX MyRegion object into an IVT MyRegion instance
209  *
210  * @parma region VisionX MyRegion object
211  *
212  * @return IVT MyRegion instance
213  */
214  MyRegion convert(const visionx::types::Region& region);
215 
216  /**
217  * Converts a VisionX Transformation3d object into an IVT Transformation3d object
218  *
219  * @parma transformation3d VisionX Transformation3d object
220  *
221  * @return IVT Transformation3d instance
222  */
223  Transformation3d convert(const visionx::types::Transformation3d& transformation3d);
224 
225  /**
226  * Converts a VisionX ObjectEntry object into an IVT Object3DEntry instance
227  *
228  * @param objectEntry VisionX ObjectEntry object
229  *
230  * @return IVT Object3DEntry object
231  */
232  Object3DEntry convert(const visionx::types::Object3DEntry& object3DEntry);
233 
234  /**
235  * Converts an IVT Object3DList object into a VisionX Object3DEntry instance
236  *
237  * @param objectList VisionX Object3DEntry instance
238  *
239  * @return IVT Object3DList instance
240  */
241  Object3DList convert(const visionx::types::Object3DList& object3DList);
242 
243  /**
244  * Converts an IVT Vec2d Vector into VisionX Vector (float STL Vector)
245  *
246  * @param vec IVT 2D Vector
247  *
248  * @return VisionX vector
249  */
250  visionx::types::Vec convert(const Vec2d& vec);
251 
252  /**
253  * Converts an IVT Vec3d Vector into VisionX Vector (float STL Vector)
254  *
255  * @param vec IVT 3D Vector
256  *
257  * @return VisionX vector
258  */
259  visionx::types::Vec convert(const Vec3d& vec);
260 
261  /**
262  * Converts an IVT Mat3d into VisionX Matrix (float STL Vectors)
263  *
264  * @param vec IVT 3D Matrix
265  *
266  * @return VisionX matrix
267  */
268  visionx::types::Mat convert(const Mat3d& mat);
269 
270  /**
271  * Converts an IVT CStereoCalibration into a VisionX StereoCalibration struct
272  *
273  * @param ivtStereoCalibration IVT StereoCalibration
274  *
275  * @return VisionX StereoCalibration object
276  */
277  visionx::StereoCalibration convert(const CStereoCalibration& ivtStereoCalibration);
278 
279  /**
280  * Converts an IVT CCalibration into a VisionX MonocularCalibration struct
281  *
282  * @param ivtCalibration IVT Calibration
283  *
284  * @return VisionX StereoCalibration object
285  */
286  visionx::MonocularCalibration convert(const CCalibration& ivtCalibration);
287 
288  /**
289  * Converts an IVT MyRegion into a VisionX MyRegion
290  *
291  * @param ivtRegion IVT MyRegion struct instance
292  *
293  * @return VisionX MyRegion object
294  */
295  visionx::types::Region convert(const MyRegion& ivtRegion);
296 
297  /**
298  * Converts an IVT Transformation3d into a VisionX Transformation3d
299  *
300  * @param ivtTransformation3d IVT Transformation3d struct instance
301  *
302  * @return VisionX Transformation3d object
303  */
304  visionx::types::Transformation3d convert(const Transformation3d& ivtTransformation3d);
305 
306  /**
307  * Mapps an IVT Object color id onto a VisionX object color id.
308  *
309  * @param ivtObjectColor IVT Object color id
310  *
311  * @return VisionX Object color id
312  */
313  visionx::types::ObjectColor convert(const ObjectColor& ivtObjectColor);
314 
315  /**
316  * Mapps an IVT Object type id onto a VisionX object type id.
317  *
318  * @param ivtObjectType IVT Object type id
319  *
320  * @return VisionX Object type id
321  */
322  visionx::types::ObjectType convert(const ObjectType& ivtObjectType);
323 
324  /**
325  * Converts an IVT Object3DEntry id into a VisionX ObjectEntry
326  *
327  * @param ivtObject3DEntry IVT Object3DEntry
328  *
329  * @return VisionX ObjectEntry
330  */
331  visionx::types::Object3DEntry convert(const Object3DEntry& ivtObject3DEntry);
332 
333  /**
334  * Converts an IVT Object3DList object into an VisionX ObjectList
335  *
336  * @param ivtObject3DList IVT Object3DList instance
337  *
338  * @return VisionX ObjectList
339  */
340  visionx::types::Object3DList convert(const Object3DList& ivtObject3DList);
341 
342  Eigen::Matrix3f convertIVTtoEigen(const Mat3d m);
343  Eigen::Vector3f convertIVTtoEigen(const Vec3d v);
344 
345  visionx::types::Vec convertEigenVecToVisionX(Eigen::VectorXf v);
346 
347  Eigen::VectorXf convertVisionXVecToEigen(visionx::types::Vec v);
348 
349  visionx::types::Mat convertEigenMatToVisionX(Eigen::MatrixXf m);
350 
351  Eigen::MatrixXf convertVisionXMatToEigen(visionx::types::Mat m);
352 }
353 
354 
visionx::tools::convertIVTtoEigen
Eigen::Matrix3f convertIVTtoEigen(const Mat3d m)
Definition: TypeMapping.cpp:632
visionx::tools
Definition: PCLUtilities.cpp:4
visionx::tools::vectorToArray
T * vectorToArray(const std::vector< T > &dataVector)
Definition: TypeMapping.h:60
visionx::tools::arrayToVector
void arrayToVector(const T *dataArray, const int size, std::vector< T > &vec)
Definition: TypeMapping.h:76
visionx::tools::convertVisionXMatToEigen
Eigen::MatrixXf convertVisionXMatToEigen(visionx::types::Mat m)
Definition: TypeMapping.cpp:691
GfxTL::Vec2d
VectorXD< 2, double > Vec2d
Definition: VectorXD.h:694
visionx::tools::convert
CByteImage::ImageType convert(const ImageType visionxImageType)
Converts a VisionX image type into an image type of IVT's ByteImage.
Definition: TypeMapping.cpp:95
visionx::tools::convertEigenVecToVisionX
visionx::types::Vec convertEigenVecToVisionX(Eigen::VectorXf v)
Definition: TypeMapping.cpp:655
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:695
InvalidFrameRateException.h
visionx::tools::imageTypeToTypeName
std::string imageTypeToTypeName(const ImageType imageType)
Converts an image type into a string integer.
Definition: TypeMapping.cpp:70
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
visionx::tools::convertVisionXVecToEigen
Eigen::VectorXf convertVisionXVecToEigen(visionx::types::Vec v)
Definition: TypeMapping.cpp:666
visionx::tools::convertEigenMatToVisionX
visionx::types::Mat convertEigenMatToVisionX(Eigen::MatrixXf m)
Definition: TypeMapping.cpp:677
UnsupportedImageTypeException.h
visionx::tools::typeNameToImageType
ImageType typeNameToImageType(const std::string &imageTypeName)
Converts an image type name as string into an ImageType integer.
Definition: TypeMapping.cpp:42
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
InvalidImageTypeNameException.h