Changeset 973 for trunk/vizservers


Ignore:
Timestamp:
Mar 29, 2008, 10:40:15 PM (16 years ago)
Author:
gah
Message:
 
Location:
trunk/vizservers/nanovis
Files:
6 edited

Legend:

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

    r958 r973  
    973973 */
    974974static int
    975 TransfuncCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv)
     975TransfuncCmd(ClientData cdata, Tcl_Interp *interp, int objc,
     976             Tcl_Obj *CONST *objv)
    976977{
    977978    if (objc < 2) {
    978979        Tcl_AppendResult(interp, "wrong # args: should be \"",
    979                          Tcl_GetString(objv[0]), " option arg arg...\"", (char*)NULL);
     980                Tcl_GetString(objv[0]), " option arg arg...\"", (char*)NULL);
    980981        return TCL_ERROR;
    981982    }
     
    986987        if (objc != 5) {
    987988            Tcl_AppendResult(interp, "wrong # args: should be \"",
    988                              Tcl_GetString(objv[0]), " define name colormap alphamap\"",
    989                              (char*)NULL);
     989                Tcl_GetString(objv[0]), " define name colorMap alphaMap\"",
     990                (char*)NULL);
    990991            return TCL_ERROR;
    991992        }
     
    10021003        }
    10031004        if ((cmapc % 4) != 0) {
    1004             Tcl_AppendResult(interp, "bad colormap in transfunc: should be ",
    1005                              "{ v r g b ... }", (char*)NULL);
     1005            Tcl_AppendResult(interp, "wrong # elements is colormap: should be ",
     1006                "{ v r g b ... }", (char*)NULL);
    10061007            return TCL_ERROR;
    10071008        }
     
    10111012        if ((wmapc % 2) != 0) {
    10121013            Tcl_AppendResult(interp, "wrong # elements in alphamap: should be ",
    1013                              " { v w ... }", (char*)NULL);
     1014                " { v w ... }", (char*)NULL);
    10141015            return TCL_ERROR;
    10151016        }
    10161017        for (i = 0; i < cmapc; i += 4) {
    10171018            int j;
    1018             double vals[4];
     1019            double q[4];
    10191020
    10201021            for (j=0; j < 4; j++) {
    1021                 if (Tcl_GetDoubleFromObj(interp, cmapv[i+j], &vals[j]) != TCL_OK) {
     1022                if (Tcl_GetDoubleFromObj(interp, cmapv[i+j], &q[j]) != TCL_OK) {
    10221023                    return TCL_ERROR;
    10231024                }
    1024                 if ((vals[j] < 0.0) || (vals[j] > 1.0)) {
    1025                     Tcl_AppendResult(interp, "bad value \"", cmapv[i+j],
    1026                                      "\": should be in the range 0-1", (char*)NULL);
     1025                if ((q[j] < 0.0) || (q[j] > 1.0)) {
     1026                    Tcl_AppendResult(interp, "bad colormap value \"",
     1027                        Tcl_GetString(cmapv[i+j]),
     1028                        "\": should be in the range 0-1", (char*)NULL);
    10271029                    return TCL_ERROR;
    10281030                }
    10291031            }
    1030             rFunc.define(vals[0], vals[1]);
    1031             gFunc.define(vals[0], vals[2]);
    1032             bFunc.define(vals[0], vals[3]);
     1032            rFunc.define(q[0], q[1]);
     1033            gFunc.define(q[0], q[2]);
     1034            bFunc.define(q[0], q[3]);
    10331035        }
    10341036        for (i=0; i < wmapc; i += 2) {
    1035             double vals[2];
     1037            double q[2];
    10361038            int j;
    10371039
    10381040            for (j=0; j < 2; j++) {
    1039                 if (Tcl_GetDoubleFromObj(interp, wmapv[i+j], &vals[j]) != TCL_OK) {
     1041                if (Tcl_GetDoubleFromObj(interp, wmapv[i+j], &q[j]) != TCL_OK) {
    10401042                    return TCL_ERROR;
    10411043                }
    1042                 if ((vals[j] < 0.0) || (vals[j] > 1.0)) {
    1043                     Tcl_AppendResult(interp, "bad value \"", wmapv[i+j],
    1044                                      "\": should be in the range 0-1", (char*)NULL);
     1044                if ((q[j] < 0.0) || (q[j] > 1.0)) {
     1045                    Tcl_AppendResult(interp, "bad alphamap value \"",
     1046                        Tcl_GetString(wmapv[i+j]),
     1047                        "\": should be in the range 0-1", (char*)NULL);
    10451048                    return TCL_ERROR;
    10461049                }
    10471050            }
    1048             wFunc.define(vals[0], vals[1]);
     1051            wFunc.define(q[0], q[1]);
    10491052        }
    10501053        // sample the given function into discrete slots
     
    10521055        float data[4*nslots];
    10531056        for (i=0; i < nslots; i++) {
    1054             double xval = double(i)/(nslots-1);
    1055             data[4*i]   = rFunc.value(xval);
    1056             data[4*i+1] = gFunc.value(xval);
    1057             data[4*i+2] = bFunc.value(xval);
    1058             data[4*i+3] = wFunc.value(xval);
    1059         }
    1060 
     1057            double x = double(i)/(nslots-1);
     1058            data[4*i]   = rFunc.value(x);
     1059            data[4*i+1] = gFunc.value(x);
     1060            data[4*i+2] = bFunc.value(x);
     1061            data[4*i+3] = wFunc.value(x);
     1062        }
    10611063        // find or create this transfer function
    1062         TransferFunction *tf;
    1063         tf = NanoVis::get_transfunc(Tcl_GetString(objv[2]));
    1064         if (tf != NULL) {
    1065             tf->update(data);
    1066         } else {
    1067             tf = NanoVis::set_transfunc(Tcl_GetString(objv[2]), nslots, data);
    1068         }
     1064        NanoVis::DefineTransferFunction(Tcl_GetString(objv[2]), nslots, data);
    10691065    } else {
    10701066        Tcl_AppendResult(interp, "bad option \"", string,
    1071                          "\": should be define", (char*)NULL);
     1067                "\": should be define", (char*)NULL);
    10721068        return TCL_ERROR;
    10731069    }
  • trunk/vizservers/nanovis/RpDX.cpp

    r969 r973  
    4949        // error
    5050    }
    51 
    5251    // open the file with libdx
    5352    fprintf(stdout, "Calling DXImportDX(%s)\n", filename);
  • trunk/vizservers/nanovis/TransferFunction.cpp

    r830 r973  
    1818#include "TransferFunction.h"
    1919#include <memory.h>
     20#include <assert.h>
    2021
    21 
    22 TransferFunction::TransferFunction(int _size, float* data)
     22TransferFunction::TransferFunction(int size, float *data)
    2323{
    24     tex = new Texture1D(_size, GL_FLOAT);
     24    _tex = new Texture1D(size, GL_FLOAT);
    2525
    2626    // _size : # of slot, 4 : rgba
    27     size = _size * 4;
    28     this->data = new float[size];
    29     memcpy(this->data, data, sizeof(float) * size);
     27    _size = size * 4;
     28    _data = new float[_size];
     29    memcpy(_data, data, sizeof(float) * _size);
    3030
    31     tex->initialize_float_rgba(data);
    32     id = tex->id;
     31    _tex->initialize_float_rgba(_data);
     32    id = _tex->id;
    3333}
    3434
     
    3636TransferFunction::~TransferFunction()
    3737{
    38     delete [] data;
    39     delete tex;
     38    delete [] _data;
     39    delete _tex;
    4040}
    4141
    42 void TransferFunction::update(float* data)
     42void
     43TransferFunction::update(float* data)
    4344{
    44     memcpy(this->data, data, sizeof(float) * size);
    45 
    46     tex->update_float_rgba(data);
     45    memcpy(_data, data, sizeof(float) * _size);
     46    _tex->update_float_rgba(_data);
    4747}
    4848
    4949
     50void
     51TransferFunction::update(int size, float *data)
     52{
     53    assert((size*4) == _size);
     54    update(data);
     55}
     56
  • trunk/vizservers/nanovis/TransferFunction.h

    r830 r973  
    2323
    2424class TransferFunction{
    25   int size;     //the resolution of the color map, how many (RGBA) quadraples
    26   float* data;
    27   Texture1D* tex; //the texture storing the colors
     25    int _size;                  //the resolution of the color map, how many
     26                                //(RGBA) quadraples
     27    float* _data;
     28    Texture1D* _tex;            //the texture storing the colors
     29   
     30public:
     31    GLuint id;                  //OpenGL's texture identifier
    2832
    29 public:
    30   GLuint id;    //OpenGL's texture identifier
    31   TransferFunction(int _size, float* data);
    32   ~TransferFunction();
    33   void update(float* data);
    34     Texture1D* getTexture();
    35   float* getData() { return data; }
     33    TransferFunction(int size, float *data);
     34    ~TransferFunction();
     35    void update(float *data);
     36    void update(int size, float *data);
     37    Texture1D* getTexture(void) {
     38        return _tex;
     39    }
     40    float* getData(void) {
     41        return _data;
     42    }
    3643};
    3744
    38 inline Texture1D* TransferFunction::getTexture()
    39 {
    40     return tex;
    41 }
    42 
    4345#endif
  • trunk/vizservers/nanovis/nanovis.cpp

    r955 r973  
    319319// Creates of updates a colormap 1D texture by name.
    320320TransferFunction*
    321 NanoVis::set_transfunc(const char *name, int nSlots, float *data)
     321NanoVis::DefineTransferFunction(const char *name, size_t n, float *data)
    322322{
    323323    int isNew;
     
    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(n, data);
     330        Tcl_SetHashValue(hPtr, (ClientData)tf);
    331331    } else {
    332         tf = (TransferFunction*)Tcl_GetHashValue(hPtr);
    333         tf->update(data);
     332        /*
     333         * You can't delete the transfer function because many
     334         * objects may be holding its pointer.  We must update it.
     335         */
     336        tf = (TransferFunction *)Tcl_GetHashValue(hPtr);
     337        tf->update(n, data);
    334338    }
    335339    return tf;
  • trunk/vizservers/nanovis/nanovis.h

    r932 r973  
    140140
    141141    static TransferFunction* get_transfunc(const char *name);
    142     static TransferFunction* set_transfunc(const char *name, int nSlots,
    143                                           float *data);
     142    static TransferFunction* DefineTransferFunction(const char *name,
     143        size_t n, float *data);
    144144    static void SetVolumeRanges(void);
    145145    static void SetHeightmapRanges(void);
Note: See TracChangeset for help on using the changeset viewer.