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>
84 : widget(NULL), background(NULL), gc(NULL),
85 blue(), red(), yellow(), green(), cyan(), orange(), white(), black(), gdkcolor(),
86 lightBlue(), darkBlue(), lightRed(), darkRed(),lightGreen(), darkGreen(),
87 purple(), lightGray(), gray(), darkGray(),
88 colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
90 init(I, x, y, title) ;
106 : widget(NULL), background(NULL), gc(NULL),
107 blue(), red(), yellow(), green(), cyan(), orange(), white(), black(), gdkcolor(),
108 lightBlue(), darkBlue(), lightRed(), darkRed(),lightGreen(), darkGreen(),
109 purple(), lightGray(), gray(), darkGray(),
110 colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
112 init(I, x, y, title) ;
140 : widget(NULL), background(NULL), gc(NULL),
141 blue(), red(), yellow(), green(), cyan(), orange(), white(), black(), gdkcolor(),
142 lightBlue(), darkBlue(), lightRed(), darkRed(),lightGreen(), darkGreen(),
143 purple(), lightGray(), gray(), darkGray(),
144 colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
150 title_ = std::string(title);
152 title_ = std::string(
" ");
175 :
vpDisplay(), widget(NULL), background(NULL), gc(NULL),
176 blue(), red(), yellow(), green(), cyan(), orange(), white(), black(), gdkcolor(),
177 lightBlue(), darkBlue(), lightRed(), darkRed(),lightGreen(), darkGreen(),
178 purple(), lightGray(), gray(), darkGray(),
179 colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
210 "Image not initialized")) ;
242 "Image not initialized")) ;
270 gtk_init(argc,&argv);
276 widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
278 gtk_widget_add_events(widget, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
279 | GDK_POINTER_MOTION_MASK);
281 gtk_window_set_default_size(GTK_WINDOW(widget), (gint)
width, (gint)
height);
290 gtk_widget_show(widget);
295 background = gdk_pixmap_new(widget->window, (gint)width, (gint)height, -1);
298 gc = gdk_gc_new(widget->window);
301 colormap = gdk_window_get_colormap(widget->window);
306 gdk_color_parse(
"light blue",&lightBlue);
307 gdk_colormap_alloc_color(colormap,&lightBlue,FALSE,TRUE);
310 gdk_color_parse(
"blue",&blue);
311 gdk_colormap_alloc_color(colormap,&blue,FALSE,TRUE);
314 gdk_color_parse(
"dark blue",&darkBlue);
315 gdk_colormap_alloc_color(colormap,&darkBlue,FALSE,TRUE);
318 gdk_color_parse(
"#FF8C8C",&lightRed);
319 gdk_colormap_alloc_color(colormap,&lightRed,FALSE,TRUE);
322 gdk_color_parse(
"red",&red);
323 gdk_colormap_alloc_color(colormap,&red,FALSE,TRUE);
326 gdk_color_parse(
"dark red",&darkRed);
327 gdk_colormap_alloc_color(colormap,&darkRed,FALSE,TRUE);
330 gdk_color_parse(
"light green",&lightGreen);
331 gdk_colormap_alloc_color(colormap,&lightGreen,FALSE,TRUE);
334 gdk_color_parse(
"green",&green);
335 gdk_colormap_alloc_color(colormap,&green,FALSE,TRUE);
338 gdk_color_parse(
"dark green",&darkGreen);
339 gdk_colormap_alloc_color(colormap,&darkGreen,FALSE,TRUE);
342 gdk_color_parse(
"yellow",&yellow);
343 gdk_colormap_alloc_color(colormap,&yellow,FALSE,TRUE);
346 gdk_color_parse(
"cyan",&cyan);
347 gdk_colormap_alloc_color(colormap,&cyan,FALSE,TRUE);
350 gdk_color_parse(
"orange",&orange);
351 gdk_colormap_alloc_color(colormap,&orange,FALSE,TRUE);
354 gdk_color_parse(
"purple",&purple);
355 gdk_colormap_alloc_color(colormap,&purple,FALSE,TRUE);
358 gdk_color_parse(
"white",&white);
359 gdk_colormap_alloc_color(colormap,&white,FALSE,TRUE);
362 gdk_color_parse(
"black",&black);
363 gdk_colormap_alloc_color(colormap,&black,FALSE,TRUE);
366 gdk_color_parse(
"#C0C0C0",&lightGray);
367 gdk_colormap_alloc_color(colormap,&lightGray,FALSE,TRUE);
370 gdk_color_parse(
"#808080",&gray);
371 gdk_colormap_alloc_color(colormap,&gray,FALSE,TRUE);
374 gdk_color_parse(
"#404040",&darkGray);
375 gdk_colormap_alloc_color(colormap,&darkGray,FALSE,TRUE);
379 font = gdk_font_load(
"-*-times-medium-r-normal-*-16-*-*-*-*-*-*-*");
381 font = gdk_font_load(
"-*-courier-bold-r-normal-*-*-140-*-*-*-*-*-*");
383 font = gdk_font_load(
"-*-courier 10 pitch-medium-r-normal-*-16-*-*-*-*-*-*-*");
386 title_ = std::string(title);
388 title_ = std::string(
" ");
391 gdk_window_set_title(widget->window,
title_.c_str());
412 font = gdk_font_load((
const gchar*)fontname);
425 title_ = std::string(title);
427 title_ = std::string(
" ");
428 gdk_window_set_title(widget->window,
title_.c_str());
434 "GTK not initialized")) ;
450 gtk_window_move(GTK_WINDOW(widget), winx, winy);
456 "GTK not initialized")) ;
478 gdk_draw_gray_image(background,
485 gdk_window_set_back_pixmap(widget->window, background, FALSE);
495 "GTK not initialized")) ;
524 gdk_draw_gray_image(background,
525 gc, (gint)iP.
get_u(), (gint)iP.
get_v(), (gint)w, (gint)h,
531 gdk_window_set_back_pixmap(widget->window, background, FALSE);
541 "GTK not initialized")) ;
564 gdk_draw_rgb_32_image(background,
567 (
unsigned char *)I.
bitmap,
574 gdk_window_set_back_pixmap(widget->window, background, FALSE);
585 "GTK not initialized")) ;
613 gdk_draw_rgb_32_image(background,
614 gc, (gint)iP.
get_u(), (gint)iP.
get_v(), (gint)w, (gint)h,
616 (
unsigned char *)Itemp.
bitmap,
623 gdk_window_set_back_pixmap(widget->window, background, FALSE);
633 "GTK not initialized")) ;
656 delete [] col ; col = NULL ;
661 gdk_window_hide (widget->window);
662 gdk_window_destroy(widget->window);
677 gdk_window_clear(widget->window);
684 "GTK not initialized")) ;
697 gdk_window_clear(widget->window);
704 "GTK not initialized")) ;
727 unsigned int w,
unsigned int h,
728 unsigned int thickness)
738 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon() )&&(std::fabs(b) <= std::numeric_limits<double>::epsilon()) )
777 "GTK not initialized")) ;
800 gdk_gc_set_foreground(gc, col[color.
id]);
802 gdkcolor.red = 256 * color.
R;
803 gdkcolor.green = 256 * color.
G;
804 gdkcolor.blue = 256 * color.
B;
805 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
806 gdk_gc_set_foreground(gc, &gdkcolor);
809 gdk_draw_string(background, font, gc,
812 (
const gchar *)text);
814 std::cout <<
"Cannot draw string: no font is selected" << std::endl;
820 "GTK not initialized")) ;
836 unsigned int thickness )
840 if ( thickness == 1 ) thickness = 0;
843 gdk_gc_set_foreground(gc, col[color.
id]);
845 gdkcolor.red = 256 * color.
R;
846 gdkcolor.green = 256 * color.
G;
847 gdkcolor.blue = 256 * color.
B;
848 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
849 gdk_gc_set_foreground(gc, &gdkcolor);
852 gdk_gc_set_line_attributes(gc, (gint)thickness,
853 GDK_LINE_SOLID, GDK_CAP_BUTT,
857 gdk_draw_arc(background, gc, FALSE,
860 (gint)(2*radius), (gint)(2*radius), 23040, 23040) ;
862 gdk_draw_arc(background, gc, TRUE,
865 (gint)(2*radius), (gint)(2*radius), 23040, 23040) ;
871 "GTK not initialized")) ;
884 unsigned int thickness)
889 double i = ip.
get_i();
890 double j = ip.
get_j();
893 ip1.
set_i( i-size/2 );
895 ip2.
set_i( i+size/2 );
900 ip1.
set_j( j-size/2 );
902 ip2.
set_j( j+size/2 );
917 "GTK not initialized")) ;
929 unsigned int thickness )
934 if ( thickness == 1 ) thickness = 0;
937 gdk_gc_set_foreground(gc, col[color.
id]);
939 gdkcolor.red = 256 * color.
R;
940 gdkcolor.green = 256 * color.
G;
941 gdkcolor.blue = 256 * color.
B;
942 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
943 gdk_gc_set_foreground(gc, &gdkcolor);
946 gdk_gc_set_line_attributes(gc, (gint)thickness,
947 GDK_LINE_ON_OFF_DASH, GDK_CAP_BUTT,
949 gdk_draw_line(background, gc,
954 gdk_gc_set_line_attributes(gc, 0,
955 GDK_LINE_SOLID, GDK_CAP_BUTT,
962 "GTK not initialized")) ;
975 unsigned int thickness )
979 if ( thickness == 1 ) thickness = 0;
982 gdk_gc_set_foreground(gc, col[color.
id]);
984 gdkcolor.red = 256 * color.
R;
985 gdkcolor.green = 256 * color.
G;
986 gdkcolor.blue = 256 * color.
B;
987 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
988 gdk_gc_set_foreground(gc, &gdkcolor);
991 gdk_gc_set_line_attributes(gc, (gint)thickness,
992 GDK_LINE_SOLID, GDK_CAP_BUTT,
994 gdk_draw_line(background, gc,
1004 "GTK not initialized")) ;
1019 gdk_gc_set_foreground(gc, col[color.
id]);
1021 gdkcolor.red = 256 * color.
R;
1022 gdkcolor.green = 256 * color.
G;
1023 gdkcolor.blue = 256 * color.
B;
1024 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1025 gdk_gc_set_foreground(gc, &gdkcolor);
1028 gdk_draw_point(background,gc,
1036 "GTK not initialized")) ;
1056 unsigned int w,
unsigned int h,
1057 const vpColor &color,
bool fill,
1058 unsigned int thickness )
1062 if ( thickness == 1 ) thickness = 0;
1065 gdk_gc_set_foreground(gc, col[color.
id]);
1067 gdkcolor.red = 256 * color.
R;
1068 gdkcolor.green = 256 * color.
G;
1069 gdkcolor.blue = 256 * color.
B;
1070 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1071 gdk_gc_set_foreground(gc, &gdkcolor);
1073 gdk_gc_set_line_attributes(gc, (gint)thickness,
1074 GDK_LINE_SOLID, GDK_CAP_BUTT,
1078 gdk_draw_rectangle(background, gc, FALSE,
1081 (gint)w-1, (gint)h-1);
1083 gdk_draw_rectangle(background, gc, TRUE,
1089 gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1096 "GTK not initialized")) ;
1115 const vpColor &color,
bool fill,
1116 unsigned int thickness )
1120 if ( thickness == 1 ) thickness = 0;
1123 gdk_gc_set_foreground(gc, col[color.
id]);
1125 gdkcolor.red = 256 * color.
R;
1126 gdkcolor.green = 256 * color.
G;
1127 gdkcolor.blue = 256 * color.
B;
1128 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1129 gdk_gc_set_foreground(gc, &gdkcolor);
1132 gdk_gc_set_line_attributes(gc, (gint)thickness,
1133 GDK_LINE_SOLID, GDK_CAP_BUTT,
1140 gdk_draw_rectangle(background, gc, FALSE,
1145 gdk_draw_rectangle(background, gc, TRUE,
1151 gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1158 "GTK not initialized")) ;
1176 const vpColor &color,
bool fill,
1177 unsigned int thickness )
1182 gdk_gc_set_foreground(gc, col[color.
id]);
1184 gdkcolor.red = 256 * color.
R;
1185 gdkcolor.green = 256 * color.
G;
1186 gdkcolor.blue = 256 * color.
B;
1187 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1188 gdk_gc_set_foreground(gc, &gdkcolor);
1191 if ( thickness == 1 ) thickness = 0;
1193 gdk_gc_set_line_attributes(gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT,
1197 gdk_draw_rectangle(background, gc, FALSE,
1204 gdk_draw_rectangle(background, gc, TRUE,
1211 gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1218 "GTK not initialized")) ;
1247 GdkEvent *ev = NULL;
1249 while ((ev = gdk_event_get())!=NULL){
1254 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS){
1258 gdk_event_free(ev) ;
1264 }
while ( ret ==
false && blocking ==
true);
1269 "GTK not initialized")) ;
1297 GdkEvent *ev = NULL;
1300 while ((ev = gdk_event_get())!=NULL){
1301 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS) {
1302 u = ((GdkEventButton *)ev)->x ;
1303 v = ((GdkEventButton *)ev)->y ;
1308 gdk_event_free(ev) ;
1314 }
while ( ret ==
false && blocking ==
true);
1319 "GTK not initialized")) ;
1352 GdkEvent *ev = NULL;
1355 while ((ev = gdk_event_get())){
1356 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS){
1357 u = ((GdkEventButton *)ev)->x ;
1358 v = ((GdkEventButton *)ev)->y ;
1362 switch ((
int)((GdkEventButton *)ev)->button) {
1372 gdk_event_free(ev) ;
1379 }
while ( ret ==
false && blocking ==
true);
1384 "GTK not initialized")) ;
1422 GdkEvent *ev = NULL;
1425 while ((ev = gdk_event_get())!=NULL){
1426 if ( ev->any.window == widget->window
1427 && ev->type == GDK_BUTTON_RELEASE) {
1428 u = ((GdkEventButton *)ev)->x ;
1429 v = ((GdkEventButton *)ev)->y ;
1433 switch ( (
int ) ( ( GdkEventButton * ) ev )->button ) {
1443 gdk_event_free(ev) ;
1450 }
while ( ret ==
false && blocking ==
true);
1455 "GTK not initialized" ) ) ;
1477 ImageGtk = gdk_image_get(background, 0, 0, (gint)
width, (gint)
height);
1484 guchar OctetRouge,OctetVert,OctetBleu,mask;
1487 pos = (
unsigned char *)I.
bitmap;
1488 for (y=0;y<(gint)height;y++)
1490 for (x=0;x<(gint)width;x++)
1492 pixel = gdk_image_get_pixel(ImageGtk,x,y);
1493 OctetBleu = (guchar)pixel & mask;
1494 OctetVert = (guchar)(pixel>>8) & mask;
1495 OctetRouge = (guchar)(pixel>>16) & mask;
1496 *pos++ = OctetRouge;
1509 "GTK not initialized")) ;
1524 depth = (
unsigned int)gdk_window_get_visual(widget->window)->depth ;
1564 GdkEvent *ev = NULL;
1566 while ((ev = gdk_event_get())!=NULL){
1571 if (ev->any.window == widget->window && ev->type == GDK_KEY_PRESS){
1575 gdk_event_free(ev) ;
1581 }
while ( ret ==
false && blocking ==
true);
1586 "GTK not initialized")) ;
1618 GdkEvent *ev = NULL;
1620 while ((ev = gdk_event_get())!=NULL){
1625 if (ev->any.window == widget->window && ev->type == GDK_KEY_PRESS){
1627 sprintf(
string,
"%s", gdk_keyval_name (ev->key.keyval));
1631 gdk_event_free(ev) ;
1637 }
while ( ret ==
false && blocking ==
true);
1642 "GTK not initialized")) ;
1665 GdkEvent *ev = NULL;
1667 if ((ev = gdk_event_get())){
1668 if (ev->any.window == widget->window && ev->type == GDK_MOTION_NOTIFY){
1669 u = ((GdkEventMotion *)ev)->x ;
1670 v = ((GdkEventMotion *)ev)->y ;
1676 gdk_event_free(ev) ;
1682 "GTK not initialized")) ;
1703 gdk_window_get_pointer(widget->window, &u, &v, NULL);
1710 "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 without initializing it.
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
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)