Visual Servoing Platform  version 3.6.1 under development (2024-04-16)
vpDisplay_uchar.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 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 https://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<unsigned char> &I) { vp_display_close(I); }
49 
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<unsigned char> &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  const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness)
95 {
96  vp_display_display_camera(I, cMo, cam, size, color, thickness);
97 }
98 
99 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
113 void vpDisplay::displayCharString(const vpImage<unsigned char> &I, const vpImagePoint &ip, const char *string,
114  const vpColor &color)
115 {
116  vp_display_display_text(I, ip, string, color);
117 }
118 
132 void vpDisplay::displayCharString(const vpImage<unsigned char> &I, int i, int j, const char *string,
133  const vpColor &color)
134 {
135  vp_display_display_text(I, i, j, string, color);
136 }
137 #endif
138 
151  const vpColor &color, bool fill, unsigned int thickness)
152 {
153  vp_display_display_circle(I, circle.getCenter(), static_cast<unsigned int>(circle.getRadius()), color, fill, thickness);
154 }
155 
168 void vpDisplay::displayCircle(const vpImage<unsigned char> &I, const vpImagePoint &center, unsigned int radius,
169  const vpColor &color, bool fill, unsigned int thickness)
170 {
171  vp_display_display_circle(I, center, radius, color, fill, thickness);
172 }
173 
186 void vpDisplay::displayCircle(const vpImage<unsigned char> &I, int i, int j, unsigned int radius, const vpColor &color,
187  bool fill, unsigned int thickness)
188 {
189  vp_display_display_circle(I, i, j, radius, color, fill, thickness);
190 }
191 
200 void vpDisplay::displayCross(const vpImage<unsigned char> &I, const vpImagePoint &ip, unsigned int size,
201  const vpColor &color, unsigned int thickness)
202 {
203  vp_display_display_cross(I, ip, size, color, thickness);
204 }
205 
214 void vpDisplay::displayCross(const vpImage<unsigned char> &I, int i, int j, unsigned int size, const vpColor &color,
215  unsigned int thickness)
216 {
217  vp_display_display_cross(I, i, j, size, color, thickness);
218 }
219 
228  const vpColor &color, unsigned int thickness)
229 {
230  vp_display_display_dot_line(I, ip1, ip2, color, thickness);
231 }
232 
241 void vpDisplay::displayDotLine(const vpImage<unsigned char> &I, int i1, int j1, int i2, int j2, const vpColor &color,
242  unsigned int thickness)
243 {
244  vp_display_display_dot_line(I, i1, j1, i2, j2, color, thickness);
245 }
246 
256 void vpDisplay::displayDotLine(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &ips,
257  bool closeTheShape, const vpColor &color, unsigned int thickness)
258 {
259  if (ips.size() <= 1) {
260  return;
261  }
262 
263  for (size_t i = 0; i < ips.size() - 1; ++i) {
264  vp_display_display_dot_line(I, ips[i], ips[i + 1], color, thickness);
265  }
266 
267  if (closeTheShape) {
268  vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
269  }
270 }
271 
281 void vpDisplay::displayDotLine(const vpImage<unsigned char> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
282  const vpColor &color, unsigned int thickness)
283 {
284  if (ips.size() <= 1) {
285  return;
286  }
287 
288  std::list<vpImagePoint>::const_iterator it = ips.begin();
289 
290  vpImagePoint ip_prev = *(++it);
291  for (; it != ips.end(); ++it) {
292  if (vpImagePoint::distance(ip_prev, *it) > 1) {
293  vp_display_display_dot_line(I, ip_prev, *it, color, thickness);
294  ip_prev = *it;
295  }
296  }
297 
298  if (closeTheShape) {
299  vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
300  }
301 }
302 
339 void vpDisplay::displayEllipse(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &coef1,
340  const double &coef2, const double &coef3, bool use_normalized_centered_moments,
341  const vpColor &color, unsigned int thickness, bool display_center, bool display_arc)
342 {
343  vpDisplay::displayEllipse(I, center, coef1, coef2, coef3, 0., 2 * M_PI, use_normalized_centered_moments, color,
344  thickness, display_center, display_arc);
345 }
346 
386 void vpDisplay::displayEllipse(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &coef1,
387  const double &coef2, const double &coef3, const double &smallalpha,
388  const double &highalpha, bool use_normalized_centered_moments, const vpColor &color,
389  unsigned int thickness, bool display_center, bool display_arc)
390 {
391  vp_display_display_ellipse(I, center, coef1, coef2, coef3, smallalpha, highalpha, use_normalized_centered_moments,
392  color, thickness, display_center, display_arc);
393 }
394 
413  const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness,
414  const vpImagePoint &offset, const std::string &frameName, const vpColor &textColor, const vpImagePoint &textOffset)
415 {
416  vp_display_display_frame(I, cMo, cam, size, color, thickness, offset, frameName, textColor, textOffset);
417 }
418 
429  const vpColor &color, unsigned int thickness, bool segment)
430 {
431  displayLine(I, static_cast<int>(ip1.get_i()), static_cast<int>(ip1.get_j()), static_cast<int>(ip2.get_i()),
432  static_cast<int>(ip2.get_j()), color, thickness, segment);
433 }
434 
445 void vpDisplay::displayLine(const vpImage<unsigned char> &I, int i1, int j1, int i2, int j2, const vpColor &color,
446  unsigned int thickness, bool segment)
447 {
448  if (segment) {
449  vp_display_display_line(I, i1, j1, i2, j2, color, thickness);
450  }
451  else {
452  // line equation in image: i = a * j + b
453  double delta_j = static_cast<double>(j2) - static_cast<double>(j1);
454  double delta_i = static_cast<double>(i2) - static_cast<double>(i1);
455  // Test if horizontal line
456  if (std::fabs(delta_i) <= std::numeric_limits<double>::epsilon()) {
457  vp_display_display_line(I, i1, 0, i1, (I.getWidth() - 1), color, thickness);
458  }
459  // Test if vertical line
460  else if (std::fabs(delta_j) <= std::numeric_limits<double>::epsilon()) {
461  vp_display_display_line(I, 0, j1, (I.getHeight() - 1), j1, color, thickness);
462  }
463  else {
464  double a = delta_i / delta_j;
465  double b = static_cast<double>(i1) - (a * static_cast<double>(j1));
466  std::vector<vpImagePoint> vip; // Image points that intersect image borders
467  // Test intersection with vertical line j=0
468  vpImagePoint ip_left(b, 0);
469  if (ip_left.get_i() >= 0. && ip_left.get_i() <= (I.getHeight() - 1.)) {
470  vip.push_back(ip_left);
471  }
472  // Test intersection with vertical line j=width-1
473  vpImagePoint ip_right(a * (I.getWidth() - 1) + b, I.getWidth() - 1.);
474  if ((ip_right.get_i() >= 0.) && (ip_right.get_i() <= (I.getHeight() - 1.))) {
475  vip.push_back(ip_right);
476  }
477  if (vip.size() == 2) {
478  vp_display_display_line(I, vip[0], vip[1], color, thickness);
479  return;
480  }
481  // Test intersection with horizontal line i=0
482  vpImagePoint ip_top(0, -b / a);
483  if ((ip_top.get_j() >= 0.) && (ip_top.get_j() <= (I.getWidth() - 1.))) {
484  vip.push_back(ip_top);
485  }
486  if (vip.size() == 2) {
487  vp_display_display_line(I, vip[0], vip[1], color, thickness);
488  return;
489  }
490  // Test intersection with horizontal line i=height-1
491  vpImagePoint ip_bottom(I.getHeight() - 1., (I.getHeight() - 1. - b) / a);
492  if ((ip_bottom.get_j() >= 0.) && (ip_bottom.get_j() <= (I.getWidth() - 1.))) {
493  vip.push_back(ip_bottom);
494  }
495  if (vip.size() == 2) {
496  vp_display_display_line(I, vip[0], vip[1], color, thickness);
497  return;
498  }
499  }
500  }
501 }
502 
511 void vpDisplay::displayLine(const vpImage<unsigned char> &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  for (size_t i = 0; i < ips.size() - 1; ++i) {
519  vp_display_display_line(I, ips[i], ips[i + 1], color, thickness);
520  }
521 
522  if (closeTheShape) {
523  vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
524  }
525 }
526 
535 void vpDisplay::displayLine(const vpImage<unsigned char> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
536  const vpColor &color, unsigned int thickness)
537 {
538  if (ips.size() <= 1) {
539  return;
540  }
541 
542  std::list<vpImagePoint>::const_iterator it = ips.begin();
543 
544  vpImagePoint ip_prev = *(++it);
545  for (; it != ips.end(); ++it) {
546  if (vpImagePoint::distance(ip_prev, *it) > 1) {
547  vp_display_display_line(I, ip_prev, *it, color, thickness);
548  ip_prev = *it;
549  }
550  }
551 
552  if (closeTheShape) {
553  vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
554  }
555 }
556 
565  unsigned int thickness)
566 {
567  vp_display_display_point(I, ip, color, thickness);
568 }
569 
577 void vpDisplay::displayPoint(const vpImage<unsigned char> &I, int i, int j, const vpColor &color,
578  unsigned int thickness)
579 {
580  vp_display_display_point(I, i, j, color, thickness);
581 }
582 
591 void vpDisplay::displayPolygon(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &vip,
592  const vpColor &color, unsigned int thickness, bool closed)
593 {
594  vp_display_display_polygon(I, vip, color, thickness, closed);
595 }
596 
605 void vpDisplay::displayPolygon(const vpImage<unsigned char> &I, const vpPolygon &polygon, const vpColor &color,
606  unsigned int thickness, bool closed)
607 {
608  vp_display_display_polygon(I, polygon, color, thickness, closed);
609 }
610 
627 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, const vpImagePoint &topLeft, unsigned int width,
628  unsigned int height, const vpColor &color, bool fill, unsigned int thickness)
629 {
630  vp_display_display_rectangle(I, topLeft, width, height, color, fill, thickness);
631 }
632 
647 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, int i, int j, unsigned int width, unsigned int height,
648  const vpColor &color, bool fill, unsigned int thickness)
649 {
650  vp_display_display_rectangle(I, i, j, width, height, color, fill, thickness);
651 }
652 
668 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, const vpRect &rectangle, const vpColor &color,
669  bool fill, unsigned int thickness)
670 {
671  vp_display_display_rectangle(I, rectangle, color, fill, thickness);
672 }
673 
687 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, const vpImagePoint &center, float angle,
688  unsigned int width, unsigned int height, const vpColor &color, unsigned int thickness)
689 {
690  vp_display_display_rectangle(I, center, angle, width, height, color, thickness);
691 }
692 
710  const vpImagePoint &bottomRight, const vpColor &color, bool fill,
711  unsigned int thickness)
712 {
713  vp_display_display_rectangle(I, topLeft, bottomRight, color, fill, thickness);
714 }
715 
729 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, unsigned int i, unsigned int j, float angle,
730  unsigned int width, unsigned int height, const vpColor &color, unsigned int thickness)
731 {
732  vp_display_display_rectangle(I, i, j, angle, width, height, color, thickness);
733 }
734 
747 void vpDisplay::displayText(const vpImage<unsigned char> &I, const vpImagePoint &ip, const std::string &s,
748  const vpColor &color)
749 {
750  vp_display_display_text(I, ip, s, color);
751 }
752 
765 void vpDisplay::displayText(const vpImage<unsigned char> &I, int i, int j, const std::string &s, const vpColor &color)
766 {
767  vp_display_display_text(I, i, j, s, color);
768 }
769 
799 void vpDisplay::flush(const vpImage<unsigned char> &I) { vp_display_flush(I); }
800 
810 void vpDisplay::flushROI(const vpImage<unsigned char> &I, const vpRect &roi) { vp_display_flush_roi(I, roi); }
811 
823 void vpDisplay::display(const vpImage<unsigned char> &I) { vp_display_display(I); }
824 
829 void vpDisplay::displayROI(const vpImage<unsigned char> &I, const vpRect &roi) { vp_display_display_roi(I, roi); }
830 
848 bool vpDisplay::getClick(const vpImage<unsigned char> &I, bool blocking) { return vp_display_get_click(I, blocking); }
849 
868 bool vpDisplay::getClick(const vpImage<unsigned char> &I, vpImagePoint &ip, bool blocking)
869 {
870  return vp_display_get_click(I, ip, blocking);
871 }
872 
894  bool blocking)
895 {
896  return vp_display_get_click(I, ip, button, blocking);
897 }
898 
916 {
917  vpImagePoint ip;
918  return vpDisplay::getClick(I, ip, button, blocking);
919 }
920 
942  bool blocking)
943 {
944  return vp_display_get_click_up(I, ip, button, blocking);
945 }
946 
964 {
965  vpImagePoint ip;
966  return vpDisplay::getClickUp(I, ip, button, blocking);
967 }
968 
1053 {
1054  return vp_display_get_keyboard_event(I, blocking);
1055 }
1056 
1143 bool vpDisplay::getKeyboardEvent(const vpImage<unsigned char> &I, std::string &key, bool blocking)
1144 {
1145  return vp_display_get_keyboard_event(I, key, blocking);
1146 }
1147 
1234 bool vpDisplay::getKeyboardEvent(const vpImage<unsigned char> &I, char *key, bool blocking)
1235 {
1236  return vp_display_get_keyboard_event(I, key, blocking);
1237 }
1238 
1249 {
1250  return vp_display_get_pointer_motion_event(I, ip);
1251 }
1252 
1263 {
1264  return vp_display_get_pointer_position(I, ip);
1265 }
1266 
1277 {
1278  vp_display_set_background(I, color);
1279 }
1280 
1294 void vpDisplay::setFont(const vpImage<unsigned char> &I, const std::string &fontname)
1295 {
1296  vp_display_set_font(I, fontname);
1297 }
1298 
1306 void vpDisplay::setTitle(const vpImage<unsigned char> &I, const std::string &windowtitle)
1307 {
1308  vp_display_set_title(I, windowtitle);
1309 }
1310 
1321 void vpDisplay::setWindowPosition(const vpImage<unsigned char> &I, int winx, int winy)
1322 {
1323  vp_display_set_window_position(I, winx, winy);
1324 }
1325 
1334 {
1335  return vp_display_get_down_scaling_factor(I);
1336 }
Generic class defining intrinsic camera parameters.
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:152
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 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 vp_deprecated 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 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:231
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:56
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:245
unsigned int getHeight() const
Definition: vpImage.h:184
Defines a generic 2D polygon.
Definition: vpPolygon.h:97
Defines a rectangle in the plane.
Definition: vpRect.h:76