EstervQrCode 1.1.1
Library for qr code manipulation
opengl.hpp
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_CORE_OPENGL_HPP
44 #define OPENCV_CORE_OPENGL_HPP
45 
46 #ifndef __cplusplus
47 # error opengl.hpp header must be compiled as C++
48 #endif
49 
50 #include "opencv2/core.hpp"
51 #include "ocl.hpp"
52 
53 namespace cv { namespace ogl {
54 
66 
68 
80 {
81 public:
84  enum Target
85  {
86  ARRAY_BUFFER = 0x8892,
87  ELEMENT_ARRAY_BUFFER = 0x8893,
88  PIXEL_PACK_BUFFER = 0x88EB,
89  PIXEL_UNPACK_BUFFER = 0x88EC
90  };
91 
92  enum Access
93  {
94  READ_ONLY = 0x88B8,
95  WRITE_ONLY = 0x88B9,
96  READ_WRITE = 0x88BA
97  };
98 
105 
113  Buffer(int arows, int acols, int atype, unsigned int abufId, bool autoRelease = false);
114 
121  Buffer(Size asize, int atype, unsigned int abufId, bool autoRelease = false);
122 
130  Buffer(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
131 
138  Buffer(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
139 
145  explicit Buffer(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false);
146 
155  void create(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
156 
163  void create(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
164 
169  void release();
170 
180  void setAutoRelease(bool flag);
181 
187  void copyFrom(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false);
188 
190  void copyFrom(InputArray arr, cuda::Stream& stream, Target target = ARRAY_BUFFER, bool autoRelease = false);
191 
197  void copyTo(OutputArray arr) const;
198 
200  void copyTo(OutputArray arr, cuda::Stream& stream) const;
201 
207  Buffer clone(Target target = ARRAY_BUFFER, bool autoRelease = false) const;
208 
213  void bind(Target target) const;
214 
219  static void unbind(Target target);
220 
236  Mat mapHost(Access access);
237 
240  void unmapHost();
241 
244  void unmapDevice();
245 
253 
256  void unmapDevice(cuda::Stream& stream);
257 
258  int rows() const;
259  int cols() const;
260  Size size() const;
261  bool empty() const;
262 
263  int type() const;
264  int depth() const;
265  int channels() const;
266  int elemSize() const;
267  int elemSize1() const;
268 
270  unsigned int bufId() const;
271 
272  class Impl;
273 
274 private:
275  Ptr<Impl> impl_;
276  int rows_;
277  int cols_;
278  int type_;
279 };
280 
284 {
285 public:
288  enum Format
289  {
290  NONE = 0,
291  DEPTH_COMPONENT = 0x1902,
292  RGB = 0x1907,
293  RGBA = 0x1908
294  };
295 
302 
304  Texture2D(int arows, int acols, Format aformat, unsigned int atexId, bool autoRelease = false);
305 
307  Texture2D(Size asize, Format aformat, unsigned int atexId, bool autoRelease = false);
308 
315  Texture2D(int arows, int acols, Format aformat, bool autoRelease = false);
316 
322  Texture2D(Size asize, Format aformat, bool autoRelease = false);
323 
328  explicit Texture2D(InputArray arr, bool autoRelease = false);
329 
337  void create(int arows, int acols, Format aformat, bool autoRelease = false);
343  void create(Size asize, Format aformat, bool autoRelease = false);
344 
349  void release();
350 
361  void setAutoRelease(bool flag);
362 
368  void copyFrom(InputArray arr, bool autoRelease = false);
369 
377  void copyTo(OutputArray arr, int ddepth = CV_32F, bool autoRelease = false) const;
378 
381  void bind() const;
382 
383  int rows() const;
384  int cols() const;
385  Size size() const;
386  bool empty() const;
387 
388  Format format() const;
389 
391  unsigned int texId() const;
392 
393  class Impl;
394 
395 private:
396  Ptr<Impl> impl_;
397  int rows_;
398  int cols_;
399  Format format_;
400 };
401 
407 {
408 public:
412 
417 
421 
426 
430 
435 
439 
443  void setTexCoordArray(InputArray texCoord);
444 
448 
451  void release();
452 
456  void setAutoRelease(bool flag);
457 
460  void bind() const;
461 
464  int size() const;
465  bool empty() const;
466 
467 private:
468  int size_;
469  Buffer vertex_;
470  Buffer color_;
471  Buffer normal_;
472  Buffer texCoord_;
473 };
474 
476 
479  POINTS = 0x0000,
480  LINES = 0x0001,
481  LINE_LOOP = 0x0002,
482  LINE_STRIP = 0x0003,
483  TRIANGLES = 0x0004,
484  TRIANGLE_STRIP = 0x0005,
485  TRIANGLE_FAN = 0x0006,
486  QUADS = 0x0007,
487  QUAD_STRIP = 0x0008,
488  POLYGON = 0x0009
489 };
490 
496 CV_EXPORTS void render(const Texture2D& tex,
497  Rect_<double> wndRect = Rect_<double>(0.0, 0.0, 1.0, 1.0),
498  Rect_<double> texRect = Rect_<double>(0.0, 0.0, 1.0, 1.0));
499 
505 CV_EXPORTS void render(const Arrays& arr, int mode = POINTS, Scalar color = Scalar::all(255));
506 
513 CV_EXPORTS void render(const Arrays& arr, InputArray indices, int mode = POINTS, Scalar color = Scalar::all(255));
514 
516 
517 namespace ocl {
518 using namespace cv::ocl;
519 
520 // TODO static functions in the Context class
525 
526 } // namespace cv::ogl::ocl
527 
533 
539 
552 
560 
562 }} // namespace cv::ogl
563 
564 namespace cv { namespace cuda {
565 
572 CV_EXPORTS void setGlDevice(int device = 0);
573 
574 }}
575 
577 
581 
582 inline
583 cv::ogl::Buffer::Buffer(int arows, int acols, int atype, Target target, bool autoRelease) : rows_(0), cols_(0), type_(0)
584 {
585  create(arows, acols, atype, target, autoRelease);
586 }
587 
588 inline
589 cv::ogl::Buffer::Buffer(Size asize, int atype, Target target, bool autoRelease) : rows_(0), cols_(0), type_(0)
590 {
591  create(asize, atype, target, autoRelease);
592 }
593 
594 inline
595 void cv::ogl::Buffer::create(Size asize, int atype, Target target, bool autoRelease)
596 {
597  create(asize.height, asize.width, atype, target, autoRelease);
598 }
599 
600 inline
601 int cv::ogl::Buffer::rows() const
602 {
603  return rows_;
604 }
605 
606 inline
607 int cv::ogl::Buffer::cols() const
608 {
609  return cols_;
610 }
611 
612 inline
614 {
615  return Size(cols_, rows_);
616 }
617 
618 inline
619 bool cv::ogl::Buffer::empty() const
620 {
621  return rows_ == 0 || cols_ == 0;
622 }
623 
624 inline
625 int cv::ogl::Buffer::type() const
626 {
627  return type_;
628 }
629 
630 inline
631 int cv::ogl::Buffer::depth() const
632 {
633  return CV_MAT_DEPTH(type_);
634 }
635 
636 inline
637 int cv::ogl::Buffer::channels() const
638 {
639  return CV_MAT_CN(type_);
640 }
641 
642 inline
643 int cv::ogl::Buffer::elemSize() const
644 {
645  return CV_ELEM_SIZE(type_);
646 }
647 
648 inline
649 int cv::ogl::Buffer::elemSize1() const
650 {
651  return CV_ELEM_SIZE1(type_);
652 }
653 
655 
656 inline
657 cv::ogl::Texture2D::Texture2D(int arows, int acols, Format aformat, bool autoRelease) : rows_(0), cols_(0), format_(NONE)
658 {
659  create(arows, acols, aformat, autoRelease);
660 }
661 
662 inline
663 cv::ogl::Texture2D::Texture2D(Size asize, Format aformat, bool autoRelease) : rows_(0), cols_(0), format_(NONE)
664 {
665  create(asize, aformat, autoRelease);
666 }
667 
668 inline
669 void cv::ogl::Texture2D::create(Size asize, Format aformat, bool autoRelease)
670 {
671  create(asize.height, asize.width, aformat, autoRelease);
672 }
673 
674 inline
675 int cv::ogl::Texture2D::rows() const
676 {
677  return rows_;
678 }
679 
680 inline
681 int cv::ogl::Texture2D::cols() const
682 {
683  return cols_;
684 }
685 
686 inline
688 {
689  return Size(cols_, rows_);
690 }
691 
692 inline
693 bool cv::ogl::Texture2D::empty() const
694 {
695  return rows_ == 0 || cols_ == 0;
696 }
697 
698 inline
700 {
701  return format_;
702 }
703 
705 
706 // WARNING: unreachable code using Ninja
707 #if defined _MSC_VER && _MSC_VER >= 1920
708 #pragma warning(push)
709 #pragma warning(disable: 4702)
710 #endif
711 inline
712 cv::ogl::Arrays::Arrays() : size_(0)
713 {
714 }
715 #if defined _MSC_VER && _MSC_VER >= 1920
716 #pragma warning(pop)
717 #endif
718 
719 inline
720 int cv::ogl::Arrays::size() const
721 {
722  return size_;
723 }
724 
725 inline
726 bool cv::ogl::Arrays::empty() const
727 {
728  return size_ == 0;
729 }
730 
732 
733 #endif /* OPENCV_CORE_OPENGL_HPP */
n-dimensional dense array class
Definition: mat.hpp:812
Template class for 2D rectangles.
Definition: types.hpp:444
static Scalar_< double > all(double v0)
returns a scalar with all elements set to v0
Template class for specifying the size of an image or rectangle.
Definition: types.hpp:335
Definition: mat.hpp:2433
This type is very similar to InputArray except that it is used for input/output and output function p...
Definition: mat.hpp:296
Base storage class for GPU memory with reference counting.
Definition: cuda.hpp:106
This class encapsulates a queue of asynchronous calls.
Definition: cuda.hpp:908
Definition: ocl.hpp:259
Wrapper for OpenGL Client-Side Vertex arrays.
Definition: opengl.hpp:407
void bind() const
Binds all vertex arrays.
void release()
Releases all inner buffers.
void resetNormalArray()
Resets vertex normals.
void resetTexCoordArray()
Resets vertex texture coordinates.
void resetColorArray()
Resets vertex colors.
void resetVertexArray()
Resets vertex coordinates.
void setTexCoordArray(InputArray texCoord)
Sets an array of vertex texture coordinates.
void setAutoRelease(bool flag)
Sets auto release mode all inner buffers.
void setVertexArray(InputArray vertex)
Sets an array of vertex coordinates.
bool empty() const
int size() const
Returns the vertex count.
void setNormalArray(InputArray normal)
Sets an array of vertex normals.
void setColorArray(InputArray color)
Sets an array of vertex colors.
Arrays()
Default constructor.
Smart pointer for OpenGL buffer object with reference counting.
Definition: opengl.hpp:80
Buffer(Size asize, int atype, unsigned int abufId, bool autoRelease=false)
void create(int arows, int acols, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false)
Allocates memory for ogl::Buffer object.
void create(Size asize, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false)
void unmapDevice(cuda::Stream &stream)
Unmaps OpenGL buffer.
void copyTo(OutputArray arr) const
Copies from OpenGL buffer to host/device memory or another OpenGL buffer object.
Mat mapHost(Access access)
Maps OpenGL buffer to host memory.
void bind(Target target) const
Binds OpenGL buffer to the specified buffer binding point.
int depth() const
void copyTo(OutputArray arr, cuda::Stream &stream) const
cuda::GpuMat mapDevice()
map to device memory (blocking)
int cols() const
Access
Definition: opengl.hpp:93
int elemSize1() const
bool empty() const
int elemSize() const
Buffer(InputArray arr, Target target=ARRAY_BUFFER, bool autoRelease=false)
Target
The target defines how you intend to use the buffer object.
Definition: opengl.hpp:85
void unmapHost()
Unmaps OpenGL buffer.
static void unbind(Target target)
Unbind any buffers from the specified binding point.
Buffer(int arows, int acols, int atype, unsigned int abufId, bool autoRelease=false)
Buffer clone(Target target=ARRAY_BUFFER, bool autoRelease=false) const
Creates a full copy of the buffer object and the underlying data.
int rows() const
void release()
Decrements the reference counter and destroys the buffer object if needed.
cuda::GpuMat mapDevice(cuda::Stream &stream)
Maps OpenGL buffer to CUDA device memory.
int type() const
int channels() const
void copyFrom(InputArray arr, Target target=ARRAY_BUFFER, bool autoRelease=false)
Copies from host/device memory to OpenGL buffer.
unsigned int bufId() const
get OpenGL opject id
void copyFrom(InputArray arr, cuda::Stream &stream, Target target=ARRAY_BUFFER, bool autoRelease=false)
Buffer()
The constructors.
Size size() const
Buffer(Size asize, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false)
Buffer(int arows, int acols, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false)
void setAutoRelease(bool flag)
Sets auto release mode.
Smart pointer for OpenGL 2D texture memory with reference counting.
Definition: opengl.hpp:284
Texture2D(int arows, int acols, Format aformat, unsigned int atexId, bool autoRelease=false)
int cols() const
Format
An Image Format describes the way that the images in Textures store their data.
Definition: opengl.hpp:289
Texture2D(int arows, int acols, Format aformat, bool autoRelease=false)
void copyTo(OutputArray arr, int ddepth=CV_32F, bool autoRelease=false) const
Copies from OpenGL texture to host/device memory or another OpenGL texture object.
Texture2D(Size asize, Format aformat, bool autoRelease=false)
Texture2D(Size asize, Format aformat, unsigned int atexId, bool autoRelease=false)
void create(int arows, int acols, Format aformat, bool autoRelease=false)
Allocates memory for ogl::Texture2D object.
Texture2D(InputArray arr, bool autoRelease=false)
Texture2D()
The constructors.
Size size() const
void release()
Decrements the reference counter and destroys the texture object if needed.
void bind() const
Binds texture to current active texture unit for GL_TEXTURE_2D target.
Format format() const
void copyFrom(InputArray arr, bool autoRelease=false)
Copies from host/device memory to OpenGL texture.
bool empty() const
void setAutoRelease(bool flag)
Sets auto release mode.
unsigned int texId() const
get OpenGL opject id
int rows() const
void create(Size asize, Format aformat, bool autoRelease=false)
Size2i Size
Definition: types.hpp:370
AccessFlag
Definition: mat.hpp:65
CV__DEBUG_NS_END typedef const _InputArray & InputArray
Definition: mat.hpp:442
@ ACCESS_READ
Definition: mat.hpp:65
@ ACCESS_WRITE
Definition: mat.hpp:65
CvArr * arr
Definition: core_c.h:1247
#define CV_MAT_DEPTH(flags)
Definition: interface.h:83
#define CV_32F
Definition: interface.h:78
CV_EXPORTS UMat mapGLBuffer(const Buffer &buffer, AccessFlag accessFlags=ACCESS_READ|ACCESS_WRITE)
Maps Buffer object to process on CL side (convert to UMat).
CV_EXPORTS void convertFromGLTexture2D(const Texture2D &texture, OutputArray dst)
Converts Texture2D object to OutputArray.
CV_EXPORTS void render(const Texture2D &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 OpenGL texture or primitives.
CV_EXPORTS void convertToGLTexture2D(InputArray src, Texture2D &texture)
Converts InputArray to Texture2D object.
CV_EXPORTS void setGlDevice(int device=0)
Sets a CUDA device and initializes it for the current thread with OpenGL interoperability.
RenderModes
render mode
Definition: opengl.hpp:478
CV_EXPORTS void unmapGLBuffer(UMat &u)
Unmaps Buffer object (releases UMat, previously mapped from Buffer).
@ TRIANGLE_FAN
Definition: opengl.hpp:485
@ QUADS
Definition: opengl.hpp:486
@ LINE_STRIP
Definition: opengl.hpp:482
@ POINTS
Definition: opengl.hpp:479
@ POLYGON
Definition: opengl.hpp:488
@ LINES
Definition: opengl.hpp:480
@ QUAD_STRIP
Definition: opengl.hpp:487
@ TRIANGLES
Definition: opengl.hpp:483
@ TRIANGLE_STRIP
Definition: opengl.hpp:484
@ LINE_LOOP
Definition: opengl.hpp:481
#define CV_EXPORTS
Definition: cvdef.h:435
#define CV_ELEM_SIZE1(type)
Definition: cvdef.h:508
#define CV_MAT_CN(flags)
Definition: cvdef.h:495
#define CV_ELEM_SIZE(type)
Definition: cvdef.h:510
CvPoint CvPoint CvScalar color
Definition: imgproc_c.h:968
CvPoint CvPoint void * buffer
Definition: imgproc_c.h:357
OutputArray dst
Definition: imgproc.hpp:3564
Definition: ocl.hpp:49
CV_EXPORTS Context & initializeContextFromGL()
Creates OpenCL context from GL.
"black box" representation of the file storage associated with a file on disk.
Definition: calib3d.hpp:441