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>
87 init(I, x, y, title) ;
106 init(I, x, y, title) ;
142 strcpy(this->title, title) ;
196 "Image not initialized")) ;
228 "Image not initialized")) ;
256 gtk_init(argc,&argv);
262 widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
264 gtk_widget_add_events(widget, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
265 | GDK_POINTER_MOTION_MASK);
267 gtk_window_set_default_size(GTK_WINDOW(widget), (gint)width, (gint)height);
276 gtk_widget_show(widget);
281 background = gdk_pixmap_new(widget->window, (gint)width, (gint)height, -1);
284 gc = gdk_gc_new(widget->window);
287 colormap = gdk_window_get_colormap(widget->window);
292 gdk_color_parse(
"light blue",&lightBlue);
293 gdk_colormap_alloc_color(colormap,&lightBlue,FALSE,TRUE);
296 gdk_color_parse(
"blue",&blue);
297 gdk_colormap_alloc_color(colormap,&blue,FALSE,TRUE);
300 gdk_color_parse(
"dark blue",&darkBlue);
301 gdk_colormap_alloc_color(colormap,&darkBlue,FALSE,TRUE);
304 gdk_color_parse(
"#FF8C8C",&lightRed);
305 gdk_colormap_alloc_color(colormap,&lightRed,FALSE,TRUE);
308 gdk_color_parse(
"red",&red);
309 gdk_colormap_alloc_color(colormap,&red,FALSE,TRUE);
312 gdk_color_parse(
"dark red",&darkRed);
313 gdk_colormap_alloc_color(colormap,&darkRed,FALSE,TRUE);
316 gdk_color_parse(
"light green",&lightGreen);
317 gdk_colormap_alloc_color(colormap,&lightGreen,FALSE,TRUE);
320 gdk_color_parse(
"green",&green);
321 gdk_colormap_alloc_color(colormap,&green,FALSE,TRUE);
324 gdk_color_parse(
"dark green",&darkGreen);
325 gdk_colormap_alloc_color(colormap,&darkGreen,FALSE,TRUE);
328 gdk_color_parse(
"yellow",&yellow);
329 gdk_colormap_alloc_color(colormap,&yellow,FALSE,TRUE);
332 gdk_color_parse(
"cyan",&cyan);
333 gdk_colormap_alloc_color(colormap,&cyan,FALSE,TRUE);
336 gdk_color_parse(
"orange",&orange);
337 gdk_colormap_alloc_color(colormap,&orange,FALSE,TRUE);
340 gdk_color_parse(
"purple",&purple);
341 gdk_colormap_alloc_color(colormap,&purple,FALSE,TRUE);
344 gdk_color_parse(
"white",&white);
345 gdk_colormap_alloc_color(colormap,&white,FALSE,TRUE);
348 gdk_color_parse(
"black",&black);
349 gdk_colormap_alloc_color(colormap,&black,FALSE,TRUE);
352 gdk_color_parse(
"#C0C0C0",&lightGray);
353 gdk_colormap_alloc_color(colormap,&lightGray,FALSE,TRUE);
356 gdk_color_parse(
"#808080",&gray);
357 gdk_colormap_alloc_color(colormap,&gray,FALSE,TRUE);
360 gdk_color_parse(
"#404040",&darkGray);
361 gdk_colormap_alloc_color(colormap,&darkGray,FALSE,TRUE);
365 Police1 = gdk_font_load(
"-*-times-medium-r-normal-*-16-*-*-*-*-*-*-*");
366 Police2 = gdk_font_load(
"-*-courier-bold-r-normal-*-*-140-*-*-*-*-*-*");
369 strcpy(this->title, title) ;
406 gdk_window_set_title(widget->window,(
char *)title);
412 "GTK not initialized")) ;
428 gtk_window_move(GTK_WINDOW(widget), winx, winy);
434 "GTK not initialized")) ;
456 gdk_draw_gray_image(background,
463 gdk_window_set_back_pixmap(widget->window, background, FALSE);
473 "GTK not initialized")) ;
502 gdk_draw_gray_image(background,
509 gdk_window_set_back_pixmap(widget->window, background, FALSE);
519 "GTK not initialized")) ;
542 gdk_draw_rgb_32_image(background,
545 (
unsigned char *)I.
bitmap,
552 gdk_window_set_back_pixmap(widget->window, background, FALSE);
563 "GTK not initialized")) ;
591 gdk_draw_rgb_32_image(background,
594 (
unsigned char *)Itemp.
bitmap,
601 gdk_window_set_back_pixmap(widget->window, background, FALSE);
611 "GTK not initialized")) ;
634 delete [] col ; col = NULL ;
639 gdk_window_hide (widget->window);
640 gdk_window_destroy(widget->window);
655 gdk_window_clear(widget->window);
662 "GTK not initialized")) ;
675 gdk_window_clear(widget->window);
682 "GTK not initialized")) ;
705 unsigned int w,
unsigned int h,
706 unsigned int thickness)
716 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon() )&&(std::fabs(b) <= std::numeric_limits<double>::epsilon()) )
752 "GTK not initialized")) ;
775 gdk_gc_set_foreground(gc, col[color.
id]);
777 gdkcolor.red = 256 * color.
R;
778 gdkcolor.green = 256 * color.
G;
779 gdkcolor.blue = 256 * color.
B;
780 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
781 gdk_gc_set_foreground(gc, &gdkcolor);
784 gdk_draw_string(background, Police2, gc,
787 (
const gchar *)text);
794 "GTK not initialized")) ;
810 unsigned int thickness )
814 if ( thickness == 1 ) thickness = 0;
817 gdk_gc_set_foreground(gc, col[color.
id]);
819 gdkcolor.red = 256 * color.
R;
820 gdkcolor.green = 256 * color.
G;
821 gdkcolor.blue = 256 * color.
B;
822 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
823 gdk_gc_set_foreground(gc, &gdkcolor);
826 gdk_gc_set_line_attributes(gc, (gint)thickness,
827 GDK_LINE_SOLID, GDK_CAP_BUTT,
831 gdk_draw_arc(background, gc, FALSE,
834 (gint)(2*radius), (gint)(2*radius), 23040, 23040) ;
836 gdk_draw_arc(background, gc, TRUE,
839 (gint)(2*radius), (gint)(2*radius), 23040, 23040) ;
845 "GTK not initialized")) ;
858 unsigned int thickness)
863 double i = ip.
get_i();
864 double j = ip.
get_j();
867 ip1.
set_i( i-size/2 );
869 ip2.
set_i( i+size/2 );
874 ip1.
set_j( j-size/2 );
876 ip2.
set_j( j+size/2 );
891 "GTK not initialized")) ;
903 unsigned int thickness )
908 if ( thickness == 1 ) thickness = 0;
911 gdk_gc_set_foreground(gc, col[color.
id]);
913 gdkcolor.red = 256 * color.
R;
914 gdkcolor.green = 256 * color.
G;
915 gdkcolor.blue = 256 * color.
B;
916 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
917 gdk_gc_set_foreground(gc, &gdkcolor);
920 gdk_gc_set_line_attributes(gc, (gint)thickness,
921 GDK_LINE_ON_OFF_DASH, GDK_CAP_BUTT,
923 gdk_draw_line(background, gc,
928 gdk_gc_set_line_attributes(gc, 0,
929 GDK_LINE_SOLID, GDK_CAP_BUTT,
936 "GTK not initialized")) ;
949 unsigned int thickness )
953 if ( thickness == 1 ) thickness = 0;
956 gdk_gc_set_foreground(gc, col[color.
id]);
958 gdkcolor.red = 256 * color.
R;
959 gdkcolor.green = 256 * color.
G;
960 gdkcolor.blue = 256 * color.
B;
961 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
962 gdk_gc_set_foreground(gc, &gdkcolor);
965 gdk_gc_set_line_attributes(gc, (gint)thickness,
966 GDK_LINE_SOLID, GDK_CAP_BUTT,
968 gdk_draw_line(background, gc,
978 "GTK not initialized")) ;
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_draw_point(background,gc,
1010 "GTK not initialized")) ;
1030 unsigned int width,
unsigned int height,
1031 const vpColor &color,
bool fill,
1032 unsigned int thickness )
1036 if ( thickness == 1 ) thickness = 0;
1039 gdk_gc_set_foreground(gc, col[color.
id]);
1041 gdkcolor.red = 256 * color.
R;
1042 gdkcolor.green = 256 * color.
G;
1043 gdkcolor.blue = 256 * color.
B;
1044 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1045 gdk_gc_set_foreground(gc, &gdkcolor);
1047 gdk_gc_set_line_attributes(gc, (gint)thickness,
1048 GDK_LINE_SOLID, GDK_CAP_BUTT,
1052 gdk_draw_rectangle(background, gc, FALSE,
1055 (gint)width-1, (gint)height-1);
1057 gdk_draw_rectangle(background, gc, TRUE,
1060 (gint)
width, (gint)height);
1063 gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1070 "GTK not initialized")) ;
1089 const vpColor &color,
bool fill,
1090 unsigned int thickness )
1094 if ( thickness == 1 ) thickness = 0;
1097 gdk_gc_set_foreground(gc, col[color.
id]);
1099 gdkcolor.red = 256 * color.
R;
1100 gdkcolor.green = 256 * color.
G;
1101 gdkcolor.blue = 256 * color.
B;
1102 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1103 gdk_gc_set_foreground(gc, &gdkcolor);
1106 gdk_gc_set_line_attributes(gc, (gint)thickness,
1107 GDK_LINE_SOLID, GDK_CAP_BUTT,
1114 gdk_draw_rectangle(background, gc, FALSE,
1119 gdk_draw_rectangle(background, gc, TRUE,
1125 gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1132 "GTK not initialized")) ;
1150 const vpColor &color,
bool fill,
1151 unsigned int thickness )
1156 gdk_gc_set_foreground(gc, col[color.
id]);
1158 gdkcolor.red = 256 * color.
R;
1159 gdkcolor.green = 256 * color.
G;
1160 gdkcolor.blue = 256 * color.
B;
1161 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1162 gdk_gc_set_foreground(gc, &gdkcolor);
1165 if ( thickness == 1 ) thickness = 0;
1167 gdk_gc_set_line_attributes(gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT,
1171 gdk_draw_rectangle(background, gc, FALSE,
1178 gdk_draw_rectangle(background, gc, TRUE,
1185 gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1192 "GTK not initialized")) ;
1221 GdkEvent *ev = NULL;
1223 while ((ev = gdk_event_get())!=NULL){
1228 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS){
1232 gdk_event_free(ev) ;
1238 }
while ( ret ==
false && blocking ==
true);
1243 "GTK not initialized")) ;
1271 GdkEvent *ev = NULL;
1274 while ((ev = gdk_event_get())!=NULL){
1275 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS) {
1276 u = ((GdkEventButton *)ev)->x ;
1277 v = ((GdkEventButton *)ev)->y ;
1282 gdk_event_free(ev) ;
1288 }
while ( ret ==
false && blocking ==
true);
1293 "GTK not initialized")) ;
1326 GdkEvent *ev = NULL;
1329 while ((ev = gdk_event_get())){
1330 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS){
1331 u = ((GdkEventButton *)ev)->x ;
1332 v = ((GdkEventButton *)ev)->y ;
1336 switch ((
int)((GdkEventButton *)ev)->button) {
1346 gdk_event_free(ev) ;
1353 }
while ( ret ==
false && blocking ==
true);
1358 "GTK not initialized")) ;
1396 GdkEvent *ev = NULL;
1399 while ((ev = gdk_event_get())!=NULL){
1400 if ( ev->any.window == widget->window
1401 && ev->type == GDK_BUTTON_RELEASE) {
1402 u = ((GdkEventButton *)ev)->x ;
1403 v = ((GdkEventButton *)ev)->y ;
1407 switch ( (
int ) ( ( GdkEventButton * ) ev )->button ) {
1417 gdk_event_free(ev) ;
1424 }
while ( ret ==
false && blocking ==
true);
1429 "GTK not initialized" ) ) ;
1451 ImageGtk = gdk_image_get(background, 0, 0, (gint)
width, (gint)
height);
1458 guchar OctetRouge,OctetVert,OctetBleu,mask;
1461 pos = (
unsigned char *)I.
bitmap;
1462 for (y=0;y<(gint)height;y++)
1464 for (x=0;x<(gint)width;x++)
1466 pixel = gdk_image_get_pixel(ImageGtk,x,y);
1467 OctetBleu = (guchar)pixel & mask;
1468 OctetVert = (guchar)(pixel>>8) & mask;
1469 OctetRouge = (guchar)(pixel>>16) & mask;
1470 *pos++ = OctetRouge;
1483 "GTK not initialized")) ;
1498 depth = (
unsigned int)gdk_window_get_visual(widget->window)->depth ;
1538 GdkEvent *ev = NULL;
1540 while ((ev = gdk_event_get())!=NULL){
1545 if (ev->any.window == widget->window && ev->type == GDK_KEY_PRESS){
1549 gdk_event_free(ev) ;
1555 }
while ( ret ==
false && blocking ==
true);
1560 "GTK not initialized")) ;
1592 GdkEvent *ev = NULL;
1594 while ((ev = gdk_event_get())!=NULL){
1599 if (ev->any.window == widget->window && ev->type == GDK_KEY_PRESS){
1601 sprintf(
string,
"%s", gdk_keyval_name (ev->key.keyval));
1605 gdk_event_free(ev) ;
1611 }
while ( ret ==
false && blocking ==
true);
1616 "GTK not initialized")) ;
1639 GdkEvent *ev = NULL;
1641 if ((ev = gdk_event_get())){
1642 if (ev->any.window == widget->window && ev->type == GDK_MOTION_NOTIFY){
1643 u = ((GdkEventMotion *)ev)->x ;
1644 v = ((GdkEventMotion *)ev)->y ;
1650 gdk_event_free(ev) ;
1656 "GTK not initialized")) ;
1677 gdk_window_get_pointer(widget->window, &u, &v, NULL);
1684 "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)
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