ViSP  3.0.0
plot3d.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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 <iostream>
46 #include <visp3/core/vpConfig.h>
47 #include <visp3/gui/vpPlot.h>
48 
49 int main ()
50 {
51 #if defined(VISP_HAVE_DISPLAY)
52  try {
53  //Create a window with one graphic
54  vpPlot plot(1);
55 
56  // Change the default font
57  //plot.setFont("-misc-fixed-bold-r-semicondensed--0-0-75-75-c-0-iso8859-10");
58 
59  //The graphic contains 2 curves
60  plot.initGraph(0,2);
61 
62  //Set the graphic parameters
63  plot.setTitle(0, "First graphic");
64  plot.setUnitX(0, "time (s)");
65  plot.setUnitY(0, "y");
66  plot.setUnitZ(0, "z");
67  plot.setLegend(0,0, "y^2+z^2=1 and y(0) = 1");
68  plot.setLegend(0,1, "y^2+z^2=1 and y(0) = -1");
69  plot.setColor(0,0,vpColor::red);
70  plot.setColor(0,1,vpColor::green);
71 
72  double x = 0;
73  double y = 1;
74  double z = 0 ;
75  double dx = 0.08;
76  double dy = 0.04;
77  double zsign = 1.0;
78 
79  unsigned long iter = 0;
80 
81  std::cout << "Hit CTRL-C to or right mouse button to exit..." << std::endl;
82  bool end = false;
83  while( !end ) {
84  if (iter < 300) {
85  //y*y+z*z = 1
86  if (fabs(y) < 1.0)
87  z = sqrt(1.0-y*y);
88  else z = 0;
89 
90  //Add points to the graphic
91  if (plot.plot(0,0, x, y, z*zsign) == vpMouseButton::button3)
92  end = true;
93  if (plot.plot(0,1, x, -y, -z*zsign) == vpMouseButton::button3)
94  end = true;
95 
96  x += dx;
97 
98  if (fabs(y) >= 1.0 )
99  dy = -dy;
100  y += dy;
101  if (fabs(y) >= 1.0 )
102  zsign = -zsign;
103  }
104  else {
105  // Tip: to allows modifying the point of view with the mouse we
106  // plot always the last point
107  if (plot.plot(0,0, x, y,z*zsign) == vpMouseButton::button3)
108  end = true;
109  if (plot.plot(0,1, x, -y,-z*zsign) == vpMouseButton::button3)
110  end = true;
111  }
112  iter ++;
113  }
114  return 0;
115  }
116  catch(vpException e) {
117  std::cout << "Catch an exception: " << e << std::endl;
118  return 1;
119  }
120 #else
121  std::cout << "Plot functionalities are not avalaible since no display is available." << std::endl;
122 #endif
123 }
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