Visual Servoing Platform  version 3.0.0
vpD3DRenderer.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Authors:
34  * Bruno Renier
35  *
36  *****************************************************************************/
37 
38 #ifndef DOXYGEN_SHOULD_SKIP_THIS
39 
40 #include <visp3/core/vpConfig.h>
41 
42 #if ( defined(VISP_HAVE_D3D9) )
43 
44 #ifndef VPD3DRENDERER_HH
45 #define VPD3DRENDERER_HH
46 
47 #include <windows.h>
48 #include <d3dx9.h>
49 #include <visp3/gui/vpWin32Renderer.h>
50 #include <visp3/core/vpDisplayException.h>
51 
52 
53 #include <iostream>
54 
62 class VISP_EXPORT vpD3DRenderer : public vpWin32Renderer
63 {
64 
65  IDirect3D9 * pD3D;
66 
67  //The d3d device we will be working with.
68  IDirect3DDevice9 * pd3dDevice;
69 
70  //Sprite used to render the texture.
71  ID3DXSprite * pSprite;
72 
73  //The system memory texture :
74  //The one we will be drawing on.
75  IDirect3DTexture9 * pd3dText;
76 
77  //The video memory texture :
78  //The one we will use for display.
79  IDirect3DTexture9 * pd3dVideoText;
80 
81  //The texture's width.
82  unsigned int textWidth;
83 
84  //The window's handle.
85  HWND hWnd;
86 
87  //Colors for overlay drawn with d3d directly.
88  unsigned long colors[vpColor::id_unknown];
89 
90  //Colors for overlay drawn with GDI.
91  COLORREF colorsGDI[vpColor::id_unknown];
92 
93  //Font used for text drawing.
94  HFONT hFont;
95 
96  public:
97 
98  bool init(HWND hwnd, unsigned int width, unsigned int height);
99  bool render();
100 
101  vpD3DRenderer();
102  virtual ~vpD3DRenderer();
103 
104  void setImg(const vpImage<vpRGBa>& im);
105  void setImg(const vpImage<unsigned char>& im);
106  void setImgROI(const vpImage<vpRGBa>& im, const vpImagePoint &iP, const unsigned int width, const unsigned int height );
107  void setImgROI(const vpImage<unsigned char>& im, const vpImagePoint &iP, const unsigned int width, const unsigned int height );
108 
109  void setPixel(const vpImagePoint &iP, const vpColor &color);
110 
111  void drawLine(const vpImagePoint &ip1,
112  const vpImagePoint &ip2,
113  const vpColor &color, unsigned int thickness, int style=PS_SOLID);
114 
115  void drawRect(const vpImagePoint &topLeft,
116  unsigned int width, unsigned int height,
117  const vpColor &color, bool fill=false,
118  unsigned int thickness=1);
119 
120  void clear(const vpColor &color);
121 
122  void drawCircle(const vpImagePoint &center, unsigned int radius,
123  const vpColor &color, bool fill=false, unsigned int thickness=1);
124 
125  void drawText(const vpImagePoint &ip, const char * text,
126  const vpColor &color);
127 
128  void drawCross(const vpImagePoint &ip, unsigned int size,
129  const vpColor &color, unsigned int thickness=1);
130 
131  void drawArrow(const vpImagePoint &ip1,
132  const vpImagePoint &ip2,
133  const vpColor &color, unsigned int w,unsigned int h, unsigned int thickness=1);
134 
135  void getImage(vpImage<vpRGBa> &I);
136 
137 
138 
139  private:
140 
141  void initView(float, float);
142 
147  void subDrawCircle(int i, int j,
148  int x, int y,
149  vpColor col, unsigned char* buf,
150  unsigned int pitch, unsigned int maxX, unsigned int maxY);
151 
152 
164  inline void setBufferPixel(unsigned char* buf, unsigned int pitch,
165  int x, int y,
166  const vpColor &color,
167  unsigned int maxX, unsigned int maxY)
168  {
169  unsigned long c;
170  if (color.id < vpColor::id_unknown)
171  c = colors[color.id];
172  else {
173  c = D3DCOLOR_ARGB(0xFF, color.R, color.G, color.B);
174  }
175 
176  if(x>=0 && y>=0 && x<= (int)maxX && y<= (int)maxY)
177  *(unsigned long*)(buf + (y*pitch) + (x<<2)) = c; //colors[color];
178  }
188  inline void setBufferPixel(unsigned char* buf, unsigned int pitch,
189  int x, int y,
190  const vpColor &color)
191  {
192  unsigned long c;
193  if (color.id < vpColor::id_unknown)
194  c = colors[color.id];
195  else {
196  c = D3DCOLOR_ARGB(0xFF, color.R, color.G, color.B);
197  }
198 
199  *(unsigned long*)(buf + (y*pitch) + (x<<2)) = c; //colors[color];
200  }
201 
202  unsigned int supPowerOf2(unsigned int n);
203 
204 };
205 #endif
206 #endif
207 #endif
unsigned char B
Blue component.
Definition: vpRGBa.h:144
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
unsigned char G
Green component.
Definition: vpRGBa.h:143
vpColorIdentifier id
Definition: vpColor.h:152
unsigned char R
Red component.
Definition: vpRGBa.h:142
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88