Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
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 
236 void vpDisplay::displayDotLine(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &ips,
237  bool closeTheShape, const vpColor &color, unsigned int thickness)
238 {
239  if (ips.size() <= 1)
240  return;
241 
242  for (size_t i = 0; i < ips.size() - 1; i++)
243  vp_display_display_dot_line(I, ips[i], ips[i + 1], color, thickness);
244 
245  if (closeTheShape)
246  vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
247 }
248 
299 void vpDisplay::displayEllipse(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &coef1,
300  const double &coef2, const double &coef3, bool use_centered_moments,
301  const vpColor &color, unsigned int thickness)
302 {
303  vpDisplay::displayEllipse(I, center, coef1, coef2, coef3, 0., vpMath::rad(360), use_centered_moments, color,
304  thickness);
305 }
306 
362 void vpDisplay::displayEllipse(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &coef1,
363  const double &coef2, const double &coef3, const double &theta1, const double &theta2,
364  bool use_centered_moments, const vpColor &color, unsigned int thickness)
365 {
366  vp_display_display_ellipse(I, center, coef1, coef2, coef3, theta1, theta2, use_centered_moments, color, thickness);
367 }
368 
385  const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness,
386  const vpImagePoint &offset)
387 {
388  vp_display_display_frame(I, cMo, cam, size, color, thickness, offset);
389 }
390 
401  const vpColor &color, unsigned int thickness, bool segment)
402 {
403  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);
404 }
405 
416 void vpDisplay::displayLine(const vpImage<unsigned char> &I, int i1, int j1, int i2, int j2, const vpColor &color,
417  unsigned int thickness, bool segment)
418 {
419  if (segment) {
420  vp_display_display_line(I, i1, j1, i2, j2, color, thickness);
421  }
422  else {
423  // line equation in image: i = a * j + b
424  double delta_j = static_cast<double>(j2) - static_cast<double>(j1);
425  double delta_i = static_cast<double>(i2) - static_cast<double>(i1);
426  // Test if horizontal line
427  if (std::fabs(delta_i) <= std::numeric_limits<double>::epsilon()) {
428  vp_display_display_line(I, i1, 0, i1, (I.getWidth()-1), color, thickness);
429  }
430  // Test if vertical line
431  else if (std::fabs(delta_j) <= std::numeric_limits<double>::epsilon()) {
432  vp_display_display_line(I, 0, j1, (I.getHeight()-1), j1, color, thickness);
433  }
434  else {
435  double a = delta_i / delta_j;
436  double b = static_cast<double>(i1) - a * static_cast<double>(j1);
437  std::vector<vpImagePoint> vip; // Image points that intersect image borders
438  // Test intersection with vertical line j=0
439  vpImagePoint ip_left(b, 0);
440  if (ip_left.get_i() >= 0. && ip_left.get_i() <= (I.getHeight()-1.)) {
441  vip.push_back(ip_left);
442  }
443  // Test intersection with vertical line j=width-1
444  vpImagePoint ip_right(a*(I.getWidth()-1)+b, I.getWidth()-1.);
445  if (ip_right.get_i() >= 0. && ip_right.get_i() <= (I.getHeight()-1.)) {
446  vip.push_back(ip_right);
447  }
448  if (vip.size() == 2) {
449  vp_display_display_line(I, vip[0], vip[1], color, thickness);
450  return;
451  }
452  // Test intersection with horizontal line i=0
453  vpImagePoint ip_top(0, -b/a);
454  if (ip_top.get_j() >= 0. && ip_top.get_j() <= (I.getWidth()-1.)) {
455  vip.push_back(ip_top);
456  }
457  if (vip.size() == 2) {
458  vp_display_display_line(I, vip[0], vip[1], color, thickness);
459  return;
460  }
461  // Test intersection with horizontal line i=height-1
462  vpImagePoint ip_bottom(I.getHeight()-1., (I.getHeight()-1. - b)/a);
463  if (ip_bottom.get_j() >= 0. && ip_bottom.get_j() <= (I.getWidth()-1.)) {
464  vip.push_back(ip_bottom);
465  }
466  if (vip.size() == 2) {
467  vp_display_display_line(I, vip[0], vip[1], color, thickness);
468  return;
469  }
470  }
471  }
472 }
473 
481 void vpDisplay::displayLine(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &ips,
482  bool closeTheShape, const vpColor &color, unsigned int thickness)
483 {
484  if (ips.size() <= 1)
485  return;
486 
487  for (size_t i = 0; i < ips.size() - 1; i++)
488  vp_display_display_line(I, ips[i], ips[i + 1], color, thickness);
489 
490  if (closeTheShape)
491  vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
492 }
493 
502  unsigned int thickness)
503 {
504  vp_display_display_point(I, ip, color, thickness);
505 }
506 
514 void vpDisplay::displayPoint(const vpImage<unsigned char> &I, int i, int j, const vpColor &color,
515  unsigned int thickness)
516 {
517  vp_display_display_point(I, i, j, color, thickness);
518 }
519 
528 void vpDisplay::displayPolygon(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &vip,
529  const vpColor &color, unsigned int thickness, bool closed)
530 {
531  vp_display_display_polygon(I, vip, color, thickness, closed);
532 }
533 
548 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, const vpImagePoint &topLeft, unsigned int width,
549  unsigned int height, const vpColor &color, bool fill, unsigned int thickness)
550 {
551  vp_display_display_rectangle(I, topLeft, width, height, color, fill, thickness);
552 }
553 
568 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, int i, int j, unsigned int width, unsigned int height,
569  const vpColor &color, bool fill, unsigned int thickness)
570 {
571  vp_display_display_rectangle(I, i, j, width, height, color, fill, thickness);
572 }
573 
587 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, const vpRect &rectangle, const vpColor &color,
588  bool fill, unsigned int thickness)
589 {
590  vp_display_display_rectangle(I, rectangle, color, fill, thickness);
591 }
592 
606 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, const vpImagePoint &center, float angle,
607  unsigned int width, unsigned int height, const vpColor &color, unsigned int thickness)
608 {
609  vp_display_display_rectangle(I, center, angle, width, height, color, thickness);
610 }
611 
627  const vpImagePoint &bottomRight, const vpColor &color, bool fill,
628  unsigned int thickness)
629 {
630  vp_display_display_rectangle(I, topLeft, bottomRight, color, fill, thickness);
631 }
632 
646 void vpDisplay::displayRectangle(const vpImage<unsigned char> &I, unsigned int i, unsigned int j, float angle,
647  unsigned int width, unsigned int height, const vpColor &color, unsigned int thickness)
648 {
649  vp_display_display_rectangle(I, i, j, angle, width, height, color, thickness);
650 }
651 
664 void vpDisplay::displayText(const vpImage<unsigned char> &I, const vpImagePoint &ip, const std::string &s,
665  const vpColor &color)
666 {
667  vp_display_display_text(I, ip, s, color);
668 }
669 
682 void vpDisplay::displayText(const vpImage<unsigned char> &I, int i, int j, const std::string &s, const vpColor &color)
683 {
684  vp_display_display_text(I, i, j, s, color);
685 }
686 
716 void vpDisplay::flush(const vpImage<unsigned char> &I) { vp_display_flush(I); }
717 
727 void vpDisplay::flushROI(const vpImage<unsigned char> &I, const vpRect &roi) { vp_display_flush_roi(I, roi); }
728 
740 void vpDisplay::display(const vpImage<unsigned char> &I) { vp_display_display(I); }
741 
746 void vpDisplay::displayROI(const vpImage<unsigned char> &I, const vpRect &roi) { vp_display_display_roi(I, roi); }
747 
765 bool vpDisplay::getClick(const vpImage<unsigned char> &I, bool blocking) { return vp_display_get_click(I, blocking); }
766 
785 bool vpDisplay::getClick(const vpImage<unsigned char> &I, vpImagePoint &ip, bool blocking)
786 {
787  return vp_display_get_click(I, ip, blocking);
788 }
789 
811  bool blocking)
812 {
813  return vp_display_get_click(I, ip, button, blocking);
814 }
815 
833 {
834  vpImagePoint ip;
835  return vpDisplay::getClick(I, ip, button, blocking);
836 }
837 
859  bool blocking)
860 {
861  return vp_display_get_click_up(I, ip, button, blocking);
862 }
863 
881 {
882  vpImagePoint ip;
883  return vpDisplay::getClickUp(I, ip, button, blocking);
884 }
885 
970 {
971  return vp_display_get_keyboard_event(I, blocking);
972 }
973 
1060 bool vpDisplay::getKeyboardEvent(const vpImage<unsigned char> &I, std::string &key, bool blocking)
1061 {
1062  return vp_display_get_keyboard_event(I, key, blocking);
1063 }
1064 
1151 bool vpDisplay::getKeyboardEvent(const vpImage<unsigned char> &I, char *key, bool blocking)
1152 {
1153  return vp_display_get_keyboard_event(I, key, blocking);
1154 }
1155 
1166 {
1167  return vp_display_get_pointer_motion_event(I, ip);
1168 }
1169 
1180 {
1181  return vp_display_get_pointer_position(I, ip);
1182 }
1183 
1194 {
1195  vp_display_set_background(I, color);
1196 }
1197 
1211 void vpDisplay::setFont(const vpImage<unsigned char> &I, const std::string &fontname)
1212 {
1213  vp_display_set_font(I, fontname);
1214 }
1215 
1223 void vpDisplay::setTitle(const vpImage<unsigned char> &I, const std::string &windowtitle)
1224 {
1225  vp_display_set_title(I, windowtitle);
1226 }
1227 
1238 void vpDisplay::setWindowPosition(const vpImage<unsigned char> &I, int winx, int winy)
1239 {
1240  vp_display_set_window_position(I, winx, winy);
1241 }
1242 
1253 {
1254  return vp_display_get_down_scaling_factor(I);
1255 }
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.
Class to define colors available for display functionnalities.
Definition: vpColor.h:119
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 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)