v2_ test_lab setup
[The-Artvertiser.git] / garfeild / lightcalib / ipltexture.h
blobafb42a33108e79114bd9d00f7c0a3dd70aece3d6
1 #ifndef _IPLTEXTURE_H
2 #define _IPLTEXTURE_H
4 #include <cv.h>
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
15 #ifdef __APPLE__
16 #undef HAVE_GLEW
17 #endif
18 #ifdef HAVE_GLEW
19 #include <GL/glew.h>
20 #ifndef HAVE_GL
21 #define HAVE_GL
22 #endif
23 #else
24 #ifdef WIN32
25 #include <windows.h>
26 #include <GL/gl.h>
27 #define HAVE_GL
28 #endif
30 #ifdef HAVE_GL
31 #ifdef HAVE_APPLE_OPENGL_FRAMEWORK
32 #include <OpenGL/gl.h>
33 #else
34 #include <GL/gl.h>
35 #endif
36 #endif
37 #endif
40 /*!
41 * \ingroup photocalib
43 * Represent a texture in video memory, with optional caching.
45 * Honours many IplImage fields like nChannels, depth, align, and origin.
47 class IplTexture {
49 public:
50 IplTexture(IplImage *image=0, bool cache=true, bool smooth=true)
51 : im(image), downsampled(0), allowCache(cache), reload(true),
52 smooth(smooth), textureGenerated(false), refcnt(1) {}
54 virtual ~IplTexture();
56 //! Only call genTexture from a valid OpenGL context !
57 void genTexture();
58 void loadTexture();
59 void disableTexture();
60 void update() { reload=true; }
61 void setImage(IplImage *image);
62 IplImage *getImage() { return im; }
63 IplImage *getIm() { return im; }
64 const IplImage *getIm() const { return im; }
65 void freeImage() { if (this && im) { cvReleaseImage(&im); } }
67 //! Get the U texel coordinates from pixel coordinate x.
68 double u(double x) { return x*uScale; }
70 //! Get the V texel coordinates from pixel coordinate y (axis pointing down).
71 double v(double y) { return y*vScale + vOrigin; }
73 //! force texture regeneration.
74 void regen();
76 //! Add a reference to the reference counter.
77 void addRef() { refcnt++; }
79 /*! Removes a reference to the reference counter, and delete the
80 * texture if it reaches 0.
82 void unref();
84 void clearWithoutDelete() { im = downsampled = 0; }
86 private:
87 IplImage *im;
88 IplImage *downsampled;
90 bool allowCache;
91 bool reload;
92 bool smooth;
93 bool textureGenerated;
94 int refcnt;
95 unsigned int texture;
96 double uScale, vScale, vOrigin;
97 int texWidth, texHeight;
100 #endif