Visual Servoing Platform  version 3.6.1 under development (2023-11-30)
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() override;
122 
123  void clearDisplay(const vpColor &color = vpColor::white) override;
124  void closeDisplay() override;
125  void displayImage(const vpImage<vpRGBa> &I) override;
126  void displayImage(const vpImage<unsigned char> &I) override;
127 
128  void displayImageROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, unsigned int width,
129  unsigned int height) override;
130  void displayImageROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, unsigned int width, unsigned int height) override;
131 
132  void flushDisplay() override;
133  void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) override;
134 
135  void getImage(vpImage<vpRGBa> &I) override;
136  unsigned int getScreenHeight() override;
137  void getScreenSize(unsigned int &width, unsigned int &height) override;
138  unsigned int getScreenWidth() override;
139 
140  void init(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "") override;
141  void init(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "") override;
142  void init(unsigned int width, unsigned int height, int winx = -1, int winy = -1, const std::string &title = "") override;
143 
144  void setFont(const std::string &fontname) 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) override;
152  void setWindowPosition(int winx, int winy) 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) override;
157 
158  void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill = false,
159  unsigned int thickness = 1) override;
160 
161  void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1) override;
162 
163  void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
164  unsigned int thickness = 1) override;
165 
166  void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1) override;
167 
168  void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1) 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) override;
172  void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color,
173  bool fill = false, unsigned int thickness = 1) override;
174  void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) override;
175 
176  void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) override;
177 
178  bool getClick(bool blocking = true) override;
179  bool getClick(vpImagePoint &ip, bool blocking = true) override;
180  bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) override;
181  bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) override;
182 
183  bool getKeyboardEvent(bool blocking = true) override;
184  bool getKeyboardEvent(std::string &key, bool blocking) override;
185  bool getPointerMotionEvent(vpImagePoint &ip) override;
186  bool getPointerPosition(vpImagePoint &ip) 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
static const vpColor green
Definition: vpColor.h:214
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)
vpDisplayWin32(vpImage< vpRGBa > &I, int winx=-1, int winy=-1, const std::string &title="")
vpDisplayWin32(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
HANDLE hThread
Handle of the window's thread.
bool iStatus
Initialization status.
static const int MAX_INIT_DELAY
Maximum delay for window initialization.
void setDownScalingFactor(unsigned int scale)
Class that defines generic functionalities for display.
Definition: vpDisplay.h:173
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void displayCircle(const vpImage< unsigned char > &I, const vpImageCircle &circle, const vpColor &color, bool fill=false, unsigned int thickness=1)
static bool getKeyboardEvent(const vpImage< unsigned char > &I, bool blocking=true)
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:138
static bool getClickUp(const vpImage< unsigned char > &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
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)
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
static void setFont(const vpImage< unsigned char > &I, const std::string &font)
static void displayDotLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
static bool getPointerPosition(const vpImage< unsigned char > &I, vpImagePoint &ip)
static bool getPointerMotionEvent(const vpImage< unsigned char > &I, vpImagePoint &ip)
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 setWindowPosition(const vpImage< unsigned char > &I, int winx, int winy)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
Defines a rectangle in the plane.
Definition: vpRect.h:76