50 #include <visp/vpConfig.h>
52 #if ( defined(VISP_HAVE_GTK) )
61 #include <visp/vpDisplay.h>
62 #include <visp/vpDisplayGTK.h>
65 #include <visp/vpDebug.h>
66 #include <visp/vpDisplayException.h>
67 #include <visp/vpMath.h>
68 #include <visp/vpImageTools.h>
94 init(I, x, y, title) ;
120 init(I, x, y, title) ;
162 title_ = std::string(title);
164 title_ = std::string(
" ");
224 "Image not initialized")) ;
256 "Image not initialized")) ;
284 gtk_init(argc,&argv);
290 widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
292 gtk_widget_add_events(widget, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
293 | GDK_POINTER_MOTION_MASK);
295 gtk_window_set_default_size(GTK_WINDOW(widget), (gint)width, (gint)height);
304 gtk_widget_show(widget);
309 background = gdk_pixmap_new(widget->window, (gint)width, (gint)height, -1);
312 gc = gdk_gc_new(widget->window);
315 colormap = gdk_window_get_colormap(widget->window);
320 gdk_color_parse(
"light blue",&lightBlue);
321 gdk_colormap_alloc_color(colormap,&lightBlue,FALSE,TRUE);
324 gdk_color_parse(
"blue",&blue);
325 gdk_colormap_alloc_color(colormap,&blue,FALSE,TRUE);
328 gdk_color_parse(
"dark blue",&darkBlue);
329 gdk_colormap_alloc_color(colormap,&darkBlue,FALSE,TRUE);
332 gdk_color_parse(
"#FF8C8C",&lightRed);
333 gdk_colormap_alloc_color(colormap,&lightRed,FALSE,TRUE);
336 gdk_color_parse(
"red",&red);
337 gdk_colormap_alloc_color(colormap,&red,FALSE,TRUE);
340 gdk_color_parse(
"dark red",&darkRed);
341 gdk_colormap_alloc_color(colormap,&darkRed,FALSE,TRUE);
344 gdk_color_parse(
"light green",&lightGreen);
345 gdk_colormap_alloc_color(colormap,&lightGreen,FALSE,TRUE);
348 gdk_color_parse(
"green",&green);
349 gdk_colormap_alloc_color(colormap,&green,FALSE,TRUE);
352 gdk_color_parse(
"dark green",&darkGreen);
353 gdk_colormap_alloc_color(colormap,&darkGreen,FALSE,TRUE);
356 gdk_color_parse(
"yellow",&yellow);
357 gdk_colormap_alloc_color(colormap,&yellow,FALSE,TRUE);
360 gdk_color_parse(
"cyan",&cyan);
361 gdk_colormap_alloc_color(colormap,&cyan,FALSE,TRUE);
364 gdk_color_parse(
"orange",&orange);
365 gdk_colormap_alloc_color(colormap,&orange,FALSE,TRUE);
368 gdk_color_parse(
"purple",&purple);
369 gdk_colormap_alloc_color(colormap,&purple,FALSE,TRUE);
372 gdk_color_parse(
"white",&white);
373 gdk_colormap_alloc_color(colormap,&white,FALSE,TRUE);
376 gdk_color_parse(
"black",&black);
377 gdk_colormap_alloc_color(colormap,&black,FALSE,TRUE);
380 gdk_color_parse(
"#C0C0C0",&lightGray);
381 gdk_colormap_alloc_color(colormap,&lightGray,FALSE,TRUE);
384 gdk_color_parse(
"#808080",&gray);
385 gdk_colormap_alloc_color(colormap,&gray,FALSE,TRUE);
388 gdk_color_parse(
"#404040",&darkGray);
389 gdk_colormap_alloc_color(colormap,&darkGray,FALSE,TRUE);
393 font = gdk_font_load(
"-*-times-medium-r-normal-*-16-*-*-*-*-*-*-*");
395 font = gdk_font_load(
"-*-courier-bold-r-normal-*-*-140-*-*-*-*-*-*");
397 font = gdk_font_load(
"-*-courier 10 pitch-medium-r-normal-*-16-*-*-*-*-*-*-*");
400 title_ = std::string(title);
402 title_ = std::string(
" ");
405 gdk_window_set_title(widget->window,
title_.c_str());
426 font = gdk_font_load((
const gchar*)fontname);
439 title_ = std::string(title);
441 title_ = std::string(
" ");
442 gdk_window_set_title(widget->window,
title_.c_str());
448 "GTK not initialized")) ;
464 gtk_window_move(GTK_WINDOW(widget), winx, winy);
470 "GTK not initialized")) ;
492 gdk_draw_gray_image(background,
499 gdk_window_set_back_pixmap(widget->window, background, FALSE);
509 "GTK not initialized")) ;
538 gdk_draw_gray_image(background,
545 gdk_window_set_back_pixmap(widget->window, background, FALSE);
555 "GTK not initialized")) ;
578 gdk_draw_rgb_32_image(background,
581 (
unsigned char *)I.
bitmap,
588 gdk_window_set_back_pixmap(widget->window, background, FALSE);
599 "GTK not initialized")) ;
627 gdk_draw_rgb_32_image(background,
630 (
unsigned char *)Itemp.
bitmap,
637 gdk_window_set_back_pixmap(widget->window, background, FALSE);
647 "GTK not initialized")) ;
670 delete [] col ; col = NULL ;
675 gdk_window_hide (widget->window);
676 gdk_window_destroy(widget->window);
691 gdk_window_clear(widget->window);
698 "GTK not initialized")) ;
711 gdk_window_clear(widget->window);
718 "GTK not initialized")) ;
741 unsigned int w,
unsigned int h,
742 unsigned int thickness)
752 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon() )&&(std::fabs(b) <= std::numeric_limits<double>::epsilon()) )
788 "GTK not initialized")) ;
811 gdk_gc_set_foreground(gc, col[color.
id]);
813 gdkcolor.red = 256 * color.
R;
814 gdkcolor.green = 256 * color.
G;
815 gdkcolor.blue = 256 * color.
B;
816 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
817 gdk_gc_set_foreground(gc, &gdkcolor);
820 gdk_draw_string(background, font, gc,
823 (
const gchar *)text);
825 std::cout <<
"Cannot draw string: no font is selected" << std::endl;
831 "GTK not initialized")) ;
847 unsigned int thickness )
851 if ( thickness == 1 ) thickness = 0;
854 gdk_gc_set_foreground(gc, col[color.
id]);
856 gdkcolor.red = 256 * color.
R;
857 gdkcolor.green = 256 * color.
G;
858 gdkcolor.blue = 256 * color.
B;
859 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
860 gdk_gc_set_foreground(gc, &gdkcolor);
863 gdk_gc_set_line_attributes(gc, (gint)thickness,
864 GDK_LINE_SOLID, GDK_CAP_BUTT,
868 gdk_draw_arc(background, gc, FALSE,
871 (gint)(2*radius), (gint)(2*radius), 23040, 23040) ;
873 gdk_draw_arc(background, gc, TRUE,
876 (gint)(2*radius), (gint)(2*radius), 23040, 23040) ;
882 "GTK not initialized")) ;
895 unsigned int thickness)
900 double i = ip.
get_i();
901 double j = ip.
get_j();
904 ip1.
set_i( i-size/2 );
906 ip2.
set_i( i+size/2 );
911 ip1.
set_j( j-size/2 );
913 ip2.
set_j( j+size/2 );
928 "GTK not initialized")) ;
940 unsigned int thickness )
945 if ( thickness == 1 ) thickness = 0;
948 gdk_gc_set_foreground(gc, col[color.
id]);
950 gdkcolor.red = 256 * color.
R;
951 gdkcolor.green = 256 * color.
G;
952 gdkcolor.blue = 256 * color.
B;
953 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
954 gdk_gc_set_foreground(gc, &gdkcolor);
957 gdk_gc_set_line_attributes(gc, (gint)thickness,
958 GDK_LINE_ON_OFF_DASH, GDK_CAP_BUTT,
960 gdk_draw_line(background, gc,
965 gdk_gc_set_line_attributes(gc, 0,
966 GDK_LINE_SOLID, GDK_CAP_BUTT,
973 "GTK not initialized")) ;
986 unsigned int thickness )
990 if ( thickness == 1 ) thickness = 0;
993 gdk_gc_set_foreground(gc, col[color.
id]);
995 gdkcolor.red = 256 * color.
R;
996 gdkcolor.green = 256 * color.
G;
997 gdkcolor.blue = 256 * color.
B;
998 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
999 gdk_gc_set_foreground(gc, &gdkcolor);
1002 gdk_gc_set_line_attributes(gc, (gint)thickness,
1003 GDK_LINE_SOLID, GDK_CAP_BUTT,
1005 gdk_draw_line(background, gc,
1015 "GTK not initialized")) ;
1030 gdk_gc_set_foreground(gc, col[color.
id]);
1032 gdkcolor.red = 256 * color.
R;
1033 gdkcolor.green = 256 * color.
G;
1034 gdkcolor.blue = 256 * color.
B;
1035 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1036 gdk_gc_set_foreground(gc, &gdkcolor);
1039 gdk_draw_point(background,gc,
1047 "GTK not initialized")) ;
1067 unsigned int width,
unsigned int height,
1068 const vpColor &color,
bool fill,
1069 unsigned int thickness )
1073 if ( thickness == 1 ) thickness = 0;
1076 gdk_gc_set_foreground(gc, col[color.
id]);
1078 gdkcolor.red = 256 * color.
R;
1079 gdkcolor.green = 256 * color.
G;
1080 gdkcolor.blue = 256 * color.
B;
1081 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1082 gdk_gc_set_foreground(gc, &gdkcolor);
1084 gdk_gc_set_line_attributes(gc, (gint)thickness,
1085 GDK_LINE_SOLID, GDK_CAP_BUTT,
1089 gdk_draw_rectangle(background, gc, FALSE,
1092 (gint)width-1, (gint)height-1);
1094 gdk_draw_rectangle(background, gc, TRUE,
1097 (gint)
width, (gint)height);
1100 gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1107 "GTK not initialized")) ;
1126 const vpColor &color,
bool fill,
1127 unsigned int thickness )
1131 if ( thickness == 1 ) thickness = 0;
1134 gdk_gc_set_foreground(gc, col[color.
id]);
1136 gdkcolor.red = 256 * color.
R;
1137 gdkcolor.green = 256 * color.
G;
1138 gdkcolor.blue = 256 * color.
B;
1139 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1140 gdk_gc_set_foreground(gc, &gdkcolor);
1143 gdk_gc_set_line_attributes(gc, (gint)thickness,
1144 GDK_LINE_SOLID, GDK_CAP_BUTT,
1151 gdk_draw_rectangle(background, gc, FALSE,
1156 gdk_draw_rectangle(background, gc, TRUE,
1162 gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1169 "GTK not initialized")) ;
1187 const vpColor &color,
bool fill,
1188 unsigned int thickness )
1193 gdk_gc_set_foreground(gc, col[color.
id]);
1195 gdkcolor.red = 256 * color.
R;
1196 gdkcolor.green = 256 * color.
G;
1197 gdkcolor.blue = 256 * color.
B;
1198 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1199 gdk_gc_set_foreground(gc, &gdkcolor);
1202 if ( thickness == 1 ) thickness = 0;
1204 gdk_gc_set_line_attributes(gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT,
1208 gdk_draw_rectangle(background, gc, FALSE,
1215 gdk_draw_rectangle(background, gc, TRUE,
1222 gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1229 "GTK not initialized")) ;
1258 GdkEvent *ev = NULL;
1260 while ((ev = gdk_event_get())!=NULL){
1265 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS){
1269 gdk_event_free(ev) ;
1275 }
while ( ret ==
false && blocking ==
true);
1280 "GTK not initialized")) ;
1308 GdkEvent *ev = NULL;
1311 while ((ev = gdk_event_get())!=NULL){
1312 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS) {
1313 u = ((GdkEventButton *)ev)->x ;
1314 v = ((GdkEventButton *)ev)->y ;
1319 gdk_event_free(ev) ;
1325 }
while ( ret ==
false && blocking ==
true);
1330 "GTK not initialized")) ;
1363 GdkEvent *ev = NULL;
1366 while ((ev = gdk_event_get())){
1367 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS){
1368 u = ((GdkEventButton *)ev)->x ;
1369 v = ((GdkEventButton *)ev)->y ;
1373 switch ((
int)((GdkEventButton *)ev)->button) {
1383 gdk_event_free(ev) ;
1390 }
while ( ret ==
false && blocking ==
true);
1395 "GTK not initialized")) ;
1433 GdkEvent *ev = NULL;
1436 while ((ev = gdk_event_get())!=NULL){
1437 if ( ev->any.window == widget->window
1438 && ev->type == GDK_BUTTON_RELEASE) {
1439 u = ((GdkEventButton *)ev)->x ;
1440 v = ((GdkEventButton *)ev)->y ;
1444 switch ( (
int ) ( ( GdkEventButton * ) ev )->button ) {
1454 gdk_event_free(ev) ;
1461 }
while ( ret ==
false && blocking ==
true);
1466 "GTK not initialized" ) ) ;
1488 ImageGtk = gdk_image_get(background, 0, 0, (gint)
width, (gint)
height);
1495 guchar OctetRouge,OctetVert,OctetBleu,mask;
1498 pos = (
unsigned char *)I.
bitmap;
1499 for (y=0;y<(gint)height;y++)
1501 for (x=0;x<(gint)width;x++)
1503 pixel = gdk_image_get_pixel(ImageGtk,x,y);
1504 OctetBleu = (guchar)pixel & mask;
1505 OctetVert = (guchar)(pixel>>8) & mask;
1506 OctetRouge = (guchar)(pixel>>16) & mask;
1507 *pos++ = OctetRouge;
1520 "GTK not initialized")) ;
1535 depth = (
unsigned int)gdk_window_get_visual(widget->window)->depth ;
1575 GdkEvent *ev = NULL;
1577 while ((ev = gdk_event_get())!=NULL){
1582 if (ev->any.window == widget->window && ev->type == GDK_KEY_PRESS){
1586 gdk_event_free(ev) ;
1592 }
while ( ret ==
false && blocking ==
true);
1597 "GTK not initialized")) ;
1629 GdkEvent *ev = NULL;
1631 while ((ev = gdk_event_get())!=NULL){
1636 if (ev->any.window == widget->window && ev->type == GDK_KEY_PRESS){
1638 sprintf(
string,
"%s", gdk_keyval_name (ev->key.keyval));
1642 gdk_event_free(ev) ;
1648 }
while ( ret ==
false && blocking ==
true);
1653 "GTK not initialized")) ;
1676 GdkEvent *ev = NULL;
1678 if ((ev = gdk_event_get())){
1679 if (ev->any.window == widget->window && ev->type == GDK_MOTION_NOTIFY){
1680 u = ((GdkEventMotion *)ev)->x ;
1681 v = ((GdkEventMotion *)ev)->y ;
1687 gdk_event_free(ev) ;
1693 "GTK not initialized")) ;
1714 gdk_window_get_pointer(widget->window, &u, &v, NULL);
1721 "GTK not initialized")) ;
void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
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 displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, const unsigned int width, const unsigned int height)
unsigned int getWidth() const
unsigned char B
Blue component.
Type * bitmap
points toward the bitmap
void setFont(const char *fontname)
Class to define colors available for display functionnalities.
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)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
bool displayHasBeenInitialized
display has been initialized
unsigned char G
Green component.
static int wait(double t0, double t)
static int round(const double x)
void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height)
void set_i(const double ii)
void set_u(const double u)
static double sqr(double x)
void set_v(const double v)
bool getPointerPosition(vpImagePoint &ip)
void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
void resize(const unsigned int h, const unsigned int w)
set the size of the image
void displayImage(const vpImage< vpRGBa > &I)
void displayPoint(const vpImagePoint &ip, const vpColor &color)
bool getPointerMotionEvent(vpImagePoint &ip)
void getScreenSize(unsigned int &width, unsigned int &height)
get the window size
void getImage(vpImage< vpRGBa > &I)
get the window pixmap and put it in vpRGBa image
void set_j(const double jj)
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)
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)
void setWindowPosition(int winx, int winy)
int windowXPosition
display position
unsigned char R
Red component.
unsigned int getScreenDepth()
get the window depth (8,16,24,32)
unsigned int getHeight() const
Defines a rectangle in the plane.
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 ...
void setTitle(const char *title)
bool getKeyboardEvent(bool blocking=true)
int windowYPosition
display position