ViSP  2.9.0
plot2d.cpp
1 /****************************************************************************
2  *
3  * $Id: plot2d.cpp 4574 2014-01-09 08:48:51Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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  try {
59  vpPlot plot(2, 700, 700, 100, 200, "Curves...");
60 
61  // Change the default font
62  // plot.setFont("-misc-fixed-bold-r-semicondensed--0-0-75-75-c-0-iso8859-10");
63 
64  //Initialize the number of curve for each graphic
65  plot.initGraph(0,1);
66  plot.initGraph(1,1);
67 
68  //Set the color of the curves
69  plot.setColor(0,0,vpColor::green);
70  plot.setColor(1,0,vpColor::red);
71 
72  //Set the titles of the graphic
73  char title[40];
74  strncpy( title, "cos function", 40 );
75  plot.setTitle(0,title);
76  strncpy( title, "sin function", 40 );
77  plot.setTitle(1, title);
78 
79  //Set the legend of each curves
80  char legend[40];
81  strncpy( legend, "cos x", 40 );
82  plot.setLegend(0,0,legend);
83  strncpy( legend, "sin x", 40 );
84  plot.setLegend(1,0, legend);
85 
86  //Set the x axis legend of each curves
87  char unit[40];
88  strncpy( unit, "x", 40 );
89  plot.setUnitX(0,unit);
90  strncpy( unit, "x", 40 );
91  plot.setUnitX(1,unit);
92 
93  //Set the y axis legend of each curves
94  strncpy( unit, "y", 40 );
95  plot.setUnitY(0,unit);
96  strncpy( unit, "y", 40 );
97  plot.setUnitY(1,unit);
98 
99  //Plot the cosinus and sinus functions
100  double i = 0;
101  while(i <= 20*2*M_PI)
102  {
103  double co = cos(i);
104  double si = sin(i);
105  plot.plot(0,0,i,co);
106  plot.plot(1,0,i,si);
107  i+=0.1;
108  }
109 
110  vpDisplay::getClick(plot.I);
111 
112  //Save the datas as text files
113  plot.saveData(0, "dataCos.txt");
114  plot.saveData(0, "dataSin.txt");
115  return 0;
116  }
117  catch(vpException e) {
118  std::cout << "Catch an exception: " << e << std::endl;
119  return 1;
120  }
121 
122 #else
123  std::cout << "Plot functionalities are not avalaible since no display is available." << std::endl;
124 #endif
125 
126 }
error that can be emited by ViSP classes.
Definition: vpException.h:76
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