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 #include <visp3/core/vpMeterPixelConversion.h>
39 #include <visp3/core/vpPoint.h>
40
vp_display_close(vpImage<Type> & I)41 template <class Type> void vp_display_close(vpImage<Type> &I)
42 {
43 if (I.display != NULL) {
44 (I.display)->closeDisplay();
45 I.display = NULL;
46 }
47 }
48
vp_display_display(const vpImage<Type> & I)49 template <class Type> void vp_display_display(const vpImage<Type> &I)
50 {
51 if (I.display != NULL) {
52 (I.display)->displayImage(I);
53 }
54 }
55
56 template <class Type>
vp_display_display_arrow(const vpImage<Type> & I,const vpImagePoint & ip1,const vpImagePoint & ip2,const vpColor & color,unsigned int w,unsigned int h,unsigned int thickness)57 void vp_display_display_arrow(const vpImage<Type> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
58 const vpColor &color, unsigned int w, unsigned int h, unsigned int thickness)
59 {
60 if (I.display != NULL) {
61 (I.display)->displayArrow(ip1, ip2, color, w, h, thickness);
62 }
63 }
64
65 template <class Type>
vp_display_display_arrow(const vpImage<Type> & I,int i1,int j1,int i2,int j2,const vpColor & color,unsigned int w,unsigned int h,unsigned int thickness)66 void vp_display_display_arrow(const vpImage<Type> &I, int i1, int j1, int i2, int j2, const vpColor &color,
67 unsigned int w, unsigned int h, unsigned int thickness)
68 {
69 if (I.display != NULL) {
70 vpImagePoint ip1, ip2;
71 ip1.set_i(i1);
72 ip1.set_j(j1);
73 ip2.set_i(i2);
74 ip2.set_j(j2);
75 (I.display)->displayArrow(ip1, ip2, color, w, h, thickness);
76 }
77 }
78
79 template <class Type>
vp_display_display_camera(const vpImage<Type> & I,const vpHomogeneousMatrix & cMo,const vpCameraParameters & cam,double size,const vpColor & color,unsigned int thickness)80 void vp_display_display_camera(const vpImage<Type> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
81 double size, const vpColor &color, unsigned int thickness)
82 {
83 // used by display
84 double halfSize = size / 2.0;
85 vpPoint pt[5];
86 pt[0].setWorldCoordinates(-halfSize, -halfSize, 0.0);
87 pt[1].setWorldCoordinates(halfSize, -halfSize, 0.0);
88 pt[2].setWorldCoordinates(halfSize, halfSize, 0.0);
89 pt[3].setWorldCoordinates(-halfSize, halfSize, 0.0);
90 pt[4].setWorldCoordinates(0.0, 0.0, -size);
91
92 for (int i = 0; i < 5; i++)
93 pt[i].track(cMo);
94
95 vpImagePoint ip, ip_1, ip0;
96 vpMeterPixelConversion::convertPoint(cam, pt[4].p[0], pt[4].p[1], ip0);
97
98 for (int i = 0; i < 4; i++) {
99 vpMeterPixelConversion::convertPoint(cam, pt[i].p[0], pt[i].p[1], ip_1);
100 vpMeterPixelConversion::convertPoint(cam, pt[(i + 1) % 4].p[0], pt[(i + 1) % 4].p[1], ip);
101 vpDisplay::displayLine(I, ip_1, ip, color, thickness);
102 vpDisplay::displayLine(I, ip0, ip_1, color, thickness);
103 }
104 }
105
106 template <class Type>
vp_display_display_char_string(const vpImage<Type> & I,const vpImagePoint & ip,const char * string,const vpColor & color)107 void vp_display_display_char_string(const vpImage<Type> &I, const vpImagePoint &ip, const char *string,
108 const vpColor &color)
109 {
110 if (I.display != NULL) {
111 (I.display)->displayCharString(ip, string, color);
112 }
113 }
114
115 template <class Type>
vp_display_display_char_string(const vpImage<Type> & I,int i,int j,const char * string,const vpColor & color)116 void vp_display_display_char_string(const vpImage<Type> &I, int i, int j, const char *string, const vpColor &color)
117 {
118 if (I.display != NULL) {
119 vpImagePoint ip;
120 ip.set_i(i);
121 ip.set_j(j);
122
123 (I.display)->displayCharString(ip, string, color);
124 }
125 }
126
127 template <class Type>
vp_display_display_circle(const vpImage<Type> & I,const vpImagePoint & center,unsigned int radius,const vpColor & color,bool fill,unsigned int thickness)128 void vp_display_display_circle(const vpImage<Type> &I, const vpImagePoint ¢er, unsigned int radius,
129 const vpColor &color, bool fill, unsigned int thickness)
130 {
131 if (I.display != NULL) {
132 (I.display)->displayCircle(center, radius, color, fill, thickness);
133 }
134 }
135
136 template <class Type>
vp_display_display_circle(const vpImage<Type> & I,int i,int j,unsigned int radius,const vpColor & color,bool fill,unsigned int thickness)137 void vp_display_display_circle(const vpImage<Type> &I, int i, int j, unsigned int radius, const vpColor &color,
138 bool fill, unsigned int thickness)
139 {
140 if (I.display != NULL) {
141 vpImagePoint ip;
142 ip.set_i(i);
143 ip.set_j(j);
144
145 (I.display)->displayCircle(ip, radius, color, fill, thickness);
146 }
147 }
148
149 template <class Type>
vp_display_display_cross(const vpImage<Type> & I,const vpImagePoint & ip,unsigned int size,const vpColor & color,unsigned int thickness)150 void vp_display_display_cross(const vpImage<Type> &I, const vpImagePoint &ip, unsigned int size, const vpColor &color,
151 unsigned int thickness)
152 {
153 if (I.display != NULL) {
154 (I.display)->displayCross(ip, size, color, thickness);
155 }
156 }
157
158 template <class Type>
vp_display_display_cross(const vpImage<Type> & I,int i,int j,unsigned int size,const vpColor & color,unsigned int thickness)159 void vp_display_display_cross(const vpImage<Type> &I, int i, int j, unsigned int size, const vpColor &color,
160 unsigned int thickness)
161 {
162 if (I.display != NULL) {
163 vpImagePoint ip;
164 ip.set_i(i);
165 ip.set_j(j);
166
167 (I.display)->displayCross(ip, size, color, thickness);
168 }
169 }
170
171 template <class Type>
vp_display_display_dot_line(const vpImage<Type> & I,const vpImagePoint & ip1,const vpImagePoint & ip2,const vpColor & color,unsigned int thickness)172 void vp_display_display_dot_line(const vpImage<Type> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
173 const vpColor &color, unsigned int thickness)
174 {
175 if (I.display != NULL) {
176 (I.display)->displayDotLine(ip1, ip2, color, thickness);
177 }
178 }
179
180 template <class Type>
vp_display_display_dot_line(const vpImage<Type> & I,int i1,int j1,int i2,int j2,const vpColor & color,unsigned int thickness)181 void vp_display_display_dot_line(const vpImage<Type> &I, int i1, int j1, int i2, int j2, const vpColor &color,
182 unsigned int thickness)
183 {
184 if (I.display != NULL) {
185 vpImagePoint ip1, ip2;
186 ip1.set_i(i1);
187 ip1.set_j(j1);
188 ip2.set_i(i2);
189 ip2.set_j(j2);
190 (I.display)->displayDotLine(ip1, ip2, color, thickness);
191 }
192 }
193
194 template <class Type>
vp_display_display_ellipse(const vpImage<Type> & 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)195 void vp_display_display_ellipse(const vpImage<Type> &I, const vpImagePoint ¢er, const double &coef1,
196 const double &coef2, const double &coef3, const double &smallalpha, const double &highalpha,
197 bool use_normalized_centered_moments, const vpColor &color, unsigned int thickness, bool display_center, bool display_arc)
198 {
199 if (I.display != NULL) {
200 double a = 0., b = 0., e = 0.;
201
202 if (use_normalized_centered_moments) {
203 // Chaumette, Image Moments: A General and Useful Set of Features for Visual Servoing, TRO 2004, eq 24
204 // Similar code as in function vpMeEllipse::computeAbeFromNij() in vpMeEllipse.cpp
205 double n20_p = coef1;
206 double n11_p = coef2;
207 double n02_p = coef3;
208 double num = n20_p - n02_p;
209 double d = num * num + 4.0 * n11_p * n11_p; // always >= 0
210
211 if (d <= std::numeric_limits<double>::epsilon()) { // circle
212 e = 0.0; // case n20 = n02 and n11 = 0 : circle, e undefined
213 a = b = 2.0*sqrt(n20_p);
214 }
215 else { // real ellipse
216 e = atan2(2.0*n11_p, num)/2.0; // e in [-Pi/2 ; Pi/2]
217 d = sqrt(d); // d in sqrt always >= 0
218 num = n20_p + n02_p;
219 a = sqrt(2.0*(num + d)); // term in sqrt always > 0
220 b = sqrt(2.0*(num - d)); // term in sqrt always > 0
221 }
222 } else {
223 a = coef1;
224 b = coef2;
225 e = coef3;
226 }
227
228 // For all what follows similar code as in function vpMeEllipse::display() in vpMeEllipse.cpp
229
230 // Approximation of the circumference of an ellipse:
231 // [Ramanujan, S., "Modular Equations and Approximations to ,"
232 // Quart. J. Pure. Appl. Math., vol. 45 (1913-1914), pp. 350-372]
233 double angle = highalpha - smallalpha;
234
235 // Disable arc drawing when the ellipse is complete
236 if (std::fabs(angle - 2* M_PI) <= std::numeric_limits<double>::epsilon()) {
237 display_arc = false;
238 }
239
240 double t = (a - b) / (a + b);
241 t *= t; // t^2
242 double circumference = (angle/2.0) * (a + b) * (1.0 + 3.0 * t / (10.0 + sqrt(4.0 - 3.0 * t)));
243 unsigned int nbpoints = (unsigned int)(floor(circumference / 20));
244 if (nbpoints < 10) {
245 nbpoints = 10;
246 }
247 double incr = angle / nbpoints; // angle increment
248
249 double u0 = center.get_u();
250 double v0 = center.get_v();
251 double cose = cos(e);
252 double sine = sin(e);
253
254 double u = a * cos(smallalpha); // equation of an ellipse
255 double v = b * sin(smallalpha); // equation of an ellipse
256 angle = smallalpha;
257 // (i1,j1) are the coordinates on the origin centered ellipse ;
258 // a rotation by "e" and a translation by (xci,jc) are done
259 // to get the coordinates of the point on the shifted ellipse
260 vpImagePoint iP11;
261 iP11.set_uv(u0 + cose * u - sine * v, v0 + sine * u + cose * v);
262
263 if (display_arc) {
264 // Display the line from the center to the first extremity for an arc
265 (I.display)->displayLine(center, iP11, color, thickness);
266 }
267
268 // display the arc of the ellipse by succesive small segments
269 for (unsigned int i = 0; i < nbpoints; i++) {
270 angle += incr;
271 // Two concentric circles method used
272 u = a * cos(angle);
273 v = b * sin(angle);
274 // to get the coordinates of the point on the shifted ellipse
275 vpImagePoint iP22;
276 iP22.set_uv(u0 + cose * u - sine * v, v0 + sine * u + cose * v);
277
278 (I.display)->displayLine(iP11, iP22, color, thickness);
279
280 iP11 = iP22;
281 }
282 if (display_center) {
283 // display a cross at the center of the ellipse
284 (I.display)->displayCross(center, 20, vpColor::red, thickness);
285 }
286 if (display_arc) {
287 // Display the line from the center to the second extremity for an arc
288 (I.display)->displayLine(center, iP11, color, thickness);
289 }
290 }
291 }
292
293 template <class Type>
vp_display_display_frame(const vpImage<Type> & I,const vpHomogeneousMatrix & cMo,const vpCameraParameters & cam,double size,const vpColor & color,unsigned int thickness,const vpImagePoint & offset)294 void vp_display_display_frame(const vpImage<Type> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
295 double size, const vpColor &color, unsigned int thickness, const vpImagePoint &offset)
296 {
297 // used by display
298 vpPoint o(0.0, 0.0, 0.0);
299 vpPoint x(size, 0.0, 0.0);
300 vpPoint y(0.0, size, 0.0);
301 vpPoint z(0.0, 0.0, size);
302
303 o.track(cMo);
304 x.track(cMo);
305 y.track(cMo);
306 z.track(cMo);
307
308 vpImagePoint ipo, ip1;
309
310 if (color == vpColor::none) {
311 vpMeterPixelConversion::convertPoint(cam, o.p[0], o.p[1], ipo);
312
313 vpMeterPixelConversion::convertPoint(cam, x.p[0], x.p[1], ip1);
314 vpDisplay::displayArrow(I, ipo + offset, ip1 + offset, vpColor::red, 4 * thickness, 2 * thickness, thickness);
315
316 vpMeterPixelConversion::convertPoint(cam, y.p[0], y.p[1], ip1);
317 vpDisplay::displayArrow(I, ipo + offset, ip1 + offset, vpColor::green, 4 * thickness, 2 * thickness, thickness);
318
319 vpMeterPixelConversion::convertPoint(cam, z.p[0], z.p[1], ip1);
320 vpDisplay::displayArrow(I, ipo + offset, ip1 + offset, vpColor::blue, 4 * thickness, 2 * thickness, thickness);
321 } else {
322 vpMeterPixelConversion::convertPoint(cam, o.p[0], o.p[1], ipo);
323
324 vpMeterPixelConversion::convertPoint(cam, x.p[0], x.p[1], ip1);
325 vpDisplay::displayArrow(I, ipo + offset, ip1 + offset, color, 4 * thickness, 2 * thickness, thickness);
326
327 vpMeterPixelConversion::convertPoint(cam, y.p[0], y.p[1], ip1);
328 vpDisplay::displayArrow(I, ipo + offset, ip1 + offset, color, 4 * thickness, 2 * thickness, thickness);
329
330 vpMeterPixelConversion::convertPoint(cam, z.p[0], z.p[1], ip1);
331 vpDisplay::displayArrow(I, ipo + offset, ip1 + offset, color, 4 * thickness, 2 * thickness, thickness);
332 }
333 }
334
335 template <class Type>
vp_display_display_line(const vpImage<Type> & I,const vpImagePoint & ip1,const vpImagePoint & ip2,const vpColor & color,unsigned int thickness)336 void vp_display_display_line(const vpImage<Type> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
337 const vpColor &color, unsigned int thickness)
338 {
339 if (I.display != NULL) {
340 (I.display)->displayLine(ip1, ip2, color, thickness);
341 }
342 }
343
344 template <class Type>
vp_display_display_line(const vpImage<Type> & I,int i1,int j1,int i2,int j2,const vpColor & color,unsigned int thickness)345 void vp_display_display_line(const vpImage<Type> &I, int i1, int j1, int i2, int j2, const vpColor &color,
346 unsigned int thickness)
347 {
348 if (I.display != NULL) {
349 vpImagePoint ip1, ip2;
350 ip1.set_i(i1);
351 ip1.set_j(j1);
352 ip2.set_i(i2);
353 ip2.set_j(j2);
354 (I.display)->displayLine(ip1, ip2, color, thickness);
355 }
356 }
357
358 template <class Type>
vp_display_display_point(const vpImage<Type> & I,const vpImagePoint & ip,const vpColor & color,unsigned int thickness)359 void vp_display_display_point(const vpImage<Type> &I, const vpImagePoint &ip, const vpColor &color,
360 unsigned int thickness)
361 {
362 if (I.display != NULL) {
363 (I.display)->displayPoint(ip, color, thickness);
364 }
365 }
366
367 template <class Type>
vp_display_display_point(const vpImage<Type> & I,int i,int j,const vpColor & color,unsigned int thickness)368 void vp_display_display_point(const vpImage<Type> &I, int i, int j, const vpColor &color, unsigned int thickness)
369 {
370 if (I.display != NULL) {
371 vpImagePoint ip;
372 ip.set_i(i);
373 ip.set_j(j);
374 (I.display)->displayPoint(ip, color, thickness);
375 }
376 }
377
378 template <class Type>
379 void vp_display_display_polygon(const vpImage<Type> &I, const std::vector<vpImagePoint> &vip, const vpColor &color,
380 unsigned int thickness, bool closed=true)
381 {
382 if (I.display != NULL) {
383 if (closed) {
384 for (unsigned int i = 0; i < vip.size(); i++) {
385 (I.display)->displayLine(vip[i], vip[(i + 1) % vip.size()], color, thickness);
386 }
387 }
388 else {
389 for (unsigned int i = 1; i < vip.size(); i++) {
390 (I.display)->displayLine(vip[i-1], vip[i], color, thickness);
391 }
392 }
393 }
394 }
395
396 template <class Type>
vp_display_display_rectangle(const vpImage<Type> & I,const vpImagePoint & topLeft,unsigned int width,unsigned int height,const vpColor & color,bool fill,unsigned int thickness)397 void vp_display_display_rectangle(const vpImage<Type> &I, const vpImagePoint &topLeft, unsigned int width,
398 unsigned int height, const vpColor &color, bool fill, unsigned int thickness)
399 {
400 if (I.display != NULL) {
401 (I.display)->displayRectangle(topLeft, width, height, color, fill, thickness);
402 }
403 }
404
405 template <class Type>
vp_display_display_rectangle(const vpImage<Type> & I,const vpRect & rectangle,const vpColor & color,bool fill,unsigned int thickness)406 void vp_display_display_rectangle(const vpImage<Type> &I, const vpRect &rectangle, const vpColor &color, bool fill,
407 unsigned int thickness)
408 {
409 if (I.display != NULL) {
410 (I.display)->displayRectangle(rectangle, color, fill, thickness);
411 }
412 }
413
414 template <class Type>
vp_display_display_rectangle(const vpImage<Type> & I,const vpImagePoint & center,float angle,unsigned int width,unsigned int height,const vpColor & color,unsigned int thickness)415 void vp_display_display_rectangle(const vpImage<Type> &I, const vpImagePoint ¢er, float angle, unsigned int width,
416 unsigned int height, const vpColor &color, unsigned int thickness)
417 {
418 if (I.display != NULL) {
419 double i = center.get_i();
420 double j = center.get_j();
421
422 // A, B, C, D, corners of the rectangle clockwise
423 vpImagePoint ipa, ipb, ipc, ipd;
424 double cosinus = cos(angle);
425 double sinus = sin(angle);
426 ipa.set_u(j + 0.5 * width * cosinus + 0.5 * height * sinus);
427 ipa.set_v(i + 0.5 * width * sinus - 0.5 * height * cosinus);
428 ipb.set_u(j + 0.5 * width * cosinus - 0.5 * height * sinus);
429 ipb.set_v(i + 0.5 * width * sinus + 0.5 * height * cosinus);
430 ipc.set_u(j - 0.5 * width * cosinus - 0.5 * height * sinus);
431 ipc.set_v(i - 0.5 * width * sinus + 0.5 * height * cosinus);
432 ipd.set_u(j - 0.5 * width * cosinus + 0.5 * height * sinus);
433 ipd.set_v(i - 0.5 * width * sinus - 0.5 * height * cosinus);
434
435 (I.display)->displayLine(I, ipa, ipb, color, thickness);
436 (I.display)->displayLine(I, ipa, ipd, color, thickness);
437 (I.display)->displayLine(I, ipc, ipb, color, thickness);
438 (I.display)->displayLine(I, ipc, ipd, color, thickness);
439 }
440 }
441
442 template <class Type>
vp_display_display_rectangle(const vpImage<Type> & I,const vpImagePoint & topLeft,const vpImagePoint & bottomRight,const vpColor & color,bool fill,unsigned int thickness)443 void vp_display_display_rectangle(const vpImage<Type> &I, const vpImagePoint &topLeft, const vpImagePoint &bottomRight,
444 const vpColor &color, bool fill, unsigned int thickness)
445 {
446 if (I.display != NULL) {
447 (I.display)->displayRectangle(topLeft, bottomRight, color, fill, thickness);
448 }
449 }
450
451 template <class Type>
vp_display_display_rectangle(const vpImage<Type> & I,int i,int j,unsigned int width,unsigned int height,const vpColor & color,bool fill,unsigned int thickness)452 void vp_display_display_rectangle(const vpImage<Type> &I, int i, int j, unsigned int width, unsigned int height,
453 const vpColor &color, bool fill, unsigned int thickness)
454 {
455 if (I.display != NULL) {
456 vpImagePoint topLeft;
457 topLeft.set_i(i);
458 topLeft.set_j(j);
459
460 (I.display)->displayRectangle(topLeft, width, height, color, fill, thickness);
461 }
462 }
463
464 template <class Type>
vp_display_display_rectangle(const vpImage<Type> & I,unsigned int i,unsigned int j,float angle,unsigned int width,unsigned int height,const vpColor & color,unsigned int thickness)465 void vp_display_display_rectangle(const vpImage<Type> &I, unsigned int i, unsigned int j, float angle,
466 unsigned int width, unsigned int height, const vpColor &color, unsigned int thickness)
467 {
468 if (I.display != NULL) {
469 // A, B, C, D, corners of the rectangle clockwise
470 vpImagePoint ipa, ipb, ipc, ipd;
471 float cosinus = cos(angle);
472 float sinus = sin(angle);
473 ipa.set_u(j + 0.5 * width * cosinus + 0.5 * height * sinus);
474 ipa.set_v(i + 0.5 * width * sinus - 0.5 * height * cosinus);
475 ipb.set_u(j + 0.5 * width * cosinus - 0.5 * height * sinus);
476 ipb.set_v(i + 0.5 * width * sinus + 0.5 * height * cosinus);
477 ipc.set_u(j - 0.5 * width * cosinus - 0.5 * height * sinus);
478 ipc.set_v(i - 0.5 * width * sinus + 0.5 * height * cosinus);
479 ipd.set_u(j - 0.5 * width * cosinus + 0.5 * height * sinus);
480 ipd.set_v(i - 0.5 * width * sinus - 0.5 * height * cosinus);
481
482 (I.display)->displayLine(I, ipa, ipb, color, thickness);
483 (I.display)->displayLine(I, ipa, ipd, color, thickness);
484 (I.display)->displayLine(I, ipc, ipb, color, thickness);
485 (I.display)->displayLine(I, ipc, ipd, color, thickness);
486 }
487 }
488
vp_display_display_roi(const vpImage<Type> & I,const vpRect & roi)489 template <class Type> void vp_display_display_roi(const vpImage<Type> &I, const vpRect &roi)
490 {
491 double top = floor(roi.getTop());
492 double left = floor(roi.getLeft());
493 double roiheight = floor(roi.getHeight());
494 double roiwidth = floor(roi.getWidth());
495 double iheight = (double)(I.getHeight());
496 double iwidth = (double)(I.getWidth());
497
498 if (top < 0 || top > iheight || left < 0 || left > iwidth || top + roiheight > iheight || left + roiwidth > iwidth) {
499 throw(vpException(vpException::dimensionError, "Region of interest outside of the image"));
500 }
501
502 if (I.display != NULL) {
503 (I.display)->displayImageROI(I, vpImagePoint(top, left), (unsigned int)roiwidth, (unsigned int)roiheight);
504 }
505 }
506
vp_display_flush(const vpImage<Type> & I)507 template <class Type> void vp_display_flush(const vpImage<Type> &I)
508 {
509 if (I.display != NULL) {
510 (I.display)->flushDisplay();
511 }
512 }
513
vp_display_flush_roi(const vpImage<Type> & I,const vpRect & roi)514 template <class Type> void vp_display_flush_roi(const vpImage<Type> &I, const vpRect &roi)
515 {
516 if (I.display != NULL) {
517 (I.display)->flushDisplayROI(roi.getTopLeft(), (unsigned int)roi.getWidth(), (unsigned int)roi.getHeight());
518 }
519 }
520
vp_display_get_click(const vpImage<Type> & I,bool blocking)521 template <class Type> bool vp_display_get_click(const vpImage<Type> &I, bool blocking)
522 {
523 if (I.display != NULL) {
524 return (I.display)->getClick(blocking);
525 }
526 return false;
527 }
528
vp_display_get_click(const vpImage<Type> & I,vpImagePoint & ip,bool blocking)529 template <class Type> bool vp_display_get_click(const vpImage<Type> &I, vpImagePoint &ip, bool blocking)
530 {
531 if (I.display != NULL) {
532 return (I.display)->getClick(ip, blocking);
533 }
534 return false;
535 }
536
537 template <class Type>
vp_display_get_click(const vpImage<Type> & I,vpImagePoint & ip,vpMouseButton::vpMouseButtonType & button,bool blocking)538 bool vp_display_get_click(const vpImage<Type> &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button,
539 bool blocking)
540 {
541 if (I.display != NULL) {
542 return (I.display)->getClick(ip, button, blocking);
543 }
544 return false;
545 }
546
547 template <class Type>
vp_display_get_click_up(const vpImage<Type> & I,vpImagePoint & ip,vpMouseButton::vpMouseButtonType & button,bool blocking)548 bool vp_display_get_click_up(const vpImage<Type> &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button,
549 bool blocking)
550 {
551 if (I.display != NULL) {
552 return (I.display)->getClickUp(ip, button, blocking);
553 }
554 return false;
555 }
556
vp_display_get_keyboard_event(const vpImage<Type> & I,bool blocking)557 template <class Type> bool vp_display_get_keyboard_event(const vpImage<Type> &I, bool blocking)
558 {
559 if (I.display != NULL) {
560 return (I.display)->getKeyboardEvent(blocking);
561 }
562 return false;
563 }
564
vp_display_get_keyboard_event(const vpImage<Type> & I,std::string & key,bool blocking)565 template <class Type> bool vp_display_get_keyboard_event(const vpImage<Type> &I, std::string &key, bool blocking)
566 {
567 if (I.display != NULL) {
568 return (I.display)->getKeyboardEvent(key, blocking);
569 }
570 return false;
571 }
572
vp_display_get_keyboard_event(const vpImage<Type> & I,char * key,bool blocking)573 template <class Type> bool vp_display_get_keyboard_event(const vpImage<Type> &I, char *key, bool blocking)
574 {
575 if (I.display != NULL) {
576 std::string str;
577 bool ret = (I.display)->getKeyboardEvent(str, blocking);
578 sprintf(key, "%s", str.c_str());
579 return ret;
580 }
581 return false;
582 }
583
vp_display_get_pointer_motion_event(const vpImage<Type> & I,vpImagePoint & ip)584 template <class Type> bool vp_display_get_pointer_motion_event(const vpImage<Type> &I, vpImagePoint &ip)
585 {
586 if (I.display != NULL) {
587 return (I.display)->getPointerMotionEvent(ip);
588 }
589 return false;
590 }
591
vp_display_get_pointer_position(const vpImage<Type> & I,vpImagePoint & ip)592 template <class Type> bool vp_display_get_pointer_position(const vpImage<Type> &I, vpImagePoint &ip)
593 {
594 if (I.display != NULL) {
595 return (I.display)->getPointerPosition(ip);
596 }
597 return false;
598 }
599
vp_display_set_background(const vpImage<Type> & I,const vpColor & color)600 template <class Type> void vp_display_set_background(const vpImage<Type> &I, const vpColor &color)
601 {
602 if (I.display != NULL) {
603 (I.display)->clearDisplay(color);
604 }
605 }
606
607 template <class Type>
vp_display_display_text(const vpImage<Type> & I,const vpImagePoint & ip,const std::string & s,const vpColor & color)608 void vp_display_display_text(const vpImage<Type> &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
609 {
610 if (I.display != NULL) {
611 (I.display)->displayCharString(ip, s.c_str(), color);
612 }
613 }
614
615 template <class Type>
vp_display_display_text(const vpImage<Type> & I,int i,int j,const std::string & s,const vpColor & color)616 void vp_display_display_text(const vpImage<Type> &I, int i, int j, const std::string &s, const vpColor &color)
617 {
618 if (I.display != NULL) {
619 vpImagePoint ip;
620 ip.set_i(i);
621 ip.set_j(j);
622
623 (I.display)->displayCharString(ip, s.c_str(), color);
624 }
625 }
626
vp_display_set_font(const vpImage<Type> & I,const std::string & fontname)627 template <class Type> void vp_display_set_font(const vpImage<Type> &I, const std::string &fontname)
628 {
629 if (I.display != NULL) {
630 (I.display)->setFont(fontname);
631 }
632 }
633
vp_display_set_title(const vpImage<Type> & I,const std::string & windowtitle)634 template <class Type> void vp_display_set_title(const vpImage<Type> &I, const std::string &windowtitle)
635 {
636 if (I.display != NULL) {
637 (I.display)->setTitle(windowtitle);
638 }
639 }
640
vp_display_set_window_position(const vpImage<Type> & I,int winx,int winy)641 template <class Type> void vp_display_set_window_position(const vpImage<Type> &I, int winx, int winy)
642 {
643 if (I.display != NULL) {
644 (I.display)->setWindowPosition(winx, winy);
645 }
646 }
647
vp_display_get_down_scaling_factor(const vpImage<Type> & I)648 template <class Type> unsigned int vp_display_get_down_scaling_factor(const vpImage<Type> &I)
649 {
650 if (I.display != NULL) {
651 return (I.display)->getDownScalingFactor();
652 } else {
653 throw(vpException(vpException::fatalError, "Cannot get the down scaling factor: Display is not initialized"));
654 }
655 }
656