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