$search
00001 00002 #ifndef _TG_IMAGE_PROCESSOR_H_ 00003 #define _TG_IMAGE_PROCESSOR_H_ 00004 00005 #include <blort/TomGine/headers.h> 00006 00007 #include <blort/TomGine/tgShader.h> 00008 #include <blort/TomGine/tgTexture.h> 00009 #include <blort/TomGine/tgCamera.h> 00010 00011 namespace TomGine{ 00012 00014 class tgImageProcessor{ 00015 private: 00016 unsigned m_width; // Image width in pixels 00017 unsigned m_height; // Image height in pixels 00018 00019 tgShader* m_shadeGauss; // Fragment shader for blurring image using gaussian filter 00020 tgShader* m_shadeSobel; // Fragment shader for edge detection with sobel algorithm 00021 tgShader* m_shadeThinning; // Fragment shader for thinning edges 00022 tgShader* m_shadeSpreading; // Fragment shader for spreading edges 00023 00024 TomGine::tgCamera m_cam_ortho, m_cam_ortho_fbo; 00025 00026 GLuint fbo; 00027 GLuint fbo_tex; 00028 GLuint fbo_tex_depth; 00029 int fbo_res; 00030 int fbo_stage; 00031 bool m_avg_init; 00032 00033 void drawQuadUpsideDown(float w, float h); 00034 void drawQuad(float w, float h); 00035 bool transform(float i, float j, float *ix, float *iy); 00036 00037 void init(unsigned width, unsigned height); 00038 00039 void initFBO(int res); 00040 00041 public: 00042 tgImageProcessor( const char *gauss_frag_file, 00043 const char *sobel_frag_file, 00044 const char *thinning_frag_file, 00045 const char *spreading_frag_file, 00046 unsigned img_width, unsigned img_height, 00047 int avg_resolution); 00048 ~tgImageProcessor(); 00049 00050 void initShader(float width, float height); 00051 00052 // Set functions 00053 void setCamOrtho(); 00054 int getWidth(){ return m_width; } 00055 int getHeight(){ return m_height; } 00056 00057 // Image Processing functions 00058 void flipUpsideDown(const tgTexture& source, tgTexture& result); 00059 void copy(const tgTexture& source, tgTexture& result); 00060 void gauss(const tgTexture& source, tgTexture& result); 00061 void sobel(const tgTexture& source, tgTexture& result, float threshold=0.01, bool normalise=false, bool binary=false); 00062 void sobel(const tgTexture& source, tgTexture& result, tgTexture& mask, float threshold=0.01, bool normalize=false, bool binary=false); 00063 void thinning(const tgTexture& source, tgTexture& result); 00064 void thinning(const tgTexture& source, tgTexture& result, tgTexture& mask); 00065 void spreading(const tgTexture& source, tgTexture& result); 00066 void render(const tgTexture& tex); 00067 00068 // average computations 00069 void avgActivate(); 00070 void avgGet(float *avg, int lvl=0); 00071 void avgDeactivate(); 00072 inline int avgGetResolution(){ return fbo_res; } 00073 }; 00074 00075 } // namespace TomGine 00076 00077 #endif