GLTexImage.h
Go to the documentation of this file.
00001 
00002 //      File:           GLTexImage.h
00003 //      Author:         Changchang Wu
00004 //      Description : interface for the GLTexImage class.
00005 //              GLTexImage:             naive texture class. 
00006 //                                              sevral different quad drawing functions are provied
00007 //              GLTexPacked:    packed version (four value packed as four channels of a pixel)
00008 //              GLTexInput:             GLTexImage + some input information
00009 //
00010 //      Copyright (c) 2007 University of North Carolina at Chapel Hill
00011 //      All Rights Reserved
00012 //
00013 //      Permission to use, copy, modify and distribute this software and its
00014 //      documentation for educational, research and non-profit purposes, without
00015 //      fee, and without a written agreement is hereby granted, provided that the
00016 //      above copyright notice and the following paragraph appear in all copies.
00017 //      
00018 //      The University of North Carolina at Chapel Hill make no representations
00019 //      about the suitability of this software for any purpose. It is provided
00020 //      'as is' without express or implied warranty. 
00021 //
00022 //      Please send BUG REPORTS to ccwu@cs.unc.edu
00023 //
00025 
00026 
00027 #ifndef GL_TEX_IMAGE_H
00028 #define GL_TEX_IMAGE_H
00029 
00030 class GlobalUtil;
00031 class GLTexImage :public GlobalUtil 
00032 {       
00033 protected:
00034         GLuint  _texID;
00035         int             _imgWidth;
00036         int             _imgHeight;
00037         int             _texWidth;
00038         int             _texHeight;
00039         int             _drawWidth;
00040         int             _drawHeight;
00041 public:
00042         static void DetachFBO(int i);
00043         static void UnbindTex();
00044         static void UnbindMultiTex(int n);
00045         static void DrawQuad(float x1, float x2, float y1, float y2);
00046 
00047 public:
00048         virtual void DrawQuadUS(int scale);
00049         virtual void DrawQuadDS(int scale);
00050         virtual void DrawImage();
00051         virtual void TexConvertRGB();
00052         virtual void ZeroHistoMargin();
00053         virtual void SetImageSize(int width, int height);
00054         virtual void InitTexture(int width, int height, int clamp_to_edge =1 );
00055         void InitTexture(int width, int height, int clamp_to_edge, GLuint format);
00056         virtual void FillMargin(int marginx, int marginy);
00057 public:
00058         void DrawScaledQuad(float scale);
00059         int  CopyToPBO(GLuint pbo, int width, int height, GLenum format = GL_RGBA);
00060         void CopyFromPBO(GLuint pbo, int width, int height, GLenum format = GL_RGBA);
00061         void FitRealTexViewPort();
00062         void DrawQuadMT8();
00063         void DrawQuadMT4();
00064         void DrawQuadReduction();
00065         void DrawQuadReduction(int w, int h);
00066         void DrawMargin(int right, int bottom);
00067         void DrawQuad();
00068         void FitTexViewPort();
00069         void ZeroHistoMargin(int hw, int hh);
00070         int  CheckTexture();
00071 public:
00072         void AttachToFBO(int i );
00073         void BindTex();
00074         operator GLuint (){return _texID;}      
00075         GLuint GetTexID(){return _texID;}
00076         int     GetImgPixelCount(){return _imgWidth*_imgHeight;}
00077         int GetTexPixelCount(){return _texWidth*_texHeight;}
00078         int     GetImgWidth(){return _imgWidth;}
00079         int GetImgHeight(){return _imgHeight;}
00080         int     GetTexWidth(){return _texWidth;}
00081         int GetTexHeight(){return _texHeight;}
00082         int     GetDrawWidth(){return _drawWidth;}
00083         int GetDrawHeight(){return _drawHeight;}
00084         //int   IsTexTight(){return _texWidth == _drawWidth && _texHeight == _drawHeight;}
00085         int     IsTexPacked(){return _drawWidth != _imgWidth;}
00086         GLTexImage();
00087         virtual ~GLTexImage();
00088         friend class SiftGPU;
00089 };
00090 
00091 //class for handle data input, to support all openGL-supported data format, 
00092 //data are first uploaded to an openGL texture then converted, and optionally
00093 //when the datatype is simple, we downsample/convert on cpu
00094 class GLTexInput:public GLTexImage
00095 {
00096 public:
00097         int      _down_sampled;
00098         int      _rgb_converted;
00099     int      _data_modified;
00100 
00102         float *        _converted_data;
00103     const void*    _pixel_data;
00104 public:
00105         static int  IsSimpleGlFormat(unsigned int gl_format, unsigned int gl_type)
00106         {
00107                 //the formats there is a cpu code to conver rgb and downsample
00108                  return (gl_format ==GL_LUMINANCE ||gl_format == GL_LUMINANCE_ALPHA||
00109                                 gl_format == GL_RGB||   gl_format == GL_RGBA||
00110                                 gl_format == GL_BGR || gl_format == GL_BGRA) && 
00111                                 (gl_type == GL_UNSIGNED_BYTE || gl_type == GL_FLOAT || gl_type == GL_UNSIGNED_SHORT); 
00112         }
00113 //in vc6, template member function doesn't work
00114 #if !defined(_MSC_VER) || _MSC_VER > 1200
00115         template <class Uint> 
00116         static int DownSamplePixelDataI(unsigned int gl_format, int width, int height, 
00117                 int ds, const Uint * pin, Uint * pout);
00118         template <class Uint> 
00119         static int DownSamplePixelDataI2F(unsigned int gl_format, int width, int height, 
00120                 int ds, const Uint * pin, float * pout, int skip  = 0);
00121 #endif
00122         static int DownSamplePixelDataF(unsigned int gl_format, int width, int height, 
00123                 int ds, const float * pin, float * pout, int skip = 0);
00124     static int TruncateWidthCU(int w) {return  w & 0xfffffffc; }
00125 public:
00126         GLTexInput() : _down_sampled(0), _rgb_converted(0), _data_modified(0), 
00127                     _converted_data(0), _pixel_data(0){}
00128         int SetImageData(int width, int height, const void * data, 
00129                                         unsigned int gl_format, unsigned int gl_type);
00130         int LoadImageFile(char * imagepath, int & w, int &h);
00131     void VerifyTexture();
00132     virtual ~GLTexInput();
00133 };
00134 
00135 //GLTexPacked doesn't have any data
00136 //so that we can use the GLTexImage* pointer to index a GLTexPacked Vector
00137 
00138 class GLTexPacked:public GLTexImage
00139 {
00140 public:
00141         virtual void    DrawImage();
00142         virtual void    DrawQuadUS(int scale);
00143         virtual void    DrawQuadDS(int scale);
00144         virtual void    FillMargin(int marginx, int marginy);
00145         virtual void    InitTexture(int width, int height, int clamp_to_edge =1);
00146         virtual void    TexConvertRGB();
00147         virtual void    SetImageSize(int width, int height);
00148         virtual void    ZeroHistoMargin();
00149         //virtual void  GetHistWH(int& w, int& h){return w = (3 + sz)>>1;}
00150 public:
00151         void    DrawMargin(int right, int bottom, int mx, int my);
00152         GLTexPacked():GLTexImage(){}
00153 };
00154 
00155 
00156 #endif // !defined(GL_TEX_IMAGE_H)
00157 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


rgbd_registration
Author(s): Ross Kidson
autogenerated on Thu May 23 2013 15:36:53