Visual Servoing Platform  version 3.0.0
vpDisplayWin32.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  * Windows 32 display base class
32  *
33  * Authors:
34  * Bruno Renier
35  *
36  *****************************************************************************/
37 
38 #include <visp3/core/vpConfig.h>
39 
40 #if ( defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) )
41 
42 #ifndef vpDisplayWin32_hh
43 #define vpDisplayWin32_hh
44 
45 #include <string>
46 
47 #include <visp3/core/vpImage.h>
48 #include <visp3/core/vpDisplay.h>
49 #include <windows.h>
50 #include <visp3/gui/vpWin32Window.h>
51 #include <visp3/gui/vpWin32Renderer.h>
52 #include <visp3/core/vpRect.h>
53 #include <visp3/core/vpImagePoint.h>
54 
55 #ifndef DOXYGEN_SHOULD_SKIP_THIS
56 
59 struct threadParam
60 {
62  vpDisplayWin32 * vpDisp;
63 
65  int x;
66 
68  int y;
69 
71  unsigned int w;
72 
74  unsigned int h;
75 
77  std::string title;
78 };
79 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
80 
93 class VISP_EXPORT vpDisplayWin32 : public vpDisplay
94 {
95  protected:
97  static const int MAX_INIT_DELAY;
98 
100  HANDLE hThread;
101 
103  DWORD threadId;
104 
106  bool iStatus;
107 
109  vpWin32Window window;
110 
112  RECT roi;
113 
115  friend void vpCreateWindow(threadParam * param);
116 
117  public:
118 
119  vpDisplayWin32(vpWin32Renderer * rend = NULL);
120 
122  int winx=-1, int winy=-1,
123  const char *title=NULL);
124 
126  int winx=-1, int winy=-1,
127  const char *title=NULL);
128 
129  virtual ~vpDisplayWin32();
130 
131  void setTitle(const char *windowtitle);
132  void setFont( const char *fontname );
133  void setWindowPosition(int winx, int winy);
134  void clearDisplay(const vpColor &color=vpColor::white);
135  void closeDisplay();
136  void displayImage(const vpImage<vpRGBa> &I);
137  void displayImage(const vpImage<unsigned char> &I);
138 
139  void displayImageROI(const vpImage<unsigned char> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
140  void displayImageROI(const vpImage<vpRGBa> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
141 
142  void flushDisplay();
143  void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height);
144 
146  int winx=-1, int winy=-1,
147  const char *title=NULL) ;
148 
149  void init(vpImage<vpRGBa> &I,
150  int winx=-1, int winy=-1,
151  const char *title=NULL) ;
152 
153  void init(unsigned int width, unsigned int height,
154  int winx=-1, int winy=-1 ,
155  const char *title=NULL) ;
156 
157  void getImage(vpImage<vpRGBa> &I);
158 
159  protected:
160 
161  void displayArrow(const vpImagePoint &ip1,
162  const vpImagePoint &ip2,
163  const vpColor &color=vpColor::white,
164  unsigned int w=4,unsigned int h=2,
165  unsigned int thickness=1) ;
166 
167  void displayCharString(const vpImagePoint &ip, const char *text,
168  const vpColor &color=vpColor::green) ;
169 
170  void displayCircle(const vpImagePoint &center, unsigned int radius,
171  const vpColor &color,
172  bool fill = false,
173  unsigned int thickness=1);
174 
175  void displayCross(const vpImagePoint &ip, unsigned int size,
176  const vpColor &color, unsigned int thickness=1) ;
177 
178  void displayDotLine(const vpImagePoint &ip1,
179  const vpImagePoint &ip2,
180  const vpColor &color, unsigned int thickness=1) ;
181 
182  void displayLine(const vpImagePoint &ip1,
183  const vpImagePoint &ip2,
184  const vpColor &color, unsigned int thickness=1);
185 
186 
187  void displayPoint(const vpImagePoint &ip, const vpColor &color);
188 
189  void displayRectangle(const vpImagePoint &topLeft,
190  unsigned int width, unsigned int height,
191  const vpColor &color, bool fill = false,
192  unsigned int thickness=1);
193  void displayRectangle(const vpImagePoint &topLeft,
194  const vpImagePoint &bottomRight,
195  const vpColor &color, bool fill = false,
196  unsigned int thickness=1) ;
197  void displayRectangle(const vpRect &rectangle,
198  const vpColor &color, bool fill = false,
199  unsigned int thickness=1) ;
200 
201  bool getClick( bool blocking=true);
202 
203  bool getClick(vpImagePoint &ip, bool blocking=true);
204 
205  bool getClick(vpImagePoint &ip,
206  vpMouseButton::vpMouseButtonType& button, bool blocking=true);
207 
208  bool getClickUp(vpImagePoint &ip,
210  bool blocking=true);
211  bool getKeyboardEvent( bool blocking=true);
212  bool getKeyboardEvent(char *string, bool blocking);
214  bool getPointerPosition (vpImagePoint &ip);
215 
216  void waitForInit();
217 
218 };
219 #endif
220 #endif
221 
virtual void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)=0
static const int MAX_INIT_DELAY
Maximum delay for window initialization.
DWORD threadId
Id of the window's thread.
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
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
virtual void clearDisplay(const vpColor &color=vpColor::white)=0
virtual bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)=0
virtual bool getPointerMotionEvent(vpImagePoint &ip)=0
bool iStatus
Initialization status.
static const vpColor green
Definition: vpColor.h:166
vpWin32Window window
The window.
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
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
HANDLE hThread
Handle of the window's thread.
virtual void closeDisplay()=0
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
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
Base abstract class for Windows 32 displays. Implements the window creation in a separate thread and ...
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