Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
vpGDIRenderer.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
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 https://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 
34 #ifndef VP_GDI_RENDERER_H
35 #define VP_GDI_RENDERER_H
36 
37 #include <visp3/core/vpConfig.h>
38 
39 #if (defined(VISP_HAVE_GDI))
40 
41 #ifndef DOXYGEN_SHOULD_SKIP_THIS
42 
43 // Include WinSock2.h before windows.h to ensure that winsock.h is not
44 // included by windows.h since winsock.h and winsock2.h are incompatible
45 #include <WinSock2.h>
46 #include <windows.h>
47 
48 #include <visp3/core/vpDisplayException.h>
49 #include <visp3/core/vpImage.h>
50 #include <visp3/core/vpRGBa.h>
51 #include <visp3/gui/vpWin32Renderer.h>
52 
53 #include <visp3/core/vpMath.h>
54 
56 
57 class VISP_EXPORT vpGDIRenderer : public vpWin32Renderer
58 {
59  // the handle of the associated window
60  HWND m_hWnd;
61 
62  // the bitmap object to display
63  HBITMAP m_bmp;
64 
65  // colors for overlay
66  COLORREF m_colors[vpColor::id_unknown];
67 
68  // font used to draw text
69  HFONT m_hFont;
70 
71  // used to ensure that only one thread at a time is accessing bmp
72  CRITICAL_SECTION m_criticalSection;
73 
74  unsigned int m_bmp_width;
75  unsigned int m_bmp_height;
76 
77 public:
78  double timelost;
79  vpGDIRenderer();
80  virtual ~vpGDIRenderer();
81 
82  bool init(HWND hWnd, unsigned int width, unsigned int height);
83 
84  bool render();
85 
86  void setImg(const vpImage<vpRGBa> &I);
87  void setImg(const vpImage<unsigned char> &I);
88  void setImgROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, unsigned int width, unsigned int height);
89  void setImgROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, unsigned int width, unsigned int height);
90 
91  void setPixel(const vpImagePoint &iP, const vpColor &color);
92 
93  void drawLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness,
94  int style = PS_SOLID);
95 
96  void drawRect(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color,
97  bool fill = false, unsigned int thickness = 1);
98 
99  void clear(const vpColor &color);
100 
101  void drawCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill = false,
102  unsigned int thickness = 1);
103 
104  void drawText(const vpImagePoint &ip, const char *text, const vpColor &color);
105 
106  void drawCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1);
107 
108  void drawArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int w, unsigned int h,
109  unsigned int thickness = 1);
110 
111  void getImage(vpImage<vpRGBa> &I) VP_OVERRIDE;
112 
113 private:
114  // updates the renderer hbitmaps.
115  bool updateBitmap(HBITMAP &hBmp, unsigned char *imBuffer, unsigned int w, unsigned int h);
116  // updates the renderer hbitmaps.
117  bool updateBitmapROI(unsigned char *imBuffer, int i_min, int j_min, int w, int h);
118 
119  // converts a vpImage<vpRGBa> into a HBITMAP .
120  void convert(const vpImage<vpRGBa> &I, HBITMAP &hBmp);
121 
122  // converst a vpImage<unsigned char> into a HBITMAP .
123  void convert(const vpImage<unsigned char> &I, HBITMAP &hBmp);
124 
125  // converts a vpImage<vpRGBa> into a HBITMAP .
126  void convertROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, unsigned int width, unsigned int height);
127 
128  // converst a vpImage<unsigned char> into a HBITMAP .
129  void convertROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, unsigned int width, unsigned int height);
130 };
131 
132 END_VISP_NAMESPACE
133 #endif
134 #endif
135 #endif
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
@ id_unknown
Definition: vpColor.h:199
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82