Visual Servoing Platform  version 3.2.1 under development (2019-12-06)
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 
150 void vpDisplay::displayCircle(const vpImage<unsigned char> &I, const vpImagePoint &center, unsigned int radius,
151  const vpColor &color, bool fill, unsigned int thickness)
152 {
153  vp_display_display_circle(I, center, radius, color, fill, thickness);
154 }
155 
166 void vpDisplay::displayCircle(const vpImage<unsigned char> &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<unsigned char> &I, const vpImagePoint &ip, unsigned int size,
181  const vpColor &color, unsigned int thickness)
182 {
183  vp_display_display_cross(I, ip, size, color, thickness);
184 }
185 
194 void vpDisplay::displayCross(const vpImage<unsigned char> &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<unsigned char> &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 
235 void vpDisplay::displayDotLine(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &ips,
236  const bool closeTheShape, const vpColor &color, unsigned int thickness)
237 {
238  if (ips.size() <= 1)
239  return;
240 
241  for (size_t i = 0; i < ips.size() - 1; i++)
242  vp_display_display_dot_line(I, ips[i], ips[i + 1], color, thickness);
243 
244  if (closeTheShape)
245  vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
246 }
247 
296 void vpDisplay::displayEllipse(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &coef1,
297  const double &coef2, const double &coef3, bool use_centered_moments,
298  const vpColor &color, unsigned int thickness)
299 {
300  vpDisplay::displayEllipse(I, center, coef1, coef2, coef3, 0., vpMath::rad(360), use_centered_moments, color,
301  thickness);
302 }
303 
356 void vpDisplay::displayEllipse(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &coef1,
357  const double &coef2, const double &coef3, const double &theta1, const double &theta2,
358  bool use_centered_moments, const vpColor &color, unsigned int thickness)
359 {
360  vp_display_display_ellipse(I, center, coef1, coef2, coef3, theta1, theta2, use_centered_moments, color, thickness);
361 }
362 
379  const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness,
380  const vpImagePoint &offset)
381 {
382  vp_display_display_frame(I, cMo, cam, size, color, thickness, offset);
383 }
384 
395  const vpColor &color, unsigned int thickness, bool segment)
396 {
397  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);
398 }
399 
410 void vpDisplay::displayLine(const vpImage<unsigned char> &I, int i1, int j1, int i2, int j2, const vpColor &color,
411  unsigned int thickness, bool segment)
412 {
413  if (segment) {
414  vp_display_display_line(I, i1, j1, i2, j2, color, thickness);
415  }
416  else {
417  // line equation in image: i = a * j + b
418  double delta_j = static_cast<double>(j2) - static_cast<double>(j1);
419  double delta_i = static_cast<double>(i2) - static_cast<double>(i1);
420  // Test if horizontal line
421  if (std::fabs(delta_i) <= std::numeric_limits<double>::epsilon()) {
422  vp_display_display_line(I, i1, 0, i1, (I.getWidth()-1), color, thickness);
423  }
424  // Test if vertical line
425  else if (std::fabs(delta_j) <= std::numeric_limits<double>::epsilon()) {
426  vp_display_display_line(I, 0, j1, (I.getHeight()-1), j1, color, thickness);
427  }
428  else {
429  double a = delta_i / delta_j;
430  double b = static_cast<double>(i1) - a * static_cast<double>(j1);
431  std::vector<vpImagePoint> vip; // Image points that intersect image borders
432  // Test intersection with vertical line j=0
433  vpImagePoint ip_left(b, 0);
434  if (ip_left.get_i() >= 0. && ip_left.get_i() <= (I.getHeight()-1.)) {
435  vip.push_back(ip_left);
436  }
437  // Test intersection with vertical line j=width-1
438  vpImagePoint ip_right(a*(I.getWidth()-1)+b, I.getWidth()-1.);
439  if (ip_right.get_i() >= 0. && ip_right.get_i() <= (I.getHeight()-1.)) {
440  vip.push_back(ip_right);
441  }
442  if (vip.size() == 2) {
443  vp_display_display_line(I, vip[0], vip[1], color, thickness);
444  return;
445  }
446  // Test intersection with horizontal line i=0
447  vpImagePoint ip_top(0, -b/a);
448  if (ip_top.get_j() >= 0. && ip_top.get_j() <= (I.getWidth()-1.)) {
449  vip.push_back(ip_top);
450  }
451  if (vip.size() == 2) {
452  vp_display_display_line(I, vip[0], vip[1], color, thickness);
453  return;
454  }
455  // Test intersection with horizontal line i=height-1
456  vpImagePoint ip_bottom(I.getHeight()-1., (I.getHeight()-1. - b)/a);
457  if (ip_bottom.get_j() >= 0. && ip_bottom.get_j() <= (I.getWidth()-1.)) {
458  vip.push_back(ip_bottom);
459  }
460  if (vip.size() == 2) {
461  vp_display_display_line(I, vip[0], vip[1], color, thickness);
462  return;
463  }
464  }
465  }
466 }
467 
475 void vpDisplay::displayLine(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &ips,
476  const bool closeTheShape, const vpColor &color, unsigned int thickness)
477 {
478  if (ips.size() <= 1)
479  return;
480 
481  for (size_t i = 0; i < ips.size() - 1; i++)
482  vp_display_display_line(I, ips[i], ips[i + 1], color, thickness);
483 
484  if (closeTheShape)
485  vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
486 }
487 
496  unsigned int thickness)
497 {
498  vp_display_display_point(I, ip, color, thickness);
499 }
500 
508 void vpDisplay::displayPoint(const vpImage<unsigned char> &I, int i, int j, const vpColor &color,
509  unsigned int thickness)
510 {
511  vp_display_display_point(I, i, j, color, thickness);
512 }
513 
521 void vpDisplay::displayPolygon(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &vip,
522  const vpColor &color, unsigned int thickness)
523 {
524  vp_display_display_polygon(I, vip, color, thickness);
525 }
526 
541 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, const vpImagePoint &topLeft, unsigned int width,
542  unsigned int height, const vpColor &color, bool fill, unsigned int thickness)
543 {
544  vp_display_display_rectangle(I, topLeft, width, height, color, fill, thickness);
545 }
546 
561 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, int i, int j, unsigned int width, unsigned int height,
562  const vpColor &color, bool fill, unsigned int thickness)
563 {
564  vp_display_display_rectangle(I, i, j, width, height, color, fill, thickness);
565 }
566 
580 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, const vpRect &rectangle, const vpColor &color,
581  bool fill, unsigned int thickness)
582 {
583  vp_display_display_rectangle(I, rectangle, color, fill, thickness);
584 }
585 
599 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, const vpImagePoint &center, float angle,
600  unsigned int width, unsigned int height, const vpColor &color, unsigned int thickness)
601 {
602  vp_display_display_rectangle(I, center, angle, width, height, color, thickness);
603 }
604 
620  const vpImagePoint &bottomRight, const vpColor &color, bool fill,
621  unsigned int thickness)
622 {
623  vp_display_display_rectangle(I, topLeft, bottomRight, color, fill, thickness);
624 }
625 
639 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, unsigned int i, unsigned int j, float angle,
640  unsigned int width, unsigned int height, const vpColor &color, unsigned int thickness)
641 {
642  vp_display_display_rectangle(I, i, j, angle, width, height, color, thickness);
643 }
644 
657 void vpDisplay::displayText(const vpImage<unsigned char> &I, const vpImagePoint &ip, const std::string &s,
658  const vpColor &color)
659 {
660  vp_display_display_text(I, ip, s, color);
661 }
662 
675 void vpDisplay::displayText(const vpImage<unsigned char> &I, int i, int j, const std::string &s, const vpColor &color)
676 {
677  vp_display_display_text(I, i, j, s, color);
678 }
679 
709 void vpDisplay::flush(const vpImage<unsigned char> &I) { vp_display_flush(I); }
710 
720 void vpDisplay::flushROI(const vpImage<unsigned char> &I, const vpRect &roi) { vp_display_flush_roi(I, roi); }
721 
733 void vpDisplay::display(const vpImage<unsigned char> &I) { vp_display_display(I); }
734 
739 void vpDisplay::displayROI(const vpImage<unsigned char> &I, const vpRect &roi) { vp_display_display_roi(I, roi); }
740 
758 bool vpDisplay::getClick(const vpImage<unsigned char> &I, bool blocking) { return vp_display_get_click(I, blocking); }
759 
778 bool vpDisplay::getClick(const vpImage<unsigned char> &I, vpImagePoint &ip, bool blocking)
779 {
780  return vp_display_get_click(I, ip, blocking);
781 }
782 
804  bool blocking)
805 {
806  return vp_display_get_click(I, ip, button, blocking);
807 }
808 
826 {
827  vpImagePoint ip;
828  return vpDisplay::getClick(I, ip, button, blocking);
829 }
830 
852  bool blocking)
853 {
854  return vp_display_get_click_up(I, ip, button, blocking);
855 }
856 
874 {
875  vpImagePoint ip;
876  return vpDisplay::getClickUp(I, ip, button, blocking);
877 }
878 
963 {
964  return vp_display_get_keyboard_event(I, blocking);
965 }
966 
1053 bool vpDisplay::getKeyboardEvent(const vpImage<unsigned char> &I, std::string &key, bool blocking)
1054 {
1055  return vp_display_get_keyboard_event(I, key, blocking);
1056 }
1057 
1144 bool vpDisplay::getKeyboardEvent(const vpImage<unsigned char> &I, char *key, bool blocking)
1145 {
1146  return vp_display_get_keyboard_event(I, key, blocking);
1147 }
1148 
1159 {
1160  return vp_display_get_pointer_motion_event(I, ip);
1161 }
1162 
1173 {
1174  return vp_display_get_pointer_position(I, ip);
1175 }
1176 
1187 {
1188  vp_display_set_background(I, color);
1189 }
1190 
1204 void vpDisplay::setFont(const vpImage<unsigned char> &I, const std::string &fontname)
1205 {
1206  vp_display_set_font(I, fontname);
1207 }
1208 
1216 void vpDisplay::setTitle(const vpImage<unsigned char> &I, const std::string &windowtitle)
1217 {
1218  vp_display_set_title(I, windowtitle);
1219 }
1220 
1231 void vpDisplay::setWindowPosition(const vpImage<unsigned char> &I, int winx, int winy)
1232 {
1233  vp_display_set_window_position(I, winx, winy);
1234 }
1235 
1246 {
1247  return vp_display_get_down_scaling_factor(I);
1248 }
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:204
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.
static void displayPolygon(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &vip, const vpColor &color, unsigned int thickness=1)
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
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 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 display(const vpImage< unsigned char > &I)
double get_j() const
Definition: vpImagePoint.h:215
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:108
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:186
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:229
static void setBackground(const vpImage< unsigned char > &I, const vpColor &color)
Defines a rectangle in the plane.
Definition: vpRect.h:78
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:88
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:244
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)