Visual Servoing Platform  version 3.1.0
vpPlotCurve.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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, const double x, const 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, const double xorg, const double yorg, const double zoomx,
99  const double zoomy)
100 {
101  std::list<double>::const_iterator it_ptListx = pointListx.begin();
102  std::list<double>::const_iterator it_ptListy = pointListy.begin();
103 
104  unsigned int k = 0;
105  vpImagePoint iP;
106  while (k < nbPoint) {
107  iP.set_ij(yorg - (zoomy * (*it_ptListy)), xorg + (zoomx * (*it_ptListx)));
108 
109  if (k > 0)
110  vpDisplay::displayLine(I, lastPoint, iP, color, thickness);
111 
112  lastPoint = iP;
113 
114  ++it_ptListx;
115  ++it_ptListy;
116  k++;
117  }
118 }
119 
120 #elif !defined(VISP_BUILD_SHARED_LIBS)
121 // Work arround to avoid warning: libvisp_core.a(vpPlotCurve.cpp.o) has no
122 // symbols
123 void dummy_vpPlotCurve(){};
124 #endif
125 #endif
double get_i() const
Definition: vpImagePoint.h:204
vpImage< unsigned char > I
Definition: vpPlot.h:118
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
double get_j() const
Definition: vpImagePoint.h:215
Defines a rectangle in the plane.
Definition: vpRect.h:78
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:88
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
void set_ij(const double ii, const double jj)
Definition: vpImagePoint.h:189