Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpDisplayWin32.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  * 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 
121  vpDisplayWin32(vpImage<vpRGBa> &I, int winx=-1, int winy=-1, const std::string &title="");
122 
123  vpDisplayWin32(vpImage<unsigned char> &I, int winx=-1, int winy=-1, const std::string &title="");
124 
125  virtual ~vpDisplayWin32();
126 
127  void clearDisplay(const vpColor &color=vpColor::white);
128  void closeDisplay();
129  void displayImage(const vpImage<vpRGBa> &I);
130  void displayImage(const vpImage<unsigned char> &I);
131 
132  void displayImageROI(const vpImage<unsigned char> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
133  void displayImageROI(const vpImage<vpRGBa> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
134 
135  void flushDisplay();
136  void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height);
137 
138  void getImage(vpImage<vpRGBa> &I);
139  unsigned int getScreenHeight();
140  void getScreenSize(unsigned int &width, unsigned int &height);
141  unsigned int getScreenWidth();
142 
143  void init(vpImage<unsigned char> &I, int winx=-1, int winy=-1, const std::string &title="");
144  void init(vpImage<vpRGBa> &I, int winx=-1, int winy=-1, const std::string &title="");
145  void init(unsigned int width, unsigned int height, int winx=-1, int winy=-1, const std::string &title="");
146 
147  void setFont( const std::string &fontname );
148  void setDownScalingFactor(unsigned int scale) { window.setScale(scale); m_scale = scale; }
149  void setTitle(const std::string &windowtitle);
150  void setWindowPosition(int winx, int winy);
151 
152 protected:
153 
154  void displayArrow(const vpImagePoint &ip1,
155  const vpImagePoint &ip2,
156  const vpColor &color=vpColor::white,
157  unsigned int w=4,unsigned int h=2,
158  unsigned int thickness=1) ;
159 
160  void displayCharString(const vpImagePoint &ip, const char *text,
161  const vpColor &color=vpColor::green) ;
162 
163  void displayCircle(const vpImagePoint &center, unsigned int radius,
164  const vpColor &color,
165  bool fill = false,
166  unsigned int thickness=1);
167 
168  void displayCross(const vpImagePoint &ip, unsigned int size,
169  const vpColor &color, unsigned int thickness=1) ;
170 
171  void displayDotLine(const vpImagePoint &ip1,
172  const vpImagePoint &ip2,
173  const vpColor &color, unsigned int thickness=1) ;
174 
175  void displayLine(const vpImagePoint &ip1,
176  const vpImagePoint &ip2,
177  const vpColor &color, unsigned int thickness=1);
178 
179  void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1);
180 
181  void displayRectangle(const vpImagePoint &topLeft,
182  unsigned int width, unsigned int height,
183  const vpColor &color, bool fill = false,
184  unsigned int thickness=1);
185  void displayRectangle(const vpImagePoint &topLeft,
186  const vpImagePoint &bottomRight,
187  const vpColor &color, bool fill = false,
188  unsigned int thickness=1) ;
189  void displayRectangle(const vpRect &rectangle,
190  const vpColor &color, bool fill = false,
191  unsigned int thickness=1) ;
192 
193  bool getClick( bool blocking=true);
194 
195  bool getClick(vpImagePoint &ip, bool blocking=true);
196 
197  bool getClick(vpImagePoint &ip,
198  vpMouseButton::vpMouseButtonType& button, bool blocking=true);
199 
200  bool getClickUp(vpImagePoint &ip,
202  bool blocking=true);
203  bool getKeyboardEvent( bool blocking=true);
204  bool getKeyboardEvent(std::string &key, bool blocking);
206  bool getPointerPosition (vpImagePoint &ip);
207 
208  void waitForInit();
209 
210 };
211 #endif
212 #endif
213 
static const int MAX_INIT_DELAY
Maximum delay for window initialization.
DWORD threadId
Id of the window's thread.
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
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)
bool iStatus
Initialization status.
static const vpColor green
Definition: vpColor.h:166
static void setFont(const vpImage< unsigned char > &I, const std::string &font)
vpWin32Window window
The window.
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)
void setDownScalingFactor(unsigned int scale)
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)
HANDLE hThread
Handle of the window's thread.
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)
Base abstract class for Windows 32 displays. Implements the window creation in a separate thread and ...
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)