Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpGDIRenderer.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 * GDI renderer for windows 32 display
32 */
33
34#ifndef VP_GDI_RENDERER_H
35#define VP_GDI_RENDERER_H
36
37#include <visp3/core/vpConfig.h>
38
39#if (defined(VISP_HAVE_GDI))
40
41#ifndef DOXYGEN_SHOULD_SKIP_THIS
42
43// Mute warning with clang-cl
44// warning : non-portable path to file '<WinSock2.h>'; specified path differs in case from file name on disk [-Wnonportable-system-include-path]
45// warning : non-portable path to file '<Windows.h>'; specified path differs in case from file name on disk [-Wnonportable-system-include-path]
46#if defined(__clang__)
47# pragma clang diagnostic push
48# pragma clang diagnostic ignored "-Wnonportable-system-include-path"
49#endif
50
51// Include WinSock2.h before windows.h to ensure that winsock.h is not
52// included by windows.h since winsock.h and winsock2.h are incompatible
53#include <WinSock2.h>
54#include <windows.h>
55
56#if defined(__clang__)
57# pragma clang diagnostic pop
58#endif
59
60#include <visp3/core/vpDisplayException.h>
61#include <visp3/core/vpImage.h>
62#include <visp3/core/vpRGBa.h>
63#include <visp3/gui/vpWin32Renderer.h>
64
65#include <visp3/core/vpMath.h>
66
68
69class VISP_EXPORT vpGDIRenderer : public vpWin32Renderer
70{
71 // the handle of the associated window
72 HWND m_hWnd;
73
74 // the bitmap object to display
75 HBITMAP m_bmp;
76
77 // colors for overlay
78 COLORREF m_colors[vpColor::id_unknown];
79
80 // font used to draw text
81 HFONT m_hFont;
82
83 // used to ensure that only one thread at a time is accessing bmp
84 CRITICAL_SECTION m_criticalSection;
85
86 unsigned int m_bmp_width;
87 unsigned int m_bmp_height;
88
89public:
90 double timelost;
91 vpGDIRenderer();
92 virtual ~vpGDIRenderer() VP_OVERRIDE;
93
94#if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98)
95 vpGDIRenderer(const vpGDIRenderer &) = default;
96 vpGDIRenderer &operator=(const vpGDIRenderer &) = default;
97#endif
98
99 bool init(HWND hWnd, unsigned int width, unsigned int height) VP_OVERRIDE;
100
101 bool render() VP_OVERRIDE;
102
103 void setImg(const vpImage<vpRGBa> &I) VP_OVERRIDE;
104 void setImg(const vpImage<unsigned char> &I) VP_OVERRIDE;
105 void setImgROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE;
106 void setImgROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE;
107
108 void setPixel(const vpImagePoint &iP, const vpColor &color) VP_OVERRIDE;
109
110 void drawLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness,
111 int style = PS_SOLID) VP_OVERRIDE;
112
113 void drawRect(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color,
114 bool fill = false, unsigned int thickness = 1) VP_OVERRIDE;
115
116 void clear(const vpColor &color) VP_OVERRIDE;
117
118 void drawCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill = false,
119 unsigned int thickness = 1) VP_OVERRIDE;
120
121 void drawText(const vpImagePoint &ip, const char *text, const vpColor &color) VP_OVERRIDE;
122
123 void drawCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1) VP_OVERRIDE;
124
125 void drawArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int w, unsigned int h,
126 unsigned int thickness = 1) VP_OVERRIDE;
127
128 void getImage(vpImage<vpRGBa> &I) VP_OVERRIDE;
129
130private:
131 // updates the renderer hbitmaps.
132 bool updateBitmap(HBITMAP &hBmp, unsigned char *imBuffer, unsigned int w, unsigned int h);
133 // updates the renderer hbitmaps.
134 bool updateBitmapROI(unsigned char *imBuffer, int i_min, int j_min, int w, int h);
135
136 // converts a vpImage<vpRGBa> into a HBITMAP .
137 void convert(const vpImage<vpRGBa> &I, HBITMAP &hBmp);
138
139 // converst a vpImage<unsigned char> into a HBITMAP .
140 void convert(const vpImage<unsigned char> &I, HBITMAP &hBmp);
141
142 // converts a vpImage<vpRGBa> into a HBITMAP .
143 void convertROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, unsigned int width, unsigned int height);
144
145 // converst a vpImage<unsigned char> into a HBITMAP .
146 void convertROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, unsigned int width, unsigned int height);
147};
148
149END_VISP_NAMESPACE
150#endif
151#endif
152#endif
@ id_unknown
Definition vpColor.h:181