Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpDisplayWin32.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 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#ifndef VP_DISPLAY_WIN32_H
35#define VP_DISPLAY_WIN32_H
36
37#include <visp3/core/vpConfig.h>
38#include <visp3/core/vpDisplay.h>
39
40#if (defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9))
41
42#include <string>
43
44#include <visp3/core/vpImage.h>
45
46// Mute warning with clang-cl
47// warning : non-portable path to file '<WinSock2.h>'; specified path differs in case from file name on disk [-Wnonportable-system-include-path]
48// warning : non-portable path to file '<Windows.h>'; specified path differs in case from file name on disk [-Wnonportable-system-include-path]
49#if defined(__clang__)
50# pragma clang diagnostic push
51# pragma clang diagnostic ignored "-Wnonportable-system-include-path"
52#endif
53
54// Include WinSock2.h before windows.h to ensure that winsock.h is not
55// included by windows.h since winsock.h and winsock2.h are incompatible
56#include <WinSock2.h>
57#include <visp3/core/vpImagePoint.h>
58#include <visp3/core/vpRect.h>
59#include <visp3/gui/vpWin32Renderer.h>
60#include <visp3/gui/vpWin32Window.h>
61
62#include <windows.h>
63
64#if defined(__clang__)
65# pragma clang diagnostic pop
66#endif
67
69
70#ifndef DOXYGEN_SHOULD_SKIP_THIS
74struct threadParam
75{
77 vpDisplayWin32 *vpDisp;
78
80 int x;
81
83 int y;
84
86 unsigned int w;
87
89 unsigned int h;
90
92 std::string title;
93};
94#endif /* DOXYGEN_SHOULD_SKIP_THIS */
95
106class VISP_EXPORT vpDisplayWin32 : public vpDisplay
107{
108protected:
110 static const int MAX_INIT_DELAY;
111
113 HANDLE hThread;
114
116 DWORD threadId;
117
120
122 vpWin32Window window;
123
125 RECT roi;
126
128 friend void vpCreateWindow(threadParam *param);
129
130public:
131 VP_EXPLICIT vpDisplayWin32(vpWin32Renderer *rend = nullptr);
132
133 vpDisplayWin32(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "");
134
135 vpDisplayWin32(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "");
136
138 virtual ~vpDisplayWin32() VP_OVERRIDE;
139 vpDisplayWin32 &operator=(const vpDisplayWin32 &display);
140
141 void clearDisplay(const vpColor &color = vpColor::white) VP_OVERRIDE;
142 void closeDisplay() VP_OVERRIDE;
143 void displayImage(const vpImage<vpRGBa> &I) VP_OVERRIDE;
144 void displayImage(const vpImage<unsigned char> &I) VP_OVERRIDE;
145
146 void displayImageROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, unsigned int width,
147 unsigned int height) VP_OVERRIDE;
148 void displayImageROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE;
149
150 void flushDisplay() VP_OVERRIDE;
151 void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE;
152
153 void getImage(vpImage<vpRGBa> &I) VP_OVERRIDE;
154 unsigned int getScreenHeight() VP_OVERRIDE;
155 void getScreenSize(unsigned int &width, unsigned int &height) VP_OVERRIDE;
156 unsigned int getScreenWidth() VP_OVERRIDE;
157
158 void init(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "") VP_OVERRIDE;
159 void init(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "") VP_OVERRIDE;
160 void init(unsigned int width, unsigned int height, int winx = -1, int winy = -1, const std::string &title = "") VP_OVERRIDE;
161
162 void setFont(const std::string &fontname) VP_OVERRIDE;
163 void setDownScalingFactor(unsigned int scale) VP_OVERRIDE
164 {
165 window.setScale(scale);
166 m_scale = scale;
167 }
168 void setDownScalingFactor(vpScaleType scaleType) VP_OVERRIDE { m_scaleType = scaleType; }
169 void setTitle(const std::string &windowtitle) VP_OVERRIDE;
170 void setWindowPosition(int winx, int winy) VP_OVERRIDE;
171
172protected:
173 void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color = vpColor::white,
174 unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1) VP_OVERRIDE;
175
176 void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill = false,
177 unsigned int thickness = 1) VP_OVERRIDE;
178
179 void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE;
180
181 void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
182 unsigned int thickness = 1) VP_OVERRIDE;
183
184 void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE;
185
186 void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE;
187
188 void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color,
189 bool fill = false, unsigned int thickness = 1) VP_OVERRIDE;
190 void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color,
191 bool fill = false, unsigned int thickness = 1) VP_OVERRIDE;
192 void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1) VP_OVERRIDE;
193
194 void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color = vpColor::green) VP_OVERRIDE;
195
196 bool getClick(bool blocking = true) VP_OVERRIDE;
197 bool getClick(vpImagePoint &ip, bool blocking = true) VP_OVERRIDE;
198 bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) VP_OVERRIDE;
199 bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) VP_OVERRIDE;
200
201 bool getKeyboardEvent(bool blocking = true) VP_OVERRIDE;
202 bool getKeyboardEvent(std::string &key, bool blocking) VP_OVERRIDE;
203 bool getPointerMotionEvent(vpImagePoint &ip) VP_OVERRIDE;
204 bool getPointerPosition(vpImagePoint &ip) VP_OVERRIDE;
205
206 void waitForInit();
207};
208
209END_VISP_NAMESPACE
210#endif
211#endif
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157
static const vpColor white
Definition vpColor.h:193
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="") VP_OVERRIDE
void displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE
DWORD threadId
Id of the window's thread.
vpWin32Window window
The window.
unsigned int getScreenWidth() VP_OVERRIDE
void displayImage(const vpImage< vpRGBa > &I) VP_OVERRIDE
void closeDisplay() VP_OVERRIDE
VP_EXPLICIT vpDisplayWin32(vpWin32Renderer *rend=nullptr)
unsigned int getScreenHeight() VP_OVERRIDE
HANDLE hThread
Handle of the window's thread.
friend void vpCreateWindow(threadParam *param)
Function used to launch the window in a thread.
void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE
Flush the Win32 buffer.
void setDownScalingFactor(unsigned int scale) VP_OVERRIDE
bool iStatus
Initialization status.
void getScreenSize(unsigned int &width, unsigned int &height) VP_OVERRIDE
void getImage(vpImage< vpRGBa > &I) VP_OVERRIDE
void flushDisplay() VP_OVERRIDE
Flush the Win32 buffer.
void setFont(const std::string &fontname) VP_OVERRIDE
Set the font used to display text.
void setDownScalingFactor(vpScaleType scaleType) VP_OVERRIDE
void clearDisplay(const vpColor &color=vpColor::white) VP_OVERRIDE
static const int MAX_INIT_DELAY
Maximum delay for window initialization.
vpScaleType m_scaleType
Definition vpDisplay.h:931
static void display(const vpImage< unsigned char > &I)
unsigned int m_scale
Definition vpDisplay.h:930
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 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 of the vpImage class member functions.
Definition vpImage.h:131
Class that defines mouse button identifiers.
Defines a rectangle in the plane.
Definition vpRect.h:79