Changeset 1258 for trunk/packages
- Timestamp:
- Dec 10, 2008, 12:48:52 PM (16 years ago)
- Location:
- trunk/packages/vizservers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/VolumeRenderer.cpp
r1177 r1258 109 109 } 110 110 111 struct SortElement {112 float z;113 int volume_id;114 int slice_id;115 SortElement(float _z, int _v, int _s):116 111 struct SortElement { 112 float z; 113 int volume_id; 114 int slice_id; 115 SortElement(float _z, int _v, int _s): 116 z(_z), volume_id(_v), slice_id(_s){} 117 117 }; 118 118 … … 154 154 } 155 155 156 void VolumeRenderer::render_all() 156 void 157 VolumeRenderer::render_all() 157 158 { 158 159 Volume* cur_vol = 0; … … 163 164 int num_volumes = n_volumes; 164 165 165 if (_volumeInterpolator->is_started()) 166 { 167 ++ num_volumes; 166 if (_volumeInterpolator->is_started()) { 167 ++num_volumes; 168 168 ani_tf = tf[_volumeInterpolator->getReferenceVolumeID()]; 169 169 ani_vol = _volumeInterpolator->getVolume(); 170 170 } 171 171 172 ConvexPolygon*** polys = new ConvexPolygon**[num_volumes];//two dimension pointer array173 int* actual_slices = new int[num_volumes]; //number of actual slices for each volume174 175 for(int vol_index = 0; vol_index< num_volumes; vol_index++)176 { 177 if (vol_index != n_volumes)178 {172 //two dimension pointer array 173 ConvexPolygon*** polys = new ConvexPolygon**[num_volumes]; 174 //number of actual slices for each volume 175 int* actual_slices = new int[num_volumes]; 176 177 for(int vol_index = 0; vol_index< num_volumes; vol_index++) { 178 if (vol_index != n_volumes) { 179 179 cur_vol = volume[vol_index]; 180 180 cur_tf = tf[vol_index]; 181 } 182 else 183 { 181 } else { 184 182 cur_vol = ani_vol; 185 183 cur_tf = ani_tf; … … 193 191 194 192 int n_slices = cur_vol->get_n_slice(); 195 if (cur_vol->get_isosurface()) 196 { 197 // double the number of slices 193 if (cur_vol->get_isosurface()) { 194 // double the number of slices 198 195 n_slices <<= 1; 199 200 196 } 197 201 198 //volume start location 202 199 Vector3* location = cur_vol->get_location(); 203 200 Vector4 shift_4d(location->x, location->y, location->z, 0); 204 201 205 202 double x0 = 0; 206 203 double y0 = 0; 207 204 double z0 = 0; 208 205 209 206 Mat4x4 model_view_no_trans, model_view_trans; 210 207 Mat4x4 model_view_no_trans_inverse, model_view_trans_inverse; 211 208 212 209 double zNear, zFar; 213 214 210 211 //initialize volume plane with world coordinates 215 212 Plane volume_planes[6]; 216 volume_planes[0].set_coeffs( 1, 0,0, -x0);217 volume_planes[1].set_coeffs(-1, 0, 0,x0+1);218 volume_planes[2].set_coeffs( 0, 1,0, -y0);219 volume_planes[3].set_coeffs( 0, -1, 0,y0+1);220 volume_planes[4].set_coeffs( 0, 0,1, -z0);221 volume_planes[5].set_coeffs( 0, 0, -1,z0+1);222 223 213 volume_planes[0].set_coeffs( 1, 0, 0, -x0); 214 volume_planes[1].set_coeffs(-1, 0, 0, x0+1); 215 volume_planes[2].set_coeffs( 0, 1, 0, -y0); 216 volume_planes[3].set_coeffs( 0, -1, 0, y0+1); 217 volume_planes[4].set_coeffs( 0, 0, 1, -z0); 218 volume_planes[5].set_coeffs( 0, 0, -1, z0+1); 219 220 //get modelview matrix with no translation 224 221 glPushMatrix(); 225 222 glScalef(cur_vol->aspect_ratio_width, 226 227 228 223 cur_vol->aspect_ratio_height, 224 cur_vol->aspect_ratio_depth); 225 229 226 glEnable(GL_DEPTH_TEST); 230 227 231 228 GLfloat mv_no_trans[16]; 232 229 glGetFloatv(GL_MODELVIEW_MATRIX, mv_no_trans); 233 230 234 231 model_view_no_trans = Mat4x4(mv_no_trans); 235 232 model_view_no_trans_inverse = model_view_no_trans.inverse(); 236 233 237 234 glPopMatrix(); 238 239 235 236 //get modelview matrix with translation 240 237 glPushMatrix(); 241 238 glTranslatef(shift_4d.x, shift_4d.y, shift_4d.z); 242 239 glScalef(cur_vol->aspect_ratio_width, 243 244 240 cur_vol->aspect_ratio_height, 241 cur_vol->aspect_ratio_depth); 245 242 GLfloat mv_trans[16]; 246 243 glGetFloatv(GL_MODELVIEW_MATRIX, mv_trans); 247 244 248 245 model_view_trans = Mat4x4(mv_trans); 249 246 model_view_trans_inverse = model_view_trans.inverse(); 250 247 251 248 //draw volume bounding box with translation (the correct location in 252 249 //space) … … 255 252 cur_vol->get_outline_color(olcolor); 256 253 draw_bounding_box(x0, y0, z0, x0+1, y0+1, z0+1, 257 258 254 (double)olcolor[0], (double)olcolor[1], (double)olcolor[2], 255 1.5); 259 256 } 260 257 glPopMatrix(); 261 258 262 259 //draw labels 263 260 glPushMatrix(); 264 261 glTranslatef(shift_4d.x, shift_4d.y, shift_4d.z); 265 262 if(cur_vol->outline_is_enabled()) { 266 263 //draw_label(i); 267 264 } 268 265 glPopMatrix(); 269 270 266 267 //transform volume_planes to eye coordinates. 271 268 for(int i=0; i<6; i++) 272 269 volume_planes[i].transform(model_view_no_trans); 273 270 274 271 get_near_far_z(mv_no_trans, zNear, zFar); 275 276 272 273 //compute actual rendering slices 277 274 float z_step = fabs(zNear-zFar)/n_slices; 278 275 int n_actual_slices; 279 276 280 277 if (cur_vol->data_is_enabled()) { 281 278 n_actual_slices = (int)(fabs(zNear-zFar)/z_step + 1); … … 286 283 } 287 284 actual_slices[vol_index] = n_actual_slices; 288 285 289 286 Vector4 vert1 = (Vector4(-10, -10, -0.5, 1)); 290 287 Vector4 vert2 = (Vector4(-10, +10, -0.5, 1)); 291 288 Vector4 vert3 = (Vector4(+10, +10, -0.5, 1)); 292 289 Vector4 vert4 = (Vector4(+10, -10, -0.5, 1)); 293 294 295 //Render cutplanes first with depth test enabled. 296 //They will mark the image with their depth values. Then we render other volume slices. 297 //These volume slices will be occluded correctly by the cutplanes and vice versa. 298 299 ConvexPolygon static_poly; 300 for(int i=0; i<cur_vol->get_cutplane_count(); i++) 301 { 302 if(!cur_vol->cutplane_is_enabled(i)) 303 continue; 304 305 float offset = cur_vol->get_cutplane(i)->offset; 306 int axis = cur_vol->get_cutplane(i)->orient; 307 308 if(axis==3){ 309 vert1 = Vector4(-10, -10, offset, 1); 310 vert2 = Vector4(-10, +10, offset, 1); 311 vert3 = Vector4(+10, +10, offset, 1); 312 vert4 = Vector4(+10, -10, offset, 1); 313 //continue; 314 } 315 else if(axis==1){ 316 vert1 = Vector4(offset, -10, -10, 1); 317 vert2 = Vector4(offset, +10, -10, 1); 318 vert3 = Vector4(offset, +10, +10, 1); 319 vert4 = Vector4(offset, -10, +10, 1); 320 //continue; 321 } 322 else if(axis==2){ 323 vert1 = Vector4(-10, offset, -10, 1); 324 vert2 = Vector4(+10, offset, -10, 1); 325 vert3 = Vector4(+10, offset, +10, 1); 326 vert4 = Vector4(-10, offset, +10, 1); 327 //continue; 328 } 329 330 vert1 = model_view_no_trans.transform(vert1); 331 vert2 = model_view_no_trans.transform(vert2); 332 vert3 = model_view_no_trans.transform(vert3); 333 vert4 = model_view_no_trans.transform(vert4); 334 335 ConvexPolygon* p = &static_poly; 336 p->vertices.clear(); 337 338 p->append_vertex(vert1); 339 p->append_vertex(vert2); 340 p->append_vertex(vert3); 341 p->append_vertex(vert4); 342 343 for(int k=0; k<6; k++){ 344 p->clip(volume_planes[k], true); 345 } 346 347 p->transform(model_view_no_trans_inverse); 348 p->transform(model_view_trans); 349 350 glPushMatrix(); 351 glScalef(cur_vol->aspect_ratio_width, cur_vol->aspect_ratio_height, cur_vol->aspect_ratio_depth); 352 353 activate_volume_shader(cur_vol, cur_tf, true); 354 glPopMatrix(); 355 356 glEnable(GL_DEPTH_TEST); 357 glDisable(GL_BLEND); 358 359 glBegin(GL_POLYGON); 360 p->Emit(true); 361 glEnd(); 362 glDisable(GL_DEPTH_TEST); 363 364 deactivate_volume_shader(); 365 } //done cutplanes 366 367 368 //Now do volume rendering 369 290 291 292 // Render cutplanes first with depth test enabled. They will mark the 293 // image with their depth values. Then we render other volume slices. 294 // These volume slices will be occluded correctly by the cutplanes and 295 // vice versa. 296 297 ConvexPolygon static_poly; 298 for(int i=0; i<cur_vol->get_cutplane_count(); i++) { 299 if(!cur_vol->cutplane_is_enabled(i)) 300 continue; 301 302 float offset = cur_vol->get_cutplane(i)->offset; 303 int axis = cur_vol->get_cutplane(i)->orient; 304 305 if(axis==3){ 306 vert1 = Vector4(-10, -10, offset, 1); 307 vert2 = Vector4(-10, +10, offset, 1); 308 vert3 = Vector4(+10, +10, offset, 1); 309 vert4 = Vector4(+10, -10, offset, 1); 310 //continue; 311 } else if(axis==1){ 312 vert1 = Vector4(offset, -10, -10, 1); 313 vert2 = Vector4(offset, +10, -10, 1); 314 vert3 = Vector4(offset, +10, +10, 1); 315 vert4 = Vector4(offset, -10, +10, 1); 316 //continue; 317 } else if(axis==2){ 318 vert1 = Vector4(-10, offset, -10, 1); 319 vert2 = Vector4(+10, offset, -10, 1); 320 vert3 = Vector4(+10, offset, +10, 1); 321 vert4 = Vector4(-10, offset, +10, 1); 322 //continue; 323 } 324 325 vert1 = model_view_no_trans.transform(vert1); 326 vert2 = model_view_no_trans.transform(vert2); 327 vert3 = model_view_no_trans.transform(vert3); 328 vert4 = model_view_no_trans.transform(vert4); 329 330 ConvexPolygon* p = &static_poly; 331 p->vertices.clear(); 332 333 p->append_vertex(vert1); 334 p->append_vertex(vert2); 335 p->append_vertex(vert3); 336 p->append_vertex(vert4); 337 338 for(int k=0; k<6; k++){ 339 p->clip(volume_planes[k], true); 340 } 341 342 p->transform(model_view_no_trans_inverse); 343 p->transform(model_view_trans); 344 345 glPushMatrix(); 346 glScalef(cur_vol->aspect_ratio_width, cur_vol->aspect_ratio_height, 347 cur_vol->aspect_ratio_depth); 348 349 activate_volume_shader(cur_vol, cur_tf, true); 350 glPopMatrix(); 351 352 glEnable(GL_DEPTH_TEST); 353 glDisable(GL_BLEND); 354 355 glBegin(GL_POLYGON); 356 p->Emit(true); 357 glEnd(); 358 glDisable(GL_DEPTH_TEST); 359 360 deactivate_volume_shader(); 361 } //done cutplanes 362 363 364 //Now do volume rendering 365 370 366 vert1 = (Vector4(-10, -10, -0.5, 1)); 371 367 vert2 = (Vector4(-10, +10, -0.5, 1)); 372 368 vert3 = (Vector4(+10, +10, -0.5, 1)); 373 369 vert4 = (Vector4(+10, -10, -0.5, 1)); 374 370 375 371 int counter = 0; 376 377 372 373 //transform slices and store them 378 374 float slice_z; 379 for (int i=0; i<n_actual_slices; i++) 380 { 381 slice_z = zFar + i * z_step; //back to front 382 375 for (int i=0; i<n_actual_slices; i++) { 376 slice_z = zFar + i * z_step; //back to front 377 383 378 ConvexPolygon *poly = new ConvexPolygon(); 384 379 polys[vol_index][counter] = poly; 385 380 counter++; 386 381 387 382 poly->vertices.clear(); 388 383 poly->set_id(vol_index); 389 384 390 385 //Setting Z-coordinate 391 386 vert1.z = slice_z; … … 393 388 vert3.z = slice_z; 394 389 vert4.z = slice_z; 395 390 396 391 poly->append_vertex(vert1); 397 392 poly->append_vertex(vert2); 398 393 poly->append_vertex(vert3); 399 394 poly->append_vertex(vert4); 400 401 for(int k=0; k<6; k++) 402 { 403 poly->clip(volume_planes[k], true); 404 } 405 395 396 for(int k=0; k<6; k++) { 397 poly->clip(volume_planes[k], true); 398 } 399 406 400 poly->transform(model_view_no_trans_inverse); 407 401 poly->transform(model_view_trans); 408 402 409 403 if(poly->vertices.size()>=3) 410 404 total_rendered_slices++; 411 405 } 412 413 } //iterate all volumes414 //fprintf(stderr, "total slices: %d\n", total_rendered_slices);415 416 //We sort all the polygons according to their eye-space depth, from farthest to the closest.417 //This step is critical for correct blending418 419 SortElement* slices = (SortElement*) 420 406 407 } //iterate all volumes 408 //fprintf(stderr, "total slices: %d\n", total_rendered_slices); 409 410 //We sort all the polygons according to their eye-space depth, from farthest to the closest. 411 //This step is critical for correct blending 412 413 SortElement* slices = (SortElement*)malloc(sizeof(SortElement)*total_rendered_slices); 414 421 415 int counter = 0; 422 416 for(int i=0; i<num_volumes; i++){ … … 428 422 } 429 423 } 430 431 //sort them424 425 //sort them 432 426 qsort(slices, total_rendered_slices, sizeof(SortElement), slice_sort); 433 434 //Now we are ready to render all the slices from back to front427 428 //Now we are ready to render all the slices from back to front 435 429 glEnable(GL_DEPTH_TEST); 436 430 glEnable(GL_BLEND); 437 431 438 432 for(int i=0; i<total_rendered_slices; i++){ 439 433 int volume_index = slices[i].volume_id; 440 434 int slice_index = slices[i].slice_id; 441 435 ConvexPolygon* cur = polys[volume_index][slice_index]; 442 443 if (volume_index == n_volumes) 444 { 445 cur_vol = ani_vol; 446 cur_tf = ani_tf; 447 } 448 else 449 { 436 437 if (volume_index == n_volumes) { 438 cur_vol = ani_vol; 439 cur_tf = ani_tf; 440 } else { 450 441 cur_vol = volume[volume_index]; 451 442 cur_tf = tf[volume_index]; 452 443 } 453 454 444 445 455 446 glPushMatrix(); 456 447 glScalef(cur_vol->aspect_ratio_width, cur_vol->aspect_ratio_height, cur_vol->aspect_ratio_depth); 457 448 458 449 activate_volume_shader(cur_vol, cur_tf, false); 459 450 glPopMatrix(); 460 451 461 452 glBegin(GL_POLYGON); 462 453 cur->Emit(true); … … 465 456 deactivate_volume_shader(); 466 457 } 467 468 458 459 469 460 glDisable(GL_DEPTH_TEST); 470 461 glDisable(GL_BLEND); 471 462 472 463 //Deallocate all the memory used 473 464 for(int i=0; i<num_volumes; i++){ … … 475 466 delete polys[i][j]; 476 467 } 477 478 if (polys[i]) 479 { 468 469 if (polys[i]) { 480 470 delete[] polys[i]; 481 471 } 482 472 } 483 473 484 474 delete[] polys; 485 475 delete[] actual_slices; -
trunk/packages/vizservers/nanovis/nanovis.cpp
r1249 r1258 461 461 462 462 /* Load a 3D volume 463 * index: the index into the volume array, which stores pointers to 3D volume instances 464 * data: pointer to an array of floats. 465 * n_component: the number of scalars for each space point. 466 * All component scalars for a point are placed consequtively in data array 467 * width, height and depth: number of points in each dimension 463 * index: the index into the volume array, which stores pointers 464 * to 3D volume instances 465 * data: pointer to an array of floats. 466 * n_component: the number of scalars for each space point. All component 467 * scalars for a point are placed consequtively in data array 468 * width, height and depth: number of points in each dimension 468 469 */ 469 470 Volume * -
trunk/packages/vizservers/pymolproxy/pymolproxy.c
r1219 r1258 68 68 69 69 static FILE *flog; 70 static int debug = TRUE;70 static int debug = 0; 71 71 72 72 typedef struct {
Note: See TracChangeset
for help on using the changeset viewer.