Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpDisplay_rgba.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Display implementation.
32 */
33
34#include <visp3/core/vpDisplay.h>
35
36#include "vpDisplay_impl.h"
37
38//************************************************************************
39// Modifications done in this file should be reported in all vpDisplay_*.cpp
40// files that implement other types (unsigned char, vpRGB, vpRGBa)
41//************************************************************************
46void vpDisplay::close(vpImage<vpRGBa> &I) { vp_display_close(I); }
47
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
77void 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
102#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
116void vpDisplay::displayCharString(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const char *string,
117 const vpColor &color)
118{
119 vp_display_display_text(I, ip, string, color);
120}
121
136void vpDisplay::displayCharString(const vpImage<vpRGBa> &I, int i, int j, const char *string, const vpColor &color)
137{
138 vp_display_display_text(I, i, j, string, color);
139}
140#endif
141
154 const vpColor &color, bool fill, unsigned int thickness)
155{
156 vp_display_display_circle(I, circle.getCenter(), static_cast<unsigned int>(circle.getRadius()), color, fill, thickness);
157}
158
171void vpDisplay::displayCircle(const vpImage<vpRGBa> &I, const vpImagePoint &center, unsigned int radius,
172 const vpColor &color, bool fill, unsigned int thickness)
173{
174 vp_display_display_circle(I, center, radius, color, fill, thickness);
175}
176
190void vpDisplay::displayCircle(const vpImage<vpRGBa> &I, int i, int j, unsigned int radius, const vpColor &color,
191 bool fill, unsigned int thickness)
192{
193 vp_display_display_circle(I, i, j, radius, color, fill, thickness);
194}
195
204void vpDisplay::displayCross(const vpImage<vpRGBa> &I, const vpImagePoint &ip, unsigned int size, const vpColor &color,
205 unsigned int thickness)
206{
207 vp_display_display_cross(I, ip, size, color, thickness);
208}
209
219void vpDisplay::displayCross(const vpImage<vpRGBa> &I, int i, int j, unsigned int size, const vpColor &color,
220 unsigned int thickness)
221{
222 vp_display_display_cross(I, i, j, size, color, thickness);
223}
224
234 const vpColor &color, unsigned int thickness)
235{
236 vp_display_display_dot_line(I, ip1, ip2, color, thickness);
237}
238
249void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
250 unsigned int thickness)
251{
252 vp_display_display_dot_line(I, i1, j1, i2, j2, color, thickness);
253}
254
264void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &ips, bool closeTheShape,
265 const vpColor &color, unsigned int thickness)
266{
267 if (ips.size() <= 1) {
268 return;
269 }
270 size_t ips_size = ips.size();
271 for (size_t i = 0; i < (ips_size - 1); ++i) {
272 vp_display_display_dot_line(I, ips[i], ips[i + 1], color, thickness);
273 }
274
275 if (closeTheShape) {
276 vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
277 }
278}
279
289void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
290 const vpColor &color, unsigned int thickness)
291{
292 if (ips.size() <= 1) {
293 return;
294 }
295
296 std::list<vpImagePoint>::const_iterator it = ips.begin();
297
298 vpImagePoint ip_prev = *(++it);
299 std::list<vpImagePoint>::const_iterator ips_end = ips.end();
300 for (; it != ips_end; ++it) {
301 if (vpImagePoint::distance(ip_prev, *it) > 1) {
302 vp_display_display_dot_line(I, ip_prev, *it, color, thickness);
303 ip_prev = *it;
304 }
305 }
306
307 if (closeTheShape) {
308 vp_display_display_dot_line(I, ips.front(), ips.back(), color, thickness);
309 }
310}
311
357void vpDisplay::displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &coef1,
358 const double &coef2, const double &coef3, bool use_normalized_centered_moments,
359 const vpColor &color, unsigned int thickness, bool display_center, bool display_arc)
360{
361 vpDisplay::displayEllipse(I, center, coef1, coef2, coef3, 0., 2 * M_PI, use_normalized_centered_moments, color,
362 thickness, display_center, display_arc);
363}
364
413void vpDisplay::displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &coef1,
414 const double &coef2, const double &coef3, const double &smallalpha,
415 const double &highalpha, bool use_normalized_centered_moments, const vpColor &color,
416 unsigned int thickness, bool display_center, bool display_arc)
417{
418 vp_display_display_ellipse(I, center, coef1, coef2, coef3, smallalpha, highalpha, use_normalized_centered_moments,
419 color, thickness, display_center, display_arc);
420}
421
439 double size, const vpColor &color, unsigned int thickness, const vpImagePoint &offset,
440 const std::string &frameName, const vpColor &textColor, const vpImagePoint &textOffset)
441{
442 vp_display_display_frame(I, cMo, cam, size, color, thickness, offset, frameName, textColor, textOffset);
443}
444
456 const vpColor &color, unsigned int thickness, bool segment)
457{
458 displayLine(I, static_cast<int>(ip1.get_i()), static_cast<int>(ip1.get_j()), static_cast<int>(ip2.get_i()),
459 static_cast<int>(ip2.get_j()), color, thickness, segment);
460}
461
474void vpDisplay::displayLine(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
475 unsigned int thickness, bool segment)
476{
477 if (segment) {
478 vp_display_display_line(I, i1, j1, i2, j2, color, thickness);
479 }
480 else {
481 // line equation in image: i = a * j + b
482 double delta_j = static_cast<double>(j2) - static_cast<double>(j1);
483 double delta_i = static_cast<double>(i2) - static_cast<double>(i1);
484 int w = static_cast<int>(I.getWidth());
485 int h = static_cast<int>(I.getHeight());
486 // Test if horizontal line
487 if (std::fabs(delta_i) <= std::numeric_limits<double>::epsilon()) {
488 vp_display_display_line(I, i1, 0, i1, (w - 1), color, thickness);
489 }
490 // Test if vertical line
491 else if (std::fabs(delta_j) <= std::numeric_limits<double>::epsilon()) {
492 vp_display_display_line(I, 0, j1, (h - 1), j1, color, thickness);
493 }
494 else {
495 double a = delta_i / delta_j;
496 double b = static_cast<double>(i1) - (a * static_cast<double>(j1));
497 std::vector<vpImagePoint> vip; // Image points that intersect image borders
498 // Test intersection with vertical line j=0
499 vpImagePoint ip_left(b, 0);
500 if ((ip_left.get_i() >= 0.) && (ip_left.get_i() <= (h - 1.))) {
501 vip.push_back(ip_left);
502 }
503 // Test intersection with vertical line j=width-1
504 vpImagePoint ip_right((a * (w - 1)) + b, w - 1.);
505 if ((ip_right.get_i() >= 0.) && (ip_right.get_i() <= (h - 1.))) {
506 vip.push_back(ip_right);
507 }
508 if (vip.size() == 2) {
509 vp_display_display_line(I, vip[0], vip[1], color, thickness);
510 return;
511 }
512 // Test intersection with horizontal line i=0
513 vpImagePoint ip_top(0, -b / a);
514 if ((ip_top.get_j() >= 0.) && (ip_top.get_j() <= (w - 1.))) {
515 vip.push_back(ip_top);
516 }
517 if (vip.size() == 2) {
518 vp_display_display_line(I, vip[0], vip[1], color, thickness);
519 return;
520 }
521 // Test intersection with horizontal line i=height-1
522 vpImagePoint ip_bottom(h - 1., (h - 1. - b) / a);
523 if ((ip_bottom.get_j() >= 0.) && (ip_bottom.get_j() <= (w - 1.))) {
524 vip.push_back(ip_bottom);
525 }
526 if (vip.size() == 2) {
527 vp_display_display_line(I, vip[0], vip[1], color, thickness);
528 return;
529 }
530 }
531 }
532}
533
543void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &ips, bool closeTheShape,
544 const vpColor &color, unsigned int thickness)
545{
546 if (ips.size() <= 1) {
547 return;
548 }
549
550 size_t ips_size = ips.size();
551 for (size_t i = 0; i < (ips_size - 1); ++i) {
552 vp_display_display_line(I, ips[i], ips[i + 1], color, thickness);
553 }
554
555 if (closeTheShape) {
556 vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
557 }
558}
559
569void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const std::list<vpImagePoint> &ips, bool closeTheShape,
570 const vpColor &color, unsigned int thickness)
571{
572 if (ips.size() <= 1) {
573 return;
574 }
575
576 std::list<vpImagePoint>::const_iterator it = ips.begin();
577
578 vpImagePoint ip_prev = *(++it);
579 std::list<vpImagePoint>::const_iterator ips_end = ips.end();
580 for (; it != ips_end; ++it) {
581 if (vpImagePoint::distance(ip_prev, *it) > 1) {
582 vp_display_display_line(I, ip_prev, *it, color, thickness);
583 ip_prev = *it;
584 }
585 }
586
587 if (closeTheShape) {
588 vp_display_display_line(I, ips.front(), ips.back(), color, thickness);
589 }
590}
591
599void vpDisplay::displayPoint(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const vpColor &color,
600 unsigned int thickness)
601{
602 vp_display_display_point(I, ip, color, thickness);
603}
604
613void vpDisplay::displayPoint(const vpImage<vpRGBa> &I, int i, int j, const vpColor &color, unsigned int thickness)
614{
615 vp_display_display_point(I, i, j, color, thickness);
616}
617
626void vpDisplay::displayPolygon(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &vip, const vpColor &color,
627 unsigned int thickness, bool closed)
628{
629 vp_display_display_polygon(I, vip, color, thickness, closed);
630}
631
640void vpDisplay::displayPolygon(const vpImage<vpRGBa> &I, const vpPolygon &polygon, const vpColor &color,
641 unsigned int thickness, bool closed)
642{
643 vp_display_display_polygon(I, polygon, color, thickness, closed);
644}
645
663void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &topLeft, unsigned int width,
664 unsigned int height, const vpColor &color, bool fill, unsigned int thickness)
665{
666 vp_display_display_rectangle(I, topLeft, width, height, color, fill, thickness);
667}
668
685void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, int i, int j, unsigned int width, unsigned int height,
686 const vpColor &color, bool fill, unsigned int thickness)
687{
688 vp_display_display_rectangle(I, i, j, width, height, color, fill, thickness);
689}
690
706void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpRect &rectangle, const vpColor &color, bool fill,
707 unsigned int thickness)
708{
709 vp_display_display_rectangle(I, rectangle, color, fill, thickness);
710}
711
725void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &center, float angle, unsigned int width,
726 unsigned int height, const vpColor &color, unsigned int thickness)
727{
728 vp_display_display_rectangle(I, center, angle, width, height, color, thickness);
729}
730
747void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &topLeft, const vpImagePoint &bottomRight,
748 const vpColor &color, bool fill, unsigned int thickness)
749{
750 vp_display_display_rectangle(I, topLeft, bottomRight, color, fill, thickness);
751}
752
767void vpDisplay::displayRectangle(const vpImage<vpRGBa> &I, unsigned int i, unsigned int j, float angle,
768 unsigned int width, unsigned int height, const vpColor &color, unsigned int thickness)
769{
770 vp_display_display_rectangle(I, i, j, angle, width, height, color, thickness);
771}
772
785void vpDisplay::displayText(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const std::string &s,
786 const vpColor &color)
787{
788 vp_display_display_text(I, ip, s, color);
789}
790
804void vpDisplay::displayText(const vpImage<vpRGBa> &I, int i, int j, const std::string &s, const vpColor &color)
805{
806 vp_display_display_text(I, i, j, s, color);
807}
808
842void vpDisplay::flush(const vpImage<vpRGBa> &I) { vp_display_flush(I); }
843
853void vpDisplay::flushROI(const vpImage<vpRGBa> &I, const vpRect &roi) { vp_display_flush_roi(I, roi); }
854
866void vpDisplay::display(const vpImage<vpRGBa> &I) { vp_display_display(I); }
867
872void vpDisplay::displayROI(const vpImage<vpRGBa> &I, const vpRect &roi) { vp_display_display_roi(I, roi); }
873
891bool vpDisplay::getClick(const vpImage<vpRGBa> &I, bool blocking) { return vp_display_get_click(I, blocking); }
892
911bool vpDisplay::getClick(const vpImage<vpRGBa> &I, vpImagePoint &ip, bool blocking)
912{
913 return vp_display_get_click(I, ip, blocking);
914}
915
937 bool blocking)
938{
939 return vp_display_get_click(I, ip, button, blocking);
940}
941
959{
960 vpImagePoint ip;
961 return vpDisplay::getClick(I, ip, button, blocking);
962}
963
985 bool blocking)
986{
987 return vp_display_get_click_up(I, ip, button, blocking);
988}
989
1007{
1008 vpImagePoint ip;
1009 return vpDisplay::getClickUp(I, ip, button, blocking);
1010}
1011
1099{
1100 return vp_display_get_keyboard_event(I, blocking);
1101}
1102
1193bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, std::string &key, bool blocking)
1194{
1195 return vp_display_get_keyboard_event(I, key, blocking);
1196}
1197
1288bool vpDisplay::getKeyboardEvent(const vpImage<vpRGBa> &I, char *key, bool blocking)
1289{
1290 return vp_display_get_keyboard_event(I, key, blocking);
1291}
1292
1303{
1304 return vp_display_get_pointer_motion_event(I, ip);
1305}
1306
1317{
1318 return vp_display_get_pointer_position(I, ip);
1319}
1320
1330void vpDisplay::setBackground(const vpImage<vpRGBa> &I, const vpColor &color) { vp_display_set_background(I, color); }
1331
1345void vpDisplay::setFont(const vpImage<vpRGBa> &I, const std::string &fontname) { vp_display_set_font(I, fontname); }
1346
1354void vpDisplay::setTitle(const vpImage<vpRGBa> &I, const std::string &windowtitle)
1355{
1356 vp_display_set_title(I, windowtitle);
1357}
1358
1370void vpDisplay::setWindowPosition(const vpImage<vpRGBa> &I, int winx, int winy)
1371{
1372 vp_display_set_window_position(I, winx, winy);
1373}
1374
1382unsigned int vpDisplay::getDownScalingFactor(const vpImage<vpRGBa> &I) { return vp_display_get_down_scaling_factor(I); }
1383END_VISP_NAMESPACE
Generic class defining intrinsic camera parameters.
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157
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 close(vpImage< unsigned char > &I)
static VP_DEPRECATED 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:218
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:131
Defines a generic 2D polygon.
Definition vpPolygon.h:103
Defines a rectangle in the plane.
Definition vpRect.h:79