46 #include <visp3/core/vpConfig.h> 48 #if (defined(VISP_HAVE_GTK)) 57 #include <visp3/core/vpDisplay.h> 58 #include <visp3/gui/vpDisplayGTK.h> 61 #include <visp3/core/vpDebug.h> 62 #include <visp3/core/vpDisplayException.h> 63 #include <visp3/core/vpImageTools.h> 64 #include <visp3/core/vpMath.h> 88 : widget(NULL), m_background(NULL), m_gc(NULL), blue(), red(), yellow(), green(), cyan(), orange(), white(), black(),
89 gdkcolor(), lightBlue(), darkBlue(), lightRed(), darkRed(), lightGreen(), darkGreen(), purple(), lightGray(),
90 gray(), darkGray(), colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
120 : widget(NULL), m_background(NULL), m_gc(NULL), blue(), red(), yellow(), green(), cyan(), orange(), white(), black(),
121 gdkcolor(), lightBlue(), darkBlue(), lightRed(), darkRed(), lightGreen(), darkGreen(), purple(), lightGray(),
122 gray(), darkGray(), colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
125 init(I, x, y, title);
148 : widget(NULL), m_background(NULL), m_gc(NULL), blue(), red(), yellow(), green(), cyan(), orange(), white(), black(),
149 gdkcolor(), lightBlue(), darkBlue(), lightRed(), darkRed(), lightGreen(), darkGreen(), purple(), lightGray(),
150 gray(), darkGray(), colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
178 : widget(NULL), m_background(NULL), m_gc(NULL), blue(), red(), yellow(), green(), cyan(), orange(), white(), black(),
179 gdkcolor(), lightBlue(), darkBlue(), lightRed(), darkRed(), lightGreen(), darkGreen(), purple(), lightGray(),
180 gray(), darkGray(), colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
183 init(I, x, y, title);
209 : widget(NULL), m_background(NULL), m_gc(NULL), blue(), red(), yellow(), green(), cyan(), orange(), white(), black(),
210 gdkcolor(), lightBlue(), darkBlue(), lightRed(), darkRed(), lightGreen(), darkGreen(), purple(), lightGray(),
211 gray(), darkGray(), colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
238 :
vpDisplay(), widget(NULL), m_background(NULL), m_gc(NULL), blue(), red(), yellow(), green(), cyan(), orange(),
239 white(), black(), gdkcolor(), lightBlue(), darkBlue(), lightRed(), darkRed(), lightGreen(), darkGreen(), purple(),
240 lightGray(), gray(), darkGray(), colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
322 gtk_init(argc, &argv);
330 widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
332 gtk_widget_add_events(widget, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK);
334 gtk_window_set_default_size(GTK_WINDOW(widget), (gint)
m_width, (gint)
m_height);
343 gtk_widget_show(widget);
348 m_background = gdk_pixmap_new(widget->window, (gint)m_width, (gint)m_height, -1);
351 m_gc = gdk_gc_new(widget->window);
354 colormap = gdk_window_get_colormap(widget->window);
359 gdk_color_parse(
"light blue", &lightBlue);
360 gdk_colormap_alloc_color(colormap, &lightBlue, FALSE, TRUE);
363 gdk_color_parse(
"blue", &blue);
364 gdk_colormap_alloc_color(colormap, &blue, FALSE, TRUE);
367 gdk_color_parse(
"dark blue", &darkBlue);
368 gdk_colormap_alloc_color(colormap, &darkBlue, FALSE, TRUE);
371 gdk_color_parse(
"#FF8C8C", &lightRed);
372 gdk_colormap_alloc_color(colormap, &lightRed, FALSE, TRUE);
375 gdk_color_parse(
"red", &red);
376 gdk_colormap_alloc_color(colormap, &red, FALSE, TRUE);
379 gdk_color_parse(
"dark red", &darkRed);
380 gdk_colormap_alloc_color(colormap, &darkRed, FALSE, TRUE);
383 gdk_color_parse(
"light green", &lightGreen);
384 gdk_colormap_alloc_color(colormap, &lightGreen, FALSE, TRUE);
387 gdk_color_parse(
"green", &green);
388 gdk_colormap_alloc_color(colormap, &green, FALSE, TRUE);
391 gdk_color_parse(
"dark green", &darkGreen);
392 gdk_colormap_alloc_color(colormap, &darkGreen, FALSE, TRUE);
395 gdk_color_parse(
"yellow", &yellow);
396 gdk_colormap_alloc_color(colormap, &yellow, FALSE, TRUE);
399 gdk_color_parse(
"cyan", &cyan);
400 gdk_colormap_alloc_color(colormap, &cyan, FALSE, TRUE);
403 gdk_color_parse(
"orange", &orange);
404 gdk_colormap_alloc_color(colormap, &orange, FALSE, TRUE);
407 gdk_color_parse(
"purple", &purple);
408 gdk_colormap_alloc_color(colormap, &purple, FALSE, TRUE);
411 gdk_color_parse(
"white", &white);
412 gdk_colormap_alloc_color(colormap, &white, FALSE, TRUE);
415 gdk_color_parse(
"black", &black);
416 gdk_colormap_alloc_color(colormap, &black, FALSE, TRUE);
419 gdk_color_parse(
"#C0C0C0", &lightGray);
420 gdk_colormap_alloc_color(colormap, &lightGray, FALSE, TRUE);
423 gdk_color_parse(
"#808080", &gray);
424 gdk_colormap_alloc_color(colormap, &gray, FALSE, TRUE);
427 gdk_color_parse(
"#404040", &darkGray);
428 gdk_colormap_alloc_color(colormap, &darkGray, FALSE, TRUE);
432 font = gdk_font_load(
"-*-times-medium-r-normal-*-16-*-*-*-*-*-*-*");
434 font = gdk_font_load(
"-*-courier-bold-r-normal-*-*-140-*-*-*-*-*-*");
436 font = gdk_font_load(
"-*-courier 10 pitch-medium-r-normal-*-16-*-*-*-*-*-*-*");
440 gdk_window_set_title(widget->window,
m_title.c_str());
470 gdk_window_set_title(widget->window,
m_title.c_str());
489 gtk_window_move(GTK_WINDOW(widget), winx, winy);
512 gdk_draw_gray_image(m_background, m_gc, 0, 0, (gint)
m_width, (gint)
m_height, GDK_RGB_DITHER_NONE, I.
bitmap,
517 gdk_draw_gray_image(m_background, m_gc, 0, 0, (gint)
m_width, (gint)
m_height, GDK_RGB_DITHER_NONE, sampled.
bitmap,
522 gdk_window_set_back_pixmap(widget->window, m_background, FALSE);
553 int i_min = (std::max)((
int)ceil(iP.
get_i() /
m_scale), 0);
554 int j_min = (std::max)((
int)ceil(iP.
get_j() /
m_scale), 0);
556 gdk_draw_gray_image(m_background, m_gc, (gint)j_min, (gint)i_min, (gint)Itemp.getWidth(), (gint)Itemp.getHeight(),
557 GDK_RGB_DITHER_NONE, Itemp.bitmap, (gint)Itemp.getWidth());
560 gdk_window_set_back_pixmap(widget->window, m_background, FALSE);
583 gdk_draw_rgb_32_image(m_background, m_gc, 0, 0, (gint)
m_width, (gint)
m_height, GDK_RGB_DITHER_NONE,
584 (
unsigned char *)I.
bitmap, (gint)(4 * m_width));
588 gdk_draw_rgb_32_image(m_background, m_gc, 0, 0, (gint)
m_width, (gint)
m_height, GDK_RGB_DITHER_NONE,
589 (
unsigned char *)sampled.
bitmap, (gint)(4 * m_width));
595 gdk_window_set_back_pixmap(widget->window, m_background, FALSE);
626 int i_min = (std::max)((
int)ceil(iP.
get_i() /
m_scale), 0);
627 int j_min = (std::max)((
int)ceil(iP.
get_j() /
m_scale), 0);
629 gdk_draw_rgb_32_image(m_background, m_gc, (gint)j_min, (gint)i_min, (gint)Itemp.getWidth(), (gint)Itemp.getHeight(),
630 GDK_RGB_DITHER_NONE, (
unsigned char *)Itemp.bitmap, (gint)Itemp.getWidth() * 4);
633 gdk_window_set_back_pixmap(widget->window, m_background, FALSE);
658 if (widget != NULL) {
659 gdk_window_hide(widget->window);
660 gdk_window_destroy(widget->window);
661 gtk_widget_destroy(widget);
674 gdk_window_clear(widget->window);
689 gdk_window_clear(widget->window);
709 unsigned int h,
unsigned int thickness)
717 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon()) &&
718 (std::fabs(b) <= std::numeric_limits<double>::epsilon())) {
763 gdk_gc_set_foreground(m_gc, col[color.
id]);
765 gdkcolor.red = 256 * color.
R;
766 gdkcolor.green = 256 * color.
G;
767 gdkcolor.blue = 256 * color.
B;
768 gdk_colormap_alloc_color(colormap, &gdkcolor, FALSE, TRUE);
769 gdk_gc_set_foreground(m_gc, &gdkcolor);
775 std::cout <<
"Cannot draw string: no font is selected" << std::endl;
790 unsigned int thickness)
797 gdk_gc_set_foreground(m_gc, col[color.
id]);
799 gdkcolor.red = 256 * color.
R;
800 gdkcolor.green = 256 * color.
G;
801 gdkcolor.blue = 256 * color.
B;
802 gdk_colormap_alloc_color(colormap, &gdkcolor, FALSE, TRUE);
803 gdk_gc_set_foreground(m_gc, &gdkcolor);
806 gdk_gc_set_line_attributes(m_gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL);
811 (gint)(2. * radius /
m_scale), 23040, 23040);
815 (gint)(2. * radius /
m_scale), 23040, 23040);
830 double i = ip.
get_i();
831 double j = ip.
get_j();
834 ip1.
set_i(i - size / 2);
836 ip2.
set_i(i + size / 2);
841 ip1.
set_j(j - size / 2);
843 ip2.
set_j(j + size / 2);
859 unsigned int thickness)
867 gdk_gc_set_foreground(m_gc, col[color.
id]);
869 gdkcolor.red = 256 * color.
R;
870 gdkcolor.green = 256 * color.
G;
871 gdkcolor.blue = 256 * color.
B;
872 gdk_colormap_alloc_color(colormap, &gdkcolor, FALSE, TRUE);
873 gdk_gc_set_foreground(m_gc, &gdkcolor);
876 gdk_gc_set_line_attributes(m_gc, (gint)thickness, GDK_LINE_ON_OFF_DASH, GDK_CAP_BUTT, GDK_JOIN_BEVEL);
879 gdk_gc_set_line_attributes(m_gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL);
892 unsigned int thickness)
899 gdk_gc_set_foreground(m_gc, col[color.
id]);
901 gdkcolor.red = 256 * color.
R;
902 gdkcolor.green = 256 * color.
G;
903 gdkcolor.blue = 256 * color.
B;
904 gdk_colormap_alloc_color(colormap, &gdkcolor, FALSE, TRUE);
905 gdk_gc_set_foreground(m_gc, &gdkcolor);
908 gdk_gc_set_line_attributes(m_gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL);
926 gdk_gc_set_foreground(m_gc, col[color.
id]);
928 gdkcolor.red = 256 * color.
R;
929 gdkcolor.green = 256 * color.
G;
930 gdkcolor.blue = 256 * color.
B;
931 gdk_colormap_alloc_color(colormap, &gdkcolor, FALSE, TRUE);
932 gdk_gc_set_foreground(m_gc, &gdkcolor);
935 if (thickness == 1) {
960 bool fill,
unsigned int thickness)
967 gdk_gc_set_foreground(m_gc, col[color.
id]);
969 gdkcolor.red = 256 * color.
R;
970 gdkcolor.green = 256 * color.
G;
971 gdkcolor.blue = 256 * color.
B;
972 gdk_colormap_alloc_color(colormap, &gdkcolor, FALSE, TRUE);
973 gdk_gc_set_foreground(m_gc, &gdkcolor);
975 gdk_gc_set_line_attributes(m_gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL);
985 gdk_gc_set_line_attributes(m_gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL);
1004 bool fill,
unsigned int thickness)
1011 gdk_gc_set_foreground(m_gc, col[color.
id]);
1013 gdkcolor.red = 256 * color.
R;
1014 gdkcolor.green = 256 * color.
G;
1015 gdkcolor.blue = 256 * color.
B;
1016 gdk_colormap_alloc_color(colormap, &gdkcolor, FALSE, TRUE);
1017 gdk_gc_set_foreground(m_gc, &gdkcolor);
1020 gdk_gc_set_line_attributes(m_gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL);
1033 gdk_gc_set_line_attributes(m_gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL);
1055 gdk_gc_set_foreground(m_gc, col[color.
id]);
1057 gdkcolor.red = 256 * color.
R;
1058 gdkcolor.green = 256 * color.
G;
1059 gdkcolor.blue = 256 * color.
B;
1060 gdk_colormap_alloc_color(colormap, &gdkcolor, FALSE, TRUE);
1061 gdk_gc_set_foreground(m_gc, &gdkcolor);
1067 gdk_gc_set_line_attributes(m_gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL);
1080 gdk_gc_set_line_attributes(m_gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL);
1110 GdkEvent *ev = NULL;
1111 while ((ev = gdk_event_get()) != NULL) {
1116 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS) {
1126 }
while (ret ==
false && blocking ==
true);
1157 GdkEvent *ev = NULL;
1158 while ((ev = gdk_event_get()) != NULL) {
1159 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS) {
1160 u = ((GdkEventButton *)ev)->x;
1161 v = ((GdkEventButton *)ev)->y;
1163 ip.
set_v(v * m_scale);
1172 }
while (ret ==
false && blocking ==
true);
1205 GdkEvent *ev = NULL;
1206 while ((ev = gdk_event_get())) {
1207 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS) {
1208 u = ((GdkEventButton *)ev)->x;
1209 v = ((GdkEventButton *)ev)->y;
1211 ip.
set_v(v * m_scale);
1213 switch ((
int)((GdkEventButton *)ev)->button) {
1233 }
while (ret ==
false && blocking ==
true);
1272 GdkEvent *ev = NULL;
1273 while ((ev = gdk_event_get()) != NULL) {
1274 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_RELEASE) {
1275 u = ((GdkEventButton *)ev)->x;
1276 v = ((GdkEventButton *)ev)->y;
1278 ip.
set_v(v * m_scale);
1280 switch ((
int)((GdkEventButton *)ev)->button) {
1300 }
while (ret ==
false && blocking ==
true);
1320 ImageGtk = gdk_image_get(m_background, 0, 0, (gint)
m_width, (gint)
m_height);
1322 I.
resize(m_height, m_width);
1325 guchar OctetRouge, OctetVert, OctetBleu, mask;
1328 for (y = 0; y < (gint)m_height; y++) {
1329 for (x = 0; x < (gint)m_width; x++) {
1330 pixel = gdk_image_get_pixel(ImageGtk, x, y);
1331 OctetBleu = (guchar)pixel & mask;
1332 OctetVert = (guchar)(pixel >> 8) & mask;
1333 OctetRouge = (guchar)(pixel >> 16) & mask;
1334 I[y][x].R = OctetRouge;
1335 I[y][x].G = OctetVert;
1336 I[y][x].B = OctetBleu;
1355 depth = (
unsigned int)gdk_window_get_visual(widget->window)->depth;
1383 GdkEvent *ev = NULL;
1384 while ((ev = gdk_event_get()) != NULL) {
1389 if (ev->any.window == widget->window && ev->type == GDK_KEY_PRESS) {
1399 }
while (ret ==
false && blocking ==
true);
1433 GdkEvent *ev = NULL;
1434 while ((ev = gdk_event_get()) != NULL) {
1439 if (ev->any.window == widget->window && ev->type == GDK_KEY_PRESS) {
1442 key = gdk_keyval_name(ev->key.keyval);
1452 }
while (ret ==
false && blocking ==
true);
1476 GdkEvent *ev = NULL;
1477 if ((ev = gdk_event_get())) {
1478 if (ev->any.window == widget->window && ev->type == GDK_MOTION_NOTIFY) {
1479 double u = ((GdkEventMotion *)ev)->x;
1480 double v = ((GdkEventMotion *)ev)->y;
1482 ip.
set_v(v * m_scale);
1508 gdk_window_get_pointer(widget->window, &u, &v, NULL);
1510 ip.
set_v(v * m_scale);
1530 gtk_init(argc, &argv);
1532 GtkWidget *widget_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1533 gtk_window_set_default_size(GTK_WINDOW(widget_), 100, 100);
1534 gtk_widget_show(widget_);
1536 GdkScreen *screen_ = gdk_window_get_screen(widget_->window);
1537 w = (
unsigned int)gdk_screen_get_width(screen_);
1538 h = (
unsigned int)gdk_screen_get_height(screen_);
1539 gtk_widget_destroy(widget_);
1541 GdkScreen *screen_ = gdk_window_get_screen(widget->window);
1542 w = (
unsigned int)gdk_screen_get_width(screen_);
1543 h = (
unsigned int)gdk_screen_get_height(screen_);
1552 unsigned int width, height;
1562 unsigned int width, height;
1567 #elif !defined(VISP_BUILD_SHARED_LIBS) 1570 void dummy_vpDisplayGTK(){};
void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
VISP_EXPORT int wait(double t0, double t)
int m_windowYPosition
display position
void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)
Class that defines generic functionnalities for display.
bool getClick(bool blocking=true)
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
unsigned char B
Blue component.
Type * bitmap
points toward the bitmap
void subsample(unsigned int v_scale, unsigned int h_scale, vpImage< Type > &sampled) const
Class to define colors available for display functionnalities.
void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height)
bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
unsigned char G
Green component.
bool m_displayHasBeenInitialized
display has been initialized
void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
int m_windowXPosition
display position
void setScale(vpScaleType scaleType, unsigned int width, unsigned int height)
static double sqr(double x)
bool getPointerPosition(vpImagePoint &ip)
void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
void displayImage(const vpImage< vpRGBa > &I)
unsigned int getScreenWidth()
bool getPointerMotionEvent(vpImagePoint &ip)
void getScreenSize(unsigned int &width, unsigned int &height)
void setTitle(const std::string &title)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
void getImage(vpImage< vpRGBa > &I)
get the window pixmap and put it in vpRGBa image
void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
static int round(double x)
void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)
Error that can be emited by the vpDisplay class and its derivates.
void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
unsigned int getHeight() const
void setFont(const std::string &fontname)
void setWindowPosition(int winx, int winy)
unsigned char R
Red component.
unsigned int getScreenDepth()
get the window depth (8,16,24,32)
Defines a rectangle in the plane.
unsigned int getScreenHeight()
void clearDisplay(const vpColor &color=vpColor::white)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
bool getKeyboardEvent(bool blocking=true)
unsigned int getWidth() const
void displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, unsigned int width, unsigned int height)
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)