Changeset 397 for trunk/gui/vizservers/nanovis/Lic.cpp
- Timestamp:
- Apr 4, 2006 4:01:47 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/vizservers/nanovis/Lic.cpp
r396 r397 15 15 16 16 17 #include <stdlib.h> 18 #include <math.h> 19 #include <assert.h> 17 20 18 21 #include "Lic.h" 19 22 20 21 Lic::Lic(int _size, int _width, int _height): 23 Lic::Lic(int _size, int _width, int _height, float _offset, 24 CGcontext _context, NVISid _vector_field, 25 float scalex, float scaley, float scalez): 22 26 size(_size), 27 offset(_offset), 28 m_g_context(_context), 23 29 display_width(_width), 24 display_height(_height) 30 display_height(_height), 31 iframe(0), 32 Npat(64), 33 alpha(0.12*255), 34 tmax(NPIX/(SCALE*NPN)), 35 dmax(SCALE/NPIX) 25 36 { 37 scale = Vector3(scalex, scaley, scalez); 38 slice_vector = new float[NMESH*NMESH*4]; 26 39 27 40 //initialize the pattern texture … … 39 52 40 53 //initialize frame buffer objects 54 55 //render buffer for projecting 3D velocity onto a 2D plane 41 56 glGenFramebuffersEXT(1, &vel_fbo); 42 57 glGenTextures(1, &slice_vector_tex); … … 44 59 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo); 45 60 46 //initialize texture storing per slice vectors47 61 glBindTexture(GL_TEXTURE_RECTANGLE_NV, slice_vector_tex); 48 62 glTexParameterf(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); … … 54 68 55 69 56 // lic result fbo70 //render buffer for the convolution 57 71 glGenFramebuffersEXT(1, &fbo); 58 72 glGenTextures(1, &color_tex); … … 74 88 assert(glGetError()==0); 75 89 76 } 77 78 79 void Lic::MakePatterns(void) 90 m_render_vel_fprog = loadProgram(m_g_context, CG_PROFILE_FP30, CG_SOURCE, "./shaders/render_vel.cg"); 91 m_vel_tex_param_render_vel = cgGetNamedParameter(m_render_vel_fprog, "vel_tex"); 92 m_plane_normal_param_render_vel = cgGetNamedParameter(m_render_vel_fprog, "plane_normal"); 93 cgGLSetTextureParameter(m_vel_tex_param_render_vel, _vector_field); 94 95 get_slice(); 96 make_patterns(); 97 98 fprintf(stderr, "initialize lic ...\n"); 99 } 100 101 Lic::~Lic(){ 102 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo); 103 glDeleteTextures(1, &slice_vector_tex); 104 105 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 106 glDeleteTextures(1, &color_tex); 107 108 NVISid buffers[2] = {vel_fbo, fbo}; 109 glDeleteFramebuffersEXT(2, buffers); 110 111 delete slice_vector; 112 } 113 114 void Lic::make_patterns() 80 115 { 81 116 int lut[256]; … … 107 142 108 143 109 void Lic:: MakeMagnitudes()144 void Lic::make_magnitudes() 110 145 { 111 146 … … 145 180 } 146 181 182 //project 3D vectors to a 2D slice for line integral convolution 183 void Lic::get_slice(){ 184 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo); 185 glBindTexture(GL_TEXTURE_RECTANGLE_NV, slice_vector_tex); 186 187 glClear(GL_COLOR_BUFFER_BIT); 188 189 glViewport(0, 0, NMESH, NMESH); 190 glMatrixMode(GL_PROJECTION); 191 glLoadIdentity(); 192 gluOrtho2D(0, NMESH, 0, NMESH); 193 glMatrixMode(GL_MODELVIEW); 194 glLoadIdentity(); 195 196 cgGLBindProgram(m_render_vel_fprog); 197 cgGLEnableTextureParameter(m_vel_tex_param_render_vel); 198 cgGLSetParameter4f(m_plane_normal_param_render_vel, 1., 1., 0., 0); 199 200 cgGLEnableProfile(CG_PROFILE_FP30); 201 glBegin(GL_QUADS); 202 glTexCoord3f(0., 0., offset); glVertex2f(0., 0.); 203 glTexCoord3f(1., 0., offset); glVertex2f(size, 0.); 204 glTexCoord3f(1., 1., offset); glVertex2f(size, size); 205 glTexCoord3f(0., 1., offset); glVertex2f(0., size); 206 glEnd(); 207 cgGLDisableProfile(CG_PROFILE_FP30); 208 209 cgGLDisableTextureParameter(m_vel_tex_param_render_vel); 210 211 //read the vectors 212 glReadPixels(0, 0, NMESH, NMESH, GL_RGBA, GL_FLOAT, slice_vector); 213 /* 214 for(int i=0; i<NMESH*NMESH; i++){ 215 fprintf(stderr, "%f,%f,%f,%f", slice_vector[4*i], slice_vector[4*i+1], slice_vector[4*i+2], slice_vector[4*i+3]); 216 } 217 */ 218 assert(glGetError()==0); 219 } 220 147 221 148 222 //line integral convolution 149 223 void Lic::convolve(){ 224 150 225 int i, j; 151 226 float x1, x2, y, px, py; 227 228 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 152 229 153 230 glViewport(0, 0, (GLsizei) NPIX, (GLsizei) NPIX); … … 167 244 y = DM*j; 168 245 glTexCoord2f(x1, y); 169 get DP(x1, y, &px, &py);246 get_velocity(x1, y, &px, &py); 170 247 glVertex2f(px, py); 171 248 172 249 glTexCoord2f(x2, y); 173 get DP(x2, y, &px, &py);250 get_velocity(x2, y, &px, &py); 174 251 glVertex2f(px, py); 175 252 } … … 201 278 glDisable(GL_BLEND); 202 279 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, NPIX, NPIX, 0); 203 } 204 205 void display(){ 206 207 208 } 209 280 281 /* 282 //blend magnitude texture 283 glBindTexture(GL_TEXTURE_2D, mag_tex); 284 glEnable(GL_TEXTURE_2D); 285 glEnable(GL_BLEND); 286 glBegin(GL_QUADS); 287 glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0); 288 glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 1.); 289 glTexCoord2f(1.0, 1.0); glVertex2f(1., 1.); 290 glTexCoord2f(1.0, 0.0); glVertex2f(1., 0.0); 291 glEnd(); 292 */ 293 } 294 295 void Lic::display(){ 296 297 glBindTexture(GL_TEXTURE_2D, color_tex); 298 glEnable(GL_TEXTURE_2D); 299 300 //draw line integral convolution quad 301 glEnable(GL_DEPTH_TEST); 302 glPushMatrix(); 303 glScalef(scale.x, scale.y, scale.z); 304 305 glBegin(GL_QUADS); 306 glTexCoord2f(0, 0); glVertex3f(0, 0, offset); 307 glTexCoord2f(1, 0); glVertex3f(1, 0, offset); 308 glTexCoord2f(1, 1); glVertex3f(1, 1, offset); 309 glTexCoord2f(0, 1); glVertex3f(0, 1, offset); 310 glEnd(); 311 312 glPopMatrix(); 313 314 glDisable(GL_DEPTH_TEST); 315 glDisable(GL_TEXTURE_2D); 316 } 317 318 319 void Lic::get_velocity(float x, float y, float *px, float *py) 320 { 321 float dx, dy, vx, vy, r; 322 323 int xi = x*NMESH; 324 int yi = y*NMESH; 325 326 vx = slice_vector[4*(xi+yi*NMESH)]; 327 vy = slice_vector[4*(xi+yi*NMESH)+1]; 328 r = vx*vx + vy*vy; 329 if (r > dmax*dmax) { 330 r = sqrt(r); 331 vx *= dmax/r; 332 vy *= dmax/r; 333 } 334 *px = x + vx; 335 *py = y + vy; 336 } 337 338 void Lic::set_offset(float v){ 339 offset = v; 340 get_slice(); 341 }
Note: See TracChangeset
for help on using the changeset viewer.