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