Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpD3DRenderer.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 * D3D renderer for windows 32 display
32 */
33
34#ifndef VP_D3D_RENDERER_H
35#define VP_D3D_RENDERER_H
36
37#include <visp3/core/vpConfig.h>
38
39#ifndef DOXYGEN_SHOULD_SKIP_THIS
40#if (defined(VISP_HAVE_D3D9))
41
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 <d3dx9.h>
55#include <visp3/core/vpDisplayException.h>
56#include <visp3/gui/vpWin32Renderer.h>
57
58
59#include <windows.h>
60
61#if defined(__clang__)
62# pragma clang diagnostic pop
63#endif
64
65#include <iostream>
66
68
75class VISP_EXPORT vpD3DRenderer : public vpWin32Renderer
76{
77 IDirect3D9 *pD3D;
78
79 // The d3d device we will be working with.
80 IDirect3DDevice9 *pd3dDevice;
81
82 // Sprite used to render the texture.
83 ID3DXSprite *pSprite;
84
85 // The system memory texture :
86 // The one we will be drawing on.
87 IDirect3DTexture9 *pd3dText;
88
89 // The video memory texture :
90 // The one we will use for display.
91 IDirect3DTexture9 *pd3dVideoText;
92
93 // The texture's width.
94 unsigned int textWidth;
95
96 // The window's handle.
97 HWND hWnd;
98
99 // Colors for overlay drawn with d3d directly.
100 unsigned long colors[vpColor::id_unknown];
101
102 // Colors for overlay drawn with GDI.
103 COLORREF colorsGDI[vpColor::id_unknown];
104
105 // Font used for text drawing.
106 HFONT hFont;
107
108public:
109 bool init(HWND hwnd, unsigned int width, unsigned int height);
110 bool render();
111
112 vpD3DRenderer();
113 virtual ~vpD3DRenderer() VP_OVERRIDE;
114
115 void setImg(const vpImage<vpRGBa> &im);
116 void setImg(const vpImage<unsigned char> &im);
117 void setImgROI(const vpImage<vpRGBa> &im, const vpImagePoint &iP, unsigned int width, unsigned int height);
118 void setImgROI(const vpImage<unsigned char> &im, const vpImagePoint &iP, unsigned int width, unsigned int height);
119
120 void setPixel(const vpImagePoint &iP, const vpColor &color);
121
122 void drawLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness,
123 int style = PS_SOLID);
124
125 void drawRect(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color,
126 bool fill = false, unsigned int thickness = 1);
127
128 void clear(const vpColor &color);
129
130 void drawCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill = false,
131 unsigned int thickness = 1);
132
133 void drawText(const vpImagePoint &ip, const char *text, const vpColor &color);
134
135 void drawCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1);
136
137 void drawArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int w, unsigned int h,
138 unsigned int thickness = 1);
139
140 void getImage(vpImage<vpRGBa> &I) VP_OVERRIDE;
141
142private:
143 void initView(float, float);
144
149 void subDrawCircle(int i, int j, int x, int y, vpColor col, unsigned char *buf, unsigned int pitch, unsigned int maxX,
150 unsigned int maxY);
151
152 void convert(const vpImage<vpRGBa> &I, unsigned char *imBuffer, unsigned int pitch);
153 void convert(const vpImage<unsigned char> &I, unsigned char *imBuffer, unsigned int pitch);
154 void convertROI(const vpImage<vpRGBa> &I, unsigned char *imBuffer, unsigned int pitch, int i_min, int j_min,
155 int i_max, int j_max);
156 void convertROI(const vpImage<unsigned char> &I, unsigned char *imBuffer, unsigned int pitch, int i_min, int j_min,
157 int i_max, int j_max);
158
171 inline void setBufferPixel(unsigned char *buf, unsigned int pitch, int x, int y, const vpColor &color,
172 unsigned int maxX, unsigned int maxY)
173 {
174 unsigned long c;
175 if (color.id < vpColor::id_unknown)
176 c = colors[color.id];
177 else {
178 c = D3DCOLOR_ARGB(0xFF, color.R, color.G, color.B);
179 }
180
181 if (x >= 0 && y >= 0 && x <= static_cast<int>(maxX) && y <= static_cast<int>(maxY))
182 *(unsigned long *)(buf + (y * pitch) + (x << 2)) = c; // colors[color];
183 }
193 inline void setBufferPixel(unsigned char *buf, unsigned int pitch, int x, int y, const vpColor &color)
194 {
195 unsigned long c;
196 if (color.id < vpColor::id_unknown)
197 c = colors[color.id];
198 else {
199 c = D3DCOLOR_ARGB(0xFF, color.R, color.G, color.B);
200 }
201
202 *(unsigned long *)(buf + (y * pitch) + (x << 2)) = c; // colors[color];
203 }
204
205 unsigned int supPowerOf2(unsigned int n);
206};
207#endif
208
209END_VISP_NAMESPACE
210
211#endif
212#endif
@ id_unknown
Definition vpColor.h:181