Visual Servoing Platform  version 3.6.1 under development (2024-12-10)
vpDisplay_rgba.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Display implementation.
32  *
33 *****************************************************************************/
34 
35 #include <visp3/core/vpDisplay.h>
36 
37 #include "vpDisplay_impl.h"
38 
39 //************************************************************************
40 // Modifications done in this file should be reported in all vpDisplay_*.cpp
41 // files that implement other types (unsigned char, vpRGB, vpRGBa)
42 //************************************************************************
43 BEGIN_VISP_NAMESPACE
47 void vpDisplay::close(vpImage<vpRGBa> &I) { vp_display_close(I); }
48 
57 void vpDisplay::displayArrow(const vpImage<vpRGBa> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
58  const vpColor &color, unsigned int w, unsigned int h, unsigned int thickness)
59 {
60  vp_display_display_arrow(I, ip1, ip2, color, w, h, thickness);
61 }
62 
73 void vpDisplay::displayArrow(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
74  unsigned int w, unsigned int h, unsigned int thickness)
75 {
76  vp_display_display_arrow(I, i1, j1, i2, j2, color, w, h, thickness);
77 }
78 
93  double size, const vpColor &color, unsigned int thickness)
94 {
95  vp_display_display_camera(I, cMo, cam, size, color, thickness);
96 }
97 
98 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
112 void vpDisplay::displayCharString(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const char *string,
113  const vpColor &color)
114 {
115  vp_display_display_text(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_text(I, i, j, string, color);
134 }
135 #endif
136 
149  const vpColor &color, bool fill, unsigned int thickness)
150 {
151  vp_display_display_circle(I, circle.getCenter(), static_cast<unsigned int>(circle.getRadius()), color, fill, thickness);
152 }
153 
166 void vpDisplay::displayCircle(const vpImage<vpRGBa> &I, const vpImagePoint &center, unsigned int radius,
167  const vpColor &color, bool fill, unsigned int thickness)
168 {
169  vp_display_display_circle(I, center, radius, color, fill, thickness);
170 }
171 
184 void vpDisplay::displayCircle(const vpImage<vpRGBa> &I, int i, int j, unsigned int radius, const vpColor &color,
185  bool fill, unsigned int thickness)
186 {
187  vp_display_display_circle(I, i, j, radius, color, fill, thickness);
188 }
189 
198 void vpDisplay::displayCross(const vpImage<vpRGBa> &I, const vpImagePoint &ip, unsigned int size, const vpColor &color,
199  unsigned int thickness)
200 {
201  vp_display_display_cross(I, ip, size, color, thickness);
202 }
203 
212 void vpDisplay::displayCross(const vpImage<vpRGBa> &I, int i, int j, unsigned int size, const vpColor &color,
213  unsigned int thickness)
214 {
215  vp_display_display_cross(I, i, j, size, color, thickness);
216 }
217 
226  const vpColor &color, unsigned int thickness)
227 {
228  vp_display_display_dot_line(I, ip1, ip2, color, thickness);
229 }
230 
239 void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
240  unsigned int thickness)
241 {
242  vp_display_display_dot_line(I, i1, j1, i2, j2, color, thickness);
243 }
244 
254 void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &ips, bool closeTheShape,
255  const vpColor &color, unsigned int thickness)
256 {
257  if (ips.size() <= 1) {
258  return;
259  }
260  size_t ips_size = ips.size();
261  for (size_t i = 0; i < (ips_size - 1); ++i) {
262  vp_display_display_dot_line(I, ips[i], ips[i + 1], color, thickness);
263  }
264 
265  if (closeTheShape) {
266  vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
267  }
268 }
269 
279 void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
280  const vpColor &color, unsigned int thickness)
281 {
282  if (ips.size() <= 1) {
283  return;
284  }
285 
286  std::list<vpImagePoint>::const_iterator it = ips.begin();
287 
288  vpImagePoint ip_prev = *(++it);
289  std::list<vpImagePoint>::const_iterator ips_end = ips.end();
290  for (; it != ips_end; ++it) {
291  if (vpImagePoint::distance(ip_prev, *it) > 1) {
292  vp_display_display_dot_line(I, ip_prev, *it, color, thickness);
293  ip_prev = *it;
294  }
295  }
296 
297  if (closeTheShape) {
298  vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
299  }
300 }
301 
338 void vpDisplay::displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &coef1,
339  const double &coef2, const double &coef3, bool use_normalized_centered_moments,
340  const vpColor &color, unsigned int thickness, bool display_center, bool display_arc)
341 {
342  vpDisplay::displayEllipse(I, center, coef1, coef2, coef3, 0., 2 * M_PI, use_normalized_centered_moments, color,
343  thickness, display_center, display_arc);
344 }
345 
385 void vpDisplay::displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &coef1,
386  const double &coef2, const double &coef3, const double &smallalpha,
387  const double &highalpha, bool use_normalized_centered_moments, const vpColor &color,
388  unsigned int thickness, bool display_center, bool display_arc)
389 {
390  vp_display_display_ellipse(I, center, coef1, coef2, coef3, smallalpha, highalpha, use_normalized_centered_moments,
391  color, thickness, display_center, display_arc);
392 }
393 
412  double size, const vpColor &color, unsigned int thickness, const vpImagePoint &offset,
413  const std::string &frameName, const vpColor &textColor, const vpImagePoint &textOffset)
414 {
415  vp_display_display_frame(I, cMo, cam, size, color, thickness, offset, frameName, textColor, textOffset);
416 }
417 
427 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
428  const vpColor &color, unsigned int thickness, bool segment)
429 {
430  displayLine(I, static_cast<int>(ip1.get_i()), static_cast<int>(ip1.get_j()), static_cast<int>(ip2.get_i()),
431  static_cast<int>(ip2.get_j()), color, thickness, segment);
432 }
433 
444 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
445  unsigned int thickness, bool segment)
446 {
447  if (segment) {
448  vp_display_display_line(I, i1, j1, i2, j2, color, thickness);
449  }
450  else {
451  // line equation in image: i = a * j + b
452  double delta_j = static_cast<double>(j2) - static_cast<double>(j1);
453  double delta_i = static_cast<double>(i2) - static_cast<double>(i1);
454  // Test if horizontal line
455  if (std::fabs(delta_i) <= std::numeric_limits<double>::epsilon()) {
456  vp_display_display_line(I, i1, 0, i1, (I.getWidth() - 1), color, thickness);
457  }
458  // Test if vertical line
459  else if (std::fabs(delta_j) <= std::numeric_limits<double>::epsilon()) {
460  vp_display_display_line(I, 0, j1, (I.getHeight() - 1), j1, color, thickness);
461  }
462  else {
463  double a = delta_i / delta_j;
464  double b = static_cast<double>(i1) - (a * static_cast<double>(j1));
465  std::vector<vpImagePoint> vip; // Image points that intersect image borders
466  // Test intersection with vertical line j=0
467  vpImagePoint ip_left(b, 0);
468  if ((ip_left.get_i() >= 0.) && (ip_left.get_i() <= (I.getHeight() - 1.))) {
469  vip.push_back(ip_left);
470  }
471  // Test intersection with vertical line j=width-1
472  vpImagePoint ip_right((a * (I.getWidth() - 1)) + b, I.getWidth() - 1.);
473  if ((ip_right.get_i() >= 0.) && (ip_right.get_i() <= (I.getHeight() - 1.))) {
474  vip.push_back(ip_right);
475  }
476  if (vip.size() == 2) {
477  vp_display_display_line(I, vip[0], vip[1], color, thickness);
478  return;
479  }
480  // Test intersection with horizontal line i=0
481  vpImagePoint ip_top(0, -b / a);
482  if ((ip_top.get_j() >= 0.) && (ip_top.get_j() <= (I.getWidth() - 1.))) {
483  vip.push_back(ip_top);
484  }
485  if (vip.size() == 2) {
486  vp_display_display_line(I, vip[0], vip[1], color, thickness);
487  return;
488  }
489  // Test intersection with horizontal line i=height-1
490  vpImagePoint ip_bottom(I.getHeight() - 1., (I.getHeight() - 1. - b) / a);
491  if ((ip_bottom.get_j() >= 0.) && (ip_bottom.get_j() <= (I.getWidth() - 1.))) {
492  vip.push_back(ip_bottom);
493  }
494  if (vip.size() == 2) {
495  vp_display_display_line(I, vip[0], vip[1], color, thickness);
496  return;
497  }
498  }
499  }
500 }
501 
511 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &ips, bool closeTheShape,
512  const vpColor &color, unsigned int thickness)
513 {
514  if (ips.size() <= 1) {
515  return;
516  }
517 
518  size_t ips_size = ips.size();
519  for (size_t i = 0; i < (ips_size - 1); ++i) {
520  vp_display_display_line(I, ips[i], ips[i + 1], color, thickness);
521  }
522 
523  if (closeTheShape) {
524  vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
525  }
526 }
527 
537 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
538  const vpColor &color, unsigned int thickness)
539 {
540  if (ips.size() <= 1) {
541  return;
542  }
543 
544  std::list<vpImagePoint>::const_iterator it = ips.begin();
545 
546  vpImagePoint ip_prev = *(++it);
547  std::list<vpImagePoint>::const_iterator ips_end = ips.end();
548  for (; it != ips_end; ++it) {
549  if (vpImagePoint::distance(ip_prev, *it) > 1) {
550  vp_display_display_line(I, ip_prev, *it, color, thickness);
551  ip_prev = *it;
552  }
553  }
554 
555  if (closeTheShape) {
556  vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
557  }
558 }
559 
567 void vpDisplay::displayPoint(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const vpColor &color,
568  unsigned int thickness)
569 {
570  vp_display_display_point(I, ip, color, thickness);
571 }
572 
580 void vpDisplay::displayPoint(const vpImage<vpRGBa> &I, int i, int j, const vpColor &color, unsigned int thickness)
581 {
582  vp_display_display_point(I, i, j, color, thickness);
583 }
584 
593 void vpDisplay::displayPolygon(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &vip, const vpColor &color,
594  unsigned int thickness, bool closed)
595 {
596  vp_display_display_polygon(I, vip, color, thickness, closed);
597 }
598 
607 void vpDisplay::displayPolygon(const vpImage<vpRGBa> &I, const vpPolygon &polygon, const vpColor &color,
608  unsigned int thickness, bool closed)
609 {
610  vp_display_display_polygon(I, polygon, color, thickness, closed);
611 }
612 
629 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &topLeft, unsigned int width,
630  unsigned int height, const vpColor &color, bool fill, unsigned int thickness)
631 {
632  vp_display_display_rectangle(I, topLeft, width, height, color, fill, thickness);
633 }
634 
649 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, int i, int j, unsigned int width, unsigned int height,
650  const vpColor &color, bool fill, unsigned int thickness)
651 {
652  vp_display_display_rectangle(I, i, j, width, height, color, fill, thickness);
653 }
654 
670 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpRect &rectangle, const vpColor &color, bool fill,
671  unsigned int thickness)
672 {
673  vp_display_display_rectangle(I, rectangle, color, fill, thickness);
674 }
675 
689 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &center, float angle, unsigned int width,
690  unsigned int height, const vpColor &color, unsigned int thickness)
691 {
692  vp_display_display_rectangle(I, center, angle, width, height, color, thickness);
693 }
694 
711 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &topLeft, const vpImagePoint &bottomRight,
712  const vpColor &color, bool fill, unsigned int thickness)
713 {
714  vp_display_display_rectangle(I, topLeft, bottomRight, color, fill, thickness);
715 }
716 
730 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, unsigned int i, unsigned int j, float angle,
731  unsigned int width, unsigned int height, const vpColor &color, unsigned int thickness)
732 {
733  vp_display_display_rectangle(I, i, j, angle, width, height, color, thickness);
734 }
735 
748 void vpDisplay::displayText(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const std::string &s,
749  const vpColor &color)
750 {
751  vp_display_display_text(I, ip, s, color);
752 }
753 
766 void vpDisplay::displayText(const vpImage<vpRGBa> &I, int i, int j, const std::string &s, const vpColor &color)
767 {
768  vp_display_display_text(I, i, j, s, color);
769 }
770 
804 void vpDisplay::flush(const vpImage<vpRGBa> &I) { vp_display_flush(I); }
805 
815 void vpDisplay::flushROI(const vpImage<vpRGBa> &I, const vpRect &roi) { vp_display_flush_roi(I, roi); }
816 
828 void vpDisplay::display(const vpImage<vpRGBa> &I) { vp_display_display(I); }
829 
834 void vpDisplay::displayROI(const vpImage<vpRGBa> &I, const vpRect &roi) { vp_display_display_roi(I, roi); }
835 
853 bool vpDisplay::getClick(const vpImage<vpRGBa> &I, bool blocking) { return vp_display_get_click(I, blocking); }
854 
873 bool vpDisplay::getClick(const vpImage<vpRGBa> &I, vpImagePoint &ip, bool blocking)
874 {
875  return vp_display_get_click(I, ip, blocking);
876 }
877 
899  bool blocking)
900 {
901  return vp_display_get_click(I, ip, button, blocking);
902 }
903 
921 {
922  vpImagePoint ip;
923  return vpDisplay::getClick(I, ip, button, blocking);
924 }
925 
947  bool blocking)
948 {
949  return vp_display_get_click_up(I, ip, button, blocking);
950 }
951 
969 {
970  vpImagePoint ip;
971  return vpDisplay::getClickUp(I, ip, button, blocking);
972 }
973 
1060 bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, bool blocking)
1061 {
1062  return vp_display_get_keyboard_event(I, blocking);
1063 }
1064 
1155 bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, std::string &key, bool blocking)
1156 {
1157  return vp_display_get_keyboard_event(I, key, blocking);
1158 }
1159 
1250 bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, char *key, bool blocking)
1251 {
1252  return vp_display_get_keyboard_event(I, key, blocking);
1253 }
1254 
1265 {
1266  return vp_display_get_pointer_motion_event(I, ip);
1267 }
1268 
1279 {
1280  return vp_display_get_pointer_position(I, ip);
1281 }
1282 
1292 void vpDisplay::setBackground(const vpImage<vpRGBa> &I, const vpColor &color) { vp_display_set_background(I, color); }
1293 
1307 void vpDisplay::setFont(const vpImage<vpRGBa> &I, const std::string &fontname) { vp_display_set_font(I, fontname); }
1308 
1316 void vpDisplay::setTitle(const vpImage<vpRGBa> &I, const std::string &windowtitle)
1317 {
1318  vp_display_set_title(I, windowtitle);
1319 }
1320 
1331 void vpDisplay::setWindowPosition(const vpImage<vpRGBa> &I, int winx, int winy)
1332 {
1333  vp_display_set_window_position(I, winx, winy);
1334 }
1335 
1343 unsigned int vpDisplay::getDownScalingFactor(const vpImage<vpRGBa> &I) { return vp_display_get_down_scaling_factor(I); }
1344 END_VISP_NAMESPACE
Generic class defining intrinsic camera parameters.
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
static void setBackground(const vpImage< unsigned char > &I, const vpColor &color)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void displayCircle(const vpImage< unsigned char > &I, const vpImageCircle &circle, const vpColor &color, bool fill=false, unsigned int thickness=1)
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 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), const std::string &frameName="", const vpColor &textColor=vpColor::black, const vpImagePoint &textOffset=vpImagePoint(15, 15))
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 close(vpImage< unsigned char > &I)
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 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:221
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 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 circle in an image.
Definition: vpImageCircle.h:57
float getRadius() const
vpImagePoint getCenter() const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
double get_j() const
Definition: vpImagePoint.h:125
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
double get_i() const
Definition: vpImagePoint.h:114
unsigned int getWidth() const
Definition: vpImage.h:242
unsigned int getHeight() const
Definition: vpImage.h:181
Defines a generic 2D polygon.
Definition: vpPolygon.h:103
Defines a rectangle in the plane.
Definition: vpRect.h:79