TypeMapping.cpp
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 #include "TypeMapping.h"
26 
28 
29 // SLT
30 #include <vector>
31 #include <map>
32 
33 // IVT
34 #include <Structs/Structs.h>
35 #include <Image/ByteImage.h>
36 #include <Math/Math2d.h>
37 #include <Math/Math3d.h>
38 #include <Calibration/Calibration.h>
39 #include <Calibration/StereoCalibration.h>
40 
41 
42 visionx::ImageType visionx::tools::typeNameToImageType(const std::string& imageTypeName)
43 {
44  static std::map<std::string, visionx::ImageType> nameToTypeMap;
45 
46  // initialize image type name to image type integer mapping
47  if (nameToTypeMap.empty())
48  {
49  nameToTypeMap["bayer-pattern"] = visionx::eBayerPattern;
50  nameToTypeMap["gray-scale"] = visionx::eGrayScale;
51  nameToTypeMap["rgb"] = visionx::eRgb;
52  nameToTypeMap["float-1-channel"] = visionx::eFloat1Channel;
53  nameToTypeMap["float-3-channels"] = visionx::eFloat3Channels;
54  }
55 
56  std::string lowerCaseTypeName = imageTypeName;
57  std::transform(lowerCaseTypeName.begin(), lowerCaseTypeName.end(), lowerCaseTypeName.begin(), ::tolower);
58 
59  std::map<std::string, visionx::ImageType>::iterator nameToTypeIter = nameToTypeMap.find(lowerCaseTypeName);
60 
61  if (nameToTypeIter == nameToTypeMap.end())
62  {
64  }
65 
66  return nameToTypeIter->second;
67 }
68 
69 
70 std::string visionx::tools::imageTypeToTypeName(const ImageType imageType)
71 {
72  switch (imageType)
73  {
74  case visionx::eBayerPattern:
75  return "bayer-pattern";
76 
77  case visionx::eGrayScale:
78  return "gray-scale";
79 
80  case visionx::eRgb:
81  return "rgb";
82 
83  case visionx::eFloat1Channel:
84  return "float-1-channel";
85 
86  case visionx::eFloat3Channels:
87  return "float-3-channel";
88 
89  default:
90  return "unknown";
91  }
92 }
93 
94 
95 CByteImage::ImageType visionx::tools::convert(const ImageType visionxImageType)
96 {
97  static std::map<visionx::ImageType, CByteImage::ImageType> visionxTypeToIvtTypeMap;
98 
99  // initialize VisionX image type to ByteImage image type mapping
100  if (visionxTypeToIvtTypeMap.empty())
101  {
102  visionxTypeToIvtTypeMap[visionx::eRgb] = CByteImage::eRGB24;
103  visionxTypeToIvtTypeMap[visionx::eGrayScale] = CByteImage::eGrayScale;
104  visionxTypeToIvtTypeMap[visionx::eBayerPattern] = CByteImage::eGrayScale;
105  }
106 
107  std::map<visionx::ImageType, CByteImage::ImageType>::iterator visionxTypeToIvtTypeIter = visionxTypeToIvtTypeMap.find(visionxImageType);
108 
109  if (visionxTypeToIvtTypeIter == visionxTypeToIvtTypeMap.end())
110  {
112  }
113 
114  return visionxTypeToIvtTypeIter->second;
115 }
116 
117 
118 ImageProcessor::BayerPatternType visionx::tools::convert(const BayerPatternType visionxBayerPatternType)
119 {
120  switch (visionxBayerPatternType)
121  {
122  case visionx::eBayerPatternBg:
123  return ::ImageProcessor::eBayerBG;
124 
125  case visionx::eBayerPatternGb:
126  return ::ImageProcessor::eBayerGB;
127 
128  case visionx::eBayerPatternGr:
129  return ::ImageProcessor::eBayerGR;
130 
131  case visionx::eBayerPatternRg:
132  return ::ImageProcessor::eBayerRG;
133  }
134 
135  // default value (this is never reached since there are only 4 Bayer Pattern
136  // types which are already handled by the switch above)
137  return ::ImageProcessor::eBayerRG;
138 }
139 
140 
141 CVideoCaptureInterface::VideoMode visionx::tools::convert(const ImageDimension& imageDimension)
142 {
143  // since the width or the height of each available dimension is unique, we use only
144  // the width to identify the dimension
145  switch (imageDimension.width)
146  {
147  case 0:
148  return CVideoCaptureInterface::eNone;
149 
150  case 320:
151  return CVideoCaptureInterface::e320x240;
152 
153  case 640:
154  return CVideoCaptureInterface::e640x480;
155 
156  case 800:
157  return CVideoCaptureInterface::e800x600;
158 
159  case 768:
160  return CVideoCaptureInterface::e768x576;
161 
162  case 1024:
163  return CVideoCaptureInterface::e1024x768;
164 
165  case 1280:
166  return CVideoCaptureInterface::e1280x960;
167 
168  case 1600:
169  return CVideoCaptureInterface::e1600x1200;
170  }
171 
172  return CVideoCaptureInterface::eNone;
173 }
174 
175 CVideoCaptureInterface::FrameRate visionx::tools::convert(const float frameRate)
176 {
177  using FrameRateRange = std::pair<float, float>;
178 
179  static std::map<FrameRateRange, CVideoCaptureInterface::FrameRate> frameRateMap;
180 
181  using FrameRateMapIter = std::map<FrameRateRange, CVideoCaptureInterface::FrameRate>::iterator;
182 
183  if (frameRateMap.empty())
184  {
185  frameRateMap[FrameRateRange(0.f, 1.875f + 1.875f / 2)] = CVideoCaptureInterface::e1_875fps;
186  frameRateMap[FrameRateRange(1.875f + 1.875f / 2, 3.75f + 1.875f)] = CVideoCaptureInterface::e3_75fps;
187  frameRateMap[FrameRateRange(3.75f + 1.875f, 7.5f + 3.75f)] = CVideoCaptureInterface::e7_5fps;
188  frameRateMap[FrameRateRange(7.5f + 3.75f, 15.f + 7.5f)] = CVideoCaptureInterface::e15fps;
189  frameRateMap[FrameRateRange(15.f + 7.5f, 30.f + 15.f)] = CVideoCaptureInterface::e30fps;
190  frameRateMap[FrameRateRange(30.f + 15.f, 1024.f)] = CVideoCaptureInterface::e60fps;
191  }
192 
193  FrameRateMapIter iter = frameRateMap.begin();
194 
195  while (iter != frameRateMap.end())
196  {
197  if (frameRate >= iter->first.first && frameRate < iter->first.second)
198  {
199  return iter->second;
200  }
201 
202  iter++;
203  }
204 
206 }
207 
208 
209 Vec2d visionx::tools::convert(const visionx::types::Vec* pVec)
210 {
211  Vec2d vec2d;
212  vec2d.x = (*pVec)[0];
213  vec2d.y = (*pVec)[1];
214 
215  return vec2d;
216 }
217 
218 
219 Vec3d visionx::tools::convert(const visionx::types::Vec& vec)
220 {
221  Vec3d vec3d;
222  vec3d.x = vec[0];
223  vec3d.y = vec[1];
224  vec3d.z = vec[2];
225 
226  return vec3d;
227 }
228 
229 
230 Mat3d visionx::tools::convert(const visionx::types::Mat& mat)
231 {
232  Mat3d ivtMat3d;
233  ARMARX_CHECK_EQUAL(mat.size(), 3);
234  ARMARX_CHECK_EQUAL(mat[0].size(), 3);
235  ARMARX_CHECK_EQUAL(mat[1].size(), 3);
236  ARMARX_CHECK_EQUAL(mat[2].size(), 3);
237 
238 
239  ivtMat3d.r1 = mat[0][0];
240  ivtMat3d.r2 = mat[0][1];
241  ivtMat3d.r3 = mat[0][2];
242  ivtMat3d.r4 = mat[1][0];
243  ivtMat3d.r5 = mat[1][1];
244  ivtMat3d.r6 = mat[1][2];
245  ivtMat3d.r7 = mat[2][0];
246  ivtMat3d.r8 = mat[2][1];
247  ivtMat3d.r9 = mat[2][2];
248 
249  return ivtMat3d;
250 }
251 
252 
253 visionx::types::Vec visionx::tools::convert(const Vec2d& ivtVec2d)
254 {
255  std::vector<float> vec(2);
256  vec[0] = ivtVec2d.x;
257  vec[1] = ivtVec2d.y;
258 
259  return vec;
260 }
261 
262 
263 visionx::types::Vec visionx::tools::convert(const Vec3d& ivtVec3d)
264 {
265  std::vector<float> vec(3);
266  vec[0] = ivtVec3d.x;
267  vec[1] = ivtVec3d.y;
268  vec[2] = ivtVec3d.z;
269 
270  return vec;
271 }
272 
273 
274 visionx::types::Mat visionx::tools::convert(const Mat3d& ivtMat3d)
275 {
276  std::vector<std::vector<float> > mat(3);
277  std::vector<float> rowVec(3);
278 
279  rowVec[0] = ivtMat3d.r1;
280  rowVec[1] = ivtMat3d.r2;
281  rowVec[2] = ivtMat3d.r3;
282  mat[0] = rowVec;
283 
284  rowVec = std::vector<float>(3);
285  rowVec[0] = ivtMat3d.r4;
286  rowVec[1] = ivtMat3d.r5;
287  rowVec[2] = ivtMat3d.r6;
288  mat[1] = rowVec;
289 
290  rowVec = std::vector<float>(3);
291  rowVec[0] = ivtMat3d.r7;
292  rowVec[1] = ivtMat3d.r8;
293  rowVec[2] = ivtMat3d.r9;
294  mat[2] = rowVec;
295 
296  return mat;
297 }
298 
299 
300 CStereoCalibration* visionx::tools::convert(const visionx::StereoCalibration& stereoCalibration)
301 {
302  CStereoCalibration* ivtStereoCalibration = new CStereoCalibration();
303 
304  CCalibration ivtCalibrationLeft;
305  CCalibration ivtCalibrationRight;
306 
307  const visionx::CameraParameters& cameraParamLeft = stereoCalibration.calibrationLeft.cameraParam;
308  const visionx::CameraParameters& cameraParamRight = stereoCalibration.calibrationRight.cameraParam;
309 
310  Mat3d R = convert(cameraParamLeft.rotation);
311  Vec3d t = convert(cameraParamLeft.translation);
312  ARMARX_CHECK_EQUAL(cameraParamLeft.focalLength.size(), 2);
313  ARMARX_CHECK_EQUAL(cameraParamLeft.principalPoint.size(), 2);
314  ARMARX_CHECK_EQUAL(cameraParamLeft.distortion.size(), 4);
315  ivtCalibrationLeft.SetCameraParameters
316  (
317  cameraParamLeft.focalLength[0],
318  cameraParamLeft.focalLength[1],
319  cameraParamLeft.principalPoint[0],
320  cameraParamLeft.principalPoint[1],
321  cameraParamLeft.distortion[0],
322  cameraParamLeft.distortion[1],
323  cameraParamLeft.distortion[2],
324  cameraParamLeft.distortion[3],
325  R,
326  t,
327  cameraParamLeft.width,
328  cameraParamLeft.height
329  );
330 
331  R = convert(cameraParamRight.rotation);
332  t = convert(cameraParamRight.translation);
333  ARMARX_CHECK_EQUAL(cameraParamRight.focalLength.size(), 2);
334  ARMARX_CHECK_EQUAL(cameraParamRight.principalPoint.size(), 2);
335  ARMARX_CHECK_EQUAL(cameraParamRight.distortion.size(), 4);
336 
337  ivtCalibrationRight.SetCameraParameters
338  (
339  cameraParamRight.focalLength[0],
340  cameraParamRight.focalLength[1],
341  cameraParamRight.principalPoint[0],
342  cameraParamRight.principalPoint[1],
343  cameraParamRight.distortion[0],
344  cameraParamRight.distortion[1],
345  cameraParamRight.distortion[2],
346  cameraParamRight.distortion[3],
347  R,
348  t,
349  cameraParamRight.width,
350  cameraParamRight.height
351  );
352 
353  ivtStereoCalibration->SetSingleCalibrations(ivtCalibrationLeft, ivtCalibrationRight);
354 
355  ivtStereoCalibration->rectificationHomographyLeft = convert(stereoCalibration.rectificationHomographyLeft);
356  ivtStereoCalibration->rectificationHomographyRight = convert(stereoCalibration.rectificationHomographyRight);
357 
358  return ivtStereoCalibration;
359 }
360 
361 
362 
363 CCalibration* visionx::tools::convert(const visionx::MonocularCalibration& calibration)
364 {
365  CCalibration* ivtCalibration = new CCalibration();
366 
367  const visionx::CameraParameters& cameraParam = calibration.cameraParam;
368 
369  Mat3d R = convert(cameraParam.rotation);
370  Vec3d t = convert(cameraParam.translation);
371 
372  ivtCalibration->SetCameraParameters
373  (
374  cameraParam.focalLength[0],
375  cameraParam.focalLength[1],
376  cameraParam.principalPoint[0],
377  cameraParam.principalPoint[1],
378  cameraParam.distortion[0],
379  cameraParam.distortion[1],
380  cameraParam.distortion[2],
381  cameraParam.distortion[3],
382  R,
383  t,
384  cameraParam.width,
385  cameraParam.height
386  );
387 
388  return ivtCalibration;
389 }
390 
391 visionx::StereoCalibration visionx::tools::convert(const CStereoCalibration& ivtStereoCalibration)
392 {
393  visionx::StereoCalibration stereoCalibration;
394 
395  const CCalibration::CCameraParameters& ivtCalibParamLeft = ivtStereoCalibration.GetLeftCalibration()->GetCameraParameters();
396  const CCalibration::CCameraParameters& ivtCalibParamRight = ivtStereoCalibration.GetRightCalibration()->GetCameraParameters();
397 
398  visionx::CameraParameters& cameraParamLeft = stereoCalibration.calibrationLeft.cameraParam;
399  visionx::CameraParameters& cameraParamRight = stereoCalibration.calibrationRight.cameraParam;
400 
401  // Left camera parameters
402  cameraParamLeft.width = ivtCalibParamLeft.width;
403  cameraParamLeft.height = ivtCalibParamLeft.height;
404 
405  cameraParamLeft.principalPoint = convert(ivtCalibParamLeft.principalPoint);
406  cameraParamLeft.focalLength = convert(ivtCalibParamLeft.focalLength);
407  cameraParamLeft.rotation = convert(ivtCalibParamLeft.rotation);
408  cameraParamLeft.translation = convert(ivtCalibParamLeft.translation);
409 
410  cameraParamLeft.distortion.push_back(ivtCalibParamLeft.distortion[0]);
411  cameraParamLeft.distortion.push_back(ivtCalibParamLeft.distortion[1]);
412  cameraParamLeft.distortion.push_back(ivtCalibParamLeft.distortion[2]);
413  cameraParamLeft.distortion.push_back(ivtCalibParamLeft.distortion[3]);
414 
415  // right camera parameters
416  cameraParamRight.width = ivtCalibParamRight.width;
417  cameraParamRight.height = ivtCalibParamRight.height;
418 
419  cameraParamRight.principalPoint = convert(ivtCalibParamRight.principalPoint);
420  cameraParamRight.focalLength = convert(ivtCalibParamRight.focalLength);
421  cameraParamRight.rotation = convert(ivtCalibParamRight.rotation);
422  cameraParamRight.translation = convert(ivtCalibParamRight.translation);
423 
424  cameraParamRight.distortion.push_back(ivtCalibParamRight.distortion[0]);
425  cameraParamRight.distortion.push_back(ivtCalibParamRight.distortion[1]);
426  cameraParamRight.distortion.push_back(ivtCalibParamRight.distortion[2]);
427  cameraParamRight.distortion.push_back(ivtCalibParamRight.distortion[3]);
428 
429  stereoCalibration.rectificationHomographyLeft = convert(ivtStereoCalibration.rectificationHomographyLeft);
430  stereoCalibration.rectificationHomographyRight = convert(ivtStereoCalibration.rectificationHomographyRight);
431 
432  return stereoCalibration;
433 }
434 
435 
436 visionx::MonocularCalibration visionx::tools::convert(const CCalibration& ivtCalibration)
437 {
438  visionx::MonocularCalibration calibration;
439  const CCalibration::CCameraParameters& ivtCalibParam = ivtCalibration.GetCameraParameters();
440 
441  calibration.cameraParam.width = ivtCalibParam.width;
442  calibration.cameraParam.height = ivtCalibParam.height;
443 
444  calibration.cameraParam.principalPoint = convert(ivtCalibParam.principalPoint);
445  calibration.cameraParam.focalLength = convert(ivtCalibParam.focalLength);
446  calibration.cameraParam.rotation = convert(ivtCalibParam.rotation);
447  calibration.cameraParam.translation = convert(ivtCalibParam.translation);
448 
449  calibration.cameraParam.distortion.push_back(ivtCalibParam.distortion[0]);
450  calibration.cameraParam.distortion.push_back(ivtCalibParam.distortion[1]);
451  calibration.cameraParam.distortion.push_back(ivtCalibParam.distortion[2]);
452  calibration.cameraParam.distortion.push_back(ivtCalibParam.distortion[3]);
453 
454  return calibration;
455 }
456 
457 
458 visionx::types::Region visionx::tools::convert(const MyRegion& ivtRegion)
459 {
460  visionx::types::Region region;
461 
462  visionx::tools::arrayToVector(ivtRegion.pPixels, ivtRegion.nPixels, region.pixels);
463  region.nPixels = ivtRegion.nPixels;
464 
465  region.minX = ivtRegion.min_x;
466  region.maxX = ivtRegion.max_x;
467  region.minY = ivtRegion.min_y;
468  region.maxY = ivtRegion.max_y;
469 
470  region.ratio = ivtRegion.ratio;
471 
472  region.centroid = visionx::tools::convert(ivtRegion.centroid);
473 
474  return region;
475 }
476 
477 
478 MyRegion visionx::tools::convert(const visionx::types::Region& region)
479 {
480  MyRegion ivtRegion;
481 
482  ivtRegion.pPixels = visionx::tools::vectorToArray(region.pixels);
483  ivtRegion.nPixels = region.nPixels;
484 
485  ivtRegion.min_x = region.minX;
486  ivtRegion.max_x = region.maxX;
487  ivtRegion.min_y = region.minY;
488  ivtRegion.max_y = region.maxY;
489 
490  ivtRegion.ratio = region.ratio;
491 
492  ivtRegion.centroid = visionx::tools::convert(&region.centroid);
493 
494  return ivtRegion;
495 }
496 
497 
498 visionx::types::ObjectColor visionx::tools::convert(const ObjectColor& ivtObjectColor)
499 {
500  return (visionx::types::ObjectColor) ivtObjectColor;
501 }
502 
503 
504 ObjectColor visionx::tools::convert(const visionx::types::ObjectColor& objectColor)
505 {
506  return (ObjectColor) objectColor;
507 }
508 
509 
510 visionx::types::ObjectType visionx::tools::convert(const ObjectType& ivtObjectType)
511 {
512  return (visionx::types::ObjectType) ivtObjectType;
513 }
514 
515 
516 ObjectType visionx::tools::convert(const visionx::types::ObjectType& objectType)
517 {
518  return (ObjectType) objectType;
519 }
520 
521 
522 visionx::types::Transformation3d visionx::tools::convert(const Transformation3d& ivtTransformation3d)
523 {
524  visionx::types::Transformation3d transformation3d;
525 
526  transformation3d.translation = visionx::tools::convert(ivtTransformation3d.translation);
527  transformation3d.rotation = visionx::tools::convert(ivtTransformation3d.rotation);
528 
529  return transformation3d;
530 }
531 
532 
533 Transformation3d visionx::tools::convert(const visionx::types::Transformation3d& transformation3d)
534 {
535  Transformation3d ivtTransformation3d;
536 
537  ivtTransformation3d.translation = visionx::tools::convert(transformation3d.translation);
538  ivtTransformation3d.rotation = visionx::tools::convert(transformation3d.rotation);
539 
540  return ivtTransformation3d;
541 }
542 
543 
544 Object3DEntry visionx::tools::convert(const visionx::types::Object3DEntry& object3DEntry)
545 {
546  Object3DEntry ivtObject3DEntry;
547 
548  ivtObject3DEntry.region_left = convert(object3DEntry.regionLeft);
549  ivtObject3DEntry.region_right = convert(object3DEntry.regionRight);
550  ivtObject3DEntry.region_id_left = object3DEntry.regionIdLeft;
551  ivtObject3DEntry.region_id_right = object3DEntry.regionIdRight;
552  ivtObject3DEntry.type = convert(object3DEntry.type);
553  ivtObject3DEntry.color = convert(object3DEntry.color);
554  ivtObject3DEntry.pose = convert(object3DEntry.pose);
555  ivtObject3DEntry.world_point = convert(object3DEntry.worldPoint);
556  ivtObject3DEntry.orientation = convert(object3DEntry.orientation);
557  ivtObject3DEntry.sName = "";
558  ivtObject3DEntry.sName += object3DEntry.name;
559  ivtObject3DEntry.sOivFilePath = "";
560  // ivtObject3DEntry.sOivFilePath += objectEntry.oivFilePath;
561  ivtObject3DEntry.data = nullptr;
562  ivtObject3DEntry.class_id = object3DEntry.classId;
563  ivtObject3DEntry.quality = object3DEntry.quality;
564  ivtObject3DEntry.quality2 = object3DEntry .quality2;
565 
566  return ivtObject3DEntry;
567 }
568 
569 
570 visionx::types::Object3DEntry visionx::tools::convert(const Object3DEntry& ivtObject3DEntry)
571 {
572  visionx::types::Object3DEntry object3DEntry;
573 
574  object3DEntry.regionLeft = convert(ivtObject3DEntry.region_left);
575  object3DEntry.regionRight = convert(ivtObject3DEntry.region_right);
576  object3DEntry.regionIdLeft = ivtObject3DEntry.region_id_left;
577  object3DEntry.regionIdRight = ivtObject3DEntry.region_id_right;
578  object3DEntry.type = convert(ivtObject3DEntry.type);
579  object3DEntry.color = convert(ivtObject3DEntry.color);
580  object3DEntry.pose = convert(ivtObject3DEntry.pose);
581  object3DEntry.worldPoint = convert(ivtObject3DEntry.world_point);
582  object3DEntry.orientation = convert(ivtObject3DEntry.orientation);
583  object3DEntry.name = "";
584  object3DEntry.name += ivtObject3DEntry.sName;
585  //objectEntry.sOivFilePath = "";
586  // ivtObject3DEntry.sOivFilePath += objectEntry.oivFilePath;
587  object3DEntry.classId = ivtObject3DEntry.class_id;
588  object3DEntry.quality = ivtObject3DEntry.quality;
589  object3DEntry.quality2 = ivtObject3DEntry.quality2;
590 
591  return object3DEntry;
592 }
593 
594 Object3DList visionx::tools::convert(const visionx::types::Object3DList& object3DList)
595 {
596  Object3DList ivtObject3DList(object3DList.size());
597 
598  visionx::types::Object3DList::const_iterator iter = object3DList.begin();
599 
600  int i = 0;
601 
602  while (iter != object3DList.end())
603  {
604  ivtObject3DList[i] = convert(*iter);
605 
606  iter++;
607  }
608 
609  return ivtObject3DList;
610 }
611 
612 
613 visionx::types::Object3DList visionx::tools::convert(const Object3DList& ivtObject3DList)
614 {
615  visionx::types::Object3DList object3DList(ivtObject3DList.size());
616 
617  Object3DList::const_iterator iter = ivtObject3DList.begin();
618 
619  int i = 0;
620 
621  while (iter != ivtObject3DList.end())
622  {
623  object3DList[i] = convert(*iter);
624 
625  iter++;
626  }
627 
628  return object3DList;
629 }
630 
631 
633 {
634  Eigen::Matrix3f result;
635  result(0, 0) = m.r1;
636  result(0, 1) = m.r2;
637  result(0, 2) = m.r3;
638  result(1, 0) = m.r4;
639  result(1, 1) = m.r5;
640  result(1, 2) = m.r6;
641  result(2, 0) = m.r7;
642  result(2, 1) = m.r8;
643  result(2, 2) = m.r9;
644  return result;
645 }
646 
647 
649 {
650  Eigen::Vector3f result(v.x, v.y, v.z);
651  return result;
652 }
653 
654 
655 visionx::types::Vec visionx::tools::convertEigenVecToVisionX(Eigen::VectorXf v)
656 {
657  visionx::types::Vec res;
658  res.resize(v.rows());
659  for (int i = 0; i < v.rows(); i++)
660  {
661  res[i] = v[i];
662  }
663  return res;
664 }
665 
666 Eigen::VectorXf visionx::tools::convertVisionXVecToEigen(visionx::types::Vec v)
667 {
668  Eigen::VectorXf res;
669  res.resize(v.size());
670  for (int i= 0; i < v.size(); i++){
671  res[i] = v[i];
672  }
673  return res;
674 }
675 
676 
677 visionx::types::Mat visionx::tools::convertEigenMatToVisionX(Eigen::MatrixXf m)
678 {
679  visionx::types::Mat res;
680  res.resize(m.cols());
681  for (int i = 0; i < m.cols(); i++)
682  {
683  visionx::types::Vec v;
684  Eigen::VectorXf vec = m.block(0, i, m.rows(), 1);
686  res[i] = v;
687  }
688  return res;
689 }
690 
691 Eigen::MatrixXf visionx::tools::convertVisionXMatToEigen(visionx::types::Mat m)
692 {
693  if (m.empty()){
694  return Eigen::MatrixXf();
695  }
696  const size_t rows = m[0].size();
697  const size_t cols = m.size();
698 
699  Eigen::MatrixXf res(rows, cols);
700 
701  for (size_t col = 0; col < cols; ++col) {
702  visionx::types::Vec v = m[col];
703  Eigen::VectorXf vec = convertVisionXVecToEigen(v);
704  res.col(col) = vec;
705  }
706 
707  return res;
708 }
visionx::tools::convertIVTtoEigen
Eigen::Matrix3f convertIVTtoEigen(const Mat3d m)
Definition: TypeMapping.cpp:632
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
convert
void convert(const std::filesystem::path &in, const std::filesystem::path &out, bool print_progress)
Performs the actual conversion.
Definition: main.cpp:154
visionx::exceptions::local::InvalidFrameRateException
Definition: InvalidFrameRateException.h:31
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
visionx::exceptions::local::InvalidImageTypeNameException
Definition: InvalidImageTypeNameException.h:31
visionx::tools::imageTypeToTypeName
std::string imageTypeToTypeName(const ImageType imageType)
Converts an image type into a string integer.
Definition: TypeMapping.cpp:70
ExpressionException.h
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
armarx::transform
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT > >
Convenience function (with less typing) to transform a container of type InputT into the same contain...
Definition: algorithm.h:315
visionx::tools::typeNameToImageType
ImageType typeNameToImageType(const std::string &imageTypeName)
Converts an image type name as string into an ImageType integer.
Definition: TypeMapping.cpp:42
TypeMapping.h
ARMARX_CHECK_EQUAL
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
Definition: ExpressionException.h:130
visionx::exceptions::local::UnsupportedImageTypeException
Definition: UnsupportedImageTypeException.h:31