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/vpMath.h>
64 #include <visp3/core/vpImageTools.h>
80 : widget(NULL), background(NULL), gc(NULL),
81 blue(), red(), yellow(), green(), cyan(), orange(), white(), black(), gdkcolor(),
82 lightBlue(), darkBlue(), lightRed(), darkRed(),lightGreen(), darkGreen(),
83 purple(), lightGray(), gray(), darkGray(),
84 colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
86 init(I, x, y, title) ;
102 : widget(NULL), background(NULL), gc(NULL),
103 blue(), red(), yellow(), green(), cyan(), orange(), white(), black(), gdkcolor(),
104 lightBlue(), darkBlue(), lightRed(), darkRed(),lightGreen(), darkGreen(),
105 purple(), lightGray(), gray(), darkGray(),
106 colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
108 init(I, x, y, title) ;
136 : widget(NULL), background(NULL), gc(NULL),
137 blue(), red(), yellow(), green(), cyan(), orange(), white(), black(), gdkcolor(),
138 lightBlue(), darkBlue(), lightRed(), darkRed(),lightGreen(), darkGreen(),
139 purple(), lightGray(), gray(), darkGray(),
140 colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
146 title_ = std::string(title);
148 title_ = std::string(
" ");
171 :
vpDisplay(), widget(NULL), background(NULL), gc(NULL),
172 blue(), red(), yellow(), green(), cyan(), orange(), white(), black(), gdkcolor(),
173 lightBlue(), darkBlue(), lightRed(), darkRed(),lightGreen(), darkGreen(),
174 purple(), lightGray(), gray(), darkGray(),
175 colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
206 "Image not initialized")) ;
238 "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);
286 gtk_widget_show(widget);
291 background = gdk_pixmap_new(widget->window, (gint)width, (gint)height, -1);
294 gc = gdk_gc_new(widget->window);
297 colormap = gdk_window_get_colormap(widget->window);
302 gdk_color_parse(
"light blue",&lightBlue);
303 gdk_colormap_alloc_color(colormap,&lightBlue,FALSE,TRUE);
306 gdk_color_parse(
"blue",&blue);
307 gdk_colormap_alloc_color(colormap,&blue,FALSE,TRUE);
310 gdk_color_parse(
"dark blue",&darkBlue);
311 gdk_colormap_alloc_color(colormap,&darkBlue,FALSE,TRUE);
314 gdk_color_parse(
"#FF8C8C",&lightRed);
315 gdk_colormap_alloc_color(colormap,&lightRed,FALSE,TRUE);
318 gdk_color_parse(
"red",&red);
319 gdk_colormap_alloc_color(colormap,&red,FALSE,TRUE);
322 gdk_color_parse(
"dark red",&darkRed);
323 gdk_colormap_alloc_color(colormap,&darkRed,FALSE,TRUE);
326 gdk_color_parse(
"light green",&lightGreen);
327 gdk_colormap_alloc_color(colormap,&lightGreen,FALSE,TRUE);
330 gdk_color_parse(
"green",&green);
331 gdk_colormap_alloc_color(colormap,&green,FALSE,TRUE);
334 gdk_color_parse(
"dark green",&darkGreen);
335 gdk_colormap_alloc_color(colormap,&darkGreen,FALSE,TRUE);
338 gdk_color_parse(
"yellow",&yellow);
339 gdk_colormap_alloc_color(colormap,&yellow,FALSE,TRUE);
342 gdk_color_parse(
"cyan",&cyan);
343 gdk_colormap_alloc_color(colormap,&cyan,FALSE,TRUE);
346 gdk_color_parse(
"orange",&orange);
347 gdk_colormap_alloc_color(colormap,&orange,FALSE,TRUE);
350 gdk_color_parse(
"purple",&purple);
351 gdk_colormap_alloc_color(colormap,&purple,FALSE,TRUE);
354 gdk_color_parse(
"white",&white);
355 gdk_colormap_alloc_color(colormap,&white,FALSE,TRUE);
358 gdk_color_parse(
"black",&black);
359 gdk_colormap_alloc_color(colormap,&black,FALSE,TRUE);
362 gdk_color_parse(
"#C0C0C0",&lightGray);
363 gdk_colormap_alloc_color(colormap,&lightGray,FALSE,TRUE);
366 gdk_color_parse(
"#808080",&gray);
367 gdk_colormap_alloc_color(colormap,&gray,FALSE,TRUE);
370 gdk_color_parse(
"#404040",&darkGray);
371 gdk_colormap_alloc_color(colormap,&darkGray,FALSE,TRUE);
375 font = gdk_font_load(
"-*-times-medium-r-normal-*-16-*-*-*-*-*-*-*");
377 font = gdk_font_load(
"-*-courier-bold-r-normal-*-*-140-*-*-*-*-*-*");
379 font = gdk_font_load(
"-*-courier 10 pitch-medium-r-normal-*-16-*-*-*-*-*-*-*");
382 title_ = std::string(title);
384 title_ = std::string(
" ");
387 gdk_window_set_title(widget->window,
title_.c_str());
408 font = gdk_font_load((
const gchar*)fontname);
421 title_ = std::string(title);
423 title_ = std::string(
" ");
424 gdk_window_set_title(widget->window,
title_.c_str());
430 "GTK not initialized")) ;
446 gtk_window_move(GTK_WINDOW(widget), winx, winy);
452 "GTK not initialized")) ;
474 gdk_draw_gray_image(background,
481 gdk_window_set_back_pixmap(widget->window, background, FALSE);
491 "GTK not initialized")) ;
520 gdk_draw_gray_image(background,
521 gc, (gint)iP.
get_u(), (gint)iP.
get_v(), (gint)w, (gint)h,
527 gdk_window_set_back_pixmap(widget->window, background, FALSE);
537 "GTK not initialized")) ;
560 gdk_draw_rgb_32_image(background,
563 (
unsigned char *)I.
bitmap,
570 gdk_window_set_back_pixmap(widget->window, background, FALSE);
581 "GTK not initialized")) ;
609 gdk_draw_rgb_32_image(background,
610 gc, (gint)iP.
get_u(), (gint)iP.
get_v(), (gint)w, (gint)h,
612 (
unsigned char *)Itemp.
bitmap,
619 gdk_window_set_back_pixmap(widget->window, background, FALSE);
629 "GTK not initialized")) ;
652 delete [] col ; col = NULL ;
657 gdk_window_hide (widget->window);
658 gdk_window_destroy(widget->window);
673 gdk_window_clear(widget->window);
680 "GTK not initialized")) ;
693 gdk_window_clear(widget->window);
700 "GTK not initialized")) ;
723 unsigned int w,
unsigned int h,
724 unsigned int thickness)
734 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon() )&&(std::fabs(b) <= std::numeric_limits<double>::epsilon()) )
773 "GTK not initialized")) ;
796 gdk_gc_set_foreground(gc, col[color.
id]);
798 gdkcolor.red = 256 * color.
R;
799 gdkcolor.green = 256 * color.
G;
800 gdkcolor.blue = 256 * color.
B;
801 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
802 gdk_gc_set_foreground(gc, &gdkcolor);
805 gdk_draw_string(background, font, gc,
808 (
const gchar *)text);
810 std::cout <<
"Cannot draw string: no font is selected" << std::endl;
816 "GTK not initialized")) ;
832 unsigned int thickness )
836 if ( thickness == 1 ) thickness = 0;
839 gdk_gc_set_foreground(gc, col[color.
id]);
841 gdkcolor.red = 256 * color.
R;
842 gdkcolor.green = 256 * color.
G;
843 gdkcolor.blue = 256 * color.
B;
844 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
845 gdk_gc_set_foreground(gc, &gdkcolor);
848 gdk_gc_set_line_attributes(gc, (gint)thickness,
849 GDK_LINE_SOLID, GDK_CAP_BUTT,
853 gdk_draw_arc(background, gc, FALSE,
856 (gint)(2*radius), (gint)(2*radius), 23040, 23040) ;
858 gdk_draw_arc(background, gc, TRUE,
861 (gint)(2*radius), (gint)(2*radius), 23040, 23040) ;
867 "GTK not initialized")) ;
880 unsigned int thickness)
885 double i = ip.
get_i();
886 double j = ip.
get_j();
889 ip1.
set_i( i-size/2 );
891 ip2.
set_i( i+size/2 );
896 ip1.
set_j( j-size/2 );
898 ip2.
set_j( j+size/2 );
913 "GTK not initialized")) ;
925 unsigned int thickness )
930 if ( thickness == 1 ) thickness = 0;
933 gdk_gc_set_foreground(gc, col[color.
id]);
935 gdkcolor.red = 256 * color.
R;
936 gdkcolor.green = 256 * color.
G;
937 gdkcolor.blue = 256 * color.
B;
938 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
939 gdk_gc_set_foreground(gc, &gdkcolor);
942 gdk_gc_set_line_attributes(gc, (gint)thickness,
943 GDK_LINE_ON_OFF_DASH, GDK_CAP_BUTT,
945 gdk_draw_line(background, gc,
950 gdk_gc_set_line_attributes(gc, 0,
951 GDK_LINE_SOLID, GDK_CAP_BUTT,
958 "GTK not initialized")) ;
971 unsigned int thickness )
975 if ( thickness == 1 ) thickness = 0;
978 gdk_gc_set_foreground(gc, col[color.
id]);
980 gdkcolor.red = 256 * color.
R;
981 gdkcolor.green = 256 * color.
G;
982 gdkcolor.blue = 256 * color.
B;
983 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
984 gdk_gc_set_foreground(gc, &gdkcolor);
987 gdk_gc_set_line_attributes(gc, (gint)thickness,
988 GDK_LINE_SOLID, GDK_CAP_BUTT,
990 gdk_draw_line(background, gc,
1000 "GTK not initialized")) ;
1015 gdk_gc_set_foreground(gc, col[color.
id]);
1017 gdkcolor.red = 256 * color.
R;
1018 gdkcolor.green = 256 * color.
G;
1019 gdkcolor.blue = 256 * color.
B;
1020 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1021 gdk_gc_set_foreground(gc, &gdkcolor);
1024 gdk_draw_point(background,gc,
1032 "GTK not initialized")) ;
1052 unsigned int w,
unsigned int h,
1053 const vpColor &color,
bool fill,
1054 unsigned int thickness )
1058 if ( thickness == 1 ) thickness = 0;
1061 gdk_gc_set_foreground(gc, col[color.
id]);
1063 gdkcolor.red = 256 * color.
R;
1064 gdkcolor.green = 256 * color.
G;
1065 gdkcolor.blue = 256 * color.
B;
1066 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1067 gdk_gc_set_foreground(gc, &gdkcolor);
1069 gdk_gc_set_line_attributes(gc, (gint)thickness,
1070 GDK_LINE_SOLID, GDK_CAP_BUTT,
1074 gdk_draw_rectangle(background, gc, FALSE,
1077 (gint)w-1, (gint)h-1);
1079 gdk_draw_rectangle(background, gc, TRUE,
1085 gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1092 "GTK not initialized")) ;
1111 const vpColor &color,
bool fill,
1112 unsigned int thickness )
1116 if ( thickness == 1 ) thickness = 0;
1119 gdk_gc_set_foreground(gc, col[color.
id]);
1121 gdkcolor.red = 256 * color.
R;
1122 gdkcolor.green = 256 * color.
G;
1123 gdkcolor.blue = 256 * color.
B;
1124 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1125 gdk_gc_set_foreground(gc, &gdkcolor);
1128 gdk_gc_set_line_attributes(gc, (gint)thickness,
1129 GDK_LINE_SOLID, GDK_CAP_BUTT,
1136 gdk_draw_rectangle(background, gc, FALSE,
1141 gdk_draw_rectangle(background, gc, TRUE,
1147 gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1154 "GTK not initialized")) ;
1172 const vpColor &color,
bool fill,
1173 unsigned int thickness )
1178 gdk_gc_set_foreground(gc, col[color.
id]);
1180 gdkcolor.red = 256 * color.
R;
1181 gdkcolor.green = 256 * color.
G;
1182 gdkcolor.blue = 256 * color.
B;
1183 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1184 gdk_gc_set_foreground(gc, &gdkcolor);
1187 if ( thickness == 1 ) thickness = 0;
1189 gdk_gc_set_line_attributes(gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT,
1193 gdk_draw_rectangle(background, gc, FALSE,
1200 gdk_draw_rectangle(background, gc, TRUE,
1207 gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1214 "GTK not initialized")) ;
1243 GdkEvent *ev = NULL;
1245 while ((ev = gdk_event_get())!=NULL){
1250 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS){
1254 gdk_event_free(ev) ;
1260 }
while ( ret ==
false && blocking ==
true);
1265 "GTK not initialized")) ;
1293 GdkEvent *ev = NULL;
1296 while ((ev = gdk_event_get())!=NULL){
1297 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS) {
1298 u = ((GdkEventButton *)ev)->x ;
1299 v = ((GdkEventButton *)ev)->y ;
1304 gdk_event_free(ev) ;
1310 }
while ( ret ==
false && blocking ==
true);
1315 "GTK not initialized")) ;
1348 GdkEvent *ev = NULL;
1351 while ((ev = gdk_event_get())){
1352 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS){
1353 u = ((GdkEventButton *)ev)->x ;
1354 v = ((GdkEventButton *)ev)->y ;
1358 switch ((
int)((GdkEventButton *)ev)->button) {
1368 gdk_event_free(ev) ;
1375 }
while ( ret ==
false && blocking ==
true);
1380 "GTK not initialized")) ;
1418 GdkEvent *ev = NULL;
1421 while ((ev = gdk_event_get())!=NULL){
1422 if ( ev->any.window == widget->window
1423 && ev->type == GDK_BUTTON_RELEASE) {
1424 u = ((GdkEventButton *)ev)->x ;
1425 v = ((GdkEventButton *)ev)->y ;
1429 switch ( (
int ) ( ( GdkEventButton * ) ev )->button ) {
1439 gdk_event_free(ev) ;
1446 }
while ( ret ==
false && blocking ==
true);
1451 "GTK not initialized" ) ) ;
1473 ImageGtk = gdk_image_get(background, 0, 0, (gint)
width, (gint)
height);
1480 guchar OctetRouge,OctetVert,OctetBleu,mask;
1483 pos = (
unsigned char *)I.
bitmap;
1484 for (y=0;y<(gint)height;y++)
1486 for (x=0;x<(gint)width;x++)
1488 pixel = gdk_image_get_pixel(ImageGtk,x,y);
1489 OctetBleu = (guchar)pixel & mask;
1490 OctetVert = (guchar)(pixel>>8) & mask;
1491 OctetRouge = (guchar)(pixel>>16) & mask;
1492 *pos++ = OctetRouge;
1505 "GTK not initialized")) ;
1520 depth = (
unsigned int)gdk_window_get_visual(widget->window)->depth ;
1560 GdkEvent *ev = NULL;
1562 while ((ev = gdk_event_get())!=NULL){
1567 if (ev->any.window == widget->window && ev->type == GDK_KEY_PRESS){
1571 gdk_event_free(ev) ;
1577 }
while ( ret ==
false && blocking ==
true);
1582 "GTK not initialized")) ;
1614 GdkEvent *ev = NULL;
1616 while ((ev = gdk_event_get())!=NULL){
1621 if (ev->any.window == widget->window && ev->type == GDK_KEY_PRESS){
1623 sprintf(
string,
"%s", gdk_keyval_name (ev->key.keyval));
1627 gdk_event_free(ev) ;
1633 }
while ( ret ==
false && blocking ==
true);
1638 "GTK not initialized")) ;
1661 GdkEvent *ev = NULL;
1663 if ((ev = gdk_event_get())){
1664 if (ev->any.window == widget->window && ev->type == GDK_MOTION_NOTIFY){
1665 u = ((GdkEventMotion *)ev)->x ;
1666 v = ((GdkEventMotion *)ev)->y ;
1672 gdk_event_free(ev) ;
1678 "GTK not initialized")) ;
1699 gdk_window_get_pointer(widget->window, &u, &v, NULL);
1706 "GTK not initialized")) ;
1712 #elif !defined(VISP_BUILD_SHARED_LIBS)
1714 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)
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 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)