Visual Servoing Platform  version 3.6.1 under development (2024-03-28)
vpDisplayWin32.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
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 https://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 
34 #include <visp3/core/vpConfig.h>
35 
36 #if (defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9))
37 
38 #ifndef vpDisplayWin32_hh
39 #define vpDisplayWin32_hh
40 
41 #include <string>
42 
43 #include <visp3/core/vpDisplay.h>
44 #include <visp3/core/vpImage.h>
45 // Include WinSock2.h before windows.h to ensure that winsock.h is not
46 // included by windows.h since winsock.h and winsock2.h are incompatible
47 #include <WinSock2.h>
48 #include <visp3/core/vpImagePoint.h>
49 #include <visp3/core/vpRect.h>
50 #include <visp3/gui/vpWin32Renderer.h>
51 #include <visp3/gui/vpWin32Window.h>
52 #include <windows.h>
53 
54 #ifndef DOXYGEN_SHOULD_SKIP_THIS
58 struct threadParam
59 {
61  vpDisplayWin32 *vpDisp;
62 
64  int x;
65 
67  int y;
68 
70  unsigned int w;
71 
73  unsigned int h;
74 
76  std::string title;
77 };
78 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
79 
90 class VISP_EXPORT vpDisplayWin32 : public vpDisplay
91 {
92 protected:
94  static const int MAX_INIT_DELAY;
95 
97  HANDLE hThread;
98 
100  DWORD threadId;
101 
103  bool iStatus;
104 
106  vpWin32Window window;
107 
109  RECT roi;
110 
112  friend void vpCreateWindow(threadParam *param);
113 
114 public:
115  explicit vpDisplayWin32(vpWin32Renderer *rend = nullptr);
116 
117  vpDisplayWin32(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "");
118 
119  vpDisplayWin32(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "");
120 
121  virtual ~vpDisplayWin32() vp_override;
122 
123  void clearDisplay(const vpColor &color = vpColor::white) vp_override;
124  void closeDisplay() vp_override;
125  void displayImage(const vpImage<vpRGBa> &I) vp_override;
126  void displayImage(const vpImage<unsigned char> &I) vp_override;
127 
128  void displayImageROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, unsigned int width,
129  unsigned int height) vp_override;
130  void displayImageROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, unsigned int width, unsigned int height) vp_override;
131 
132  void flushDisplay() vp_override;
133  void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) vp_override;
134 
135  void getImage(vpImage<vpRGBa> &I) vp_override;
136  unsigned int getScreenHeight() vp_override;
137  void getScreenSize(unsigned int &width, unsigned int &height) vp_override;
138  unsigned int getScreenWidth() vp_override;
139 
140  void init(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "") vp_override;
141  void init(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "") vp_override;
142  void init(unsigned int width, unsigned int height, int winx = -1, int winy = -1, const std::string &title = "") vp_override;
143 
144  void setFont(const std::string &fontname) vp_override;
145  void setDownScalingFactor(unsigned int scale)
146  {
147  window.setScale(scale);
148  m_scale = scale;
149  }
150  void setDownScalingFactor(vpScaleType scaleType) { m_scaleType = scaleType; }
151  void setTitle(const std::string &windowtitle) vp_override;
152  void setWindowPosition(int winx, int winy) vp_override;
153 
154 protected:
155  void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color = vpColor::white,
156  unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1) vp_override;
157 
158  void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill = false,
159  unsigned int thickness = 1) vp_override;
160 
161  void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1) vp_override;
162 
163  void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
164  unsigned int thickness = 1) vp_override;
165 
166  void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1) vp_override;
167 
168  void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1) vp_override;
169 
170  void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color,
171  bool fill = false, unsigned int thickness = 1) vp_override;
172  void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color,
173  bool fill = false, unsigned int thickness = 1) vp_override;
174  void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) vp_override;
175 
176  void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) vp_override;
177 
178  bool getClick(bool blocking = true) vp_override;
179  bool getClick(vpImagePoint &ip, bool blocking = true) vp_override;
180  bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) vp_override;
181  bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) vp_override;
182 
183  bool getKeyboardEvent(bool blocking = true) vp_override;
184  bool getKeyboardEvent(std::string &key, bool blocking) vp_override;
185  bool getPointerMotionEvent(vpImagePoint &ip) vp_override;
186  bool getPointerPosition(vpImagePoint &ip) vp_override;
187 
188  void waitForInit();
189 };
190 #endif
191 #endif
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:152
static const vpColor white
Definition: vpColor.h:206
Base abstract class for Windows 32 displays. Implements the window creation in a separate thread and ...
DWORD threadId
Id of the window's thread.
vpWin32Window window
The window.
void setDownScalingFactor(vpScaleType scaleType)
HANDLE hThread
Handle of the window's thread.
bool iStatus
Initialization status.
static const int MAX_INIT_DELAY
Maximum delay for window initialization.
Class that defines generic functionalities for display.
Definition: vpDisplay.h:173
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)
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 setScale(vpScaleType scaleType, unsigned int width, unsigned int height)
Definition: vpDisplay.cpp:255
static void setWindowPosition(const vpImage< unsigned char > &I, int winx, int winy)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
Class that defines mouse button identifiers.
Definition: vpMouseButton.h:45
Definition: vpRGBa.h:61
Defines a rectangle in the plane.
Definition: vpRect.h:76