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 
12 #include <mrpt/system/os.h>
13 #include <iostream>
14 
15 using namespace mrpt;
16 using namespace mrpt::gui;
17 using namespace mrpt::math;
18 using namespace std;
19 
20 void myOnMenu(int menuID, float x, float y, void* param)
21 {
22  cout << "Menu: " << menuID << endl << " x=" << x << " y=" << y << endl;
23 }
24 
25 // ------------------------------------------------------
26 // TestDisplayPlots
27 // ------------------------------------------------------
28 void TestDisplayPlots()
29 {
30  CDisplayWindowPlots win("Example of function plot", 400, 300);
31 
32  win.enableMousePanZoom(true);
33  win.addPopupMenuEntry("Mark this point...", 1);
34  win.setMenuCallback(myOnMenu);
35 
36  // Generate data for a 2D plot:
37  CVectorDouble X, Y;
38  for (double x = 0; x < 5; x += 0.01f)
39  {
40  double y = math::normalPDF(x, 2, 0.3);
41  X.push_back(x);
42  Y.push_back(y);
43  }
44 
45  win.plot(X, Y, "r-3");
46  win.axis_equal(false);
47  win.axis_fit();
48 
49  win.setPos(10, 10);
50  // -----------
51  CDisplayWindowPlots win2("Example of plot update", 400, 300);
52 
53  win2.enableMousePanZoom(true);
54 
55  // Add an unnamed & a named ellipse:
56  float mean_x = 5;
57  float mean_y = 0;
58  CMatrixFloat ellipse_cov(2, 2);
59  ellipse_cov(0, 0) = 1.0f;
60  ellipse_cov(1, 1) = 1.0f;
61  ellipse_cov(0, 1) = ellipse_cov(1, 0) = 0.5f;
62 
63  win2.plotEllipse(1.0f, 2.0f, ellipse_cov, 3, "k-2");
64  win2.plotEllipse(mean_x, mean_y, ellipse_cov, 3, "b-2", "my_ellipse");
65 
66  win2.axis(-10, 10, -10, 10);
67  win2.axis_equal(true);
68 
69  win2.setPos(450, 10);
70 
71  cout << "Press any key to exit..." << endl;
72  // win.waitForKey();
73 
74  float t = 0;
75  ellipse_cov(0, 1) = ellipse_cov(1, 0) = -0.9f;
76  while (!mrpt::system::os::kbhit() && win.isOpen() && win2.isOpen() &&
77  !win.keyHit() && !win2.keyHit())
78  {
79  t += 0.05f;
80  mean_x = cos(t) * 5;
81  mean_y = sin(t) * 5;
82  win2.plotEllipse(mean_x, mean_y, ellipse_cov, 3, "b-2", "my_ellipse");
83 
84  std::this_thread::sleep_for(50ms);
85  }
86 }
87 
88 // ------------------------------------------------------
89 // MAIN
90 // ------------------------------------------------------
91 int main()
92 {
93  try
94  {
96  return 0;
97  }
98  catch (std::exception& e)
99  {
100  std::cout << "MRPT exception caught: " << e.what() << std::endl;
101  return -1;
102  }
103  catch (...)
104  {
105  printf("Untyped exception!!");
106  return -1;
107  }
108 }
mrpt::system::os::kbhit
bool kbhit() noexcept
An OS-independent version of kbhit, which returns true if a key has been pushed.
Definition: os.cpp:390
os.h
TestDisplayPlots
void TestDisplayPlots()
Definition: vision_stereo_rectify/test.cpp:28
t
GLdouble GLdouble t
Definition: glext.h:3689
mrpt::math::dynamic_vector
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction.
Definition: eigen_frwds.h:44
myOnMenu
void myOnMenu(int menuID, float x, float y, void *param)
Definition: vision_stereo_rectify/test.cpp:20
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::math::normalPDF
double normalPDF(double x, double mu, double std)
Evaluates the univariate normal (Gaussian) distribution at a given point "x".
Definition: math.cpp:33
mrpt::math::CMatrixTemplateNumeric
A matrix of dynamic size.
Definition: CMatrixTemplateNumeric.h:37
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
win
mrpt::gui::CDisplayWindow3D::Ptr win
Definition: vision_stereo_rectify/test.cpp:31
distributions.h
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:16
mrpt::gui::CDisplayWindowPlots
Create a GUI window and display plots with MATLAB-like interfaces and commands.
Definition: CDisplayWindowPlots.h:31
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
CDisplayWindowPlots.h
y
GLenum GLint GLint y
Definition: glext.h:3538
x
GLenum GLint x
Definition: glext.h:3538
param
GLfloat param
Definition: glext.h:3831



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