Changeset 416 for trunk


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!!

Location:
trunk/gui/vizservers/nanovis
Files:
5 edited

Legend:

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

    r407 r416  
    2525        type(t),
    2626        interp_type(interp),
    27         n_components(n)
     27        n_components(n),
     28        enabled(true)
    2829{
    2930
     
    3839  location = Vector3(x,y,z);
    3940
    40   //add cut planes
     41  //Add cut planes. We create 3 default cut planes facing x, y, z directions.
     42  //The default location of cut plane is in the middle of the data.
    4143  plane.clear();
    4244  plane.push_back(CutPlane(1, 0.5));
     
    4850
    4951Volume::~Volume(){ delete tex; }
     52
     53
     54void Volume::enable() { enabled = true; }
     55void Volume::disable() { enabled = false; }
     56void Volume::move(Vector3 _loc) { location = _loc; }
     57bool Volume::is_enabled() { return enabled; }
     58Vector3* Volume::get_location() { return &location; }
     59
     60
     61int Volume::add_cutplane(int _orientation, float _location){
     62  plane.push_back(CutPlane(1, 0.5));
     63  return plane.size() - 1;
     64}
     65
     66void Volume::enable_cutplane(int index){
     67  assert(index < plane.size());
     68  plane[index].enabled = true;
     69}
     70
     71void Volume::disable_cutplane(int index){
     72  assert(index < plane.size());
     73  plane[index].enabled = false;
     74}
     75
     76void Volume::move_cutplane(int index, float location){
     77  assert(index < plane.size());
     78  plane[index].offset = location;
     79}
     80
     81CutPlane* Volume::get_cutplane(int index){
     82  assert(index < plane.size());
     83  return &plane[index];
     84}
     85
     86int Volume::get_cutplane_count(){
     87  return plane.size();
     88}
     89
     90bool Volume::cutplane_is_enabled(int index){
     91  assert(index < plane.size());
     92  return plane[index].enabled;
     93}
  • trunk/gui/vizservers/nanovis/Volume.h

    r407 r416  
    2828  int orient;   //orientation - 1: xy slice, 2: yz slice, 3: xz slice
    2929  float offset; //normalized offset [0,1] in the volume
     30  bool enabled;
    3031
    3132  CutPlane(int _orient, float _offset):
    3233        orient(_orient),
    33         offset(_offset){}
     34        offset(_offset),
     35        enabled(true){}
    3436};
    3537
     
    3739class Volume{
    3840       
     41private:
     42        vector <CutPlane> plane; //cut planes
     43
    3944public:
    4045        Vector3 location;
    41         vector <CutPlane> plane; //cut planes
     46
     47        bool enabled;
    4248
    4349        int width;
     
    6268        ~Volume();
    6369       
    64         void activate();
    65         void deactivate();
    66         void initialize(float* data);
     70        void enable(); //VolumeRenderer will render an enabled volume and its cutplanes
     71        void disable();
     72        void move(Vector3 _loc);
     73        bool is_enabled();
     74        Vector3* get_location();
     75
     76        //methods related to cutplanes
     77        int add_cutplane(int _orientation, float _location); //add a plane and returns its index
     78        void enable_cutplane(int index);
     79        void disable_cutplane(int index);
     80        void move_cutplane(int index, float _location);
     81        CutPlane* get_cutplane(int index);
     82        int get_cutplane_count();       //returns the number of cutplanes in the volume
     83        bool cutplane_is_enabled(int index);    //check if a cutplane is enabled
    6784
    6885};
  • 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
  • trunk/gui/vizservers/nanovis/nanovis.cpp

    r415 r416  
    870870   init_lic();  //init line integral convolution
    871871
    872    //create volume renderer
     872   //create volume renderer and add volumes to it
    873873   vol_render = new VolumeRenderer(cam, volume[1], tf[0], g_context);
     874   volume[2]->move(Vector3(0.42, 0.1, 0.1));
    874875   vol_render->add_volume(volume[2], tf[0], 256);
    875    volume[2]->location =Vector3(0.42, 0.1, 0.1);
     876   volume[3]->move(Vector3(0.2, -0.1, -0.1));
    876877   vol_render->add_volume(volume[3], tf[0], 256);
    877    volume[3]->location =Vector3(0.2, -0.1, -0.1);
    878878
    879879   
  • trunk/gui/vizservers/nanovis/shaders/one_volume.cg

    r415 r416  
    1818
    1919
    20 //#define PHONG_SHADING
    21 
    2220PixelOut main(v2f IN, /* uniform sampler1D tf,*/
    2321                uniform sampler3D volume,
     
    3028  PixelOut OUT;
    3129  float4 tex_coord = mul(modelViewInv, IN.TexCoord);
    32        
    33 //if(renderParameters.y==1){ //1 component
     30  float4 sample = tex3D(volume, tex_coord.xyz);
    3431
    35     float4 sample = tex3D(volume, tex_coord.xyz);
     32  //sample the transfer function texture
     33  float4 color = tex1D(tf, sample.x);
    3634
    37 #ifdef PHONG_SHADING
    38       //lighting parameters
    39       float3 normal;
    40       if(length(sample.yzw)>0.0)
    41         normal = normalize(sample.yzw);
     35  if(renderParameters.x < 0.5)
     36  { //If single slice render, only flat shading, completely opaque.
     37    color.w = 1;
     38    //color.w = renderParameters.y*color.w/renderParameters.x;
     39  }
     40  else
     41  { //regular volume rendering, we do PHONG SHADING
    4242
    43       float3 light_vector = normalize(IN.Light);
    44       float3 eye_vector = normalize(IN.EyeVector);
    45       float3 half_vector = normalize(eye_vector+light_vector);
     43    //lighting parameters
     44    float3 normal;
     45    if(length(sample.yzw)>0.0)
     46      normal = normalize(sample.yzw);
    4647
    47 #endif
     48    float3 light_vector = normalize(IN.Light);
     49    float3 eye_vector = normalize(IN.EyeVector);
     50    float3 half_vector = normalize(eye_vector+light_vector);
    4851
    49       //sample the transfer function texture
    50       float4 color = tex1D(tf, sample.x);
    51       //color.w = renderParameters.y*color.w/renderParameters.x;
    52       //color.w = 0.5;
     52    //lighting computation
     53    float normal_dot_light = max(dot(normal, light_vector), 0);
     54    float normal_dot_half = max(dot(normal, half_vector), 0);
    5355
    54       //float4 color = float4(sample.x, 0, 0, 1);
    55        
     56    float ambient = 0.1;
     57    float diffuse = normal_dot_light * renderParameters.z;
     58    float specular = pow(normal_dot_half, renderParameters.w)*(1-ambient-diffuse);
    5659
    57 #ifdef PHONG_SHADING
    58       //lighting computation
    59       float normal_dot_light = max(dot(normal, light_vector), 0);
    60       float normal_dot_half = max(dot(normal, half_vector), 0);
     60    float lighting = ambient + diffuse + specular;
     61    color.xyz = color.xyz * lighting;
     62  }
    6163
    62       float ambient = 0.1;
    63       float diffuse = normal_dot_light * renderParameters.z;
    64       float specular = pow(normal_dot_half, renderParameters.w)*(1-ambient-diffuse);
    65 
    66       float lighting = ambient + diffuse + specular;
    67       color.xyz = color.xyz * lighting;
    68 
    69       //debug
    70       //color.xyz = normal.xyz;       //display normals
    71 #endif
    72 
    73       OUT.Color = color;
    74 //  }
    75 
    76 /*
    77   else if(renderParameters.y==0){
    78     //3 component
    79     float3 sample = tex3D(volume, tex_coord.xyz).xyz;
    80     OUT.Color = float4(3*sample, 2*length(sample)/renderParameters.x);
    81   }
    82 */
    83 
     64  OUT.Color = color;
    8465  //debug
    8566  //OUT.Color = float4(tex_coord, 1);
Note: See TracChangeset for help on using the changeset viewer.