bazar  1.3.1
ipltexture.h
Go to the documentation of this file.
1 #ifndef _IPLTEXTURE_H
2 #define _IPLTEXTURE_H
3 
4 #include <cv.h>
5 
6 #ifdef HAVE_CONFIG_H
7 #include <config.h>
8 #else
9 #ifdef WIN32
10  // Comment this out if you do not have GLEW installed.
11 #define HAVE_GLEW
12 #endif
13 #endif
14 
15 #ifdef HAVE_GLEW
16 #include <GL/glew.h>
17 #ifndef HAVE_GL
18 #define HAVE_GL
19 #endif
20 #else
21 #ifdef WIN32
22 #include <windows.h>
23 #include <GL/gl.h>
24 #define HAVE_GL
25 #endif
26 
27 #ifdef HAVE_GL
28 #ifdef HAVE_APPLE_OPENGL_FRAMEWORK
29 #include <OpenGL/gl.h>
30 #else
31 #include <GL/gl.h>
32 #endif
33 #endif
34 #endif
35 
36 
44 class IplTexture {
45 
46 public:
47  IplTexture(IplImage *image=0, bool cache=true, bool smooth=true)
48  : im(image), downsampled(0), allowCache(cache), reload(true),
49  smooth(smooth), textureGenerated(false), refcnt(1) {}
50 
51  virtual ~IplTexture();
52 
54  void genTexture();
55  void loadTexture();
56  void disableTexture();
57  void update() { reload=true; }
58  void setImage(IplImage *image);
59  IplImage *getImage() { return im; }
60  IplImage *getIm() { return im; }
61  const IplImage *getIm() const { return im; }
62  void freeImage() { if (this && im) { cvReleaseImage(&im); } }
63 
65  double u(double x) { return x*uScale; }
66 
68  double v(double y) { return y*vScale + vOrigin; }
69 
71  void regen();
72 
74  void addRef() { refcnt++; }
75 
79  void unref();
80 
81  void clearWithoutDelete() { im = downsampled = 0; }
82 
83 private:
84  IplImage *im;
85  IplImage *downsampled;
86 
87  bool allowCache;
88  bool reload;
89  bool smooth;
90  bool textureGenerated;
91  int refcnt;
92  unsigned int texture;
93  double uScale, vScale, vOrigin;
94  int texWidth, texHeight;
95 };
96 
97 #endif