Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
vpDisplayWin32.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 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 
35 #ifndef VP_DISPLAY_WIN32_H
36 #define VP_DISPLAY_WIN32_H
37 
38 #include <visp3/core/vpConfig.h>
39 #include <visp3/core/vpDisplay.h>
40 
41 #if (defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9))
42 
43 #include <string>
44 
45 #include <visp3/core/vpImage.h>
46 // Include WinSock2.h before windows.h to ensure that winsock.h is not
47 // included by windows.h since winsock.h and winsock2.h are incompatible
48 #include <WinSock2.h>
49 #include <visp3/core/vpImagePoint.h>
50 #include <visp3/core/vpRect.h>
51 #include <visp3/gui/vpWin32Renderer.h>
52 #include <visp3/gui/vpWin32Window.h>
53 #include <windows.h>
54 
56 
57 #ifndef DOXYGEN_SHOULD_SKIP_THIS
61 struct threadParam
62 {
64  vpDisplayWin32 *vpDisp;
65 
67  int x;
68 
70  int y;
71 
73  unsigned int w;
74 
76  unsigned int h;
77 
79  std::string title;
80 };
81 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
82 
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  VP_EXPLICIT vpDisplayWin32(vpWin32Renderer *rend = nullptr);
119 
120  vpDisplayWin32(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "");
121 
122  vpDisplayWin32(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "");
123 
124  virtual ~vpDisplayWin32() VP_OVERRIDE;
125 
126  void clearDisplay(const vpColor &color = vpColor::white) VP_OVERRIDE;
127  void closeDisplay() VP_OVERRIDE;
128  void displayImage(const vpImage<vpRGBa> &I) VP_OVERRIDE;
129  void displayImage(const vpImage<unsigned char> &I) VP_OVERRIDE;
130 
131  void displayImageROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, unsigned int width,
132  unsigned int height) VP_OVERRIDE;
133  void displayImageROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE;
134 
135  void flushDisplay() VP_OVERRIDE;
136  void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE;
137 
138  void getImage(vpImage<vpRGBa> &I) VP_OVERRIDE;
139  unsigned int getScreenHeight() VP_OVERRIDE;
140  void getScreenSize(unsigned int &width, unsigned int &height) VP_OVERRIDE;
141  unsigned int getScreenWidth() VP_OVERRIDE;
142 
143  void init(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "") VP_OVERRIDE;
144  void init(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "") VP_OVERRIDE;
145  void init(unsigned int width, unsigned int height, int winx = -1, int winy = -1, const std::string &title = "") VP_OVERRIDE;
146 
147  void setFont(const std::string &fontname) VP_OVERRIDE;
148  void setDownScalingFactor(unsigned int scale)
149  {
150  window.setScale(scale);
151  m_scale = scale;
152  }
153  void setDownScalingFactor(vpScaleType scaleType) { m_scaleType = scaleType; }
154  void setTitle(const std::string &windowtitle) VP_OVERRIDE;
155  void setWindowPosition(int winx, int winy) VP_OVERRIDE;
156 
157 protected:
158  void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color = vpColor::white,
159  unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1) VP_OVERRIDE;
160 
161  void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill = false,
162  unsigned int thickness = 1) VP_OVERRIDE;
163 
164  void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE;
165 
166  void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
167  unsigned int thickness = 1) VP_OVERRIDE;
168 
169  void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE;
170 
171  void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE;
172 
173  void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color,
174  bool fill = false, unsigned int thickness = 1) VP_OVERRIDE;
175  void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color,
176  bool fill = false, unsigned int thickness = 1) VP_OVERRIDE;
177  void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) VP_OVERRIDE;
178 
179  void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) VP_OVERRIDE;
180 
181  bool getClick(bool blocking = true) VP_OVERRIDE;
182  bool getClick(vpImagePoint &ip, bool blocking = true) VP_OVERRIDE;
183  bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) VP_OVERRIDE;
184  bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) VP_OVERRIDE;
185 
186  bool getKeyboardEvent(bool blocking = true) VP_OVERRIDE;
187  bool getKeyboardEvent(std::string &key, bool blocking) VP_OVERRIDE;
188  bool getPointerMotionEvent(vpImagePoint &ip) VP_OVERRIDE;
189  bool getPointerPosition(vpImagePoint &ip) VP_OVERRIDE;
190 
191  void waitForInit();
192 };
193 
194 END_VISP_NAMESPACE
195 #endif
196 #endif
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
static const vpColor white
Definition: vpColor.h:212
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:178
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:262
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:46
Definition: vpRGBa.h:65
Defines a rectangle in the plane.
Definition: vpRect.h:79