Visual Servoing Platform  version 3.6.1 under development (2024-04-23)
vpFeatureDisplay.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  * Interface with the image for feature display.
33  *
34 *****************************************************************************/
35 
36 #include <visp3/core/vpFeatureDisplay.h>
37 
38 // Meter/pixel conversion
39 #include <visp3/core/vpMeterPixelConversion.h>
40 
41 // display
42 #include <visp3/core/vpDisplay.h>
43 
44 // Debug trace
45 #include <visp3/core/vpDebug.h>
46 
47 // math
48 #include <visp3/core/vpMath.h>
49 
50 #include <visp3/core/vpImagePoint.h>
51 
63 void vpFeatureDisplay::displayPoint(double x, double y, const vpCameraParameters &cam, const vpImage<unsigned char> &I,
64  const vpColor &color, unsigned int thickness)
65 {
66  vpImagePoint ip; // pixel coordinates in float
68  vpDisplay::displayCross(I, ip, 15, color, thickness);
69 }
70 
81 void vpFeatureDisplay::displayLine(double rho, double theta, const vpCameraParameters &cam,
82  const vpImage<unsigned char> &I, const vpColor &color, unsigned int thickness)
83 {
84  // --comment: x times cos(theta) plus y times sin(theta) minus rho equals 0
85  double rhop, thetap;
86  vpMeterPixelConversion::convertLine(cam, rho, theta, rhop, thetap);
87 
88  // --comment: u times cos thetap plus v times sin thetap minus rhop equals 0
89  double co = cos(thetap);
90  double si = sin(thetap);
91  double c = -rhop;
92 
93  double a = si;
94  double b = co;
95  vpImagePoint ip1, ip2;
96 
97  if (fabs(a) < fabs(b)) {
98  ip1.set_ij(0, (-c) / b);
99  double h = I.getHeight() - 1;
100  ip2.set_ij(h, (-c - (a * h)) / b);
101  vpDisplay::displayLine(I, ip1, ip2, color, thickness);
102  }
103  else {
104  ip1.set_ij((-c) / a, 0);
105  double w = I.getWidth() - 1;
106  ip2.set_ij((-c - (b * w)) / a, w);
107  vpDisplay::displayLine(I, ip1, ip2, color, thickness);
108  }
109 }
110 
122 void vpFeatureDisplay::displayCylinder(double rho1, double theta1, double rho2, double theta2,
123  const vpCameraParameters &cam, const vpImage<unsigned char> &I,
124  const vpColor &color, unsigned int thickness)
125 {
126  displayLine(rho1, theta1, cam, I, color, thickness);
127  displayLine(rho2, theta2, cam, I, color, thickness);
128 }
129 
147 void vpFeatureDisplay::displayEllipse(double x, double y, double n20, double n11, double n02,
148  const vpCameraParameters &cam, const vpImage<unsigned char> &I,
149  const vpColor &color, unsigned int thickness)
150 {
151  vpImagePoint center;
152  double n20_p, n11_p, n02_p;
153  vpCircle circle;
154  circle.p[0] = x;
155  circle.p[1] = y;
156  circle.p[2] = n20;
157  circle.p[3] = n11;
158  circle.p[4] = n02;
159 
160  vpMeterPixelConversion::convertEllipse(cam, circle, center, n20_p, n11_p, n02_p);
161  vpDisplay::displayEllipse(I, center, n20_p, n11_p, n02_p, true, color, thickness);
162 }
163 
175 void vpFeatureDisplay::displayPoint(double x, double y, const vpCameraParameters &cam, const vpImage<vpRGBa> &I,
176  const vpColor &color, unsigned int thickness)
177 {
178  vpImagePoint ip; // pixel coordinates in float
180 
181  vpDisplay::displayCross(I, ip, 15, color, thickness);
182 }
183 
194 void vpFeatureDisplay::displayLine(double rho, double theta, const vpCameraParameters &cam, const vpImage<vpRGBa> &I,
195  const vpColor &color, unsigned int thickness)
196 {
197  // --comment: x times cos of theta plus y times sin of theta minus rho equals 0
198  double rhop, thetap;
199  vpMeterPixelConversion::convertLine(cam, rho, theta, rhop, thetap);
200 
201  // --comment: u times cos of thetap plus v times sin of thetap minus rhop equals 0
202  double co = cos(thetap);
203  double si = sin(thetap);
204  double c = -rhop;
205 
206  double a = si;
207  double b = co;
208  vpImagePoint ip1, ip2;
209 
210  if (fabs(a) < fabs(b)) {
211  ip1.set_ij(0, (-c) / b);
212  double h = I.getHeight() - 1;
213  ip2.set_ij(h, (-c - (a * h)) / b);
214  vpDisplay::displayLine(I, ip1, ip2, color, thickness);
215  }
216  else {
217  ip1.set_ij((-c) / a, 0);
218  double w = I.getWidth() - 1;
219  ip2.set_ij((-c - (b * w)) / a, w);
220  vpDisplay::displayLine(I, ip1, ip2, color, thickness);
221  }
222 }
223 
235 void vpFeatureDisplay::displayCylinder(double rho1, double theta1, double rho2, double theta2,
236  const vpCameraParameters &cam, const vpImage<vpRGBa> &I, const vpColor &color,
237  unsigned int thickness)
238 {
239  displayLine(rho1, theta1, cam, I, color, thickness);
240  displayLine(rho2, theta2, cam, I, color, thickness);
241 }
242 
260 void vpFeatureDisplay::displayEllipse(double x, double y, double n20, double n11, double n02,
261  const vpCameraParameters &cam, const vpImage<vpRGBa> &I, const vpColor &color,
262  unsigned int thickness)
263 {
264  vpImagePoint center;
265  double n20_p, n11_p, n02_p;
266  vpCircle circle;
267  circle.p[0] = x;
268  circle.p[1] = y;
269  circle.p[2] = n20;
270  circle.p[3] = n11;
271  circle.p[4] = n02;
272 
273  vpMeterPixelConversion::convertEllipse(cam, circle, center, n20_p, n11_p, n02_p);
274  vpDisplay::displayEllipse(I, center, n20_p, n11_p, n02_p, true, color, thickness);
275 }
Generic class defining intrinsic camera parameters.
Class that defines a 3D circle in the object frame and allows forward projection of a 3D circle in th...
Definition: vpCircle.h:86
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 displayEllipse(const vpImage< unsigned char > &I, const vpImagePoint &center, const double &coef1, const double &coef2, const double &coef3, bool use_normalized_centered_moments, const vpColor &color, unsigned int thickness=1, bool display_center=false, bool display_arc=false)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void displayCylinder(double rho1, double theta1, double rho2, double theta2, const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1)
static void displayLine(double rho, double theta, const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1)
static void displayEllipse(double x, double y, double n20, double n11, double n02, const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1)
static void displayPoint(double x, double y, const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
void set_ij(double ii, double jj)
Definition: vpImagePoint.h:315
unsigned int getWidth() const
Definition: vpImage.h:245
unsigned int getHeight() const
Definition: vpImage.h:184
static void convertLine(const vpCameraParameters &cam, const double &rho_m, const double &theta_m, double &rho_p, double &theta_p)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
static void convertEllipse(const vpCameraParameters &cam, const vpSphere &sphere, vpImagePoint &center_p, double &n20_p, double &n11_p, double &n02_p)
vpColVector p
Definition: vpTracker.h:67