Changeset 416 for trunk/gui/vizservers/nanovis/VolumeRenderer.cpp
- Timestamp:
- Apr 27, 2006, 12:52:42 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/vizservers/nanovis/VolumeRenderer.cpp
r415 r416 62 62 tf.push_back(_tf); 63 63 slice.push_back(_slice); 64 render_bit.push_back(true);65 64 66 65 n_volumes++; … … 89 88 int total_rendered_slices = 0; 90 89 90 //compute total enabled volumes 91 91 for(int i=0; i<n_volumes; i++){ 92 if( render_bit[i])92 if(volume[i]->is_enabled()) 93 93 total_enabled_volumes ++; 94 94 } 95 95 fprintf(stderr, "total volumes rendered: %d\n", total_enabled_volumes); 96 96 97 ConvexPolygon*** polys = new ConvexPolygon**[total_enabled_volumes]; 98 int* actual_slices = new int[total_enabled_volumes]; 99 100 int cur_index = -1; 97 ConvexPolygon*** polys = new ConvexPolygon**[total_enabled_volumes]; //two dimension pointer array 98 //storing the slices 99 int* actual_slices = new int[total_enabled_volumes]; //number of actual slices for each volume 100 101 int cur_vol = -1; 101 102 for(int i=0; i<n_volumes; i++){ 102 if(!render_bit[i]) 103 continue; 104 cur_index++; 103 if(!volume[i]->is_enabled()) 104 continue; //skip this volume 105 106 cur_vol++; 105 107 106 108 int volume_index = i; … … 108 110 109 111 //volume start location 110 Vector4 shift_4d(volume[volume_index]->location.x, volume[volume_index]->location.y, volume[volume_index]->location.z, 0); 112 Vector3* location = volume[volume_index]->get_location(); 113 Vector4 shift_4d(location->x, location->y, location->z, 0); 111 114 112 115 double x0 = 0; … … 128 131 volume_planes[5].set_coeffs(0, 0, -1, z0+1); 129 132 133 //get modelview matrix with no translation 130 134 glPushMatrix(); 131 132 135 glScalef(volume[volume_index]->aspect_ratio_width, 133 136 volume[volume_index]->aspect_ratio_height, … … 156 159 model_view_trans_inverse = model_view_trans.inverse(); 157 160 158 //draw volume bounding box 161 //draw volume bounding box with translation (the correct location in space) 159 162 draw_bounding_box(x0, y0, z0, x0+1, y0+1, z0+1, 0.8, 0.1, 0.1, 1.5); 160 163 glPopMatrix(); … … 163 166 for(int i=0; i<6; i++) 164 167 volume_planes[i].transform(model_view_no_trans); 165 166 168 get_near_far_z(mv_no_trans, zNear, zFar); 167 //fprintf(stderr, "zNear:%f, zFar:%f\n", zNear, zFar);168 //fflush(stderr);169 169 170 170 //compute actual rendering slices 171 171 float z_step = fabs(zNear-zFar)/n_slices; 172 172 int n_actual_slices = (int)(fabs(zNear-zFar)/z_step + 1); 173 actual_slices[cur_index] = n_actual_slices; 174 polys[cur_index] = new ConvexPolygon*[n_actual_slices]; 175 176 //fprintf(stderr, "slices: %d\n", n_actual_slices); 177 //fflush(stderr); 173 actual_slices[cur_vol] = n_actual_slices; 174 polys[cur_vol] = new ConvexPolygon*[n_actual_slices]; 178 175 179 176 float slice_z; … … 184 181 Vector4 vert4 = (Vector4(+10, -10, -0.5, 1)); 185 182 183 //Render cutplanes first with depth test enabled. 184 //They will mark the image with their depth values. Then we render other volume slices. 185 //These volume slices will be occluded correctly by the cutplanes and vice versa. 186 glEnable(GL_DEPTH_TEST); 187 glDisable(GL_BLEND); 188 189 for(int i=0; i<volume[volume_index]->get_cutplane_count(); i++){ 190 if(!volume[volume_index]->cutplane_is_enabled(i)) 191 continue; 192 193 float offset = volume[volume_index]->get_cutplane(i)->offset; 194 int axis = volume[volume_index]->get_cutplane(i)->orient; 195 196 if(axis==1){ 197 vert1 = Vector4(-10, -10, offset, 1); 198 vert2 = Vector4(-10, +10, offset, 1); 199 vert3 = Vector4(+10, +10, offset, 1); 200 vert4 = Vector4(+10, -10, offset, 1); 201 } 202 else if(axis==2){ 203 vert1 = Vector4(offset, -10, -10, 1); 204 vert2 = Vector4(offset, +10, -10, 1); 205 vert3 = Vector4(offset, +10, +10, 1); 206 vert4 = Vector4(offset, -10, +10, 1); 207 } 208 else if(axis==3){ 209 vert1 = Vector4(-10, offset, -10, 1); 210 vert2 = Vector4(+10, offset, -10, 1); 211 vert3 = Vector4(+10, offset, +10, 1); 212 vert4 = Vector4(-10, offset, +10, 1); 213 } 214 215 vert1 = model_view_no_trans.transform(vert1); 216 vert2 = model_view_no_trans.transform(vert2); 217 vert3 = model_view_no_trans.transform(vert3); 218 vert4 = model_view_no_trans.transform(vert4); 219 220 ConvexPolygon poly; 221 poly.vertices.clear(); 222 223 poly.append_vertex(vert1); 224 poly.append_vertex(vert2); 225 poly.append_vertex(vert3); 226 poly.append_vertex(vert4); 227 228 for(int k=0; k<6; k++){ 229 poly.clip(volume_planes[k], true); 230 } 231 232 //poly->transform(model_view_inverse); 233 //poly->translate(shift_4d); 234 //poly->transform(model_view); 235 poly.transform(model_view_no_trans_inverse); 236 poly.transform(model_view_trans); 237 238 glPushMatrix(); 239 glScalef(volume[volume_index]->aspect_ratio_width, volume[volume_index]->aspect_ratio_height, volume[volume_index]->aspect_ratio_depth); 240 241 activate_one_volume_shader(volume_index, 0, 1); 242 glPopMatrix(); 243 244 glBegin(GL_POLYGON); 245 poly.Emit(true); 246 glEnd(); 247 248 deactivate_one_volume_shader(); 249 } //done cutplanes 250 251 252 //Now do volume rendering 253 186 254 int counter = 0; 187 255 //transform slices and store them … … 190 258 191 259 ConvexPolygon *poly = new ConvexPolygon(); 192 polys[cur_ index][counter] = poly;260 polys[cur_vol][counter] = poly; 193 261 counter++; 194 262 … … 238 306 qsort(slices, total_rendered_slices, sizeof(SortElement), slice_sort); 239 307 308 /* 240 309 //debug 241 310 for(int i=0; i<total_rendered_slices; i++){ … … 243 312 } 244 313 fprintf(stderr, "\n\n"); 245 314 */ 246 315 247 316 //Now we are ready to render all the slices from back to front 248 249 317 glEnable(GL_DEPTH_TEST); 250 318 glEnable(GL_BLEND); … … 261 329 glPopMatrix(); 262 330 263 glEnable(GL_DEPTH_TEST);264 331 glBegin(GL_POLYGON); 265 332 cur->Emit(true); … … 365 432 glEnable(GL_BLEND); 366 433 367 #if 0368 434 if(slice_mode){ 369 435 glEnable(GL_DEPTH_TEST); 370 436 371 437 //render the cut planes 372 for(int i=0; i<volume[volume_index]-> plane.size(); i++){373 float offset = volume[volume_index]-> plane[i].offset;374 int axis = volume[volume_index]-> plane[i].orient;438 for(int i=0; i<volume[volume_index]->get_cutplane_count(); i++){ 439 float offset = volume[volume_index]->get_cutplane(i)->offset; 440 int axis = volume[volume_index]->get_cutplane(i)->orient; 375 441 376 442 if(axis==1){ … … 393 459 } 394 460 395 vert1 = model_view .transform(vert1);396 vert2 = model_view .transform(vert2);397 vert3 = model_view .transform(vert3);398 vert4 = model_view .transform(vert4);461 vert1 = model_view_no_trans.transform(vert1); 462 vert2 = model_view_no_trans.transform(vert2); 463 vert3 = model_view_no_trans.transform(vert3); 464 vert4 = model_view_no_trans.transform(vert4); 399 465 400 466 ConvexPolygon *poly; … … 411 477 } 412 478 413 poly->transform(model_view_inverse); 414 poly->translate(shift_4d); 415 poly->transform(model_view); 479 //poly->transform(model_view_inverse); 480 //poly->translate(shift_4d); 481 //poly->transform(model_view); 482 poly->transform(model_view_no_trans_inverse); 483 poly->transform(model_view_trans); 416 484 417 485 glPushMatrix(); 418 486 glScalef(volume[volume_index]->aspect_ratio_width, volume[volume_index]->aspect_ratio_height, volume[volume_index]->aspect_ratio_depth); 419 487 420 //activate_one_volume_shader(volume_index, 1, 1);488 activate_one_volume_shader(volume_index, 1, 1); 421 489 glPopMatrix(); 422 490 423 glDisable(GL_TEXTURE_3D); 424 glDisable(GL_TEXTURE_2D); 425 glDisable(GL_BLEND); 426 glColor3f(1,1,1); 427 428 //glBegin(GL_POLYGON); 429 glBegin(GL_LINE_LOOP); 430 //poly->Emit(true); 431 poly->Emit(false); 491 glBegin(GL_POLYGON); 492 poly->Emit(true); 432 493 glEnd(); 433 494 434 //deactivate_one_volume_shader();495 deactivate_one_volume_shader(); 435 496 } 436 497 } //slice_mode 437 498 438 #endif439 499 440 500 if(volume_mode){ … … 500 560 glDisable(GL_BLEND); 501 561 glDisable(GL_DEPTH_TEST); 502 //glPopMatrix();503 562 } 504 563
Note: See TracChangeset
for help on using the changeset viewer.