Changeset 2920 for trunk/packages/vizservers
- Timestamp:
- Apr 1, 2012, 5:19:58 PM (13 years ago)
- Location:
- trunk/packages/vizservers/nanovis
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/FlowCmd.cpp
r2877 r2920 1065 1065 } 1066 1066 // FIXME: This doesn't work when there is more than one flow. 1067 licRenderer->set _offset(flowPtr->GetRelativePosition());1067 licRenderer->setOffset(flowPtr->GetRelativePosition()); 1068 1068 NanoVis::velocityArrowsSlice->slicePos(flowPtr->GetRelativePosition()); 1069 1069 -
trunk/packages/vizservers/nanovis/FlowCmd.h
r2875 r2920 298 298 { 299 299 /* Must set axis before offset or position goes to wrong axis. */ 300 NanoVis::licRenderer->set _axis(_sv.slicePos.axis);301 NanoVis::licRenderer->set _offset(_sv.slicePos.value);300 NanoVis::licRenderer->setAxis(_sv.slicePos.axis); 301 NanoVis::licRenderer->setOffset(_sv.slicePos.value); 302 302 NanoVis::licRenderer->active(true); 303 303 } … … 322 322 void SetAxis() 323 323 { 324 NanoVis::licRenderer->set _axis(_sv.slicePos.axis);324 NanoVis::licRenderer->setAxis(_sv.slicePos.axis); 325 325 } 326 326 … … 328 328 { 329 329 _sv.slicePos.axis = axis; 330 NanoVis::licRenderer->set _axis(_sv.slicePos.axis);330 NanoVis::licRenderer->setAxis(_sv.slicePos.axis); 331 331 } 332 332 … … 334 334 { 335 335 _sv.slicePos.value = position; 336 NanoVis::licRenderer->set _offset(_sv.slicePos.value);336 NanoVis::licRenderer->setOffset(_sv.slicePos.value); 337 337 } 338 338 339 339 void SetCurrentPosition() 340 340 { 341 NanoVis::licRenderer->set _offset(_sv.slicePos.value);341 NanoVis::licRenderer->setOffset(_sv.slicePos.value); 342 342 } 343 343 -
trunk/packages/vizservers/nanovis/NvLIC.cpp
r2884 r2920 29 29 #define SCALE 3.0 //scale for background pattern. small value -> fine texture 30 30 31 NvLIC::NvLIC(int _size, int _width, int _height, int _axis,32 const Vector3& _offset, CGcontext _context) :31 NvLIC::NvLIC(int size, int width, int height, int axis, 32 const Vector3& offset) : 33 33 Renderable(Vector3(0.0f, 0.0f, 0.0f)), 34 disListID(0), 35 width(_width), 36 height(_height), 37 size(_size), 38 scale(1.0f, 1.0f, 1.0f), 39 offset(_offset), 40 iframe(0), 41 Npat(64), 42 alpha((int) 0.12*255), 43 tmax(NPIX/(SCALE*NPN)), 44 dmax(SCALE/NPIX), 45 max(1.0f), 46 _cgContext(_context), 34 _width(width), 35 _height(height), 36 _size(size), 37 _scale(1.0f, 1.0f, 1.0f), 38 _origin(0, 0, 0), 39 _offset(offset), 40 _axis(axis), 41 _iframe(0), 42 _Npat(64), 43 _alpha((int)0.12*255), 44 _tmax(NPIX/(SCALE*NPN)), 45 _dmax(SCALE/NPIX), 46 _max(1.0f), 47 _disListID(0), 47 48 _vectorFieldId(0), 48 49 _activate(false) 49 50 { 50 51 axis = _axis; 52 slice_vector = new float[size*size*4]; 53 memset(slice_vector, 0, sizeof(float) * size * size * 4); 54 55 origin.set(0, 0, 0); 51 _sliceVector = new float[_size*_size*4]; 52 memset(_sliceVector, 0, sizeof(float) * _size * _size * 4); 53 54 int fboOrig; 55 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &fboOrig); 56 56 57 57 //initialize the pattern texture 58 glGenTextures(1, & pattern_tex);59 glBindTexture(GL_TEXTURE_2D, pattern_tex);58 glGenTextures(1, &_patternTex); 59 glBindTexture(GL_TEXTURE_2D, _patternTex); 60 60 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 61 61 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); … … 64 64 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 65 65 66 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, NPN, NPN, 0, 67 GL_RGBA, GL_UNSIGNED_BYTE, NULL); 68 66 69 //initialize frame buffer objects 67 70 //render buffer for projecting 3D velocity onto a 2D plane 68 glGenFramebuffersEXT(1, & vel_fbo);69 glGenTextures(1, & slice_vector_tex);70 71 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo);72 73 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, slice_vector_tex);71 glGenFramebuffersEXT(1, &_velFbo); 72 glGenTextures(1, &_sliceVectorTex); 73 74 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _velFbo); 75 76 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _sliceVectorTex); 74 77 glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 75 78 glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 76 77 // ADD INSOO 78 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, 79 GL_CLAMP_TO_EDGE); 80 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, 81 GL_CLAMP_TO_EDGE); 82 83 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA32F_ARB, size, size, 84 0, GL_RGBA, GL_FLOAT, NULL); 79 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 80 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 81 82 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA32F_ARB, _size, _size, 83 0, GL_RGBA, GL_FLOAT, NULL); 85 84 86 85 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, 87 GL_TEXTURE_RECTANGLE_ARB, slice_vector_tex, 0);86 GL_TEXTURE_RECTANGLE_ARB, _sliceVectorTex, 0); 88 87 89 88 //render buffer for the convolution 90 glGenFramebuffersEXT(1, & fbo);91 glGenTextures(1, & color_tex);92 93 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);89 glGenFramebuffersEXT(1, &_fbo); 90 glGenTextures(1, &_colorTex); 91 92 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fbo); 94 93 95 94 //initialize color texture for lic 96 glBindTexture(GL_TEXTURE_2D, color_tex); 97 // INSOO 98 //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 99 //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 100 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 101 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 102 103 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, 104 GL_RGB, GL_INT, NULL); 105 106 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 107 GL_COLOR_ATTACHMENT0_EXT, 108 GL_TEXTURE_2D, color_tex, 0); 95 glBindTexture(GL_TEXTURE_2D, _colorTex); 96 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 97 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 98 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 99 100 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, _width, _height, 0, 101 GL_RGB, GL_UNSIGNED_BYTE, NULL); 102 103 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, 104 GL_TEXTURE_2D, _colorTex, 0); 109 105 110 106 // Check framebuffer completeness at the end of initialization. 111 107 CHECK_FRAMEBUFFER_STATUS(); 112 108 113 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);114 115 _render _vel_fprog =116 LoadCgSourceProgram(_cgContext, "render_vel.cg",117 CG_PROFILE_FP40, "main"); 118 119 _vel_tex_param_render_vel =120 cgGetNamedParameter(_render_vel_fprog, "vel_tex"); 121 122 _plane_normal_param_render_vel =123 cgGetNamedParameter(_render_vel_fprog, "plane_normal"); 124 125 _max_param = cgGetNamedParameter(_render_vel_fprog,"vmax");126 127 make _patterns();109 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboOrig); 110 111 _renderVelShader = new NvShader(); 112 _renderVelShader->loadFragmentProgram("render_vel.cg", "main"); 113 114 _velTexParamRenderVel = 115 _renderVelShader->getNamedParameterFromFP("vel_tex"); 116 117 _planeNormalParamRenderVel = 118 _renderVelShader->getNamedParameterFromFP("plane_normal"); 119 120 _maxParam = 121 _renderVelShader->getNamedParameterFromFP("vmax"); 122 123 makePatterns(); 128 124 } 129 125 130 126 NvLIC::~NvLIC() 131 127 { 132 glDeleteTextures(1, & pattern_tex);133 glDeleteTextures(1, & mag_tex);134 135 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo);136 glDeleteTextures(1, & slice_vector_tex);137 138 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);139 glDeleteTextures(1, & color_tex);140 141 GLuint buffers[2] = { vel_fbo,fbo};128 glDeleteTextures(1, &_patternTex); 129 glDeleteTextures(1, &_magTex); 130 131 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _velFbo); 132 glDeleteTextures(1, &_sliceVectorTex); 133 134 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fbo); 135 glDeleteTextures(1, &_colorTex); 136 137 GLuint buffers[2] = {_velFbo, _fbo}; 142 138 glDeleteFramebuffersEXT(2, buffers); 143 139 144 glDeleteLists(disListID, Npat); 145 146 /* 147 TBD.. 148 cgDestroyParameter(_vel_tex_param_render_vel); 149 cgDestroyParameter(_plane_normal_param_render_vel); 150 cgDestroyParameter(_max_param); 151 */ 152 cgDestroyProgram(_render_vel_fprog); 153 154 delete [] slice_vector; 155 } 156 157 void 158 NvLIC::make_patterns() 140 glDeleteLists(_disListID, _Npat); 141 142 delete _renderVelShader; 143 144 delete [] _sliceVector; 145 } 146 147 void 148 NvLIC::makePatterns() 159 149 { 160 TRACE("begin make _patterns\n");161 if ( disListID > 0) {162 glDeleteLists(disListID,Npat);163 } 164 disListID = glGenLists(Npat);165 166 TRACE("DisplayList : %d\n", disListID);150 TRACE("begin makePatterns\n"); 151 if (_disListID > 0) { 152 glDeleteLists(_disListID, _Npat); 153 } 154 _disListID = glGenLists(_Npat); 155 156 TRACE("DisplayList : %d\n", _disListID); 167 157 168 158 int lut[256]; … … 179 169 } 180 170 } 181 for (k = 0; k < Npat; k++) {182 t = (k << 8) / Npat;171 for (k = 0; k < _Npat; k++) { 172 t = (k << 8) / _Npat; 183 173 for (i = 0; i < NPN; i++) { 184 174 for (j = 0; j < NPN; j++) { 185 175 pat[i][j][0] = pat[i][j][1] = pat[i][j][2] = 186 176 lut[(t + phase[i][j]) % 255]; 187 pat[i][j][3] = alpha;177 pat[i][j][3] = _alpha; 188 178 } 189 179 } 190 glNewList( disListID + k, GL_COMPILE);191 glBindTexture(GL_TEXTURE_2D, pattern_tex);192 glTexImage2D(GL_TEXTURE_2D, 0, 4, NPN, NPN, 0, GL_RGBA,193 GL_ UNSIGNED_BYTE, pat);180 glNewList(_disListID + k, GL_COMPILE); 181 glBindTexture(GL_TEXTURE_2D, _patternTex); 182 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, NPN, NPN, 0, 183 GL_RGBA, GL_UNSIGNED_BYTE, pat); 194 184 glEndList(); 195 185 } 196 186 197 glBindTexture(GL_TEXTURE_2D, pattern_tex);198 glTexImage2D(GL_TEXTURE_2D, 0, 4, NPN, NPN, 0,187 glBindTexture(GL_TEXTURE_2D, _patternTex); 188 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, NPN, NPN, 0, 199 189 GL_RGBA, GL_UNSIGNED_BYTE, pat); 200 TRACE("finish make _patterns\n");201 } 202 203 void NvLIC::make _magnitudes()190 TRACE("finish makePatterns\n"); 191 } 192 193 void NvLIC::makeMagnitudes() 204 194 { 205 195 GLubyte mag[NMESH][NMESH][4]; … … 225 215 } 226 216 } 227 glGenTextures(1, & mag_tex);228 glBindTexture(GL_TEXTURE_2D, mag_tex);217 glGenTextures(1, &_magTex); 218 glBindTexture(GL_TEXTURE_2D, _magTex); 229 219 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 230 220 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); … … 238 228 239 229 void 240 NvLIC::get_slice() 241 { 242 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo); 230 NvLIC::getSlice() 231 { 232 int fboOrig; 233 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &fboOrig); 234 235 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _velFbo); 236 237 glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT); 243 238 244 239 glClear(GL_COLOR_BUFFER_BIT); 245 246 glViewport(0, 0, size, size); 240 glDisable(GL_DEPTH_TEST); 241 glDisable(GL_BLEND); 242 243 glViewport(0, 0, _size, _size); 247 244 glMatrixMode(GL_PROJECTION); 245 glPushMatrix(); 248 246 glLoadIdentity(); 249 gluOrtho2D(0, size, 0,size);247 gluOrtho2D(0, _size, 0, _size); 250 248 glMatrixMode(GL_MODELVIEW); 249 glPushMatrix(); 251 250 glLoadIdentity(); 252 251 253 252 glEnable(GL_TEXTURE_3D); 254 253 glBindTexture(GL_TEXTURE_3D, _vectorFieldId); 255 cgGLBindProgram(_render_vel_fprog); 256 257 cgGLSetTextureParameter(_vel_tex_param_render_vel, _vectorFieldId); 258 cgGLEnableTextureParameter(_vel_tex_param_render_vel); 259 cgGLSetParameter4f(_plane_normal_param_render_vel, 1., 1., 0., 0); 260 cgGLSetParameter1f(_max_param, max); 261 262 cgGLEnableProfile(CG_PROFILE_FP40); 254 255 cgGLSetTextureParameter(_velTexParamRenderVel, _vectorFieldId); 256 cgGLEnableTextureParameter(_velTexParamRenderVel); 257 cgGLSetParameter4f(_planeNormalParamRenderVel, 1., 1., 0., 0); 258 cgGLSetParameter1f(_maxParam, _max); 259 260 _renderVelShader->bind(); 263 261 264 262 glBegin(GL_QUADS); 265 263 { 266 switch (axis) {267 268 269 glTexCoord3f( offset.x, 0., 0.); glVertex2f(0.,0.);270 glTexCoord3f( offset.x, 1., 0.); glVertex2f(size, 0.);271 glTexCoord3f( offset.x, 1., 1.); glVertex2f(size,size);272 glTexCoord3f( offset.x, 0., 1.); glVertex2f(0.,size);273 274 275 276 glTexCoord3f(0., offset.y, 0.); glVertex2f(0.,0.);277 glTexCoord3f(1., offset.y, 0.); glVertex2f(size, 0.);278 glTexCoord3f(1., offset.y, 1.); glVertex2f(size,size);279 glTexCoord3f(0., offset.y, 1.); glVertex2f(0.,size);280 281 282 glTexCoord3f(0., 0., offset.z); glVertex2f(0.,0.);283 glTexCoord3f(1., 0., offset.z); glVertex2f(size, 0.);284 glTexCoord3f(1., 1., offset.z); glVertex2f(size,size);285 glTexCoord3f(0., 1., offset.z); glVertex2f(0.,size);286 break; 287 264 switch (_axis) { 265 case 0 : 266 // TBD.. 267 glTexCoord3f(_offset.x, 0., 0.); glVertex2f(0., 0.); 268 glTexCoord3f(_offset.x, 1., 0.); glVertex2f(_size, 0.); 269 glTexCoord3f(_offset.x, 1., 1.); glVertex2f(_size, _size); 270 glTexCoord3f(_offset.x, 0., 1.); glVertex2f(0., _size); 271 break; 272 case 1 : 273 // TBD.. 274 glTexCoord3f(0., _offset.y, 0.); glVertex2f(0., 0.); 275 glTexCoord3f(1., _offset.y, 0.); glVertex2f(_size, 0.); 276 glTexCoord3f(1., _offset.y, 1.); glVertex2f(_size, _size); 277 glTexCoord3f(0., _offset.y, 1.); glVertex2f(0., _size); 278 break; 279 case 2 : 280 glTexCoord3f(0., 0., _offset.z); glVertex2f(0., 0.); 281 glTexCoord3f(1., 0., _offset.z); glVertex2f(_size, 0.); 282 glTexCoord3f(1., 1., _offset.z); glVertex2f(_size, _size); 283 glTexCoord3f(0., 1., _offset.z); glVertex2f(0., _size); 284 break; 285 } 288 286 } 289 287 glEnd(); 290 288 291 cgGLDisableProfile(CG_PROFILE_FP40);292 293 cgGLDisableTextureParameter(_vel _tex_param_render_vel);289 _renderVelShader->unbind(); 290 291 cgGLDisableTextureParameter(_velTexParamRenderVel); 294 292 295 293 glBindTexture(GL_TEXTURE_3D, 0); … … 297 295 298 296 //read the vectors 299 glReadPixels(0, 0, size, size, GL_RGBA, GL_FLOAT, slice_vector); 300 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 301 302 int lim = size * size * 4; 303 float* v= slice_vector; 297 glReadPixels(0, 0, _size, _size, GL_RGBA, GL_FLOAT, _sliceVector); 298 299 int lim = _size * _size * 4; 300 float *v = _sliceVector; 304 301 for (int i = 0; i < lim; ++i) { 305 302 if (isnan(*v)) { … … 308 305 ++v; 309 306 } 307 308 glMatrixMode(GL_PROJECTION); 309 glPopMatrix(); 310 glMatrixMode(GL_MODELVIEW); 311 glPopMatrix(); 312 313 glPopAttrib(); 314 315 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboOrig); 310 316 } 311 317 … … 315 321 { 316 322 if (_vectorFieldId == 0) { 317 323 return; 318 324 } 319 325 … … 321 327 float x1, x2, y, px, py; 322 328 329 int fboOrig; 330 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &fboOrig); 331 332 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fbo); 333 334 glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 335 336 glMatrixMode(GL_PROJECTION); 323 337 glPushMatrix(); 324 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 325 326 glMatrixMode(GL_PROJECTION); 327 glLoadIdentity(); 328 glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT); 329 330 /*glPushMatrix();*/ 338 glLoadIdentity(); 339 331 340 glViewport(0, 0, (GLsizei) NPIX, (GLsizei) NPIX); 332 341 //glTranslatef(-1.0, -1.0, 0.0); … … 335 344 336 345 glMatrixMode(GL_MODELVIEW); 337 glLoadIdentity(); 338 339 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 340 341 //sa = 0.010*cos(iframe*2.0*M_PI/200.0); 346 glPushMatrix(); 347 glLoadIdentity(); 348 349 glClear(GL_COLOR_BUFFER_BIT); 350 //glDepthMask(GL_FALSE); 351 glDisable(GL_DEPTH_TEST); 352 glDisable(GL_LIGHTING); 353 glDisable(GL_ALPHA_TEST); 354 355 //_sa = 0.010*cos(_iframe*2.0*M_PI/200.0); 342 356 glEnable(GL_TEXTURE_2D); 343 glBindTexture(GL_TEXTURE_2D, pattern_tex);344 sa = 0.01;357 glBindTexture(GL_TEXTURE_2D, _patternTex); 358 _sa = 0.01; 345 359 360 glColor4f(1, 1, 1, 1); 346 361 for (i = 0; i < NMESH-1; i++) { 347 362 x1 = DM*i; x2 = x1 + DM; … … 350 365 y = DM*j; 351 366 glTexCoord2f(x1, y); 352 get _velocity(x1, y, &px, &py);367 getVelocity(x1, y, &px, &py); 353 368 glVertex2f(px, py); 354 369 355 370 glTexCoord2f(x2, y); 356 get _velocity(x2, y, &px, &py);371 getVelocity(x2, y, &px, &py); 357 372 glVertex2f(px, py); 358 373 } 359 374 glEnd(); 360 375 } 361 iframe =iframe + 1;376 _iframe = _iframe + 1; 362 377 363 378 glEnable(GL_BLEND); … … 366 381 367 382 glEnable(GL_TEXTURE_2D); 368 glCallList( iframe % Npat +disListID);383 glCallList(_iframe % _Npat + _disListID); 369 384 glBegin(GL_QUAD_STRIP); 370 385 { 371 glTexCoord2f(0.0, 0.0);glVertex2f(0.0, 0.0);372 glTexCoord2f(0.0, tmax); glVertex2f(0.0, 1.0);373 glTexCoord2f( tmax, 0.0);glVertex2f(1.0, 0.0);374 glTexCoord2f( tmax,tmax); glVertex2f(1.0, 1.0);386 glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0); 387 glTexCoord2f(0.0, _tmax); glVertex2f(0.0, 1.0); 388 glTexCoord2f(_tmax, 0.0); glVertex2f(1.0, 0.0); 389 glTexCoord2f(_tmax, _tmax); glVertex2f(1.0, 1.0); 375 390 glEnd(); 376 391 } … … 389 404 */ 390 405 391 glDisable(GL_ALPHA_TEST);392 393 406 glDisable(GL_BLEND); 394 407 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, NPIX, NPIX, 0); … … 396 409 /* 397 410 //blend magnitude texture 398 glBindTexture(GL_TEXTURE_2D, mag_tex);411 glBindTexture(GL_TEXTURE_2D, _magTex); 399 412 glEnable(GL_TEXTURE_2D); 400 413 glEnable(GL_BLEND); … … 407 420 */ 408 421 409 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 422 glMatrixMode(GL_PROJECTION); 423 glPopMatrix(); 424 glMatrixMode(GL_MODELVIEW); 425 glPopMatrix(); 426 410 427 glPopAttrib(); 428 429 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboOrig); 430 } 431 432 void 433 NvLIC::render() 434 { 435 if (_vectorFieldId == 0) { 436 return; 437 } 438 439 //draw line integral convolution quad 440 441 glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT); 442 glBindTexture(GL_TEXTURE_2D, _colorTex); 443 glEnable(GL_TEXTURE_2D); 444 //glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); 445 //glEnable(GL_LIGHTING); 446 glDisable(GL_LIGHTING); 447 glEnable(GL_DEPTH_TEST); 448 449 glMatrixMode(GL_MODELVIEW); 450 glPushMatrix(); 451 452 float w = 1.0f / _scale.x; 453 glTranslatef(_origin.x, _origin.y, _origin.z); 454 glScalef(1.0f, 1.0f / _scale.y / w, 1.0f / _scale.z / w); 455 456 glColor4f(1, 1, 1, 1); 457 glBegin(GL_QUADS); 458 switch (_axis) { 459 case 0: 460 glNormal3f(1, 0, 0); 461 glTexCoord2f(0, 0); glVertex3f(_offset.x, 0, 0); 462 glTexCoord2f(1, 0); glVertex3f(_offset.x, 1, 0); 463 glTexCoord2f(1, 1); glVertex3f(_offset.x, 1, 1); 464 glTexCoord2f(0, 1); glVertex3f(_offset.x, 0, 1); 465 break; 466 case 1: 467 glNormal3f(0, 1, 0); 468 glTexCoord2f(0, 0); glVertex3f(0, _offset.y, 0); 469 glTexCoord2f(1, 0); glVertex3f(1, _offset.y, 0); 470 glTexCoord2f(1, 1); glVertex3f(1, _offset.y, 1); 471 glTexCoord2f(0, 1); glVertex3f(0, _offset.y, 1); 472 break; 473 case 2: 474 glNormal3f(0, 0, 1); 475 glTexCoord2f(0, 0); glVertex3f(0, 0, _offset.z); 476 glTexCoord2f(1, 0); glVertex3f(1, 0, _offset.z); 477 glTexCoord2f(1, 1); glVertex3f(1, 1, _offset.z); 478 glTexCoord2f(0, 1); glVertex3f(0, 1, _offset.z); 479 break; 480 } 481 glEnd(); 482 411 483 glPopMatrix(); 412 glMatrixMode(GL_PROJECTION); 413 /*glPopMatrix();*/ 414 glMatrixMode(GL_MODELVIEW); 415 } 416 417 void NvLIC::render() 418 { 419 display(); 420 } 421 422 void 423 NvLIC::display() 424 { 425 if (_vectorFieldId == 0) { 426 return; 427 } 428 429 glBindTexture(GL_TEXTURE_2D, color_tex); 430 glEnable(GL_TEXTURE_2D); 431 432 //draw line integral convolution quad 433 glEnable(GL_DEPTH_TEST); 434 435 glPushMatrix(); 436 437 float w = 1.0f / scale.x; 438 glTranslatef(origin.x, origin.y, origin.z); 439 glScalef(1.0f, 1.0f / scale.y / w, 1.0f / scale.z / w); 440 441 glBegin(GL_QUADS); 442 switch (axis) { 443 case 0: 444 glTexCoord2f(0, 0); glVertex3f(offset.x, 0, 0); 445 glTexCoord2f(1, 0); glVertex3f(offset.x, 1, 0); 446 glTexCoord2f(1, 1); glVertex3f(offset.x, 1, 1); 447 glTexCoord2f(0, 1); glVertex3f(offset.x, 0, 1); 448 break; 449 case 1: 450 glTexCoord2f(0, 0); glVertex3f(0, offset.y, 0); 451 glTexCoord2f(1, 0); glVertex3f(1, offset.y, 0); 452 glTexCoord2f(1, 1); glVertex3f(1, offset.y, 1); 453 glTexCoord2f(0, 1); glVertex3f(0, offset.y, 1); 454 break; 455 case 2: 456 glTexCoord2f(0, 0); glVertex3f(0, 0, offset.z); 457 glTexCoord2f(1, 0); glVertex3f(1, 0, offset.z); 458 glTexCoord2f(1, 1); glVertex3f(1, 1, offset.z); 459 glTexCoord2f(0, 1); glVertex3f(0, 1, offset.z); 460 break; 461 } 462 glEnd(); 463 464 glPopMatrix(); 465 466 glBindTexture(GL_TEXTURE_2D,0); 467 468 glDisable(GL_DEPTH_TEST); 469 glDisable(GL_TEXTURE_2D); 470 } 471 472 void 473 NvLIC::setVectorField(unsigned int texID, const Vector3& ori, 474 float scaleX, float scaleY, float scaleZ, float max) 484 485 glBindTexture(GL_TEXTURE_2D, 0); 486 487 glPopAttrib(); 488 } 489 490 void 491 NvLIC::setVectorField(unsigned int texID, const Vector3& origin, 492 float scaleX, float scaleY, float scaleZ, float max) 475 493 { 476 494 TRACE("NvLIC: vector field is assigned [%d]\n", texID); 477 495 _vectorFieldId = texID; 478 origin = ori;479 scale = Vector3(scaleX, scaleY, scaleZ);480 this->max = max;481 482 make _patterns();483 484 get _slice();485 } 486 487 void 488 NvLIC::get _velocity(float x, float y, float *px, float *py)496 _origin = origin; 497 _scale = Vector3(scaleX, scaleY, scaleZ); 498 _max = max; 499 500 makePatterns(); 501 502 getSlice(); 503 } 504 505 void 506 NvLIC::getVelocity(float x, float y, float *px, float *py) 489 507 { 490 508 float vx, vy, r; 491 509 492 int xi = (int)(x* size);493 int yi = (int)(y* size);510 int xi = (int)(x*_size); 511 int yi = (int)(y*_size); 494 512 495 513 //TRACE("(xi yi) = (%d %d), ", xi, yi); 496 vx = slice_vector[4 * (xi+yi*size)];497 vy = slice_vector[4 * (xi+yi*size)+1];514 vx = _sliceVector[4 * (xi+yi*_size)]; 515 vy = _sliceVector[4 * (xi+yi*_size)+1]; 498 516 r = vx*vx + vy*vy; 499 517 500 518 //TRACE("(vx vx) = (%f %f), r=%f, ", vx, vy, r); 501 if (r > ( dmax*dmax)) {519 if (r > (_dmax * _dmax)) { 502 520 r = sqrt(r); 503 vx *= dmax/r;504 vy *= dmax/r;521 vx *= _dmax/r; 522 vy *= _dmax/r; 505 523 } 506 524 … … 512 530 513 531 void 514 NvLIC::set _offset(float v)515 { 516 switch ( axis) {517 case 0 : offset.x = v; break;518 case 1 : offset.y = v; break;519 case 2 : offset.z = v; break;520 } 521 get _slice();522 } 523 524 void NvLIC::set _axis(int axis)525 { 526 this->axis = axis;532 NvLIC::setOffset(float v) 533 { 534 switch (_axis) { 535 case 0 : _offset.x = v; break; 536 case 1 : _offset.y = v; break; 537 case 2 : _offset.z = v; break; 538 } 539 getSlice(); 540 } 541 542 void NvLIC::setAxis(int axis) 543 { 544 _axis = axis; 527 545 } 528 546 529 547 void NvLIC::reset() 530 548 { 531 make _patterns();532 } 549 makePatterns(); 550 } -
trunk/packages/vizservers/nanovis/NvLIC.h
r2870 r2920 18 18 19 19 #include <GL/glew.h> 20 #include <Cg/cg GL.h>20 #include <Cg/cg.h> 21 21 22 22 #include "config.h" … … 26 26 #include "Vector3.h" 27 27 #include "Volume.h" 28 #include "NvShader.h" 28 29 29 30 class NvLIC : public Renderable 30 31 { 31 32 public: 32 NvLIC(int _size, int _width, int _height, int axis,33 const Vector3& _offset, CGcontext _context);33 NvLIC(int size, int width, int height, int axis, 34 const Vector3& offset); 34 35 ~NvLIC(); 35 36 … … 38 39 39 40 /// Display the convolution result 40 void display();41 42 41 void render(); 43 42 44 void make _patterns();43 void makePatterns(); 45 44 46 void make _magnitudes();45 void makeMagnitudes(); 47 46 48 void get _velocity(float x, float y, float *px, float *py);47 void getVelocity(float x, float y, float *px, float *py); 49 48 50 void get _slice();49 void getSlice(); 51 50 52 void set _offset(float v);51 void setOffset(float v); 53 52 54 53 /** 55 * @brief Specify the per dicular axis54 * @brief Specify the perpendicular axis 56 55 * 57 56 * 0 : x axis<br> … … 59 58 * 2 : z axis<br> 60 59 */ 61 void set _axis(int axis);60 void setAxis(int axis); 62 61 63 void setVectorField(unsigned int texID, const Vector3& ori ,62 void setVectorField(unsigned int texID, const Vector3& origin, 64 63 float scaleX, float scaleY, float scaleZ, float max); 65 64 … … 91 90 * the inherited Vector3 location is its center 92 91 */ 93 Vector3 normal;92 Vector3 _normal; 94 93 95 GLuint disListID; 96 97 int width, height; 98 int size; // The lic is a square of size, it can 94 int _width, _height; 95 int _size; // The lic is a square of size, it can 99 96 // be stretched 100 float * slice_vector; // Storage for the per slice vectors97 float *_sliceVector; // Storage for the per slice vectors 101 98 // driving the follow. 102 Vector3 scale; // Scaling factor stretching the lic99 Vector3 _scale; // Scaling factor stretching the lic 103 100 // plane to fit the actual dimensions 104 Vector3 origin;105 Vector3 offset; // [0,1] offset could be x, y, or z101 Vector3 _origin; 102 Vector3 _offset; // [0,1] offset could be x, y, or z 106 103 // direction 107 int axis;104 int _axis; 108 105 109 106 //some convolve variables. They can pretty much stay fixed 110 int iframe;111 int Npat;112 int alpha;113 float sa;114 float tmax;115 float dmax;116 float max;107 int _iframe; 108 int _Npat; 109 int _alpha; 110 float _sa; 111 float _tmax; 112 float _dmax; 113 float _max; 117 114 115 GLuint _disListID; 116 117 NvShader *_renderVelShader; 118 118 //CG shader parameters 119 CGcontext _cgContext; 120 CGparameter _vel_tex_param; 121 CGparameter _vel_tex_param_render_vel; 122 CGparameter _plane_normal_param_render_vel; 123 CGprogram _render_vel_fprog; 124 CGparameter _max_param; 119 CGparameter _velTexParam; 120 CGparameter _velTexParamRenderVel; 121 CGparameter _planeNormalParamRenderVel; 122 CGparameter _maxParam; 125 123 126 GLuint color_tex, pattern_tex, mag_tex;127 GLuint fbo, vel_fbo, slice_vector_tex; // For projecting 3d vector to 2d124 GLuint _colorTex, _patternTex, _magTex; 125 GLuint _fbo, _velFbo, _sliceVectorTex; // For projecting 3d vector to 2d 128 126 // vector on a plane. 129 127 GLuint _vectorFieldId; -
trunk/packages/vizservers/nanovis/nanovis.cpp
r2885 r2920 712 712 { 713 713 flowVisRenderer->initialize(); 714 licRenderer->make _patterns();714 licRenderer->makePatterns(); 715 715 } 716 716 … … 795 795 796 796 licRenderer = new NvLIC(NMESH, NPIX, NPIX, _licAxis, 797 Vector3(_licSliceX, _licSliceY, _licSliceZ), 798 NvShader::getCgContext()); 797 Vector3(_licSliceX, _licSliceY, _licSliceZ)); 799 798 800 799 grid = new Grid();
Note: See TracChangeset
for help on using the changeset viewer.