Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
vpPlotCurve.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Define a curve for the vpPlot class.
32  *
33 *****************************************************************************/
34 #include <visp3/core/vpConfig.h>
35 
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
37 
38 #include <visp3/gui/vpDisplayD3D.h>
39 #include <visp3/gui/vpDisplayGDI.h>
40 #include <visp3/gui/vpDisplayGTK.h>
41 #include <visp3/gui/vpDisplayOpenCV.h>
42 #include <visp3/gui/vpDisplayX.h>
43 #include <visp3/gui/vpPlotCurve.h>
44 
45 #if defined(VISP_HAVE_DISPLAY)
46 
47 BEGIN_VISP_NAMESPACE
48 
49 vpPlotCurve::vpPlotCurve()
50  : color(vpColor::red), curveStyle(point), thickness(1), nbPoint(0), lastPoint(), pointListx(), pointListy(),
51  pointListz(), legend(), xmin(0), xmax(0), ymin(0), ymax(0)
52 { }
53 
54 vpPlotCurve::~vpPlotCurve()
55 {
56  pointListx.clear();
57  pointListy.clear();
58  pointListz.clear();
59 }
60 
61 void vpPlotCurve::plotPoint(const vpImage<unsigned char> &I, const vpImagePoint &iP, double x, double y)
62 {
63  nbPoint++;
64 
65  if (nbPoint > 1) {
66  vpDisplay::displayLine(I, lastPoint, iP, color, thickness);
67  }
68 #if defined(VISP_HAVE_DISPLAY)
69  double top;
70  double left;
71  double width;
72  double height;
73 
74  if (iP.get_i() <= lastPoint.get_i()) {
75  top = iP.get_i() - 5;
76  height = lastPoint.get_i() - top + 10;
77  }
78  else {
79  top = lastPoint.get_i() - 5;
80  height = iP.get_i() - top + 10;
81  }
82  if (iP.get_j() <= lastPoint.get_j()) {
83  left = iP.get_j() - 5;
84  width = lastPoint.get_j() - left + 10;
85  }
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 END_VISP_NAMESPACE
120 
121 #elif !defined(VISP_BUILD_SHARED_LIBS)
122 // Work around to avoid warning: libvisp_gui.a(vpPlotCurve.cpp.o) has no symbols
123 void dummy_vpPlotCurve() { };
124 #endif
125 #endif
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
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:320
double get_i() const
Definition: vpImagePoint.h:114
Defines a rectangle in the plane.
Definition: vpRect.h:79