Changeset 2822 for trunk/packages/vizservers/nanovis/VolumeRenderer.cpp
- Timestamp:
- Mar 7, 2012, 12:21:30 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/VolumeRenderer.cpp
r2804 r2822 14 14 * ====================================================================== 15 15 */ 16 16 #include <stdlib.h> 17 17 #include <assert.h> 18 18 #include <time.h> 19 19 #include <sys/time.h> 20 20 21 #include <GL/glew.h> 22 #include <GL/glut.h> 23 24 #include <tcl.h> 25 26 #include <vector> 27 21 28 #include <R2/R2string.h> 22 29 #include <R2/R2FilePath.h> 23 30 24 31 #include "nanovis.h" 25 26 32 #include "VolumeRenderer.h" 27 #include "VolumeInterpolator.h" 33 #include "ConvexPolygon.h" 34 28 35 #include "NvStdVertexShader.h" 29 36 #include "Trace.h" … … 40 47 const char *path = R2FilePath::getInstance()->getPath("Font.bmp"); 41 48 if (path == NULL) { 42 43 49 ERROR("can't find Font.bmp\n"); 50 assert(path != NULL); 44 51 } 45 52 init_font(path); … … 57 64 58 65 //initialize the volume shaders 59 void VolumeRenderer::init_shaders() {60 61 //standard vertex program62 _stdVertexShader = new NvStdVertexShader();63 64 //volume rendering shader: one cubic volume65 _regularVolumeShader = new NvRegularVolumeShader();66 67 //volume rendering shader: one zincblende orbital volume.68 //This shader renders one orbital of the simulation.69 //A sim has S, P, D, SS orbitals. thus a full rendering requires 4 zincblende orbital volumes.70 //A zincblende orbital volume is decomposed into 2 "interlocking" cubic 4-component volumes and passed to the shader.71 //We render each orbital with a independent transfer functions then blend the result.72 //73 //The engine is already capable of rendering multiple volumes and combine them. Thus, we just invoke this shader on74 //S, P, D and SS orbitals with different transfor functions. The result is a multi-orbital rendering.75 _zincBlendeShader = new NvZincBlendeVolumeShader();66 void VolumeRenderer::init_shaders() 67 { 68 //standard vertex program 69 _stdVertexShader = new NvStdVertexShader(); 70 71 //volume rendering shader: one cubic volume 72 _regularVolumeShader = new NvRegularVolumeShader(); 73 74 //volume rendering shader: one zincblende orbital volume. 75 //This shader renders one orbital of the simulation. 76 //A sim has S, P, D, SS orbitals. thus a full rendering requires 4 zincblende orbital volumes. 77 //A zincblende orbital volume is decomposed into 2 "interlocking" cubic 4-component volumes and passed to the shader. 78 //We render each orbital with a independent transfer functions then blend the result. 79 // 80 //The engine is already capable of rendering multiple volumes and combine them. Thus, we just invoke this shader on 81 //S, P, D and SS orbitals with different transfor functions. The result is a multi-orbital rendering. 82 _zincBlendeShader = new NvZincBlendeVolumeShader(); 76 83 } 77 84 … … 80 87 int volume_id; 81 88 int slice_id; 89 82 90 SortElement(float _z, int _v, int _s) : 83 91 z(_z), volume_id(_v), slice_id(_s) 84 92 {} 85 93 }; 86 94 87 int slice_sort(const void* a, const void* b){ 88 if((*((SortElement*)a)).z > (*((SortElement*)b)).z) 95 int slice_sort(const void* a, const void* b) 96 { 97 if ((*((SortElement*)a)).z > (*((SortElement*)b)).z) 89 98 return 1; 90 99 else … … 549 558 } 550 559 } 551 552 560 void VolumeRenderer::deactivate_volume_shader() 553 561 { … … 557 565 } 558 566 559 void VolumeRenderer::get_near_far_z(Mat4x4 mv, double &zNear, double &zFar) 560 { 561 double x0 = 0; 562 double y0 = 0; 563 double z0 = 0; 564 double x1 = 1; 565 double y1 = 1; 566 double z1 = 1; 567 568 double zMin, zMax; 569 zMin = 10000; 570 zMax = -10000; 571 572 double vertex[8][4]; 573 574 vertex[0][0]=x0; vertex[0][1]=y0; vertex[0][2]=z0; vertex[0][3]=1.0; 575 vertex[1][0]=x1; vertex[1][1]=y0; vertex[1][2]=z0; vertex[1][3]=1.0; 576 vertex[2][0]=x0; vertex[2][1]=y1; vertex[2][2]=z0; vertex[2][3]=1.0; 577 vertex[3][0]=x0; vertex[3][1]=y0; vertex[3][2]=z1; vertex[3][3]=1.0; 578 vertex[4][0]=x1; vertex[4][1]=y1; vertex[4][2]=z0; vertex[4][3]=1.0; 579 vertex[5][0]=x1; vertex[5][1]=y0; vertex[5][2]=z1; vertex[5][3]=1.0; 580 vertex[6][0]=x0; vertex[6][1]=y1; vertex[6][2]=z1; vertex[6][3]=1.0; 581 vertex[7][0]=x1; vertex[7][1]=y1; vertex[7][2]=z1; vertex[7][3]=1.0; 582 583 for (int i = 0; i < 8; i++) { 584 Vector4 tmp = mv.transform(Vector4(vertex[i][0], vertex[i][1], vertex[i][2], vertex[i][3])); 585 tmp.perspective_devide(); 586 vertex[i][2] = tmp.z; 587 if (vertex[i][2]<zMin) zMin = vertex[i][2]; 588 if (vertex[i][2]>zMax) zMax = vertex[i][2]; 589 } 590 591 zNear = zMax; 592 zFar = zMin; 593 } 594 595 void VolumeRenderer::set_slice_mode(bool val) { slice_mode = val; } 596 void VolumeRenderer::set_volume_mode(bool val) { volume_mode = val; } 597 void VolumeRenderer::switch_slice_mode() { slice_mode = (!slice_mode); } 598 void VolumeRenderer::switch_volume_mode() { volume_mode = (!volume_mode); } 567 void VolumeRenderer::get_near_far_z(const Mat4x4& mv, double& zNear, double& zFar) 568 { 569 double x0 = 0; 570 double y0 = 0; 571 double z0 = 0; 572 double x1 = 1; 573 double y1 = 1; 574 double z1 = 1; 575 576 double zMin, zMax; 577 zMin = 10000; 578 zMax = -10000; 579 580 double vertex[8][4]; 581 582 vertex[0][0]=x0; vertex[0][1]=y0; vertex[0][2]=z0; vertex[0][3]=1.0; 583 vertex[1][0]=x1; vertex[1][1]=y0; vertex[1][2]=z0; vertex[1][3]=1.0; 584 vertex[2][0]=x0; vertex[2][1]=y1; vertex[2][2]=z0; vertex[2][3]=1.0; 585 vertex[3][0]=x0; vertex[3][1]=y0; vertex[3][2]=z1; vertex[3][3]=1.0; 586 vertex[4][0]=x1; vertex[4][1]=y1; vertex[4][2]=z0; vertex[4][3]=1.0; 587 vertex[5][0]=x1; vertex[5][1]=y0; vertex[5][2]=z1; vertex[5][3]=1.0; 588 vertex[6][0]=x0; vertex[6][1]=y1; vertex[6][2]=z1; vertex[6][3]=1.0; 589 vertex[7][0]=x1; vertex[7][1]=y1; vertex[7][2]=z1; vertex[7][3]=1.0; 590 591 for (int i = 0; i < 8; i++) { 592 Vector4 tmp = mv.transform(Vector4(vertex[i][0], vertex[i][1], vertex[i][2], vertex[i][3])); 593 tmp.perspective_divide(); 594 vertex[i][2] = tmp.z; 595 if (vertex[i][2] < zMin) zMin = vertex[i][2]; 596 if (vertex[i][2] > zMax) zMax = vertex[i][2]; 597 } 598 599 zNear = zMax; 600 zFar = zMin; 601 } 599 602 600 603 bool … … 759 762 glPushMatrix(); 760 763 761 glTranslatef(.5*vol->aspect_ratio_width, vol->aspect_ratio_height, 764 glTranslatef(.5*vol->aspect_ratio_width, vol->aspect_ratio_height, 762 765 -0.1*vol->aspect_ratio_depth); 763 766 glRotatef(180, 0, 0, 1); … … 765 768 766 769 glScalef(0.0008, 0.0008, 0.0008); 767 for (int i=0; i<length; i++){770 for (int i = 0; i < length; i++) { 768 771 glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[0].c_str()[i]); 769 772 glTranslatef(0.04, 0., 0.); … … 777 780 glRotatef(90, 0, 1, 0); 778 781 glRotatef(90, 0, 0, 1); 779 782 780 783 glScalef(0.0008, 0.0008, 0.0008); 781 for (int i=0; i<length; i++){784 for (int i = 0; i < length; i++) { 782 785 glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[1].c_str()[i]); 783 786 glTranslatef(0.04, 0., 0.); … … 792 795 793 796 glScalef(0.0008, 0.0008, 0.0008); 794 for (int i=0; i<length; i++){797 for (int i = 0; i < length; i++) { 795 798 glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[2].c_str()[i]); 796 799 glTranslatef(0.04, 0., 0.); … … 811 814 cy = (float) (loop / 16) / 16.0f; 812 815 glNewList(font_base + loop, GL_COMPILE); 813 814 815 816 817 818 819 820 821 822 823 816 glBegin(GL_QUADS); 817 glTexCoord2f(cx, 1 - cy - 0.0625f); 818 glVertex3f(0, 0, 0); 819 glTexCoord2f(cx + 0.0625f, 1 - cy - 0.0625f); 820 glVertex3f(0.04, 0, 0); 821 glTexCoord2f(cx + 0.0625f, 1 - cy); 822 glVertex3f(0.04, 0.04, 0); 823 glTexCoord2f(cx, 1 - cy); 824 glVertex3f(0, 0.04, 0); 825 glEnd(); 826 glTranslated(0.04, 0, 0); 824 827 glEndList(); 825 828 } … … 830 833 { 831 834 if (set > 1) { 832 set=1;835 set = 1; 833 836 } 834 837 glBindTexture(GL_TEXTURE_2D, font_texture);
Note: See TracChangeset
for help on using the changeset viewer.