Visual Servoing Platform  version 3.4.0
plot2d.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 <visp3/core/vpConfig.h>
46 #include <visp3/core/vpDebug.h>
47 
48 #include <visp3/core/vpMath.h>
49 #include <visp3/gui/vpPlot.h>
50 
51 int main()
52 {
53 #if defined(VISP_HAVE_DISPLAY)
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 
105  vpDisplay::getClick(plot.I);
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  } catch (const vpException &e) {
112  std::cout << "Catch an exception: " << e << std::endl;
113  return EXIT_FAILURE;
114  }
115 
116 #else
117  std::cout << "Plot functionalities are not avalaible since no display is "
118  "available."
119  << std::endl;
120  return EXIT_SUCCESS;
121 #endif
122 }
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
error that can be emited by ViSP classes.
Definition: vpException.h:71
static const vpColor green
Definition: vpColor.h:220
static const vpColor red
Definition: vpColor.h:217
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition: vpPlot.h:115