ViSP  2.10.0
vpDisplayX.h
1 /****************************************************************************
2  *
3  * $Id: vpDisplayX.h 5126 2015-01-05 22:07:11Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Image display.
36  *
37  * Authors:
38  * Fabien Spindler
39  *
40  *****************************************************************************/
41 
42 #ifndef vpDisplayX_h
43 #define vpDisplayX_h
44 
45 #include <visp/vpConfig.h>
46 #include <visp/vpDisplay.h>
47 #ifdef VISP_HAVE_X11
48 
49 //namespace X11name
50 //{
51 #include <X11/Xlib.h>
52 #include <X11/Xutil.h>
53 //#include <X11/Xatom.h>
54 //#include <X11/cursorfont.h>
55 //} ;
56 
57 //using namespace X11name ;
58 
59 #include <visp/vpImage.h>
60 #include <visp/vpRect.h>
61 
62 
63 
152 class VISP_EXPORT vpDisplayX: public vpDisplay
153 {
154 private:
155  Display *display ;
156  Window window ;
157  XImage *Ximage ;
158  Colormap lut ;
159  GC context ;
160  int screen ;
161  int planes;
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  int size ;
170  bool ximage_data_init;
171  unsigned int RMask, GMask, BMask;
172  int RShift, GShift, BShift;
173 
174 public:
175  vpDisplayX() ;
176  vpDisplayX(int winx, int winy, const char *title=NULL) ;
177  vpDisplayX(vpImage<unsigned char> &I, int winx=-1, int winy=-1,
178  const char *title=NULL) ;
179  vpDisplayX(vpImage<vpRGBa> &I, int winx=-1, int winy=-1,
180  const char *title=NULL) ;
181 
182  virtual ~vpDisplayX() ;
183 
185  int winx=-1, int winy=-1,
186  const char *title=NULL) ;
187  void init(vpImage<vpRGBa> &I,
188  int winx=-1, int winy=-1,
189  const char *title=NULL) ;
190 
191  void init(unsigned int width, unsigned int height,
192  int winx=-1, int winy=-1 ,
193  const char *title=NULL) ;
194 
195  unsigned int getScreenDepth();
196  void getScreenSize(unsigned int &width, unsigned int &height);
197  void getImage(vpImage<vpRGBa> &I) ;
198 
199 protected:
200 
201  void setFont( const char *font );
202  void setTitle(const char *title) ;
203  void setWindowPosition(int winx, int winy);
204 
205  void clearDisplay(const vpColor &color=vpColor::white) ;
206 
207  void closeDisplay() ;
208 
209  void displayArrow(const vpImagePoint &ip1,
210  const vpImagePoint &ip2,
211  const vpColor &color=vpColor::white,
212  unsigned int w=4,unsigned int h=2,
213  unsigned int thickness=1) ;
214 
215  void displayCharString(const vpImagePoint &ip, const char *text,
216  const vpColor &color=vpColor::green) ;
217 
218  void displayCircle(const vpImagePoint &center, unsigned int radius,
219  const vpColor &color,
220  bool fill = false,
221  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,
226  const vpColor &color, unsigned int thickness=1) ;
227 
228  void displayImage(const vpImage<vpRGBa> &I) ;
229  void displayImage(const vpImage<unsigned char> &I) ;
230  void displayImage(const unsigned char *I) ;
231 
232  void displayImageROI(const vpImage<unsigned char> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
233  void displayImageROI(const vpImage<vpRGBa> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
234 
235  void displayLine(const vpImagePoint &ip1,
236  const vpImagePoint &ip2,
237  const vpColor &color, unsigned int thickness=1) ;
238  void displayPoint(const vpImagePoint &ip, const vpColor &color) ;
239 
240  void displayRectangle(const vpImagePoint &topLeft,
241  unsigned int width, unsigned int height,
242  const vpColor &color, bool fill = false,
243  unsigned int thickness=1) ;
244  void displayRectangle(const vpImagePoint &topLeft,
245  const vpImagePoint &bottomRight,
246  const vpColor &color, bool fill = false,
247  unsigned int thickness=1) ;
248  void displayRectangle(const vpRect &rectangle,
249  const vpColor &color, bool fill = false,
250  unsigned int thickness=1) ;
251 
252  void flushDisplay() ;
253  void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height);
254 
255  bool getClick(bool blocking=true) ;
256  bool getClick(vpImagePoint &ip, bool blocking=true);
257  bool getClick(vpImagePoint &ip,
259  bool blocking=true) ;
260  bool getClickUp(vpImagePoint &ip,
262  bool blocking=true);
263 
264  bool getKeyboardEvent(bool blocking=true);
265  bool getKeyboardEvent(char *string, bool blocking=true);
266 
267  int getMsb(unsigned int u32val);
269  bool getPointerPosition (vpImagePoint &ip);
270 
271  inline unsigned int getWidth() const { return width ; }
272  inline unsigned int getHeight() const { return height ; }
273 
274 
275 } ;
276 
277 
278 #endif
279 #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:174
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:183
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
virtual void clearDisplay(const vpColor &color=vpColor::white)=0
Define the X11 console to display images.
Definition: vpDisplayX.h:152
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:170
unsigned int getHeight() const
Definition: vpDisplayX.h:272
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:210
unsigned int height
Definition: vpDisplay.h:184
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:328
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:271
Defines a rectangle in the plane.
Definition: vpRect.h:85
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:93
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:162
virtual void displayPoint(const vpImagePoint &ip, const vpColor &color)=0