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>
83 : widget(NULL), m_background(NULL), m_gc(NULL),
84 blue(), red(), yellow(), green(), cyan(), orange(), white(), black(), gdkcolor(),
85 lightBlue(), darkBlue(), lightRed(), darkRed(),lightGreen(), darkGreen(),
86 purple(), lightGray(), gray(), darkGray(),
87 colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
115 : widget(NULL), m_background(NULL), m_gc(NULL),
116 blue(), red(), yellow(), green(), cyan(), orange(), white(), black(), gdkcolor(),
117 lightBlue(), darkBlue(), lightRed(), darkRed(),lightGreen(), darkGreen(),
118 purple(), lightGray(), gray(), darkGray(),
119 colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
122 init(I, x, y, title) ;
140 : widget(NULL), m_background(NULL), m_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)
170 : widget(NULL), m_background(NULL), m_gc(NULL),
171 blue(), red(), yellow(), green(), cyan(), orange(), white(), black(), gdkcolor(),
172 lightBlue(), darkBlue(), lightRed(), darkRed(),lightGreen(), darkGreen(),
173 purple(), lightGray(), gray(), darkGray(),
174 colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
177 init(I, x, y, title) ;
203 : widget(NULL), m_background(NULL), m_gc(NULL),
204 blue(), red(), yellow(), green(), cyan(), orange(), white(), black(), gdkcolor(),
205 lightBlue(), darkBlue(), lightRed(), darkRed(),lightGreen(), darkGreen(),
206 purple(), lightGray(), gray(), darkGray(),
207 colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
234 :
vpDisplay(), widget(NULL), m_background(NULL), m_gc(NULL),
235 blue(), red(), yellow(), green(), cyan(), orange(), white(), black(), gdkcolor(),
236 lightBlue(), darkBlue(), lightRed(), darkRed(),lightGreen(), darkGreen(),
237 purple(), lightGray(), gray(), darkGray(),
238 colormap(NULL), font(NULL), vectgtk(NULL), col(NULL), ncol(0), nrow(0)
263 const std::string &title)
268 "Image not initialized")) ;
299 const std::string &title)
304 "Image not initialized")) ;
332 const std::string &title)
338 gtk_init(argc, &argv);
346 widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
348 gtk_widget_add_events(widget, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
349 | GDK_POINTER_MOTION_MASK);
351 gtk_window_set_default_size(GTK_WINDOW(widget), (gint)
m_width, (gint)
m_height);
360 gtk_widget_show(widget);
365 m_background = gdk_pixmap_new(widget->window, (gint)m_width, (gint)m_height, -1);
368 m_gc = gdk_gc_new(widget->window);
371 colormap = gdk_window_get_colormap(widget->window);
376 gdk_color_parse(
"light blue",&lightBlue);
377 gdk_colormap_alloc_color(colormap,&lightBlue,FALSE,TRUE);
380 gdk_color_parse(
"blue",&blue);
381 gdk_colormap_alloc_color(colormap,&blue,FALSE,TRUE);
384 gdk_color_parse(
"dark blue",&darkBlue);
385 gdk_colormap_alloc_color(colormap,&darkBlue,FALSE,TRUE);
388 gdk_color_parse(
"#FF8C8C",&lightRed);
389 gdk_colormap_alloc_color(colormap,&lightRed,FALSE,TRUE);
392 gdk_color_parse(
"red",&red);
393 gdk_colormap_alloc_color(colormap,&red,FALSE,TRUE);
396 gdk_color_parse(
"dark red",&darkRed);
397 gdk_colormap_alloc_color(colormap,&darkRed,FALSE,TRUE);
400 gdk_color_parse(
"light green",&lightGreen);
401 gdk_colormap_alloc_color(colormap,&lightGreen,FALSE,TRUE);
404 gdk_color_parse(
"green",&green);
405 gdk_colormap_alloc_color(colormap,&green,FALSE,TRUE);
408 gdk_color_parse(
"dark green",&darkGreen);
409 gdk_colormap_alloc_color(colormap,&darkGreen,FALSE,TRUE);
412 gdk_color_parse(
"yellow",&yellow);
413 gdk_colormap_alloc_color(colormap,&yellow,FALSE,TRUE);
416 gdk_color_parse(
"cyan",&cyan);
417 gdk_colormap_alloc_color(colormap,&cyan,FALSE,TRUE);
420 gdk_color_parse(
"orange",&orange);
421 gdk_colormap_alloc_color(colormap,&orange,FALSE,TRUE);
424 gdk_color_parse(
"purple",&purple);
425 gdk_colormap_alloc_color(colormap,&purple,FALSE,TRUE);
428 gdk_color_parse(
"white",&white);
429 gdk_colormap_alloc_color(colormap,&white,FALSE,TRUE);
432 gdk_color_parse(
"black",&black);
433 gdk_colormap_alloc_color(colormap,&black,FALSE,TRUE);
436 gdk_color_parse(
"#C0C0C0",&lightGray);
437 gdk_colormap_alloc_color(colormap,&lightGray,FALSE,TRUE);
440 gdk_color_parse(
"#808080",&gray);
441 gdk_colormap_alloc_color(colormap,&gray,FALSE,TRUE);
444 gdk_color_parse(
"#404040",&darkGray);
445 gdk_colormap_alloc_color(colormap,&darkGray,FALSE,TRUE);
449 font = gdk_font_load(
"-*-times-medium-r-normal-*-16-*-*-*-*-*-*-*");
451 font = gdk_font_load(
"-*-courier-bold-r-normal-*-*-140-*-*-*-*-*-*");
453 font = gdk_font_load(
"-*-courier 10 pitch-medium-r-normal-*-16-*-*-*-*-*-*-*");
457 gdk_window_set_title(widget->window,
m_title.c_str());
480 font = gdk_font_load((
const gchar*)fontname.c_str());
494 gdk_window_set_title(widget->window,
m_title.c_str());
499 "GTK not initialized")) ;
515 gtk_window_move(GTK_WINDOW(widget), winx, winy);
520 "GTK not initialized")) ;
543 gdk_draw_gray_image(m_background,
552 gdk_draw_gray_image(m_background,
560 gdk_window_set_back_pixmap(widget->window, m_background, FALSE);
565 "GTK not initialized")) ;
598 gdk_draw_gray_image(m_background,
599 m_gc, (gint)j_min, (gint)i_min, (gint)Itemp.getWidth(), (gint)Itemp.getHeight(),
602 (gint)Itemp.getWidth());
605 gdk_window_set_back_pixmap(widget->window, m_background, FALSE);
610 "GTK not initialized")) ;
633 gdk_draw_rgb_32_image(m_background,
636 (
unsigned char *)I.
bitmap,
642 gdk_draw_rgb_32_image(m_background,
645 (
unsigned char *)sampled.
bitmap,
652 gdk_window_set_back_pixmap(widget->window, m_background, FALSE);
657 "GTK not initialized")) ;
689 gdk_draw_rgb_32_image(m_background,
690 m_gc, (gint)j_min, (gint)i_min, (gint)Itemp.getWidth(), (gint)Itemp.getHeight(),
692 (
unsigned char *)Itemp.bitmap,
693 (gint)Itemp.getWidth()*4);
696 gdk_window_set_back_pixmap(widget->window, m_background, FALSE);
701 "GTK not initialized")) ;
724 delete [] col ; col = NULL ;
729 gdk_window_hide (widget->window);
730 gdk_window_destroy(widget->window);
731 gtk_widget_destroy(widget);
746 gdk_window_clear(widget->window);
752 "GTK not initialized")) ;
765 gdk_window_clear(widget->window);
771 "GTK not initialized")) ;
794 unsigned int w,
unsigned int h,
795 unsigned int thickness)
804 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon() )&&(std::fabs(b) <= std::numeric_limits<double>::epsilon()) )
836 "GTK not initialized")) ;
859 gdk_gc_set_foreground(m_gc, col[color.
id]);
861 gdkcolor.red = 256 * color.
R;
862 gdkcolor.green = 256 * color.
G;
863 gdkcolor.blue = 256 * color.
B;
864 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
865 gdk_gc_set_foreground(m_gc, &gdkcolor);
868 gdk_draw_string(m_background, font, m_gc,
871 (
const gchar *)text);
873 std::cout <<
"Cannot draw string: no font is selected" << std::endl;
878 "GTK not initialized")) ;
894 unsigned int thickness )
898 if ( thickness == 1 ) thickness = 0;
901 gdk_gc_set_foreground(m_gc, col[color.
id]);
903 gdkcolor.red = 256 * color.
R;
904 gdkcolor.green = 256 * color.
G;
905 gdkcolor.blue = 256 * color.
B;
906 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
907 gdk_gc_set_foreground(m_gc, &gdkcolor);
910 gdk_gc_set_line_attributes(m_gc, (gint)thickness,
911 GDK_LINE_SOLID, GDK_CAP_BUTT,
915 gdk_draw_arc(m_background, m_gc, FALSE,
918 (gint)(2.*radius/
m_scale), (gint)(2.*radius/
m_scale), 23040, 23040) ;
920 gdk_draw_arc(m_background, m_gc, TRUE,
923 (gint)(2.*radius/
m_scale), (gint)(2.*radius/
m_scale), 23040, 23040) ;
928 "GTK not initialized")) ;
941 unsigned int thickness)
945 double i = ip.
get_i();
946 double j = ip.
get_j();
949 ip1.
set_i( i-size/2 );
951 ip2.
set_i( i+size/2 );
956 ip1.
set_j( j-size/2 );
958 ip2.
set_j( j+size/2 );
966 "GTK not initialized")) ;
978 unsigned int thickness )
983 if ( thickness == 1 ) thickness = 0;
986 gdk_gc_set_foreground(m_gc, col[color.
id]);
988 gdkcolor.red = 256 * color.
R;
989 gdkcolor.green = 256 * color.
G;
990 gdkcolor.blue = 256 * color.
B;
991 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
992 gdk_gc_set_foreground(m_gc, &gdkcolor);
995 gdk_gc_set_line_attributes(m_gc, (gint)thickness,
996 GDK_LINE_ON_OFF_DASH, GDK_CAP_BUTT,
998 gdk_draw_line(m_background, m_gc,
1003 gdk_gc_set_line_attributes(m_gc, 0,
1004 GDK_LINE_SOLID, GDK_CAP_BUTT,
1010 "GTK not initialized")) ;
1023 unsigned int thickness )
1027 if ( thickness == 1 ) thickness = 0;
1030 gdk_gc_set_foreground(m_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(m_gc, &gdkcolor);
1039 gdk_gc_set_line_attributes(m_gc, (gint)thickness,
1040 GDK_LINE_SOLID, GDK_CAP_BUTT,
1042 gdk_draw_line(m_background, m_gc,
1051 "GTK not initialized")) ;
1066 gdk_gc_set_foreground(m_gc, col[color.
id]);
1068 gdkcolor.red = 256 * color.
R;
1069 gdkcolor.green = 256 * color.
G;
1070 gdkcolor.blue = 256 * color.
B;
1071 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1072 gdk_gc_set_foreground(m_gc, &gdkcolor);
1075 if (thickness == 1) {
1076 gdk_draw_point(m_background, m_gc,
1081 gdk_draw_rectangle( m_background, m_gc, TRUE,
1084 thickness, thickness );
1090 "GTK not initialized")) ;
1110 unsigned int w,
unsigned int h,
1111 const vpColor &color,
bool fill,
1112 unsigned int thickness )
1116 if ( thickness == 1 ) thickness = 0;
1119 gdk_gc_set_foreground(m_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(m_gc, &gdkcolor);
1127 gdk_gc_set_line_attributes(m_gc, (gint)thickness,
1128 GDK_LINE_SOLID, GDK_CAP_BUTT,
1132 gdk_draw_rectangle(m_background, m_gc, FALSE,
1137 gdk_draw_rectangle(m_background, m_gc, TRUE,
1143 gdk_gc_set_line_attributes(m_gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1149 "GTK not initialized")) ;
1168 const vpColor &color,
bool fill,
1169 unsigned int thickness )
1173 if ( thickness == 1 ) thickness = 0;
1176 gdk_gc_set_foreground(m_gc, col[color.
id]);
1178 gdkcolor.red = 256 * color.
R;
1179 gdkcolor.green = 256 * color.
G;
1180 gdkcolor.blue = 256 * color.
B;
1181 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1182 gdk_gc_set_foreground(m_gc, &gdkcolor);
1185 gdk_gc_set_line_attributes(m_gc, (gint)thickness,
1186 GDK_LINE_SOLID, GDK_CAP_BUTT,
1193 gdk_draw_rectangle(m_background, m_gc, FALSE,
1198 gdk_draw_rectangle(m_background, m_gc, TRUE,
1204 gdk_gc_set_line_attributes(m_gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1210 "GTK not initialized")) ;
1228 const vpColor &color,
bool fill,
1229 unsigned int thickness )
1234 gdk_gc_set_foreground(m_gc, col[color.
id]);
1236 gdkcolor.red = 256 * color.
R;
1237 gdkcolor.green = 256 * color.
G;
1238 gdkcolor.blue = 256 * color.
B;
1239 gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
1240 gdk_gc_set_foreground(m_gc, &gdkcolor);
1243 if ( thickness == 1 ) thickness = 0;
1245 gdk_gc_set_line_attributes(m_gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT,
1249 gdk_draw_rectangle(m_background, m_gc, FALSE,
1256 gdk_draw_rectangle(m_background, m_gc, TRUE,
1263 gdk_gc_set_line_attributes(m_gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
1269 "GTK not initialized")) ;
1299 GdkEvent *ev = NULL;
1300 while ((ev = gdk_event_get())!=NULL){
1305 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS){
1309 gdk_event_free(ev) ;
1315 }
while ( ret ==
false && blocking ==
true);
1319 "GTK not initialized")) ;
1349 GdkEvent *ev = NULL;
1350 while ((ev = gdk_event_get())!=NULL){
1351 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS) {
1352 u = ((GdkEventButton *)ev)->x ;
1353 v = ((GdkEventButton *)ev)->y ;
1355 ip.
set_v( v*m_scale );
1358 gdk_event_free(ev) ;
1364 }
while ( ret ==
false && blocking ==
true);
1368 "GTK not initialized")) ;
1403 GdkEvent *ev = NULL;
1404 while ((ev = gdk_event_get())){
1405 if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS){
1406 u = ((GdkEventButton *)ev)->x ;
1407 v = ((GdkEventButton *)ev)->y ;
1409 ip.
set_v( v*m_scale );
1411 switch ((
int)((GdkEventButton *)ev)->button) {
1421 gdk_event_free(ev) ;
1428 }
while ( ret ==
false && blocking ==
true);
1432 "GTK not initialized")) ;
1472 GdkEvent *ev = NULL;
1473 while ((ev = gdk_event_get())!=NULL){
1474 if ( ev->any.window == widget->window
1475 && ev->type == GDK_BUTTON_RELEASE) {
1476 u = ((GdkEventButton *)ev)->x ;
1477 v = ((GdkEventButton *)ev)->y ;
1479 ip.
set_v( v*m_scale );
1481 switch ( (
int ) ( ( GdkEventButton * ) ev )->button ) {
1491 gdk_event_free(ev) ;
1498 }
while ( ret ==
false && blocking ==
true);
1502 "GTK not initialized" ) ) ;
1521 ImageGtk = gdk_image_get(m_background, 0, 0, (gint)
m_width, (gint)
m_height);
1523 I.
resize(m_height, m_width) ;
1526 guchar OctetRouge,OctetVert,OctetBleu,mask;
1529 for (y=0;y<(gint)m_height;y++)
1531 for (x=0;x<(gint)m_width;x++)
1533 pixel = gdk_image_get_pixel(ImageGtk,x,y);
1534 OctetBleu = (guchar)pixel & mask;
1535 OctetVert = (guchar)(pixel>>8) & mask;
1536 OctetRouge = (guchar)(pixel>>16) & mask;
1537 I[y][x].R = OctetRouge;
1538 I[y][x].G = OctetVert;
1539 I[y][x].B = OctetBleu;
1547 "GTK not initialized")) ;
1562 depth = (
unsigned int)gdk_window_get_visual(widget->window)->depth ;
1591 GdkEvent *ev = NULL;
1592 while ((ev = gdk_event_get())!=NULL){
1597 if (ev->any.window == widget->window && ev->type == GDK_KEY_PRESS){
1601 gdk_event_free(ev) ;
1607 }
while ( ret ==
false && blocking ==
true);
1611 "GTK not initialized")) ;
1644 GdkEvent *ev = NULL;
1645 while ((ev = gdk_event_get())!=NULL){
1650 if (ev->any.window == widget->window && ev->type == GDK_KEY_PRESS){
1652 key = gdk_keyval_name (ev->key.keyval);
1656 gdk_event_free(ev) ;
1662 }
while ( ret ==
false && blocking ==
true);
1666 "GTK not initialized")) ;
1689 GdkEvent *ev = NULL;
1690 if ((ev = gdk_event_get())){
1691 if (ev->any.window == widget->window && ev->type == GDK_MOTION_NOTIFY){
1692 double u = ((GdkEventMotion *)ev)->x ;
1693 double v = ((GdkEventMotion *)ev)->y ;
1695 ip.
set_v( v*m_scale );
1699 gdk_event_free(ev) ;
1704 "GTK not initialized")) ;
1725 gdk_window_get_pointer(widget->window, &u, &v, NULL);
1727 ip.
set_v( v*m_scale );
1731 "GTK not initialized")) ;
1749 gtk_init(argc, &argv);
1751 GtkWidget *widget_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1752 gtk_window_set_default_size(GTK_WINDOW(widget_), 100, 100);
1753 gtk_widget_show(widget_);
1755 GdkScreen *screen_ = gdk_window_get_screen(widget_->window);
1756 w = (
unsigned int)gdk_screen_get_width(screen_);
1757 h = (
unsigned int)gdk_screen_get_height(screen_);
1758 gtk_widget_destroy(widget_);
1761 GdkScreen *screen_ = gdk_window_get_screen(widget->window);
1762 w = (
unsigned int)gdk_screen_get_width(screen_);
1763 h = (
unsigned int)gdk_screen_get_height(screen_);
1773 unsigned int width, height;
1783 unsigned int width, height;
1788 #elif !defined(VISP_BUILD_SHARED_LIBS)
1790 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)
int m_windowYPosition
display position
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 displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
unsigned char G
Green component.
bool m_displayHasBeenInitialized
display has been initialized
static int round(const double x)
void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height)
void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
void set_i(const double ii)
int m_windowXPosition
display position
void setScale(vpScaleType scaleType, unsigned int width, 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 resize(const unsigned int h, const unsigned int w)
resize the image : Image initialization
void displayImage(const vpImage< vpRGBa > &I)
unsigned int getScreenWidth()
bool getPointerMotionEvent(vpImagePoint &ip)
void getScreenSize(unsigned int &width, unsigned int &height)
void setTitle(const std::string &title)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
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 subsample(unsigned int v_scale, unsigned int h_scale, vpImage< Type > &sampled) const
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 setFont(const std::string &fontname)
void setWindowPosition(int winx, int winy)
vpScaleType
Values that could be applied to a display to down scale the size of the display.
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.
unsigned int getScreenHeight()
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 ...
bool getKeyboardEvent(bool blocking=true)
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)