ViSP  2.8.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 - 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 <iostream>
50 #include <visp/vpConfig.h>
51 #include <visp/vpPlot.h>
52 
53 int main ()
54 {
55 #if defined(VISP_HAVE_DISPLAY)
56  //Create a window with one graphic
57  vpPlot plot(1);
58 
59  // Change the default font
60  //plot.setFont("-misc-fixed-bold-r-semicondensed--0-0-75-75-c-0-iso8859-10");
61 
62  //The graphic contains 2 curves
63  plot.initGraph(0,2);
64 
65  //Set the graphic parameters
66  plot.setTitle(0, "First graphic");
67  plot.setUnitX(0, "time (s)");
68  plot.setUnitY(0, "y");
69  plot.setUnitZ(0, "z");
70  plot.setLegend(0,0, "y^2+z^2=1 and y(0) = 1");
71  plot.setLegend(0,1, "y^2+z^2=1 and y(0) = -1");
72  plot.setColor(0,0,vpColor::red);
73  plot.setColor(0,1,vpColor::green);
74 
75  double x = 0;
76  double y = 1;
77  double z = 0 ;
78  double dx = 0.08;
79  double dy = 0.04;
80  double zsign = 1.0;
81 
82  unsigned long iter = 0;
83 
84  std::cout << "Hit CTRL-C to exit...";
85  while(1) {
86  if (iter < 300) {
87  //y*y+z*z = 1
88  if (fabs(y) < 1.0)
89  z = sqrt(1.0-y*y);
90  else z = 0;
91 
92  //Add points to the graphic
93  plot.plot(0,0, x, y,z*zsign);
94  plot.plot(0,1, x, -y,-z*zsign);
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  plot.plot(0,0, x, y,z*zsign);
108  plot.plot(0,1, x, -y,-z*zsign);
109  }
110  iter ++;
111  }
112 
113  return 0;
114 #else
115  std::cout << "Plot functionalities are not avalaible since no display is available." << std::endl;
116 #endif
117 }
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