Changeset 449 for trunk


Ignore:
Timestamp:
May 30, 2006, 7:29:30 PM (18 years ago)
Author:
mmc
Message:

Fixed the VolumeRenderer? to render multiple volumes properly when
one or more are turned off. Merged Wei's changes for axis labels
and added "volume axis label" command to change labels.

Location:
trunk/gui/vizservers/nanovis
Files:
4 edited

Legend:

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

    r448 r449  
    5454 
    5555  //initialize the labels 
    56   strcpy(label[0], "X Label");
    57   strcpy(label[1], "Y Label");
    58   strcpy(label[2], "Z Label");
     56  label[0] = "X Label";
     57  label[1] = "Y Label";
     58  label[2] = "Z Label";
    5959}
    6060
     
    136136
    137137void Volume::set_label(int axis, char* txt){
    138   strcpy(label[axis], txt);
    139 }       
     138  label[axis] = txt;
     139}
  • trunk/gui/vizservers/nanovis/Volume.h

    r448 r449  
    1717#define _VOLUME_H_
    1818
     19#include <string>
    1920#include <vector>
    2021
     
    121122
    122123        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
     124        std::string label[3];   // the labels along each axis 0:x , 1:y, 2:z
    124125};
    125126
  • trunk/gui/vizservers/nanovis/VolumeRenderer.cpp

    r448 r449  
    8383
    8484void VolumeRenderer::render_all(){
    85   int total_enabled_volumes = 0;
    8685  int total_rendered_slices = 0;
    8786
    88   //compute total enabled volumes
     87  ConvexPolygon*** polys = new ConvexPolygon**[n_volumes];      //two dimension pointer array
     88                                                                        //storing the slices
     89  int* actual_slices = new int[n_volumes]; //number of actual slices for each volume
     90
    8991  for(int i=0; i<n_volumes; i++){
    90     if(volume[i]->is_enabled())
    91       total_enabled_volumes ++;
    92   }
    93   //fprintf(stderr, "total volumes rendered: %d\n", total_enabled_volumes);
    94 
    95   ConvexPolygon*** polys = new ConvexPolygon**[total_enabled_volumes];  //two dimension pointer array
    96                                                                         //storing the slices
    97   int* actual_slices = new int[total_enabled_volumes]; //number of actual slices for each volume
    98 
    99   int cur_vol = -1;
    100   for(int i=0; i<n_volumes; i++){
     92    polys[i] = NULL;
     93    actual_slices[i] = 0;
     94
    10195    if(!volume[i]->is_enabled())
    10296      continue; //skip this volume
    103 
    104     cur_vol++;
    10597
    10698    int volume_index = i;
     
    158150
    159151    //draw volume bounding box with translation (the correct location in space)
    160     if (volume[i]->outline_is_enabled()) {
     152    if (volume[volume_index]->outline_is_enabled()) {
    161153        float olcolor[3];
    162         volume[i]->get_outline_color(olcolor);
     154        volume[volume_index]->get_outline_color(olcolor);
    163155        draw_bounding_box(x0, y0, z0, x0+1, y0+1, z0+1,
    164156            (double)olcolor[0], (double)olcolor[1], (double)olcolor[2],
     
    178170    int n_actual_slices;
    179171
    180     if (volume[i]->data_is_enabled()) {
     172    if (volume[volume_index]->data_is_enabled()) {
    181173        n_actual_slices = (int)(fabs(zNear-zFar)/z_step + 1);
    182         polys[cur_vol] = new ConvexPolygon*[n_actual_slices];
     174        polys[volume_index] = new ConvexPolygon*[n_actual_slices];
    183175    } else {
    184176        n_actual_slices = 0;
    185         polys[cur_vol] = NULL;
    186     }
    187     actual_slices[cur_vol] = n_actual_slices;
     177        polys[volume_index] = NULL;
     178    }
     179    actual_slices[volume_index] = n_actual_slices;
    188180
    189181    Vector4 vert1 = (Vector4(-10, -10, -0.5, 1));
     
    280272
    281273      ConvexPolygon *poly = new ConvexPolygon();
    282       polys[cur_vol][counter] = poly;
     274      polys[volume_index][counter] = poly;
    283275      counter++;
    284276
     
    317309
    318310  int counter = 0;
    319   for(int i=0; i<total_enabled_volumes; i++){
     311  for(int i=0; i<n_volumes; i++){
    320312    for(int j=0; j<actual_slices[i]; j++){
    321313      if(polys[i][j]->vertices.size() >= 3){
     
    364356
    365357  //Deallocate all the memory used
    366   for(int i=0; i<total_enabled_volumes; i++){
     358  for(int i=0; i<n_volumes; i++){
    367359    for(int j=0; j<actual_slices[i]; j++){
    368360      delete polys[i][j];
    369361    }
    370     delete[] polys[i];
     362    if (polys[i]) {
     363      delete[] polys[i];
     364    }
    371365  }
    372366  delete[] polys;
     
    865859          1./volume[volume_index]->aspect_ratio_height,
    866860          1./volume[volume_index]->aspect_ratio_depth);
    867       glPrint(vol->label[0], 0);
     861      glPrint((char*)vol->label[0].c_str(), 0);
    868862    glPopMatrix();
    869863  glPopMatrix();
     
    871865  //y
    872866  glPushMatrix();
    873     glTranslatef(-0.02, 0., 1.);
     867    glTranslatef(1., 0.5, 0.);
    874868
    875869    glPushMatrix();
     
    877871          1./volume[volume_index]->aspect_ratio_height,
    878872          1./volume[volume_index]->aspect_ratio_depth);
    879       glRotatef(90., 0., 0., 1.);
     873      glRotatef(45., 0., 1., 0.);
    880874      glColor3f(1.f, 1.0f, 1.0f);
    881       glPrint(vol->label[1], 0);
     875      glPrint((char*)vol->label[1].c_str(), 0);
    882876    glPopMatrix();
    883877  glPopMatrix();
     
    893887      glRotatef(90., 0., 1., 0.);
    894888      glColor3f(1.f, 1.0f, 1.0f);
    895       glPrint(vol->label[2], 0);
     889      glPrint((char*)vol->label[2].c_str(), 0);
    896890    glPopMatrix();
    897891  glPopMatrix();
  • trunk/gui/vizservers/nanovis/nanovis.cpp

    r448 r449  
    421421        char **xferv;
    422422
    423         if (Tcl_SplitList(interp, argv[3], &xferc, (const char***) &xferv) != TCL_OK) {
     423        if (Tcl_SplitList(interp, argv[3], &xferc, &xferv) != TCL_OK) {
    424424            return TCL_ERROR;
    425425        }
     
    487487 * ----------------------------------------------------------------------
    488488 * CLIENT COMMAND:
     489 *   volume axis label x|y|z <value> ?<volumeId> ...?
    489490 *   volume data state on|off ?<volumeId> ...?
    490491 *   volume outline state on|off ?<volumeId> ...?
     
    502503VolumeCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])
    503504{
    504         if (argc < 2) {
    505                 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    506                         " option arg arg...\"", (char*)NULL);
    507                 return TCL_ERROR;
     505    if (argc < 2) {
     506        Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     507            " option arg arg...\"", (char*)NULL);
     508        return TCL_ERROR;
    508509    }
    509510
    510511    char c = *argv[1];
    511         if (c == 'd' && strcmp(argv[1],"data") == 0) {
     512    if (c == 'a' && strcmp(argv[1],"axis") == 0) {
    512513        if (argc < 3) {
    513                     Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    514                             argv[1], " option ?arg arg...?\"", (char*)NULL);
    515                     return TCL_ERROR;
     514            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     515                argv[1], " option ?arg arg...?\"", (char*)NULL);
     516            return TCL_ERROR;
    516517        }
    517518        c = *argv[2];
    518             if (c == 's' && strcmp(argv[2],"state") == 0) {
     519        if (c == 'l' && strcmp(argv[2],"label") == 0) {
    519520            if (argc < 4) {
    520                         Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    521                                 argv[1], " state on|off ?volume ...?\"", (char*)NULL);
    522                         return TCL_ERROR;
     521                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     522                    argv[1], " label x|y|z string ?volume ...?\"", (char*)NULL);
     523                return TCL_ERROR;
     524            }
     525
     526            int axis;
     527            if (GetAxis(interp, argv[3], &axis) != TCL_OK) {
     528                return TCL_ERROR;
     529            }
     530
     531            int ivol;
     532            if (argc < 6) {
     533                for (ivol=0; ivol < n_volumes; ivol++) {
     534                    volume[ivol]->set_label(axis, argv[4]);
     535                }
     536            } else {
     537                for (int n=5; n < argc; n++) {
     538                    if (Tcl_GetInt(interp, argv[n], &ivol) != TCL_OK) {
     539                        return TCL_ERROR;
     540                    }
     541                    volume[ivol]->set_label(axis, argv[4]);
     542                }
     543            }
     544            return TCL_OK;
     545        }
     546        Tcl_AppendResult(interp, "bad option \"", argv[2],
     547            "\": should be label", (char*)NULL);
     548        return TCL_ERROR;
     549    }
     550    else if (c == 'd' && strcmp(argv[1],"data") == 0) {
     551        if (argc < 3) {
     552            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     553                argv[1], " option ?arg arg...?\"", (char*)NULL);
     554            return TCL_ERROR;
     555        }
     556        c = *argv[2];
     557        if (c == 's' && strcmp(argv[2],"state") == 0) {
     558            if (argc < 4) {
     559                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     560                    argv[1], " state on|off ?volume ...?\"", (char*)NULL);
     561                return TCL_ERROR;
    523562            }
    524563
    525564            int state;
    526                 if (Tcl_GetBoolean(interp, argv[3], &state) != TCL_OK) {
    527                         return TCL_ERROR;
    528                 }
     565            if (Tcl_GetBoolean(interp, argv[3], &state) != TCL_OK) {
     566                return TCL_ERROR;
     567            }
    529568
    530569            int ivol;
     
    539578            } else {
    540579                for (int n=4; n < argc; n++) {
    541                         if (Tcl_GetInt(interp, argv[n], &ivol) != TCL_OK) {
    542                                 return TCL_ERROR;
    543                         }
     580                    if (Tcl_GetInt(interp, argv[n], &ivol) != TCL_OK) {
     581                        return TCL_ERROR;
     582                    }
    544583                    if (state) {
    545584                        volume[ivol]->enable_data();
     
    551590            return TCL_OK;
    552591        }
    553             else if (c == 'f' && strcmp(argv[2],"follows") == 0) {
     592        else if (c == 'f' && strcmp(argv[2],"follows") == 0) {
    554593            int nbytes;
    555                 if (Tcl_GetInt(interp, argv[3], &nbytes) != TCL_OK) {
    556                         return TCL_ERROR;
    557                 }
     594            if (Tcl_GetInt(interp, argv[3], &nbytes) != TCL_OK) {
     595                return TCL_ERROR;
     596            }
    558597
    559598            char fname[64];
     
    609648        return TCL_ERROR;
    610649    }
    611         else if (c == 'o' && strcmp(argv[1],"outline") == 0) {
     650    else if (c == 'o' && strcmp(argv[1],"outline") == 0) {
    612651        if (argc < 3) {
    613                     Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    614                             argv[1], " option ?arg arg...?\"", (char*)NULL);
    615                     return TCL_ERROR;
     652            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     653                argv[1], " option ?arg arg...?\"", (char*)NULL);
     654            return TCL_ERROR;
    616655        }
    617656        c = *argv[2];
     
    693732        return TCL_ERROR;
    694733    }
    695         else if (c == 's' && strcmp(argv[1],"shading") == 0) {
     734    else if (c == 's' && strcmp(argv[1],"shading") == 0) {
    696735        if (argc < 3) {
    697                     Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    698                             argv[1], " option ?arg arg...?\"", (char*)NULL);
    699                     return TCL_ERROR;
     736            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     737                argv[1], " option ?arg arg...?\"", (char*)NULL);
     738            return TCL_ERROR;
    700739        }
    701740        c = *argv[2];
    702             if (c == 'c' && strcmp(argv[2],"color") == 0) {
     741        if (c == 'c' && strcmp(argv[2],"color") == 0) {
    703742            if (argc < 4) {
    704                         Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    705                                 argv[1], " color value ?volume ...?\"", (char*)NULL);
    706                         return TCL_ERROR;
     743                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     744                    argv[1], " color value ?volume ...?\"", (char*)NULL);
     745                return TCL_ERROR;
    707746            }
    708747
    709748            float cval[3];
    710                 if (GetColor(interp, (char*) argv[3], cval) != TCL_OK) {
    711                         return TCL_ERROR;
    712                 }
     749            if (GetColor(interp, (char*) argv[3], cval) != TCL_OK) {
     750                return TCL_ERROR;
     751            }
    713752
    714753            int ivol;
     
    719758            } else {
    720759                for (int n=4; n < argc; n++) {
    721                         if (Tcl_GetInt(interp, argv[n], &ivol) != TCL_OK) {
    722                                 return TCL_ERROR;
    723                         }
     760                    if (Tcl_GetInt(interp, argv[n], &ivol) != TCL_OK) {
     761                        return TCL_ERROR;
     762                    }
    724763                    //volume[ivol]->set_diffuse((float)dval);
    725764                }
     
    727766            return TCL_OK;
    728767        }
    729             else if (c == 'd' && strcmp(argv[2],"diffuse") == 0) {
     768        else if (c == 'd' && strcmp(argv[2],"diffuse") == 0) {
    730769            if (argc < 4) {
    731                         Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    732                                 argv[1], " diffuse value ?volume ...?\"", (char*)NULL);
    733                         return TCL_ERROR;
     770                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     771                    argv[1], " diffuse value ?volume ...?\"", (char*)NULL);
     772                return TCL_ERROR;
    734773            }
    735774
    736775            double dval;
    737                 if (Tcl_GetDouble(interp, argv[3], &dval) != TCL_OK) {
    738                         return TCL_ERROR;
    739                 }
     776            if (Tcl_GetDouble(interp, argv[3], &dval) != TCL_OK) {
     777                return TCL_ERROR;
     778            }
    740779
    741780            int ivol;
     
    746785            } else {
    747786                for (int n=4; n < argc; n++) {
    748                         if (Tcl_GetInt(interp, argv[n], &ivol) != TCL_OK) {
    749                                 return TCL_ERROR;
    750                         }
     787                    if (Tcl_GetInt(interp, argv[n], &ivol) != TCL_OK) {
     788                        return TCL_ERROR;
     789                    }
    751790                    volume[ivol]->set_diffuse((float)dval);
    752791                }
     
    754793            return TCL_OK;
    755794        }
    756             else if (c == 'o' && strcmp(argv[2],"opacity") == 0) {
     795        else if (c == 'o' && strcmp(argv[2],"opacity") == 0) {
    757796            if (argc < 4) {
    758                         Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    759                                 argv[1], " opacity value ?volume ...?\"", (char*)NULL);
    760                         return TCL_ERROR;
     797                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     798                    argv[1], " opacity value ?volume ...?\"", (char*)NULL);
     799                return TCL_ERROR;
    761800            }
    762801
    763802            double dval;
    764                 if (Tcl_GetDouble(interp, argv[3], &dval) != TCL_OK) {
    765                         return TCL_ERROR;
    766                 }
     803            if (Tcl_GetDouble(interp, argv[3], &dval) != TCL_OK) {
     804                return TCL_ERROR;
     805            }
    767806
    768807            int ivol;
     
    773812            } else {
    774813                for (int n=4; n < argc; n++) {
    775                         if (Tcl_GetInt(interp, argv[n], &ivol) != TCL_OK) {
    776                                 return TCL_ERROR;
    777                         }
     814                    if (Tcl_GetInt(interp, argv[n], &ivol) != TCL_OK) {
     815                        return TCL_ERROR;
     816                    }
    778817                    volume[ivol]->set_opacity_scale((float)dval);
    779818                }
     
    781820            return TCL_OK;
    782821        }
    783             else if (c == 's' && strcmp(argv[2],"specular") == 0) {
     822        else if (c == 's' && strcmp(argv[2],"specular") == 0) {
    784823            if (argc < 4) {
    785                         Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    786                                 argv[1], " specular value ?volume ...?\"", (char*)NULL);
    787                         return TCL_ERROR;
     824                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     825                    argv[1], " specular value ?volume ...?\"", (char*)NULL);
     826                return TCL_ERROR;
    788827            }
    789828
    790829            double dval;
    791                 if (Tcl_GetDouble(interp, argv[3], &dval) != TCL_OK) {
    792                         return TCL_ERROR;
    793                 }
     830            if (Tcl_GetDouble(interp, argv[3], &dval) != TCL_OK) {
     831                return TCL_ERROR;
     832            }
    794833
    795834            int ivol;
     
    800839            } else {
    801840                for (int n=4; n < argc; n++) {
    802                         if (Tcl_GetInt(interp, argv[n], &ivol) != TCL_OK) {
    803                                 return TCL_ERROR;
    804                         }
     841                    if (Tcl_GetInt(interp, argv[n], &ivol) != TCL_OK) {
     842                        return TCL_ERROR;
     843                    }
    805844                    volume[ivol]->set_specular((float)dval);
    806845                }
     
    9761015    int rgbc;
    9771016    char **rgbv;
    978     if (Tcl_SplitList(interp, str, &rgbc, (const char***)&rgbv) != TCL_OK) {
     1017    if (Tcl_SplitList(interp, str, &rgbc, &rgbv) != TCL_OK) {
    9791018        return TCL_ERROR;
    9801019    }
Note: See TracChangeset for help on using the changeset viewer.