ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ShaderMan.cpp
Go to the documentation of this file.
1 // File: ShaderMan.cpp
3 // Author: Changchang Wu
4 // Description : implementation of the ShaderMan class.
5 // A Shader Manager that calls different implementation of shaders
6 //
7 //
8 // Copyright (c) 2007 University of North Carolina at Chapel Hill
9 // All Rights Reserved
10 //
11 // Permission to use, copy, modify and distribute this software and its
12 // documentation for educational, research and non-profit purposes, without
13 // fee, and without a written agreement is hereby granted, provided that the
14 // above copyright notice and the following paragraph appear in all copies.
15 //
16 // The University of North Carolina at Chapel Hill make no representations
17 // about the suitability of this software for any purpose. It is provided
18 // 'as is' without express or implied warranty.
19 //
20 // Please send BUG REPORTS to ccwu@cs.unc.edu
21 //
23 
24 
25 #include "GL/glew.h"
26 #include <vector>
27 #include <iostream>
28 #include <stdlib.h>
29 #include <math.h>
30 using std::vector;
31 using std::ostream;
32 using std::endl;
33 
34 
35 #include "ProgramGLSL.h"
36 #include "GlobalUtil.h"
37 #include "GLTexImage.h"
38 #include "SiftGPU.h"
39 #include "ShaderMan.h"
40 
43 
45 // Construction/Destruction
47 
49 {
50  if(s_bag) return;
51 
53  else s_bag =new ShaderBagGLSL;
54 
55  GlobalUtil::StartTimer("Load Programs");
57  s_bag->LoadDynamicShaders(param);
60 
61  GlobalUtil::CheckErrorsGL("InitShaderMan");
62 }
63 
64 
66 {
67  if(s_bag) delete s_bag;
68  s_bag = NULL;
69 }
70 
72 {
73  if(s_bag) s_bag->UnloadProgram();
74 }
75 
77 {
78  if(filter == NULL) return;
79 
81  src->FillMargin(filter->_size, 0);
82 
83  //output parameter
84  if(tmp) tmp->AttachToFBO(0);
85  else dst->AttachToFBO(0);
86 
87 
88  //input parameter
89  src->BindTex();
90  dst->FitTexViewPort();
91 
92  //horizontal filter
93  filter->s_shader_h->UseProgram();
94  dst->DrawQuad();
95 
96  //parameters
97  if(tmp)
98  {
99  // fill margin for out-of-boundary lookup
100  tmp->DetachFBO(0);
101  tmp->AttachToFBO(0);
102  tmp->FillMargin(0, filter->_size);
103  tmp->DetachFBO(0);
104  dst->AttachToFBO(0);
105  tmp->BindTex();
106  }
107  else
108  {
109  glFinish();
110  // fill margin for out-of-boundary lookup
111  dst->FillMargin(0, filter->_size);
112  dst->BindTex();
113  }
114 
115  //vertical filter
116  filter->s_shader_v->UseProgram();
117  dst->DrawQuad();
118 
119 
120  //clean up
121  dst->UnbindTex();
122  dst->DetachFBO(0);
123 
124  //
126 }
127 
128 
130 {
132 }
133 
135 {
137 }
138 
140 {
141 
142  dst->AttachToFBO(0);
143 
144  src->BindTex();
145 
146  dst->FitTexViewPort();
147 
148  dst->DrawQuad();
149 
150  dst->UnbindTex();
151 // ShaderMan::UnloadProgram();
152  dst->DetachFBO(0);
153  return;
154 }
156 {
157  //output parameter
158 
159  dst->AttachToFBO(0);
160 
161  //input parameter
162  src->BindTex();
163 
164  //
165  dst->FitTexViewPort();
166 
168 
169  dst->DrawQuadDS(scale);
170  src->UnbindTex();
171 
172  UnloadProgram();
173 
174  dst->DetachFBO(0);
175 }
176 
178 {
179 
180  //output parameter
181  dst->AttachToFBO(0);
182  //input parameter
183  src->BindTex();
184 
185  dst->FitTexViewPort();
186 
188 
190  {
192  }
193 
194  dst->DrawQuadUS(scale);
195  src->UnbindTex();
196 
197  UnloadProgram();
198 
199  dst->DetachFBO(0);
200 
202 }
203 
204 
205 
207 {
209 }
210 
212 {
214 }
215 
216 
217 
219 {
221 }
222 
223 
225 {
227 }
228 
229 
231 {
233 }
234 
235 
236 
237 
238 
240 {
242  s_bag->SetGradPassParam(texP);
243 }
244 
245 
246 void ShaderMan::UseShaderKeypoint(int texU, int texD)
247 {
249  s_bag->SetDogTexParam(texU, texD);
250 }
251 
252 
253 
254 void ShaderMan::UseShaderGenListInit(int w, int h, int tight)
255 {
256  if(tight)
257  {
259  }else
260  {
262  s_bag->SetGenListInitParam(w, h);
263  }
264 }
265 
267 {
269 
270 }
271 
272 
273 
274 
275 void ShaderMan::UseShaderGenListStart(float fw, int tex0)
276 {
278  s_bag->SetGenListStartParam(fw, tex0);
279 }
280 
281 void ShaderMan::UseShaderGenListStep(int tex, int tex0)
282 {
284  s_bag->SetGenListStepParam( tex, tex0);
285 }
286 
288 {
290  s_bag->SetGenListEndParam(ktex);
291 }
292 
294 {
296 }
297 
299 {
301 }
302 
303 void ShaderMan::UseShaderGenVBO( float width, float fwidth, float size)
304 {
306  s_bag->SetGenVBOParam(width, fwidth, size);
307 }
308 void ShaderMan::UseShaderMarginCopy(int xmax, int ymax)
309 {
311  s_bag->SetMarginCopyParam(xmax, ymax);
312 
313 }
315 {
317 }
318 
319 void ShaderMan::UseShaderSimpleOrientation(int oTex, float sigma, float sigma_step)
320 {
322  s_bag->SetSimpleOrientationInput(oTex, sigma, sigma_step);
323 }
324 
325 
326 
327 void ShaderMan::UseShaderOrientation(int gtex, int width, int height, float sigma, int auxtex, float step, int keypoint_list)
328 {
330 
331  //changes in v345.
332  //set sigma to 0 to identify keypoit list mode
333  //set sigma to negative to identify fixed_orientation
334  if(keypoint_list) sigma = 0.0f;
335  else if(GlobalUtil::_FixedOrientation) sigma = - sigma;
336 
337  s_bag->SetFeatureOrientationParam(gtex, width, height, sigma, auxtex, step);
338 }
339 
340 void ShaderMan::UseShaderDescriptor(int gtex, int otex, int dwidth, int fwidth, int width, int height, float sigma)
341 {
343  s_bag->SetFeatureDescirptorParam(gtex, otex, (float)dwidth, (float)fwidth, (float)width, (float)height, sigma);
344 }
345 
347 {
348  s_bag->SelectInitialSmoothingFilter(octave_min, param);
349 }
int width
int size
int height
#define NULL
ProgramGPU * s_shader_h
Definition: ProgramGPU.h:49
ProgramGPU * s_shader_v
Definition: ProgramGPU.h:50
void FitTexViewPort()
Definition: GLTexImage.cpp:353
virtual void FillMargin(int marginx, int marginy)
Definition: GLTexImage.cpp:181
void BindTex()
Definition: GLTexImage.cpp:159
static void DetachFBO(int i)
Definition: GLTexImage.cpp:368
static void DrawQuad(float x1, float x2, float y1, float y2)
Definition: GLTexImage.cpp:374
static void UnbindTex()
Definition: GLTexImage.cpp:164
virtual void DrawQuadDS(int scale)
Definition: GLTexImage.cpp:401
void AttachToFBO(int i)
Definition: GLTexImage.cpp:363
virtual void DrawQuadUS(int scale)
Definition: GLTexImage.cpp:406
static int _UseSiftGPUEX
Definition: GlobalUtil.h:76
static int _FixedOrientation
Definition: GlobalUtil.h:84
static int _usePackedTex
Definition: GlobalUtil.h:48
static void CheckErrorsGL(const char *location=NULL)
Definition: GlobalUtil.h:137
static void StopTimer()
Definition: GlobalUtil.h:127
static void StartTimer(const char *event)
Definition: GlobalUtil.h:128
static void SetTextureParameter()
Definition: GlobalUtil.cpp:211
static void SetTextureParameterUS()
Definition: GlobalUtil.cpp:223
virtual int UseProgram()=0
FilterProgram * f_gaussian_skip1
Definition: ProgramGLSL.h:143
virtual void LoadFixedShaders()=0
virtual void SetGenListStepParam(int tex, int tex0)=0
ProgramGPU * s_keypoint
Definition: ProgramGLSL.h:124
ProgramGPU * s_display_gaussian
Definition: ProgramGLSL.h:111
ProgramGPU * s_display_grad
Definition: ProgramGLSL.h:115
ProgramGPU * s_genlist_histo
Definition: ProgramGLSL.h:129
virtual void SetSimpleOrientationInput(int oTex, float sigma, float sigma_step)
Definition: ProgramGLSL.h:153
virtual void SetGenVBOParam(float width, float fwidth, float size)=0
ProgramGPU * s_genlist_step
Definition: ProgramGLSL.h:131
ProgramGPU * s_genlist_end
Definition: ProgramGLSL.h:132
ProgramGPU * s_descriptor_fp
Definition: ProgramGLSL.h:137
ProgramGPU * s_orientation
Definition: ProgramGLSL.h:109
virtual void SetGradPassParam(int texP=0)
Definition: ProgramGLSL.h:162
ProgramGPU * s_genlist_init_ex
Definition: ProgramGLSL.h:128
virtual void SetGenListInitParam(int w, int h)
Definition: ProgramGLSL.h:147
virtual void SetMarginCopyParam(int xmax, int ymax)
Definition: ProgramGLSL.h:149
ProgramGPU * s_display_dog
Definition: ProgramGLSL.h:113
FilterProgram * f_gaussian_skip0
Definition: ProgramGLSL.h:141
ProgramGPU * s_margin_copy
Definition: ProgramGLSL.h:139
virtual void SetDogTexParam(int texU, int texD)=0
virtual void SetFeatureOrientationParam(int gtex, int width, int height, float sigma, int stex, float step)
Definition: ProgramGLSL.h:152
ProgramGPU * s_gray
Definition: ProgramGLSL.h:102
ProgramGPU * s_debug
Definition: ProgramGLSL.h:106
virtual void SetGenListEndParam(int ktex)
Definition: ProgramGLSL.h:148
virtual void UnloadProgram()=0
void LoadDynamicShaders(SiftParam &param)
ProgramGPU * s_genlist_start
Definition: ProgramGLSL.h:130
ProgramGPU * s_copy_key
Definition: ProgramGLSL.h:104
ProgramGPU * s_vertex_list
Definition: ProgramGLSL.h:135
ProgramGPU * s_zero_pass
Definition: ProgramGLSL.h:133
void SelectInitialSmoothingFilter(int octave_min, SiftParam &param)
ProgramGPU * s_sampling
Definition: ProgramGLSL.h:119
ProgramGPU * s_genlist_init_tight
Definition: ProgramGLSL.h:127
ProgramGPU * s_display_keys
Definition: ProgramGLSL.h:117
virtual void SetGenListStartParam(float width, int tex0)=0
virtual void LoadDisplayShaders()=0
virtual void SetFeatureDescirptorParam(int gtex, int otex, float dwidth, float fwidth, float width, float height, float sigma)
Definition: ProgramGLSL.h:151
ProgramGPU * s_grad_pass
Definition: ProgramGLSL.h:121
static void UseShaderDisplayGrad()
Definition: ShaderMan.cpp:224
static void UseShaderGenListHisto()
Definition: ShaderMan.cpp:266
static void UseShaderGenListEnd(int ktex)
Definition: ShaderMan.cpp:287
static void UseShaderZeroPass()
Definition: ShaderMan.cpp:298
static void UseShaderDisplayDOG()
Definition: ShaderMan.cpp:211
static void FilterSampledImage(GLTexImage *tex, GLTexImage *buf)
Definition: ShaderMan.cpp:134
static void FilterInitialImage(GLTexImage *tex, GLTexImage *buf)
Definition: ShaderMan.cpp:129
static void UseShaderRGB2Gray()
Definition: ShaderMan.cpp:218
static void UseShaderDisplayGaussian()
Definition: ShaderMan.cpp:206
static void UseShaderMarginCopy(int xmax, int ymax)
Definition: ShaderMan.cpp:308
static void UseShaderGenListStart(float fw, int tex0)
Definition: ShaderMan.cpp:275
static void UseShaderCopyKeypoint()
Definition: ShaderMan.cpp:314
static void InitShaderMan(SiftParam &param)
Definition: ShaderMan.cpp:48
static void FilterImage(FilterProgram *filter, GLTexImage *dst, GLTexImage *src, GLTexImage *tmp)
Definition: ShaderMan.cpp:76
static void DestroyShaders()
Definition: ShaderMan.cpp:65
static void UnloadProgram()
Definition: ShaderMan.cpp:71
static void TextureCopy(GLTexImage *dst, GLTexImage *src)
Definition: ShaderMan.cpp:139
static void UseShaderGenListInit(int w, int h, int tight=1)
Definition: ShaderMan.cpp:254
static void UseShaderKeypoint(int texU, int texD)
Definition: ShaderMan.cpp:246
static void UseShaderGenVBO(float width, float fwidth, float size)
Definition: ShaderMan.cpp:303
static void TextureUpSample(GLTexImage *dst, GLTexImage *src, int scale)
Definition: ShaderMan.cpp:177
static void SelectInitialSmoothingFilter(int octave_min, SiftParam &param)
Definition: ShaderMan.cpp:346
static void UseShaderDescriptor(int gtex, int otex, int dwidth, int fwidth, int width, int height, float sigma)
Definition: ShaderMan.cpp:340
static void UseShaderGradientPass(int texP=0)
Definition: ShaderMan.cpp:239
static void TextureDownSample(GLTexImage *dst, GLTexImage *src, int scale=2)
Definition: ShaderMan.cpp:155
static void UseShaderOrientation(int gtex, int width, int height, float sigma, int auxtex, float step, int keypoint_list)
Definition: ShaderMan.cpp:327
static void UseShaderDisplayKeypoints()
Definition: ShaderMan.cpp:230
static void UseShaderDebug()
Definition: ShaderMan.cpp:293
static void UseShaderSimpleOrientation(int oTex, float sigma, float sigma_step)
Definition: ShaderMan.cpp:319
static ShaderBag * s_bag
Definition: ShaderMan.h:43
static void UseShaderGenListStep(int tex, int tex0)
Definition: ShaderMan.cpp:281
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718