Visual Servoing Platform  version 3.5.1 under development (2023-02-04)
vpDisplay_rgba.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2022 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  *****************************************************************************/
35 
36 #include <visp3/core/vpDisplay.h>
37 
38 #include "vpDisplay_impl.h"
39 
40 //************************************************************************
41 // Modifications done in this file should be reported in all vpDisplay_*.cpp
42 // files that implement other types (unsigned char, vpRGB, vpRGBa)
43 //************************************************************************
44 
48 void vpDisplay::close(vpImage<vpRGBa> &I) { vp_display_close(I); }
49 
58 void vpDisplay::displayArrow(const vpImage<vpRGBa> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
59  const vpColor &color, unsigned int w, unsigned int h, unsigned int thickness)
60 {
61  vp_display_display_arrow(I, ip1, ip2, color, w, h, thickness);
62 }
63 
74 void vpDisplay::displayArrow(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
75  unsigned int w, unsigned int h, unsigned int thickness)
76 {
77  vp_display_display_arrow(I, i1, j1, i2, j2, color, w, h, thickness);
78 }
79 
94  double size, const vpColor &color, unsigned int thickness)
95 {
96  vp_display_display_camera(I, cMo, cam, size, color, thickness);
97 }
98 
112 void vpDisplay::displayCharString(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const char *string,
113  const vpColor &color)
114 {
115  vp_display_display_char_string(I, ip, string, color);
116 }
117 
131 void vpDisplay::displayCharString(const vpImage<vpRGBa> &I, int i, int j, const char *string, const vpColor &color)
132 {
133  vp_display_display_char_string(I, i, j, string, color);
134 }
135 
148 void vpDisplay::displayCircle(const vpImage<vpRGBa> &I, const vpImagePoint &center, unsigned int radius,
149  const vpColor &color, bool fill, unsigned int thickness)
150 {
151  vp_display_display_circle(I, center, radius, color, fill, thickness);
152 }
153 
166 void vpDisplay::displayCircle(const vpImage<vpRGBa> &I, int i, int j, unsigned int radius, const vpColor &color,
167  bool fill, unsigned int thickness)
168 {
169  vp_display_display_circle(I, i, j, radius, color, fill, thickness);
170 }
171 
180 void vpDisplay::displayCross(const vpImage<vpRGBa> &I, const vpImagePoint &ip, unsigned int size, const vpColor &color,
181  unsigned int thickness)
182 {
183  vp_display_display_cross(I, ip, size, color, thickness);
184 }
185 
194 void vpDisplay::displayCross(const vpImage<vpRGBa> &I, int i, int j, unsigned int size, const vpColor &color,
195  unsigned int thickness)
196 {
197  vp_display_display_cross(I, i, j, size, color, thickness);
198 }
199 
208  const vpColor &color, unsigned int thickness)
209 {
210  vp_display_display_dot_line(I, ip1, ip2, color, thickness);
211 }
212 
221 void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
222  unsigned int thickness)
223 {
224  vp_display_display_dot_line(I, i1, j1, i2, j2, color, thickness);
225 }
226 
236 void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &ips, bool closeTheShape,
237  const vpColor &color, unsigned int thickness)
238 {
239  if (ips.size() <= 1)
240  return;
241 
242  for (size_t i = 0; i < ips.size() - 1; i++)
243  vp_display_display_dot_line(I, ips[i], ips[i + 1], color, thickness);
244 
245  if (closeTheShape)
246  vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
247 }
248 
258 void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
259  const vpColor &color, unsigned int thickness)
260 {
261  if (ips.size() <= 1)
262  return;
263 
264  std::list<vpImagePoint>::const_iterator it = ips.begin();
265 
266  vpImagePoint ip_prev = *(it++);
267  for (; it != ips.end(); ++it) {
268  if (vpImagePoint::distance(ip_prev, *it) > 1) {
269  vp_display_display_dot_line(I, ip_prev, *it, color, thickness);
270  ip_prev = *it;
271  }
272  }
273 
274  if (closeTheShape) {
275  vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
276  }
277 }
278 
315 void vpDisplay::displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &coef1,
316  const double &coef2, const double &coef3, bool use_normalized_centered_moments,
317  const vpColor &color, unsigned int thickness, bool display_center, bool display_arc)
318 {
319  vpDisplay::displayEllipse(I, center, coef1, coef2, coef3, 0., 2 * M_PI, use_normalized_centered_moments, color,
320  thickness, display_center, display_arc);
321 }
322 
362 void vpDisplay::displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &coef1,
363  const double &coef2, const double &coef3, const double &smallalpha,
364  const double &highalpha, bool use_normalized_centered_moments, const vpColor &color,
365  unsigned int thickness, bool display_center, bool display_arc)
366 {
367  vp_display_display_ellipse(I, center, coef1, coef2, coef3, smallalpha, highalpha, use_normalized_centered_moments,
368  color, thickness, display_center, display_arc);
369 }
370 
387  double size, const vpColor &color, unsigned int thickness, const vpImagePoint &offset)
388 {
389  vp_display_display_frame(I, cMo, cam, size, color, thickness, offset);
390 }
391 
401 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
402  const vpColor &color, unsigned int thickness, bool segment)
403 {
404  displayLine(I, static_cast<int>(ip1.get_i()), static_cast<int>(ip1.get_j()), static_cast<int>(ip2.get_i()),
405  static_cast<int>(ip2.get_j()), color, thickness, segment);
406 }
407 
418 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
419  unsigned int thickness, bool segment)
420 {
421  if (segment) {
422  vp_display_display_line(I, i1, j1, i2, j2, color, thickness);
423  } else {
424  // line equation in image: i = a * j + b
425  double delta_j = static_cast<double>(j2) - static_cast<double>(j1);
426  double delta_i = static_cast<double>(i2) - static_cast<double>(i1);
427  // Test if horizontal line
428  if (std::fabs(delta_i) <= std::numeric_limits<double>::epsilon()) {
429  vp_display_display_line(I, i1, 0, i1, (I.getWidth() - 1), color, thickness);
430  }
431  // Test if vertical line
432  else if (std::fabs(delta_j) <= std::numeric_limits<double>::epsilon()) {
433  vp_display_display_line(I, 0, j1, (I.getHeight() - 1), j1, color, thickness);
434  } else {
435  double a = delta_i / delta_j;
436  double b = static_cast<double>(i1) - a * static_cast<double>(j1);
437  std::vector<vpImagePoint> vip; // Image points that intersect image borders
438  // Test intersection with vertical line j=0
439  vpImagePoint ip_left(b, 0);
440  if (ip_left.get_i() >= 0. && ip_left.get_i() <= (I.getHeight() - 1.)) {
441  vip.push_back(ip_left);
442  }
443  // Test intersection with vertical line j=width-1
444  vpImagePoint ip_right(a * (I.getWidth() - 1) + b, I.getWidth() - 1.);
445  if (ip_right.get_i() >= 0. && ip_right.get_i() <= (I.getHeight() - 1.)) {
446  vip.push_back(ip_right);
447  }
448  if (vip.size() == 2) {
449  vp_display_display_line(I, vip[0], vip[1], color, thickness);
450  return;
451  }
452  // Test intersection with horizontal line i=0
453  vpImagePoint ip_top(0, -b / a);
454  if (ip_top.get_j() >= 0. && ip_top.get_j() <= (I.getWidth() - 1.)) {
455  vip.push_back(ip_top);
456  }
457  if (vip.size() == 2) {
458  vp_display_display_line(I, vip[0], vip[1], color, thickness);
459  return;
460  }
461  // Test intersection with horizontal line i=height-1
462  vpImagePoint ip_bottom(I.getHeight() - 1., (I.getHeight() - 1. - b) / a);
463  if (ip_bottom.get_j() >= 0. && ip_bottom.get_j() <= (I.getWidth() - 1.)) {
464  vip.push_back(ip_bottom);
465  }
466  if (vip.size() == 2) {
467  vp_display_display_line(I, vip[0], vip[1], color, thickness);
468  return;
469  }
470  }
471  }
472 }
473 
483 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &ips, bool closeTheShape,
484  const vpColor &color, unsigned int thickness)
485 {
486  if (ips.size() <= 1)
487  return;
488 
489  for (size_t i = 0; i < ips.size() - 1; i++)
490  vp_display_display_line(I, ips[i], ips[i + 1], color, thickness);
491 
492  if (closeTheShape)
493  vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
494 }
495 
505 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
506  const vpColor &color, unsigned int thickness)
507 {
508  if (ips.size() <= 1)
509  return;
510 
511  std::list<vpImagePoint>::const_iterator it = ips.begin();
512 
513  vpImagePoint ip_prev = *(it++);
514  for (; it != ips.end(); ++it) {
515  if (vpImagePoint::distance(ip_prev, *it) > 1) {
516  vp_display_display_line(I, ip_prev, *it, color, thickness);
517  ip_prev = *it;
518  }
519  }
520 
521  if (closeTheShape) {
522  vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
523  }
524 }
525 
533 void vpDisplay::displayPoint(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const vpColor &color,
534  unsigned int thickness)
535 {
536  vp_display_display_point(I, ip, color, thickness);
537 }
538 
546 void vpDisplay::displayPoint(const vpImage<vpRGBa> &I, int i, int j, const vpColor &color, unsigned int thickness)
547 {
548  vp_display_display_point(I, i, j, color, thickness);
549 }
550 
559 void vpDisplay::displayPolygon(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &vip, const vpColor &color,
560  unsigned int thickness, bool closed)
561 {
562  vp_display_display_polygon(I, vip, color, thickness, closed);
563 }
564 
581 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &topLeft, unsigned int width,
582  unsigned int height, const vpColor &color, bool fill, unsigned int thickness)
583 {
584  vp_display_display_rectangle(I, topLeft, width, height, color, fill, thickness);
585 }
586 
601 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, int i, int j, unsigned int width, unsigned int height,
602  const vpColor &color, bool fill, unsigned int thickness)
603 {
604  vp_display_display_rectangle(I, i, j, width, height, color, fill, thickness);
605 }
606 
622 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpRect &rectangle, const vpColor &color, bool fill,
623  unsigned int thickness)
624 {
625  vp_display_display_rectangle(I, rectangle, color, fill, thickness);
626 }
627 
641 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &center, float angle, unsigned int width,
642  unsigned int height, const vpColor &color, unsigned int thickness)
643 {
644  vp_display_display_rectangle(I, center, angle, width, height, color, thickness);
645 }
646 
663 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &topLeft, const vpImagePoint &bottomRight,
664  const vpColor &color, bool fill, unsigned int thickness)
665 {
666  vp_display_display_rectangle(I, topLeft, bottomRight, color, fill, thickness);
667 }
668 
682 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, unsigned int i, unsigned int j, float angle,
683  unsigned int width, unsigned int height, const vpColor &color, unsigned int thickness)
684 {
685  vp_display_display_rectangle(I, i, j, angle, width, height, color, thickness);
686 }
687 
700 void vpDisplay::displayText(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const std::string &s,
701  const vpColor &color)
702 {
703  vp_display_display_text(I, ip, s, color);
704 }
705 
718 void vpDisplay::displayText(const vpImage<vpRGBa> &I, int i, int j, const std::string &s, const vpColor &color)
719 {
720  vp_display_display_text(I, i, j, s, color);
721 }
722 
752 void vpDisplay::flush(const vpImage<vpRGBa> &I) { vp_display_flush(I); }
753 
763 void vpDisplay::flushROI(const vpImage<vpRGBa> &I, const vpRect &roi) { vp_display_flush_roi(I, roi); }
764 
776 void vpDisplay::display(const vpImage<vpRGBa> &I) { vp_display_display(I); }
777 
782 void vpDisplay::displayROI(const vpImage<vpRGBa> &I, const vpRect &roi) { vp_display_display_roi(I, roi); }
783 
801 bool vpDisplay::getClick(const vpImage<vpRGBa> &I, bool blocking) { return vp_display_get_click(I, blocking); }
802 
821 bool vpDisplay::getClick(const vpImage<vpRGBa> &I, vpImagePoint &ip, bool blocking)
822 {
823  return vp_display_get_click(I, ip, blocking);
824 }
825 
847  bool blocking)
848 {
849  return vp_display_get_click(I, ip, button, blocking);
850 }
851 
869 {
870  vpImagePoint ip;
871  return vpDisplay::getClick(I, ip, button, blocking);
872 }
873 
895  bool blocking)
896 {
897  return vp_display_get_click_up(I, ip, button, blocking);
898 }
899 
917 {
918  vpImagePoint ip;
919  return vpDisplay::getClickUp(I, ip, button, blocking);
920 }
921 
1004 bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, bool blocking)
1005 {
1006  return vp_display_get_keyboard_event(I, blocking);
1007 }
1008 
1095 bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, std::string &key, bool blocking)
1096 {
1097  return vp_display_get_keyboard_event(I, key, blocking);
1098 }
1099 
1186 bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, char *key, bool blocking)
1187 {
1188  return vp_display_get_keyboard_event(I, key, blocking);
1189 }
1190 
1201 {
1202  return vp_display_get_pointer_motion_event(I, ip);
1203 }
1204 
1215 {
1216  return vp_display_get_pointer_position(I, ip);
1217 }
1218 
1228 void vpDisplay::setBackground(const vpImage<vpRGBa> &I, const vpColor &color) { vp_display_set_background(I, color); }
1229 
1243 void vpDisplay::setFont(const vpImage<vpRGBa> &I, const std::string &fontname) { vp_display_set_font(I, fontname); }
1244 
1252 void vpDisplay::setTitle(const vpImage<vpRGBa> &I, const std::string &windowtitle)
1253 {
1254  vp_display_set_title(I, windowtitle);
1255 }
1256 
1267 void vpDisplay::setWindowPosition(const vpImage<vpRGBa> &I, int winx, int winy)
1268 {
1269  vp_display_set_window_position(I, winx, winy);
1270 }
1271 
1279 unsigned int vpDisplay::getDownScalingFactor(const vpImage<vpRGBa> &I) { return vp_display_get_down_scaling_factor(I); }
Generic class defining intrinsic camera parameters.
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:158
static void close(vpImage< unsigned char > &I)
static void setBackground(const vpImage< unsigned char > &I, const vpColor &color)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static bool getKeyboardEvent(const vpImage< unsigned char > &I, bool blocking=true)
static void displayROI(const vpImage< unsigned char > &I, const vpRect &roi)
static void display(const vpImage< unsigned char > &I)
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void displayEllipse(const vpImage< unsigned char > &I, const vpImagePoint &center, const double &coef1, const double &coef2, const double &coef3, bool use_normalized_centered_moments, const vpColor &color, unsigned int thickness=1, bool display_center=false, bool display_arc=false)
static void flushROI(const vpImage< unsigned char > &I, const vpRect &roi)
static bool getClickUp(const vpImage< unsigned char > &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void displayCharString(const vpImage< unsigned char > &I, const vpImagePoint &ip, const char *string, const vpColor &color)
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)
static void flush(const vpImage< unsigned char > &I)
static void displayArrow(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
static void setFont(const vpImage< unsigned char > &I, const std::string &font)
static void displayDotLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
static bool getPointerPosition(const vpImage< unsigned char > &I, vpImagePoint &ip)
static bool getPointerMotionEvent(const vpImage< unsigned char > &I, vpImagePoint &ip)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0))
static void displayCamera(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness)
unsigned int getDownScalingFactor()
Definition: vpDisplay.h:235
static void displayRectangle(const vpImage< unsigned char > &I, const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void setWindowPosition(const vpImage< unsigned char > &I, int winx, int winy)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
static void displayCircle(const vpImage< unsigned char > &I, const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void displayPolygon(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &vip, const vpColor &color, unsigned int thickness=1, bool closed=true)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:89
double get_j() const
Definition: vpImagePoint.h:132
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
double get_i() const
Definition: vpImagePoint.h:121
unsigned int getWidth() const
Definition: vpImage.h:247
unsigned int getHeight() const
Definition: vpImage.h:189
Defines a rectangle in the plane.
Definition: vpRect.h:80