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 * Display implementation.
33 *
34 * Authors:
35 * Fabien Spindler
36 *
37 *****************************************************************************/
38
39 #include <visp3/core/vpDisplay.h>
40
41 #include "vpDisplay_impl.h"
42
43 //************************************************************************
44 // Modifications done in this file should be reported in all vpDisplay_*.cpp
45 // files that implement other types (unsigned char, vpRGB, vpRGBa)
46 //************************************************************************
47
48 /*!
49 Close the display attached to I.
50 */
close(vpImage<vpRGBa> & I)51 void vpDisplay::close(vpImage<vpRGBa> &I) { vp_display_close(I); }
52
53 /*!
54 Display an arrow from image point \e ip1 to image point \e ip2.
55 \param I : The image associated to the display.
56 \param ip1,ip2 : Initial and final image points.
57 \param color : Arrow color.
58 \param w,h : Width and height of the arrow.
59 \param thickness : Thickness of the lines used to display the arrow.
60 */
displayArrow(const vpImage<vpRGBa> & I,const vpImagePoint & ip1,const vpImagePoint & ip2,const vpColor & color,unsigned int w,unsigned int h,unsigned int thickness)61 void vpDisplay::displayArrow(const vpImage<vpRGBa> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
62 const vpColor &color, unsigned int w, unsigned int h, unsigned int thickness)
63 {
64 vp_display_display_arrow(I, ip1, ip2, color, w, h, thickness);
65 }
66
67 /*!
68 Display an arrow from image point (i1,j1) to image point (i2,j2).
69
70 \param I : The image associated to the display.
71 \param i1,j1 : Initial image point.
72 \param i2,j2 : Final image point.
73 \param color : Arrow color.
74 \param w,h : Width and height of the arrow.
75 \param thickness : Thickness of the lines used to display the arrow.
76 */
displayArrow(const vpImage<vpRGBa> & I,int i1,int j1,int i2,int j2,const vpColor & color,unsigned int w,unsigned int h,unsigned int thickness)77 void vpDisplay::displayArrow(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
78 unsigned int w, unsigned int h, unsigned int thickness)
79 {
80 vp_display_display_arrow(I, i1, j1, i2, j2, color, w, h, thickness);
81 }
82
83 /*!
84 Display the projection of an object camera represented by a cone in
85 the image.
86
87 \param I : The image associated to the display.
88 \param cMo : Homogeneous matrix that gives the transformation
89 between the camera frame and the object frame to project in the
90 image.
91 \param cam : Camera intrinsic parameters.
92 \param size : Size of the object camera.
93 \param color : Color used to display the camera in the image.
94 \param thickness : Thickness of the graphics drawing.
95 */
displayCamera(const vpImage<vpRGBa> & I,const vpHomogeneousMatrix & cMo,const vpCameraParameters & cam,double size,const vpColor & color,unsigned int thickness)96 void vpDisplay::displayCamera(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
97 double size, const vpColor &color, unsigned int thickness)
98 {
99 vp_display_display_camera(I, cMo, cam, size, color, thickness);
100 }
101
102 /*!
103 Display a string at the image point \e ip location.
104 Use rather displayText() that does the same.
105
106 To select the font used to display the string, use setFont().
107
108 \param I : Image associated to the display.
109 \param ip : Upper left image point location of the string in the display.
110 \param string : String to display in overlay.
111 \param color : String color.
112
113 \sa setFont(), displayText()
114 */
displayCharString(const vpImage<vpRGBa> & I,const vpImagePoint & ip,const char * string,const vpColor & color)115 void vpDisplay::displayCharString(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const char *string,
116 const vpColor &color)
117 {
118 vp_display_display_char_string(I, ip, string, color);
119 }
120
121 /*!
122 Display a string at the image point (i,j) location.
123 Use rather displayText() that does the same.
124
125 To select the font used to display the string, use setFont().
126
127 \param I : Image associated to the display.
128 \param i,j : Upper left image point location of the string in the display.
129 \param string : String to display in overlay.
130 \param color : String color.
131
132 \sa setFont(), displayText()
133 */
displayCharString(const vpImage<vpRGBa> & I,int i,int j,const char * string,const vpColor & color)134 void vpDisplay::displayCharString(const vpImage<vpRGBa> &I, int i, int j, const char *string, const vpColor &color)
135 {
136 vp_display_display_char_string(I, i, j, string, color);
137 }
138
139 /*!
140 Display a circle.
141 \param I : The image associated to the display.
142 \param center : Circle center position.
143 \param radius : Circle radius.
144 \param color : Circle color.
145 \param fill : When set to true fill the circle. When vpDisplayOpenCV is used,
146 and color alpha channel is set, filling feature can handle transparency. See vpColor
147 header class documentation.
148 \param thickness : Thickness of the circle. This parameter is only useful
149 when \e fill is set to false.
150 */
displayCircle(const vpImage<vpRGBa> & I,const vpImagePoint & center,unsigned int radius,const vpColor & color,bool fill,unsigned int thickness)151 void vpDisplay::displayCircle(const vpImage<vpRGBa> &I, const vpImagePoint ¢er, unsigned int radius,
152 const vpColor &color, bool fill, unsigned int thickness)
153 {
154 vp_display_display_circle(I, center, radius, color, fill, thickness);
155 }
156
157 /*!
158 Display a circle.
159 \param I : The image associated to the display.
160 \param i,j : Circle center position.
161 \param radius : Circle radius.
162 \param color : Circle color.
163 \param fill : When set to true fill the circle. When vpDisplayOpenCV is used,
164 and color alpha channel is set, filling feature can handle transparency. See vpColor
165 header class documentation.
166 \param thickness : Thickness of the circle. This parameter is only useful
167 when \e fill is set to false.
168 */
displayCircle(const vpImage<vpRGBa> & I,int i,int j,unsigned int radius,const vpColor & color,bool fill,unsigned int thickness)169 void vpDisplay::displayCircle(const vpImage<vpRGBa> &I, int i, int j, unsigned int radius, const vpColor &color,
170 bool fill, unsigned int thickness)
171 {
172 vp_display_display_circle(I, i, j, radius, color, fill, thickness);
173 }
174
175 /*!
176 Display a cross at the image point \e ip location.
177 \param I : The image associated to the display.
178 \param ip : Cross location.
179 \param size : Size (width and height) of the cross.
180 \param color : Cross color.
181 \param thickness : Thickness of the lines used to display the cross.
182 */
displayCross(const vpImage<vpRGBa> & I,const vpImagePoint & ip,unsigned int size,const vpColor & color,unsigned int thickness)183 void vpDisplay::displayCross(const vpImage<vpRGBa> &I, const vpImagePoint &ip, unsigned int size, const vpColor &color,
184 unsigned int thickness)
185 {
186 vp_display_display_cross(I, ip, size, color, thickness);
187 }
188
189 /*!
190 Display a cross at the image point (i,j) location.
191 \param I : The image associated to the display.
192 \param i,j : Cross location.
193 \param size : Size (width and height) of the cross.
194 \param color : Cross color.
195 \param thickness : Thickness of the lines used to display the cross.
196 */
displayCross(const vpImage<vpRGBa> & I,int i,int j,unsigned int size,const vpColor & color,unsigned int thickness)197 void vpDisplay::displayCross(const vpImage<vpRGBa> &I, int i, int j, unsigned int size, const vpColor &color,
198 unsigned int thickness)
199 {
200 vp_display_display_cross(I, i, j, size, color, thickness);
201 }
202
203 /*!
204 Display a dashed line from image point \e ip1 to image point \e ip2.
205 \param I : The image associated to the display.
206 \param ip1,ip2 : Initial and final image points.
207 \param color : Line color.
208 \param thickness : Dashed line thickness.
209 */
displayDotLine(const vpImage<vpRGBa> & I,const vpImagePoint & ip1,const vpImagePoint & ip2,const vpColor & color,unsigned int thickness)210 void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
211 const vpColor &color, unsigned int thickness)
212 {
213 vp_display_display_dot_line(I, ip1, ip2, color, thickness);
214 }
215
216 /*!
217 Display a dashed line from image point (i1,j1) to image point (i2,j2).
218 \param I : The image associated to the display.
219 \param i1,j1: Initial image point.
220 \param i2,j2: Final image point.
221 \param color : Line color.
222 \param thickness : Dashed line thickness.
223 */
displayDotLine(const vpImage<vpRGBa> & I,int i1,int j1,int i2,int j2,const vpColor & color,unsigned int thickness)224 void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
225 unsigned int thickness)
226 {
227 vp_display_display_dot_line(I, i1, j1, i2, j2, color, thickness);
228 }
229
230 /*!
231 Display the dashed lines formed by the list of image points
232 \param I : The image associated to the display.
233 \param ips : Vector of image points.
234 \param closeTheShape : If true, display a dashed line from the first and
235 last image points.
236 \param color : Line color.
237 \param thickness : Dashed line thickness.
238 */
displayDotLine(const vpImage<vpRGBa> & I,const std::vector<vpImagePoint> & ips,bool closeTheShape,const vpColor & color,unsigned int thickness)239 void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &ips, bool closeTheShape,
240 const vpColor &color, unsigned int thickness)
241 {
242 if (ips.size() <= 1)
243 return;
244
245 for (size_t i = 0; i < ips.size() - 1; i++)
246 vp_display_display_dot_line(I, ips[i], ips[i + 1], color, thickness);
247
248 if (closeTheShape)
249 vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
250 }
251
252 /*!
253 Display the dashed lines formed by the list of image points
254 \param I : The image associated to the display.
255 \param ips : List of image points.
256 \param closeTheShape : If true, display a dashed line from the first and
257 last image points.
258 \param color : Line color.
259 \param thickness : Dashed line thickness.
260 */
displayDotLine(const vpImage<vpRGBa> & I,const std::list<vpImagePoint> & ips,bool closeTheShape,const vpColor & color,unsigned int thickness)261 void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
262 const vpColor &color, unsigned int thickness)
263 {
264 if (ips.size() <= 1)
265 return;
266
267 std::list<vpImagePoint>::const_iterator it = ips.begin();
268
269 vpImagePoint ip_prev = *(it++);
270 for (; it != ips.end(); ++it) {
271 if (vpImagePoint::distance(ip_prev, *it) > 1) {
272 vp_display_display_dot_line(I, ip_prev, *it, color, thickness);
273 ip_prev = *it;
274 }
275 }
276
277 if (closeTheShape) {
278 vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
279 }
280 }
281
282 /*!
283 Display an ellipse from its parameters expressed in pixels.
284 \param I : Image to consider.
285 \param center : Center \f$(u_c, v_c)\f$ of the ellipse.
286 \param coef1, coef2, coef3 : Depending on the parameter \e
287 use_normalized_centered_moments these parameters are:
288 - second order centered moments of the ellipse normalized by its area
289 (i.e., such that \f$n_{ij} = \mu_{ij}/a\f$ where \f$\mu_{ij}\f$ are the
290 centered moments and a the area) expressed in pixels.
291 - the major and minor axis lenght in pixels and the excentricity of the
292 ellipse in radians: \f$a, b, e\f$.
293 \param use_normalized_centered_moments : When false,
294 the parameters coef1, coef2, coef3 are the parameters \f$a, b, e\f$. When
295 true, the parameters coef1, coef2, coef3 are rather the normalized centered moments
296 \f$n_{20}, n_{11}, n_{02}\f$ expressed in pixels. In that case, we
297 compute the parameters \e a, \e b and \e e from the centered moments.
298 \param color : Ellipse color.
299 \param thickness : Ellipse thickness.
300 \param display_center : Display a cross at the center of the ellipse.
301 \param display_arc : Display a line between the center and the first arc extremity
302 and a line between the center and the second arc extremity.
303
304 The following example shows how to use for example this function to display
305 the result of a tracking.
306 \code
307 vpMeEllipse ellipse;
308 ...
309 vpDisplay::display(I);
310 ellipse.track(I);
311
312 vpDisplay::displayEllipse(I, ellipse.getCenter(),
313 ellipse.get_nij()[0], ellipse.get_nij()[1], ellipse.get_nij()[2],
314 true, vpColor::orange, 1);
315 vpDisplay::flush(I);
316 \endcode
317 */
displayEllipse(const vpImage<vpRGBa> & I,const vpImagePoint & center,const double & coef1,const double & coef2,const double & coef3,bool use_normalized_centered_moments,const vpColor & color,unsigned int thickness,bool display_center,bool display_arc)318 void vpDisplay::displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint ¢er, const double &coef1,
319 const double &coef2, const double &coef3, bool use_normalized_centered_moments,
320 const vpColor &color, unsigned int thickness, bool display_center, bool display_arc)
321 {
322 vpDisplay::displayEllipse(I, center, coef1, coef2, coef3, 0., 2 * M_PI, use_normalized_centered_moments, color,
323 thickness, display_center, display_arc);
324 }
325
326 /*!
327 Display an ellipse from its parameters expressed in pixels.
328 \param I : Image to consider.
329 \param center : Center \f$(u_c, v_c)\f$ of the ellipse.
330 \param coef1, coef2, coef3 : Depending on the parameter \e
331 use_normalized_centered_moments these parameters are:
332 - second order centered moments of the ellipse normalized by its area
333 (i.e., such that \f$n_{ij} = \mu_{ij}/a\f$ where \f$\mu_{ij}\f$ are the
334 centered moments and a the area) expressed in pixels.
335 - the major and minor axis lenght in pixels and the excentricity of the
336 ellipse in radians: \f$a, b, e\f$.
337 \param smallalpha : Smallest \f$ alpha \f$ angle in rad (0 for a complete ellipse).
338 \param highalpha : Highest \f$ alpha \f$ angle in rad (2 \f$ \Pi \f$ for a complete ellipse).
339 \param use_normalized_centered_moments : When false, the parameters coef1,
340 coef2, coef3 are the parameters \f$a, b, e\f$. When true, the parameters
341 coef1, coef2, coef3 are rather the normalized centered moments \f$n_{20}, n_{11},
342 n_{02}\f$ expressed in pixels. In that case, we compute the parameters \e
343 a, \e b and \e e from the centered moments.
344 \param color : Ellipse color.
345 \param thickness : Ellipse thickness.
346 \param display_center : Display a cross at the center of the ellipse.
347 \param display_arc : Display a line between the center and the first arc extremity
348 and a line between the center and the second arc extremity.
349
350 The following example shows how to use for example this function to display
351 the result of a tracking.
352 \code
353 vpMeEllipse ellipse;
354 ...
355 vpDisplay::display(I);
356 ellipse.track(I);
357
358 vpDisplay::displayEllipse(I, ellipse.getCenter(),
359 ellipse.get_nij()[0], ellipse.get_nij()[1], ellipse.get_nij()[2],
360 ellipse.getSmallestAngle(), ellipse.getHighestAngle(),
361 true, vpColor::orange, 1);
362 vpDisplay::flush(I);
363 \endcode
364 */
displayEllipse(const vpImage<vpRGBa> & I,const vpImagePoint & center,const double & coef1,const double & coef2,const double & coef3,const double & smallalpha,const double & highalpha,bool use_normalized_centered_moments,const vpColor & color,unsigned int thickness,bool display_center,bool display_arc)365 void vpDisplay::displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint ¢er, const double &coef1,
366 const double &coef2, const double &coef3, const double &smallalpha, const double &highalpha,
367 bool use_normalized_centered_moments, const vpColor &color, unsigned int thickness,
368 bool display_center, bool display_arc)
369 {
370 vp_display_display_ellipse(I, center, coef1, coef2, coef3, smallalpha, highalpha, use_normalized_centered_moments,
371 color, thickness, display_center, display_arc);
372 }
373
374 /*!
375 Display the projection of an object frame represented by 3 arrows in
376 the image. Red, green and blue arrows correspond to frame X, Y and Z axis respectively.
377
378 \param I : The image associated to the display.
379 \param cMo : Homogeneous matrix that gives the transformation
380 between the camera frame and the object frame to project in the
381 image.
382 \param cam : Camera intrinsic parameters.
383 \param size : Size of the object frame.
384 \param color : Color used to display the frame in the image.
385 \param thickness : the thickness of the line.
386 \param offset : Offset in pixels applied to the frame origin location in the
387 image.
388 */
displayFrame(const vpImage<vpRGBa> & I,const vpHomogeneousMatrix & cMo,const vpCameraParameters & cam,double size,const vpColor & color,unsigned int thickness,const vpImagePoint & offset)389 void vpDisplay::displayFrame(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
390 double size, const vpColor &color, unsigned int thickness, const vpImagePoint &offset)
391 {
392 vp_display_display_frame(I, cMo, cam, size, color, thickness, offset);
393 }
394
395 /*!
396 Display a line from image point \e ip1 to image point \e ip2.
397 \param I : The image associated to the display.
398 \param ip1,ip2 : Initial and final image points.
399 \param color : Line color.
400 \param thickness : Line thickness.
401 \param segment: If true (default) display the segment between the two image points.
402 If false, display the line passing through the two image points.
403 */
displayLine(const vpImage<vpRGBa> & I,const vpImagePoint & ip1,const vpImagePoint & ip2,const vpColor & color,unsigned int thickness,bool segment)404 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
405 const vpColor &color, unsigned int thickness, bool segment)
406 {
407 displayLine(I, static_cast<int>(ip1.get_i()), static_cast<int>(ip1.get_j()), static_cast<int>(ip2.get_i()), static_cast<int>(ip2.get_j()), color, thickness, segment);
408 }
409
410 /*!
411 Display a line from image point (i1,j1) to image point (i2,j2).
412 \param I : The image associated to the display.
413 \param i1,j1: Initial image point.
414 \param i2,j2: Final image point.
415 \param color : Line color.
416 \param thickness : Line thickness.
417 \param segment: If true (default) display the segment between the two image points.
418 If false, display the line passing through the two image points.
419 */
displayLine(const vpImage<vpRGBa> & I,int i1,int j1,int i2,int j2,const vpColor & color,unsigned int thickness,bool segment)420 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
421 unsigned int thickness, bool segment)
422 {
423 if (segment) {
424 vp_display_display_line(I, i1, j1, i2, j2, color, thickness);
425 }
426 else {
427 // line equation in image: i = a * j + b
428 double delta_j = static_cast<double>(j2) - static_cast<double>(j1);
429 double delta_i = static_cast<double>(i2) - static_cast<double>(i1);
430 // Test if horizontal line
431 if (std::fabs(delta_i) <= std::numeric_limits<double>::epsilon()) {
432 vp_display_display_line(I, i1, 0, i1, (I.getWidth()-1), color, thickness);
433 }
434 // Test if vertical line
435 else if (std::fabs(delta_j) <= std::numeric_limits<double>::epsilon()) {
436 vp_display_display_line(I, 0, j1, (I.getHeight()-1), j1, color, thickness);
437 }
438 else {
439 double a = delta_i / delta_j;
440 double b = static_cast<double>(i1) - a * static_cast<double>(j1);
441 std::vector<vpImagePoint> vip; // Image points that intersect image borders
442 // Test intersection with vertical line j=0
443 vpImagePoint ip_left(b, 0);
444 if (ip_left.get_i() >= 0. && ip_left.get_i() <= (I.getHeight()-1.)) {
445 vip.push_back(ip_left);
446 }
447 // Test intersection with vertical line j=width-1
448 vpImagePoint ip_right(a*(I.getWidth()-1)+b, I.getWidth()-1.);
449 if (ip_right.get_i() >= 0. && ip_right.get_i() <= (I.getHeight()-1.)) {
450 vip.push_back(ip_right);
451 }
452 if (vip.size() == 2) {
453 vp_display_display_line(I, vip[0], vip[1], color, thickness);
454 return;
455 }
456 // Test intersection with horizontal line i=0
457 vpImagePoint ip_top(0, -b/a);
458 if (ip_top.get_j() >= 0. && ip_top.get_j() <= (I.getWidth()-1.)) {
459 vip.push_back(ip_top);
460 }
461 if (vip.size() == 2) {
462 vp_display_display_line(I, vip[0], vip[1], color, thickness);
463 return;
464 }
465 // Test intersection with horizontal line i=height-1
466 vpImagePoint ip_bottom(I.getHeight()-1., (I.getHeight()-1. - b)/a);
467 if (ip_bottom.get_j() >= 0. && ip_bottom.get_j() <= (I.getWidth()-1.)) {
468 vip.push_back(ip_bottom);
469 }
470 if (vip.size() == 2) {
471 vp_display_display_line(I, vip[0], vip[1], color, thickness);
472 return;
473 }
474 }
475 }
476 }
477
478 /*!
479 Display the lines formed by the list of image points.
480 \param I : The image associated to the display.
481 \param ips : Vector of image points.
482 \param closeTheShape : If true, draw a line from the first and last image
483 points.
484 \param color : Line color.
485 \param thickness : Line thickness.
486 */
displayLine(const vpImage<vpRGBa> & I,const std::vector<vpImagePoint> & ips,bool closeTheShape,const vpColor & color,unsigned int thickness)487 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &ips, bool closeTheShape,
488 const vpColor &color, unsigned int thickness)
489 {
490 if (ips.size() <= 1)
491 return;
492
493 for (size_t i = 0; i < ips.size() - 1; i++)
494 vp_display_display_line(I, ips[i], ips[i + 1], color, thickness);
495
496 if (closeTheShape)
497 vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
498 }
499
500 /*!
501 Display the lines formed by the list of image points.
502 \param I : The image associated to the display.
503 \param ips : List of image points.
504 \param closeTheShape : If true, draw a line from the first and last image
505 points.
506 \param color : Line color.
507 \param thickness : Line thickness.
508 */
displayLine(const vpImage<vpRGBa> & I,const std::list<vpImagePoint> & ips,bool closeTheShape,const vpColor & color,unsigned int thickness)509 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
510 const vpColor &color, unsigned int thickness)
511 {
512 if (ips.size() <= 1)
513 return;
514
515 std::list<vpImagePoint>::const_iterator it = ips.begin();
516
517 vpImagePoint ip_prev = *(it++);
518 for (; it != ips.end(); ++it) {
519 if (vpImagePoint::distance(ip_prev, *it) > 1) {
520 vp_display_display_line(I, ip_prev, *it, color, thickness);
521 ip_prev = *it;
522 }
523 }
524
525 if (closeTheShape) {
526 vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
527 }
528 }
529
530 /*!
531 Display a point at the image point \e ip location.
532 \param I : The image associated to the display.
533 \param ip : Point location.
534 \param color : Point color.
535 \param thickness : Thickness of the point
536 */
displayPoint(const vpImage<vpRGBa> & I,const vpImagePoint & ip,const vpColor & color,unsigned int thickness)537 void vpDisplay::displayPoint(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const vpColor &color,
538 unsigned int thickness)
539 {
540 vp_display_display_point(I, ip, color, thickness);
541 }
542
543 /*!
544 Display a point at the image point (i,j) location.
545 \param I : The image associated to the display.
546 \param i,j : Point location.
547 \param color : Point color.
548 \param thickness : Thickness of the point
549 */
displayPoint(const vpImage<vpRGBa> & I,int i,int j,const vpColor & color,unsigned int thickness)550 void vpDisplay::displayPoint(const vpImage<vpRGBa> &I, int i, int j, const vpColor &color, unsigned int thickness)
551 {
552 vp_display_display_point(I, i, j, color, thickness);
553 }
554
555 /*!
556 Display a polygon defined by a vector of image points.
557 \param I : The image associated to the display.
558 \param vip : Vector of image point that define the vertexes of the polygon.
559 \param color : Line color.
560 \param thickness : Line thickness.
561 \param closed : When true display a closed polygon with a segment between first and last image point.
562 */
displayPolygon(const vpImage<vpRGBa> & I,const std::vector<vpImagePoint> & vip,const vpColor & color,unsigned int thickness,bool closed)563 void vpDisplay::displayPolygon(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &vip, const vpColor &color,
564 unsigned int thickness, bool closed)
565 {
566 vp_display_display_polygon(I, vip, color, thickness, closed);
567 }
568
569 /*!
570 Display a rectangle with \e topLeft as the top-left corner and \e
571 width and \e height the rectangle size.
572
573 \param I : The image associated to the display.
574 \param topLeft : Top-left corner of the rectangle.
575 \param width,height : Rectangle size.
576 \param color : Rectangle color.
577 \param fill : When set to true fill the rectangle. When vpDisplayOpenCV is used,
578 and color alpha channel is set, filling feature can handle transparency. See vpColor
579 header class documentation.
580
581 \param thickness : Thickness of the four lines used to display the
582 rectangle. This parameter is only useful when \e fill is set to
583 false.
584 */
displayRectangle(const vpImage<vpRGBa> & I,const vpImagePoint & topLeft,unsigned int width,unsigned int height,const vpColor & color,bool fill,unsigned int thickness)585 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &topLeft, unsigned int width,
586 unsigned int height, const vpColor &color, bool fill, unsigned int thickness)
587 {
588 vp_display_display_rectangle(I, topLeft, width, height, color, fill, thickness);
589 }
590
591 /*!
592 Display a rectangle with (i,j) as the top-left corner and \e
593 width and \e height the rectangle size.
594
595 \param I : The image associated to the display.
596 \param i,j : Top-left corner of the rectangle.
597 \param width,height : Rectangle size.
598 \param color : Rectangle color.
599 \param fill : When set to true fill the rectangle.
600
601 \param thickness : Thickness of the four lines used to display the
602 rectangle. This parameter is only useful when \e fill is set to
603 false.
604 */
displayRectangle(const vpImage<vpRGBa> & I,int i,int j,unsigned int width,unsigned int height,const vpColor & color,bool fill,unsigned int thickness)605 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, int i, int j, unsigned int width, unsigned int height,
606 const vpColor &color, bool fill, unsigned int thickness)
607 {
608 vp_display_display_rectangle(I, i, j, width, height, color, fill, thickness);
609 }
610
611 /*!
612 Display a rectangle with \e topLeft as the top-left corner and \e
613 width and \e height the rectangle size.
614
615 \param I : The image associated to the display.
616 \param rectangle : Rectangle characteristics.
617 \param color : Rectangle color.
618 \param fill : When set to true fill the rectangle. When vpDisplayOpenCV is used,
619 and color alpha channel is set, filling feature can handle transparency. See vpColor
620 header class documentation.
621
622 \param thickness : Thickness of the four lines used to display the
623 rectangle. This parameter is only useful when \e fill is set to
624 false.
625 */
displayRectangle(const vpImage<vpRGBa> & I,const vpRect & rectangle,const vpColor & color,bool fill,unsigned int thickness)626 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpRect &rectangle, const vpColor &color, bool fill,
627 unsigned int thickness)
628 {
629 vp_display_display_rectangle(I, rectangle, color, fill, thickness);
630 }
631
632 /*!
633 Display a rectangle defined by its center, its orientation (angle)
634 and its size.
635
636 \param I : Image associated to the display.
637 \param center : Rectangle center point.
638 \param angle : Angle in radians width an horizontal axis oriented from left
639 to right.
640 \param width,height : Rectangle size.
641 \param color : Rectangle color.
642 \param thickness : Thickness of the four lines used to display the
643 rectangle.
644 */
displayRectangle(const vpImage<vpRGBa> & I,const vpImagePoint & center,float angle,unsigned int width,unsigned int height,const vpColor & color,unsigned int thickness)645 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint ¢er, float angle, unsigned int width,
646 unsigned int height, const vpColor &color, unsigned int thickness)
647 {
648 vp_display_display_rectangle(I, center, angle, width, height, color, thickness);
649 }
650
651 /*!
652 Display a rectangle with \e topLeft as the top-left corner and \e
653 width and \e height the rectangle size.
654
655 \param I : The image associated to the display.
656 \param topLeft : Top-left corner of the rectangle.
657 \param bottomRight : Bottom-right corner of the rectangle.
658 \param color : Rectangle color.
659 \param fill : When set to true fill the rectangle. When vpDisplayOpenCV is used,
660 and color alpha channel is set, filling feature can handle transparency. See vpColor
661 header class documentation.
662
663 \param thickness : Thickness of the four lines used to display the
664 rectangle. This parameter is only useful when \e fill is set to
665 false.
666 */
displayRectangle(const vpImage<vpRGBa> & I,const vpImagePoint & topLeft,const vpImagePoint & bottomRight,const vpColor & color,bool fill,unsigned int thickness)667 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &topLeft, const vpImagePoint &bottomRight,
668 const vpColor &color, bool fill, unsigned int thickness)
669 {
670 vp_display_display_rectangle(I, topLeft, bottomRight, color, fill, thickness);
671 }
672
673 /*!
674 Display a rectangle defined by its center, its orientation (angle)
675 and its size.
676
677 \param I : Image associated to the display.
678 \param i,j : Rectangle center point.
679 \param angle : Angle in radians width an horizontal axis oriented from left
680 to right.
681 \param width,height : Rectangle size.
682 \param color : Rectangle color.
683 \param thickness : Thickness of the four lines used to display the
684 rectangle.
685 */
displayRectangle(const vpImage<vpRGBa> & I,unsigned int i,unsigned int j,float angle,unsigned int width,unsigned int height,const vpColor & color,unsigned int thickness)686 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, unsigned int i, unsigned int j, float angle,
687 unsigned int width, unsigned int height, const vpColor &color, unsigned int thickness)
688 {
689 vp_display_display_rectangle(I, i, j, angle, width, height, color, thickness);
690 }
691
692 /*!
693 Display a string at the image point \e ip location.
694
695 To select the font used to display the string, use setFont().
696
697 \param I : Image associated to the display.
698 \param ip : Upper left image point location of the string in the display.
699 \param s : String to display in overlay.
700 \param color : String color.
701
702 \sa setFont()
703 */
displayText(const vpImage<vpRGBa> & I,const vpImagePoint & ip,const std::string & s,const vpColor & color)704 void vpDisplay::displayText(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const std::string &s,
705 const vpColor &color)
706 {
707 vp_display_display_text(I, ip, s, color);
708 }
709
710 /*!
711 Display a string at the image point (i,j) location.
712
713 To select the font used to display the string, use setFont().
714
715 \param I : Image associated to the display.
716 \param i,j : Upper left image point location of the string in the display.
717 \param s : String to display in overlay.
718 \param color : String color.
719
720 \sa setFont()
721 */
displayText(const vpImage<vpRGBa> & I,int i,int j,const std::string & s,const vpColor & color)722 void vpDisplay::displayText(const vpImage<vpRGBa> &I, int i, int j, const std::string &s, const vpColor &color)
723 {
724 vp_display_display_text(I, i, j, s, color);
725 }
726
727 /*!
728 Flushes the output buffer associated to image \e I display.
729 It's necessary to use this function to see the results of any drawing.
730
731 \warning This function is particular and must be called
732 to show the overlay. Because it's time spending, use it parcimoniously.
733
734 \code
735 #include <visp3/core/vpColor.h>
736 #include <visp3/core/vpDisplay.h>
737 #include <visp3/core/vpImage.h>
738 #include <visp3/core/vpImagePoint.h>
739 #include <visp3/gui/vpDisplayGDI.h>
740
741 int main() {
742 vpImage<vpRGBa> I(240, 380);
743 vpDisplayGDI d;
744 d.init(I);
745 vpDisplay::display(I); // display the image
746 vpImagePoint center;
747 unsigned int radius = 100;
748 vpDisplay::displayCircle(I, center, radius, vpColor::red);
749
750 vpDisplay::flush(I); // Mendatory to display the requested features.
751 }
752 \endcode
753
754 \sa flushROI()
755 */
flush(const vpImage<vpRGBa> & I)756 void vpDisplay::flush(const vpImage<vpRGBa> &I) { vp_display_flush(I); }
757
758 /*!
759 Flushes the output buffer associated to image \e I display.
760 It's necessary to use this function to see the results of any drawing.
761
762 \warning This function is particular and must be called
763 to show the overlay. Because it's time spending, use it parcimoniously.
764
765 \sa flush()
766 */
flushROI(const vpImage<vpRGBa> & I,const vpRect & roi)767 void vpDisplay::flushROI(const vpImage<vpRGBa> &I, const vpRect &roi) { vp_display_flush_roi(I, roi); }
768
769 /*!
770 Display image \e I.
771
772 \warning Display has to be initialized.
773
774 \warning Suppress the overlay drawing.
775
776 \param I : Image to display.
777
778 \sa init(), close()
779 */
display(const vpImage<vpRGBa> & I)780 void vpDisplay::display(const vpImage<vpRGBa> &I) { vp_display_display(I); }
781
782 /*!
783 Update the display with the content of the image that is in the region of
784 interest. \param I : Image. \param roi : Region of interest.
785 */
displayROI(const vpImage<vpRGBa> & I,const vpRect & roi)786 void vpDisplay::displayROI(const vpImage<vpRGBa> &I, const vpRect &roi) { vp_display_display_roi(I, roi); }
787
788 /*!
789 Wait for a click from one of the mouse button.
790
791 \param I [in] : The displayed image.
792
793 \param blocking [in] : Blocking behavior.
794 - When set to true, this method waits until a mouse button is
795 pressed and then returns always true.
796 - When set to false, returns true only if a mouse button is
797 pressed, otherwise returns false.
798
799 \return
800 - true if a button was clicked. This is always the case if blocking is set
801 to \e true.
802 - false if no button was clicked. This can occur if blocking is set
803 to \e false.
804 */
getClick(const vpImage<vpRGBa> & I,bool blocking)805 bool vpDisplay::getClick(const vpImage<vpRGBa> &I, bool blocking) { return vp_display_get_click(I, blocking); }
806
807 /*!
808 Wait for a click from one of the mouse button and get the position
809 of the clicked image point.
810
811 \param I [in] : The displayed image.
812
813 \param ip [out] : The coordinates of the clicked image point.
814
815 \param blocking [in] : Blocking behavior.
816 - When set to true, this method waits until a mouse button is
817 pressed and then returns always true.
818 - When set to false, returns true only if a mouse button is
819 pressed, otherwise returns false.
820
821 \return true if a mouse button is pressed, false otherwise. If a
822 button is pressed, the location of the mouse pointer is updated in
823 \e ip.
824 */
getClick(const vpImage<vpRGBa> & I,vpImagePoint & ip,bool blocking)825 bool vpDisplay::getClick(const vpImage<vpRGBa> &I, vpImagePoint &ip, bool blocking)
826 {
827 return vp_display_get_click(I, ip, blocking);
828 }
829
830 /*!
831 Wait for a mouse button click and get the position of the clicked
832 image point. The button used to click is also set.
833
834 \param I [in] : The displayed image.
835
836 \param ip [out] : The coordinates of the clicked image point.
837
838 \param button [out] : The button used to click.
839
840 \param blocking [in] :
841 - When set to true, this method waits until a mouse button is
842 pressed and then returns always true.
843 - When set to false, returns true only if a mouse button is
844 pressed, otherwise returns false.
845
846 \return true if a mouse button is pressed, false otherwise. If a
847 button is pressed, the location of the mouse pointer is updated in
848 \e ip.
849 */
getClick(const vpImage<vpRGBa> & I,vpImagePoint & ip,vpMouseButton::vpMouseButtonType & button,bool blocking)850 bool vpDisplay::getClick(const vpImage<vpRGBa> &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button,
851 bool blocking)
852 {
853 return vp_display_get_click(I, ip, button, blocking);
854 }
855
856 /*!
857 Wait for a mouse button click and get the position of the clicked
858 image point. The button used to click is also set.
859
860 \param I [in] : The displayed image.
861
862 \param button [out] : The button used to click.
863
864 \param blocking [in] :
865 - When set to true, this method waits until a mouse button is
866 pressed and then returns always true.
867 - When set to false, returns true only if a mouse button is
868 pressed, otherwise returns false.
869
870 \return true if a mouse button is pressed, false otherwise.
871 */
getClick(const vpImage<vpRGBa> & I,vpMouseButton::vpMouseButtonType & button,bool blocking)872 bool vpDisplay::getClick(const vpImage<vpRGBa> &I, vpMouseButton::vpMouseButtonType &button, bool blocking)
873 {
874 vpImagePoint ip;
875 return vpDisplay::getClick(I, ip, button, blocking);
876 }
877
878 /*!
879 Wait for a mouse button click release and get the position of the clicked
880 image point. The button used to click is also set.
881
882 \param I [in] : The displayed image.
883
884 \param ip [out] : The coordinates of the clicked image point.
885
886 \param button [out] : The clicked button.
887
888 \param blocking [in] :
889 - When set to true, this method waits until a mouse button is
890 released and then returns always true.
891 - When set to false, returns true only if a mouse button is
892 released, otherwise returns false.
893
894 \return true if a mouse button is released, false otherwise. If a
895 button is released, the location of the mouse pointer is updated in
896 \e ip.
897 */
getClickUp(const vpImage<vpRGBa> & I,vpImagePoint & ip,vpMouseButton::vpMouseButtonType & button,bool blocking)898 bool vpDisplay::getClickUp(const vpImage<vpRGBa> &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button,
899 bool blocking)
900 {
901 return vp_display_get_click_up(I, ip, button, blocking);
902 }
903
904 /*!
905 Wait for a mouse button click release and get the position of the clicked
906 image point. The button used to click is also set.
907
908 \param I [in] : The displayed image.
909
910 \param button [out] : The clicked button.
911
912 \param blocking [in] :
913 - When set to true, this method waits until a mouse button is
914 released and then returns always true.
915 - When set to false, returns true only if a mouse button is
916 released, otherwise returns false.
917
918 \return true if a mouse button is released, false otherwise.
919 */
getClickUp(const vpImage<vpRGBa> & I,vpMouseButton::vpMouseButtonType & button,bool blocking)920 bool vpDisplay::getClickUp(const vpImage<vpRGBa> &I, vpMouseButton::vpMouseButtonType &button, bool blocking)
921 {
922 vpImagePoint ip;
923 return vpDisplay::getClickUp(I, ip, button, blocking);
924 }
925
926 /*!
927 Get a keyboard event.
928
929 \param I [in] : The displayed image.
930
931 \param blocking [in] : Blocking behavior.
932 - When set to true, this method waits until a key is
933 pressed and then returns always true.
934 - When set to false, returns true only if a key is
935 pressed, otherwise returns false.
936
937 \return
938 - true if a key was pressed. This is always the case if blocking is set
939 to \e true.
940 - false if no key was pressed. This can occur if blocking is set
941 to \e false.
942
943 Below you will find an example showing how to use this method.
944 \code
945 #include <visp3/core/vpConfig.h>
946 #include <visp3/gui/vpDisplayD3D.h>
947 #include <visp3/gui/vpDisplayGDI.h>
948 #include <visp3/gui/vpDisplayGTK.h>
949 #include <visp3/gui/vpDisplayOpenCV.h>
950 #include <visp3/gui/vpDisplayX.h>
951
952 int main()
953 {
954 vpImage<vpRGBa> I(240, 320); // Create a black image
955
956 vpDisplay *d;
957
958 #if defined(VISP_HAVE_X11)
959 d = new vpDisplayX;
960 #elif defined(VISP_HAVE_GTK)
961 d = new vpDisplayGTK;
962 #elif defined(VISP_HAVE_GDI)
963 d = new vpDisplayGDI;
964 #elif defined(VISP_HAVE_D3D9)
965 d = new vpDisplayD3D;
966 #elif defined(VISP_HAVE_OPENCV)
967 d = new vpDisplayOpenCV;
968 #else
969 std::cout << "Sorry, no video device is available" << std::endl;
970 return -1;
971 #endif
972
973 // Initialize the display with the image I. Display and image are
974 // now link together.
975 #ifdef VISP_HAVE_DISPLAY
976 d->init(I);
977 #endif
978
979 // Set the display background with image I content
980 vpDisplay::display(I);
981
982 // Flush the foreground and background display
983 vpDisplay::flush(I);
984
985 // Wait for keyboard event
986 std::cout << "Waiting a keyboard event..." << std::endl;
987 vpDisplay::getKeyboardEvent(I, true);
988 std::cout << "A keyboard event was detected" << std::endl;
989
990 // Non blocking keyboard event loop
991 int cpt_event = 0;
992 std::cout << "Enter a non blocking keyboard event detection loop..." << std::endl;
993 do {
994 bool event = vpDisplay::getKeyboardEvent(I, false);
995 if (event) {
996 std::cout << "A keyboard event was detected" << std::endl; cpt_event ++;
997 }
998
999 vpTime::wait(5); // wait 5 ms
1000 } while(cpt_event < 5);
1001
1002 #ifdef VISP_HAVE_DISPLAY
1003 delete d;
1004 #endif
1005 }
1006 \endcode
1007 */
getKeyboardEvent(const vpImage<vpRGBa> & I,bool blocking)1008 bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, bool blocking)
1009 {
1010 return vp_display_get_keyboard_event(I, blocking);
1011 }
1012
1013 /*!
1014 Get a keyboard event.
1015
1016 \param I [in] : The displayed image.
1017
1018 \param blocking [in] : Blocking behavior.
1019 - When set to true, this method waits until a key is
1020 pressed and then returns always true.
1021 - When set to false, returns true only if a key is
1022 pressed, otherwise returns false.
1023
1024 \param key [out]: If possible, an ISO Latin-1 character
1025 corresponding to the keyboard key.
1026
1027 \return
1028 - true if a key was pressed. This is always the case if blocking is set
1029 to \e true.
1030 - false if no key was pressed. This can occur if blocking is set
1031 to \e false.
1032
1033 Below you will find an example showing how to use this method.
1034 \code
1035 #include <visp3/gui/vpDisplayD3D.h>
1036 #include <visp3/gui/vpDisplayGDI.h>
1037 #include <visp3/gui/vpDisplayGTK.h>
1038 #include <visp3/gui/vpDisplayOpenCV.h>
1039 #include <visp3/gui/vpDisplayX.h>
1040
1041 int main()
1042 {
1043 vpImage<vpRGBa> I(240, 320); // Create a black image
1044
1045 vpDisplay *d;
1046
1047 #if defined(VISP_HAVE_X11)
1048 d = new vpDisplayX;
1049 #elif defined(VISP_HAVE_GTK)
1050 d = new vpDisplayGTK;
1051 #elif defined(VISP_HAVE_GDI)
1052 d = new vpDisplayGDI;
1053 #elif defined(VISP_HAVE_D3D9)
1054 d = new vpDisplayD3D;
1055 #elif defined(VISP_HAVE_OPENCV)
1056 d = new vpDisplayOpenCV;
1057 #else
1058 std::cout << "Sorry, no video device is available" << std::endl;
1059 return -1;
1060 #endif
1061
1062 // Initialize the display with the image I. Display and image are
1063 // now link together.
1064 #ifdef VISP_HAVE_DISPLAY
1065 d->init(I);
1066 #endif
1067
1068 // Set the display background with image I content
1069 vpDisplay::display(I);
1070
1071 // Flush the foreground and background display
1072 vpDisplay::flush(I);
1073
1074 // Wait for keyboard event
1075 std::cout << "Waiting a keyboard event..." << std::endl;
1076 vpDisplay::getKeyboardEvent(I, true);
1077 std::cout << "A keyboard event was detected" << std::endl;
1078
1079 // Non blocking keyboard event loop
1080 int cpt_event = 0;
1081 std::string key;
1082 std::cout << "Enter a non blocking keyboard event detection loop..." << std::endl;
1083 do {
1084 bool event = vpDisplay::getKeyboardEvent(I, key, false);
1085 if (event) {
1086 std::cout << "Key detected: " << key << std::endl;
1087 cpt_event ++;
1088 }
1089
1090 vpTime::wait(5); // wait 5 ms
1091 } while(cpt_event < 5);
1092
1093 #ifdef VISP_HAVE_DISPLAY
1094 delete d;
1095 #endif
1096 }
1097 \endcode
1098 */
getKeyboardEvent(const vpImage<vpRGBa> & I,std::string & key,bool blocking)1099 bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, std::string &key, bool blocking)
1100 {
1101 return vp_display_get_keyboard_event(I, key, blocking);
1102 }
1103
1104 /*!
1105 Get a keyboard event.
1106
1107 \param I [in] : The displayed image.
1108
1109 \param blocking [in] : Blocking behavior.
1110 - When set to true, this method waits until a key is
1111 pressed and then returns always true.
1112 - When set to false, returns true only if a key is
1113 pressed, otherwise returns false.
1114
1115 \param key [out]: If possible, an ISO Latin-1 character
1116 corresponding to the keyboard key.
1117
1118 \return
1119 - true if a key was pressed. This is always the case if blocking is set
1120 to \e true.
1121 - false if no key was pressed. This can occur if blocking is set
1122 to \e false.
1123
1124 Below you will find an example showing how to use this method.
1125 \code
1126 #include <visp3/gui/vpDisplayD3D.h>
1127 #include <visp3/gui/vpDisplayGDI.h>
1128 #include <visp3/gui/vpDisplayGTK.h>
1129 #include <visp3/gui/vpDisplayOpenCV.h>
1130 #include <visp3/gui/vpDisplayX.h>
1131
1132 int main()
1133 {
1134 vpImage<vpRGBa> I(240, 320); // Create a black image
1135
1136 vpDisplay *d;
1137
1138 #if defined(VISP_HAVE_X11)
1139 d = new vpDisplayX;
1140 #elif defined(VISP_HAVE_GTK)
1141 d = new vpDisplayGTK;
1142 #elif defined(VISP_HAVE_GDI)
1143 d = new vpDisplayGDI;
1144 #elif defined(VISP_HAVE_D3D9)
1145 d = new vpDisplayD3D;
1146 #elif defined(VISP_HAVE_OPENCV)
1147 d = new vpDisplayOpenCV;
1148 #else
1149 std::cout << "Sorry, no video device is available" << std::endl;
1150 return -1;
1151 #endif
1152
1153 // Initialize the display with the image I. Display and image are
1154 // now link together.
1155 #ifdef VISP_HAVE_DISPLAY
1156 d->init(I);
1157 #endif
1158
1159 // Set the display background with image I content
1160 vpDisplay::display(I);
1161
1162 // Flush the foreground and background display
1163 vpDisplay::flush(I);
1164
1165 // Wait for keyboard event
1166 std::cout << "Waiting a keyboard event..." << std::endl;
1167 vpDisplay::getKeyboardEvent(I, true);
1168 std::cout << "A keyboard event was detected" << std::endl;
1169
1170 // Non blocking keyboard event loop
1171 int cpt_event = 0;
1172 char key[10];
1173 std::cout << "Enter a non blocking keyboard event detection loop..." << std::endl;
1174 do {
1175 bool event = vpDisplay::getKeyboardEvent(I, &key[Ø], false);
1176 if (event) {
1177 std::cout << "Key detected: " << key << std::endl;
1178 cpt_event ++;
1179 }
1180
1181 vpTime::wait(5); // wait 5 ms
1182 } while(cpt_event < 5);
1183
1184 #ifdef VISP_HAVE_DISPLAY
1185 delete d;
1186 #endif
1187 }
1188 \endcode
1189 */
getKeyboardEvent(const vpImage<vpRGBa> & I,char * key,bool blocking)1190 bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, char *key, bool blocking)
1191 {
1192 return vp_display_get_keyboard_event(I, key, blocking);
1193 }
1194
1195 /*!
1196 Get the coordinates of the mouse pointer.
1197
1198 \param I [in] : The displayed image.
1199
1200 \param ip [out] : The coordinates of the mouse pointer.
1201
1202 \return true if a pointer motion event was received, false otherwise.
1203 */
getPointerMotionEvent(const vpImage<vpRGBa> & I,vpImagePoint & ip)1204 bool vpDisplay::getPointerMotionEvent(const vpImage<vpRGBa> &I, vpImagePoint &ip)
1205 {
1206 return vp_display_get_pointer_motion_event(I, ip);
1207 }
1208
1209 /*!
1210 Get the coordinates of the mouse pointer.
1211
1212 \param I [in] : The displayed image.
1213
1214 \param ip [out] : The coordinates of the mouse pointer.
1215
1216 \return true.
1217 */
getPointerPosition(const vpImage<vpRGBa> & I,vpImagePoint & ip)1218 bool vpDisplay::getPointerPosition(const vpImage<vpRGBa> &I, vpImagePoint &ip)
1219 {
1220 return vp_display_get_pointer_position(I, ip);
1221 }
1222
1223 /*!
1224 Set the window background.
1225
1226 \param I : Image associated to the display window.
1227 \param color: Background color.
1228
1229 \exception vpDisplayException::notInitializedError : If the video
1230 device is not initialized.
1231 */
setBackground(const vpImage<vpRGBa> & I,const vpColor & color)1232 void vpDisplay::setBackground(const vpImage<vpRGBa> &I, const vpColor &color) { vp_display_set_background(I, color); }
1233
1234 /*!
1235 Set the font of a text printed in the display overlay. To print a
1236 text you may use displayCharString().
1237
1238 \param I : Image associated to the display window.
1239 \param fontname : The expected font name.
1240
1241 \note Under UNIX, the available fonts are given by
1242 the "xlsfonts" binary. To choose a font you can also use the
1243 "xfontsel" binary.
1244
1245 \sa displayText()
1246 */
setFont(const vpImage<vpRGBa> & I,const std::string & fontname)1247 void vpDisplay::setFont(const vpImage<vpRGBa> &I, const std::string &fontname) { vp_display_set_font(I, fontname); }
1248
1249 /*!
1250 Set the windows title.
1251 \note This functionality is not implemented when vpDisplayOpenCV is used.
1252
1253 \param I : Image associated to the display window.
1254 \param windowtitle : Window title.
1255 */
setTitle(const vpImage<vpRGBa> & I,const std::string & windowtitle)1256 void vpDisplay::setTitle(const vpImage<vpRGBa> &I, const std::string &windowtitle)
1257 {
1258 vp_display_set_title(I, windowtitle);
1259 }
1260
1261 /*!
1262 Set the window position in the screen.
1263
1264 \param I : Image associated to the display window.
1265 \param winx, winy : Position of the upper-left window's border in the
1266 screen.
1267
1268 \exception vpDisplayException::notInitializedError : If the video
1269 device is not initialized.
1270 */
setWindowPosition(const vpImage<vpRGBa> & I,int winx,int winy)1271 void vpDisplay::setWindowPosition(const vpImage<vpRGBa> &I, int winx, int winy)
1272 {
1273 vp_display_set_window_position(I, winx, winy);
1274 }
1275
1276 /*!
1277 Return the value of the down scale factor applied to the image in order to
1278 reduce the size of the window used to display the image.
1279
1280 \param I : Image associated to the display window.
1281
1282 \exception vpDisplayException::notInitializedError : If the video
1283 device is not initialized.
1284 */
getDownScalingFactor(const vpImage<vpRGBa> & I)1285 unsigned int vpDisplay::getDownScalingFactor(const vpImage<vpRGBa> &I) { return vp_display_get_down_scaling_factor(I); }
1286