1/** 2 3\page tutorial-plotter Tutorial: Real-time curves plotter tool 4\tableofcontents 5 6This tutorial focuses on real-time curves drawing. It shows how to modify tutorial-ibvs-4pts.cpp introduced in \ref tutorial-ibvs to draw the evolution of the visual features error and the camera velocity skew vector during an image-based visual servoing. 7 8Note that all the material (source code and image) described in this tutorial is part of ViSP source code and could be downloaded using the following command: 9 10\code 11$ svn export https://github.com/lagadic/visp.git/trunk/tutorial/visual-servoing/ibvs 12\endcode 13 14The modified code also available in tutorial-ibvs-4pts-plotter.cpp is the following. 15 16 17\include tutorial-ibvs-4pts-plotter.cpp 18 19The last image of the drawing is the following: 20 21\image html img-ibvs-plotter.jpg Last image produced by the plotter. 22 23Now we describe the new lines that were introduced: 24 25\code 26#include <visp3/core/vpPlot.h> 27\endcode 28 29Include the header of the vpPlot class that allows curves drawing. 30 31\code 32#ifdef VISP_HAVE_DISPLAY 33 vpPlot plotter(2, 250*2, 500, 100, 200, "Real time curves plotter"); 34\endcode 35 36Since the plotter opens a windows to display the graphics, the usage of vpPlot class is only possible if ViSP is build with a 3rd party that allows display capabilities; either libx11, GDI, OpenCV or GTK. If this is the case, we create an instance of the vpPlot class. The window that is created will contain two graphics. The windows size will be 500 by 500 pixels. The window position will be (100, 200), and the title "Real time curves plotter". 37 38\code 39 plotter.setTitle(0, "Visual features error"); 40 plotter.setTitle(1, "Camera velocities"); 41\endcode 42 43To differentiate the graphics we associate a title to each of them. The first graphic (the one with index 0) will be designed to draw the evolution of the visual features error, while the second (index 1) will be designed to draw the camera velocities. 44 45\code 46 plotter.initGraph(0, 8); 47 plotter.initGraph(1, 6); 48\endcode 49 50Here we initialize the first graphic to be able to plot 8 curves. We recall that we have 4 points, each point has 2 visual features (x and y), that is why there are 8 curves to plot. The second graphic is designed to plot 6 curves corresponding to the camera velocities (3 translation velocities in m/s and 3 rotation velocities in rad/s). 51 52\code 53 plotter.setLegend(0, 0, "x1"); 54 plotter.setLegend(0, 1, "y1"); 55 plotter.setLegend(0, 2, "x2"); 56 plotter.setLegend(0, 3, "y2"); 57 plotter.setLegend(0, 4, "x3"); 58 plotter.setLegend(0, 5, "y3"); 59 plotter.setLegend(0, 6, "x4"); 60 plotter.setLegend(0, 7, "y4"); 61 62 plotter.setLegend(1, 0, "v_x"); 63 plotter.setLegend(1, 1, "v_y"); 64 plotter.setLegend(1, 2, "v_z"); 65 plotter.setLegend(1, 3, "w_x"); 66 plotter.setLegend(1, 4, "w_y"); 67 plotter.setLegend(1, 5, "w_z"); 68#endif 69\endcode 70 71The previous lines allow to associate a legend to each curve. 72 73\code 74#ifdef VISP_HAVE_DISPLAY 75 plotter.plot(0, iter, task.getError()); 76 plotter.plot(1, iter, v); 77#endif 78\endcode 79 80Once the plotter is initialized, in the servo loop we add at each iteration the corresponding values of the visual features error \f${\bf e}(t) = {\bf s}-{\bf s}^*\f$, and the camera velocities \f${\bf v}_c\f$. 81 82\code 83#ifdef VISP_HAVE_DISPLAY 84 plotter.saveData(0, "error.dat"); 85 plotter.saveData(1, "vc.dat"); 86#endif 87\endcode 88 89At the end of the servo loop, we save the data that were plotted in two separate files, one for each graphic. The first line of each text file is the graphic title. Then the coordinates along x,y and z are given in separated columns for each data. 90 91\code 92 vpDisplay::getClick(plotter.I); 93\endcode 94 95Before exiting the program we wait for a human mouse click in the plotter window. 96 97*/ 98