Main MRPT website > C++ reference for MRPT 1.9.9
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <mrpt/poses/CPose2D.h>
11 #include <mrpt/poses/CPose3D.h>
12 #include <mrpt/poses/CPoint3D.h>
13 #include <mrpt/system/CTicTac.h>
14 #include <iostream>
15 
16 using namespace mrpt;
17 using namespace mrpt::poses;
18 using namespace mrpt::system;
19 using namespace std;
20 
21 void TestGeometry3D2()
22 {
23  CPose3D iniPoseVehicle(
24  745.327749, 407.959716, 14.851070, -2.985091, 0.009412, 0.051315);
25 
26  CPoint3D GPSPosOnVehicle(-0.25, 0, 0.10);
27 
28  CPoint3D iniPoseGPS = iniPoseVehicle + GPSPosOnVehicle;
29 
30  printf(
31  "Pose: %.6f,%.6f,%.6f", iniPoseGPS.x(), iniPoseGPS.y(), iniPoseGPS.z());
32 }
33 // ------------------------------------------------------
34 // TestGeometry3D
35 // ------------------------------------------------------
36 void TestGeometry3D()
37 {
38  // The landmark (global) position: 3D (x,y,z)
39  CPoint3D L(0, 4, 2);
40 
41  // Robot pose: 2D (x,y,phi)
42  CPose2D R(2, 1, DEG2RAD(45.0f));
43 
44  // Camera pose relative to the robot: 6D (x,y,z,yaw,pitch,roll).
45  CPose3D C(0.5f, 0.5f, 1.5f, DEG2RAD(-90.0f), DEG2RAD(0), DEG2RAD(-90.0f));
46 
47  // TEST 1. Relative position L' of the landmark wrt the camera
48  // --------------------------------------------------------------
49  cout << "L: " << L << endl;
50  cout << "R: " << R << endl;
51  cout << "C: " << C << endl;
52  cout << "R+C:" << (R + C) << endl;
53  // cout << (R+C).getHomogeneousMatrix();
54 
55  CPoint3D L2;
56  CTicTac tictac;
57  tictac.Tic();
58  size_t i, N = 10000;
59  for (i = 0; i < N; i++) L2 = L - (R + C);
60  cout << "Computation in: " << 1e6 * tictac.Tac() / ((double)N) << " us"
61  << endl;
62 
63  cout << "L': " << L2 << endl;
64 
65  // TEST 2. Reconstruct the landmark position:
66  // --------------------------------------------------------------
67  CPoint3D L3 = R + C + L2;
68  cout << "R(+)C(+)L' = " << L3 << endl;
69  cout << "Should be equal to L = " << L << endl;
70 
71  // TEST 3. Distance from the camera to the landmark
72  // --------------------------------------------------------------
73  cout << "|(R(+)C)-L|= " << (R + C).distanceTo(L) << endl;
74  cout << "|L-(R(+)C)|= " << (R + C).distanceTo(L) << endl;
75 }
76 
77 // ------------------------------------------------------
78 // MAIN
79 // ------------------------------------------------------
80 int main()
81 {
82  try
83  {
85  // TestGeometry3D2();
86  return 0;
87  }
88  catch (exception& e)
89  {
90  cerr << "EXCEPCTION: " << e.what() << endl;
91  return -1;
92  }
93  catch (...)
94  {
95  cerr << "Untyped excepcion!!";
96  return -1;
97  }
98 }
TestGeometry3D
void TestGeometry3D()
Definition: vision_stereo_rectify/test.cpp:36
mrpt::system::CTicTac
A high-performance stopwatch, with typical resolution of nanoseconds.
Definition: system/CTicTac.h:19
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
TestGeometry3D2
void TestGeometry3D2()
Definition: vision_stereo_rectify/test.cpp:21
R
const float R
Definition: CKinematicChain.cpp:138
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:25
CPose2D.h
mrpt::system::CTicTac::Tac
double Tac() noexcept
Stops the stopwatch.
Definition: CTicTac.cpp:90
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::poses::CPoseOrPoint::y
double y() const
Definition: CPoseOrPoint.h:144
mrpt::poses::CPose2D
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
Definition: CPose2D.h:40
mrpt::poses::CPoseOrPoint::x
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:140
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
mrpt::system::CTicTac::Tic
void Tic() noexcept
Starts the stopwatch.
Definition: CTicTac.cpp:79
CPoint3D.h
CPose3D.h
CTicTac.h
mrpt::poses::CPoint3D
A class used to store a 3D point.
Definition: CPoint3D.h:33
mrpt::system
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Definition: math_frwds.h:25
mrpt::DEG2RAD
double DEG2RAD(const double x)
Degrees to radians.
Definition: core/include/mrpt/core/bits_math.h:42



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST