Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
vpDisplayGTK.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Image display.
33  *
34  * Authors:
35  * Christophe Collewet
36  * Eric Marchand
37  *
38  *****************************************************************************/
39 
40 #ifndef vpDisplayGTK_h
41 #define vpDisplayGTK_h
42 
43 #include <visp3/core/vpConfig.h>
44 #if (defined(VISP_HAVE_GTK))
45 
46 #include <visp3/core/vpDisplay.h>
47 #include <visp3/core/vpImage.h>
48 
49 #include <gdk/gdkrgb.h>
50 #include <gtk/gtk.h>
51 
138 class VISP_EXPORT vpDisplayGTK : public vpDisplay
139 {
140 private:
142  GtkWidget *widget;
143  GdkPixmap *m_background;
144  GdkGC *m_gc;
145  GdkColor blue, red, yellow, green, cyan, orange, white, black, gdkcolor, lightBlue, darkBlue, lightRed, darkRed,
146  lightGreen, darkGreen, purple, lightGray, gray, darkGray;
147  GdkColormap *colormap;
148 
149  GdkFont *font;
150  guchar *vectgtk;
151  GdkColor **col;
152  int ncol, nrow;
153 
154  typedef enum {
155  id_black = 0,
156  id_white,
157  id_lightGray,
158  id_gray,
159  id_darkGray,
160  id_lightRed,
161  id_red,
162  id_darkRed,
163  id_lightGreen,
164  id_green,
165  id_darkGreen,
166  id_lightBlue,
167  id_blue,
168  id_darkBlue,
169  id_yellow,
170  id_cyan,
171  id_orange,
172  id_purple,
173  id_npredefined // Number of predefined colors
174  } vpColorIdentifier;
175 
176 public:
177  vpDisplayGTK();
178  vpDisplayGTK(int winx, int winy, const std::string &title = "");
180  vpDisplayGTK(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "",
181  vpScaleType type = SCALE_DEFAULT);
183  vpDisplayGTK(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "",
184  vpScaleType type = SCALE_DEFAULT);
185 
186  virtual ~vpDisplayGTK();
187 
188  void getImage(vpImage<vpRGBa> &I);
189  unsigned int getScreenDepth();
190  unsigned int getScreenHeight();
191  void getScreenSize(unsigned int &width, unsigned int &height);
192  unsigned int getScreenWidth();
193 
194  void init(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "");
195  void init(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "");
196  void init(unsigned int width, unsigned int height, int winx = -1, int winy = -1, const std::string &title = "");
197 
198 protected:
199  void setFont(const std::string &fontname);
200  void setTitle(const std::string &title);
201  void setWindowPosition(int winx, int winy);
202 
203  void clearDisplay(const vpColor &color = vpColor::white);
204 
205  void closeDisplay();
206 
207  void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color = vpColor::white,
208  unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1);
209  void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color = vpColor::green);
210 
211  void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill = false,
212  unsigned int thickness = 1);
213  void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1);
214  void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
215  unsigned int thickness = 1);
216 
217  void displayImage(const vpImage<vpRGBa> &I);
218  void displayImage(const vpImage<unsigned char> &I);
219  void displayImage(const unsigned char *I);
220 
221  void displayImageROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, const unsigned int width,
222  const unsigned int height);
223  void displayImageROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, const unsigned int width,
224  const unsigned int height);
225 
226  void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1);
227 
228  void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1);
229  void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color,
230  bool fill = false, unsigned int thickness = 1);
231  void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color,
232  bool fill = false, unsigned int thickness = 1);
233  void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1);
234 
235  void flushDisplay();
236  void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height);
237 
238  bool getClick(bool blocking = true);
239  bool getClick(vpImagePoint &ip, bool blocking = true);
240  bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true);
241  bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true);
242  bool getKeyboardEvent(bool blocking = true);
243  bool getKeyboardEvent(std::string &key, bool blocking = true);
246 };
247 
248 #endif
249 #endif
250 
251 /*
252  * Local variables:
253  * c-basic-offset: 2
254  * End:
255  */
Class that defines generic functionnalities for display.
Definition: vpDisplay.h:171
static bool getPointerPosition(const vpImage< unsigned char > &I, vpImagePoint &ip)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static bool getPointerMotionEvent(const vpImage< unsigned char > &I, vpImagePoint &ip)
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
static bool getClickUp(const vpImage< unsigned char > &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
static const vpColor green
Definition: vpColor.h:183
static void setFont(const vpImage< unsigned char > &I, const std::string &font)
static void displayArrow(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:138
static void displayRectangle(const vpImage< unsigned char > &I, const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:144
static void displayCircle(const vpImage< unsigned char > &I, const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void setWindowPosition(const vpImage< unsigned char > &I, int winx, int winy)
Defines a rectangle in the plane.
Definition: vpRect.h:78
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
static bool getKeyboardEvent(const vpImage< unsigned char > &I, bool blocking=true)
static void displayCharString(const vpImage< unsigned char > &I, const vpImagePoint &ip, const char *string, const vpColor &color)
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)
static const vpColor white
Definition: vpColor.h:175
static void displayDotLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)