Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpGDIRenderer.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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 m_hWnd;
60 
61  //the bitmap object to display
62  HBITMAP m_bmp;
63 
64  //colors for overlay
65  COLORREF m_colors[vpColor::id_unknown];
66 
67  //font used to draw text
68  HFONT m_hFont;
69 
70  //used to ensure that only one thread at a time is accessing bmp
71  CRITICAL_SECTION m_criticalSection;
72 
73  unsigned int m_bmp_width;
74  unsigned int m_bmp_height;
75 
76 public:
77  double timelost;
78  vpGDIRenderer();
79  virtual ~vpGDIRenderer();
80 
81  bool init(HWND hWnd, unsigned int width, unsigned int height);
82 
83  bool render();
84 
85  void setImg(const vpImage<vpRGBa>& I);
86  void setImg(const vpImage<unsigned char>& I);
87  void setImgROI(const vpImage<vpRGBa>& I, const vpImagePoint &iP, const unsigned int width, const unsigned int height );
88  void setImgROI(const vpImage<unsigned char>& I, const vpImagePoint &iP, const unsigned int width, const unsigned int height );
89 
90  void setPixel(const vpImagePoint &iP, const vpColor &color);
91 
92  void drawLine(const vpImagePoint &ip1,
93  const vpImagePoint &ip2,
94  const vpColor &color, unsigned int thickness, int style=PS_SOLID);
95 
96  void drawRect(const vpImagePoint &topLeft,
97  unsigned int width, unsigned int height,
98  const vpColor &color, bool fill=false,
99  unsigned int thickness=1);
100 
101  void clear(const vpColor &color);
102 
103  void drawCircle(const vpImagePoint &center, unsigned int radius,
104  const vpColor &color, bool fill=false, unsigned int thickness=1);
105 
106  void drawText(const vpImagePoint &ip, const char * text,
107  const vpColor &color);
108 
109  void drawCross(const vpImagePoint &ip, unsigned int size,
110  const vpColor &color, unsigned int thickness=1);
111 
112  void drawArrow(const vpImagePoint &ip1,
113  const vpImagePoint &ip2,
114  const vpColor &color, unsigned int w,unsigned int h, unsigned int thickness=1);
115 
116  void getImage(vpImage<vpRGBa> &I);
117 
118 private:
119 
120  //updates the renderer hbitmaps.
121  bool updateBitmap(HBITMAP& hBmp, unsigned char * imBuffer,
122  unsigned int w, unsigned int h);
123  //updates the renderer hbitmaps.
124  bool updateBitmapROI(unsigned char * imBuffer, int i_min, int j_min, int w, int h);
125 
126  //converts a vpImage<vpRGBa> into a HBITMAP .
127  void convert(const vpImage<vpRGBa> &I, HBITMAP& hBmp);
128 
129  //converst a vpImage<unsigned char> into a HBITMAP .
130  void convert(const vpImage<unsigned char> &I, HBITMAP& hBmp);
131 
132  //converts a vpImage<vpRGBa> into a HBITMAP .
133  void convertROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, const unsigned int width, const unsigned int height);
134 
135  //converst a vpImage<unsigned char> into a HBITMAP .
136  void convertROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, const unsigned int width, const unsigned int height);
137 
138 };
139 #endif
140 #endif
141 #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