Visual Servoing Platform  version 3.2.1 under development (2019-08-19)
vpDisplayX.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  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
39 #ifndef vpDisplayX_h
40 #define vpDisplayX_h
41 
42 #include <visp3/core/vpConfig.h>
43 #include <visp3/core/vpDisplay.h>
44 #ifdef VISP_HAVE_X11
45 
46 // namespace X11name
47 //{
48 #include <X11/Xlib.h>
49 #include <X11/Xutil.h>
50 //#include <X11/Xatom.h>
51 //#include <X11/cursorfont.h>
52 //} ;
53 
54 // using namespace X11name ;
55 
56 // Work arround to use this class with Eigen3
57 #ifdef Success
58 #undef Success // See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=253
59 #endif
60 
61 #include <visp3/core/vpImage.h>
62 #include <visp3/core/vpRect.h>
63 
151 class VISP_EXPORT vpDisplayX : public vpDisplay
152 {
153 private:
154  Display *display;
155  Window window;
156  XImage *Ximage;
157  Colormap lut;
158  GC context;
159  int screen;
160  XEvent event;
161  Pixmap pixmap;
162  unsigned long *x_color; // Array of predefined colors
163  unsigned int screen_depth;
164  unsigned short colortable[256];
165  XColor xcolor;
166  XGCValues values;
167  bool ximage_data_init;
168  unsigned int RMask, GMask, BMask;
169  int RShift, GShift, BShift;
170 
171  // private:
172  //#ifndef DOXYGEN_SHOULD_SKIP_THIS
173  // vpDisplayX(const vpDisplayX &)
174  // : vpDisplay(), display(NULL), window(), Ximage(NULL), lut(),
175  // context(), screen(), event(), pixmap(),
176  // x_color(NULL), screen_depth(8), xcolor(), values(),
177  // ximage_data_init(false), RMask(0), GMask(0), BMask(0), RShift(0),
178  // GShift(0), BShift(0)
179  // {
180  // throw vpException(vpException::functionNotImplementedError, "Not
181  // implemented!");
182  // }
183  // vpDisplayX &operator=(const vpDisplayX &){
184  // throw vpException(vpException::functionNotImplementedError, "Not
185  // implemented!"); return *this;
186  // }
187  //#endif
188 
189 public:
190  vpDisplayX();
191  vpDisplayX(int winx, int winy, const std::string &title = "");
193  vpDisplayX(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "",
194  vpScaleType type = SCALE_DEFAULT);
196  vpDisplayX(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "",
197  vpScaleType type = SCALE_DEFAULT);
198 
199  virtual ~vpDisplayX();
200 
201  void getImage(vpImage<vpRGBa> &I);
202  unsigned int getScreenDepth();
203  unsigned int getScreenHeight();
204  void getScreenSize(unsigned int &width, unsigned int &height);
205  unsigned int getScreenWidth();
206 
207  void init(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "");
208  void init(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "");
209  void init(unsigned int width, unsigned int height, int winx = -1, int winy = -1, const std::string &title = "");
210 
211 protected:
212  void clearDisplay(const vpColor &color = vpColor::white);
213 
214  void closeDisplay();
215 
216  void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color = vpColor::white,
217  unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1);
218 
219  void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color = vpColor::green);
220 
221  void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill = false,
222  unsigned int thickness = 1);
223  void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1);
224  void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
225  unsigned int thickness = 1);
226 
227  void displayImage(const vpImage<unsigned char> &I);
228  void displayImage(const vpImage<vpRGBa> &I);
229  void displayImage(const unsigned char *I);
230 
231  void displayImageROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, const unsigned int width,
232  const unsigned int height);
233  void displayImageROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, const unsigned int width,
234  const unsigned int height);
235 
236  void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1);
237  void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1);
238 
239  void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color,
240  bool fill = false, unsigned int thickness = 1);
241  void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color,
242  bool fill = false, unsigned int thickness = 1);
243  void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1);
244 
245  void flushDisplay();
246  void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height);
247 
248  bool getClick(bool blocking = true);
249  bool getClick(vpImagePoint &ip, bool blocking = true);
250  bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true);
251  bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true);
252 
253  bool getKeyboardEvent(bool blocking = true);
254  bool getKeyboardEvent(std::string &key, bool blocking = true);
255 
256  int getMsb(unsigned int u32val);
259 
260  void setFont(const std::string &font);
261  void setTitle(const std::string &title);
262  void setWindowPosition(int winx, int winy);
263 };
264 
265 #endif
266 #endif
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
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:151
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)
static void display(const vpImage< unsigned char > &I)
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 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 displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void displayDotLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)