Visual Servoing Platform  version 3.5.1 under development (2022-07-05)
vpDisplay_uchar.cpp
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 
51 void vpDisplay::close(vpImage<unsigned char> &I) { vp_display_close(I); }
52 
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 
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 
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 
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 
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 
152 void vpDisplay::displayCircle(const vpImage<unsigned char> &I, const vpImagePoint &center, 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 
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 
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 
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 
212  const vpColor &color, unsigned int thickness)
213 {
214  vp_display_display_dot_line(I, ip1, ip2, color, thickness);
215 }
216 
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 
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 
262 void vpDisplay::displayDotLine(const vpImage<unsigned char> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
263  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 
319 void vpDisplay::displayEllipse(const vpImage<unsigned char> &I, const vpImagePoint &center, 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 
366 void vpDisplay::displayEllipse(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &coef1,
367  const double &coef2, const double &coef3, const double &smallalpha,
368  const double &highalpha, bool use_normalized_centered_moments, const vpColor &color,
369  unsigned int thickness, bool display_center, bool display_arc)
370 {
371  vp_display_display_ellipse(I, center, coef1, coef2, coef3, smallalpha, highalpha, use_normalized_centered_moments,
372  color, thickness, display_center, display_arc);
373 }
374 
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 
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()),
410  static_cast<int>(ip2.get_j()), color, thickness, segment);
411 }
412 
423 void vpDisplay::displayLine(const vpImage<unsigned char> &I, int i1, int j1, int i2, int j2, const vpColor &color,
424  unsigned int thickness, bool segment)
425 {
426  if (segment) {
427  vp_display_display_line(I, i1, j1, i2, j2, color, thickness);
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  } else {
440  double a = delta_i / delta_j;
441  double b = static_cast<double>(i1) - a * static_cast<double>(j1);
442  std::vector<vpImagePoint> vip; // Image points that intersect image borders
443  // Test intersection with vertical line j=0
444  vpImagePoint ip_left(b, 0);
445  if (ip_left.get_i() >= 0. && ip_left.get_i() <= (I.getHeight() - 1.)) {
446  vip.push_back(ip_left);
447  }
448  // Test intersection with vertical line j=width-1
449  vpImagePoint ip_right(a * (I.getWidth() - 1) + b, I.getWidth() - 1.);
450  if (ip_right.get_i() >= 0. && ip_right.get_i() <= (I.getHeight() - 1.)) {
451  vip.push_back(ip_right);
452  }
453  if (vip.size() == 2) {
454  vp_display_display_line(I, vip[0], vip[1], color, thickness);
455  return;
456  }
457  // Test intersection with horizontal line i=0
458  vpImagePoint ip_top(0, -b / a);
459  if (ip_top.get_j() >= 0. && ip_top.get_j() <= (I.getWidth() - 1.)) {
460  vip.push_back(ip_top);
461  }
462  if (vip.size() == 2) {
463  vp_display_display_line(I, vip[0], vip[1], color, thickness);
464  return;
465  }
466  // Test intersection with horizontal line i=height-1
467  vpImagePoint ip_bottom(I.getHeight() - 1., (I.getHeight() - 1. - b) / a);
468  if (ip_bottom.get_j() >= 0. && ip_bottom.get_j() <= (I.getWidth() - 1.)) {
469  vip.push_back(ip_bottom);
470  }
471  if (vip.size() == 2) {
472  vp_display_display_line(I, vip[0], vip[1], color, thickness);
473  return;
474  }
475  }
476  }
477 }
478 
487 void vpDisplay::displayLine(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &ips, bool closeTheShape,
488  const vpColor &color, unsigned int thickness)
489 {
490  if (ips.size() <= 1)
491  return;
492 
493  for (size_t i = 0; i < ips.size() - 1; i++)
494  vp_display_display_line(I, ips[i], ips[i + 1], color, thickness);
495 
496  if (closeTheShape)
497  vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
498 }
499 
508 void vpDisplay::displayLine(const vpImage<unsigned char> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
509  const vpColor &color, unsigned int thickness)
510 {
511  if (ips.size() <= 1)
512  return;
513 
514  std::list<vpImagePoint>::const_iterator it = ips.begin();
515 
516  vpImagePoint ip_prev = *(it++);
517  for (; it != ips.end(); ++it) {
518  if (vpImagePoint::distance(ip_prev, *it) > 1) {
519  vp_display_display_line(I, ip_prev, *it, color, thickness);
520  ip_prev = *it;
521  }
522  }
523 
524  if (closeTheShape) {
525  vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
526  }
527 }
528 
537  unsigned int thickness)
538 {
539  vp_display_display_point(I, ip, color, thickness);
540 }
541 
549 void vpDisplay::displayPoint(const vpImage<unsigned char> &I, int i, int j, const vpColor &color,
550  unsigned int thickness)
551 {
552  vp_display_display_point(I, i, j, color, thickness);
553 }
554 
563 void vpDisplay::displayPolygon(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &vip,
564  const vpColor &color, unsigned int thickness, bool closed)
565 {
566  vp_display_display_polygon(I, vip, color, thickness, closed);
567 }
568 
585 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, const vpImagePoint &topLeft, unsigned int width,
586  unsigned int height, const vpColor &color, bool fill, unsigned int thickness)
587 {
588  vp_display_display_rectangle(I, topLeft, width, height, color, fill, thickness);
589 }
590 
605 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, int i, int j, unsigned int width, unsigned int height,
606  const vpColor &color, bool fill, unsigned int thickness)
607 {
608  vp_display_display_rectangle(I, i, j, width, height, color, fill, thickness);
609 }
610 
626 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, const vpRect &rectangle, const vpColor &color,
627  bool fill, unsigned int thickness)
628 {
629  vp_display_display_rectangle(I, rectangle, color, fill, thickness);
630 }
631 
645 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, const vpImagePoint &center, float angle,
646  unsigned int width, unsigned int height, const vpColor &color, unsigned int thickness)
647 {
648  vp_display_display_rectangle(I, center, angle, width, height, color, thickness);
649 }
650 
668  const vpImagePoint &bottomRight, const vpColor &color, bool fill,
669  unsigned int thickness)
670 {
671  vp_display_display_rectangle(I, topLeft, bottomRight, color, fill, thickness);
672 }
673 
687 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, unsigned int i, unsigned int j, float angle,
688  unsigned int width, unsigned int height, const vpColor &color, unsigned int thickness)
689 {
690  vp_display_display_rectangle(I, i, j, angle, width, height, color, thickness);
691 }
692 
705 void vpDisplay::displayText(const vpImage<unsigned char> &I, const vpImagePoint &ip, const std::string &s,
706  const vpColor &color)
707 {
708  vp_display_display_text(I, ip, s, color);
709 }
710 
723 void vpDisplay::displayText(const vpImage<unsigned char> &I, int i, int j, const std::string &s, const vpColor &color)
724 {
725  vp_display_display_text(I, i, j, s, color);
726 }
727 
757 void vpDisplay::flush(const vpImage<unsigned char> &I) { vp_display_flush(I); }
758 
768 void vpDisplay::flushROI(const vpImage<unsigned char> &I, const vpRect &roi) { vp_display_flush_roi(I, roi); }
769 
781 void vpDisplay::display(const vpImage<unsigned char> &I) { vp_display_display(I); }
782 
787 void vpDisplay::displayROI(const vpImage<unsigned char> &I, const vpRect &roi) { vp_display_display_roi(I, roi); }
788 
806 bool vpDisplay::getClick(const vpImage<unsigned char> &I, bool blocking) { return vp_display_get_click(I, blocking); }
807 
826 bool vpDisplay::getClick(const vpImage<unsigned char> &I, vpImagePoint &ip, bool blocking)
827 {
828  return vp_display_get_click(I, ip, blocking);
829 }
830 
852  bool blocking)
853 {
854  return vp_display_get_click(I, ip, button, blocking);
855 }
856 
874 {
875  vpImagePoint ip;
876  return vpDisplay::getClick(I, ip, button, blocking);
877 }
878 
900  bool blocking)
901 {
902  return vp_display_get_click_up(I, ip, button, blocking);
903 }
904 
922 {
923  vpImagePoint ip;
924  return vpDisplay::getClickUp(I, ip, button, blocking);
925 }
926 
1011 {
1012  return vp_display_get_keyboard_event(I, blocking);
1013 }
1014 
1101 bool vpDisplay::getKeyboardEvent(const vpImage<unsigned char> &I, std::string &key, bool blocking)
1102 {
1103  return vp_display_get_keyboard_event(I, key, blocking);
1104 }
1105 
1192 bool vpDisplay::getKeyboardEvent(const vpImage<unsigned char> &I, char *key, bool blocking)
1193 {
1194  return vp_display_get_keyboard_event(I, key, blocking);
1195 }
1196 
1207 {
1208  return vp_display_get_pointer_motion_event(I, ip);
1209 }
1210 
1221 {
1222  return vp_display_get_pointer_position(I, ip);
1223 }
1224 
1235 {
1236  vp_display_set_background(I, color);
1237 }
1238 
1252 void vpDisplay::setFont(const vpImage<unsigned char> &I, const std::string &fontname)
1253 {
1254  vp_display_set_font(I, fontname);
1255 }
1256 
1264 void vpDisplay::setTitle(const vpImage<unsigned char> &I, const std::string &windowtitle)
1265 {
1266  vp_display_set_title(I, windowtitle);
1267 }
1268 
1279 void vpDisplay::setWindowPosition(const vpImage<unsigned char> &I, int winx, int winy)
1280 {
1281  vp_display_set_window_position(I, winx, winy);
1282 }
1283 
1292 {
1293  return vp_display_get_down_scaling_factor(I);
1294 }
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:246
unsigned int getHeight() const
Definition: vpImage.h:188
Defines a rectangle in the plane.
Definition: vpRect.h:80