Visual Servoing Platform version 3.5.0
plot3d.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See http://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 *
31 * Description:
32 * Example which describes how to use the vpPlot class
33 *
34 * Author:
35 * Nicolas Melchior
36 *
37 *****************************************************************************/
38
45#include <iostream>
46#include <visp3/core/vpConfig.h>
47#include <visp3/gui/vpPlot.h>
48
49int main()
50{
51#if defined(VISP_HAVE_DISPLAY)
52 try {
53 // Create a window with one graphic
54 vpPlot plot(1);
55
56 // Change the default font
57 // plot.setFont("-misc-fixed-bold-r-semicondensed--0-0-75-75-c-0-iso8859-10");
58
59 // The graphic contains 2 curves
60 plot.initGraph(0, 2);
61
62 // Set the graphic parameters
63 plot.setTitle(0, "First graphic");
64 plot.setUnitX(0, "time (s)");
65 plot.setUnitY(0, "y");
66 plot.setUnitZ(0, "z");
67 plot.setLegend(0, 0, "y^2+z^2=1 and y(0) = 1");
68 plot.setLegend(0, 1, "y^2+z^2=1 and y(0) = -1");
69 plot.setColor(0, 0, vpColor::red);
70 plot.setColor(0, 1, vpColor::green);
71
72 double x = 0;
73 double y = 1;
74 double z = 0;
75 double dx = 0.08;
76 double dy = 0.04;
77 double zsign = 1.0;
78
79 unsigned long iter = 0;
80
81 std::cout << "Hit CTRL-C to or right mouse button to exit..." << std::endl;
82 bool end = false;
83 while (!end) {
84 if (iter < 300) {
85 // y*y+z*z = 1
86 if (fabs(y) < 1.0)
87 z = sqrt(1.0 - y * y);
88 else
89 z = 0;
90
91 // Add points to the graphic
92 if (plot.plot(0, 0, x, y, z * zsign) == vpMouseButton::button3)
93 end = true;
94 if (plot.plot(0, 1, x, -y, -z * zsign) == vpMouseButton::button3)
95 end = true;
96
97 x += dx;
98
99 if (fabs(y) >= 1.0)
100 dy = -dy;
101 y += dy;
102 if (fabs(y) >= 1.0)
103 zsign = -zsign;
104 } else {
105 // Tip: to allows modifying the point of view with the mouse we
106 // plot always the last point
107 if (plot.plot(0, 0, x, y, z * zsign) == vpMouseButton::button3)
108 end = true;
109 if (plot.plot(0, 1, x, -y, -z * zsign) == vpMouseButton::button3)
110 end = true;
111 }
112 iter++;
113 }
114 return EXIT_SUCCESS;
115 } catch (const vpException &e) {
116 std::cout << "Catch an exception: " << e << std::endl;
117 return EXIT_FAILURE;
118 }
119#else
120 std::cout << "Plot functionalities are not avalaible since no display is "
121 "available."
122 << std::endl;
123 return EXIT_SUCCESS;
124#endif
125}
static const vpColor red
Definition: vpColor.h:217
static const vpColor green
Definition: vpColor.h:220
error that can be emited by ViSP classes.
Definition: vpException.h:72
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition: vpPlot.h:116