Ignore:
Timestamp:
Apr 27, 2006, 12:52:42 PM (18 years ago)
Author:
qiaow
Message:

More interface functions for manipulating cutplanes. Now multiple volumes with multiple cutplanes working!!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/vizservers/nanovis/VolumeRenderer.cpp

    r415 r416  
    6262  tf.push_back(_tf);
    6363  slice.push_back(_slice);
    64   render_bit.push_back(true);
    6564
    6665  n_volumes++;
     
    8988  int total_rendered_slices = 0;
    9089
     90  //compute total enabled volumes
    9191  for(int i=0; i<n_volumes; i++){
    92     if(render_bit[i])
     92    if(volume[i]->is_enabled())
    9393      total_enabled_volumes ++;
    9494  }
    9595  fprintf(stderr, "total volumes rendered: %d\n", total_enabled_volumes);
    9696
    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;
    101102  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++;
    105107
    106108    int volume_index = i;
     
    108110
    109111    //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);
    111114
    112115    double x0 = 0;
     
    128131    volume_planes[5].set_coeffs(0, 0, -1, z0+1);
    129132 
     133    //get modelview matrix with no translation
    130134    glPushMatrix();
    131 
    132135    glScalef(volume[volume_index]->aspect_ratio_width,
    133136          volume[volume_index]->aspect_ratio_height,
     
    156159    model_view_trans_inverse = model_view_trans.inverse();
    157160
    158     //draw volume bounding box
     161    //draw volume bounding box with translation (the correct location in space)
    159162    draw_bounding_box(x0, y0, z0, x0+1, y0+1, z0+1, 0.8, 0.1, 0.1, 1.5);
    160163    glPopMatrix();
     
    163166    for(int i=0; i<6; i++)
    164167      volume_planes[i].transform(model_view_no_trans);
    165 
    166168    get_near_far_z(mv_no_trans, zNear, zFar);
    167     //fprintf(stderr, "zNear:%f, zFar:%f\n", zNear, zFar);
    168     //fflush(stderr);
    169169
    170170    //compute actual rendering slices
    171171    float z_step = fabs(zNear-zFar)/n_slices;           
    172172    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];
    178175
    179176    float slice_z;
     
    184181    Vector4 vert4 = (Vector4(+10, -10, -0.5, 1));
    185182
     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
    186254    int counter = 0;
    187255    //transform slices and store them
     
    190258
    191259      ConvexPolygon *poly = new ConvexPolygon();
    192       polys[cur_index][counter] = poly;
     260      polys[cur_vol][counter] = poly;
    193261      counter++;
    194262
     
    238306  qsort(slices, total_rendered_slices, sizeof(SortElement), slice_sort);
    239307
     308  /*
    240309  //debug
    241310  for(int i=0; i<total_rendered_slices; i++){
     
    243312  }
    244313  fprintf(stderr, "\n\n");
    245 
     314  */
    246315
    247316  //Now we are ready to render all the slices from back to front
    248 
    249317  glEnable(GL_DEPTH_TEST);
    250318  glEnable(GL_BLEND);
     
    261329    glPopMatrix();
    262330
    263     glEnable(GL_DEPTH_TEST);
    264331    glBegin(GL_POLYGON);
    265332      cur->Emit(true);
     
    365432  glEnable(GL_BLEND);
    366433
    367 #if 0
    368434  if(slice_mode){
    369435    glEnable(GL_DEPTH_TEST);
    370436
    371437  //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;
    375441
    376442    if(axis==1){
     
    393459    }
    394460
    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);
    399465
    400466    ConvexPolygon *poly;
     
    411477    }
    412478
    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);
    416484
    417485    glPushMatrix();
    418486    glScalef(volume[volume_index]->aspect_ratio_width, volume[volume_index]->aspect_ratio_height, volume[volume_index]->aspect_ratio_depth);
    419487
    420     //activate_one_volume_shader(volume_index, 1, 1);
     488    activate_one_volume_shader(volume_index, 1, 1);
    421489    glPopMatrix();
    422490
    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);
    432493    glEnd();
    433494
    434     //deactivate_one_volume_shader();
     495    deactivate_one_volume_shader();
    435496  }
    436497  } //slice_mode
    437498
    438 #endif
    439499
    440500  if(volume_mode){
     
    500560  glDisable(GL_BLEND);
    501561  glDisable(GL_DEPTH_TEST);
    502   //glPopMatrix();
    503562}
    504563
Note: See TracChangeset for help on using the changeset viewer.