Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
plot2d.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 <visp3/core/vpConfig.h>
42#include <visp3/core/vpDebug.h>
43
44#include <visp3/core/vpMath.h>
45#include <visp3/gui/vpPlot.h>
46
47int main()
48{
49#if defined(VISP_HAVE_DISPLAY)
50#ifdef ENABLE_VISP_NAMESPACE
51 using namespace VISP_NAMESPACE_NAME;
52#endif
53
54 try {
55 vpPlot plot(2, 700, 700, 100, 200, "Curves...");
56
57 // Change the default font
58 // plot.setFont("-misc-fixed-bold-r-semicondensed--0-0-75-75-c-0-iso8859-10");
59
60 // Initialize the number of curve for each graphic
61 plot.initGraph(0, 1);
62 plot.initGraph(1, 1);
63
64 // Set the color of the curves
65 plot.setColor(0, 0, vpColor::green);
66 plot.setColor(1, 0, vpColor::red);
67
68 // Set the titles of the graphic
69 char title[40];
70 strncpy(title, "cos function", 40);
71 plot.setTitle(0, title);
72 strncpy(title, "sin function", 40);
73 plot.setTitle(1, title);
74
75 // Set the legend of each curves
76 char legend[40];
77 strncpy(legend, "cos x", 40);
78 plot.setLegend(0, 0, legend);
79 strncpy(legend, "sin x", 40);
80 plot.setLegend(1, 0, legend);
81
82 // Set the x axis legend of each curves
83 char unit[40];
84 strncpy(unit, "x", 40);
85 plot.setUnitX(0, unit);
86 strncpy(unit, "x", 40);
87 plot.setUnitX(1, unit);
88
89 // Set the y axis legend of each curves
90 strncpy(unit, "y", 40);
91 plot.setUnitY(0, unit);
92 strncpy(unit, "y", 40);
93 plot.setUnitY(1, unit);
94
95 // Plot the cosinus and sinus functions
96 double i = 0;
97 while (i <= 20 * 2 * M_PI) {
98 double co = cos(i);
99 double si = sin(i);
100 plot.plot(0, 0, i, co);
101 plot.plot(1, 0, i, si);
102 i += 0.1;
103 }
104
106
107 // Save the datas as text files
108 plot.saveData(0, "dataCos.txt", "# ");
109 plot.saveData(1, "dataSin.txt", "# ");
110 return EXIT_SUCCESS;
111 }
112 catch (const vpException &e) {
113 std::cout << "Catch an exception: " << e << std::endl;
114 return EXIT_FAILURE;
115 }
116
117#else
118 std::cout << "Plot functionalities are not avalaible since no display is "
119 "available."
120 << std::endl;
121 return EXIT_SUCCESS;
122#endif
123}
static const vpColor red
Definition vpColor.h:198
static const vpColor green
Definition vpColor.h:201
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
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