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