- Timestamp:
- Apr 27, 2006, 12:52:42 PM (18 years ago)
- Location:
- trunk/gui/vizservers/nanovis
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/vizservers/nanovis/Volume.cpp
r407 r416 25 25 type(t), 26 26 interp_type(interp), 27 n_components(n) 27 n_components(n), 28 enabled(true) 28 29 { 29 30 … … 38 39 location = Vector3(x,y,z); 39 40 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. 41 43 plane.clear(); 42 44 plane.push_back(CutPlane(1, 0.5)); … … 48 50 49 51 Volume::~Volume(){ delete tex; } 52 53 54 void Volume::enable() { enabled = true; } 55 void Volume::disable() { enabled = false; } 56 void Volume::move(Vector3 _loc) { location = _loc; } 57 bool Volume::is_enabled() { return enabled; } 58 Vector3* Volume::get_location() { return &location; } 59 60 61 int Volume::add_cutplane(int _orientation, float _location){ 62 plane.push_back(CutPlane(1, 0.5)); 63 return plane.size() - 1; 64 } 65 66 void Volume::enable_cutplane(int index){ 67 assert(index < plane.size()); 68 plane[index].enabled = true; 69 } 70 71 void Volume::disable_cutplane(int index){ 72 assert(index < plane.size()); 73 plane[index].enabled = false; 74 } 75 76 void Volume::move_cutplane(int index, float location){ 77 assert(index < plane.size()); 78 plane[index].offset = location; 79 } 80 81 CutPlane* Volume::get_cutplane(int index){ 82 assert(index < plane.size()); 83 return &plane[index]; 84 } 85 86 int Volume::get_cutplane_count(){ 87 return plane.size(); 88 } 89 90 bool 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 28 28 int orient; //orientation - 1: xy slice, 2: yz slice, 3: xz slice 29 29 float offset; //normalized offset [0,1] in the volume 30 bool enabled; 30 31 31 32 CutPlane(int _orient, float _offset): 32 33 orient(_orient), 33 offset(_offset){} 34 offset(_offset), 35 enabled(true){} 34 36 }; 35 37 … … 37 39 class Volume{ 38 40 41 private: 42 vector <CutPlane> plane; //cut planes 43 39 44 public: 40 45 Vector3 location; 41 vector <CutPlane> plane; //cut planes 46 47 bool enabled; 42 48 43 49 int width; … … 62 68 ~Volume(); 63 69 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 67 84 68 85 }; -
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 -
trunk/gui/vizservers/nanovis/nanovis.cpp
r415 r416 870 870 init_lic(); //init line integral convolution 871 871 872 //create volume renderer 872 //create volume renderer and add volumes to it 873 873 vol_render = new VolumeRenderer(cam, volume[1], tf[0], g_context); 874 volume[2]->move(Vector3(0.42, 0.1, 0.1)); 874 875 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)); 876 877 vol_render->add_volume(volume[3], tf[0], 256); 877 volume[3]->location =Vector3(0.2, -0.1, -0.1);878 878 879 879 -
trunk/gui/vizservers/nanovis/shaders/one_volume.cg
r415 r416 18 18 19 19 20 //#define PHONG_SHADING21 22 20 PixelOut main(v2f IN, /* uniform sampler1D tf,*/ 23 21 uniform sampler3D volume, … … 30 28 PixelOut OUT; 31 29 float4 tex_coord = mul(modelViewInv, IN.TexCoord); 32 33 //if(renderParameters.y==1){ //1 component 30 float4 sample = tex3D(volume, tex_coord.xyz); 34 31 35 float4 sample = tex3D(volume, tex_coord.xyz); 32 //sample the transfer function texture 33 float4 color = tex1D(tf, sample.x); 36 34 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 42 42 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); 46 47 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); 48 51 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); 53 55 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); 56 59 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 } 61 63 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; 84 65 //debug 85 66 //OUT.Color = float4(tex_coord, 1);
Note: See TracChangeset
for help on using the changeset viewer.