Visual Servoing Platform  version 3.3.1 under development (2020-07-09)
vpDisplay_rgba.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<vpRGBa> &I) { vp_display_close(I); }
52 
61 void vpDisplay::displayArrow(const vpImage<vpRGBa> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
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<vpRGBa> &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  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<vpRGBa> &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<vpRGBa> &I, int i, int j, const char *string, const vpColor &color)
135 {
136  vp_display_display_char_string(I, i, j, string, color);
137 }
138 
151 void vpDisplay::displayCircle(const vpImage<vpRGBa> &I, const vpImagePoint &center, unsigned int radius,
152  const vpColor &color, bool fill, unsigned int thickness)
153 {
154  vp_display_display_circle(I, center, radius, color, fill, thickness);
155 }
156 
169 void vpDisplay::displayCircle(const vpImage<vpRGBa> &I, int i, int j, unsigned int radius, const vpColor &color,
170  bool fill, unsigned int thickness)
171 {
172  vp_display_display_circle(I, i, j, radius, color, fill, thickness);
173 }
174 
183 void vpDisplay::displayCross(const vpImage<vpRGBa> &I, const vpImagePoint &ip, unsigned int size, const vpColor &color,
184  unsigned int thickness)
185 {
186  vp_display_display_cross(I, ip, size, color, thickness);
187 }
188 
197 void vpDisplay::displayCross(const vpImage<vpRGBa> &I, int i, int j, unsigned int size, const vpColor &color,
198  unsigned int thickness)
199 {
200  vp_display_display_cross(I, i, j, size, color, thickness);
201 }
202 
211  const vpColor &color, unsigned int thickness)
212 {
213  vp_display_display_dot_line(I, ip1, ip2, color, thickness);
214 }
215 
224 void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
225  unsigned int thickness)
226 {
227  vp_display_display_dot_line(I, i1, j1, i2, j2, color, thickness);
228 }
229 
239 void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &ips, bool closeTheShape,
240  const vpColor &color, unsigned int thickness)
241 {
242  if (ips.size() <= 1)
243  return;
244 
245  for (size_t i = 0; i < ips.size() - 1; i++)
246  vp_display_display_dot_line(I, ips[i], ips[i + 1], color, thickness);
247 
248  if (closeTheShape)
249  vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
250 }
251 
261 void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
262  const vpColor &color, unsigned int thickness)
263 {
264  if (ips.size() <= 1)
265  return;
266 
267  std::list<vpImagePoint>::const_iterator it = ips.begin();
268 
269  vpImagePoint ip_prev = *(it++);
270  for (; it != ips.end(); ++it) {
271  if (vpImagePoint::distance(ip_prev, *it) > 1) {
272  vp_display_display_dot_line(I, ip_prev, *it, color, thickness);
273  ip_prev = *it;
274  }
275  }
276 
277  if (closeTheShape) {
278  vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
279  }
280 }
281 
332 void vpDisplay::displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &coef1,
333  const double &coef2, const double &coef3, bool use_centered_moments,
334  const vpColor &color, unsigned int thickness)
335 {
336  vpDisplay::displayEllipse(I, center, coef1, coef2, coef3, 0., vpMath::rad(360), use_centered_moments, color,
337  thickness);
338 }
339 
396 void vpDisplay::displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &coef1,
397  const double &coef2, const double &coef3, const double &theta1, const double &theta2,
398  bool use_centered_moments, const vpColor &color, unsigned int thickness)
399 {
400  vp_display_display_ellipse(I, center, coef1, coef2, coef3, theta1, theta2, use_centered_moments, color, thickness);
401 }
402 
419  double size, const vpColor &color, unsigned int thickness, const vpImagePoint &offset)
420 {
421  vp_display_display_frame(I, cMo, cam, size, color, thickness, offset);
422 }
423 
433 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
434  const vpColor &color, unsigned int thickness, bool segment)
435 {
436  displayLine(I, static_cast<int>(ip1.get_i()), static_cast<int>(ip1.get_j()), static_cast<int>(ip2.get_i()), static_cast<int>(ip2.get_j()), color, thickness, segment);
437 }
438 
449 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
450  unsigned int thickness, bool segment)
451 {
452  if (segment) {
453  vp_display_display_line(I, i1, j1, i2, j2, color, thickness);
454  }
455  else {
456  // line equation in image: i = a * j + b
457  double delta_j = static_cast<double>(j2) - static_cast<double>(j1);
458  double delta_i = static_cast<double>(i2) - static_cast<double>(i1);
459  // Test if horizontal line
460  if (std::fabs(delta_i) <= std::numeric_limits<double>::epsilon()) {
461  vp_display_display_line(I, i1, 0, i1, (I.getWidth()-1), color, thickness);
462  }
463  // Test if vertical line
464  else if (std::fabs(delta_j) <= std::numeric_limits<double>::epsilon()) {
465  vp_display_display_line(I, 0, j1, (I.getHeight()-1), j1, color, thickness);
466  }
467  else {
468  double a = delta_i / delta_j;
469  double b = static_cast<double>(i1) - a * static_cast<double>(j1);
470  std::vector<vpImagePoint> vip; // Image points that intersect image borders
471  // Test intersection with vertical line j=0
472  vpImagePoint ip_left(b, 0);
473  if (ip_left.get_i() >= 0. && ip_left.get_i() <= (I.getHeight()-1.)) {
474  vip.push_back(ip_left);
475  }
476  // Test intersection with vertical line j=width-1
477  vpImagePoint ip_right(a*(I.getWidth()-1)+b, I.getWidth()-1.);
478  if (ip_right.get_i() >= 0. && ip_right.get_i() <= (I.getHeight()-1.)) {
479  vip.push_back(ip_right);
480  }
481  if (vip.size() == 2) {
482  vp_display_display_line(I, vip[0], vip[1], color, thickness);
483  return;
484  }
485  // Test intersection with horizontal line i=0
486  vpImagePoint ip_top(0, -b/a);
487  if (ip_top.get_j() >= 0. && ip_top.get_j() <= (I.getWidth()-1.)) {
488  vip.push_back(ip_top);
489  }
490  if (vip.size() == 2) {
491  vp_display_display_line(I, vip[0], vip[1], color, thickness);
492  return;
493  }
494  // Test intersection with horizontal line i=height-1
495  vpImagePoint ip_bottom(I.getHeight()-1., (I.getHeight()-1. - b)/a);
496  if (ip_bottom.get_j() >= 0. && ip_bottom.get_j() <= (I.getWidth()-1.)) {
497  vip.push_back(ip_bottom);
498  }
499  if (vip.size() == 2) {
500  vp_display_display_line(I, vip[0], vip[1], color, thickness);
501  return;
502  }
503  }
504  }
505 }
506 
516 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &ips, bool closeTheShape,
517  const vpColor &color, unsigned int thickness)
518 {
519  if (ips.size() <= 1)
520  return;
521 
522  for (size_t i = 0; i < ips.size() - 1; i++)
523  vp_display_display_line(I, ips[i], ips[i + 1], color, thickness);
524 
525  if (closeTheShape)
526  vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
527 }
528 
538 void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
539  const vpColor &color, unsigned int thickness)
540 {
541  if (ips.size() <= 1)
542  return;
543 
544  std::list<vpImagePoint>::const_iterator it = ips.begin();
545 
546  vpImagePoint ip_prev = *(it++);
547  for (; it != ips.end(); ++it) {
548  if (vpImagePoint::distance(ip_prev, *it) > 1) {
549  vp_display_display_line(I, ip_prev, *it, color, thickness);
550  ip_prev = *it;
551  }
552  }
553 
554  if (closeTheShape) {
555  vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
556  }
557 }
558 
566 void vpDisplay::displayPoint(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const vpColor &color,
567  unsigned int thickness)
568 {
569  vp_display_display_point(I, ip, color, thickness);
570 }
571 
579 void vpDisplay::displayPoint(const vpImage<vpRGBa> &I, int i, int j, const vpColor &color, unsigned int thickness)
580 {
581  vp_display_display_point(I, i, j, color, thickness);
582 }
583 
592 void vpDisplay::displayPolygon(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &vip, const vpColor &color,
593  unsigned int thickness, bool closed)
594 {
595  vp_display_display_polygon(I, vip, color, thickness, closed);
596 }
597 
614 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &topLeft, unsigned int width,
615  unsigned int height, const vpColor &color, bool fill, unsigned int thickness)
616 {
617  vp_display_display_rectangle(I, topLeft, width, height, color, fill, thickness);
618 }
619 
634 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, int i, int j, unsigned int width, unsigned int height,
635  const vpColor &color, bool fill, unsigned int thickness)
636 {
637  vp_display_display_rectangle(I, i, j, width, height, color, fill, thickness);
638 }
639 
655 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpRect &rectangle, const vpColor &color, bool fill,
656  unsigned int thickness)
657 {
658  vp_display_display_rectangle(I, rectangle, color, fill, thickness);
659 }
660 
674 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &center, float angle, unsigned int width,
675  unsigned int height, const vpColor &color, unsigned int thickness)
676 {
677  vp_display_display_rectangle(I, center, angle, width, height, color, thickness);
678 }
679 
696 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &topLeft, const vpImagePoint &bottomRight,
697  const vpColor &color, bool fill, unsigned int thickness)
698 {
699  vp_display_display_rectangle(I, topLeft, bottomRight, color, fill, thickness);
700 }
701 
715 void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, unsigned int i, unsigned int j, float angle,
716  unsigned int width, unsigned int height, const vpColor &color, unsigned int thickness)
717 {
718  vp_display_display_rectangle(I, i, j, angle, width, height, color, thickness);
719 }
720 
733 void vpDisplay::displayText(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const std::string &s,
734  const vpColor &color)
735 {
736  vp_display_display_text(I, ip, s, color);
737 }
738 
751 void vpDisplay::displayText(const vpImage<vpRGBa> &I, int i, int j, const std::string &s, const vpColor &color)
752 {
753  vp_display_display_text(I, i, j, s, color);
754 }
755 
785 void vpDisplay::flush(const vpImage<vpRGBa> &I) { vp_display_flush(I); }
786 
796 void vpDisplay::flushROI(const vpImage<vpRGBa> &I, const vpRect &roi) { vp_display_flush_roi(I, roi); }
797 
809 void vpDisplay::display(const vpImage<vpRGBa> &I) { vp_display_display(I); }
810 
815 void vpDisplay::displayROI(const vpImage<vpRGBa> &I, const vpRect &roi) { vp_display_display_roi(I, roi); }
816 
834 bool vpDisplay::getClick(const vpImage<vpRGBa> &I, bool blocking) { return vp_display_get_click(I, blocking); }
835 
854 bool vpDisplay::getClick(const vpImage<vpRGBa> &I, vpImagePoint &ip, bool blocking)
855 {
856  return vp_display_get_click(I, ip, blocking);
857 }
858 
880  bool blocking)
881 {
882  return vp_display_get_click(I, ip, button, blocking);
883 }
884 
902 {
903  vpImagePoint ip;
904  return vpDisplay::getClick(I, ip, button, blocking);
905 }
906 
928  bool blocking)
929 {
930  return vp_display_get_click_up(I, ip, button, blocking);
931 }
932 
950 {
951  vpImagePoint ip;
952  return vpDisplay::getClickUp(I, ip, button, blocking);
953 }
954 
1037 bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, bool blocking)
1038 {
1039  return vp_display_get_keyboard_event(I, blocking);
1040 }
1041 
1128 bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, std::string &key, bool blocking)
1129 {
1130  return vp_display_get_keyboard_event(I, key, blocking);
1131 }
1132 
1219 bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, char *key, bool blocking)
1220 {
1221  return vp_display_get_keyboard_event(I, key, blocking);
1222 }
1223 
1234 {
1235  return vp_display_get_pointer_motion_event(I, ip);
1236 }
1237 
1248 {
1249  return vp_display_get_pointer_position(I, ip);
1250 }
1251 
1261 void vpDisplay::setBackground(const vpImage<vpRGBa> &I, const vpColor &color) { vp_display_set_background(I, color); }
1262 
1276 void vpDisplay::setFont(const vpImage<vpRGBa> &I, const std::string &fontname) { vp_display_set_font(I, fontname); }
1277 
1285 void vpDisplay::setTitle(const vpImage<vpRGBa> &I, const std::string &windowtitle)
1286 {
1287  vp_display_set_title(I, windowtitle);
1288 }
1289 
1300 void vpDisplay::setWindowPosition(const vpImage<vpRGBa> &I, int winx, int winy)
1301 {
1302  vp_display_set_window_position(I, winx, winy);
1303 }
1304 
1314 unsigned int vpDisplay::getDownScalingFactor(const vpImage<vpRGBa> &I) { return vp_display_get_down_scaling_factor(I); }
static void displayCamera(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness)
double get_i() const
Definition: vpImagePoint.h:203
static void displayEllipse(const vpImage< unsigned char > &I, const vpImagePoint &center, const double &coef1, const double &coef2, const double &coef3, bool use_centered_moments, const vpColor &color, unsigned int thickness=1)
static bool getPointerPosition(const vpImage< unsigned char > &I, vpImagePoint &ip)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void close(vpImage< unsigned char > &I)
static bool getPointerMotionEvent(const vpImage< unsigned char > &I, vpImagePoint &ip)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:157
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
static bool getClickUp(const vpImage< unsigned char > &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
static void flush(const vpImage< unsigned char > &I)
static void setFont(const vpImage< unsigned char > &I, const std::string &font)
static void displayPolygon(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &vip, const vpColor &color, unsigned int thickness=1, bool closed=true)
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 double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
static void display(const vpImage< unsigned char > &I)
double get_j() const
Definition: vpImagePoint.h:214
Generic class defining intrinsic camera parameters.
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 double rad(double deg)
Definition: vpMath.h:110
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 displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
unsigned int getHeight() const
Definition: vpImage.h:188
static void setWindowPosition(const vpImage< unsigned char > &I, int winx, int winy)
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))
unsigned int getDownScalingFactor()
Definition: vpDisplay.h:235
static void setBackground(const vpImage< unsigned char > &I, const vpColor &color)
Defines a rectangle in the plane.
Definition: vpRect.h:79
static void flushROI(const vpImage< unsigned char > &I, const vpRect &roi)
static void displayROI(const vpImage< unsigned char > &I, const vpRect &roi)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:87
static bool getKeyboardEvent(const vpImage< unsigned char > &I, bool blocking=true)
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)
unsigned int getWidth() const
Definition: vpImage.h:246
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 displayDotLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)