Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpD3DRenderer.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 * D3D renderer for windows 32 display
33 *
34 * Authors:
35 * Bruno Renier
36 *
37*****************************************************************************/
38
39#ifndef DOXYGEN_SHOULD_SKIP_THIS
40
41#include <visp3/core/vpConfig.h>
42
43#if (defined(VISP_HAVE_D3D9))
44
45#ifndef VPD3DRENDERER_HH
46#define VPD3DRENDERER_HH
47
48// Include WinSock2.h before windows.h to ensure that winsock.h is not
49// included by windows.h since winsock.h and winsock2.h are incompatible
50#include <WinSock2.h>
51#include <d3dx9.h>
52#include <visp3/core/vpDisplayException.h>
53#include <visp3/gui/vpWin32Renderer.h>
54#include <windows.h>
55
56#include <iostream>
57
65class VISP_EXPORT vpD3DRenderer : public vpWin32Renderer
66{
67
68 IDirect3D9 *pD3D;
69
70 // The d3d device we will be working with.
71 IDirect3DDevice9 *pd3dDevice;
72
73 // Sprite used to render the texture.
74 ID3DXSprite *pSprite;
75
76 // The system memory texture :
77 // The one we will be drawing on.
78 IDirect3DTexture9 *pd3dText;
79
80 // The video memory texture :
81 // The one we will use for display.
82 IDirect3DTexture9 *pd3dVideoText;
83
84 // The texture's width.
85 unsigned int textWidth;
86
87 // The window's handle.
88 HWND hWnd;
89
90 // Colors for overlay drawn with d3d directly.
91 unsigned long colors[vpColor::id_unknown];
92
93 // Colors for overlay drawn with GDI.
94 COLORREF colorsGDI[vpColor::id_unknown];
95
96 // Font used for text drawing.
97 HFONT hFont;
98
99public:
100 bool init(HWND hwnd, unsigned int width, unsigned int height);
101 bool render();
102
103 vpD3DRenderer();
104 virtual ~vpD3DRenderer();
105
106 void setImg(const vpImage<vpRGBa> &im);
107 void setImg(const vpImage<unsigned char> &im);
108 void setImgROI(const vpImage<vpRGBa> &im, const vpImagePoint &iP, unsigned int width, unsigned int height);
109 void setImgROI(const vpImage<unsigned char> &im, const vpImagePoint &iP, unsigned int width, unsigned int height);
110
111 void setPixel(const vpImagePoint &iP, const vpColor &color);
112
113 void drawLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness,
114 int style = PS_SOLID);
115
116 void drawRect(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color,
117 bool fill = false, unsigned int thickness = 1);
118
119 void clear(const vpColor &color);
120
121 void drawCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill = false,
122 unsigned int thickness = 1);
123
124 void drawText(const vpImagePoint &ip, const char *text, const vpColor &color);
125
126 void drawCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1);
127
128 void drawArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int w, unsigned int h,
129 unsigned int thickness = 1);
130
131 void getImage(vpImage<vpRGBa> &I);
132
133private:
134 void initView(float, float);
135
140 void subDrawCircle(int i, int j, int x, int y, vpColor col, unsigned char *buf, unsigned int pitch, unsigned int maxX,
141 unsigned int maxY);
142
143 void convert(const vpImage<vpRGBa> &I, unsigned char *imBuffer, unsigned int pitch);
144 void convert(const vpImage<unsigned char> &I, unsigned char *imBuffer, unsigned int pitch);
145 void convertROI(const vpImage<vpRGBa> &I, unsigned char *imBuffer, unsigned int pitch, int i_min, int j_min,
146 int i_max, int j_max);
147 void convertROI(const vpImage<unsigned char> &I, unsigned char *imBuffer, unsigned int pitch, int i_min, int j_min,
148 int i_max, int j_max);
149
162 inline void setBufferPixel(unsigned char *buf, unsigned int pitch, int x, int y, const vpColor &color,
163 unsigned int maxX, unsigned int maxY)
164 {
165 unsigned long c;
166 if (color.id < vpColor::id_unknown)
167 c = colors[color.id];
168 else {
169 c = D3DCOLOR_ARGB(0xFF, color.R, color.G, color.B);
170 }
171
172 if (x >= 0 && y >= 0 && x <= (int)maxX && y <= (int)maxY)
173 *(unsigned long *)(buf + (y * pitch) + (x << 2)) = c; // colors[color];
174 }
184 inline void setBufferPixel(unsigned char *buf, unsigned int pitch, int x, int y, const vpColor &color)
185 {
186 unsigned long c;
187 if (color.id < vpColor::id_unknown)
188 c = colors[color.id];
189 else {
190 c = D3DCOLOR_ARGB(0xFF, color.R, color.G, color.B);
191 }
192
193 *(unsigned long *)(buf + (y * pitch) + (x << 2)) = c; // colors[color];
194 }
195
196 unsigned int supPowerOf2(unsigned int n);
197};
198#endif
199#endif
200#endif
Class to define RGB colors available for display functionalities.
Definition vpColor.h:152
vpColorIdentifier id
Definition vpColor.h:200
@ id_unknown
Definition vpColor.h:193
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
unsigned char B
Blue component.
Definition vpRGBa.h:140
unsigned char R
Red component.
Definition vpRGBa.h:138
unsigned char G
Green component.
Definition vpRGBa.h:139