Visual Servoing Platform  version 3.0.0
vpDisplayX.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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 #include <visp3/core/vpImage.h>
56 #include <visp3/core/vpRect.h>
57 
58 
59 
148 class VISP_EXPORT vpDisplayX: public vpDisplay
149 {
150 private:
151  Display *display ;
152  Window window ;
153  XImage *Ximage ;
154  Colormap lut ;
155  GC context ;
156  int screen ;
157  XEvent event;
158  Pixmap pixmap;
159  unsigned long *x_color; // Array of predefined colors
160  unsigned int screen_depth ;
161  unsigned short colortable[256];
162  XColor xcolor;
163  XGCValues values;
164  bool ximage_data_init;
165  unsigned int RMask, GMask, BMask;
166  int RShift, GShift, BShift;
167 
168 //private:
169 //#ifndef DOXYGEN_SHOULD_SKIP_THIS
170 // vpDisplayX(const vpDisplayX &)
171 // : vpDisplay(), display(NULL), window(), Ximage(NULL), lut(), context(), screen(), event(), pixmap(),
172 // x_color(NULL), screen_depth(8), xcolor(), values(), ximage_data_init(false),
173 // RMask(0), GMask(0), BMask(0), RShift(0), GShift(0), BShift(0)
174 // {
175 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
176 // }
177 // vpDisplayX &operator=(const vpDisplayX &){
178 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
179 // return *this;
180 // }
181 //#endif
182 
183 public:
184  vpDisplayX() ;
185  vpDisplayX(int winx, int winy, const char *title=NULL) ;
186  vpDisplayX(vpImage<unsigned char> &I, int winx=-1, int winy=-1,
187  const char *title=NULL) ;
188  vpDisplayX(vpImage<vpRGBa> &I, int winx=-1, int winy=-1,
189  const char *title=NULL) ;
190 
191  virtual ~vpDisplayX() ;
192 
194  int winx=-1, int winy=-1,
195  const char *title=NULL) ;
196  void init(vpImage<vpRGBa> &I,
197  int winx=-1, int winy=-1,
198  const char *title=NULL) ;
199 
200  void init(unsigned int width, unsigned int height,
201  int winx=-1, int winy=-1 ,
202  const char *title=NULL) ;
203 
204  unsigned int getScreenDepth();
205  void getScreenSize(unsigned int &width, unsigned int &height);
206  void getImage(vpImage<vpRGBa> &I) ;
207 
208 protected:
209 
210  void setFont( const char *font );
211  void setTitle(const char *title) ;
212  void setWindowPosition(int winx, int winy);
213 
214  void clearDisplay(const vpColor &color=vpColor::white) ;
215 
216  void closeDisplay() ;
217 
218  void displayArrow(const vpImagePoint &ip1,
219  const vpImagePoint &ip2,
220  const vpColor &color=vpColor::white,
221  unsigned int w=4,unsigned int h=2,
222  unsigned int thickness=1) ;
223 
224  void displayCharString(const vpImagePoint &ip, const char *text,
225  const vpColor &color=vpColor::green) ;
226 
227  void displayCircle(const vpImagePoint &center, unsigned int radius,
228  const vpColor &color,
229  bool fill = false,
230  unsigned int thickness=1);
231  void displayCross(const vpImagePoint &ip, unsigned int size,
232  const vpColor &color, unsigned int thickness=1) ;
233  void displayDotLine(const vpImagePoint &ip1,
234  const vpImagePoint &ip2,
235  const vpColor &color, unsigned int thickness=1) ;
236 
237  void displayImage(const vpImage<vpRGBa> &I) ;
238  void displayImage(const vpImage<unsigned char> &I) ;
239  void displayImage(const unsigned char *I) ;
240 
241  void displayImageROI(const vpImage<unsigned char> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
242  void displayImageROI(const vpImage<vpRGBa> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
243 
244  void displayLine(const vpImagePoint &ip1,
245  const vpImagePoint &ip2,
246  const vpColor &color, unsigned int thickness=1) ;
247  void displayPoint(const vpImagePoint &ip, const vpColor &color) ;
248 
249  void displayRectangle(const vpImagePoint &topLeft,
250  unsigned int width, unsigned int height,
251  const vpColor &color, bool fill = false,
252  unsigned int thickness=1) ;
253  void displayRectangle(const vpImagePoint &topLeft,
254  const vpImagePoint &bottomRight,
255  const vpColor &color, bool fill = false,
256  unsigned int thickness=1) ;
257  void displayRectangle(const vpRect &rectangle,
258  const vpColor &color, bool fill = false,
259  unsigned int thickness=1) ;
260 
261  void flushDisplay() ;
262  void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height);
263 
264  bool getClick(bool blocking=true) ;
265  bool getClick(vpImagePoint &ip, bool blocking=true);
266  bool getClick(vpImagePoint &ip,
268  bool blocking=true) ;
269  bool getClickUp(vpImagePoint &ip,
271  bool blocking=true);
272 
273  bool getKeyboardEvent(bool blocking=true);
274  bool getKeyboardEvent(char *string, bool blocking=true);
275 
276  int getMsb(unsigned int u32val);
278  bool getPointerPosition (vpImagePoint &ip);
279 
280  inline unsigned int getWidth() const { return width ; }
281  inline unsigned int getHeight() const { return height ; }
282 
283 
284 } ;
285 
286 
287 #endif
288 #endif
virtual void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)=0
virtual void displayImage(const vpImage< unsigned char > &I)=0
virtual void init(vpImage< unsigned char > &I, int x=-1, int y=-1, const char *title=NULL)=0
Class that defines generic functionnalities for display.
Definition: vpDisplay.h:170
virtual 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)=0
unsigned int width
Definition: vpDisplay.h:179
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
virtual void clearDisplay(const vpColor &color=vpColor::white)=0
Define the X11 console to display images.
Definition: vpDisplayX.h:148
virtual bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)=0
virtual bool getPointerMotionEvent(vpImagePoint &ip)=0
static const vpColor green
Definition: vpColor.h:166
unsigned int getHeight() const
Definition: vpDisplayX.h:281
virtual void flushDisplay()=0
virtual bool getPointerPosition(vpImagePoint &ip)=0
virtual bool getKeyboardEvent(bool blocking=true)=0
virtual void setWindowPosition(int winx, int winy)=0
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:206
unsigned int height
Definition: vpDisplay.h:180
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
virtual void displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, const unsigned int width, const unsigned int height)=0
virtual void setTitle(const char *title)=0
virtual void setFont(const char *font)=0
virtual void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)=0
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:324
virtual void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
virtual void closeDisplay()=0
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
unsigned int getWidth() const
Definition: vpDisplayX.h:280
Defines a rectangle in the plane.
Definition: vpRect.h:81
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
virtual void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height)=0
static const vpColor white
Definition: vpColor.h:158
virtual void displayPoint(const vpImagePoint &ip, const vpColor &color)=0