Changeset 4067


Ignore:
Timestamp:
Nov 15, 2013 7:29:27 PM (10 years ago)
Author:
ldelgass
Message:

Use TransferFunction::sample() instead of Rappture::Field1D

Location:
trunk/packages/vizservers/nanovis
Files:
3 edited

Legend:

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

    r4063 r4067  
    3939#include <tcl.h>
    4040
    41 #include <RpField1D.h>
    4241#include <RpEncode.h>
    4342#include <RpBuffer.h>
     
    10381037
    10391038        // decode the data and store in a series of fields
    1040         Rappture::Field1D rFunc, gFunc, bFunc, wFunc;
    1041         int cmapc, wmapc, i;
     1039        int cmapc, amapc, i;
    10421040        Tcl_Obj **cmapv;
    1043         Tcl_Obj **wmapv;
    1044 
    1045         wmapv = cmapv = NULL;
     1041        Tcl_Obj **amapv;
     1042
     1043        amapv = cmapv = NULL;
    10461044        if (Tcl_ListObjGetElements(interp, objv[3], &cmapc, &cmapv) != TCL_OK) {
    10471045            return TCL_ERROR;
     
    10521050            return TCL_ERROR;
    10531051        }
    1054         if (Tcl_ListObjGetElements(interp, objv[4], &wmapc, &wmapv) != TCL_OK) {
     1052        if (Tcl_ListObjGetElements(interp, objv[4], &amapc, &amapv) != TCL_OK) {
    10551053            return TCL_ERROR;
    10561054        }
    1057         if ((wmapc % 2) != 0) {
     1055        if ((amapc % 2) != 0) {
    10581056            Tcl_AppendResult(interp, "wrong # elements in alphamap: should be ",
    10591057                " { v w ... }", (char*)NULL);
    10601058            return TCL_ERROR;
    10611059        }
     1060
     1061        int numColors = cmapc/4;
     1062        float *colorKeys = new float[numColors];
     1063        Vector3f *colors = new Vector3f[numColors];
    10621064        for (i = 0; i < cmapc; i += 4) {
    10631065            int j;
     
    10751077                }
    10761078            }
    1077             rFunc.define(q[0], q[1]);
    1078             gFunc.define(q[0], q[2]);
    1079             bFunc.define(q[0], q[3]);
    1080         }
    1081         for (i=0; i < wmapc; i += 2) {
     1079
     1080            colorKeys[i/4] = (float)q[0];
     1081            colors[i/4].set((float)q[1], (float)q[2], (float)q[3]);
     1082        }
     1083        int numAlphas = amapc/2;
     1084        float *alphaKeys = new float[numAlphas];
     1085        float *alphas = new float[numAlphas];
     1086        for (i=0; i < amapc; i += 2) {
    10821087            double q[2];
    10831088            int j;
    10841089
    10851090            for (j=0; j < 2; j++) {
    1086                 if (Tcl_GetDoubleFromObj(interp, wmapv[i+j], &q[j]) != TCL_OK) {
     1091                if (Tcl_GetDoubleFromObj(interp, amapv[i+j], &q[j]) != TCL_OK) {
    10871092                    return TCL_ERROR;
    10881093                }
    10891094                if ((q[j] < 0.0) || (q[j] > 1.0)) {
    10901095                    Tcl_AppendResult(interp, "bad alphamap value \"",
    1091                         Tcl_GetString(wmapv[i+j]),
     1096                        Tcl_GetString(amapv[i+j]),
    10921097                        "\": should be in the range 0-1", (char*)NULL);
    10931098                    return TCL_ERROR;
    10941099                }
    10951100            }
    1096             wFunc.define(q[0], q[1]);
     1101
     1102            alphaKeys[i/2] = (float)q[0];
     1103            alphas[i/2] = (float)q[1];
    10971104        }
    10981105        // sample the given function into discrete slots
     
    11001107        float data[4*nslots];
    11011108        for (i=0; i < nslots; i++) {
    1102             double x = double(i)/(nslots-1);
    1103             data[4*i]   = rFunc.value(x);
    1104             data[4*i+1] = gFunc.value(x);
    1105             data[4*i+2] = bFunc.value(x);
    1106             data[4*i+3] = wFunc.value(x);
    1107         }
     1109            float x = float(i)/(nslots-1);
     1110            Vector3f color;
     1111            float alpha;
     1112            TransferFunction::sample(x, colorKeys, colors, numColors, &color);
     1113            TransferFunction::sample(x, alphaKeys, alphas, numAlphas, &alpha);
     1114
     1115            data[4*i]   = color.r;
     1116            data[4*i+1] = color.g;
     1117            data[4*i+2] = color.b;
     1118            data[4*i+3] = alpha;
     1119        }
     1120        delete [] colorKeys;
     1121        delete [] colors;
     1122        delete [] alphaKeys;
     1123        delete [] alphas;
    11081124        // find or create this transfer function
    11091125        NanoVis::defineTransferFunction(Tcl_GetString(objv[2]), nslots, data);
  • trunk/packages/vizservers/nanovis/TransferFunction.cpp

    r3611 r4067  
    5959
    6060void
    61 TransferFunction::sample(float fraction, float *key, int count, Vector3f *keyValue, Vector3f *ret)
     61TransferFunction::sample(float fraction, float *keys, Vector3f *keyValues, int count, Vector3f *ret)
    6262{
    6363    int limit = count - 1;
    64     if (fraction <= key[0]) {
    65         *ret = keyValue[0];
    66     } else if (fraction >= key[limit]) {
    67         *ret = keyValue[limit];
     64    if (fraction <= keys[0]) {
     65        *ret = keyValues[0];
     66    } else if (fraction >= keys[limit]) {
     67        *ret = keyValues[limit];
    6868    } else {
    6969        int n;
    70         for (n = 0; n < limit; n++){
    71             if (fraction >= key[n] && fraction < key[n+1]) break;
     70        for (n = 0; n < limit; n++) {
     71            if (fraction >= keys[n] && fraction < keys[n+1]) break;
    7272        }
    7373        if (n >= limit) {
    74             *ret = keyValue[limit];
     74            *ret = keyValues[limit];
    7575        } else {
    76             float inter = (fraction - key[n]) / (key[n + 1] - key[n]);
    77             ret->set(inter * (keyValue[n + 1].x - keyValue[n].x) + keyValue[n].x,
    78                      inter * (keyValue[n + 1].y - keyValue[n].y) + keyValue[n].y,
    79                      inter * (keyValue[n + 1].z - keyValue[n].z) + keyValue[n].z);
     76            float inter = (fraction - keys[n]) / (keys[n + 1] - keys[n]);
     77            ret->set(inter * (keyValues[n + 1].x - keyValues[n].x) + keyValues[n].x,
     78                     inter * (keyValues[n + 1].y - keyValues[n].y) + keyValues[n].y,
     79                     inter * (keyValues[n + 1].z - keyValues[n].z) + keyValues[n].z);
    8080        }
    8181    }
     
    8383
    8484void
    85 TransferFunction::sample(float fraction, float *key, int count, float *keyValue, float *ret)
     85TransferFunction::sample(float fraction, float *keys, float *keyValues, int count, float *ret)
    8686{
    8787    int limit = count - 1;
    88     if (fraction <= key[0]) {
    89         *ret = keyValue[0];
    90     } else if (fraction >= key[limit]) {
    91         *ret = keyValue[limit];
     88    if (fraction <= keys[0]) {
     89        *ret = keyValues[0];
     90    } else if (fraction >= keys[limit]) {
     91        *ret = keyValues[limit];
    9292    } else {
    9393        int n;
    94         for (n = 0; n < limit; n++){
    95             if (fraction >= key[n] && fraction < key[n+1]) break;
     94        for (n = 0; n < limit; n++) {
     95            if (fraction >= keys[n] && fraction < keys[n+1]) break;
    9696        }
    9797        if (n >= limit) {
    98             *ret = keyValue[limit];
     98            *ret = keyValues[limit];
    9999        } else {
    100             float inter = (fraction - key[n]) / (key[n + 1] - key[n]);
    101             *ret = inter * (keyValue[n + 1] - keyValue[n]) + keyValue[n];
     100            float inter = (fraction - keys[n]) / (keys[n + 1] - keys[n]);
     101            *ret = inter * (keyValues[n + 1] - keyValues[n]) + keyValues[n];
    102102        }
    103103    }
  • trunk/packages/vizservers/nanovis/TransferFunction.h

    r3613 r4067  
    6464    }
    6565
    66     static void sample(float fraction, float *key, int count, vrmath::Vector3f *keyValue, vrmath::Vector3f *ret);
     66    static void sample(float fraction, float *keys, vrmath::Vector3f *keyValues, int count, vrmath::Vector3f *ret);
    6767
    68     static void sample(float fraction, float *key, int count, float *keyValue, float *ret);
     68    static void sample(float fraction, float *keys, float *keyValues, int count, float *ret);
    6969
    7070protected :
Note: See TracChangeset for help on using the changeset viewer.