Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
plot3d.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Example which describes how to use the vpPlot class
32 *
33 */
34
40
41#include <iostream>
42#include <visp3/core/vpConfig.h>
43#include <visp3/gui/vpPlot.h>
44
45int main()
46{
47#if defined(VISP_HAVE_DISPLAY)
48#ifdef ENABLE_VISP_NAMESPACE
49 using namespace VISP_NAMESPACE_NAME;
50#endif
51
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 }
105 else {
106 // Tip: to allows modifying the point of view with the mouse we
107 // plot always the last point
108 if (plot.plot(0, 0, x, y, z * zsign) == vpMouseButton::button3)
109 end = true;
110 if (plot.plot(0, 1, x, -y, -z * zsign) == vpMouseButton::button3)
111 end = true;
112 }
113 iter++;
114 }
115 return EXIT_SUCCESS;
116 }
117 catch (const vpException &e) {
118 std::cout << "Catch an exception: " << e << std::endl;
119 return EXIT_FAILURE;
120 }
121#else
122 std::cout << "Plot functionalities are not avalaible since no display is "
123 "available."
124 << std::endl;
125 return EXIT_SUCCESS;
126#endif
127}
static const vpColor red
Definition vpColor.h:198
static const vpColor green
Definition vpColor.h:201
error that can be emitted by ViSP classes.
Definition vpException.h:60
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition vpPlot.h:117