Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpDisplayWin32.h
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 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 https://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
63struct 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
96class VISP_EXPORT vpDisplayWin32 : public vpDisplay
97{
98protected:
100 static const int MAX_INIT_DELAY;
101
103 HANDLE hThread;
104
106 DWORD threadId;
107
110
112 vpWin32Window window;
113
115 RECT roi;
116
118 friend void vpCreateWindow(threadParam *param);
119
120public:
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, unsigned int height);
137
138 void flushDisplay();
139 void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height);
140
141 void getImage(vpImage<vpRGBa> &I);
142 unsigned int getScreenHeight();
143 void getScreenSize(unsigned int &width, unsigned int &height);
144 unsigned int getScreenWidth();
145
146 void init(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "");
147 void init(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "");
148 void init(unsigned int width, unsigned int height, int winx = -1, int winy = -1, const std::string &title = "");
149
150 void setFont(const std::string &fontname);
151 void setDownScalingFactor(unsigned int scale)
152 {
153 window.setScale(scale);
154 m_scale = scale;
155 }
156 void setDownScalingFactor(vpScaleType scaleType) { m_scaleType = scaleType; }
157 void setTitle(const std::string &windowtitle);
158 void setWindowPosition(int winx, int winy);
159
160protected:
161 void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color = vpColor::white,
162 unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1);
163
164 void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color = vpColor::green);
165
166 void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill = false,
167 unsigned int thickness = 1);
168
169 void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1);
170
171 void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
172 unsigned int thickness = 1);
173
174 void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1);
175
176 void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1);
177
178 void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color,
179 bool fill = false, unsigned int thickness = 1);
180 void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color,
181 bool fill = false, unsigned int thickness = 1);
182 void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1);
183
184 bool getClick(bool blocking = true);
185
186 bool getClick(vpImagePoint &ip, bool blocking = true);
187
188 bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true);
189
190 bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true);
191 bool getKeyboardEvent(bool blocking = true);
192 bool getKeyboardEvent(std::string &key, bool blocking);
195
196 void waitForInit();
197};
198#endif
199#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)
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 displayCharString(const vpImage< unsigned char > &I, const vpImagePoint &ip, const char *string, const vpColor &color)
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)
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:135
Defines a rectangle in the plane.
Definition vpRect.h:76