opengl_interop_deprecated.hpp
Go to the documentation of this file.
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
8 //
9 //
10 // License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
22 //
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
26 //
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42 
43 #ifndef __OPENCV_OPENGL_INTEROP_DEPRECATED_HPP__
44 #define __OPENCV_OPENGL_INTEROP_DEPRECATED_HPP__
45 
46 #ifdef __cplusplus
47 
48 #include "opencv2/core/core.hpp"
49 
50 namespace cv
51 {
53 class CV_EXPORTS GlBuffer
54 {
55 public:
56  enum Usage
57  {
58  ARRAY_BUFFER = 0x8892, // buffer will use for OpenGL arrays (vertices, colors, normals, etc)
59  TEXTURE_BUFFER = 0x88EC // buffer will ise for OpenGL textures
60  };
61 
63  explicit GlBuffer(Usage usage);
64 
66  GlBuffer(int rows, int cols, int type, Usage usage);
67  GlBuffer(Size size, int type, Usage usage);
68 
70  GlBuffer(InputArray mat, Usage usage);
71 
72  void create(int rows, int cols, int type, Usage usage);
73  void create(Size size, int type, Usage usage);
74  void create(int rows, int cols, int type);
75  void create(Size size, int type);
76 
77  void release();
78 
80  void copyFrom(InputArray mat);
81 
82  void bind() const;
83  void unbind() const;
84 
86  Mat mapHost();
87  void unmapHost();
88 
90  gpu::GpuMat mapDevice();
91  void unmapDevice();
92 
93  inline int rows() const { return rows_; }
94  inline int cols() const { return cols_; }
95  inline Size size() const { return Size(cols_, rows_); }
96  inline bool empty() const { return rows_ == 0 || cols_ == 0; }
97 
98  inline int type() const { return type_; }
99  inline int depth() const { return CV_MAT_DEPTH(type_); }
100  inline int channels() const { return CV_MAT_CN(type_); }
101  inline int elemSize() const { return CV_ELEM_SIZE(type_); }
102  inline int elemSize1() const { return CV_ELEM_SIZE1(type_); }
103 
104  inline Usage usage() const { return usage_; }
105 
106  class Impl;
107 private:
108  int rows_;
109  int cols_;
110  int type_;
111  Usage usage_;
112 
113  Ptr<Impl> impl_;
114 };
115 
116 template <> CV_EXPORTS void Ptr<GlBuffer::Impl>::delete_obj();
117 
119 class CV_EXPORTS GlTexture
120 {
121 public:
123  GlTexture();
124 
126  GlTexture(int rows, int cols, int type);
127  GlTexture(Size size, int type);
128 
130  explicit GlTexture(InputArray mat, bool bgra = true);
131 
132  void create(int rows, int cols, int type);
133  void create(Size size, int type);
134  void release();
135 
137  void copyFrom(InputArray mat, bool bgra = true);
138 
139  void bind() const;
140  void unbind() const;
141 
142  inline int rows() const { return rows_; }
143  inline int cols() const { return cols_; }
144  inline Size size() const { return Size(cols_, rows_); }
145  inline bool empty() const { return rows_ == 0 || cols_ == 0; }
146 
147  inline int type() const { return type_; }
148  inline int depth() const { return CV_MAT_DEPTH(type_); }
149  inline int channels() const { return CV_MAT_CN(type_); }
150  inline int elemSize() const { return CV_ELEM_SIZE(type_); }
151  inline int elemSize1() const { return CV_ELEM_SIZE1(type_); }
152 
153  class Impl;
154 private:
155  int rows_;
156  int cols_;
157  int type_;
158 
159  Ptr<Impl> impl_;
160  GlBuffer buf_;
161 };
162 
163 template <> CV_EXPORTS void Ptr<GlTexture::Impl>::delete_obj();
164 
166 class CV_EXPORTS GlArrays
167 {
168 public:
169  inline GlArrays()
170  : vertex_(GlBuffer::ARRAY_BUFFER), color_(GlBuffer::ARRAY_BUFFER), bgra_(true), normal_(GlBuffer::ARRAY_BUFFER), texCoord_(GlBuffer::ARRAY_BUFFER)
171  {
172  }
173 
174  void setVertexArray(InputArray vertex);
175  inline void resetVertexArray() { vertex_.release(); }
176 
177  void setColorArray(InputArray color, bool bgra = true);
178  inline void resetColorArray() { color_.release(); }
179 
180  void setNormalArray(InputArray normal);
181  inline void resetNormalArray() { normal_.release(); }
182 
183  void setTexCoordArray(InputArray texCoord);
184  inline void resetTexCoordArray() { texCoord_.release(); }
185 
186  void bind() const;
187  void unbind() const;
188 
189  inline int rows() const { return vertex_.rows(); }
190  inline int cols() const { return vertex_.cols(); }
191  inline Size size() const { return vertex_.size(); }
192  inline bool empty() const { return vertex_.empty(); }
193 
194 private:
195  GlBuffer vertex_;
196  GlBuffer color_;
197  bool bgra_;
198  GlBuffer normal_;
199  GlBuffer texCoord_;
200 };
201 
203 class CV_EXPORTS GlFont
204 {
205 public:
206  enum Weight
207  {
208  WEIGHT_LIGHT = 300,
210  WEIGHT_SEMIBOLD = 600,
211  WEIGHT_BOLD = 700,
212  WEIGHT_BLACK = 900
213  };
214 
215  enum Style
216  {
217  STYLE_NORMAL = 0,
218  STYLE_ITALIC = 1,
219  STYLE_UNDERLINE = 2
220  };
221 
222  static Ptr<GlFont> get(const std::string& family, int height = 12, Weight weight = WEIGHT_NORMAL, Style style = STYLE_NORMAL);
223 
224  void draw(const char* str, int len) const;
225 
226  inline const std::string& family() const { return family_; }
227  inline int height() const { return height_; }
228  inline Weight weight() const { return weight_; }
229  inline Style style() const { return style_; }
230 
231 private:
232  GlFont(const std::string& family, int height, Weight weight, Style style);
233 
234  std::string family_;
235  int height_;
236  Weight weight_;
237  Style style_;
238 
239  unsigned int base_;
240 
241  GlFont(const GlFont&);
242  GlFont& operator =(const GlFont&);
243 };
244 
246 
248 CV_EXPORTS void render(const GlTexture& tex,
249  Rect_<double> wndRect = Rect_<double>(0.0, 0.0, 1.0, 1.0),
250  Rect_<double> texRect = Rect_<double>(0.0, 0.0, 1.0, 1.0));
251 
253 namespace RenderMode {
254  enum {
255  POINTS = 0x0000,
256  LINES = 0x0001,
257  LINE_LOOP = 0x0002,
258  LINE_STRIP = 0x0003,
259  TRIANGLES = 0x0004,
260  TRIANGLE_STRIP = 0x0005,
261  TRIANGLE_FAN = 0x0006,
262  QUADS = 0x0007,
263  QUAD_STRIP = 0x0008,
264  POLYGON = 0x0009
265  };
266 }
267 
269 CV_EXPORTS void render(const GlArrays& arr, int mode = RenderMode::POINTS, Scalar color = Scalar::all(255));
270 
271 CV_EXPORTS void render(const std::string& str, const Ptr<GlFont>& font, Scalar color, Point2d pos);
272 
274 class CV_EXPORTS GlCamera
275 {
276 public:
277  GlCamera();
278 
279  void lookAt(Point3d eye, Point3d center, Point3d up);
280  void setCameraPos(Point3d pos, double yaw, double pitch, double roll);
281 
282  void setScale(Point3d scale);
283 
284  void setProjectionMatrix(const Mat& projectionMatrix, bool transpose = true);
285  void setPerspectiveProjection(double fov, double aspect, double zNear, double zFar);
286  void setOrthoProjection(double left, double right, double bottom, double top, double zNear, double zFar);
287 
288  void setupProjectionMatrix() const;
289  void setupModelViewMatrix() const;
290 
291 private:
292  Point3d eye_;
293  Point3d center_;
294  Point3d up_;
295 
296  Point3d pos_;
297  double yaw_;
298  double pitch_;
299  double roll_;
300 
301  bool useLookAtParams_;
302 
303  Point3d scale_;
304 
305  Mat projectionMatrix_;
306 
307  double fov_;
308  double aspect_;
309 
310  double left_;
311  double right_;
312  double bottom_;
313  double top_;
314 
315  double zNear_;
316  double zFar_;
317 
318  bool perspectiveProjection_;
319 };
320 
321 inline void GlBuffer::create(Size _size, int _type, Usage _usage) { create(_size.height, _size.width, _type, _usage); }
322 inline void GlBuffer::create(int _rows, int _cols, int _type) { create(_rows, _cols, _type, usage()); }
323 inline void GlBuffer::create(Size _size, int _type) { create(_size.height, _size.width, _type, usage()); }
324 inline void GlTexture::create(Size _size, int _type) { create(_size.height, _size.width, _type); }
325 
326 } // namespace cv
327 
328 #endif // __cplusplus
329 
330 #endif // __OPENCV_OPENGL_INTEROP_DEPRECATED_HPP__
GLenum mode
GLdouble GLdouble GLdouble GLdouble top
GLdouble zFar
int cols() const
Definition: opengl_interop_deprecated.hpp:190
void delete_obj()
deletes the object. Override if needed
Definition: operations.hpp:2612
Size2i Size
Definition: core.hpp:896
int elemSize() const
Definition: opengl_interop_deprecated.hpp:150
Size size() const
Definition: opengl_interop_deprecated.hpp:95
void create(int rows, int cols, int type)
void resetColorArray()
Definition: opengl_interop_deprecated.hpp:178
Definition: opengl_interop_deprecated.hpp:255
void resetTexCoordArray()
Definition: opengl_interop_deprecated.hpp:184
void resetNormalArray()
Definition: opengl_interop_deprecated.hpp:181
CvPoint center
Definition: core_c.h:1290
int rows() const
Definition: opengl_interop_deprecated.hpp:189
OpenGL Font.
Definition: opengl_interop_deprecated.hpp:203
Definition: opengl_interop_deprecated.hpp:257
CV_EXPORTS void render(const GlTexture &tex, Rect_< double > wndRect=Rect_< double >(0.0, 0.0, 1.0, 1.0), Rect_< double > texRect=Rect_< double >(0.0, 0.0, 1.0, 1.0))
render functions
Proxy datatype for passing Mat's and vector<>'s as input parameters.
Definition: core.hpp:1312
Definition: opengl_interop_deprecated.hpp:263
const CvPoint2D32f vertex[4]
Definition: legacy.hpp:1070
The 2D size class.
Definition: core.hpp:81
const char const char * str
Definition: core_c.h:1552
OpenGL Arrays.
Definition: opengl_interop_deprecated.hpp:166
Definition: opengl_interop_deprecated.hpp:262
Size size() const
Definition: opengl_interop_deprecated.hpp:191
GlArrays()
Definition: opengl_interop_deprecated.hpp:169
int type() const
Definition: opengl_interop_deprecated.hpp:98
CvMemStoragePos * pos
Definition: core_c.h:933
Smart pointer for OpenGL buffer memory with reference counting.
Definition: opengl_interop_deprecated.hpp:53
const char CvPoint const CvFont * font
Definition: core_c.h:1407
bool empty() const
Definition: opengl_interop_deprecated.hpp:192
int channels() const
Definition: opengl_interop_deprecated.hpp:100
OpenGL camera.
Definition: opengl_interop_deprecated.hpp:274
int type() const
Definition: opengl_interop_deprecated.hpp:147
Definition: opengl_interop_deprecated.hpp:258
CvArr const CvMat * mat
Definition: core_c.h:700
GLenum GLsizei GLsizei height
bool empty() const
Definition: opengl_interop_deprecated.hpp:96
Smart pointer for OpenGL 2d texture memory with reference counting.
Definition: opengl_interop_deprecated.hpp:119
Smart pointer for GPU memory with reference counting. Its interface is mostly similar with cv::Mat...
Definition: gpumat.hpp:154
int elemSize1() const
Definition: opengl_interop_deprecated.hpp:102
int depth() const
Definition: opengl_interop_deprecated.hpp:99
GLdouble left
Usage
Definition: opengl_interop_deprecated.hpp:56
int height() const
Definition: opengl_interop_deprecated.hpp:227
Style style() const
Definition: opengl_interop_deprecated.hpp:229
GLsizei GLboolean transpose
GLdouble GLdouble right
The Core Functionality.
The n-dimensional matrix class.
Definition: core.hpp:1688
int rows
Definition: core_c.h:114
static Scalar_< double > all(doublev0)
returns a scalar with all elements set to v0
int rows() const
Definition: opengl_interop_deprecated.hpp:142
Weight weight() const
Definition: opengl_interop_deprecated.hpp:228
int elemSize() const
Definition: opengl_interop_deprecated.hpp:101
int cols
Definition: core_c.h:109
GLXDrawable draw
GLuint GLuint GLsizei GLenum type
Definition: core_c.h:114
bool empty() const
Definition: opengl_interop_deprecated.hpp:145
void create(int rows, int cols, int type, Usage usage)
int depth() const
Definition: opengl_interop_deprecated.hpp:148
Definition: opengl_interop_deprecated.hpp:259
_Tp width
Definition: core.hpp:840
Usage usage() const
Definition: opengl_interop_deprecated.hpp:104
Style
Definition: opengl_interop_deprecated.hpp:215
int channels() const
Definition: opengl_interop_deprecated.hpp:149
Definition: opengl_interop_deprecated.hpp:264
Definition: opengl_interop_deprecated.hpp:260
int rows() const
Definition: opengl_interop_deprecated.hpp:93
Definition: opengl_interop_deprecated.hpp:256
CvArr * arr
Definition: core_c.h:649
Definition: opengl_interop_deprecated.hpp:261
GLsizeiptr const GLvoid GLenum usage
GLenum GLsizei len
true
Definition: color.hpp:221
GLdouble GLdouble GLdouble bottom
void resetVertexArray()
Definition: opengl_interop_deprecated.hpp:175
const std::string & family() const
Definition: opengl_interop_deprecated.hpp:226
_Tp height
Definition: core.hpp:840
GLdouble GLdouble GLdouble GLdouble GLdouble zNear
GLenum GLenum GLenum GLenum GLenum scale
Weight
Definition: opengl_interop_deprecated.hpp:206
int cols() const
Definition: opengl_interop_deprecated.hpp:143
Size size() const
Definition: opengl_interop_deprecated.hpp:144
int elemSize1() const
Definition: opengl_interop_deprecated.hpp:151
Point_< double > Point2d
Definition: core.hpp:899
GLsizeiptr size
Definition: core_c.h:939
Scalar_< double > Scalar
Definition: core.hpp:968
int cols() const
Definition: opengl_interop_deprecated.hpp:94
GLuint color
Definition: core_c.h:1276