Visual Servoing Platform  version 3.0.0
vpGDIRenderer.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  * GDI renderer for windows 32 display
32  *
33  * Authors:
34  * Bruno Renier
35  *
36  *****************************************************************************/
37 
38 #include <visp3/core/vpConfig.h>
39 
40 #if ( defined(VISP_HAVE_GDI) )
41 #ifndef vpGDIRenderer_HH
42 #define vpGDIRenderer_HH
43 
44 
45 #ifndef DOXYGEN_SHOULD_SKIP_THIS
46 
47 #include <windows.h>
48 
49 #include <visp3/gui/vpWin32Renderer.h>
50 #include <visp3/core/vpImage.h>
51 #include <visp3/core/vpRGBa.h>
52 #include <visp3/core/vpDisplayException.h>
53 
54 #include <visp3/core/vpMath.h>
55 
56 class VISP_EXPORT vpGDIRenderer : public vpWin32Renderer
57 {
58  //the handle of the associated window
59  HWND hWnd;
60 
61  //the bitmap object to display
62  HBITMAP bmp;
63 
64  //colors for overlay
65  COLORREF colors[vpColor::id_unknown];
66 
67  //font used to draw text
68  HFONT hFont;
69 
70  //used to ensure that only one thread at a time is accessing bmp
71  CRITICAL_SECTION CriticalSection;
72 
73  public:
74  double timelost;
75  vpGDIRenderer();
76  virtual ~vpGDIRenderer();
77 
78  bool init(HWND hWnd, unsigned int width, unsigned int height);
79 
80  bool render();
81 
82  // gets the image's width.
83  unsigned int getImageWidth(){ return nbCols; }
84 
85  // gets the image's height.
86  unsigned int getImageHeight(){ return nbRows; }
87 
88  void setImg(const vpImage<vpRGBa>& I);
89  void setImg(const vpImage<unsigned char>& I);
90  void setImgROI(const vpImage<vpRGBa>& I, const vpImagePoint &iP, const unsigned int width, const unsigned int height );
91  void setImgROI(const vpImage<unsigned char>& I, const vpImagePoint &iP, const unsigned int width, const unsigned int height );
92 
93  void setPixel(const vpImagePoint &iP, const vpColor &color);
94 
95  void drawLine(const vpImagePoint &ip1,
96  const vpImagePoint &ip2,
97  const vpColor &color, unsigned int thickness, int style=PS_SOLID);
98 
99  void drawRect(const vpImagePoint &topLeft,
100  unsigned int width, unsigned int height,
101  const vpColor &color, bool fill=false,
102  unsigned int thickness=1);
103 
104  void clear(const vpColor &color);
105 
106  void drawCircle(const vpImagePoint &center, unsigned int radius,
107  const vpColor &color, bool fill=false, unsigned int thickness=1);
108 
109  void drawText(const vpImagePoint &ip, const char * text,
110  const vpColor &color);
111 
112  void drawCross(const vpImagePoint &ip, unsigned int size,
113  const vpColor &color, unsigned int thickness=1);
114 
115  void drawArrow(const vpImagePoint &ip1,
116  const vpImagePoint &ip2,
117  const vpColor &color, unsigned int w,unsigned int h, unsigned int thickness=1);
118 
119  void getImage(vpImage<vpRGBa> &I);
120 
121  private:
122 
123  //updates the renderer hbitmaps.
124  bool updateBitmap(HBITMAP& hBmp, unsigned char * imBuffer,
125  unsigned int w, unsigned int h);
126  //updates the renderer hbitmaps.
127  bool updateBitmapROI(unsigned char * imBuffer, const vpImagePoint &iP,
128  unsigned int w, unsigned int h);
129 
130 
131  //converts a vpImage<vpRGBa> into a HBITMAP .
132  void convert(const vpImage<vpRGBa> &I, HBITMAP& hBmp);
133 
134  //converst a vpImage<unsigned char> into a HBITMAP .
135  void convert(const vpImage<unsigned char> &I, HBITMAP& hBmp);
136 
137  //converts a vpImage<vpRGBa> into a HBITMAP .
138  void convertROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, const unsigned int width, const unsigned int height);
139 
140  //converst a vpImage<unsigned char> into a HBITMAP .
141  void convertROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, const unsigned int width, const unsigned int height);
142 
143 };
144 #endif
145 #endif
146 #endif
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88