ViSP  2.10.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 or right mouse button to exit..." << std::endl;
86  bool end = false;
87  while( !end ) {
88  if (iter < 300) {
89  //y*y+z*z = 1
90  if (fabs(y) < 1.0)
91  z = sqrt(1.0-y*y);
92  else z = 0;
93 
94  //Add points to the graphic
95  if (plot.plot(0,0, x, y, z*zsign) == vpMouseButton::button3)
96  end = true;
97  if (plot.plot(0,1, x, -y, -z*zsign) == vpMouseButton::button3)
98  end = true;
99 
100  x += dx;
101 
102  if (fabs(y) >= 1.0 )
103  dy = -dy;
104  y += dy;
105  if (fabs(y) >= 1.0 )
106  zsign = -zsign;
107  }
108  else {
109  // Tip: to allows modifying the point of view with the mouse we
110  // plot always the last point
111  if (plot.plot(0,0, x, y,z*zsign) == vpMouseButton::button3)
112  end = true;
113  if (plot.plot(0,1, x, -y,-z*zsign) == vpMouseButton::button3)
114  end = true;
115  }
116  iter ++;
117  }
118  return 0;
119  }
120  catch(vpException e) {
121  std::cout << "Catch an exception: " << e << std::endl;
122  return 1;
123  }
124 #else
125  std::cout << "Plot functionalities are not avalaible since no display is available." << std::endl;
126 #endif
127 }
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