Ignore:
Timestamp:
May 30, 2006 8:06:30 AM (18 years ago)
Author:
qiaow
Message:

Added label drawing on each axis.
Each volume has three labels, one for each axis.

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

Legend:

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

    r434 r448  
    5353  plane.push_back(CutPlane(3, 0.5));
    5454 
     55  //initialize the labels 
     56  strcpy(label[0], "X Label");
     57  strcpy(label[1], "Y Label");
     58  strcpy(label[2], "Z Label");
    5559}
    5660
     
    130134    outline_color.GetRGB(rgb);
    131135}
     136
     137void Volume::set_label(int axis, char* txt){
     138  strcpy(label[axis], txt);
     139}       
  • trunk/gui/vizservers/nanovis/Volume.h

    r434 r448  
    5454        bool outline_enabled;   // show/hide outline around volume
    5555        Color outline_color;    // color for outline around volume
     56
    5657
    5758public:
     
    117118        void set_outline_color(float* rgb);
    118119        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
    119124};
    120125
  • trunk/gui/vizservers/nanovis/VolumeRenderer.cpp

    r434 r448  
    2727
    2828  init_shaders();
     29  init_font("./font/Font.bmp");
    2930}
    3031
     
    163164            (double)olcolor[0], (double)olcolor[1], (double)olcolor[2],
    164165            1.5);
     166
     167        draw_label(i);
    165168    }
    166169    glPopMatrix();
     
    726729  volume[index]->disable();
    727730}
     731
     732
     733void 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
     851void 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
     904void 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   
     931void 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  
    4646  bool volume_mode;     //enable full volume rendering
    4747
     48
    4849  //cg related
    4950  CGcontext g_context;          //the Nvidia cg context
     
    7071  void get_near_far_z(Mat4x4 mv, double &zNear, double &zFar);
    7172
     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
    7280public:
    7381  VolumeRenderer(CGcontext _context);
  • trunk/gui/vizservers/nanovis/nanovis.cpp

    r445 r448  
    4646
    4747//if true nanovis renders volumes in 3D, if not renders 2D plane
    48 bool volume_mode = true;
     48bool volume_mode = true; 
    4949
    5050// color table for built-in transfer function editor
     
    272272
    273273        int axis;
    274         if (GetAxis(interp, argv[3], &axis) != TCL_OK) {
     274        if (GetAxis(interp, (char*) argv[3], &axis) != TCL_OK) {
    275275            return TCL_ERROR;
    276276        }
     
    320320
    321321        int axis;
    322         if (GetAxis(interp, argv[3], &axis) != TCL_OK) {
     322        if (GetAxis(interp, (char*) argv[3], &axis) != TCL_OK) {
    323323            return TCL_ERROR;
    324324        }
     
    421421        char **xferv;
    422422
    423         if (Tcl_SplitList(interp, argv[3], &xferc, &xferv) != TCL_OK) {
     423        if (Tcl_SplitList(interp, argv[3], &xferc, (const char***) &xferv) != TCL_OK) {
    424424            return TCL_ERROR;
    425425        }
     
    664664
    665665            float rgb[3];
    666             if (GetColor(interp, argv[3], rgb) != TCL_OK) {
     666            if (GetColor(interp, (char*) argv[3], rgb) != TCL_OK) {
    667667                return TCL_ERROR;
    668668            }
     
    708708
    709709            float cval[3];
    710                 if (GetColor(interp, argv[3], cval) != TCL_OK) {
     710                if (GetColor(interp, (char*) argv[3], cval) != TCL_OK) {
    711711                        return TCL_ERROR;
    712712                }
     
    976976    int rgbc;
    977977    char **rgbv;
    978     if (Tcl_SplitList(interp, str, &rgbc, &rgbv) != TCL_OK) {
     978    if (Tcl_SplitList(interp, str, &rgbc, (const char***)&rgbv) != TCL_OK) {
    979979        return TCL_ERROR;
    980980    }
     
    19291929   //load_volume_file(0, "./data/nw-AB-Vg=0.000-Vd=1.000-potential.dx");
    19301930   //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
    19321932   //load_volume_file(0, "./data/input_nd_dx_4"); //take a VERY long time?
    19331933   //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
    19351935   //load_volume_file(3, "./data/mu-wire-3d.dx");
    19361936   //load_volume_file(4, "./data/mu-wire-3d.dx");
     
    19411941   //create volume renderer and add volumes to it
    19421942   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   */
    19431952
    19441953   //create an 2D plane renderer
     
    19471956
    19481957   plane_render->add_plane(plane[0], get_transfunc("default"));
     1958
     1959   assert(glGetError()==0);
    19491960
    19501961   //init_particle_system();
     
    28892900
    28902901#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();
    28942905
    28952906   glutMouseFunc(mouse);
Note: See TracChangeset for help on using the changeset viewer.