Changeset 887


Ignore:
Timestamp:
Feb 14, 2008, 2:29:02 PM (17 years ago)
Author:
gah
Message:
 
Location:
trunk/vizservers/nanovis
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/vizservers/nanovis/Command.cpp

    r886 r887  
    44 * Command.cpp
    55 *
    6  *      This modules creates the Tcl interface to the nanovis server.
    7  *      The communication protocol of the server is the Tcl language.
    8  *      Commands given to the server by clients are executed in a
    9  *      safe interpreter and the resulting image rendered offscreen
    10  *      is returned as BMP-formatted image data.
     6 *      This modules creates the Tcl interface to the nanovis server.
     7 *      The communication protocol of the server is the Tcl language.
     8 *      Commands given to the server by clients are executed in a
     9 *      safe interpreter and the resulting image rendered offscreen
     10 *      is returned as BMP-formatted image data.
    1111 *
    1212 * ======================================================================
     
    2424/*
    2525 * TODO:  In no particular order...
    26  *        o Convert to Tcl_CmdObj interface.
    27  *        o Use Tcl command option parser to reduce size of procedures, remove
    28  *          lots of extra error checking code.
    29  *        o Convert GetVolumeIndices to GetVolumes.  Goal is to remove
    30  *          all references of Nanovis::volume[] from this file.  Don't
    31  *          want to know how volumes are stored. Same for heightmaps.
    32  *        o Rationalize volume id scheme. Right now it's the index in
    33  *          the vector. 1) Use a list instead of a vector. 2) carry
    34  *          an id field that's a number that gets incremented each new volume.
    35  *        o Create R2, matrix, etc. libraries.
     26 *        o Convert to Tcl_CmdObj interface.
     27 *        o Use Tcl command option parser to reduce size of procedures, remove
     28 *          lots of extra error checking code.
     29 *        o Convert GetVolumeIndices to GetVolumes.  Goal is to remove
     30 *          all references of Nanovis::volume[] from this file.  Don't
     31 *          want to know how volumes are stored. Same for heightmaps.
     32 *        o Rationalize volume id scheme. Right now it's the index in
     33 *          the vector. 1) Use a list instead of a vector. 2) carry
     34 *          an id field that's a number that gets incremented each new volume.
     35 *        o Create R2, matrix, etc. libraries.
    3636 */
    3737
     
    8080extern vector<PointSet*> g_pointSet;
    8181
    82 extern float live_rot_x;                //object rotation angles
     82extern float live_rot_x;                //object rotation angles
    8383extern float live_rot_y;
    8484extern float live_rot_z;
    85 extern float live_obj_x;        //object translation location from the origin
     85extern float live_obj_x;        //object translation location from the origin
    8686extern float live_obj_y;
    8787extern float live_obj_z;
     
    9292extern Rappture::Outcome load_volume_stream(int index, std::iostream& fin);
    9393extern Rappture::Outcome load_volume_stream_odx(int index, const char *buf,
    94         int nBytes);
     94        int nBytes);
    9595extern Rappture::Outcome load_volume_stream2(int index, std::iostream& fin);
    9696extern void load_volume(int index, int width, int height, int depth,
    97         int n_component, float* data, double vmin, double vmax,
    98         double nzero_min);
     97        int n_component, float* data, double vmin, double vmax,
     98        double nzero_min);
    9999extern void load_vector_stream(int index, std::istream& fin);
    100100
     
    147147
    148148static int GetVolumeIndices(Tcl_Interp *interp, int argc, const char *argv[],
    149         vector<unsigned int>* vectorPtr);
     149        vector<unsigned int>* vectorPtr);
    150150static int GetVolumes(Tcl_Interp *interp, int argc, const char *argv[],
    151         vector<Volume *>* vectorPtr);
     151        vector<Volume *>* vectorPtr);
    152152static int GetVolume(Tcl_Interp *interp, const char *string,
    153         Volume **volPtrPtr);
     153        Volume **volPtrPtr);
    154154static int GetVolumeIndex(Tcl_Interp *interp, const char *string,
    155         unsigned int *indexPtr);
     155        unsigned int *indexPtr);
    156156static int GetHeightMap(Tcl_Interp *interp, const char *string,
    157         HeightMap **hmPtrPtr);
     157        HeightMap **hmPtrPtr);
    158158static int GetIndices(Tcl_Interp *interp, int argc, const char *argv[],
    159         vector<unsigned int>* vectorPtr);
     159        vector<unsigned int>* vectorPtr);
    160160static int GetAxis(Tcl_Interp *interp, const char *string, int *valPtr);
    161161static int GetColor(Tcl_Interp *interp, const char *string, float *rgbPtr);
    162162static int GetDataStream(Tcl_Interp *interp, Rappture::Buffer &buf,
    163         int nBytes);
     163        int nBytes);
    164164static HeightMap *CreateHeightMap(ClientData clientData, Tcl_Interp *interp,
    165         int argc, const char *argv[]);
     165        int argc, const char *argv[]);
    166166
    167167static int
     
    171171
    172172    if (Tcl_GetDouble(interp, string, &value) != TCL_OK) {
    173         return TCL_ERROR;
     173        return TCL_ERROR;
    174174    }
    175175    *valuePtr = (float)value;
     
    179179static int
    180180GetCullMode(Tcl_Interp *interp, const char *string,
    181             graphics::RenderContext::CullMode *modePtr)
     181            graphics::RenderContext::CullMode *modePtr)
    182182{
    183183    if (strcmp(string, "none") == 0) {
    184         *modePtr = graphics::RenderContext::NO_CULL;
     184        *modePtr = graphics::RenderContext::NO_CULL;
    185185    } else if (strcmp(string, "front") == 0) {
    186         *modePtr = graphics::RenderContext::FRONT;
     186        *modePtr = graphics::RenderContext::FRONT;
    187187    } else if (strcmp(string, "back") == 0) {
    188         *modePtr = graphics::RenderContext::BACK;
     188        *modePtr = graphics::RenderContext::BACK;
    189189    } else {
    190         Tcl_AppendResult(interp, "invalid cull mode \"", string,
    191                 "\": should be front, back, or none\"", (char *)NULL);
    192         return TCL_ERROR;
     190        Tcl_AppendResult(interp, "invalid cull mode \"", string,
     191                "\": should be front, back, or none\"", (char *)NULL);
     192        return TCL_ERROR;
    193193    }
    194194    return TCL_OK;
     
    197197static int
    198198GetShadingModel(Tcl_Interp *interp, const char *string,
    199                 graphics::RenderContext::ShadingModel *modelPtr)
     199                graphics::RenderContext::ShadingModel *modelPtr)
    200200{
    201201    if (strcmp(string,"flat") == 0) {
    202         *modelPtr = graphics::RenderContext::FLAT;
     202        *modelPtr = graphics::RenderContext::FLAT;
    203203    } else if (strcmp(string,"smooth") == 0) {
    204         *modelPtr = graphics::RenderContext::SMOOTH;
     204        *modelPtr = graphics::RenderContext::SMOOTH;
    205205    } else {
    206         Tcl_AppendResult(interp, "bad shading model \"", string,
    207                         "\": should be flat or smooth", (char *)NULL);
    208         return TCL_ERROR;
     206        Tcl_AppendResult(interp, "bad shading model \"", string,
     207                        "\": should be flat or smooth", (char *)NULL);
     208        return TCL_ERROR;
    209209    }
    210210    return TCL_OK;
     
    213213static int
    214214GetPolygonMode(Tcl_Interp *interp, const char *string,
    215                graphics::RenderContext::PolygonMode *modePtr)
     215               graphics::RenderContext::PolygonMode *modePtr)
    216216{
    217217    if (strcmp(string,"wireframe") == 0) {
    218         *modePtr = graphics::RenderContext::LINE;
     218        *modePtr = graphics::RenderContext::LINE;
    219219    } else if (strcmp(string,"fill") == 0) {
    220         *modePtr = graphics::RenderContext::FILL;
     220        *modePtr = graphics::RenderContext::FILL;
    221221    } else {
    222         Tcl_AppendResult(interp, "invalid polygon mode \"", string,
    223         "\": should be wireframe or fill\"", (char *)NULL);
    224         return TCL_ERROR;
     222        Tcl_AppendResult(interp, "invalid polygon mode \"", string,
     223        "\": should be wireframe or fill\"", (char *)NULL);
     224        return TCL_ERROR;
    225225    }
    226226    return TCL_OK;
     
    235235    /* Find the first volume. */
    236236    for (i = 0; i < NanoVis::n_volumes; i++) {
    237         if (NanoVis::volume[i] != NULL) {
    238             break;
    239         }
     237        if (NanoVis::volume[i] != NULL) {
     238            break;
     239        }
    240240    }
    241241    if (i == NanoVis::n_volumes) {
    242         Tcl_AppendResult(interp, "no volumes found", (char *)NULL);
    243         return TCL_ERROR;
     242        Tcl_AppendResult(interp, "no volumes found", (char *)NULL);
     243        return TCL_ERROR;
    244244    }
    245245    Volume *volPtr;
     
    249249    max = volPtr->range_max();
    250250    for (i++; i < NanoVis::n_volumes; i++) {
    251         if (NanoVis::volume[i] == NULL) {
    252             continue;
    253         }
    254         volPtr = NanoVis::volume[i];
    255         if (min > volPtr->range_min()) {
    256             min = volPtr->range_min();
    257         }
    258         if (max < volPtr->range_max()) {
    259             max = volPtr->range_max();
    260         }
     251        if (NanoVis::volume[i] == NULL) {
     252            continue;
     253        }
     254        volPtr = NanoVis::volume[i];
     255        if (min > volPtr->range_min()) {
     256            min = volPtr->range_min();
     257        }
     258        if (max < volPtr->range_max()) {
     259            max = volPtr->range_max();
     260        }
    261261    }
    262262    *minPtr = min;
     
    282282{
    283283    if (argc < 2) {
    284         Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    285                         " option arg arg...\"", (char*)NULL);
    286         return TCL_ERROR;
     284        Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     285                        " option arg arg...\"", (char*)NULL);
     286        return TCL_ERROR;
    287287    }
    288288
     
    290290    if ((c == 'a') && (strcmp(argv[1],"angle") == 0)) {
    291291        if (argc != 5) {
    292             Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    293                              " angle xangle yangle zangle\"", (char*)NULL);
    294             return TCL_ERROR;
     292            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     293                             " angle xangle yangle zangle\"", (char*)NULL);
     294            return TCL_ERROR;
    295295        }
    296296        double xangle, yangle, zangle;
    297         if ((Tcl_GetDouble(interp, argv[2], &xangle) != TCL_OK) ||
    298             (Tcl_GetDouble(interp, argv[3], &yangle) != TCL_OK) ||
    299             (Tcl_GetDouble(interp, argv[4], &zangle) != TCL_OK)) {
    300             return TCL_ERROR;
    301         }
    302         NanoVis::cam->rotate(xangle, yangle, zangle);
     297        if ((Tcl_GetDouble(interp, argv[2], &xangle) != TCL_OK) ||
     298            (Tcl_GetDouble(interp, argv[3], &yangle) != TCL_OK) ||
     299            (Tcl_GetDouble(interp, argv[4], &zangle) != TCL_OK)) {
     300            return TCL_ERROR;
     301        }
     302        NanoVis::cam->rotate(xangle, yangle, zangle);
    303303    } else if ((c == 'a') && (strcmp(argv[1], "aim") == 0)) {
    304304        if (argc != 5) {
    305             Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    306                              " aim x y z\"", (char*)NULL);
    307             return TCL_ERROR;
    308         }
    309        
     305            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     306                             " aim x y z\"", (char*)NULL);
     307            return TCL_ERROR;
     308        }
     309       
    310310        double x0, y0, z0;
    311         if ((Tcl_GetDouble(interp, argv[2], &x0) != TCL_OK) ||
    312             (Tcl_GetDouble(interp, argv[3], &y0) != TCL_OK) ||
    313             (Tcl_GetDouble(interp, argv[4], &z0) != TCL_OK)) {
    314             return TCL_ERROR;
    315         }
    316         NanoVis::cam->aim(x0, y0, z0);
     311        if ((Tcl_GetDouble(interp, argv[2], &x0) != TCL_OK) ||
     312            (Tcl_GetDouble(interp, argv[3], &y0) != TCL_OK) ||
     313            (Tcl_GetDouble(interp, argv[4], &z0) != TCL_OK)) {
     314            return TCL_ERROR;
     315        }
     316        NanoVis::cam->aim(x0, y0, z0);
    317317    } else if ((c == 'z') && (strcmp(argv[1],"zoom") == 0)) {
    318318        if (argc != 3) {
    319             Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    320                              " zoom factor\"", (char*)NULL);
    321             return TCL_ERROR;
    322         }
    323        
     319            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     320                             " zoom factor\"", (char*)NULL);
     321            return TCL_ERROR;
     322        }
     323       
    324324        double zoom;
    325         if (Tcl_GetDouble(interp, argv[2], &zoom) != TCL_OK) {
    326             return TCL_ERROR;
    327         }
    328         NanoVis::zoom(zoom);
     325        if (Tcl_GetDouble(interp, argv[2], &zoom) != TCL_OK) {
     326            return TCL_ERROR;
     327        }
     328        NanoVis::zoom(zoom);
    329329    } else {
    330         Tcl_AppendResult(interp, "bad camera option \"", argv[1],
    331                      "\": should be aim, angle, or zoom", (char*)NULL);
    332         return TCL_ERROR;
     330        Tcl_AppendResult(interp, "bad camera option \"", argv[1],
     331                     "\": should be aim, angle, or zoom", (char*)NULL);
     332        return TCL_ERROR;
    333333    }
    334334
     
    349349static int
    350350ScreenShotCmd(ClientData cdata, Tcl_Interp *interp, int argc,
    351               const char *argv[])
     351              const char *argv[])
    352352{
    353353#ifdef XINETD
     
    372372        Texture2D* plane = new Texture2D(256, 2, GL_FLOAT, GL_LINEAR, 1, data);
    373373        NanoVis::color_table_renderer->render(1024, 1024, plane, tf, vol->range_min(),
    374                 vol->range_max());
     374                vol->range_max());
    375375        delete plane;
    376376   
     
    399399static int
    400400CutplaneCmd(ClientData cdata, Tcl_Interp *interp, int argc,
    401             const char *argv[])
     401            const char *argv[])
    402402{
    403403    if (argc < 2) {
     
    429429            return TCL_ERROR;
    430430        }
    431         if (state) {
    432             vector<Volume *>::iterator iter;
    433             for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     431        if (state) {
     432            vector<Volume *>::iterator iter;
     433            for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    434434                (*iter)->enable_cutplane(axis);
    435             }
    436         } else {
    437             vector<Volume *>::iterator iter;
    438             for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     435            }
     436        } else {
     437            vector<Volume *>::iterator iter;
     438            for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    439439                (*iter)->disable_cutplane(axis);
    440             }
     440            }
    441441        }
    442442    } else if ((c == 'p') && (strcmp(argv[1],"position") == 0)) {
     
    454454        // keep this just inside the volume so it doesn't disappear
    455455        if (relval < 0.01f) {
    456             relval = 0.01f;
    457         } else if (relval > 0.99f) {
    458             relval = 0.99f;
    459         }
     456            relval = 0.01f;
     457        } else if (relval > 0.99f) {
     458            relval = 0.99f;
     459        }
    460460
    461461        int axis;
     
    468468            return TCL_ERROR;
    469469        }
    470         vector<Volume *>::iterator iter;
    471         for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     470        vector<Volume *>::iterator iter;
     471        for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    472472            (*iter)->move_cutplane(axis, relval);
    473473        }
    474474    } else {
    475         Tcl_AppendResult(interp, "bad option \"", argv[1],
    476                         "\": should be position or state", (char*)NULL);
    477         return TCL_ERROR;
     475        Tcl_AppendResult(interp, "bad option \"", argv[1],
     476                        "\": should be position or state", (char*)NULL);
     477        return TCL_ERROR;
    478478    }
    479479    return TCL_OK;
     
    508508    if (tf == NULL) {
    509509        Tcl_AppendResult(interp, "no transfer function defined for volume \"",
    510                 argv[1], "\"", (char*)NULL);
     510                argv[1], "\"", (char*)NULL);
    511511        return TCL_ERROR;
    512512    }
     
    514514    int width, height;
    515515    if ((Tcl_GetInt(interp, argv[2], &width) != TCL_OK) ||
    516         (Tcl_GetInt(interp, argv[3], &height) != TCL_OK)) {
     516        (Tcl_GetInt(interp, argv[3], &height) != TCL_OK)) {
    517517        return TCL_ERROR;
    518518    }
    519519    float vmin, vmax;
    520520    if (GetVolumeLimits(interp, &vmin, &vmax) != TCL_OK) {
    521         return TCL_ERROR;
     521        return TCL_ERROR;
    522522    }
    523523    NanoVis::render_legend(tf, vmin, vmax, width, height, argv[1]);
     
    566566static int
    567567TransfuncCmd(ClientData cdata, Tcl_Interp *interp, int argc,
    568              const char *argv[])
     568             const char *argv[])
    569569{
    570570    if (argc < 2) {
    571         Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    572                         " option arg arg...\"", (char*)NULL);
    573         return TCL_ERROR;
     571        Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     572                        " option arg arg...\"", (char*)NULL);
     573        return TCL_ERROR;
    574574    }
    575575
     
    577577    if ((c == 'd') && (strcmp(argv[1],"define") == 0)) {
    578578        if (argc != 5) {
    579             Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    580                 " define name colormap alphamap\"", (char*)NULL);
     579            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     580                " define name colormap alphamap\"", (char*)NULL);
    581581            return TCL_ERROR;
    582582        }
     
    586586        int cmapc, wmapc, i;
    587587        const char **cmapv;
    588         const char **wmapv;
    589 
    590         wmapv = cmapv = NULL;
     588        const char **wmapv;
     589
     590        wmapv = cmapv = NULL;
    591591        if (Tcl_SplitList(interp, argv[3], &cmapc, &cmapv) != TCL_OK) {
    592592            return TCL_ERROR;
    593593        }
    594594        if ((cmapc % 4) != 0) {
    595             Tcl_AppendResult(interp, "bad colormap in transfunc: should be ",
     595            Tcl_AppendResult(interp, "bad colormap in transfunc: should be ",
    596596                "{ v r g b ... }", (char*)NULL);
    597             Tcl_Free((char*)cmapv);
    598             return TCL_ERROR;
     597            Tcl_Free((char*)cmapv);
     598            return TCL_ERROR;
    599599        }
    600600
    601601        if (Tcl_SplitList(interp, argv[4], &wmapc, &wmapv) != TCL_OK) {
    602             Tcl_Free((char*)cmapv);
    603             return TCL_ERROR;
     602            Tcl_Free((char*)cmapv);
     603            return TCL_ERROR;
    604604        }
    605605        if ((wmapc % 2) != 0) {
    606             Tcl_AppendResult(interp, "wrong # elements in alphamap: should be ",
    607                         " { v w ... }", (char*)NULL);
    608             Tcl_Free((char*)cmapv);
    609             Tcl_Free((char*)wmapv);
    610             return TCL_ERROR;
     606            Tcl_AppendResult(interp, "wrong # elements in alphamap: should be ",
     607                        " { v w ... }", (char*)NULL);
     608            Tcl_Free((char*)cmapv);
     609            Tcl_Free((char*)wmapv);
     610            return TCL_ERROR;
    611611        }
    612612        for (i=0; i < cmapc; i += 4) {
    613             int j;
     613            int j;
    614614            double vals[4];
    615615
    616616            for (j=0; j < 4; j++) {
    617617                if (Tcl_GetDouble(interp, cmapv[i+j], &vals[j]) != TCL_OK) {
    618                     Tcl_Free((char*)cmapv);
    619                     Tcl_Free((char*)wmapv);
    620                     return TCL_ERROR;
     618                    Tcl_Free((char*)cmapv);
     619                    Tcl_Free((char*)wmapv);
     620                    return TCL_ERROR;
    621621                }
    622622                if ((vals[j] < 0.0) || (vals[j] > 1.0)) {
    623                     Tcl_AppendResult(interp, "bad value \"", cmapv[i+j],
     623                    Tcl_AppendResult(interp, "bad value \"", cmapv[i+j],
    624624                        "\": should be in the range 0-1", (char*)NULL);
    625                     Tcl_Free((char*)cmapv);
    626                     Tcl_Free((char*)wmapv);
    627                     return TCL_ERROR;
     625                    Tcl_Free((char*)cmapv);
     626                    Tcl_Free((char*)wmapv);
     627                    return TCL_ERROR;
    628628                }
    629629            }
     
    634634        for (i=0; i < wmapc; i += 2) {
    635635            double vals[2];
    636             int j;
     636            int j;
    637637
    638638            for (j=0; j < 2; j++) {
    639639                if (Tcl_GetDouble(interp, wmapv[i+j], &vals[j]) != TCL_OK) {
    640                     Tcl_Free((char*)cmapv);
    641                     Tcl_Free((char*)wmapv);
    642                     return TCL_ERROR;
     640                    Tcl_Free((char*)cmapv);
     641                    Tcl_Free((char*)wmapv);
     642                    return TCL_ERROR;
    643643                }
    644644                if ((vals[j] < 0.0) || (vals[j] > 1.0)) {
    645                     Tcl_AppendResult(interp, "bad value \"", wmapv[i+j],
     645                    Tcl_AppendResult(interp, "bad value \"", wmapv[i+j],
    646646                        "\": should be in the range 0-1", (char*)NULL);
    647                     Tcl_Free((char*)cmapv);
    648                     Tcl_Free((char*)wmapv);
    649                     return TCL_ERROR;
     647                    Tcl_Free((char*)cmapv);
     648                    Tcl_Free((char*)wmapv);
     649                    return TCL_ERROR;
    650650                }
    651651            }
     
    668668        // find or create this transfer function
    669669        TransferFunction *tf;
    670         tf = NanoVis::get_transfunc(argv[2]);
    671         if (tf != NULL) {
    672             tf->update(data);
    673         } else {
    674             tf = NanoVis::set_transfunc(argv[2], nslots, data);
    675         }
     670        tf = NanoVis::get_transfunc(argv[2]);
     671        if (tf != NULL) {
     672            tf->update(data);
     673        } else {
     674            tf = NanoVis::set_transfunc(argv[2], nslots, data);
     675        }
    676676    } else {
    677         Tcl_AppendResult(interp, "bad option \"", argv[1],
    678                 "\": should be define", (char*)NULL);
    679         return TCL_ERROR;
     677        Tcl_AppendResult(interp, "bad option \"", argv[1],
     678                "\": should be define", (char*)NULL);
     679        return TCL_ERROR;
    680680    }
    681681    return TCL_OK;
     
    763763                return TCL_ERROR;
    764764            }
    765             vector<Volume *>::iterator iter;
    766             for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     765            vector<Volume *>::iterator iter;
     766            for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    767767                (*iter)->set_label(axis, argv[4]);
    768768            }
    769769        } else {
    770             Tcl_AppendResult(interp, "bad option \"", argv[2],
    771                 "\": should be label", (char*)NULL);
    772             return TCL_ERROR;
    773         }
     770            Tcl_AppendResult(interp, "bad option \"", argv[2],
     771                "\": should be label", (char*)NULL);
     772            return TCL_ERROR;
     773        }
    774774    } else if ((c == 'd') && (strcmp(argv[1],"data") == 0)) {
    775775        if (argc < 3) {
     
    793793                return TCL_ERROR;
    794794            }
    795             if (state) {
    796                 vector<Volume *>::iterator iter;
    797                 for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    798                     (*iter)->enable_data();
    799                 }
    800             } else {
    801                 vector<Volume *>::iterator iter;
    802                 for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    803                     (*iter)->disable_data();
    804                 }
    805             }
     795            if (state) {
     796                vector<Volume *>::iterator iter;
     797                for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     798                    (*iter)->enable_data();
     799                }
     800            } else {
     801                vector<Volume *>::iterator iter;
     802                for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     803                    (*iter)->disable_data();
     804                }
     805            }
    806806        } else if (c == 'f' && strcmp(argv[2], "follows") == 0) {
    807807            if (argc < 4) {
     
    817817                return TCL_ERROR;
    818818            }
    819            
    820             Rappture::Buffer buf;
    821             if (GetDataStream(interp, buf, nbytes) != TCL_OK) {
    822                 return TCL_ERROR;
    823             }
     819           
     820            Rappture::Buffer buf;
     821            if (GetDataStream(interp, buf, nbytes) != TCL_OK) {
     822                return TCL_ERROR;
     823            }
    824824            int n = NanoVis::n_volumes;
    825825            char header[6];
     
    831831            FILE* fp;
    832832
    833             fp = fopen("/home/nanohub/vrinside/nv/data/HOON/GaAs_AlGaAs_2QD_B4.nd_zc_1_wf", "rb");
     833            fp = fopen("/home/nanohub/vrinside/nv/data/HOON/GaAs_AlGaAs_2QD_B4.nd_zc_1_wf", "rb");
    834834            if (fp == NULL) {
    835835                printf("cannot open the file\n");
     
    840840            fread(b, buf.size(), 1, fp);
    841841            fclose(fp);
    842 #endif  /*_LOCAL_ZINC_TEST_*/
     842#endif  /*_LOCAL_ZINC_TEST_*/
    843843            printf("Checking header[%s]\n", header);
    844844            fflush(stdout);
     
    856856#else
    857857                vol = NvZincBlendeReconstructor::getInstance()->loadFromMemory((void*) buf.bytes());
    858 #endif  /*_LOCAL_ZINC_TEST_*/
     858#endif  /*_LOCAL_ZINC_TEST_*/
    859859
    860860                printf("finish loading\n");
     
    892892                }
    893893*/
    894 #endif  /*__TEST_CODE__*/
    895             } else if (strcmp(header, "<ODX>") == 0) {
    896                 Rappture::Outcome err;
     894#endif  /*__TEST_CODE__*/
     895            } else if (strcmp(header, "<ODX>") == 0) {
     896                Rappture::Outcome err;
    897897
    898898                printf("Loading DX using OpenDX library...\n");
     
    905905                }
    906906            } else {
    907                 Rappture::Outcome err;
     907                Rappture::Outcome err;
    908908
    909909                printf("OpenDX loading...\n");
     
    936936            }
    937937
    938             {
    939                 Volume *volPtr;
    940                 char info[1024];
    941                 float vmin, vmax;
    942 
    943                 if (GetVolumeLimits(interp, &vmin, &vmax) != TCL_OK) {
    944                     return TCL_ERROR;
    945                 }
    946                 volPtr = NanoVis::volume[n];
    947                 sprintf(info, "nv>data id %d min %g max %g vmin %g vmax %g\n",
    948                         n, volPtr->range_min(), volPtr->range_max(),vmin, vmax);
    949                 write(0, info, strlen(info));
    950             }
     938            {
     939                Volume *volPtr;
     940                char info[1024];
     941                float vmin, vmax;
     942
     943                if (GetVolumeLimits(interp, &vmin, &vmax) != TCL_OK) {
     944                    return TCL_ERROR;
     945                }
     946                volPtr = NanoVis::volume[n];
     947                sprintf(info, "nv>data id %d min %g max %g vmin %g vmax %g\n",
     948                        n, volPtr->range_min(), volPtr->range_max(),vmin, vmax);
     949                write(0, info, strlen(info));
     950            }
    951951        } else {
    952             Tcl_AppendResult(interp, "bad data option \"", argv[2],
    953                 "\": should be follows or state", (char*)NULL);
    954             return TCL_ERROR;
    955         }
     952            Tcl_AppendResult(interp, "bad data option \"", argv[2],
     953                "\": should be follows or state", (char*)NULL);
     954            return TCL_ERROR;
     955        }
    956956    } else if (c == 'o' && strcmp(argv[1],"outline") == 0) {
    957957        if (argc < 3) {
     
    976976                return TCL_ERROR;
    977977            }
    978             if (state) {
    979                 vector<Volume *>::iterator iter;
    980                 for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     978            if (state) {
     979                vector<Volume *>::iterator iter;
     980                for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    981981                    (*iter)->enable_outline();
    982                 }
    983             } else {
    984                 vector<Volume *>::iterator iter;
    985                 for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     982                }
     983            } else {
     984                vector<Volume *>::iterator iter;
     985                for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    986986                    (*iter)->disable_outline();
    987                 }
     987                }
    988988            }
    989989        } else if (c == 'v' && strcmp(argv[2],"visible") == 0) {
    990             int ivisible;
    991 
    992             if (Tcl_GetBoolean(interp, argv[3], &ivisible) != TCL_OK) {
    993                 return TCL_ERROR;
    994             }           
     990            int ivisible;
     991
     992            if (Tcl_GetBoolean(interp, argv[3], &ivisible) != TCL_OK) {
     993                return TCL_ERROR;
     994            }           
    995995            if (!ivisible) {
    996996                for (int i = 0; i < NanoVis::n_volumes; ++i) {
    997997                    if (NanoVis::volume[i]) {
    998                         NanoVis::volume[i]->disable_outline();
    999                     }
     998                        NanoVis::volume[i]->disable_outline();
     999                    }
    10001000                }
    10011001            } else {
    10021002                for (int i = 0; i < NanoVis::n_volumes; ++i) {
    10031003                    if (NanoVis::volume[i]) {
    1004                         NanoVis::volume[i]->enable_outline();
    1005                     }
     1004                        NanoVis::volume[i]->enable_outline();
     1005                    }
    10061006                }
    10071007            }
     
    10261026        }
    10271027        else {
    1028             Tcl_AppendResult(interp, "bad outline option \"", argv[2],
    1029                 "\": should be color, visible, or state", (char*)NULL);
    1030             return TCL_ERROR;
    1031         }
     1028            Tcl_AppendResult(interp, "bad outline option \"", argv[2],
     1029                "\": should be color, visible, or state", (char*)NULL);
     1030            return TCL_ERROR;
     1031        }
    10321032    } else if ((c == 's') && (strcmp(argv[1],"shading") == 0)) {
    10331033        if (argc < 3) {
     
    10401040            if (argc < 4) {
    10411041                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1042                     " shading transfunc name ?volume ...?\"", (char*)NULL);
     1042                    " shading transfunc name ?volume ...?\"", (char*)NULL);
    10431043                return TCL_ERROR;
    10441044            }
    10451045            TransferFunction *tf;
    1046             tf = NanoVis::get_transfunc(argv[3]);
     1046            tf = NanoVis::get_transfunc(argv[3]);
    10471047            if (tf == NULL) {
    10481048                Tcl_AppendResult(interp, "transfer function \"", argv[3],
     
    10551055            }
    10561056            vector<Volume *>::iterator iter;
    1057             for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     1057            for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    10581058                NanoVis::vol_renderer->shade_volume(*iter, tf);
    10591059                // TBD..
     
    10681068            if (argc < 4) {
    10691069                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1070                     " shading diffuse value ?volume ...?\"", (char*)NULL);
     1070                    " shading diffuse value ?volume ...?\"", (char*)NULL);
    10711071                return TCL_ERROR;
    10721072            }
     
    11261126                return TCL_ERROR;
    11271127            }
    1128             int iso_surface = 0;
    1129             if (Tcl_GetBoolean(interp, argv[3], &iso_surface) != TCL_OK) {
    1130                 return TCL_ERROR;
    1131             }
     1128            int iso_surface = 0;
     1129            if (Tcl_GetBoolean(interp, argv[3], &iso_surface) != TCL_OK) {
     1130                return TCL_ERROR;
     1131            }
    11321132            vector<Volume *> ivol;
    11331133            if (GetVolumes(interp, argc-4, argv+4, &ivol) != TCL_OK) {
     
    11381138                (*iter)->set_isosurface(iso_surface);
    11391139            }
    1140         } else {
    1141             Tcl_AppendResult(interp, "bad shading option \"", argv[2],
    1142                 "\": should be diffuse, opacity, specular, transfunc, or ",
    1143                 "isosurface", (char*)NULL);
    1144             return TCL_ERROR;
    1145         }
     1140        } else {
     1141            Tcl_AppendResult(interp, "bad shading option \"", argv[2],
     1142                "\": should be diffuse, opacity, specular, transfunc, or ",
     1143                "isosurface", (char*)NULL);
     1144            return TCL_ERROR;
     1145        }
    11461146    } else if ((c == 's') && (strcmp(argv[1], "state") == 0)) {
    11471147        if (argc < 3) {
     
    11581158            return TCL_ERROR;
    11591159        }
    1160         if (state) {
    1161             vector<Volume *>::iterator iter;
    1162             for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     1160        if (state) {
     1161            vector<Volume *>::iterator iter;
     1162            for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    11631163                (*iter)->enable();
    1164             }
    1165         } else {
    1166             vector<Volume *>::iterator iter;
    1167             for (iter = ivol.begin(); iter != ivol.end(); iter++) {
     1164            }
     1165        } else {
     1166            vector<Volume *>::iterator iter;
     1167            for (iter = ivol.begin(); iter != ivol.end(); iter++) {
    11681168                (*iter)->disable();
    11691169            }
    1170         }
     1170        }
    11711171    }
    11721172    else if (strcmp(argv[1],"animation") == 0) {
     
    12011201        return TCL_OK;
    12021202    } else {
    1203         Tcl_AppendResult(interp, "bad option \"", argv[1], "\": should be ",
    1204                 "data, outline, shading, or state", (char*)NULL);
    1205         return TCL_ERROR;
     1203        Tcl_AppendResult(interp, "bad option \"", argv[1], "\": should be ",
     1204                "data, outline, shading, or state", (char*)NULL);
     1205        return TCL_ERROR;
    12061206    }
    12071207    return TCL_OK;
     
    12141214
    12151215    if (argc < 2) {
    1216         Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1217                         " option ?arg arg?", (char *)NULL);
    1218         return TCL_ERROR;
     1216        Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1217                        " option ?arg arg?", (char *)NULL);
     1218        return TCL_ERROR;
    12191219    }
    12201220    char c = argv[1][0];
    12211221    if ((c == 'v') && (strcmp(argv[1], "vectorid") == 0)) {
    1222         if (argc != 3) {
    1223             Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1224                 " vectorid volume", (char *)NULL);
    1225             return TCL_ERROR;
    1226         }
     1222        if (argc != 3) {
     1223            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1224                " vectorid volume", (char *)NULL);
     1225            return TCL_ERROR;
     1226        }
    12271227        Volume *volPtr;
    12281228
    12291229        if (GetVolume(interp, argv[2], &volPtr) != TCL_OK) {
    1230             return TCL_ERROR;
     1230            return TCL_ERROR;
    12311231        }
    12321232        if (NanoVis::particleRenderer != NULL) {
     
    12351235                volPtr->depth  / (float)volPtr->width,
    12361236                volPtr->range_max());
    1237             NanoVis::initParticle();
     1237            NanoVis::initParticle();
    12381238        }
    12391239        if (NanoVis::licRenderer != NULL) {
     
    12511251            return TCL_ERROR;
    12521252        }
    1253         int ibool;
    1254         if (Tcl_GetBoolean(interp, argv[2], &ibool) != TCL_OK) {
    1255             return TCL_ERROR;
    1256         }
    1257         NanoVis::lic_on = (bool)ibool;
     1253        int ibool;
     1254        if (Tcl_GetBoolean(interp, argv[2], &ibool) != TCL_OK) {
     1255            return TCL_ERROR;
     1256        }
     1257        NanoVis::lic_on = (bool)ibool;
    12581258    } else if ((c == 'p') && (strcmp(argv[1], "particle") == 0)) {
    12591259        if (argc < 3) {
    12601260            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1261                 " particle visible|slice|slicepos arg \"", (char*)NULL);
    1262             return TCL_ERROR;
    1263         }
    1264         c = argv[2][0];
    1265         if ((c == 'v') && (strcmp(argv[2], "visible") == 0)) {
    1266             if (argc != 4) {
    1267                 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1268                         " particle visible on|off\"", (char*)NULL);
    1269                 return TCL_ERROR;
    1270             }
    1271             int state;
    1272             if (Tcl_GetBoolean(interp, argv[2], &state) != TCL_OK) {
    1273                 return TCL_ERROR;
    1274             }
    1275             NanoVis::particle_on = state;
    1276         } else if ((c == 's') && (strcmp(argv[2], "slice") == 0)) {
    1277             if (argc != 4) {
    1278                 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1279                         " particle slice volume\"", (char*)NULL);
    1280                 return TCL_ERROR;
    1281             }
    1282             int axis;
    1283             if (GetAxis(interp, argv[3], &axis) != TCL_OK) {
    1284                 return TCL_ERROR;
    1285             }
    1286             NanoVis::lic_axis = axis;
    1287         } else if ((c == 's') && (strcmp(argv[2], "slicepos") == 0)) {
    1288             if (argc != 4) {
    1289                 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1290                         " particle slicepos value\"", (char*)NULL);
    1291                 return TCL_ERROR;
    1292             }
    1293             float pos;
    1294             if (GetFloat(interp, argv[2], &pos) != TCL_OK) {
    1295                 return TCL_ERROR;
    1296             }
    1297             if (pos < 0.0f) {
    1298                 pos = 0.0f;
    1299             } else if (pos > 1.0f) {
    1300                 pos = 1.0f;
    1301             }
    1302             switch (NanoVis::lic_axis) {
    1303             case 0 :
    1304                 NanoVis::lic_slice_x = pos;
    1305                 break;
    1306             case 1 :
    1307                 NanoVis::lic_slice_y = pos;
    1308                 break;
    1309             case 2 :
    1310                 NanoVis::lic_slice_z = pos;
    1311                 break;
    1312             }
    1313         } else {
    1314             Tcl_AppendResult(interp, "unknown option \"", argv[2],
    1315                 "\": should be \"", argv[0], " visible, slice, or slicepos\"",
    1316                 (char *)NULL);
    1317             return TCL_ERROR;
    1318         }
     1261                " particle visible|slice|slicepos arg \"", (char*)NULL);
     1262            return TCL_ERROR;
     1263        }
     1264        c = argv[2][0];
     1265        if ((c == 'v') && (strcmp(argv[2], "visible") == 0)) {
     1266            if (argc != 4) {
     1267                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1268                        " particle visible on|off\"", (char*)NULL);
     1269                return TCL_ERROR;
     1270            }
     1271            int state;
     1272            if (Tcl_GetBoolean(interp, argv[2], &state) != TCL_OK) {
     1273                return TCL_ERROR;
     1274            }
     1275            NanoVis::particle_on = state;
     1276        } else if ((c == 's') && (strcmp(argv[2], "slice") == 0)) {
     1277            if (argc != 4) {
     1278                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1279                        " particle slice volume\"", (char*)NULL);
     1280                return TCL_ERROR;
     1281            }
     1282            int axis;
     1283            if (GetAxis(interp, argv[3], &axis) != TCL_OK) {
     1284                return TCL_ERROR;
     1285            }
     1286            NanoVis::lic_axis = axis;
     1287        } else if ((c == 's') && (strcmp(argv[2], "slicepos") == 0)) {
     1288            if (argc != 4) {
     1289                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1290                        " particle slicepos value\"", (char*)NULL);
     1291                return TCL_ERROR;
     1292            }
     1293            float pos;
     1294            if (GetFloat(interp, argv[2], &pos) != TCL_OK) {
     1295                return TCL_ERROR;
     1296            }
     1297            if (pos < 0.0f) {
     1298                pos = 0.0f;
     1299            } else if (pos > 1.0f) {
     1300                pos = 1.0f;
     1301            }
     1302            switch (NanoVis::lic_axis) {
     1303            case 0 :
     1304                NanoVis::lic_slice_x = pos;
     1305                break;
     1306            case 1 :
     1307                NanoVis::lic_slice_y = pos;
     1308                break;
     1309            case 2 :
     1310                NanoVis::lic_slice_z = pos;
     1311                break;
     1312            }
     1313        } else {
     1314            Tcl_AppendResult(interp, "unknown option \"", argv[2],
     1315                "\": should be \"", argv[0], " visible, slice, or slicepos\"",
     1316                (char *)NULL);
     1317            return TCL_ERROR;
     1318        }
    13191319    } else if ((c == 'r') && (strcmp(argv[1],"reset") == 0)) {
    1320         NanoVis::initParticle();
     1320        NanoVis::initParticle();
    13211321    } else if ((c == 'c') && (strcmp(argv[1],"capture") == 0)) {
    13221322        if (argc != 3) {
    13231323            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1324                 " capture numframes\"", (char*)NULL);
    1325             return TCL_ERROR;
    1326         }
    1327         int total_frame_count;
    1328 
    1329         if (Tcl_GetInt(interp, argv[2], &total_frame_count) != TCL_OK) {
    1330             return TCL_ERROR;
    1331         }
     1324                " capture numframes\"", (char*)NULL);
     1325            return TCL_ERROR;
     1326        }
     1327        int total_frame_count;
     1328
     1329        if (Tcl_GetInt(interp, argv[2], &total_frame_count) != TCL_OK) {
     1330            return TCL_ERROR;
     1331        }
    13321332        if (NanoVis::licRenderer) {
    1333             NanoVis::licRenderer->activate();
    1334         }
     1333            NanoVis::licRenderer->activate();
     1334        }
    13351335        if (NanoVis::particleRenderer) {
    1336             NanoVis::particleRenderer->activate();
    1337         }
    1338         // Karl
    1339         for (int frame_count = 0; frame_count < total_frame_count;
    1340              frame_count++) {
    1341            
    1342             // Generate the latest frame and send it back to the client
    1343             if (NanoVis::licRenderer &&
    1344                 NanoVis::licRenderer->isActivated()) {
    1345                 NanoVis::licRenderer->convolve();               
    1346             }
    1347             if (NanoVis::particleRenderer &&
    1348                 NanoVis::particleRenderer->isActivated()) {
    1349                 NanoVis::particleRenderer->advect();
    1350             }
    1351             NanoVis::offscreen_buffer_capture();  //enable offscreen render
    1352             NanoVis::display();
    1353            
    1354             //          printf("Read Screen for Writing to file...\n");
    1355            
    1356             NanoVis::read_screen();
    1357             glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    1358            
    1359             NanoVis::bmp_write_to_file(frame_count);
    1360             //          printf("Writing to file...\n");
    1361         }
    1362         // put your code...
     1336            NanoVis::particleRenderer->activate();
     1337        }
     1338        // Karl
     1339        for (int frame_count = 0; frame_count < total_frame_count;
     1340             frame_count++) {
     1341           
     1342            // Generate the latest frame and send it back to the client
     1343            if (NanoVis::licRenderer &&
     1344                NanoVis::licRenderer->isActivated()) {
     1345                NanoVis::licRenderer->convolve();               
     1346            }
     1347            if (NanoVis::particleRenderer &&
     1348                NanoVis::particleRenderer->isActivated()) {
     1349                NanoVis::particleRenderer->advect();
     1350            }
     1351            NanoVis::offscreen_buffer_capture();  //enable offscreen render
     1352            NanoVis::display();
     1353           
     1354            //          printf("Read Screen for Writing to file...\n");
     1355           
     1356            NanoVis::read_screen();
     1357            glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     1358           
     1359            NanoVis::bmp_write_to_file(frame_count);
     1360            //          printf("Writing to file...\n");
     1361        }
     1362        // put your code...
    13631363        if (NanoVis::licRenderer) {
    1364             NanoVis::licRenderer->deactivate();
    1365         }
     1364            NanoVis::licRenderer->deactivate();
     1365        }
    13661366        if (NanoVis::particleRenderer) {
    1367             NanoVis::particleRenderer->deactivate();
    1368         }
     1367            NanoVis::particleRenderer->deactivate();
     1368        }
    13691369        NanoVis::initParticle();
    13701370    } else if (c == 'd' && strcmp(argv[1],"data") == 0) {
    1371         if (argc < 3) {
    1372             Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1373                 " data follows ?args?", (char *)NULL);
    1374             return TCL_ERROR;
    1375         }
    1376         c = argv[2][0];
     1371        if (argc < 3) {
     1372            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1373                " data follows ?args?", (char *)NULL);
     1374            return TCL_ERROR;
     1375        }
     1376        c = argv[2][0];
    13771377        if ((c == 'f') && (strcmp(argv[2],"follows") == 0)) {
    1378             if (argc != 4) {
    1379                 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1380                                 " data follows length", (char *)NULL);
    1381                 return TCL_ERROR;
    1382             }
     1378            if (argc != 4) {
     1379                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1380                                " data follows length", (char *)NULL);
     1381                return TCL_ERROR;
     1382            }
    13831383            int nbytes;
    13841384            if (Tcl_GetInt(interp, argv[3], &nbytes) != TCL_OK) {
    13851385                return TCL_ERROR;
    13861386            }
    1387             Rappture::Buffer buf;
    1388             if (GetDataStream(interp, buf, nbytes) != TCL_OK) {
    1389                 return TCL_ERROR;
    1390             }
     1387            Rappture::Buffer buf;
     1388            if (GetDataStream(interp, buf, nbytes) != TCL_OK) {
     1389                return TCL_ERROR;
     1390            }
    13911391            int n = NanoVis::n_volumes;
    13921392            std::stringstream fdata;
    13931393            fdata.write(buf.bytes(),buf.size());
    13941394            load_vector_stream(n, fdata);
    1395             Volume *volPtr = NanoVis::volume[n];
     1395            Volume *volPtr = NanoVis::volume[n];
    13961396
    13971397            //
     
    14101410
    14111411                NanoVis::vol_renderer->add_volume(volPtr,
    1412                         NanoVis::get_transfunc("default"));
     1412                        NanoVis::get_transfunc("default"));
    14131413            }
    14141414        }
     
    14211421static int
    14221422HeightMapCmd(ClientData cdata, Tcl_Interp *interp, int argc,
    1423              const char *argv[])
     1423             const char *argv[])
    14241424{
    14251425    if (argc < 2) {
    1426         srand((unsigned)time(NULL));
    1427         int size = 20 * 200;
    1428         double sigma = 5.0;
    1429         double mean = exp(0.0) / (sigma * sqrt(2.0));
    1430         float* data = (float*) malloc(sizeof(float) * size);
    1431        
    1432         float x;
    1433         for (int i = 0; i < size; ++i) {
    1434             x = - 10 + i%20;
    1435             data[i] = exp(- (x * x)/(2 * sigma * sigma)) /
    1436                 (sigma * sqrt(2.0)) / mean * 2 + 1000;
    1437         }
    1438 
    1439         HeightMap* heightMap = new HeightMap();
    1440         float minx = 0.0f;
    1441         float maxx = 1.0f;
    1442         float miny = 0.5f;
    1443         float maxy = 3.5f;
    1444         heightMap->setHeight(minx, miny, maxx, maxy, 20, 200, data);
    1445         heightMap->setColorMap(NanoVis::get_transfunc("default"));
    1446         heightMap->setVisible(true);
    1447         heightMap->setLineContourVisible(true);
    1448         NanoVis::heightMap.push_back(heightMap);
    1449 
    1450 
    1451         Vector3 min(minx, (float) heightMap->range_min(), miny);
    1452         Vector3 max(maxx, (float) heightMap->range_max(), maxy);
    1453        
    1454         NanoVis::grid->setMinMax(min, max);
    1455         NanoVis::grid->setVisible(true);
    1456        
    1457         return TCL_OK;
     1426        srand((unsigned)time(NULL));
     1427        int size = 20 * 200;
     1428        double sigma = 5.0;
     1429        double mean = exp(0.0) / (sigma * sqrt(2.0));
     1430        float* data = (float*) malloc(sizeof(float) * size);
     1431       
     1432        float x;
     1433        for (int i = 0; i < size; ++i) {
     1434            x = - 10 + i%20;
     1435            data[i] = exp(- (x * x)/(2 * sigma * sigma)) /
     1436                (sigma * sqrt(2.0)) / mean * 2 + 1000;
     1437        }
     1438
     1439        HeightMap* heightMap = new HeightMap();
     1440        float minx = 0.0f;
     1441        float maxx = 1.0f;
     1442        float miny = 0.5f;
     1443        float maxy = 3.5f;
     1444        heightMap->setHeight(minx, miny, maxx, maxy, 20, 200, data);
     1445        heightMap->setColorMap(NanoVis::get_transfunc("default"));
     1446        heightMap->setVisible(true);
     1447        heightMap->setLineContourVisible(true);
     1448        NanoVis::heightMap.push_back(heightMap);
     1449
     1450
     1451        Vector3 min(minx, (float) heightMap->range_min(), miny);
     1452        Vector3 max(maxx, (float) heightMap->range_max(), maxy);
     1453       
     1454        NanoVis::grid->setMinMax(min, max);
     1455        NanoVis::grid->setVisible(true);
     1456       
     1457        return TCL_OK;
    14581458    }
    14591459   
    14601460    char c = argv[1][0];
    14611461    if ((c == 'c') && (strcmp(argv[1], "create") == 0)) {
    1462         HeightMap *hMap;
    1463 
    1464         /* heightmap create xmin ymin xmax ymax xnum ynum values */
    1465         hMap = CreateHeightMap(cdata, interp, argc - 2, argv + 2);
    1466         if (hMap == NULL) {
    1467             return TCL_ERROR;
    1468         }
    1469         NanoVis::heightMap.push_back(hMap);
    1470         /* FIXME: Convert this file to use Tcl_CmdObjProc */
    1471         sprintf(interp->result, "%d", NanoVis::heightMap.size() - 1);
    1472         return TCL_OK;
     1462        HeightMap *hMap;
     1463
     1464        /* heightmap create xmin ymin xmax ymax xnum ynum values */
     1465        hMap = CreateHeightMap(cdata, interp, argc - 2, argv + 2);
     1466        if (hMap == NULL) {
     1467            return TCL_ERROR;
     1468        }
     1469        NanoVis::heightMap.push_back(hMap);
     1470        /* FIXME: Convert this file to use Tcl_CmdObjProc */
     1471        sprintf(interp->result, "%d", NanoVis::heightMap.size() - 1);
     1472        return TCL_OK;
    14731473    } else if ((c == 'd') && (strcmp(argv[1],"data") == 0)) {
    1474         if (argc < 3) {
    1475             Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1476                 " data follows|visible ?args?", (char *)NULL);
    1477             return TCL_ERROR;
    1478         }
     1474        if (argc < 3) {
     1475            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1476                " data follows|visible ?args?", (char *)NULL);
     1477            return TCL_ERROR;
     1478        }
    14791479        //bytes
    14801480        char c;
    1481         c = argv[2][0];
     1481        c = argv[2][0];
    14821482        if ((c == 'v') && (strcmp(argv[2],"visible") == 0)) {
    1483             if (argc < 4) {
    1484                 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1485                         " data visible bool ?indices?", (char *)NULL);
    1486                 return TCL_ERROR;
    1487             }
    1488             int ivisible;
    1489             vector<unsigned int> indices;
    1490 
    1491             if (Tcl_GetBoolean(interp, argv[3], &ivisible) != TCL_OK) {
    1492                 return TCL_ERROR;
    1493             }
     1483            if (argc < 4) {
     1484                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1485                        " data visible bool ?indices?", (char *)NULL);
     1486                return TCL_ERROR;
     1487            }
     1488            int ivisible;
     1489            vector<unsigned int> indices;
     1490
     1491            if (Tcl_GetBoolean(interp, argv[3], &ivisible) != TCL_OK) {
     1492                return TCL_ERROR;
     1493            }
    14941494            if (GetIndices(interp, argc-4, argv+4, &indices) != TCL_OK) {
    14951495               return TCL_ERROR;
    14961496            }
    1497             bool visible;
    1498             visible = (bool)ivisible;
     1497            bool visible;
     1498            visible = (bool)ivisible;
    14991499            for (unsigned int i = 0; i < indices.size(); ++i) {
    15001500                if ((indices[i] < NanoVis::heightMap.size()) &&
    1501                     (NanoVis::heightMap[indices[i]] != NULL)) {
     1501                    (NanoVis::heightMap[indices[i]] != NULL)) {
    15021502                    NanoVis::heightMap[indices[i]]->setVisible(visible);
    15031503                }
    15041504            }
    15051505        } else if ((c == 'f') && (strcmp(argv[2],"follows") == 0)) {
    1506             if (argc != 4) {
    1507                 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1508                         " data follow length", (char *)NULL);
    1509                 return TCL_ERROR;
    1510             }
    1511             Rappture::Buffer buf;
     1506            if (argc != 4) {
     1507                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1508                        " data follow length", (char *)NULL);
     1509                return TCL_ERROR;
     1510            }
     1511            Rappture::Buffer buf;
    15121512            int nBytes;
    15131513
     
    15151515                return TCL_ERROR;
    15161516            }
    1517             if (GetDataStream(interp, buf, nBytes) != TCL_OK) {
    1518                 return TCL_ERROR;
    1519             }
    1520             buf.append("\0", 1);
    1521             if (Tcl_Eval(interp, buf.bytes()) != TCL_OK) {
    1522                 fprintf(stderr, "error in command: %s\n",
    1523                         Tcl_GetStringResult(interp));
    1524                 fflush(stderr);
    1525                 return TCL_ERROR;
    1526             }
     1517            if (GetDataStream(interp, buf, nBytes) != TCL_OK) {
     1518                return TCL_ERROR;
     1519            }
     1520            buf.append("\0", 1);
     1521            if (Tcl_Eval(interp, buf.bytes()) != TCL_OK) {
     1522                fprintf(stderr, "error in command: %s\n",
     1523                        Tcl_GetStringResult(interp));
     1524                fflush(stderr);
     1525                return TCL_ERROR;
     1526            }
    15271527        } else {
    1528             Tcl_AppendResult(interp, "unknown option \"", argv[2], "\": ",
    1529                              "should be visible or follows", (char *)NULL);
    1530             return TCL_ERROR;
    1531         }
     1528            Tcl_AppendResult(interp, "unknown option \"", argv[2], "\": ",
     1529                             "should be visible or follows", (char *)NULL);
     1530            return TCL_ERROR;
     1531        }
    15321532    } else if ((c == 'l') && (strcmp(argv[1], "linecontour") == 0)) {
    1533         if (argc < 3) {
    1534             Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1535                 " linecontour visible|color ?args?", (char *)NULL);
    1536             return TCL_ERROR;
    1537         }
     1533        if (argc < 3) {
     1534            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1535                " linecontour visible|color ?args?", (char *)NULL);
     1536            return TCL_ERROR;
     1537        }
    15381538        vector<unsigned int> indices;
    1539         char c;
    1540         c = argv[2][0];
     1539        char c;
     1540        c = argv[2][0];
    15411541        if ((c == 'v') && (strcmp(argv[2],"visible") == 0)) {
    1542             if (argc < 4) {
    1543                 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1544                         " linecontour visible boolean ?indices?", (char *)NULL);
    1545                 return TCL_ERROR;
    1546             }
    1547             int ivisible;
    1548             bool visible;
    1549             if (Tcl_GetBoolean(interp, argv[3], &ivisible) != TCL_OK) {
    1550                 return TCL_ERROR;
    1551             }
     1542            if (argc < 4) {
     1543                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1544                        " linecontour visible boolean ?indices?", (char *)NULL);
     1545                return TCL_ERROR;
     1546            }
     1547            int ivisible;
     1548            bool visible;
     1549            if (Tcl_GetBoolean(interp, argv[3], &ivisible) != TCL_OK) {
     1550                return TCL_ERROR;
     1551            }
    15521552            visible = (bool)ivisible;
    15531553            if (GetIndices(interp, argc-4, argv+4, &indices) != TCL_OK) {
     
    15561556            for (unsigned int i = 0; i < indices.size(); ++i) {
    15571557                if ((indices[i] < NanoVis::heightMap.size()) &&
    1558                     (NanoVis::heightMap[indices[i]] != NULL)) {
     1558                    (NanoVis::heightMap[indices[i]] != NULL)) {
    15591559                    NanoVis::heightMap[indices[i]]->setLineContourVisible(visible);
    15601560                }
    15611561            }
    15621562        } else if ((c == 'c') && (strcmp(argv[2],"color") == 0)) {
    1563             if (argc < 6) {
    1564                 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1565                         " linecontour color r g b ?indices?", (char *)NULL);
    1566                 return TCL_ERROR;
    1567             }
     1563            if (argc < 6) {
     1564                Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1565                        " linecontour color r g b ?indices?", (char *)NULL);
     1566                return TCL_ERROR;
     1567            }
    15681568            float r, g, b;
    15691569            if ((GetFloat(interp, argv[3], &r) != TCL_OK) ||
     
    15711571                (GetFloat(interp, argv[5], &b) != TCL_OK)) {
    15721572                return TCL_ERROR;
    1573             }           
     1573            }           
    15741574            vector<unsigned int> indices;
    15751575            if (GetIndices(interp, argc-6, argv+6, &indices) != TCL_OK) {
     
    15781578            for (unsigned int i = 0; i < indices.size(); ++i) {
    15791579                if ((indices[i] < NanoVis::heightMap.size()) &&
    1580                     (NanoVis::heightMap[indices[i]] != NULL)) {
     1580                    (NanoVis::heightMap[indices[i]] != NULL)) {
    15811581                    NanoVis::heightMap[indices[i]]->setLineContourColor(r, g, b);
    15821582                }
    15831583            }
    15841584        } else {
    1585             Tcl_AppendResult(interp, "unknown option \"", argv[2], "\": ",
    1586                              "should be visible or color", (char *)NULL);
    1587             return TCL_ERROR;
    1588         }
     1585            Tcl_AppendResult(interp, "unknown option \"", argv[2], "\": ",
     1586                             "should be visible or color", (char *)NULL);
     1587            return TCL_ERROR;
     1588        }
    15891589    } else if ((c == 't') && (strcmp(argv[1], "transfunc") == 0)) {
    1590         if (argc < 3) {
    1591             Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1592                 " transfunc name ?indices?", (char *)NULL);
    1593             return TCL_ERROR;
    1594         }
     1590        if (argc < 3) {
     1591            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1592                " transfunc name ?indices?", (char *)NULL);
     1593            return TCL_ERROR;
     1594        }
    15951595        TransferFunction *tf;
    15961596
    1597         tf = NanoVis::get_transfunc(argv[2]);
     1597        tf = NanoVis::get_transfunc(argv[2]);
    15981598        if (tf == NULL) {
    15991599            Tcl_AppendResult(interp, "transfer function \"", argv[2],
     
    16031603        vector<unsigned int> indices;
    16041604        if (GetIndices(interp, argc - 3, argv + 3, &indices) != TCL_OK) {
    1605                 return TCL_ERROR;
    1606         }
    1607         for (unsigned int i = 0; i < indices.size(); ++i) {
    1608             if ((indices[i] < NanoVis::heightMap.size()) &&
    1609                 (NanoVis::heightMap[indices[i]] != NULL)) {
    1610                 NanoVis::heightMap[indices[i]]->setColorMap(tf);
    1611             }
     1605                return TCL_ERROR;
     1606        }
     1607        for (unsigned int i = 0; i < indices.size(); ++i) {
     1608            if ((indices[i] < NanoVis::heightMap.size()) &&
     1609                (NanoVis::heightMap[indices[i]] != NULL)) {
     1610                NanoVis::heightMap[indices[i]]->setColorMap(tf);
     1611            }
    16121612        }
    16131613    } else if ((c == 'l') && (strcmp(argv[1], "legend") == 0)) {
    1614         if (argc != 5) {
    1615             Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1616                              " legend index width height\"", (char*)NULL);
    1617             return TCL_ERROR;
    1618         }
    1619         HeightMap *hMap;
    1620         if (GetHeightMap(interp, argv[2], &hMap) != TCL_OK) {
    1621             return TCL_ERROR;
    1622         }
    1623         TransferFunction *tf;
    1624         tf = hMap->getColorMap();
    1625         if (tf == NULL) {
    1626             Tcl_AppendResult(interp,
    1627                 "no transfer function defined for heightmap \"", argv[1], "\"",
    1628                 (char*)NULL);
    1629             return TCL_ERROR;
    1630         }
    1631         int width, height;
    1632         if ((Tcl_GetInt(interp, argv[3], &width) != TCL_OK) ||
    1633             (Tcl_GetInt(interp, argv[4], &height) != TCL_OK)) {
    1634             return TCL_ERROR;
    1635         }
    1636         NanoVis::render_legend(tf, hMap->range_min(), hMap->range_max(),
    1637                 width, height, argv[1]);
     1614        if (argc != 5) {
     1615            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1616                             " legend index width height\"", (char*)NULL);
     1617            return TCL_ERROR;
     1618        }
     1619        HeightMap *hMap;
     1620        if (GetHeightMap(interp, argv[2], &hMap) != TCL_OK) {
     1621            return TCL_ERROR;
     1622        }
     1623        TransferFunction *tf;
     1624        tf = hMap->getColorMap();
     1625        if (tf == NULL) {
     1626            Tcl_AppendResult(interp,
     1627                "no transfer function defined for heightmap \"", argv[1], "\"",
     1628                (char*)NULL);
     1629            return TCL_ERROR;
     1630        }
     1631        int width, height;
     1632        if ((Tcl_GetInt(interp, argv[3], &width) != TCL_OK) ||
     1633            (Tcl_GetInt(interp, argv[4], &height) != TCL_OK)) {
     1634            return TCL_ERROR;
     1635        }
     1636        NanoVis::render_legend(tf, hMap->range_min(), hMap->range_max(),
     1637                width, height, argv[1]);
    16381638    } else if ((c == 'p') && (strcmp(argv[1], "polygon") == 0)) {
    1639         if (argc != 3) {
    1640             Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1641                 " polygon mode", (char *)NULL);
    1642             return TCL_ERROR;
    1643         }
    1644         graphics::RenderContext::PolygonMode mode;
    1645         if (GetPolygonMode(interp, argv[2], &mode) != TCL_OK) {
    1646             return TCL_ERROR;
    1647         }
    1648         NanoVis::renderContext->setPolygonMode(mode);
     1639        if (argc != 3) {
     1640            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1641                " polygon mode", (char *)NULL);
     1642            return TCL_ERROR;
     1643        }
     1644        graphics::RenderContext::PolygonMode mode;
     1645        if (GetPolygonMode(interp, argv[2], &mode) != TCL_OK) {
     1646            return TCL_ERROR;
     1647        }
     1648        NanoVis::renderContext->setPolygonMode(mode);
    16491649    } else if ((c == 'c') && (strcmp(argv[1], "cull") == 0)) {
    1650         if (argc != 3) {
    1651             Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1652                 " cull mode", (char *)NULL);
    1653             return TCL_ERROR;
    1654         }
    1655         graphics::RenderContext::CullMode mode;
    1656         if (GetCullMode(interp, argv[2], &mode) != TCL_OK) {
    1657             return TCL_ERROR;
    1658         }
    1659         NanoVis::renderContext->setCullMode(mode);
     1650        if (argc != 3) {
     1651            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1652                " cull mode", (char *)NULL);
     1653            return TCL_ERROR;
     1654        }
     1655        graphics::RenderContext::CullMode mode;
     1656        if (GetCullMode(interp, argv[2], &mode) != TCL_OK) {
     1657            return TCL_ERROR;
     1658        }
     1659        NanoVis::renderContext->setCullMode(mode);
    16601660    } else if ((c == 's') && (strcmp(argv[1], "shade") == 0)) {
    1661         if (argc != 3) {
    1662             Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1663                 " shade model", (char *)NULL);
    1664             return TCL_ERROR;
    1665         }
    1666         graphics::RenderContext::ShadingModel model;
    1667         if (GetShadingModel(interp, argv[2], &model) != TCL_OK) {
    1668             return TCL_ERROR;
    1669         }
    1670         NanoVis::renderContext->setShadingModel(model);
     1661        if (argc != 3) {
     1662            Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1663                " shade model", (char *)NULL);
     1664            return TCL_ERROR;
     1665        }
     1666        graphics::RenderContext::ShadingModel model;
     1667        if (GetShadingModel(interp, argv[2], &model) != TCL_OK) {
     1668            return TCL_ERROR;
     1669        }
     1670        NanoVis::renderContext->setShadingModel(model);
    16711671    } else {
    1672         Tcl_AppendResult(interp, "bad option \"", argv[1],
    1673                 "\": should be data, linecontour, legend, or transfunc", (char*)NULL);
    1674         return TCL_ERROR;
     1672        Tcl_AppendResult(interp, "bad option \"", argv[1],
     1673                "\": should be data, linecontour, legend, or transfunc", (char*)NULL);
     1674        return TCL_ERROR;
    16751675    }
    16761676    return TCL_OK;
     
    16811681{
    16821682    if (argc < 2) {
    1683         Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    1684                         " option ?args?", (char *)NULL);
    1685         return TCL_ERROR;
     1683        Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     1684                        " option ?args?", (char *)NULL);
     1685        return TCL_ERROR;
    16861686    }
    16871687    char c = argv[1][0];
    16881688    if ((c == 'v') && (strcmp(argv[1],"visible") == 0)) {
    1689         int ivisible;
    1690 
    1691         if (Tcl_GetBoolean(interp, argv[2], &ivisible) != TCL_OK) {
    1692             return TCL_ERROR;
    1693         }
    1694         NanoVis::grid->setVisible((bool)ivisible);
     1689        int ivisible;
     1690
     1691        if (Tcl_GetBoolean(interp, argv[2], &ivisible) != TCL_OK) {
     1692            return TCL_ERROR;
     1693        }
     1694        NanoVis::grid->setVisible((bool)ivisible);
    16951695    } else if ((c == 'l') && (strcmp(argv[1],"linecount") == 0)) {
    16961696        int x, y, z;
     
    16991699            (Tcl_GetInt(interp, argv[3], &y) != TCL_OK) ||
    17001700            (Tcl_GetInt(interp, argv[4], &z) != TCL_OK)) {
    1701             return TCL_ERROR;
    1702         }
    1703         if (NanoVis::grid) {
    1704             NanoVis::grid->setGridLineCount(x, y, z);
    1705         }
     1701            return TCL_ERROR;
     1702        }
     1703        if (NanoVis::grid) {
     1704            NanoVis::grid->setGridLineCount(x, y, z);
     1705        }
    17061706    } else if ((c == 'a') && (strcmp(argv[1],"axiscolor") == 0)) {
    17071707        float r, g, b, a;
     
    17091709            (GetFloat(interp, argv[3], &g) != TCL_OK) ||
    17101710            (GetFloat(interp, argv[4], &b) != TCL_OK)) {
    1711             return TCL_ERROR;
    1712         }
    1713         a = 1.0f;
    1714         if ((argc == 6) && (GetFloat(interp, argv[5], &a) != TCL_OK)) {
    1715             return TCL_ERROR;
    1716         }          
    1717         if (NanoVis::grid) {
    1718             NanoVis::grid->setAxisColor(r, g, b, a);
    1719         }
     1711            return TCL_ERROR;
     1712        }
     1713        a = 1.0f;
     1714        if ((argc == 6) && (GetFloat(interp, argv[5], &a) != TCL_OK)) {
     1715            return TCL_ERROR;
     1716        }          
     1717        if (NanoVis::grid) {
     1718            NanoVis::grid->setAxisColor(r, g, b, a);
     1719        }
    17201720    } else if ((c == 'l') && (strcmp(argv[1],"linecolor") == 0)) {
    17211721        float r, g, b, a;
    17221722        if ((GetFloat(interp, argv[2], &r) != TCL_OK) ||
    17231723            (GetFloat(interp, argv[3], &g) != TCL_OK) ||
    1724             (GetFloat(interp, argv[4], &b) != TCL_OK)) {
    1725             return TCL_ERROR;
    1726         }
    1727         a = 1.0f;
    1728         if ((argc == 6) && (GetFloat(interp, argv[5], &a) != TCL_OK)) {
    1729             return TCL_ERROR;
    1730         }          
    1731         if (NanoVis::grid) {
    1732             NanoVis::grid->setGridLineColor(r, g, b, a);
    1733         }
     1724            (GetFloat(interp, argv[4], &b) != TCL_OK)) {
     1725            return TCL_ERROR;
     1726        }
     1727        a = 1.0f;
     1728        if ((argc == 6) && (GetFloat(interp, argv[5], &a) != TCL_OK)) {
     1729            return TCL_ERROR;
     1730        }          
     1731        if (NanoVis::grid) {
     1732            NanoVis::grid->setGridLineColor(r, g, b, a);
     1733        }
    17341734    } else if ((c == 'm') && (strcmp(argv[1],"minmax") == 0)) {
    1735         double x1, y1, z1, x2, y2, z2;
    1736         if ((Tcl_GetDouble(interp, argv[2], &x1) != TCL_OK) ||
    1737             (Tcl_GetDouble(interp, argv[3], &y1) != TCL_OK) ||
    1738             (Tcl_GetDouble(interp, argv[4], &z1) != TCL_OK) ||
    1739             (Tcl_GetDouble(interp, argv[5], &x2) != TCL_OK) ||
    1740             (Tcl_GetDouble(interp, argv[6], &y2) != TCL_OK) ||
    1741             (Tcl_GetDouble(interp, argv[7], &z2) != TCL_OK)) {
    1742             return TCL_ERROR;
    1743         }
    1744         if (NanoVis::grid) {
    1745             NanoVis::grid->setMinMax(Vector3(x1, y1, z1), Vector3(x2, y2, z2));
    1746         }
     1735        double x1, y1, z1, x2, y2, z2;
     1736        if ((Tcl_GetDouble(interp, argv[2], &x1) != TCL_OK) ||
     1737            (Tcl_GetDouble(interp, argv[3], &y1) != TCL_OK) ||
     1738            (Tcl_GetDouble(interp, argv[4], &z1) != TCL_OK) ||
     1739            (Tcl_GetDouble(interp, argv[5], &x2) != TCL_OK) ||
     1740            (Tcl_GetDouble(interp, argv[6], &y2) != TCL_OK) ||
     1741            (Tcl_GetDouble(interp, argv[7], &z2) != TCL_OK)) {
     1742            return TCL_ERROR;
     1743        }
     1744        if (NanoVis::grid) {
     1745            NanoVis::grid->setMinMax(Vector3(x1, y1, z1), Vector3(x2, y2, z2));
     1746        }
    17471747    } else if ((c == 'a') && (strcmp(argv[1],"axisname") == 0)) {
    17481748        int axisId;
    1749         if (GetAxis(interp, argv[2], &axisId) != TCL_OK) {
    1750             return TCL_ERROR;
    1751         }
     1749        if (GetAxis(interp, argv[2], &axisId) != TCL_OK) {
     1750            return TCL_ERROR;
     1751        }
    17521752        if (NanoVis::grid) {
    1753             NanoVis::grid->setAxisName(axisId, argv[3]);
    1754         }
     1753            NanoVis::grid->setAxisName(axisId, argv[3]);
     1754        }
    17551755    } else {
    1756         Tcl_AppendResult(interp, "bad option \"", argv[1],
    1757                         "\": should be data, outline, shading, or state",
    1758                         (char*)NULL);
    1759         return TCL_ERROR;
     1756        Tcl_AppendResult(interp, "bad option \"", argv[1],
     1757                        "\": should be data, outline, shading, or state",
     1758                        (char*)NULL);
     1759        return TCL_ERROR;
    17601760    }
    17611761    return TCL_OK;
     
    17721772    char c = argv[1][0];
    17731773    if ((c == 'v') && (strcmp(argv[1],"visible") == 0)) {
    1774         int ivisible;
    1775 
    1776         if (Tcl_GetBoolean(interp, argv[2], &ivisible) != TCL_OK) {
    1777             return TCL_ERROR;
    1778         }
    1779         NanoVis::axis_on = (bool)ivisible;
     1774        int ivisible;
     1775
     1776        if (Tcl_GetBoolean(interp, argv[2], &ivisible) != TCL_OK) {
     1777            return TCL_ERROR;
     1778        }
     1779        NanoVis::axis_on = (bool)ivisible;
    17801780    } else {
    1781         Tcl_AppendResult(interp, "bad axis option \"", argv[1],
    1782                         "\": should be visible", (char*)NULL);
    1783         return TCL_ERROR;
     1781        Tcl_AppendResult(interp, "bad axis option \"", argv[1],
     1782                        "\": should be visible", (char*)NULL);
     1783        return TCL_ERROR;
    17841784    }
    17851785    return TCL_OK;
     
    18041804    int mapIndex;
    18051805    if (Tcl_GetInt(interp, string, &mapIndex) != TCL_OK) {
    1806         return TCL_ERROR;
     1806        return TCL_ERROR;
    18071807    }
    18081808    if ((mapIndex < 0) || (mapIndex >= (int)NanoVis::heightMap.size()) ||
    1809         (NanoVis::heightMap[mapIndex] == NULL)) {
    1810         Tcl_AppendResult(interp, "invalid heightmap index \"", string, "\"",
    1811                         (char *)NULL);
    1812         return TCL_ERROR;
     1809        (NanoVis::heightMap[mapIndex] == NULL)) {
     1810        Tcl_AppendResult(interp, "invalid heightmap index \"", string, "\"",
     1811                        (char *)NULL);
     1812        return TCL_ERROR;
    18131813    }
    18141814    *hmPtrPtr = NanoVis::heightMap[mapIndex];
     
    18341834    int index;
    18351835    if (Tcl_GetInt(interp, string, &index) != TCL_OK) {
    1836         return TCL_ERROR;
     1836        return TCL_ERROR;
    18371837    }
    18381838    if (index < 0) {
    1839         Tcl_AppendResult(interp, "can't have negative index \"", string,
    1840                         "\"", (char*)NULL);
    1841         return TCL_ERROR;
     1839        Tcl_AppendResult(interp, "can't have negative index \"", string,
     1840                        "\"", (char*)NULL);
     1841        return TCL_ERROR;
    18421842    }
    18431843    if (index >= (int)NanoVis::volume.size()) {
    1844         Tcl_AppendResult(interp, "index \"", string,
    1845                         "\" is out of range", (char*)NULL);
    1846         return TCL_ERROR;
     1844        Tcl_AppendResult(interp, "index \"", string,
     1845                        "\" is out of range", (char*)NULL);
     1846        return TCL_ERROR;
    18471847    }
    18481848    *indexPtr = (unsigned int)index;
     
    18681868    unsigned int index;
    18691869    if (GetVolumeIndex(interp, string, &index) != TCL_OK) {
    1870         return TCL_ERROR;
     1870        return TCL_ERROR;
    18711871    }
    18721872    Volume *vol;
    18731873    vol = NanoVis::volume[index];
    18741874    if (vol == NULL) {
    1875         Tcl_AppendResult(interp, "no volume defined for index \"", string,
    1876                         "\"", (char*)NULL);
    1877         return TCL_ERROR;
     1875        Tcl_AppendResult(interp, "no volume defined for index \"", string,
     1876                        "\"", (char*)NULL);
     1877        return TCL_ERROR;
    18781878    }
    18791879    *volPtrPtr = vol;
     
    19061906    } else {
    19071907        for (int n = 0; n < argc; n++) {
    1908             unsigned int index;
    1909 
    1910             if (GetVolumeIndex(interp, argv[n], &index) != TCL_OK) {
    1911                 return TCL_ERROR;
    1912             }
     1908            unsigned int index;
     1909
     1910            if (GetVolumeIndex(interp, argv[n], &index) != TCL_OK) {
     1911                return TCL_ERROR;
     1912            }
    19131913            if (NanoVis::volume[index] != NULL) {
    19141914                vectorPtr->push_back(index);
     
    19241924{
    19251925    for (int n = 0; n < argc; n++) {
    1926         int index;
     1926        int index;
    19271927
    19281928        if (Tcl_GetInt(interp, argv[n], &index) != TCL_OK) {
    19291929            return TCL_ERROR;
    19301930        }
    1931         if (index < 0) {
    1932             Tcl_AppendResult(interp, "can't have negative index \"", argv[n],
    1933                              "\"", (char *)NULL);
    1934             return TCL_ERROR;
    1935         }
     1931        if (index < 0) {
     1932            Tcl_AppendResult(interp, "can't have negative index \"", argv[n],
     1933                             "\"", (char *)NULL);
     1934            return TCL_ERROR;
     1935        }
    19361936        vectorPtr->push_back((unsigned int)index);
    19371937    }
     
    19651965    } else {
    19661966        for (int n = 0; n < argc; n++) {
    1967             Volume *volPtr;
    1968 
    1969             if (GetVolume(interp, argv[n], &volPtr) != TCL_OK) {
    1970                 return TCL_ERROR;
    1971             }
     1967            Volume *volPtr;
     1968
     1969            if (GetVolume(interp, argv[n], &volPtr) != TCL_OK) {
     1970                return TCL_ERROR;
     1971            }
    19721972            if (volPtr != NULL) {
    19731973                vectorPtr->push_back(volPtr);
     
    19921992{
    19931993    if (string[1] == '\0') {
    1994         char c;
    1995 
    1996         c = tolower((unsigned char)string[0]);
    1997         if (c == 'x') {
    1998             *valPtr = 0;
    1999             return TCL_OK;
    2000         } else if (c == 'y') {
    2001             *valPtr = 1;
    2002             return TCL_OK;
    2003         } else if (c == 'z') {
    2004             *valPtr = 2;
    2005             return TCL_OK;
    2006         }
    2007         /*FALLTHRU*/
     1994        char c;
     1995
     1996        c = tolower((unsigned char)string[0]);
     1997        if (c == 'x') {
     1998            *valPtr = 0;
     1999            return TCL_OK;
     2000        } else if (c == 'y') {
     2001            *valPtr = 1;
     2002            return TCL_OK;
     2003        } else if (c == 'z') {
     2004            *valPtr = 2;
     2005            return TCL_OK;
     2006        }
     2007        /*FALLTHRU*/
    20082008    }
    20092009    Tcl_AppendResult(interp, "bad axis \"", string,
    2010         "\": should be x, y, or z", (char*)NULL);
     2010        "\": should be x, y, or z", (char*)NULL);
    20112011    return TCL_ERROR;
    20122012}
     
    20372037    }
    20382038    if ((GetFloat(interp, argv[0], rgbPtr + 0) != TCL_OK) ||
    2039         (GetFloat(interp, argv[1], rgbPtr + 1) != TCL_OK) ||
    2040         (GetFloat(interp, argv[2], rgbPtr + 2) != TCL_OK)) {
     2039        (GetFloat(interp, argv[1], rgbPtr + 1) != TCL_OK) ||
     2040        (GetFloat(interp, argv[2], rgbPtr + 2) != TCL_OK)) {
    20412041        Tcl_Free((char*)argv);
    20422042        return TCL_ERROR;
     
    20492049static int
    20502050PlaneNewCmd(ClientData cdata, Tcl_Interp *interp, int argc,
    2051             const char *argv[])
     2051            const char *argv[])
    20522052{
    20532053    fprintf(stderr, "load plane for 2D visualization command\n");
     
    20562056   
    20572057    if (argc != 4) {
    2058         Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    2059                         " plane_index w h \"", (char*)NULL);
    2060         return TCL_ERROR;
     2058        Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     2059                        " plane_index w h \"", (char*)NULL);
     2060        return TCL_ERROR;
    20612061    }
    20622062    if (Tcl_GetInt(interp, argv[1], &index) != TCL_OK) {
    2063         return TCL_ERROR;
     2063        return TCL_ERROR;
    20642064    }
    20652065    if (Tcl_GetInt(interp, argv[2], &w) != TCL_OK) {
    2066         return TCL_ERROR;
     2066        return TCL_ERROR;
    20672067    }
    20682068    if (Tcl_GetInt(interp, argv[3], &h) != TCL_OK) {
    2069         return TCL_ERROR;
     2069        return TCL_ERROR;
    20702070    }
    20712071   
     
    20732073    char* tmp = new char[int(w*h*sizeof(float))];
    20742074    if (tmp == NULL) {
    2075         Tcl_AppendResult(interp, "can't allocate stream data", (char *)NULL);
    2076         return TCL_ERROR;
     2075        Tcl_AppendResult(interp, "can't allocate stream data", (char *)NULL);
     2076        return TCL_ERROR;
    20772077    }
    20782078    bzero(tmp, w*h*4);
    20792079    int status = read(0, tmp, w*h*sizeof(float));
    20802080    if (status <= 0) {
    2081         exit(0);                // Bail out on read error?  Should log the
    2082                                 // error and return a non-zero exit status.
     2081        exit(0);                // Bail out on read error?  Should log the
     2082                                // error and return a non-zero exit status.
    20832083    }
    20842084    plane[index] = new Texture2D(w, h, GL_FLOAT, GL_LINEAR, 1, (float*)tmp);
     
    20902090static int
    20912091PlaneLinkCmd(ClientData cdata, Tcl_Interp *interp, int argc,
    2092              const char *argv[])
     2092             const char *argv[])
    20932093{
    20942094    fprintf(stderr, "link the plane to the 2D renderer command\n");
     
    20972097   
    20982098    if (argc != 3) {
    2099         Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    2100                         " plane_index tf_index \"", (char*)NULL);
    2101         return TCL_ERROR;
     2099        Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     2100                        " plane_index tf_index \"", (char*)NULL);
     2101        return TCL_ERROR;
    21022102    }
    21032103    if (Tcl_GetInt(interp, argv[1], &plane_index) != TCL_OK) {
    2104         return TCL_ERROR;
     2104        return TCL_ERROR;
    21052105    }
    21062106    if (Tcl_GetInt(interp, argv[2], &tf_index) != TCL_OK) {
    2107         return TCL_ERROR;
     2107        return TCL_ERROR;
    21082108    }
    21092109    //plane_render->add_plane(plane[plane_index], tf[tf_index]);
     
    21152115static int
    21162116PlaneEnableCmd(ClientData cdata, Tcl_Interp *interp, int argc,
    2117                const char *argv[])
     2117               const char *argv[])
    21182118{
    21192119    fprintf(stderr,"enable a plane so the 2D renderer can render it command\n");
    21202120   
    21212121    if (argc != 3) {
    2122         Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    2123                         " plane_index mode \"", (char*)NULL);
    2124         return TCL_ERROR;
     2122        Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
     2123                        " plane_index mode \"", (char*)NULL);
     2124        return TCL_ERROR;
    21252125    }
    21262126    int plane_index;
    21272127    if (Tcl_GetInt(interp, argv[1], &plane_index) != TCL_OK) {
    2128         return TCL_ERROR;
     2128        return TCL_ERROR;
    21292129    }
    21302130    int mode;
    21312131    if (Tcl_GetInt(interp, argv[2], &mode) != TCL_OK) {
    2132         return TCL_ERROR;
     2132        return TCL_ERROR;
    21332133    }
    21342134    if (mode == 0) {
    2135         plane_index = -1;
     2135        plane_index = -1;
    21362136    }
    21372137    plane_render->set_active_plane(plane_index);
     
    23252325    write(0, &sizes, sizeof(sizes));
    23262326    write(0, offsets, offsets_size*sizeof(offsets[0]));
    2327     write(0, rle, rle_size);    //unsigned byte
     2327    write(0, rle, rle_size);    //unsigned byte
    23282328#else
    23292329    NanoVis::bmp_write("nv>image -bytes");
     
    23372337 * GetDataStream --
    23382338 *
    2339  *      Read the requested number of bytes from standard input into the given
    2340  *      buffer.  The buffer is then decompressed and decoded.
     2339 *      Read the requested number of bytes from standard input into the given
     2340 *      buffer.  The buffer is then decompressed and decoded.
    23412341 *
    23422342 * -----------------------------------------------------------------------
     
    23492349    clearerr(stdin);
    23502350    while (nBytes > 0) {
    2351         unsigned int chunk;
    2352         int nRead;
    2353 
    2354         chunk = (sizeof(buffer) < (unsigned int) nBytes) ?
    2355             sizeof(buffer) : nBytes;
    2356         nRead = fread(buffer, sizeof(char), chunk, stdin);
    2357         if (ferror(stdin)) {
     2351        unsigned int chunk;
     2352        int nRead;
     2353
     2354        chunk = (sizeof(buffer) < (unsigned int) nBytes) ?
     2355            sizeof(buffer) : nBytes;
     2356        nRead = fread(buffer, sizeof(char), chunk, stdin);
     2357        if (ferror(stdin)) {
    23582358            Tcl_AppendResult(interp, "while reading data stream: ",
    2359                 Tcl_PosixError(interp), (char*)NULL);
    2360             return TCL_ERROR;
    2361         }
    2362         if (feof(stdin)) {
     2359                Tcl_PosixError(interp), (char*)NULL);
     2360            return TCL_ERROR;
     2361        }
     2362        if (feof(stdin)) {
    23632363            Tcl_AppendResult(interp, "premature EOF while reading data stream",
    2364                 (char*)NULL);
    2365             return TCL_ERROR;
    2366         }
    2367         buf.append(buffer, nRead);
    2368         nBytes -= nRead;
     2364                (char*)NULL);
     2365            return TCL_ERROR;
     2366        }
     2367        buf.append(buffer, nRead);
     2368        nBytes -= nRead;
    23692369    }
    23702370    {
    2371         Rappture::Outcome err;
    2372 
    2373         err = Rappture::encoding::decode(buf, RPENC_Z|RPENC_B64|RPENC_HDR);
    2374         if (err) {
    2375             printf("ERROR -- DECODING\n");
    2376             fflush(stdout);
    2377             Tcl_AppendResult(interp, err.remark().c_str(), (char*)NULL);
    2378             return TCL_ERROR;
    2379         }
     2371        Rappture::Outcome err;
     2372
     2373        err = Rappture::encoding::decode(buf, RPENC_Z|RPENC_B64|RPENC_HDR);
     2374        if (err) {
     2375            printf("ERROR -- DECODING\n");
     2376            fflush(stdout);
     2377            Tcl_AppendResult(interp, err.remark().c_str(), (char*)NULL);
     2378            return TCL_ERROR;
     2379        }
    23802380    }
    23812381    return TCL_OK;
     
    23872387 * CreateHeightMap --
    23882388 *
    2389  *      Creates a heightmap from the given the data. The format of the data
    2390  *      should be as follows:
    2391  *
    2392  *              xMin, xMax, xNum, yMin, yMax, yNum, heights...
    2393  *
    2394  *      xNum and yNum must be integer values, all others are real numbers.
    2395  *      The number of heights must be xNum * yNum;
     2389 *      Creates a heightmap from the given the data. The format of the data
     2390 *      should be as follows:
     2391 *
     2392 *              xMin, xMax, xNum, yMin, yMax, yNum, heights...
     2393 *
     2394 *      xNum and yNum must be integer values, all others are real numbers.
     2395 *      The number of heights must be xNum * yNum;
    23962396 *
    23972397 * -----------------------------------------------------------------------
     
    23992399static HeightMap *
    24002400CreateHeightMap(ClientData clientData, Tcl_Interp *interp, int argc,
    2401         const char *argv[])
     2401        const char *argv[])
    24022402{
    24032403    float xMin, yMin, xMax, yMax;
     
    24052405
    24062406    if (argc != 7) {
    2407         Tcl_AppendResult(interp,
    2408         "wrong # of values: should be xMin yMin xMax yMax xNum yNum heights",
    2409                 (char *)NULL);
    2410         return NULL;
     2407        Tcl_AppendResult(interp,
     2408        "wrong # of values: should be xMin yMin xMax yMax xNum yNum heights",
     2409                (char *)NULL);
     2410        return NULL;
    24112411    }
    24122412    if ((GetFloat(interp, argv[0], &xMin) != TCL_OK) ||
    2413         (GetFloat(interp, argv[1], &yMin) != TCL_OK) ||
    2414         (GetFloat(interp, argv[2], &xMax) != TCL_OK) ||
    2415         (GetFloat(interp, argv[3], &yMax) != TCL_OK) ||
    2416         (Tcl_GetInt(interp, argv[4], &xNum) != TCL_OK) ||
    2417         (Tcl_GetInt(interp, argv[5], &yNum) != TCL_OK)) {
    2418         return NULL;
     2413        (GetFloat(interp, argv[1], &yMin) != TCL_OK) ||
     2414        (GetFloat(interp, argv[2], &xMax) != TCL_OK) ||
     2415        (GetFloat(interp, argv[3], &yMax) != TCL_OK) ||
     2416        (Tcl_GetInt(interp, argv[4], &xNum) != TCL_OK) ||
     2417        (Tcl_GetInt(interp, argv[5], &yNum) != TCL_OK)) {
     2418        return NULL;
    24192419    }
    24202420    int nValues;
    24212421    const char **elem;
    24222422    if (Tcl_SplitList(interp, argv[6], &nValues, &elem) != TCL_OK) {
    2423         return NULL;
     2423        return NULL;
    24242424    }
    24252425    if ((xNum <= 0) || (yNum <= 0)) {
    2426         Tcl_AppendResult(interp, "bad number of x or y values", (char *)NULL);
    2427         goto error;
     2426        Tcl_AppendResult(interp, "bad number of x or y values", (char *)NULL);
     2427        goto error;
    24282428    }
    24292429    if (nValues != (xNum * yNum)) {
    2430         Tcl_AppendResult(interp, "wrong # of heights", (char *)NULL);
    2431         goto error;
     2430        Tcl_AppendResult(interp, "wrong # of heights", (char *)NULL);
     2431        goto error;
    24322432    }
    24332433
     
    24352435    heights = new float[nValues];
    24362436    if (heights == NULL) {
    2437         Tcl_AppendResult(interp, "can't allocate array of heights",
    2438                 (char *)NULL);
    2439         goto error;
     2437        Tcl_AppendResult(interp, "can't allocate array of heights",
     2438                (char *)NULL);
     2439        goto error;
    24402440    }
    24412441
    24422442    int i;
    24432443    for (i = 0; i < nValues; i++) {
    2444         if (GetFloat(interp, elem[i], heights + i) != TCL_OK) {
    2445             delete [] heights;
    2446             goto error;
    2447         }
     2444        if (GetFloat(interp, elem[i], heights + i) != TCL_OK) {
     2445            delete [] heights;
     2446            goto error;
     2447        }
    24482448    }
    24492449    HeightMap* hMap;
     
    24812481
    24822482    if ((argc & 0x01) == 0) {
    2483         Tcl_AppendResult(interp,
    2484                 "wrong number of arguments: should be key-value pairs",
    2485                 (char *)NULL);
    2486         return TCL_ERROR;
     2483        Tcl_AppendResult(interp,
     2484                "wrong number of arguments: should be key-value pairs",
     2485                (char *)NULL);
     2486        return TCL_ERROR;
    24872487    }
    24882488    zValues = NULL;
     
    24912491    int i;
    24922492    for (i = 1; i < argc; i += 2) {
    2493         if (strcmp(argv[i], "xmin") == 0) {
    2494             if (GetFloat(interp, argv[i+1], &xMin) != TCL_OK) {
    2495                 return TCL_ERROR;
    2496             }
    2497         } else if (strcmp(argv[i], "xmax") == 0) {
    2498             if (GetFloat(interp, argv[i+1], &xMax) != TCL_OK) {
    2499                 return TCL_ERROR;
    2500             }
    2501         } else if (strcmp(argv[i], "xnum") == 0) {
    2502             if (Tcl_GetInt(interp, argv[i+1], &xNum) != TCL_OK) {
    2503                 return TCL_ERROR;
    2504             }
    2505             if (xNum <= 0) {
    2506                 Tcl_AppendResult(interp, "bad xnum value: must be > 0",
    2507                                 (char *)NULL);
    2508                 return TCL_ERROR;
    2509             }
    2510         } else if (strcmp(argv[i], "ymin") == 0) {
    2511             if (GetFloat(interp, argv[i+1], &yMin) != TCL_OK) {
    2512                 return TCL_ERROR;
    2513             }
    2514         } else if (strcmp(argv[i], "ymax") == 0) {
    2515             if (GetFloat(interp, argv[i+1], &yMax) != TCL_OK) {
    2516                 return TCL_ERROR;
    2517             }
    2518         } else if (strcmp(argv[i], "ynum") == 0) {
    2519             if (Tcl_GetInt(interp, argv[i+1], &yNum) != TCL_OK) {
    2520                 return TCL_ERROR;
    2521             }
    2522             if (yNum <= 0) {
    2523                 Tcl_AppendResult(interp, "bad ynum value: must be > 0",
    2524                                 (char *)NULL);
    2525                 return TCL_ERROR;
    2526             }
    2527         } else if (strcmp(argv[i], "zvalues") == 0) {
    2528             const char **zlist;
    2529 
    2530             if (Tcl_SplitList(interp, argv[i+1], &zNum, &zlist) != TCL_OK) {
    2531                 return TCL_ERROR;
    2532             }
    2533             int j;
    2534             zValues = new float[zNum];
    2535             for (j = 0; j < zNum; j++) {
    2536                 if (GetFloat(interp, zlist[j], zValues + j) != TCL_OK) {
    2537                     Tcl_Free((char *)zlist);
    2538                     return TCL_ERROR;
    2539                 }
    2540             }
    2541             Tcl_Free((char *)zlist);
    2542         } else {
    2543             Tcl_AppendResult(interp, "unknown key \"", argv[i],
    2544                 "\": should be xmin, xmax, xnum, ymin, ymax, ynum, or zvalues",
    2545                 (char *)NULL);
    2546             return TCL_ERROR;
    2547         }
     2493        if (strcmp(argv[i], "xmin") == 0) {
     2494            if (GetFloat(interp, argv[i+1], &xMin) != TCL_OK) {
     2495                return TCL_ERROR;
     2496            }
     2497        } else if (strcmp(argv[i], "xmax") == 0) {
     2498            if (GetFloat(interp, argv[i+1], &xMax) != TCL_OK) {
     2499                return TCL_ERROR;
     2500            }
     2501        } else if (strcmp(argv[i], "xnum") == 0) {
     2502            if (Tcl_GetInt(interp, argv[i+1], &xNum) != TCL_OK) {
     2503                return TCL_ERROR;
     2504            }
     2505            if (xNum <= 0) {
     2506                Tcl_AppendResult(interp, "bad xnum value: must be > 0",
     2507                                (char *)NULL);
     2508                return TCL_ERROR;
     2509            }
     2510        } else if (strcmp(argv[i], "ymin") == 0) {
     2511            if (GetFloat(interp, argv[i+1], &yMin) != TCL_OK) {
     2512                return TCL_ERROR;
     2513            }
     2514        } else if (strcmp(argv[i], "ymax") == 0) {
     2515            if (GetFloat(interp, argv[i+1], &yMax) != TCL_OK) {
     2516                return TCL_ERROR;
     2517            }
     2518        } else if (strcmp(argv[i], "ynum") == 0) {
     2519            if (Tcl_GetInt(interp, argv[i+1], &yNum) != TCL_OK) {
     2520                return TCL_ERROR;
     2521            }
     2522            if (yNum <= 0) {
     2523                Tcl_AppendResult(interp, "bad ynum value: must be > 0",
     2524                                (char *)NULL);
     2525                return TCL_ERROR;
     2526            }
     2527        } else if (strcmp(argv[i], "zvalues") == 0) {
     2528            const char **zlist;
     2529
     2530            if (Tcl_SplitList(interp, argv[i+1], &zNum, &zlist) != TCL_OK) {
     2531                return TCL_ERROR;
     2532            }
     2533            int j;
     2534            zValues = new float[zNum];
     2535            for (j = 0; j < zNum; j++) {
     2536                if (GetFloat(interp, zlist[j], zValues + j) != TCL_OK) {
     2537                    Tcl_Free((char *)zlist);
     2538                    return TCL_ERROR;
     2539                }
     2540            }
     2541            Tcl_Free((char *)zlist);
     2542        } else {
     2543            Tcl_AppendResult(interp, "unknown key \"", argv[i],
     2544                "\": should be xmin, xmax, xnum, ymin, ymax, ynum, or zvalues",
     2545                (char *)NULL);
     2546            return TCL_ERROR;
     2547        }
    25482548    }
    25492549    if (zValues == NULL) {
    2550         Tcl_AppendResult(interp, "missing \"zvalues\" key", (char *)NULL);
    2551         return TCL_ERROR;
     2550        Tcl_AppendResult(interp, "missing \"zvalues\" key", (char *)NULL);
     2551        return TCL_ERROR;
    25522552    }
    25532553    if (zNum != (xNum * yNum)) {
    2554         Tcl_AppendResult(interp, "wrong number of z values must be xnum*ynum",
    2555                 (char *)NULL);
    2556         return TCL_ERROR;
     2554        Tcl_AppendResult(interp, "wrong number of z values must be xnum*ynum",
     2555                (char *)NULL);
     2556        return TCL_ERROR;
    25572557    }
    25582558    HeightMap* hMap;
  • trunk/vizservers/nanovis/GradientFilter.cpp

    r883 r887  
     1
    12#include <stdlib.h>
    23#include <float.h>
  • trunk/vizservers/nanovis/GradientFilter.h

    r883 r887  
    1 #pragma once;
     1#ifndef _GRADIENT_FILTER_H
     2#define _GRADIENT_FILTER_H
    23
    34typedef enum {DATRAW_UCHAR, DATRAW_FLOAT, DATRAW_USHORT} DataType;
     
    78extern void quantizeGradients(float *gradientsIn, void *gradientsOut,
    89                                           int *sizes, DataType dataType);
     10
     11#endif /*_GRADIENT_FILTER_H*/
  • trunk/vizservers/nanovis/Makefile.in

    r884 r887  
    1515bindir          = @bindir@
    1616libdir          = @libdir@
     17srcdir          = @srcdir@
    1718includedir      = @includedir@
    1819mandir          = @mandir@
     
    2728AUXSRC = config.h define.h global.h
    2829
     30RP_DIR =  @RP_DIR@
    2931R2INC = ./R2/include
    3032MATINC = ./newmat11
    3133
    32 LIB_DX = -lDXcallm -lm
    33 LIB_NANOVIS = -L@RP_DIR@/lib -ltcl8.4 -lGL -lglut -lglui -lGLEW -lCg -lCgGL -pthread -lrappture2 -lb64 -lz
    34 INCLUDES = -I@RP_DIR@/include -I@RP2_INCL_DIR@ -I/usr/include/GL -I$(R2INC) -I. -I$(MATINC)
     34DX_DIR  = /usr/dx
     35DX_INC_SPEC = -I$(DX_DIR)/include
     36DX_LIB_SPEC = -L$(DX_DIR)/lib_linux -lDXcallm -lm
     37DX_INC_SPEC = -I/usr/include/dx
     38DX_LIB_SPEC = -L/usr/lib/dx/lib_linux -lDXcallm -lm
     39GL_INC_SPEC = -I/usr/include/GL
     40GL_LIB_SPEC = -lGL -lglut -lglui -lGLEW -lCg -lCgGL -lpthread
     41MAT_INC_SPEC = -I$(MATINC)
     42R2_INC_SPEC = -I$(R2INC)
     43RP_INC_SPEC = -I$(RP_DIR)/include -I$(RP_DIR)/include/rappture2
     44RP_LIB_SPEC = -L$(RP_DIR)/lib -lrappture2 -lb64 -lz
     45
     46LIBS = \
     47        $(RP_LIB_SPEC) \
     48        -ltcl8.4 \
     49        $(GL_LIB_SPEC) \
     50        $(DX_LIB_SPEC)
     51
     52INCLUDES = \
     53        -I. \
     54        $(RP_INC_SPEC) \
     55        $(GL_INC_SPEC) \
     56        $(R2_INC_SPEC) \
     57        $(MAT_INC_SPEC)
    3558
    3659CFLAGS = @CFLAGS@
     
    112135        cholesky.o \
    113136        dxReader.o \
     137        dxReader2.o \
    114138        evalue.o \
    115139        fft.o \
     
    150174
    151175clean:
    152         rm -f *.o nanovis client
     176        rm -f nanovis client $(OBJS)
    153177
    154178distclean: clean
    155         rm Makefile
     179        rm -f Makefile *~
    156180
    157181nanovis: $(OBJS)
    158         $(CC) $(CC_SWITCHES) -o $@ $^ $(LIB_NANOVIS) $(LIB_DX)
     182        $(CC) $(CC_SWITCHES) -o $@ $^ $(LIBS)
    159183
    160184client: Socket.o ClientSocket.o RenderClient.o Event.o
    161         $(CC) $(CC_SWITCHES) -o $@ $^ $(LIB_NANOVIS) $(LIB_DX)
     185        $(CC) $(CC_SWITCHES) -o $@ $^ $(LIBS)
    162186
    163187.cpp.o:
     
    167191        $(CC) $(CC_SWITCHES) -c $^
    168192
     193dxReader2.o: $(srcdir)/dxReader2.cpp
     194        $(CC) -c $(CC_SWITCHES) $(DX_INC_SPEC) $?
    169195ColorGradient.o: transfer-function/ColorGradient.cpp
    170196        $(CC) $(CC_SWITCHES) -o $@ -c $<
  • trunk/vizservers/nanovis/VolumeRenderer.cpp

    r884 r887  
    1717#include <R2/R2FilePath.h>
    1818#include "VolumeRenderer.h"
     19#include "VolumeInterpolator.h"
    1920#include "NvStdVertexShader.h"
    2021#include <time.h>
  • trunk/vizservers/nanovis/nanovis.cpp

    r884 r887  
    8282bool NanoVis::axis_on = true;
    8383//bool NanoVis::axis_on = false;
    84 int NanoVis::win_width = NPIX;                  //size of the render window
    85 int NanoVis::win_height = NPIX;                 //size of the render window
     84int NanoVis::win_width = NPIX;                  //size of the render window
     85int NanoVis::win_height = NPIX;                 //size of the render window
    8686int NanoVis::n_volumes = 0;
    8787unsigned char* NanoVis::screen_buffer = NULL;
     
    110110
    111111// color table for built-in transfer function editor
    112 float color_table[256][4];      
     112float color_table[256][4];      
    113113
    114114/*
     
    121121void init_event_log();
    122122void end_event_log();
    123 double cur_time;        //in seconds
     123double cur_time;        //in seconds
    124124double get_time_interval();
    125125*/
    126126
    127 int render_window;              //the handle of the render window;
     127int render_window;              //the handle of the render window;
    128128
    129129// in Command.cpp
     
    140140
    141141//bool advect=false;
    142 float vert[NMESH*NMESH*3];              //particle positions in main memory
    143 float slice_vector[NMESH*NMESH*4];      //per slice vectors in main memory
     142float vert[NMESH*NMESH*3];              //particle positions in main memory
     143float slice_vector[NMESH*NMESH*4];      //per slice vectors in main memory
    144144
    145145// maps transfunc name to TransferFunction object
     
    149149
    150150
    151 PerfQuery* perf;                        //perfromance counter
     151PerfQuery* perf;                        //perfromance counter
    152152
    153153CGprogram m_passthru_fprog;
     
    159159
    160160// Object rotation angles
    161 static float live_rot_x = 90.;         
     161static float live_rot_x = 90.;         
    162162static float live_rot_y = 180.;
    163163static float live_rot_z = -135;
    164164
    165165// Object translation location from the origin
    166 static float live_obj_x = -0.0; 
     166static float live_obj_x = -0.0; 
    167167static float live_obj_y = -0.0;
    168168static float live_obj_z = -2.5;
     
    175175static int right_last_x;
    176176static int right_last_y;
    177 static bool left_down = false;                                         
     177static bool left_down = false;                                         
    178178static bool right_down = false;
    179179#endif /*XINETD*/
     
    270270 * data: pointer to an array of floats. 
    271271 * n_component: the number of scalars for each space point.
    272  *              All component scalars for a point are placed consequtively in data array
     272 *              All component scalars for a point are placed consequtively in data array
    273273 * width, height and depth: number of points in each dimension
    274274 */
    275275void
    276276NanoVis::load_volume(int index, int width, int height, int depth,
    277                      int n_component, float* data, double vmin,
    278                      double vmax, double nzero_min)
     277                     int n_component, float* data, double vmin,
     278                     double vmax, double nzero_min)
    279279{
    280280    while (n_volumes <= index) {
     
    300300
    301301    volume[index] = new Volume(0.f, 0.f, 0.f, width, height, depth, 1.,
    302                                n_component, data, vmin, vmax, nzero_min);
     302                               n_component, data, vmin, vmax, nzero_min);
    303303    assert(volume[index]!=0);
    304304}
     
    312312    hPtr = Tcl_FindHashEntry(&tftable, name);
    313313    if (hPtr == NULL) {
    314         return NULL;
     314        return NULL;
    315315    }
    316316    return (TransferFunction*)Tcl_GetHashValue(hPtr);
     
    327327    hPtr = Tcl_CreateHashEntry(&tftable, name, &isNew);
    328328    if (isNew) {
    329         tf = new TransferFunction(nSlots, data);
    330         Tcl_SetHashValue(hPtr, (ClientData)tf);
     329        tf = new TransferFunction(nSlots, data);
     330        Tcl_SetHashValue(hPtr, (ClientData)tf);
    331331    } else {
    332         tf = (TransferFunction*)Tcl_GetHashValue(hPtr);
    333         tf->update(data);
     332        tf = (TransferFunction*)Tcl_GetHashValue(hPtr);
     333        tf->update(data);
    334334    }
    335335    return tf;
     
    352352    TransferFunction *tf = NanoVis::get_transfunc("default");
    353353    if (tf == NULL) {
    354         return;
     354        return;
    355355    }
    356356   
    357357    float data[256*4];
    358358    for(int i=0; i<256; i++) {
    359         data[4*i+0] = color_table[i][0];
    360         data[4*i+1] = color_table[i][1];
    361         data[4*i+2] = color_table[i][2];
    362         data[4*i+3] = color_table[i][3];
    363         //fprintf(stderr, "(%f,%f,%f,%f) ", data[4*i+0], data[4*i+1], data[4*i+2], data[4*i+3]);
     359        data[4*i+0] = color_table[i][0];
     360        data[4*i+1] = color_table[i][1];
     361        data[4*i+2] = color_table[i][2];
     362        data[4*i+3] = color_table[i][3];
     363        //fprintf(stderr, "(%f,%f,%f,%f) ", data[4*i+0], data[4*i+1], data[4*i+2], data[4*i+3]);
    364364    }
    365365   
     
    434434#ifdef NV40
    435435    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, win_width, win_height, 0,
    436                 GL_RGB, GL_INT, NULL);
     436                GL_RGB, GL_INT, NULL);
    437437#else
    438438    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, win_width, win_height, 0,
    439                 GL_RGB, GL_INT, NULL);
     439                GL_RGB, GL_INT, NULL);
    440440#endif
    441441    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
    442                               GL_COLOR_ATTACHMENT0_EXT,
    443                               GL_TEXTURE_2D, final_color_tex, 0);
     442                              GL_COLOR_ATTACHMENT0_EXT,
     443                              GL_TEXTURE_2D, final_color_tex, 0);
    444444   
    445445    // initialize final depth renderbuffer
    446446    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb);
    447447    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
    448                              GL_DEPTH_COMPONENT24, win_width, win_height);
     448                             GL_DEPTH_COMPONENT24, win_width, win_height);
    449449    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
    450                                 GL_DEPTH_ATTACHMENT_EXT,
    451                                 GL_RENDERBUFFER_EXT, final_depth_rb);
     450                                GL_DEPTH_ATTACHMENT_EXT,
     451                                GL_RENDERBUFFER_EXT, final_depth_rb);
    452452   
    453453    // Check framebuffer completeness at the end of initialization.
     
    473473   
    474474    if (screen_buffer) {
    475         delete[] screen_buffer;
    476         screen_buffer = NULL;
     475        delete[] screen_buffer;
     476        screen_buffer = NULL;
    477477    }
    478478   
     
    505505#ifdef NV40
    506506    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, win_width, win_height, 0,
    507                 GL_RGB, GL_INT, NULL);
     507                GL_RGB, GL_INT, NULL);
    508508#else
    509509    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, win_width, win_height, 0,
    510                 GL_RGB, GL_INT, NULL);
     510                GL_RGB, GL_INT, NULL);
    511511#endif
    512512    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
    513                               GL_COLOR_ATTACHMENT0_EXT,
    514                               GL_TEXTURE_2D, final_color_tex, 0);
    515        
     513                              GL_COLOR_ATTACHMENT0_EXT,
     514                              GL_TEXTURE_2D, final_color_tex, 0);
     515       
    516516    // initialize final depth renderbuffer
    517517    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb);
    518518    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
    519                              GL_DEPTH_COMPONENT24, win_width, win_height);
     519                             GL_DEPTH_COMPONENT24, win_width, win_height);
    520520    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
    521                                 GL_DEPTH_ATTACHMENT_EXT,
    522                                 GL_RENDERBUFFER_EXT, final_depth_rb);
     521                                GL_DEPTH_ATTACHMENT_EXT,
     522                                GL_RENDERBUFFER_EXT, final_depth_rb);
    523523
    524524    // Check framebuffer completeness at the end of initialization.
     
    538538    //procedurally make a gradient plane
    539539    for(int j=0; j<h; j++){
    540         for(int i=0; i<w; i++){
    541             data[w*j+i] = float(i)/float(w);
    542         }
     540        for(int i=0; i<w; i++){
     541            data[w*j+i] = float(i)/float(w);
     542        }
    543543    }
    544544    NanoVis::plane[0] = new Texture2D(w, h, GL_FLOAT, GL_LINEAR, 1, data);
     
    565565                data[4*index+1]= j/float(particleRenderer->psys_height);
    566566                data[4*index+2]= i/float(particleRenderer->psys_width);
    567                 data[4*index+3]= 30; //shorter life span, quicker iterations   
    568                 //data[4*index+3]= 1.0f; //shorter life span, quicker iterations       
     567                data[4*index+3]= 30; //shorter life span, quicker iterations   
     568                //data[4*index+3]= 1.0f; //shorter life span, quicker iterations       
    569569            }
    570570/*
     
    574574                data[4*index+1]= 0;
    575575                data[4*index+2]= 0;
    576                 data[4*index+3]= 0;     
     576                data[4*index+3]= 0;     
    577577            }
    578578*/
     
    662662   //create the camera with default setting
    663663   cam = new NvCamera(0, 0, win_width, win_height,
    664                    live_obj_x, live_obj_y, live_obj_z,
    665                    0., 0., 100.,
    666                    (int)live_rot_x, (int)live_rot_y, (int)live_rot_z);
     664                   live_obj_x, live_obj_y, live_obj_z,
     665                   0., 0., 100.,
     666                   (int)live_rot_x, (int)live_rot_y, (int)live_rot_z);
    667667
    668668   glEnable(GL_TEXTURE_2D);
     
    682682   glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
    683683   glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
    684    glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);     
     684   glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);     
    685685   glLightfv(GL_LIGHT1, GL_DIFFUSE, green_light);
    686    glLightfv(GL_LIGHT1, GL_SPECULAR, white_light);     
     686   glLightfv(GL_LIGHT1, GL_SPECULAR, white_light);     
    687687
    688688   // init table of transfer functions
     
    736736{
    737737    glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE,
    738                 screen_buffer);
     738                screen_buffer);
    739739}
    740740
     
    755755    int i=0;
    756756    while(i<len){
    757         if (NanoVis::screen_buffer[i] == 0) {
    758             int pos = i+1;
    759             while ( (pos<len) && (NanoVis::screen_buffer[pos] == 0)) {
    760                 pos++;
    761             }
    762             offsets[offsets_size++] = -(pos - i);
    763             i = pos;
    764         }
    765        
    766         else {
    767             int pos;
    768             for (pos = i; (pos<len) && (NanoVis::screen_buffer[pos] != 0);pos++){
    769                 rle[rle_size++] = NanoVis::screen_buffer[pos];
    770             }
    771             offsets[offsets_size++] = (pos - i);
    772             i = pos;
    773         }
    774        
     757        if (NanoVis::screen_buffer[i] == 0) {
     758            int pos = i+1;
     759            while ( (pos<len) && (NanoVis::screen_buffer[pos] == 0)) {
     760                pos++;
     761            }
     762            offsets[offsets_size++] = -(pos - i);
     763            i = pos;
     764        }
     765       
     766        else {
     767            int pos;
     768            for (pos = i; (pos<len) && (NanoVis::screen_buffer[pos] != 0);pos++){
     769                rle[rle_size++] = NanoVis::screen_buffer[pos];
     770            }
     771            offsets[offsets_size++] = (pos - i);
     772            i = pos;
     773        }
     774       
    775775    }
    776776}
     
    857857    char filename[100];
    858858    if (frame_number >= 0) {
    859         sprintf(filename, "/tmp/flow_animation/image%03d.bmp", frame_number);
    860         printf("Writing %s\n", filename);
     859        sprintf(filename, "/tmp/flow_animation/image%03d.bmp", frame_number);
     860        printf("Writing %s\n", filename);
    861861        f = fopen(filename, "wb");
    862862    }
     
    948948    glColor4f(0.,0.,1.,1.);
    949949    for(int i=0; i<NMESH; i++){
    950         for(int j=0; j<NMESH; j++){
    951             Vector2 v = grid.get(i, j);
    952            
    953             int x1 = i*DM;
    954             int y1 = j*DM;
    955            
    956             int x2 = x1 + v.x;
    957             int y2 = y1 + v.y;
    958            
    959             glBegin(GL_LINES);
    960             glVertex2d(x1, y1);
    961             glVertex2d(x2, y2);
    962             glEnd();
    963         }
     950        for(int j=0; j<NMESH; j++){
     951            Vector2 v = grid.get(i, j);
     952           
     953            int x1 = i*DM;
     954            int y1 = j*DM;
     955           
     956            int x2 = x1 + v.x;
     957            int y2 = y1 + v.y;
     958           
     959            glBegin(GL_LINES);
     960            glVertex2d(x1, y1);
     961            glVertex2d(x2, y2);
     962            glEnd();
     963        }
    964964    }
    965965}
     
    10011001    glLoadIdentity();
    10021002   
    1003     glColor3f(1.,1.,1.);                //MUST HAVE THIS LINE!!!
     1003    glColor3f(1.,1.,1.);                //MUST HAVE THIS LINE!!!
    10041004    glBegin(GL_QUADS);
    10051005    glTexCoord2f(0, 0); glVertex2f(0, 0);
     
    10211021void
    10221022draw_bounding_box(float x0, float y0, float z0,
    1023                   float x1, float y1, float z1,
    1024                   float r, float g, float b, float line_width)
     1023                  float x1, float y1, float z1,
     1024                  float r, float g, float b, float line_width)
    10251025{
    10261026    glDisable(GL_TEXTURE_2D);
     
    10761076{
    10771077    if((*((Particle*)a)).aux > (*((Particle*)b)).aux) {
    1078         return -1;
     1078        return -1;
    10791079    } else {
    1080         return 1;
     1080        return 1;
    10811081    }
    10821082}
     
    10911091    p = (Particle*)malloc(sizeof(Particle)*psys->psys_width*psys->psys_height);
    10921092    for (int i=0; i<psys->psys_width * psys->psys_height; i++) {
    1093         float x = vert[3*i];
    1094         float y = vert[3*i+1];
    1095         float z = vert[3*i+2];
    1096        
    1097         float dis = (x-live_obj_x)*(x-live_obj_x) + (y-live_obj_y)*(y-live_obj_y) + (z-live_obj_z)*(z-live_obj_z);
    1098         p[i].x = x;
    1099         p[i].y = y;
    1100         p[i].z = z;
    1101         p[i].aux = dis;
     1093        float x = vert[3*i];
     1094        float y = vert[3*i+1];
     1095        float z = vert[3*i+2];
     1096       
     1097        float dis = (x-live_obj_x)*(x-live_obj_x) + (y-live_obj_y)*(y-live_obj_y) + (z-live_obj_z)*(z-live_obj_z);
     1098        p[i].x = x;
     1099        p[i].y = y;
     1100        p[i].z = z;
     1101        p[i].aux = dis;
    11021102    }
    11031103   
     
    11051105   
    11061106    for(int i=0; i<psys->psys_width * psys->psys_height; i++){
    1107         vert[3*i] = p[i].x;
    1108         vert[3*i+1] = p[i].y;
    1109         vert[3*i+2] = p[i].z;
     1107        vert[3*i] = p[i].x;
     1108        vert[3*i+1] = p[i].y;
     1109        vert[3*i+2] = p[i].z;
    11101110    }
    11111111   
     
    11591159    glBegin(GL_POINTS);
    11601160    for(int i=0; i<psys->psys_width * psys->psys_height; i++){
    1161         glVertex3f(vert[3*i], vert[3*i+1], vert[3*i+2]);
     1161        glVertex3f(vert[3*i], vert[3*i+1], vert[3*i+2]);
    11621162    }
    11631163    glEnd();
     
    11981198    oddevenMergeSort.bind();
    11991199    glUniform3fARB(oddevenMergeSort.getUniformLocation("Param1"), float(pstage+pstage),
    1200                    float(ppass%pstage), float((pstage+pstage)-(ppass%pstage)-1));
     1200                   float(ppass%pstage), float((pstage+pstage)-(ppass%pstage)-1));
    12011201    glUniform3fARB(oddevenMergeSort.getUniformLocation("Param2"), float(psys_width), float(psys_height), float(ppass));
    12021202    glUniform1iARB(oddevenMergeSort.getUniformLocation("Data"), 0);
     
    12161216    glBegin(GL_QUADS);
    12171217#ifdef notdef
    1218     glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,0.0f,0.0f,1.0f); glVertex2f(-1.0f,-1.0f); 
     1218    glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,0.0f,0.0f,1.0f); glVertex2f(-1.0f,-1.0f); 
    12191219    glMultiTexCoord4fARB(GL_TEXTURE0_ARB,float(psys_width),0.0f,1.0f,1.0f); glVertex2f(1.0f,-1.0f);
    1220     glMultiTexCoord4fARB(GL_TEXTURE0_ARB,float(psys_width),float(psys_height),1.0f,0.0f); glVertex2f(1.0f,1.0f);       
    1221     glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,float(psys_height),0.0f,0.0f); glVertex2f(-1.0f,1.0f);   
    1222 #endif
    1223     glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,0.0f,0.0f,1.0f); glVertex2f(0.,0.);       
     1220    glMultiTexCoord4fARB(GL_TEXTURE0_ARB,float(psys_width),float(psys_height),1.0f,0.0f); glVertex2f(1.0f,1.0f);       
     1221    glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,float(psys_height),0.0f,0.0f); glVertex2f(-1.0f,1.0f);   
     1222#endif
     1223    glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,0.0f,0.0f,1.0f); glVertex2f(0.,0.);       
    12241224    glMultiTexCoord4fARB(GL_TEXTURE0_ARB,float(psys_width),0.0f,1.0f,1.0f); glVertex2f(float(psys_width), 0.);
    1225     glMultiTexCoord4fARB(GL_TEXTURE0_ARB,float(psys_width),float(psys_height),1.0f,0.0f); glVertex2f(float(psys_width), float(psys_height));   
    1226     glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,float(psys_height),0.0f,0.0f); glVertex2f(0., float(psys_height));       
     1225    glMultiTexCoord4fARB(GL_TEXTURE0_ARB,float(psys_width),float(psys_height),1.0f,0.0f); glVertex2f(float(psys_width), float(psys_height));   
     1226    glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,float(psys_height),0.0f,0.0f); glVertex2f(0., float(psys_height));       
    12271227    glEnd();
    12281228
     
    12631263    glScalef(0.0005, 0.0005, 0.0005);
    12641264    glutStrokeCharacter(GLUT_STROKE_ROMAN, 'x');
    1265     glPopMatrix();     
     1265    glPopMatrix();     
    12661266   
    12671267    glPushMatrix();
     
    12711271    glScalef(0.0005, 0.0005, 0.0005);
    12721272    glutStrokeCharacter(GLUT_STROKE_ROMAN, 'y');
    1273     glPopMatrix();     
     1273    glPopMatrix();     
    12741274   
    12751275    glPushMatrix();
     
    12791279    glScalef(0.0005, 0.0005, 0.0005);
    12801280    glutStrokeCharacter(GLUT_STROKE_ROMAN, 'z');
    1281     glPopMatrix();     
     1281    glPopMatrix();     
    12821282   
    12831283    glEnable(GL_LIGHTING);
     
    12901290   
    12911291    glPushMatrix();
    1292     glRotatef(-90, 1, 0, 0);   
     1292    glRotatef(-90, 1, 0, 0);   
    12931293    gluCylinder(obj, 0.01, 0.01, 0.3, segments, segments);
    1294     glPopMatrix();     
     1294    glPopMatrix();     
    12951295   
    12961296    glPushMatrix();
    12971297    glTranslatef(0., 0.3, 0.);
    1298     glRotatef(-90, 1, 0, 0);   
     1298    glRotatef(-90, 1, 0, 0);   
    12991299    gluCylinder(obj, 0.02, 0.0, 0.06, segments, segments);
    1300     glPopMatrix();     
     1300    glPopMatrix();     
    13011301   
    13021302    glPushMatrix();
    13031303    glRotatef(90, 0, 1, 0);
    13041304    gluCylinder(obj, 0.01, 0.01, 0.3, segments, segments);
    1305     glPopMatrix();     
     1305    glPopMatrix();     
    13061306   
    13071307    glPushMatrix();
    13081308    glTranslatef(0.3, 0., 0.);
    1309     glRotatef(90, 0, 1, 0);     
     1309    glRotatef(90, 0, 1, 0);     
    13101310    gluCylinder(obj, 0.02, 0.0, 0.06, segments, segments);
    1311     glPopMatrix();     
     1311    glPopMatrix();     
    13121312   
    13131313    glPushMatrix();
    13141314    gluCylinder(obj, 0.01, 0.01, 0.3, segments, segments);
    1315     glPopMatrix();     
     1315    glPopMatrix();     
    13161316   
    13171317    glPushMatrix();
    13181318    glTranslatef(0., 0., 0.3);
    13191319    gluCylinder(obj, 0.02, 0.0, 0.06, segments, segments);
    1320     glPopMatrix();     
     1320    glPopMatrix();     
    13211321   
    13221322    glDisable(GL_LIGHTING);
     
    13391339    glBegin(GL_LINES);
    13401340    {
    1341         glVertex3f(0,0,0);
    1342         glVertex3f(1.5,0,0);
     1341        glVertex3f(0,0,0);
     1342        glVertex3f(1.5,0,0);
    13431343    }
    13441344    glEnd();
     
    13481348    glBegin(GL_LINES);
    13491349    {
    1350         glVertex3f(0,0,0);
    1351         glVertex3f(0,1.5,0);
     1350        glVertex3f(0,0,0);
     1351        glVertex3f(0,1.5,0);
    13521352    }
    13531353    glEnd();
     
    13571357    glBegin(GL_LINES);
    13581358    {
    1359         glVertex3f(0,0,0);
    1360         glVertex3f(0,0,1.5);
     1359        glVertex3f(0,0,0);
     1360        glVertex3f(0,0,1.5);
    13611361    }
    13621362    glEnd();
     
    13691369void NanoVis::update()
    13701370{
    1371     if (vol_renderer->_volumeInterpolator->is_started())
    1372     {
    1373     struct timeval clock;
    1374     gettimeofday(&clock, NULL);
    1375     double cur_time = clock.tv_sec + clock.tv_usec/1000000.0;
    1376 
    1377     float fraction;
    1378     float f = fmod(cur_time - vol_renderer->_volumeInterpolator->getStartTime(),
    1379                     vol_renderer->_volumeInterpolator->getInterval());
    1380 
    1381     if (f == 0.0f) fraction = 0.0f;
    1382     else fraction = f / vol_renderer->_volumeInterpolator->getInterval();
    1383 
    1384     vol_renderer->_volumeInterpolator->update(fraction);
    1385   }
     1371    if (vol_renderer->_volumeInterpolator->is_started()) {
     1372        struct timeval clock;
     1373        gettimeofday(&clock, NULL);
     1374        double cur_time = clock.tv_sec + clock.tv_usec/1000000.0;
     1375       
     1376        float fraction;
     1377        float f;
     1378
     1379        f = fmod(cur_time - vol_renderer->_volumeInterpolator->getStartTime(),
     1380                 vol_renderer->_volumeInterpolator->getInterval());
     1381        if (f == 0.0f) {
     1382            fraction = 0.0f;
     1383        } else {
     1384            fraction = f / vol_renderer->_volumeInterpolator->getInterval();
     1385        }
     1386        vol_renderer->_volumeInterpolator->update(fraction);
     1387    }
    13861388}
    13871389
     
    13991401        glEnable(GL_TEXTURE_2D);
    14001402        glEnable(GL_DEPTH_TEST);
    1401        
     1403       
    14021404        //camera setting activated
    14031405        cam->activate();
    1404        
     1406       
    14051407        //set up the orientation of items in the scene.
    14061408        glPushMatrix();
     
    14141416            // this is the default
    14151417            break;
    1416            
     1418           
    14171419        case 3:  // z
    14181420            glRotatef(-90, 1, 0, 0);
    14191421            glRotatef(-90, 0, 0, 1);
    14201422            break;
    1421            
     1423           
    14221424        case -1:  // -x
    14231425            glRotatef(-90, 0, 0, 1);
    14241426            break;
    1425            
     1427           
    14261428        case -2:  // -y
    14271429            glRotatef(180, 0, 0, 1);
    14281430            glRotatef(-90, 0, 1, 0);
    14291431            break;
    1430            
     1432           
    14311433        case -3:  // -z
    14321434            glRotatef(90, 1, 0, 0);
    14331435            break;
    14341436        }
    1435        
     1437       
    14361438        // TBD : This will be removed after being sure that all the functions work well.
    14371439        //glPushMatrix();
     
    14391441        //now render things in the scene
    14401442        if (axis_on) {
    1441             draw_3d_axis();
    1442         }
     1443            draw_3d_axis();
     1444        }
    14431445        if (grid->isVisible()) {
    14441446            grid->render();
     
    14551457        //fprintf(stderr, "particle pixels: %d\n", perf->get_pixel_count());
    14561458        //perf->reset();
    1457        
     1459       
    14581460        //perf->enable();
    14591461        vol_renderer->render_all();
    14601462        //perf->disable();
    1461        
     1463       
    14621464        for (unsigned int i = 0; i < heightMap.size(); ++i) {
    14631465            if (heightMap[i]->isVisible()) {
    14641466                heightMap[i]->render(renderContext);
    1465             }
     1467            }
    14661468        }
    14671469        glPopMatrix();
     
    14861488{
    14871489    if(button==GLUT_LEFT_BUTTON){
    1488         if (state==GLUT_DOWN) {
    1489             left_last_x = x;
    1490             left_last_y = y;
    1491             left_down = true;
    1492             right_down = false;
    1493         } else {
    1494             left_down = false;
    1495             right_down = false;
    1496         }
     1490        if (state==GLUT_DOWN) {
     1491            left_last_x = x;
     1492            left_last_y = y;
     1493            left_down = true;
     1494            right_down = false;
     1495        } else {
     1496            left_down = false;
     1497            right_down = false;
     1498        }
    14971499    } else {
    1498         //fprintf(stderr, "right mouse\n");
    1499 
    1500         if(state==GLUT_DOWN){
    1501             //fprintf(stderr, "right mouse down\n");
    1502             right_last_x = x;
    1503             right_last_y = y;
    1504             left_down = false;
    1505             right_down = true;
    1506         } else {
    1507             //fprintf(stderr, "right mouse up\n");
    1508             left_down = false;
    1509             right_down = false;
    1510         }
     1500        //fprintf(stderr, "right mouse\n");
     1501
     1502        if(state==GLUT_DOWN){
     1503            //fprintf(stderr, "right mouse down\n");
     1504            right_last_x = x;
     1505            right_last_y = y;
     1506            left_down = false;
     1507            right_down = true;
     1508        } else {
     1509            //fprintf(stderr, "right mouse up\n");
     1510            left_down = false;
     1511            right_down = false;
     1512        }
    15111513    }
    15121514}
     
    15191521   
    15201522    if (live_rot_x > 360.0) {
    1521         live_rot_x -= 360.0;   
     1523        live_rot_x -= 360.0;   
    15221524    } else if(live_rot_x < -360.0) {
    1523         live_rot_x += 360.0;
     1525        live_rot_x += 360.0;
    15241526    }
    15251527    if (live_rot_y > 360.0) {
    1526         live_rot_y -= 360.0;   
     1528        live_rot_y -= 360.0;   
    15271529    } else if(live_rot_y < -360.0) {
    1528         live_rot_y += 360.0;
     1530        live_rot_y += 360.0;
    15291531    }
    15301532    cam->rotate(live_rot_x, live_rot_y, live_rot_z);
     
    16101612   default:
    16111613       break;
    1612    }   
     1614   }   
    16131615#ifdef EVENTLOG
    16141616   if(log){
     
    16241626NanoVis::motion(int x, int y)
    16251627{
    1626     int old_x, old_y;   
     1628    int old_x, old_y;   
    16271629
    16281630    if(left_down){
    1629         old_x = left_last_x;
    1630         old_y = left_last_y;   
     1631        old_x = left_last_x;
     1632        old_y = left_last_y;   
    16311633    } else if(right_down){
    1632         old_x = right_last_x;
    1633         old_y = right_last_y;   
     1634        old_x = right_last_x;
     1635        old_y = right_last_y;   
    16341636    }
    16351637   
     
    16421644   
    16431645    if(left_down){
    1644         left_last_x = x;
    1645         left_last_y = y;
    1646        
    1647         update_rot(-delta_y, -delta_x);
     1646        left_last_x = x;
     1647        left_last_y = y;
     1648       
     1649        update_rot(-delta_y, -delta_x);
    16481650    } else if (right_down){
    1649         //fprintf(stderr, "right mouse motion (%d,%d)\n", x, y);
    1650        
    1651         right_last_x = x;
    1652         right_last_y = y;
    1653        
    1654         update_trans(0, 0, delta_x);
     1651        //fprintf(stderr, "right mouse motion (%d,%d)\n", x, y);
     1652       
     1653        right_last_x = x;
     1654        right_last_y = y;
     1655       
     1656        update_trans(0, 0, delta_x);
    16551657    }
    16561658   
     
    16891691    fclose(xinetd_log);
    16901692}
    1691 #endif  /*XINETD*/
     1693#endif  /*XINETD*/
    16921694
    16931695void
     
    17381740        int option_index = 0;
    17391741        struct option long_options[] = {
    1740             // name, has_arg, flag, val
    1741             { 0,0,0,0 },
     1742            // name, has_arg, flag, val
     1743            { 0,0,0,0 },
    17421744        };
    17431745
     
    17451747        if (c == -1) {
    17461748            break;
    1747         }
     1749        }
    17481750        switch(c) {
    1749         case 'p':
    1750             path = optarg;
    1751             break;
    1752         default:
    1753             fprintf(stderr,"Don't know what option '%c'.\n", c);
    1754             return 1;
     1751        case 'p':
     1752            path = optarg;
     1753            break;
     1754        default:
     1755            fprintf(stderr,"Don't know what option '%c'.\n", c);
     1756            return 1;
    17551757        }
    17561758    }
Note: See TracChangeset for help on using the changeset viewer.