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>
88 init(I, x, y, title) ;
108 init(I, x, y, title) ;
137 windowXPosition = x ;
138 windowYPosition = y ;
146 this->title =
new char[strlen(title) + 1] ;
147 strcpy(this->title, title) ;
174 windowXPosition = windowYPosition = -1 ;
184 title =
new char[1] ;
217 "Image not initialized")) ;
243 "Image not initialized")) ;
266 gtk_init(argc,&argv);
272 widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
274 gtk_widget_add_events(widget, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
275 | GDK_POINTER_MOTION_MASK);
277 gtk_window_set_default_size(GTK_WINDOW(widget), (gint)width, (gint)height);
279 gtk_window_move(GTK_WINDOW(widget), x, y);
281 gtk_widget_show(widget);
286 background = gdk_pixmap_new(widget->window, (gint)width, (gint)height, -1);
289 gc = gdk_gc_new(widget->window);
292 colormap = gdk_window_get_colormap(widget->window);
297 gdk_color_parse(
"light blue",&lightBlue);
298 gdk_colormap_alloc_color(colormap,&lightBlue,FALSE,TRUE);
301 gdk_color_parse(
"blue",&blue);
302 gdk_colormap_alloc_color(colormap,&blue,FALSE,TRUE);
305 gdk_color_parse(
"dark blue",&darkBlue);
306 gdk_colormap_alloc_color(colormap,&darkBlue,FALSE,TRUE);
309 gdk_color_parse(
"#FF8C8C",&lightRed);
310 gdk_colormap_alloc_color(colormap,&lightRed,FALSE,TRUE);
313 gdk_color_parse(
"red",&red);
314 gdk_colormap_alloc_color(colormap,&red,FALSE,TRUE);
317 gdk_color_parse(
"dark red",&darkRed);
318 gdk_colormap_alloc_color(colormap,&darkRed,FALSE,TRUE);
321 gdk_color_parse(
"light green",&lightGreen);
322 gdk_colormap_alloc_color(colormap,&lightGreen,FALSE,TRUE);
325 gdk_color_parse(
"green",&green);
326 gdk_colormap_alloc_color(colormap,&green,FALSE,TRUE);
329 gdk_color_parse(
"dark green",&darkGreen);
330 gdk_colormap_alloc_color(colormap,&darkGreen,FALSE,TRUE);
333 gdk_color_parse(
"yellow",&yellow);
334 gdk_colormap_alloc_color(colormap,&yellow,FALSE,TRUE);
337 gdk_color_parse(
"cyan",&cyan);
338 gdk_colormap_alloc_color(colormap,&cyan,FALSE,TRUE);
341 gdk_color_parse(
"orange",&orange);
342 gdk_colormap_alloc_color(colormap,&orange,FALSE,TRUE);
345 gdk_color_parse(
"purple",&purple);
346 gdk_colormap_alloc_color(colormap,&purple,FALSE,TRUE);
349 gdk_color_parse(
"white",&white);
350 gdk_colormap_alloc_color(colormap,&white,FALSE,TRUE);
353 gdk_color_parse(
"black",&black);
354 gdk_colormap_alloc_color(colormap,&black,FALSE,TRUE);
357 gdk_color_parse(
"#C0C0C0",&lightGray);
358 gdk_colormap_alloc_color(colormap,&lightGray,FALSE,TRUE);
361 gdk_color_parse(
"#808080",&gray);
362 gdk_colormap_alloc_color(colormap,&gray,FALSE,TRUE);
365 gdk_color_parse(
"#404040",&darkGray);
366 gdk_colormap_alloc_color(colormap,&darkGray,FALSE,TRUE);
370 Police1 = gdk_font_load(
"-*-times-medium-r-normal-*-16-*-*-*-*-*-*-*");
371 Police2 = gdk_font_load(
"-*-courier-bold-r-normal-*-*-140-*-*-*-*-*-*");
375 if (this->title != NULL)
377 delete [] this->
title ;
380 this->title =
new char[strlen(title) + 1] ;
381 strcpy(this->title, title) ;
418 gdk_window_set_title(widget->window,(
char *)title);
424 "GTK not initialized")) ;
440 gtk_window_move(GTK_WINDOW(widget), winx, winy);
446 "GTK not initialized")) ;
468 gdk_draw_gray_image(background,
475 gdk_window_set_back_pixmap(widget->window, background, FALSE);
485 "GTK not initialized")) ;
514 gdk_draw_gray_image(background,
521 gdk_window_set_back_pixmap(widget->window, background, FALSE);
531 "GTK not initialized")) ;
554 gdk_draw_rgb_32_image(background,
557 (
unsigned char *)I.
bitmap,
564 gdk_window_set_back_pixmap(widget->window, background, FALSE);
575 "GTK not initialized")) ;
603 gdk_draw_rgb_32_image(background,
606 (
unsigned char *)Itemp.
bitmap,
613 gdk_window_set_back_pixmap(widget->window, background, FALSE);
623 "GTK not initialized")) ;
646 delete [] col ; col = NULL ;
656 gdk_window_hide (widget->window);
657 gdk_window_destroy(widget->window);
672 gdk_window_clear(widget->window);
679 "GTK not initialized")) ;
692 gdk_window_clear(widget->window);
699 "GTK not initialized")) ;
722 unsigned int w,
unsigned int h,
723 unsigned int thickness)
733 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon() )&&(std::fabs(b) <= std::numeric_limits<double>::epsilon()) )
769 "GTK not initialized")) ;
792 gdk_gc_set_foreground(gc, col[color.
id]);
794 gdkcolor.red = 256 * color.
R;
795 gdkcolor.green = 256 * color.
G;
796 gdkcolor.blue = 256 * color.
B;
797 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
798 gdk_gc_set_foreground(gc, &gdkcolor);
801 gdk_draw_string(background, Police2, gc,
804 (
const gchar *)text);
811 "GTK not initialized")) ;
827 unsigned int thickness )
831 if ( thickness == 1 ) thickness = 0;
834 gdk_gc_set_foreground(gc, col[color.
id]);
836 gdkcolor.red = 256 * color.
R;
837 gdkcolor.green = 256 * color.
G;
838 gdkcolor.blue = 256 * color.
B;
839 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
840 gdk_gc_set_foreground(gc, &gdkcolor);
843 gdk_gc_set_line_attributes(gc, (gint)thickness,
844 GDK_LINE_SOLID, GDK_CAP_BUTT,
848 gdk_draw_arc(background, gc, FALSE,
851 (gint)(2*radius), (gint)(2*radius), 23040, 23040) ;
853 gdk_draw_arc(background, gc, TRUE,
856 (gint)(2*radius), (gint)(2*radius), 23040, 23040) ;
862 "GTK not initialized")) ;
875 unsigned int thickness)
880 double i = ip.
get_i();
881 double j = ip.
get_j();
884 ip1.
set_i( i-size/2 );
886 ip2.
set_i( i+size/2 );
891 ip1.
set_j( j-size/2 );
893 ip2.
set_j( j+size/2 );
908 "GTK not initialized")) ;
920 unsigned int thickness )
925 if ( thickness == 1 ) thickness = 0;
928 gdk_gc_set_foreground(gc, col[color.
id]);
930 gdkcolor.red = 256 * color.
R;
931 gdkcolor.green = 256 * color.
G;
932 gdkcolor.blue = 256 * color.
B;
933 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
934 gdk_gc_set_foreground(gc, &gdkcolor);
937 gdk_gc_set_line_attributes(gc, (gint)thickness,
938 GDK_LINE_ON_OFF_DASH, GDK_CAP_BUTT,
940 gdk_draw_line(background, gc,
945 gdk_gc_set_line_attributes(gc, 0,
946 GDK_LINE_SOLID, GDK_CAP_BUTT,
953 "GTK not initialized")) ;
966 unsigned int thickness )
970 if ( thickness == 1 ) thickness = 0;
973 gdk_gc_set_foreground(gc, col[color.
id]);
975 gdkcolor.red = 256 * color.
R;
976 gdkcolor.green = 256 * color.
G;
977 gdkcolor.blue = 256 * color.
B;
978 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
979 gdk_gc_set_foreground(gc, &gdkcolor);
982 gdk_gc_set_line_attributes(gc, (gint)thickness,
983 GDK_LINE_SOLID, GDK_CAP_BUTT,
985 gdk_draw_line(background, gc,
995 "GTK not initialized")) ;
1010 gdk_gc_set_foreground(gc, col[color.
id]);
1012 gdkcolor.red = 256 * color.
R;
1013 gdkcolor.green = 256 * color.
G;
1014 gdkcolor.blue = 256 * color.
B;
1015 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1016 gdk_gc_set_foreground(gc, &gdkcolor);
1019 gdk_draw_point(background,gc,
1027 "GTK not initialized")) ;
1047 unsigned int width,
unsigned int height,
1048 const vpColor &color,
bool fill,
1049 unsigned int thickness )
1053 if ( thickness == 1 ) thickness = 0;
1056 gdk_gc_set_foreground(gc, col[color.
id]);
1058 gdkcolor.red = 256 * color.
R;
1059 gdkcolor.green = 256 * color.
G;
1060 gdkcolor.blue = 256 * color.
B;
1061 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1062 gdk_gc_set_foreground(gc, &gdkcolor);
1064 gdk_gc_set_line_attributes(gc, (gint)thickness,
1065 GDK_LINE_SOLID, GDK_CAP_BUTT,
1069 gdk_draw_rectangle(background, gc, FALSE,
1072 (gint)width-1, (gint)height-1);
1074 gdk_draw_rectangle(background, gc, TRUE,
1077 (gint)
width, (gint)height);
1080 gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1087 "GTK not initialized")) ;
1106 const vpColor &color,
bool fill,
1107 unsigned int thickness )
1111 if ( thickness == 1 ) thickness = 0;
1114 gdk_gc_set_foreground(gc, col[color.
id]);
1116 gdkcolor.red = 256 * color.
R;
1117 gdkcolor.green = 256 * color.
G;
1118 gdkcolor.blue = 256 * color.
B;
1119 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1120 gdk_gc_set_foreground(gc, &gdkcolor);
1123 gdk_gc_set_line_attributes(gc, (gint)thickness,
1124 GDK_LINE_SOLID, GDK_CAP_BUTT,
1131 gdk_draw_rectangle(background, gc, FALSE,
1136 gdk_draw_rectangle(background, gc, TRUE,
1142 gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1149 "GTK not initialized")) ;
1167 const vpColor &color,
bool fill,
1168 unsigned int thickness )
1173 gdk_gc_set_foreground(gc, col[color.
id]);
1175 gdkcolor.red = 256 * color.
R;
1176 gdkcolor.green = 256 * color.
G;
1177 gdkcolor.blue = 256 * color.
B;
1178 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1179 gdk_gc_set_foreground(gc, &gdkcolor);
1182 if ( thickness == 1 ) thickness = 0;
1184 gdk_gc_set_line_attributes(gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT,
1188 gdk_draw_rectangle(background, gc, FALSE,
1195 gdk_draw_rectangle(background, gc, TRUE,
1202 gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1209 "GTK not initialized")) ;
1238 GdkEvent *ev = NULL;
1240 while ((ev = gdk_event_get())!=NULL){
1245 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS){
1249 gdk_event_free(ev) ;
1255 }
while ( ret ==
false && blocking ==
true);
1260 "GTK not initialized")) ;
1288 GdkEvent *ev = NULL;
1291 while ((ev = gdk_event_get())!=NULL){
1292 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS) {
1293 u = ((GdkEventButton *)ev)->x ;
1294 v = ((GdkEventButton *)ev)->y ;
1299 gdk_event_free(ev) ;
1305 }
while ( ret ==
false && blocking ==
true);
1310 "GTK not initialized")) ;
1343 GdkEvent *ev = NULL;
1346 while ((ev = gdk_event_get())){
1347 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS){
1348 u = ((GdkEventButton *)ev)->x ;
1349 v = ((GdkEventButton *)ev)->y ;
1353 switch ((
int)((GdkEventButton *)ev)->button) {
1363 gdk_event_free(ev) ;
1370 }
while ( ret ==
false && blocking ==
true);
1375 "GTK not initialized")) ;
1413 GdkEvent *ev = NULL;
1416 while ((ev = gdk_event_get())!=NULL){
1417 if ( ev->any.window == widget->window
1418 && ev->type == GDK_BUTTON_RELEASE) {
1419 u = ((GdkEventButton *)ev)->x ;
1420 v = ((GdkEventButton *)ev)->y ;
1424 switch ( (
int ) ( ( GdkEventButton * ) ev )->button ) {
1434 gdk_event_free(ev) ;
1441 }
while ( ret ==
false && blocking ==
true);
1446 "GTK not initialized" ) ) ;
1468 ImageGtk = gdk_image_get(background, 0, 0, (gint)
width, (gint)
height);
1475 guchar OctetRouge,OctetVert,OctetBleu,mask;
1478 pos = (
unsigned char *)I.
bitmap;
1479 for (y=0;y<(gint)height;y++)
1481 for (x=0;x<(gint)width;x++)
1483 pixel = gdk_image_get_pixel(ImageGtk,x,y);
1484 OctetBleu = (guchar)pixel & mask;
1485 OctetVert = (guchar)(pixel>>8) & mask;
1486 OctetRouge = (guchar)(pixel>>16) & mask;
1487 *pos++ = OctetRouge;
1500 "GTK not initialized")) ;
1515 depth = (
unsigned int)gdk_window_get_visual(widget->window)->depth ;
1555 GdkEvent *ev = NULL;
1557 while ((ev = gdk_event_get())!=NULL){
1562 if (ev->any.window == widget->window && ev->type == GDK_KEY_PRESS){
1566 gdk_event_free(ev) ;
1572 }
while ( ret ==
false && blocking ==
true);
1577 "GTK not initialized")) ;
1609 GdkEvent *ev = NULL;
1611 while ((ev = gdk_event_get())!=NULL){
1616 if (ev->any.window == widget->window && ev->type == GDK_KEY_PRESS){
1618 sprintf(
string,
"%s", gdk_keyval_name (ev->key.keyval));
1622 gdk_event_free(ev) ;
1628 }
while ( ret ==
false && blocking ==
true);
1633 "GTK not initialized")) ;
1656 GdkEvent *ev = NULL;
1658 if ((ev = gdk_event_get())){
1659 if (ev->any.window == widget->window && ev->type == GDK_MOTION_NOTIFY){
1660 u = ((GdkEventMotion *)ev)->x ;
1661 v = ((GdkEventMotion *)ev)->y ;
1667 gdk_event_free(ev) ;
1673 "GTK not initialized")) ;
1694 gdk_window_get_pointer(widget->window, &u, &v, NULL);
1701 "GTK not initialized")) ;
void set_j(const double j)
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
Class to define colors available for display functionnalities.
bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
void resize(const unsigned int height, const unsigned int width)
set the size of the image
void set_i(const double i)
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)
void setFont(const char *font)
char * title
display title
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_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 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 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)
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)