00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef __OPENCV_OPENGL_INTEROP_HPP__
00044 #define __OPENCV_OPENGL_INTEROP_HPP__
00045
00046 #ifdef __cplusplus
00047
00048 #include "opencv2/core/core.hpp"
00049
00050 namespace cv
00051 {
00053 class CV_EXPORTS GlBuffer
00054 {
00055 public:
00056 enum Usage
00057 {
00058 ARRAY_BUFFER = 0x8892,
00059 TEXTURE_BUFFER = 0x88EC
00060 };
00061
00063 explicit GlBuffer(Usage usage);
00064
00066 GlBuffer(int rows, int cols, int type, Usage usage);
00067 GlBuffer(Size size, int type, Usage usage);
00068
00070 GlBuffer(InputArray mat, Usage usage);
00071
00072 void create(int rows, int cols, int type, Usage usage);
00073 void create(Size size, int type, Usage usage);
00074 void create(int rows, int cols, int type);
00075 void create(Size size, int type);
00076
00077 void release();
00078
00080 void copyFrom(InputArray mat);
00081
00082 void bind() const;
00083 void unbind() const;
00084
00086 Mat mapHost();
00087 void unmapHost();
00088
00090 gpu::GpuMat mapDevice();
00091 void unmapDevice();
00092
00093 inline int rows() const { return rows_; }
00094 inline int cols() const { return cols_; }
00095 inline Size size() const { return Size(cols_, rows_); }
00096 inline bool empty() const { return rows_ == 0 || cols_ == 0; }
00097
00098 inline int type() const { return type_; }
00099 inline int depth() const { return CV_MAT_DEPTH(type_); }
00100 inline int channels() const { return CV_MAT_CN(type_); }
00101 inline int elemSize() const { return CV_ELEM_SIZE(type_); }
00102 inline int elemSize1() const { return CV_ELEM_SIZE1(type_); }
00103
00104 inline Usage usage() const { return usage_; }
00105
00106 class Impl;
00107 private:
00108 int rows_;
00109 int cols_;
00110 int type_;
00111 Usage usage_;
00112
00113 Ptr<Impl> impl_;
00114 };
00115
00116 template <> CV_EXPORTS void Ptr<GlBuffer::Impl>::delete_obj();
00117
00119 class CV_EXPORTS GlTexture
00120 {
00121 public:
00123 GlTexture();
00124
00126 GlTexture(int rows, int cols, int type);
00127 GlTexture(Size size, int type);
00128
00130 explicit GlTexture(InputArray mat, bool bgra = true);
00131
00132 void create(int rows, int cols, int type);
00133 void create(Size size, int type);
00134 void release();
00135
00137 void copyFrom(InputArray mat, bool bgra = true);
00138
00139 void bind() const;
00140 void unbind() const;
00141
00142 inline int rows() const { return rows_; }
00143 inline int cols() const { return cols_; }
00144 inline Size size() const { return Size(cols_, rows_); }
00145 inline bool empty() const { return rows_ == 0 || cols_ == 0; }
00146
00147 inline int type() const { return type_; }
00148 inline int depth() const { return CV_MAT_DEPTH(type_); }
00149 inline int channels() const { return CV_MAT_CN(type_); }
00150 inline int elemSize() const { return CV_ELEM_SIZE(type_); }
00151 inline int elemSize1() const { return CV_ELEM_SIZE1(type_); }
00152
00153 class Impl;
00154 private:
00155 int rows_;
00156 int cols_;
00157 int type_;
00158
00159 Ptr<Impl> impl_;
00160 GlBuffer buf_;
00161 };
00162
00163 template <> CV_EXPORTS void Ptr<GlTexture::Impl>::delete_obj();
00164
00166 class CV_EXPORTS GlArrays
00167 {
00168 public:
00169 inline GlArrays()
00170 : vertex_(GlBuffer::ARRAY_BUFFER), color_(GlBuffer::ARRAY_BUFFER), bgra_(true), normal_(GlBuffer::ARRAY_BUFFER), texCoord_(GlBuffer::ARRAY_BUFFER)
00171 {
00172 }
00173
00174 void setVertexArray(InputArray vertex);
00175 inline void resetVertexArray() { vertex_.release(); }
00176
00177 void setColorArray(InputArray color, bool bgra = true);
00178 inline void resetColorArray() { color_.release(); }
00179
00180 void setNormalArray(InputArray normal);
00181 inline void resetNormalArray() { normal_.release(); }
00182
00183 void setTexCoordArray(InputArray texCoord);
00184 inline void resetTexCoordArray() { texCoord_.release(); }
00185
00186 void bind() const;
00187 void unbind() const;
00188
00189 inline int rows() const { return vertex_.rows(); }
00190 inline int cols() const { return vertex_.cols(); }
00191 inline Size size() const { return vertex_.size(); }
00192 inline bool empty() const { return vertex_.empty(); }
00193
00194 private:
00195 GlBuffer vertex_;
00196 GlBuffer color_;
00197 bool bgra_;
00198 GlBuffer normal_;
00199 GlBuffer texCoord_;
00200 };
00201
00203 class CV_EXPORTS GlFont
00204 {
00205 public:
00206 enum Weight
00207 {
00208 WEIGHT_LIGHT = 300,
00209 WEIGHT_NORMAL = 400,
00210 WEIGHT_SEMIBOLD = 600,
00211 WEIGHT_BOLD = 700,
00212 WEIGHT_BLACK = 900
00213 };
00214
00215 enum Style
00216 {
00217 STYLE_NORMAL = 0,
00218 STYLE_ITALIC = 1,
00219 STYLE_UNDERLINE = 2
00220 };
00221
00222 static Ptr<GlFont> get(const std::string& family, int height = 12, Weight weight = WEIGHT_NORMAL, Style style = STYLE_NORMAL);
00223
00224 void draw(const char* str, int len) const;
00225
00226 inline const std::string& family() const { return family_; }
00227 inline int height() const { return height_; }
00228 inline Weight weight() const { return weight_; }
00229 inline Style style() const { return style_; }
00230
00231 private:
00232 GlFont(const std::string& family, int height, Weight weight, Style style);
00233
00234 std::string family_;
00235 int height_;
00236 Weight weight_;
00237 Style style_;
00238
00239 unsigned int base_;
00240
00241 GlFont(const GlFont&);
00242 GlFont& operator =(const GlFont&);
00243 };
00244
00246
00248 CV_EXPORTS void render(const GlTexture& tex,
00249 Rect_<double> wndRect = Rect_<double>(0.0, 0.0, 1.0, 1.0),
00250 Rect_<double> texRect = Rect_<double>(0.0, 0.0, 1.0, 1.0));
00251
00253 namespace RenderMode {
00254 enum {
00255 POINTS = 0x0000,
00256 LINES = 0x0001,
00257 LINE_LOOP = 0x0002,
00258 LINE_STRIP = 0x0003,
00259 TRIANGLES = 0x0004,
00260 TRIANGLE_STRIP = 0x0005,
00261 TRIANGLE_FAN = 0x0006,
00262 QUADS = 0x0007,
00263 QUAD_STRIP = 0x0008,
00264 POLYGON = 0x0009
00265 };
00266 }
00267
00269 CV_EXPORTS void render(const GlArrays& arr, int mode = RenderMode::POINTS, Scalar color = Scalar::all(255));
00270
00271 CV_EXPORTS void render(const std::string& str, const Ptr<GlFont>& font, Scalar color, Point2d pos);
00272
00274 class CV_EXPORTS GlCamera
00275 {
00276 public:
00277 GlCamera();
00278
00279 void lookAt(Point3d eye, Point3d center, Point3d up);
00280 void setCameraPos(Point3d pos, double yaw, double pitch, double roll);
00281
00282 void setScale(Point3d scale);
00283
00284 void setProjectionMatrix(const Mat& projectionMatrix, bool transpose = true);
00285 void setPerspectiveProjection(double fov, double aspect, double zNear, double zFar);
00286 void setOrthoProjection(double left, double right, double bottom, double top, double zNear, double zFar);
00287
00288 void setupProjectionMatrix() const;
00289 void setupModelViewMatrix() const;
00290
00291 private:
00292 Point3d eye_;
00293 Point3d center_;
00294 Point3d up_;
00295
00296 Point3d pos_;
00297 double yaw_;
00298 double pitch_;
00299 double roll_;
00300
00301 bool useLookAtParams_;
00302
00303 Point3d scale_;
00304
00305 Mat projectionMatrix_;
00306
00307 double fov_;
00308 double aspect_;
00309
00310 double left_;
00311 double right_;
00312 double bottom_;
00313 double top_;
00314
00315 double zNear_;
00316 double zFar_;
00317
00318 bool perspectiveProjection_;
00319 };
00320
00321 inline void GlBuffer::create(Size _size, int _type, Usage _usage) { create(_size.height, _size.width, _type, _usage); }
00322 inline void GlBuffer::create(int _rows, int _cols, int _type) { create(_rows, _cols, _type, usage()); }
00323 inline void GlBuffer::create(Size _size, int _type) { create(_size.height, _size.width, _type, usage()); }
00324 inline void GlTexture::create(Size _size, int _type) { create(_size.height, _size.width, _type); }
00325
00326 namespace gpu
00327 {
00329 CV_EXPORTS void setGlDevice(int device = 0);
00330 }
00331 }
00332
00333 #endif // __cplusplus
00334
00335 #endif // __OPENCV_OPENGL_INTEROP_HPP__