Visual Servoing Platform  version 3.4.0
vpPlotCurve.cpp
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  * Define a curve for the vpPlot class.
33  *
34  * Authors:
35  * Nicolas Melchior
36  *
37  *****************************************************************************/
38 #include <visp3/core/vpConfig.h>
39 
40 #ifndef DOXYGEN_SHOULD_SKIP_THIS
41 
42 #include <visp3/gui/vpDisplayD3D.h>
43 #include <visp3/gui/vpDisplayGDI.h>
44 #include <visp3/gui/vpDisplayGTK.h>
45 #include <visp3/gui/vpDisplayOpenCV.h>
46 #include <visp3/gui/vpDisplayX.h>
47 #include <visp3/gui/vpPlotCurve.h>
48 
49 #if defined(VISP_HAVE_DISPLAY)
50 vpPlotCurve::vpPlotCurve()
51  : color(vpColor::red), curveStyle(point), thickness(1), nbPoint(0), lastPoint(), pointListx(), pointListy(),
52  pointListz(), legend(), xmin(0), xmax(0), ymin(0), ymax(0)
53 {
54 }
55 
56 vpPlotCurve::~vpPlotCurve()
57 {
58  pointListx.clear();
59  pointListy.clear();
60  pointListz.clear();
61 }
62 
63 void vpPlotCurve::plotPoint(const vpImage<unsigned char> &I, const vpImagePoint &iP, double x, double y)
64 {
65  nbPoint++;
66 
67  if (nbPoint > 1) {
68  vpDisplay::displayLine(I, lastPoint, iP, color, thickness);
69  }
70 #if defined(VISP_HAVE_DISPLAY)
71  double top;
72  double left;
73  double width;
74  double height;
75 
76  if (iP.get_i() <= lastPoint.get_i()) {
77  top = iP.get_i() - 5;
78  height = lastPoint.get_i() - top + 10;
79  } else {
80  top = lastPoint.get_i() - 5;
81  height = iP.get_i() - top + 10;
82  }
83  if (iP.get_j() <= lastPoint.get_j()) {
84  left = iP.get_j() - 5;
85  width = lastPoint.get_j() - left + 10;
86  } else {
87  left = lastPoint.get_j() - 5;
88  width = iP.get_j() - left + 10;
89  }
90  vpDisplay::flushROI(I, vpRect(left, top, width, height));
91 #endif
92  lastPoint = iP;
93  pointListx.push_back(x);
94  pointListy.push_back(y);
95  pointListz.push_back(0.0);
96 }
97 
98 void vpPlotCurve::plotList(const vpImage<unsigned char> &I, double xorg, double yorg, double zoomx, double zoomy)
99 {
100  std::list<double>::const_iterator it_ptListx = pointListx.begin();
101  std::list<double>::const_iterator it_ptListy = pointListy.begin();
102 
103  unsigned int k = 0;
104  vpImagePoint iP;
105  while (k < nbPoint) {
106  iP.set_ij(yorg - (zoomy * (*it_ptListy)), xorg + (zoomx * (*it_ptListx)));
107 
108  if (k > 0)
109  vpDisplay::displayLine(I, lastPoint, iP, color, thickness);
110 
111  lastPoint = iP;
112 
113  ++it_ptListx;
114  ++it_ptListy;
115  k++;
116  }
117 }
118 
119 #elif !defined(VISP_BUILD_SHARED_LIBS)
120 // Work arround to avoid warning: libvisp_core.a(vpPlotCurve.cpp.o) has no
121 // symbols
122 void dummy_vpPlotCurve(){};
123 #endif
124 #endif
vpImage< unsigned char > I
Definition: vpPlot.h:118
double get_i() const
Definition: vpImagePoint.h:203
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:157
double get_j() const
Definition: vpImagePoint.h:214
void set_ij(double ii, double jj)
Definition: vpImagePoint.h:188
Defines a rectangle in the plane.
Definition: vpRect.h:79
static void flushROI(const vpImage< unsigned char > &I, const vpRect &roi)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:87
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)