ViSP  2.9.0
plot3d.cpp
1 /****************************************************************************
2  *
3  * $Id: plot.cpp 3530 2012-01-03 10:52:12Z 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 <iostream>
50 #include <visp/vpConfig.h>
51 #include <visp/vpPlot.h>
52 
53 int main ()
54 {
55 #if defined(VISP_HAVE_DISPLAY)
56  try {
57  //Create a window with one graphic
58  vpPlot plot(1);
59 
60  // Change the default font
61  //plot.setFont("-misc-fixed-bold-r-semicondensed--0-0-75-75-c-0-iso8859-10");
62 
63  //The graphic contains 2 curves
64  plot.initGraph(0,2);
65 
66  //Set the graphic parameters
67  plot.setTitle(0, "First graphic");
68  plot.setUnitX(0, "time (s)");
69  plot.setUnitY(0, "y");
70  plot.setUnitZ(0, "z");
71  plot.setLegend(0,0, "y^2+z^2=1 and y(0) = 1");
72  plot.setLegend(0,1, "y^2+z^2=1 and y(0) = -1");
73  plot.setColor(0,0,vpColor::red);
74  plot.setColor(0,1,vpColor::green);
75 
76  double x = 0;
77  double y = 1;
78  double z = 0 ;
79  double dx = 0.08;
80  double dy = 0.04;
81  double zsign = 1.0;
82 
83  unsigned long iter = 0;
84 
85  std::cout << "Hit CTRL-C to exit...";
86  while(1) {
87  if (iter < 300) {
88  //y*y+z*z = 1
89  if (fabs(y) < 1.0)
90  z = sqrt(1.0-y*y);
91  else z = 0;
92 
93  //Add points to the graphic
94  plot.plot(0,0, x, y,z*zsign);
95  plot.plot(0,1, x, -y,-z*zsign);
96 
97  x += dx;
98 
99  if (fabs(y) >= 1.0 )
100  dy = -dy;
101  y += dy;
102  if (fabs(y) >= 1.0 )
103  zsign = -zsign;
104  }
105  else {
106  // Tip: to allows modifying the point of view with the mouse we
107  // plot always the last point
108  plot.plot(0,0, x, y,z*zsign);
109  plot.plot(0,1, x, -y,-z*zsign);
110  }
111  iter ++;
112  }
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: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