Changeset 415
- Timestamp:
- Apr 27, 2006 10:55:14 AM (18 years ago)
- Location:
- trunk/gui/vizservers/nanovis
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/vizservers/nanovis/ConvexPolygon.cpp
r226 r415 25 25 } 26 26 27 void ConvexPolygon::set_id(int v_id) { volume_id; }; 28 27 29 void ConvexPolygon::append_vertex(Vector4 vert){ 28 30 vertices.push_back(vert); … … 105 107 } 106 108 107 void ConvexPolygon::clip(Plane &clipPlane ) {109 void ConvexPolygon::clip(Plane &clipPlane, bool copy_to_texcoord) { 108 110 if (vertices.size() == 0) { 109 111 //fprintf(stderr, "ConvexPolygon: polygon has no vertices\n"); … … 159 161 clippedVerts.begin(), 160 162 clippedVerts.end()); 163 164 if(copy_to_texcoord) 165 copy_vertices_to_texcoords(); 161 166 } 162 167 -
trunk/gui/vizservers/nanovis/ConvexPolygon.h
r226 r415 27 27 VertexVector vertices; 28 28 TexVector texcoords; 29 int volume_id; //which volume this polygon slice belongs to 29 30 30 31 ConvexPolygon(); … … 37 38 38 39 // Clips the polygon, retaining the portion where ax + by + cz + d >= 0 39 void clip(Plane &clipPlane );40 void clip(Plane &clipPlane, bool copy_to_texcoords); 40 41 void Emit(bool use_texture); 41 42 void Emit(bool use_texture, Vector3& shift, Vector3& scale); 42 43 void copy_vertices_to_texcoords(); 44 void set_id(int v_id); 43 45 }; 44 46 -
trunk/gui/vizservers/nanovis/Makefile
r407 r415 20 20 CFLAG = -g -c -Wall $(INCLUDES) 21 21 22 all: nanovis simclient 22 all: nanovis 23 # simclient 23 24 24 25 clean: … … 58 59 gcc -g -o client $(OBJ_CLIENT) $(LIB_CLIENT) 59 60 60 simclient: Event.o nanoscale/EventPlayer.cpp61 gcc -g $(INCLUDES) $(NANOSCALESRC)/EventPlayer.cpp $(NANOSCALESRC)/clientlib.cpp -o simclient Event.o $(LIB_CLIENT)62 #g++ -g $(INCLUDES) $(NANOSCALESRC)/EventPlayer.cpp $(NANOSCALESRC)/clientlib.cpp -o simclient Event.o61 #simclient: Event.o $(NANOSCALESRC)/EventPlayer.cpp 62 # gcc -g $(INCLUDES) $(NANOSCALESRC)/EventPlayer.cpp $(NANOSCALESRC)/clientlib.cpp -o simclient Event.o $(LIB_CLIENT) 63 # g++ -g $(INCLUDES) $(NANOSCALESRC)/EventPlayer.cpp $(NANOSCALESRC)/clientlib.cpp -o simclient Event.o 63 64 64 65 Color.o: Color.cpp Color.h -
trunk/gui/vizservers/nanovis/Plane.h
r406 r415 21 21 class Plane { 22 22 public: 23 23 float a, b, c, d; 24 24 25 25 Plane(float a, float b, float c, float d); -
trunk/gui/vizservers/nanovis/VolumeRenderer.cpp
r407 r415 23 23 cam(_cam), 24 24 n_volumes(0), 25 g_context(_context) 25 g_context(_context), 26 slice_mode(false), 27 volume_mode(true) 26 28 { 27 29 //init the vectors for volumes and transfer functions … … 54 56 VolumeRenderer::~VolumeRenderer(){} 55 57 56 void VolumeRenderer::add_volume(Volume* _vol, TransferFunction* _tf, int _slice){ 58 int VolumeRenderer::add_volume(Volume* _vol, TransferFunction* _tf, int _slice){ 59 int ret = n_volumes; 60 57 61 volume.push_back(_vol); 58 62 tf.push_back(_tf); … … 61 65 62 66 n_volumes++; 63 } 67 68 return ret; 69 } 70 71 typedef struct SortElement{ 72 float z; 73 int volume_id; 74 int slice_id; 75 SortElement(float _z, int _v, int _s): 76 z(_z), volume_id(_v), slice_id(_s){} 77 }; 78 79 int slice_sort(const void* a, const void* b){ 80 if((*((SortElement*)a)).z > (*((SortElement*)b)).z) 81 return 1; 82 else 83 return -1; 84 } 85 86 87 void VolumeRenderer::render_all(){ 88 int total_enabled_volumes = 0; 89 int total_rendered_slices = 0; 90 91 for(int i=0; i<n_volumes; i++){ 92 if(render_bit[i]) 93 total_enabled_volumes ++; 94 } 95 fprintf(stderr, "total volumes rendered: %d\n", total_enabled_volumes); 96 97 ConvexPolygon*** polys = new ConvexPolygon**[total_enabled_volumes]; 98 int* actual_slices = new int[total_enabled_volumes]; 99 100 int cur_index = -1; 101 for(int i=0; i<n_volumes; i++){ 102 if(!render_bit[i]) 103 continue; 104 cur_index++; 105 106 int volume_index = i; 107 int n_slices = slice[volume_index]; 108 109 //volume start location 110 Vector4 shift_4d(volume[volume_index]->location.x, volume[volume_index]->location.y, volume[volume_index]->location.z, 0); 111 112 double x0 = 0; 113 double y0 = 0; 114 double z0 = 0; 115 116 Mat4x4 model_view_no_trans, model_view_trans; 117 Mat4x4 model_view_no_trans_inverse, model_view_trans_inverse; 118 119 double zNear, zFar; 120 121 //initialize volume plane with world coordinates 122 Plane volume_planes[6]; 123 volume_planes[0].set_coeffs(1, 0, 0, -x0); 124 volume_planes[1].set_coeffs(-1, 0, 0, x0+1); 125 volume_planes[2].set_coeffs(0, 1, 0, -y0); 126 volume_planes[3].set_coeffs(0, -1, 0, y0+1); 127 volume_planes[4].set_coeffs(0, 0, 1, -z0); 128 volume_planes[5].set_coeffs(0, 0, -1, z0+1); 129 130 glPushMatrix(); 131 132 glScalef(volume[volume_index]->aspect_ratio_width, 133 volume[volume_index]->aspect_ratio_height, 134 volume[volume_index]->aspect_ratio_depth); 135 136 glEnable(GL_DEPTH_TEST); 137 138 GLfloat mv_no_trans[16]; 139 glGetFloatv(GL_MODELVIEW_MATRIX, mv_no_trans); 140 141 model_view_no_trans = Mat4x4(mv_no_trans); 142 model_view_no_trans_inverse = model_view_no_trans.inverse(); 143 144 glPopMatrix(); 145 146 //get modelview matrix with translation 147 glPushMatrix(); 148 glTranslatef(shift_4d.x, shift_4d.y, shift_4d.z); 149 glScalef(volume[volume_index]->aspect_ratio_width, 150 volume[volume_index]->aspect_ratio_height, 151 volume[volume_index]->aspect_ratio_depth); 152 GLfloat mv_trans[16]; 153 glGetFloatv(GL_MODELVIEW_MATRIX, mv_trans); 154 155 model_view_trans = Mat4x4(mv_trans); 156 model_view_trans_inverse = model_view_trans.inverse(); 157 158 //draw volume bounding box 159 draw_bounding_box(x0, y0, z0, x0+1, y0+1, z0+1, 0.8, 0.1, 0.1, 1.5); 160 glPopMatrix(); 161 162 //transform volume_planes to eye coordinates. 163 for(int i=0; i<6; i++) 164 volume_planes[i].transform(model_view_no_trans); 165 166 get_near_far_z(mv_no_trans, zNear, zFar); 167 //fprintf(stderr, "zNear:%f, zFar:%f\n", zNear, zFar); 168 //fflush(stderr); 169 170 //compute actual rendering slices 171 float z_step = fabs(zNear-zFar)/n_slices; 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); 178 179 float slice_z; 180 181 Vector4 vert1 = (Vector4(-10, -10, -0.5, 1)); 182 Vector4 vert2 = (Vector4(-10, +10, -0.5, 1)); 183 Vector4 vert3 = (Vector4(+10, +10, -0.5, 1)); 184 Vector4 vert4 = (Vector4(+10, -10, -0.5, 1)); 185 186 int counter = 0; 187 //transform slices and store them 188 for (int i=0; i<n_actual_slices; i++){ 189 slice_z = zFar + i * z_step; //back to front 190 191 ConvexPolygon *poly = new ConvexPolygon(); 192 polys[cur_index][counter] = poly; 193 counter++; 194 195 poly->vertices.clear(); 196 poly->set_id(volume_index); 197 198 //Setting Z-coordinate 199 vert1.z = slice_z; 200 vert2.z = slice_z; 201 vert3.z = slice_z; 202 vert4.z = slice_z; 203 204 poly->append_vertex(vert1); 205 poly->append_vertex(vert2); 206 poly->append_vertex(vert3); 207 poly->append_vertex(vert4); 208 209 for(int k=0; k<6; k++){ 210 poly->clip(volume_planes[k], true); 211 } 212 213 poly->transform(model_view_no_trans_inverse); 214 poly->transform(model_view_trans); 215 216 if(poly->vertices.size()>=3) 217 total_rendered_slices++; 218 } 219 } //iterate all volumes 220 221 222 //We sort all the polygons according to their eye-space depth, from farthest to the closest. 223 //This step is critical for correct blending 224 225 SortElement* slices = (SortElement*) malloc(sizeof(SortElement)*total_rendered_slices); 226 227 int counter = 0; 228 for(int i=0; i<total_enabled_volumes; i++){ 229 for(int j=0; j<actual_slices[i]; j++){ 230 if(polys[i][j]->vertices.size() >= 3){ 231 slices[counter] = SortElement(polys[i][j]->vertices[0].z, i, j); 232 counter++; 233 } 234 } 235 } 236 237 //sort them 238 qsort(slices, total_rendered_slices, sizeof(SortElement), slice_sort); 239 240 //debug 241 for(int i=0; i<total_rendered_slices; i++){ 242 fprintf(stderr, "%f ", slices[i].z); 243 } 244 fprintf(stderr, "\n\n"); 245 246 247 //Now we are ready to render all the slices from back to front 248 249 glEnable(GL_DEPTH_TEST); 250 glEnable(GL_BLEND); 251 252 for(int i=0; i<total_rendered_slices; i++){ 253 int volume_index = slices[i].volume_id; 254 int slice_index = slices[i].slice_id; 255 ConvexPolygon* cur = polys[volume_index][slice_index]; 256 257 glPushMatrix(); 258 glScalef(volume[volume_index]->aspect_ratio_width, volume[volume_index]->aspect_ratio_height, volume[volume_index]->aspect_ratio_depth); 259 260 activate_one_volume_shader(volume_index, 1, 1); 261 glPopMatrix(); 262 263 glEnable(GL_DEPTH_TEST); 264 glBegin(GL_POLYGON); 265 cur->Emit(true); 266 glEnd(); 267 268 deactivate_one_volume_shader(); 269 } 270 271 glDisable(GL_DEPTH_TEST); 272 glDisable(GL_BLEND); 273 274 //Deallocate all the memory used 275 for(int i=0; i<total_enabled_volumes; i++){ 276 for(int j=0; j<actual_slices[i]; j++){ 277 delete polys[i][j]; 278 } 279 delete[] polys[i]; 280 } 281 delete[] polys; 282 delete[] actual_slices; 283 free(slices); 284 } 285 64 286 65 287 void VolumeRenderer::render(int volume_index){ … … 73 295 double z0 = 0; 74 296 75 Mat4x4 model_view ;76 Mat4x4 model_view_ inverse;297 Mat4x4 model_view_no_trans, model_view_trans; 298 Mat4x4 model_view_no_trans_inverse, model_view_trans_inverse; 77 299 78 300 double zNear, zFar; … … 80 302 //initialize volume plane with world coordinates 81 303 Plane volume_planes[6]; 82 83 304 volume_planes[0].set_coeffs(1, 0, 0, -x0); 84 305 volume_planes[1].set_coeffs(-1, 0, 0, x0+1); … … 87 308 volume_planes[4].set_coeffs(0, 0, 1, -z0); 88 309 volume_planes[5].set_coeffs(0, 0, -1, z0+1); 89 310 90 311 glPushMatrix(); 91 312 … … 96 317 glEnable(GL_DEPTH_TEST); 97 318 319 GLfloat mv_no_trans[16]; 320 glGetFloatv(GL_MODELVIEW_MATRIX, mv_no_trans); 321 322 model_view_no_trans = Mat4x4(mv_no_trans); 323 model_view_no_trans_inverse = model_view_no_trans.inverse(); 324 325 glPopMatrix(); 326 327 //get modelview matrix with translation 328 glPushMatrix(); 329 glTranslatef(shift_4d.x, shift_4d.y, shift_4d.z); 330 glScalef(volume[volume_index]->aspect_ratio_width, 331 volume[volume_index]->aspect_ratio_height, 332 volume[volume_index]->aspect_ratio_depth); 333 GLfloat mv_trans[16]; 334 glGetFloatv(GL_MODELVIEW_MATRIX, mv_trans); 335 336 model_view_trans = Mat4x4(mv_trans); 337 model_view_trans_inverse = model_view_trans.inverse(); 338 98 339 //draw volume bounding box 99 draw_bounding_box(x0+shift_4d.x, y0+shift_4d.y, z0+shift_4d.z, x0+shift_4d.x+1, y0+shift_4d.y+1, z0+shift_4d.z+1, 0.8, 0.1, 0.1, 1.5); 100 101 GLfloat mv[16]; 102 glGetFloatv(GL_MODELVIEW_MATRIX, mv); 103 104 model_view = Mat4x4(mv); 105 model_view_inverse = model_view.inverse(); 106 340 draw_bounding_box(x0, y0, z0, x0+1, y0+1, z0+1, 0.8, 0.1, 0.1, 1.5); 107 341 glPopMatrix(); 108 342 109 343 //transform volume_planes to eye coordinates. 110 344 for(int i=0; i<6; i++) 111 volume_planes[i].transform(model_view );112 113 get_near_far_z(mv , zNear, zFar);345 volume_planes[i].transform(model_view_no_trans); 346 347 get_near_far_z(mv_no_trans, zNear, zFar); 114 348 //fprintf(stderr, "zNear:%f, zFar:%f\n", zNear, zFar); 115 349 //fflush(stderr); … … 129 363 Vector4 vert4 = (Vector4(+10, -10, -0.5, 1)); 130 364 131 glEnable(GL_DEPTH_TEST);132 365 glEnable(GL_BLEND); 366 367 #if 0 368 if(slice_mode){ 369 glEnable(GL_DEPTH_TEST); 133 370 134 371 //render the cut planes … … 171 408 172 409 for(int k=0; k<6; k++){ 173 poly->clip(volume_planes[k]); 174 } 175 176 poly->copy_vertices_to_texcoords(); 410 poly->clip(volume_planes[k], true); 411 } 412 177 413 poly->transform(model_view_inverse); 178 414 poly->translate(shift_4d); … … 182 418 glScalef(volume[volume_index]->aspect_ratio_width, volume[volume_index]->aspect_ratio_height, volume[volume_index]->aspect_ratio_depth); 183 419 184 activate_one_volume_shader(volume_index, 1, 1);420 //activate_one_volume_shader(volume_index, 1, 1); 185 421 glPopMatrix(); 186 422 187 glBegin(GL_POLYGON); 188 poly->Emit(true); 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); 189 432 glEnd(); 190 433 191 deactivate_one_volume_shader(); 192 } 193 194 #if 1 434 //deactivate_one_volume_shader(); 435 } 436 } //slice_mode 437 438 #endif 439 440 if(volume_mode){ 441 glEnable(GL_DEPTH_TEST); 442 195 443 for (int i=0; i<n_actual_slices; i++){ 196 444 slice_z = zFar + i * z_step; //back to front … … 212 460 213 461 for(int k=0; k<6; k++){ 214 poly->clip(volume_planes[k]); 215 } 216 217 poly->copy_vertices_to_texcoords(); 462 poly->clip(volume_planes[k], true); 463 } 464 218 465 //move the volume to the proper location 219 220 poly->transform(model_view_inverse); 221 poly->translate(shift_4d); 222 poly->transform(model_view); 466 //poly->transform(model_view_inverse); 467 //poly->translate(shift_4d); 468 //poly->transform(model_view); 469 470 poly->transform(model_view_no_trans_inverse); 471 poly->transform(model_view_trans); 223 472 224 473 glPushMatrix(); 225 474 glScalef(volume[volume_index]->aspect_ratio_width, volume[volume_index]->aspect_ratio_height, volume[volume_index]->aspect_ratio_depth); 226 475 227 //glPushMatrix(); 228 //glMatrixMode(GL_MODELVIEW); 229 //glLoadIdentity(); 230 //glScaled(volume[volume_index]->aspect_ratio_width, volume[volume_index]->aspect_ratio_height, volume[volume_index]->aspect_ratio_depth); 231 232 /* 476 /* 233 477 //draw slice lines only 234 478 glDisable(GL_BLEND); … … 252 496 253 497 } 254 #endif 498 } //volume_mode 255 499 256 500 glDisable(GL_BLEND); … … 378 622 void VolumeRenderer::set_diffuse(float val){ live_diffuse = val; } 379 623 380 624 void VolumeRenderer::set_slice_mode(bool val) { slice_mode = val; } 625 void VolumeRenderer::set_volume_mode(bool val) { volume_mode = val; } 626 void VolumeRenderer::switch_slice_mode() { slice_mode = (!slice_mode); } 627 void VolumeRenderer::switch_volume_mode() { volume_mode = (!volume_mode); } 628 -
trunk/gui/vizservers/nanovis/VolumeRenderer.h
r407 r415 50 50 float live_specular; 51 51 52 bool slice_mode; //enable cut planes 53 bool volume_mode; //enable full volume rendering 54 52 55 //cg related 53 56 CGcontext g_context; //the Nvidia cg context … … 78 81 ~VolumeRenderer(); 79 82 80 voidadd_volume(Volume* _vol, TransferFunction* _tf, int _slice);83 int add_volume(Volume* _vol, TransferFunction* _tf, int _slice); 81 84 //add a volume and its transfer function 82 85 //we require a transfer function when a 83 86 //volume is added. 84 87 void render(int volume_index); 88 void render_all(); //render all enabled volumes; 85 89 void set_specular(float val); 86 90 void set_diffuse(float val); 91 void set_slice_mode(bool val); //control independently. 92 void set_volume_mode(bool val); 93 void switch_slice_mode(); //switch_cutplane_mode 94 void switch_volume_mode(); 87 95 }; 88 96 -
trunk/gui/vizservers/nanovis/nanovis.cpp
r414 r415 862 862 load_vector_file(0, "./data/J-wire-vec.dx"); 863 863 load_volume_file(1, "./data/mu-wire-3d.dx"); 864 load_volume_file(2, "./data/mu-wire-3d.dx"); 865 load_volume_file(3, "./data/mu-wire-3d.dx"); 864 866 865 867 init_tf(); //initialize transfer function … … 870 872 //create volume renderer 871 873 vol_render = new VolumeRenderer(cam, volume[1], tf[0], g_context); 874 vol_render->add_volume(volume[2], tf[0], 256); 875 volume[2]->location =Vector3(0.42, 0.1, 0.1); 876 vol_render->add_volume(volume[3], tf[0], 256); 877 volume[3]->location =Vector3(0.2, -0.1, -0.1); 878 872 879 873 880 psys = new ParticleSystem(NMESH, NMESH, g_context, volume[0]->id, … … 1470 1477 1471 1478 perf->enable(); 1472 //render volume :0 1473 //volume[0]->location =Vector3(0.,0.,0.); 1474 //render_volume(0, 256); 1475 1476 //render volume :1 1477 volume[1]->location =Vector3(0., 0., 0.); 1478 //render_volume(1, 256); 1479 vol_render->render(0); 1479 //vol_render->render(0); 1480 vol_render->render_all(); 1480 1481 1481 1482 //fprintf(stderr, "%lf\n", get_time_interval()); … … 1639 1640 vol_render->set_diffuse(live_diffuse); 1640 1641 break; 1642 case 'v': 1643 vol_render->switch_volume_mode(); 1644 break; 1645 case 'b': 1646 vol_render->switch_slice_mode(); 1647 break; 1641 1648 1642 1649 default: -
trunk/gui/vizservers/nanovis/shaders/one_volume.cg
r407 r415 18 18 19 19 20 #define PHONG_SHADING20 //#define PHONG_SHADING 21 21 22 22 PixelOut main(v2f IN, /* uniform sampler1D tf,*/ … … 49 49 //sample the transfer function texture 50 50 float4 color = tex1D(tf, sample.x); 51 color.w = renderParameters.y*color.w/renderParameters.x; 51 //color.w = renderParameters.y*color.w/renderParameters.x; 52 //color.w = 0.5; 52 53 53 54 //float4 color = float4(sample.x, 0, 0, 1);
Note: See TracChangeset
for help on using the changeset viewer.