ViSP  2.8.0
plot2d.cpp
1 /****************************************************************************
2  *
3  * $Id: plot2d.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Example which describes how to use the vpPlot class
36  *
37  * Author:
38  * Nicolas Melchior
39  *
40  *****************************************************************************/
41 
42 
49 #include <visp/vpConfig.h>
50 #include <visp/vpDebug.h>
51 
52 #include <visp/vpPlot.h>
53 #include <visp/vpMath.h>
54 
55 int main ()
56 {
57 #if defined(VISP_HAVE_DISPLAY)
58  vpPlot plot(2, 700, 700, 100, 200, "Curves...");
59 
60  // Change the default font
61  // plot.setFont("-misc-fixed-bold-r-semicondensed--0-0-75-75-c-0-iso8859-10");
62 
63  //Initialize the number of curve for each graphic
64  plot.initGraph(0,1);
65  plot.initGraph(1,1);
66 
67  //Set the color of the curves
68  plot.setColor(0,0,vpColor::green);
69  plot.setColor(1,0,vpColor::red);
70 
71  //Set the titles of the graphic
72  char title[40];
73  strncpy( title, "cos function", 40 );
74  plot.setTitle(0,title);
75  strncpy( title, "sin function", 40 );
76  plot.setTitle(1, title);
77 
78  //Set the legend of each curves
79  char legend[40];
80  strncpy( legend, "cos x", 40 );
81  plot.setLegend(0,0,legend);
82  strncpy( legend, "sin x", 40 );
83  plot.setLegend(1,0, legend);
84 
85  //Set the x axis legend of each curves
86  char unit[40];
87  strncpy( unit, "x", 40 );
88  plot.setUnitX(0,unit);
89  strncpy( unit, "x", 40 );
90  plot.setUnitX(1,unit);
91 
92  //Set the y axis legend of each curves
93  strncpy( unit, "y", 40 );
94  plot.setUnitY(0,unit);
95  strncpy( unit, "y", 40 );
96  plot.setUnitY(1,unit);
97 
98  //Plot the cosinus and sinus functions
99  double i = 0;
100  while(i <= 20*2*M_PI)
101  {
102  double co = cos(i);
103  double si = sin(i);
104  plot.plot(0,0,i,co);
105  plot.plot(1,0,i,si);
106  i+=0.1;
107  }
108 
109  vpDisplay::getClick(plot.I);
110 
111  //Save the datas as text files
112  plot.saveData(0, "dataCos.txt");
113  plot.saveData(0, "dataSin.txt");
114 #else
115  std::cout << "Plot functionalities are not avalaible since no display is available." << std::endl;
116 #endif
117 
118  return 0;
119 }
static const vpColor green
Definition: vpColor.h:170
static const vpColor red
Definition: vpColor.h:167
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition: vpPlot.h:117
virtual bool getClick(bool blocking=true)=0