Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
vpDisplayWin32.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Windows 32 display base class
33  *
34  * Authors:
35  * Bruno Renier
36  *
37  *****************************************************************************/
38 
39 #include <visp3/core/vpConfig.h>
40 
41 #if (defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9))
42 
43 #ifndef vpDisplayWin32_hh
44 #define vpDisplayWin32_hh
45 
46 #include <string>
47 
48 #include <visp3/core/vpDisplay.h>
49 #include <visp3/core/vpImage.h>
50 // Include WinSock2.h before windows.h to ensure that winsock.h is not
51 // included by windows.h since winsock.h and winsock2.h are incompatible
52 #include <WinSock2.h>
53 #include <visp3/core/vpImagePoint.h>
54 #include <visp3/core/vpRect.h>
55 #include <visp3/gui/vpWin32Renderer.h>
56 #include <visp3/gui/vpWin32Window.h>
57 #include <windows.h>
58 
59 #ifndef DOXYGEN_SHOULD_SKIP_THIS
60 
63 struct threadParam {
65  vpDisplayWin32 *vpDisp;
66 
68  int x;
69 
71  int y;
72 
74  unsigned int w;
75 
77  unsigned int h;
78 
80  std::string title;
81 };
82 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
83 
96 class VISP_EXPORT vpDisplayWin32 : public vpDisplay
97 {
98 protected:
100  static const int MAX_INIT_DELAY;
101 
103  HANDLE hThread;
104 
106  DWORD threadId;
107 
109  bool iStatus;
110 
112  vpWin32Window window;
113 
115  RECT roi;
116 
118  friend void vpCreateWindow(threadParam *param);
119 
120 public:
121  explicit vpDisplayWin32(vpWin32Renderer *rend = NULL);
122 
123  vpDisplayWin32(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "");
124 
125  vpDisplayWin32(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "");
126 
127  virtual ~vpDisplayWin32();
128 
129  void clearDisplay(const vpColor &color = vpColor::white);
130  void closeDisplay();
131  void displayImage(const vpImage<vpRGBa> &I);
132  void displayImage(const vpImage<unsigned char> &I);
133 
134  void displayImageROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, unsigned int width,
135  unsigned int height);
136  void displayImageROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, unsigned int width,
137  unsigned int height);
138 
139  void flushDisplay();
140  void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height);
141 
142  void getImage(vpImage<vpRGBa> &I);
143  unsigned int getScreenHeight();
144  void getScreenSize(unsigned int &width, unsigned int &height);
145  unsigned int getScreenWidth();
146 
147  void init(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "");
148  void init(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "");
149  void init(unsigned int width, unsigned int height, int winx = -1, int winy = -1, const std::string &title = "");
150 
151  void setFont(const std::string &fontname);
152  void setDownScalingFactor(unsigned int scale)
153  {
154  window.setScale(scale);
155  m_scale = scale;
156  }
157  void setDownScalingFactor(vpScaleType scaleType) { m_scaleType = scaleType; }
158  void setTitle(const std::string &windowtitle);
159  void setWindowPosition(int winx, int winy);
160 
161 protected:
162  void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color = vpColor::white,
163  unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1);
164 
165  void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color = vpColor::green);
166 
167  void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill = false,
168  unsigned int thickness = 1);
169 
170  void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1);
171 
172  void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
173  unsigned int thickness = 1);
174 
175  void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1);
176 
177  void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1);
178 
179  void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color,
180  bool fill = false, unsigned int thickness = 1);
181  void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color,
182  bool fill = false, unsigned int thickness = 1);
183  void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1);
184 
185  bool getClick(bool blocking = true);
186 
187  bool getClick(vpImagePoint &ip, bool blocking = true);
188 
189  bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true);
190 
191  bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true);
192  bool getKeyboardEvent(bool blocking = true);
193  bool getKeyboardEvent(std::string &key, bool blocking);
194  bool getPointerMotionEvent(vpImagePoint &ip);
195  bool getPointerPosition(vpImagePoint &ip);
196 
197  void waitForInit();
198 };
199 #endif
200 #endif
static const int MAX_INIT_DELAY
Maximum delay for window initialization.
DWORD threadId
Id of the window&#39;s thread.
Class that defines generic functionnalities for display.
Definition: vpDisplay.h:171
Class to define colors available for display functionnalities.
Definition: vpColor.h:119
bool iStatus
Initialization status.
static const vpColor green
Definition: vpColor.h:182
vpWin32Window window
The window.
void setDownScalingFactor(unsigned int scale)
void setDownScalingFactor(vpScaleType scaleType)
HANDLE hThread
Handle of the window&#39;s thread.
Defines a rectangle in the plane.
Definition: vpRect.h:78
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
Base abstract class for Windows 32 displays. Implements the window creation in a separate thread and ...
static const vpColor white
Definition: vpColor.h:174