Changeset 448 for trunk/gui/vizservers/nanovis
- Timestamp:
- May 30, 2006 8:06:30 AM (18 years ago)
- Location:
- trunk/gui/vizservers/nanovis
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/vizservers/nanovis/Volume.cpp
r434 r448 53 53 plane.push_back(CutPlane(3, 0.5)); 54 54 55 //initialize the labels 56 strcpy(label[0], "X Label"); 57 strcpy(label[1], "Y Label"); 58 strcpy(label[2], "Z Label"); 55 59 } 56 60 … … 130 134 outline_color.GetRGB(rgb); 131 135 } 136 137 void Volume::set_label(int axis, char* txt){ 138 strcpy(label[axis], txt); 139 } -
trunk/gui/vizservers/nanovis/Volume.h
r434 r448 54 54 bool outline_enabled; // show/hide outline around volume 55 55 Color outline_color; // color for outline around volume 56 56 57 57 58 public: … … 117 118 void set_outline_color(float* rgb); 118 119 void get_outline_color(float* rgb); 120 121 122 void set_label(int axis, char* txt); //change the label displayed on an axis 123 char label[3][50]; // the labels along each axis 0:x , 1:y, 2:z 119 124 }; 120 125 -
trunk/gui/vizservers/nanovis/VolumeRenderer.cpp
r434 r448 27 27 28 28 init_shaders(); 29 init_font("./font/Font.bmp"); 29 30 } 30 31 … … 163 164 (double)olcolor[0], (double)olcolor[1], (double)olcolor[2], 164 165 1.5); 166 167 draw_label(i); 165 168 } 166 169 glPopMatrix(); … … 726 729 volume[index]->disable(); 727 730 } 731 732 733 void VolumeRenderer::init_font(char* filename) { 734 735 FILE *file; 736 unsigned short int bfType; 737 long int bfOffBits; 738 short int biPlanes; 739 short int biBitCount; 740 long int biSizeImage; 741 int width, height; 742 int i; 743 unsigned char temp; 744 745 746 /* make sure the file is there and open it read-only (binary) */ 747 if ((file = fopen(filename, "rb")) == NULL) 748 { 749 assert(false); 750 } 751 752 if(!fread(&bfType, sizeof(short int), 1, file)) 753 { 754 assert(false); 755 //printf("Error reading file!\n"); 756 } 757 758 /* check if file is a bitmap */ 759 if (bfType != 19778) 760 { 761 assert(false); 762 //printf("Not a Bitmap-File!\n"); 763 } 764 765 /* get the file size */ 766 /* skip file size and reserved fields of bitmap file header */ 767 fseek(file, 8, SEEK_CUR); 768 769 /* get the position of the actual bitmap data */ 770 if (!fread(&bfOffBits, sizeof(long int), 1, file)) 771 { 772 assert(false); 773 //printf("Error reading file!\n"); 774 } 775 //printf("Data at Offset: %ld\n", bfOffBits); 776 777 /* skip size of bitmap info header */ 778 fseek(file, 4, SEEK_CUR); 779 780 /* get the width of the bitmap */ 781 fread(&width, sizeof(int), 1, file); 782 //printf("Width of Bitmap: %d\n", texture->width); 783 784 /* get the height of the bitmap */ 785 fread(&height, sizeof(int), 1, file); 786 //printf("Height of Bitmap: %d\n", texture->height); 787 788 /* get the number of planes (must be set to 1) */ 789 fread(&biPlanes, sizeof(short int), 1, file); 790 if (biPlanes != 1) 791 { 792 assert(false); 793 //printf("Error: number of Planes not 1!\n"); 794 } 795 796 /* get the number of bits per pixel */ 797 if (!fread(&biBitCount, sizeof(short int), 1, file)) 798 { 799 assert(false); 800 //printf("Error reading file!\n"); 801 //return 0; 802 } 803 804 //printf("Bits per Pixel: %d\n", biBitCount); 805 if (biBitCount != 24) 806 { 807 assert(false); 808 //printf("Bits per Pixel not 24\n"); 809 //return 0; 810 } 811 812 813 /* calculate the size of the image in bytes */ 814 biSizeImage = width * height * 3 * sizeof(unsigned char); 815 unsigned char* data = (unsigned char*) malloc(biSizeImage); 816 817 818 /* seek to the actual data */ 819 fseek(file, bfOffBits, SEEK_SET); 820 if (!fread(data, biSizeImage, 1, file)) 821 { 822 assert(false); 823 //printf("Error loading file!\n"); 824 } 825 826 /* swap red and blue (bgr -> rgb) */ 827 for (i = 0; i < biSizeImage; i += 3) 828 { 829 temp = data[i]; 830 data[i] = data[i + 2]; 831 data[i + 2] = temp; 832 } 833 834 835 //create opengl texture 836 glGenTextures(1, &font_texture); 837 glBindTexture(GL_TEXTURE_2D, font_texture); 838 glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); 839 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 840 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 841 842 843 build_font(); 844 assert(glGetError()==0); 845 846 free(data); 847 } 848 849 850 851 void VolumeRenderer::draw_label(int volume_index){ 852 853 Volume* vol = volume[volume_index]; 854 855 glEnable(GL_TEXTURE_2D); 856 glEnable(GL_BLEND); 857 858 //x 859 glPushMatrix(); 860 glTranslatef(0., -0.2, 1.); 861 glColor3f(1.f, 1.0f, 1.0f); 862 863 glPushMatrix(); 864 glScalef(1./volume[volume_index]->aspect_ratio_width, 865 1./volume[volume_index]->aspect_ratio_height, 866 1./volume[volume_index]->aspect_ratio_depth); 867 glPrint(vol->label[0], 0); 868 glPopMatrix(); 869 glPopMatrix(); 870 871 //y 872 glPushMatrix(); 873 glTranslatef(-0.02, 0., 1.); 874 875 glPushMatrix(); 876 glScalef(1./volume[volume_index]->aspect_ratio_width, 877 1./volume[volume_index]->aspect_ratio_height, 878 1./volume[volume_index]->aspect_ratio_depth); 879 glRotatef(90., 0., 0., 1.); 880 glColor3f(1.f, 1.0f, 1.0f); 881 glPrint(vol->label[1], 0); 882 glPopMatrix(); 883 glPopMatrix(); 884 885 //z 886 glPushMatrix(); 887 glTranslatef(1., -0.2, 1.); 888 889 glPushMatrix(); 890 glScalef(1./volume[volume_index]->aspect_ratio_width, 891 1./volume[volume_index]->aspect_ratio_height, 892 1./volume[volume_index]->aspect_ratio_depth); 893 glRotatef(90., 0., 1., 0.); 894 glColor3f(1.f, 1.0f, 1.0f); 895 glPrint(vol->label[2], 0); 896 glPopMatrix(); 897 glPopMatrix(); 898 899 glDisable(GL_TEXTURE_2D); 900 } 901 902 903 904 void VolumeRenderer::build_font() { 905 906 GLfloat cx, cy; /* the character coordinates in our texture */ 907 font_base = glGenLists(256); 908 glBindTexture(GL_TEXTURE_2D, font_texture); 909 for (int loop = 0; loop < 256; loop++) 910 { 911 cx = (float) (loop % 16) / 16.0f; 912 cy = (float) (loop / 16) / 16.0f; 913 glNewList(font_base + loop, GL_COMPILE); 914 glBegin(GL_QUADS); 915 glTexCoord2f(cx, 1 - cy - 0.0625f); 916 glVertex3f(0, 0, 0); 917 glTexCoord2f(cx + 0.0625f, 1 - cy - 0.0625f); 918 glVertex3f(0.04, 0, 0); 919 glTexCoord2f(cx + 0.0625f, 1 - cy); 920 glVertex3f(0.04, 0.04, 0); 921 glTexCoord2f(cx, 1 - cy); 922 glVertex3f(0, 0.04, 0); 923 glEnd(); 924 glTranslated(0.04, 0, 0); 925 glEndList(); 926 } 927 } 928 929 930 931 void VolumeRenderer::glPrint(char* string, int set){ 932 933 if(set>1) set=1; 934 935 glBindTexture(GL_TEXTURE_2D, font_texture); 936 937 glListBase(font_base - 32 + (128 * set)); 938 glCallLists(strlen(string), GL_BYTE, string); 939 940 } 941 -
trunk/gui/vizservers/nanovis/VolumeRenderer.h
r432 r448 46 46 bool volume_mode; //enable full volume rendering 47 47 48 48 49 //cg related 49 50 CGcontext g_context; //the Nvidia cg context … … 70 71 void get_near_far_z(Mat4x4 mv, double &zNear, double &zFar); 71 72 73 void init_font(char* filename); 74 GLuint font_texture; //the id of the font texture 75 void glPrint(char* string, int set); //there are two sets of font in the texture. 0, 1 76 void draw_label(int volume_index); //draw label using bitmap texture 77 GLuint font_base; //the base of the font display list 78 void build_font(); //register the location of each alphabet in the texture 79 72 80 public: 73 81 VolumeRenderer(CGcontext _context); -
trunk/gui/vizservers/nanovis/nanovis.cpp
r445 r448 46 46 47 47 //if true nanovis renders volumes in 3D, if not renders 2D plane 48 bool volume_mode = true; 48 bool volume_mode = true; 49 49 50 50 // color table for built-in transfer function editor … … 272 272 273 273 int axis; 274 if (GetAxis(interp, argv[3], &axis) != TCL_OK) {274 if (GetAxis(interp, (char*) argv[3], &axis) != TCL_OK) { 275 275 return TCL_ERROR; 276 276 } … … 320 320 321 321 int axis; 322 if (GetAxis(interp, argv[3], &axis) != TCL_OK) {322 if (GetAxis(interp, (char*) argv[3], &axis) != TCL_OK) { 323 323 return TCL_ERROR; 324 324 } … … 421 421 char **xferv; 422 422 423 if (Tcl_SplitList(interp, argv[3], &xferc, &xferv) != TCL_OK) {423 if (Tcl_SplitList(interp, argv[3], &xferc, (const char***) &xferv) != TCL_OK) { 424 424 return TCL_ERROR; 425 425 } … … 664 664 665 665 float rgb[3]; 666 if (GetColor(interp, argv[3], rgb) != TCL_OK) {666 if (GetColor(interp, (char*) argv[3], rgb) != TCL_OK) { 667 667 return TCL_ERROR; 668 668 } … … 708 708 709 709 float cval[3]; 710 if (GetColor(interp, argv[3], cval) != TCL_OK) {710 if (GetColor(interp, (char*) argv[3], cval) != TCL_OK) { 711 711 return TCL_ERROR; 712 712 } … … 976 976 int rgbc; 977 977 char **rgbv; 978 if (Tcl_SplitList(interp, str, &rgbc, &rgbv) != TCL_OK) {978 if (Tcl_SplitList(interp, str, &rgbc, (const char***)&rgbv) != TCL_OK) { 979 979 return TCL_ERROR; 980 980 } … … 1929 1929 //load_volume_file(0, "./data/nw-AB-Vg=0.000-Vd=1.000-potential.dx"); 1930 1930 //load_volume_file(0, "./data/test2.dx"); 1931 //load_volume_file(0, "./data/mu-wire-3d.dx"); 1931 //load_volume_file(0, "./data/mu-wire-3d.dx"); //I added this line to debug: Wei 1932 1932 //load_volume_file(0, "./data/input_nd_dx_4"); //take a VERY long time? 1933 1933 //load_vector_file(1, "./data/J-wire-vec.dx"); 1934 //load_volume_file(1, "./data/mu-wire-3d.dx"); 1934 //load_volume_file(1, "./data/mu-wire-3d.dx"); //I added this line to debug: Wei 1935 1935 //load_volume_file(3, "./data/mu-wire-3d.dx"); 1936 1936 //load_volume_file(4, "./data/mu-wire-3d.dx"); … … 1941 1941 //create volume renderer and add volumes to it 1942 1942 vol_render = new VolumeRenderer(g_context); 1943 1944 /* 1945 //I added this to debug : Wei 1946 float tmp_data[4*124]; 1947 TransferFunction* tmp_tf = new TransferFunction(124, tmp_data); 1948 vol_render->add_volume(volume[0], tmp_tf); 1949 volume[1]->move(Vector3(0.5, 0.6, 0.7)); 1950 vol_render->add_volume(volume[1], tmp_tf); 1951 */ 1943 1952 1944 1953 //create an 2D plane renderer … … 1947 1956 1948 1957 plane_render->add_plane(plane[0], get_transfunc("default")); 1958 1959 assert(glGetError()==0); 1949 1960 1950 1961 //init_particle_system(); … … 2889 2900 2890 2901 #ifndef XINETD 2891 MainTransferFunctionWindow * tf_window;2892 tf_window = new MainTransferFunctionWindow();2893 tf_window->mainInit();2902 //MainTransferFunctionWindow * tf_window; 2903 //tf_window = new MainTransferFunctionWindow(); 2904 //tf_window->mainInit(); 2894 2905 2895 2906 glutMouseFunc(mouse);
Note: See TracChangeset
for help on using the changeset viewer.