Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpDisplay_rgba.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
48void vpDisplay::close(vpImage<vpRGBa> &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
74void vpDisplay::displayArrow(const vpImage<vpRGBa> &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 double size, const vpColor &color, unsigned int thickness)
95{
96 vp_display_display_camera(I, cMo, cam, size, color, thickness);
97}
98
112void vpDisplay::displayCharString(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const char *string,
113 const vpColor &color)
114{
115 vp_display_display_char_string(I, ip, string, color);
116}
117
131void vpDisplay::displayCharString(const vpImage<vpRGBa> &I, int i, int j, const char *string, const vpColor &color)
132{
133 vp_display_display_char_string(I, i, j, string, color);
134}
135
148 const vpColor &color, bool fill, unsigned int thickness)
149{
150 vp_display_display_circle(I, circle.getCenter(), static_cast<unsigned int>(circle.getRadius()), color, fill, thickness);
151}
152
165void vpDisplay::displayCircle(const vpImage<vpRGBa> &I, const vpImagePoint &center, unsigned int radius,
166 const vpColor &color, bool fill, unsigned int thickness)
167{
168 vp_display_display_circle(I, center, radius, color, fill, thickness);
169}
170
183void vpDisplay::displayCircle(const vpImage<vpRGBa> &I, int i, int j, unsigned int radius, const vpColor &color,
184 bool fill, unsigned int thickness)
185{
186 vp_display_display_circle(I, i, j, radius, color, fill, thickness);
187}
188
197void vpDisplay::displayCross(const vpImage<vpRGBa> &I, const vpImagePoint &ip, unsigned int size, const vpColor &color,
198 unsigned int thickness)
199{
200 vp_display_display_cross(I, ip, size, color, thickness);
201}
202
211void vpDisplay::displayCross(const vpImage<vpRGBa> &I, int i, int j, unsigned int size, const vpColor &color,
212 unsigned int thickness)
213{
214 vp_display_display_cross(I, i, j, size, color, thickness);
215}
216
225 const vpColor &color, unsigned int thickness)
226{
227 vp_display_display_dot_line(I, ip1, ip2, color, thickness);
228}
229
238void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
239 unsigned int thickness)
240{
241 vp_display_display_dot_line(I, i1, j1, i2, j2, color, thickness);
242}
243
253void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &ips, bool closeTheShape,
254 const vpColor &color, unsigned int thickness)
255{
256 if (ips.size() <= 1)
257 return;
258
259 for (size_t i = 0; i < ips.size() - 1; i++)
260 vp_display_display_dot_line(I, ips[i], ips[i + 1], color, thickness);
261
262 if (closeTheShape)
263 vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
264}
265
275void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
276 const vpColor &color, unsigned int thickness)
277{
278 if (ips.size() <= 1)
279 return;
280
281 std::list<vpImagePoint>::const_iterator it = ips.begin();
282
283 vpImagePoint ip_prev = *(it++);
284 for (; it != ips.end(); ++it) {
285 if (vpImagePoint::distance(ip_prev, *it) > 1) {
286 vp_display_display_dot_line(I, ip_prev, *it, color, thickness);
287 ip_prev = *it;
288 }
289 }
290
291 if (closeTheShape) {
292 vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
293 }
294}
295
332void vpDisplay::displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &coef1,
333 const double &coef2, const double &coef3, bool use_normalized_centered_moments,
334 const vpColor &color, unsigned int thickness, bool display_center, bool display_arc)
335{
336 vpDisplay::displayEllipse(I, center, coef1, coef2, coef3, 0., 2 * M_PI, use_normalized_centered_moments, color,
337 thickness, display_center, display_arc);
338}
339
379void vpDisplay::displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &coef1,
380 const double &coef2, const double &coef3, const double &smallalpha,
381 const double &highalpha, bool use_normalized_centered_moments, const vpColor &color,
382 unsigned int thickness, bool display_center, bool display_arc)
383{
384 vp_display_display_ellipse(I, center, coef1, coef2, coef3, smallalpha, highalpha, use_normalized_centered_moments,
385 color, thickness, display_center, display_arc);
386}
387
406 double size, const vpColor &color, unsigned int thickness, const vpImagePoint &offset,
407 const std::string &frameName, const vpColor &textColor, const vpImagePoint &textOffset)
408{
409 vp_display_display_frame(I, cMo, cam, size, color, thickness, offset, frameName, textColor, textOffset);
410}
411
422 const vpColor &color, unsigned int thickness, bool segment)
423{
424 displayLine(I, static_cast<int>(ip1.get_i()), static_cast<int>(ip1.get_j()), static_cast<int>(ip2.get_i()),
425 static_cast<int>(ip2.get_j()), color, thickness, segment);
426}
427
438void vpDisplay::displayLine(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
439 unsigned int thickness, bool segment)
440{
441 if (segment) {
442 vp_display_display_line(I, i1, j1, i2, j2, color, thickness);
443 }
444 else {
445 // line equation in image: i = a * j + b
446 double delta_j = static_cast<double>(j2) - static_cast<double>(j1);
447 double delta_i = static_cast<double>(i2) - static_cast<double>(i1);
448 // Test if horizontal line
449 if (std::fabs(delta_i) <= std::numeric_limits<double>::epsilon()) {
450 vp_display_display_line(I, i1, 0, i1, (I.getWidth() - 1), color, thickness);
451 }
452 // Test if vertical line
453 else if (std::fabs(delta_j) <= std::numeric_limits<double>::epsilon()) {
454 vp_display_display_line(I, 0, j1, (I.getHeight() - 1), j1, color, thickness);
455 }
456 else {
457 double a = delta_i / delta_j;
458 double b = static_cast<double>(i1) - a * static_cast<double>(j1);
459 std::vector<vpImagePoint> vip; // Image points that intersect image borders
460 // Test intersection with vertical line j=0
461 vpImagePoint ip_left(b, 0);
462 if (ip_left.get_i() >= 0. && ip_left.get_i() <= (I.getHeight() - 1.)) {
463 vip.push_back(ip_left);
464 }
465 // Test intersection with vertical line j=width-1
466 vpImagePoint ip_right(a * (I.getWidth() - 1) + b, I.getWidth() - 1.);
467 if (ip_right.get_i() >= 0. && ip_right.get_i() <= (I.getHeight() - 1.)) {
468 vip.push_back(ip_right);
469 }
470 if (vip.size() == 2) {
471 vp_display_display_line(I, vip[0], vip[1], color, thickness);
472 return;
473 }
474 // Test intersection with horizontal line i=0
475 vpImagePoint ip_top(0, -b / a);
476 if (ip_top.get_j() >= 0. && ip_top.get_j() <= (I.getWidth() - 1.)) {
477 vip.push_back(ip_top);
478 }
479 if (vip.size() == 2) {
480 vp_display_display_line(I, vip[0], vip[1], color, thickness);
481 return;
482 }
483 // Test intersection with horizontal line i=height-1
484 vpImagePoint ip_bottom(I.getHeight() - 1., (I.getHeight() - 1. - b) / a);
485 if (ip_bottom.get_j() >= 0. && ip_bottom.get_j() <= (I.getWidth() - 1.)) {
486 vip.push_back(ip_bottom);
487 }
488 if (vip.size() == 2) {
489 vp_display_display_line(I, vip[0], vip[1], color, thickness);
490 return;
491 }
492 }
493 }
494}
495
505void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &ips, bool closeTheShape,
506 const vpColor &color, unsigned int thickness)
507{
508 if (ips.size() <= 1)
509 return;
510
511 for (size_t i = 0; i < ips.size() - 1; i++)
512 vp_display_display_line(I, ips[i], ips[i + 1], color, thickness);
513
514 if (closeTheShape)
515 vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
516}
517
527void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
528 const vpColor &color, unsigned int thickness)
529{
530 if (ips.size() <= 1)
531 return;
532
533 std::list<vpImagePoint>::const_iterator it = ips.begin();
534
535 vpImagePoint ip_prev = *(it++);
536 for (; it != ips.end(); ++it) {
537 if (vpImagePoint::distance(ip_prev, *it) > 1) {
538 vp_display_display_line(I, ip_prev, *it, color, thickness);
539 ip_prev = *it;
540 }
541 }
542
543 if (closeTheShape) {
544 vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
545 }
546}
547
555void vpDisplay::displayPoint(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const vpColor &color,
556 unsigned int thickness)
557{
558 vp_display_display_point(I, ip, color, thickness);
559}
560
568void vpDisplay::displayPoint(const vpImage<vpRGBa> &I, int i, int j, const vpColor &color, unsigned int thickness)
569{
570 vp_display_display_point(I, i, j, color, thickness);
571}
572
581void vpDisplay::displayPolygon(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &vip, const vpColor &color,
582 unsigned int thickness, bool closed)
583{
584 vp_display_display_polygon(I, vip, color, thickness, closed);
585}
586
603void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &topLeft, unsigned int width,
604 unsigned int height, const vpColor &color, bool fill, unsigned int thickness)
605{
606 vp_display_display_rectangle(I, topLeft, width, height, color, fill, thickness);
607}
608
623void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, int i, int j, unsigned int width, unsigned int height,
624 const vpColor &color, bool fill, unsigned int thickness)
625{
626 vp_display_display_rectangle(I, i, j, width, height, color, fill, thickness);
627}
628
644void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpRect &rectangle, const vpColor &color, bool fill,
645 unsigned int thickness)
646{
647 vp_display_display_rectangle(I, rectangle, color, fill, thickness);
648}
649
663void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &center, float angle, unsigned int width,
664 unsigned int height, const vpColor &color, unsigned int thickness)
665{
666 vp_display_display_rectangle(I, center, angle, width, height, color, thickness);
667}
668
685void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &topLeft, const vpImagePoint &bottomRight,
686 const vpColor &color, bool fill, unsigned int thickness)
687{
688 vp_display_display_rectangle(I, topLeft, bottomRight, color, fill, thickness);
689}
690
704void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, unsigned int i, unsigned int j, float angle,
705 unsigned int width, unsigned int height, const vpColor &color, unsigned int thickness)
706{
707 vp_display_display_rectangle(I, i, j, angle, width, height, color, thickness);
708}
709
722void vpDisplay::displayText(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const std::string &s,
723 const vpColor &color)
724{
725 vp_display_display_text(I, ip, s, color);
726}
727
740void vpDisplay::displayText(const vpImage<vpRGBa> &I, int i, int j, const std::string &s, const vpColor &color)
741{
742 vp_display_display_text(I, i, j, s, color);
743}
744
774void vpDisplay::flush(const vpImage<vpRGBa> &I) { vp_display_flush(I); }
775
785void vpDisplay::flushROI(const vpImage<vpRGBa> &I, const vpRect &roi) { vp_display_flush_roi(I, roi); }
786
798void vpDisplay::display(const vpImage<vpRGBa> &I) { vp_display_display(I); }
799
804void vpDisplay::displayROI(const vpImage<vpRGBa> &I, const vpRect &roi) { vp_display_display_roi(I, roi); }
805
823bool vpDisplay::getClick(const vpImage<vpRGBa> &I, bool blocking) { return vp_display_get_click(I, blocking); }
824
843bool vpDisplay::getClick(const vpImage<vpRGBa> &I, vpImagePoint &ip, bool blocking)
844{
845 return vp_display_get_click(I, ip, blocking);
846}
847
869 bool blocking)
870{
871 return vp_display_get_click(I, ip, button, blocking);
872}
873
891{
892 vpImagePoint ip;
893 return vpDisplay::getClick(I, ip, button, blocking);
894}
895
917 bool blocking)
918{
919 return vp_display_get_click_up(I, ip, button, blocking);
920}
921
939{
940 vpImagePoint ip;
941 return vpDisplay::getClickUp(I, ip, button, blocking);
942}
943
1027{
1028 return vp_display_get_keyboard_event(I, blocking);
1029}
1030
1117bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, std::string &key, bool blocking)
1118{
1119 return vp_display_get_keyboard_event(I, key, blocking);
1120}
1121
1208bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, char *key, bool blocking)
1209{
1210 return vp_display_get_keyboard_event(I, key, blocking);
1211}
1212
1223{
1224 return vp_display_get_pointer_motion_event(I, ip);
1225}
1226
1237{
1238 return vp_display_get_pointer_position(I, ip);
1239}
1240
1250void vpDisplay::setBackground(const vpImage<vpRGBa> &I, const vpColor &color) { vp_display_set_background(I, color); }
1251
1265void vpDisplay::setFont(const vpImage<vpRGBa> &I, const std::string &fontname) { vp_display_set_font(I, fontname); }
1266
1274void vpDisplay::setTitle(const vpImage<vpRGBa> &I, const std::string &windowtitle)
1275{
1276 vp_display_set_title(I, windowtitle);
1277}
1278
1289void vpDisplay::setWindowPosition(const vpImage<vpRGBa> &I, int winx, int winy)
1290{
1291 vp_display_set_window_position(I, winx, winy);
1292}
1293
1301unsigned int vpDisplay::getDownScalingFactor(const vpImage<vpRGBa> &I) { return vp_display_get_down_scaling_factor(I); }
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 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.
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 ...
double get_j() const
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
double get_i() const
Definition of the vpImage class member functions.
Definition vpImage.h:135
unsigned int getWidth() const
Definition vpImage.h:242
unsigned int getHeight() const
Definition vpImage.h:184
Defines a rectangle in the plane.
Definition vpRect.h:76