Visual Servoing Platform  version 3.0.1
plot2d.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Author:
34  * Nicolas Melchior
35  *
36  *****************************************************************************/
37 
38 
45 #include <visp3/core/vpConfig.h>
46 #include <visp3/core/vpDebug.h>
47 
48 #include <visp3/gui/vpPlot.h>
49 #include <visp3/core/vpMath.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  {
99  double co = cos(i);
100  double si = sin(i);
101  plot.plot(0,0,i,co);
102  plot.plot(1,0,i,si);
103  i+=0.1;
104  }
105 
106  vpDisplay::getClick(plot.I);
107 
108  //Save the datas as text files
109  plot.saveData(0, "dataCos.txt", "# ");
110  plot.saveData(1, "dataSin.txt", "# ");
111  return 0;
112  }
113  catch(vpException &e) {
114  std::cout << "Catch an exception: " << e << std::endl;
115  return 1;
116  }
117 
118 #else
119  std::cout << "Plot functionalities are not avalaible since no display is available." << std::endl;
120 #endif
121 
122 }
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
error that can be emited by ViSP classes.
Definition: vpException.h:73
static const vpColor green
Definition: vpColor.h:166
static const vpColor red
Definition: vpColor.h:163
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition: vpPlot.h:113