1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Plot curves.
33  *
34  * Authors:
35  * Nicolas Melchior
36  *
37  *****************************************************************************/
38 
39 /*!
40   \file vpPlot.h
41   \brief Plot curves.
42 */
43 
44 #ifndef vpPlot_H
45 #define vpPlot_H
46 
47 #include <visp3/core/vpConfig.h>
48 #include <visp3/core/vpDisplay.h>
49 #include <visp3/gui/vpPlotGraph.h>
50 
51 /*!
52   \class vpPlot
53   \ingroup group_gui_plotter
54 
55   \brief This class enables real time drawing of 2D or 3D graphics. An
56   instance of the class open a window which contains between 1 and 4
57   graphics. Each one contains a desired number of curves.
58 
59   \warning This class is only available if one of the display functionalities
60   (X11, GDI, GTK, OpenCV or Direct3D) is available. In visp3/core/vpConfig.h
61   header file, you should have VISP_HAVE_DISPLAY define.
62 
63   The example below shows how to use the vpPlot class. An other example
64   provided in tutorial-ibvs-plotter.cpp and described in \ref tutorial-plotter
65   shows how to use this class to plot in real-time some curves during an
66   image-based visual servo.
67 
68   \code
69 #include <visp3/gui/vpPlot.h>
70 
71 int main ()
72 {
73 #if defined(VISP_HAVE_DISPLAY)
74   // Create a window (700 by 700) at position (100, 200) with two graphics
75   vpPlot A(2, 700, 700, 100, 200, "Curves...");
76 
77   // The first graphic contains 1 curve and the second graphic contains 2 curves
78   A.initGraph(0,1); A.initGraph(1,2);
79 
80   // The color of the curve in the first graphic is red
81   A.setColor(0,0,vpColor::red);
82   // The first curve in the second graphic is green
83   A.setColor(1,0,vpColor::green);
84   // The second curve in the second graphic is blue
85   A.setColor(1,1,vpColor::blue);
86 
87   // Add the point (0,0) in the first graphic
88   A.plot(0,0,0,0);
89 
90   // Add the point (0,1) to the first curve of the second graphic
91   A.plot(1,0,0,1);
92 
93   // Add the point (0,2) to the second curve of the second graphic
94   A.plot(1,1,0,2);
95 
96   for (int i = 0; i < 50; i++) {
97     // Add the point (i,sin(i*pi/10) in the first graphic
98     A.plot(0,0,i,sin(i*M_PI/10));
99 
100     // Add the point (i,1) to the first curve of the second graphic
101     A.plot(1,0,i,1);
102 
103     // Add the point (i,2) to the second curve of the second graphic
104     A.plot(1,1,i,2);
105   }
106 
107   return 0;
108 #endif
109 }
110   \endcode
111 */
112 
113 #if defined(VISP_HAVE_DISPLAY)
114 
115 class VISP_EXPORT vpPlot
116 {
117 public:
118   vpImage<unsigned char> I;
119 
120 private:
121   vpDisplay *display;
122 
123   unsigned int graphNbr;
124   vpPlotGraph *graphList;
125 
126   unsigned int margei;
127   unsigned int margej;
128 
129   float factori;
130   float factorj;
131 
132   // private:
133   //#ifndef DOXYGEN_SHOULD_SKIP_THIS
134   //    vpPlot(const vpPlot &)
135   //      : I(), display(NULL), graphNbr(0), graphList(NULL), margei(0),
136   //      margej(0),
137   //        factori(0), factorj(0)
138   //    {
139   //      throw vpException(vpException::functionNotImplementedError, "Not
140   //      implemented!");
141   //    }
142   //    vpPlot &operator=(const vpPlot &){
143   //      throw vpException(vpException::functionNotImplementedError, "Not
144   //      implemented!"); return *this;
145   //    }
146   //#endif
147 
148 public:
149   vpPlot();
150   vpPlot(unsigned int nbGraph, unsigned int height = 700, unsigned int width = 700, int x = -1,
151          int y = -1, const std::string &title = "");
152   virtual ~vpPlot();
153   void getPixelValue(bool block);
154   void init(unsigned int nbGraph, unsigned int height = 700, unsigned int width = 700,
155             int x = -1, int y = -1, const std::string &title = "");
156   void initGraph(unsigned int graphNum, unsigned int curveNbr);
157 
158   void initRange(unsigned int graphNum, double xmin, double xmax, double ymin, double ymax);
159   void initRange(unsigned int graphNum, double xmin, double xmax, double ymin, double ymax, double zmin,
160                  double zmax);
161   void navigate(void);
162 
163   void plot(unsigned int graphNum, unsigned int curveNum, double x, double y);
164   void plot(unsigned int graphNum, double x, const vpColVector &v_y);
165   void plot(unsigned int graphNum, double x, const vpRowVector &v_y);
166   void plot(unsigned int graphNum, double x, const vpPoseVector &v_y);
167   void plot(unsigned int graphNum, double x, const vpTranslationVector &v_y);
168   void plot(unsigned int graphNum, double x, const vpRotationVector &v_y);
169   vpMouseButton::vpMouseButtonType plot(unsigned int graphNum, unsigned int curveNum, double x,
170                                         double y, double z);
171   vpMouseButton::vpMouseButtonType plot(unsigned int graphNum, double x, const vpColVector &v_y,
172                                         const vpColVector &v_z);
173 
174   void resetPointList(unsigned int graphNum);
175   void resetPointList(unsigned int graphNum, unsigned int curveNum);
176 
177   void saveData(unsigned int graphNum, const std::string &dataFile, const std::string &title_prefix = "");
178   void setColor(unsigned int graphNum, unsigned int curveNum, vpColor color);
179   void setGraphThickness(unsigned int graphNum, unsigned int thickness);
180   void setGridThickness(unsigned int graphNum, unsigned int thickness);
181   /*!
182     Set the font of the characters. The display should be initialized before.
183 
184     To know which font are available, on Unix you can use xfontsel or xlsfonts
185     utilities.
186     */
setFont(const std::string & font)187   void setFont(const std::string &font)
188   {
189     if (display->isInitialised())
190       vpDisplay::setFont(I, font.c_str());
191   }
192   void setLegend(unsigned int graphNum, unsigned int curveNum, const std::string &legend);
193   void setTitle(unsigned int graphNum, const std::string &title);
194   void setUnitX(unsigned int graphNum, const std::string &unitx);
195   void setUnitY(unsigned int graphNum, const std::string &unity);
196   void setUnitZ(unsigned int graphNum, const std::string &unitz);
197   void setThickness(unsigned int graphNum, unsigned int curveNum, unsigned int thickness);
198 
199 private:
200   void initNbGraph(unsigned int nbGraph);
201   void displayGrid();
202 };
203 #endif
204 
205 #endif
206