Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpDisplayX.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Image display.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
38 #ifndef vpDisplayX_h
39 #define vpDisplayX_h
40 
41 #include <visp3/core/vpConfig.h>
42 #include <visp3/core/vpDisplay.h>
43 #ifdef VISP_HAVE_X11
44 
45 //namespace X11name
46 //{
47 #include <X11/Xlib.h>
48 #include <X11/Xutil.h>
49 //#include <X11/Xatom.h>
50 //#include <X11/cursorfont.h>
51 //} ;
52 
53 //using namespace X11name ;
54 
55 // Work arround to use this class with Eigen3
56 #ifdef Success
57 # undef Success // See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=253
58 #endif
59 
60 #include <visp3/core/vpImage.h>
61 #include <visp3/core/vpRect.h>
62 
63 
64 
153 class VISP_EXPORT vpDisplayX: public vpDisplay
154 {
155 private:
156  Display *display ;
157  Window window ;
158  XImage *Ximage ;
159  Colormap lut ;
160  GC context ;
161  int screen ;
162  XEvent event;
163  Pixmap pixmap;
164  unsigned long *x_color; // Array of predefined colors
165  unsigned int screen_depth ;
166  unsigned short colortable[256];
167  XColor xcolor;
168  XGCValues values;
169  bool ximage_data_init;
170  unsigned int RMask, GMask, BMask;
171  int RShift, GShift, BShift;
172 
173  //private:
174  //#ifndef DOXYGEN_SHOULD_SKIP_THIS
175  // vpDisplayX(const vpDisplayX &)
176  // : vpDisplay(), display(NULL), window(), Ximage(NULL), lut(), context(), screen(), event(), pixmap(),
177  // x_color(NULL), screen_depth(8), xcolor(), values(), ximage_data_init(false),
178  // RMask(0), GMask(0), BMask(0), RShift(0), GShift(0), BShift(0)
179  // {
180  // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
181  // }
182  // vpDisplayX &operator=(const vpDisplayX &){
183  // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
184  // return *this;
185  // }
186  //#endif
187 
188 public:
189  vpDisplayX() ;
190  vpDisplayX(int winx, int winy, const std::string &title="") ;
192  vpDisplayX(vpImage<unsigned char> &I, int winx=-1, int winy=-1, const std::string &title="", vpScaleType type=SCALE_DEFAULT) ;
194  vpDisplayX(vpImage<vpRGBa> &I, int winx=-1, int winy=-1, const std::string &title="", vpScaleType type=SCALE_DEFAULT) ;
195 
196  virtual ~vpDisplayX() ;
197 
198  void getImage(vpImage<vpRGBa> &I) ;
199  unsigned int getScreenDepth();
200  unsigned int getScreenHeight();
201  void getScreenSize(unsigned int &width, unsigned int &height);
202  unsigned int getScreenWidth();
203 
204  void init(vpImage<unsigned char> &I, int winx=-1, int winy=-1, const std::string &title="") ;
205  void init(vpImage<vpRGBa> &I, int winx=-1, int winy=-1, const std::string &title="") ;
206  void init(unsigned int width, unsigned int height, int winx=-1, int winy=-1, const std::string &title="") ;
207 
208 protected:
209  void clearDisplay(const vpColor &color=vpColor::white) ;
210 
211  void closeDisplay() ;
212 
213  void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2,
214  const vpColor &color=vpColor::white, unsigned int w=4,unsigned int h=2,
215  unsigned int thickness=1) ;
216 
217  void displayCharString(const vpImagePoint &ip, const char *text,
218  const vpColor &color=vpColor::green) ;
219 
220  void displayCircle(const vpImagePoint &center, unsigned int radius,
221  const vpColor &color, bool fill = false, unsigned int thickness=1);
222  void displayCross(const vpImagePoint &ip, unsigned int size,
223  const vpColor &color, unsigned int thickness=1) ;
224  void displayDotLine(const vpImagePoint &ip1,
225  const vpImagePoint &ip2, const vpColor &color, 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, const unsigned int height);
232  void displayImageROI(const vpImage<vpRGBa> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
233 
234  void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2,
235  const vpColor &color, unsigned int thickness=1) ;
236  void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1) ;
237 
238  void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height,
239  const vpColor &color, bool fill = false, unsigned int thickness=1) ;
240  void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight,
241  const vpColor &color, bool fill = false, unsigned int thickness=1) ;
242  void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false,
243  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);
258  bool getPointerPosition (vpImagePoint &ip);
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:169
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:121
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:153
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:166
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:155
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)
vpScaleType
Values that could be applied to a display to down scale the size of the display.
Definition: vpDisplay.h:173
Defines a rectangle in the plane.
Definition: vpRect.h:82
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:158
static void displayDotLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)