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