ViSP  2.10.0
vpD3DRenderer.h
1 /****************************************************************************
2  *
3  * $Id: vpD3DRenderer.h 4574 2014-01-09 08:48:51Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * D3D renderer for windows 32 display
36  *
37  * Authors:
38  * Bruno Renier
39  *
40  *****************************************************************************/
41 
42 #ifndef DOXYGEN_SHOULD_SKIP_THIS
43 
44 #include <visp/vpConfig.h>
45 
46 #if ( defined(VISP_HAVE_D3D9) )
47 
48 #ifndef VPD3DRENDERER_HH
49 #define VPD3DRENDERER_HH
50 
51 #include <windows.h>
52 #include <d3dx9.h>
53 #include <visp/vpWin32Renderer.h>
54 #include <visp/vpDisplayException.h>
55 
56 
57 #include <iostream>
58 
66 class VISP_EXPORT vpD3DRenderer : public vpWin32Renderer
67 {
68 
69  IDirect3D9 * pD3D;
70 
71  //The d3d device we will be working with.
72  IDirect3DDevice9 * pd3dDevice;
73 
74  //Sprite used to render the texture.
75  ID3DXSprite * pSprite;
76 
77  //The system memory texture :
78  //The one we will be drawing on.
79  IDirect3DTexture9 * pd3dText;
80 
81  //The video memory texture :
82  //The one we will use for display.
83  IDirect3DTexture9 * pd3dVideoText;
84 
85  //The texture's width.
86  unsigned int textWidth;
87 
88  //The window's handle.
89  HWND hWnd;
90 
91  //Colors for overlay drawn with d3d directly.
92  unsigned long colors[vpColor::id_unknown];
93 
94  //Colors for overlay drawn with GDI.
95  COLORREF colorsGDI[vpColor::id_unknown];
96 
97  //Font used for text drawing.
98  HFONT hFont;
99 
100  public:
101 
102  bool init(HWND hwnd, unsigned int width, unsigned int height);
103  bool render();
104 
105  vpD3DRenderer();
106  virtual ~vpD3DRenderer();
107 
108  void setImg(const vpImage<vpRGBa>& im);
109  void setImg(const vpImage<unsigned char>& im);
110  void setImgROI(const vpImage<vpRGBa>& im, const vpImagePoint &iP, const unsigned int width, const unsigned int height );
111  void setImgROI(const vpImage<unsigned char>& im, const vpImagePoint &iP, const unsigned int width, const unsigned int height );
112 
113  void setPixel(const vpImagePoint &iP, const vpColor &color);
114 
115  void drawLine(const vpImagePoint &ip1,
116  const vpImagePoint &ip2,
117  const vpColor &color, unsigned int thickness, int style=PS_SOLID);
118 
119  void drawRect(const vpImagePoint &topLeft,
120  unsigned int width, unsigned int height,
121  const vpColor &color, bool fill=false,
122  unsigned int thickness=1);
123 
124  void clear(const vpColor &color);
125 
126  void drawCircle(const vpImagePoint &center, unsigned int radius,
127  const vpColor &color, bool fill=false, unsigned int thickness=1);
128 
129  void drawText(const vpImagePoint &ip, const char * text,
130  const vpColor &color);
131 
132  void drawCross(const vpImagePoint &ip, unsigned int size,
133  const vpColor &color, unsigned int thickness=1);
134 
135  void drawArrow(const vpImagePoint &ip1,
136  const vpImagePoint &ip2,
137  const vpColor &color, unsigned int w,unsigned int h, unsigned int thickness=1);
138 
139  void getImage(vpImage<vpRGBa> &I);
140 
141 
142 
143  private:
144 
145  void initView(float, float);
146 
151  void subDrawCircle(int i, int j,
152  int x, int y,
153  vpColor col, unsigned char* buf,
154  unsigned int pitch, unsigned int maxX, unsigned int maxY);
155 
156 
168  inline void setBufferPixel(unsigned char* buf, unsigned int pitch,
169  int x, int y,
170  const vpColor &color,
171  unsigned int maxX, unsigned int maxY)
172  {
173  unsigned long c;
174  if (color.id < vpColor::id_unknown)
175  c = colors[color.id];
176  else {
177  c = D3DCOLOR_ARGB(0xFF, color.R, color.G, color.B);
178  }
179 
180  if(x>=0 && y>=0 && x<= (int)maxX && y<= (int)maxY)
181  *(unsigned long*)(buf + (y*pitch) + (x<<2)) = c; //colors[color];
182  }
192  inline void setBufferPixel(unsigned char* buf, unsigned int pitch,
193  int x, int y,
194  const vpColor &color)
195  {
196  unsigned long c;
197  if (color.id < vpColor::id_unknown)
198  c = colors[color.id];
199  else {
200  c = D3DCOLOR_ARGB(0xFF, color.R, color.G, color.B);
201  }
202 
203  *(unsigned long*)(buf + (y*pitch) + (x<<2)) = c; //colors[color];
204  }
205 
206  unsigned int supPowerOf2(unsigned int n);
207 
208 };
209 #endif
210 #endif
211 #endif
unsigned char B
Blue component.
Definition: vpRGBa.h:148
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
unsigned char G
Green component.
Definition: vpRGBa.h:147
vpColorIdentifier id
Definition: vpColor.h:156
unsigned char R
Red component.
Definition: vpRGBa.h:146
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:93