Changeset 4819 for nanovis


Ignore:
Timestamp:
Dec 6, 2014 7:16:39 PM (9 years ago)
Author:
ldelgass
Message:

merge r4067 from trunk

Location:
nanovis/branches/1.1
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • nanovis/branches/1.1

  • nanovis/branches/1.1/Command.cpp

    r4818 r4819  
    3838#include <tcl.h>
    3939
    40 #include <RpField1D.h>
    4140#include <RpEncode.h>
    4241#include <RpOutcome.h>
     
    981980
    982981        // decode the data and store in a series of fields
    983         Rappture::Field1D rFunc, gFunc, bFunc, aFunc;
    984982        int cmapc, amapc, i;
    985983        Tcl_Obj **cmapv;
     
    10031001            return TCL_ERROR;
    10041002        }
     1003
     1004        int numColors = cmapc/4;
     1005        float *colorKeys = new float[numColors];
     1006        Vector3f *colors = new Vector3f[numColors];
    10051007        for (i = 0; i < cmapc; i += 4) {
    10061008            int j;
     
    10181020                }
    10191021            }
    1020             rFunc.define(q[0], q[1]);
    1021             gFunc.define(q[0], q[2]);
    1022             bFunc.define(q[0], q[3]);
    1023         }
     1022
     1023            colorKeys[i/4] = (float)q[0];
     1024            colors[i/4].set((float)q[1], (float)q[2], (float)q[3]);
     1025        }
     1026        int numAlphas = amapc/2;
     1027        float *alphaKeys = new float[numAlphas];
     1028        float *alphas = new float[numAlphas];
    10241029        for (i=0; i < amapc; i += 2) {
    10251030            double q[2];
     
    10371042                }
    10381043            }
    1039             aFunc.define(q[0], q[1]);
     1044            alphaKeys[i/2] = (float)q[0];
     1045            alphas[i/2] = (float)q[1];
    10401046        }
    10411047        // sample the given function into discrete slots
     
    10431049        float data[4*nslots];
    10441050        for (i=0; i < nslots; i++) {
    1045             double x = double(i)/(nslots-1);
    1046             data[4*i]   = rFunc.value(x);
    1047             data[4*i+1] = gFunc.value(x);
    1048             data[4*i+2] = bFunc.value(x);
    1049             data[4*i+3] = aFunc.value(x);
    1050         }
     1051            float x = float(i)/(nslots-1);
     1052            Vector3f color;
     1053            float alpha;
     1054            TransferFunction::sample(x, colorKeys, colors, numColors, &color);
     1055            TransferFunction::sample(x, alphaKeys, alphas, numAlphas, &alpha);
     1056
     1057            data[4*i]   = color.r;
     1058            data[4*i+1] = color.g;
     1059            data[4*i+2] = color.b;
     1060            data[4*i+3] = alpha;
     1061        }
     1062        delete [] colorKeys;
     1063        delete [] colors;
     1064        delete [] alphaKeys;
     1065        delete [] alphas;
    10511066        // find or create this transfer function
    10521067        NanoVis::defineTransferFunction(Tcl_GetString(objv[2]), nslots, data);
  • nanovis/branches/1.1/TransferFunction.cpp

    r3568 r4819  
    5858
    5959void
    60 TransferFunction::sample(float fraction, float *key, int count, Vector3f *keyValue, Vector3f *ret)
     60TransferFunction::sample(float fraction, float *keys, Vector3f *keyValues, int count, Vector3f *ret)
    6161{
    6262    int limit = count - 1;
    63     if (fraction <= key[0]) {
    64         *ret = keyValue[0];
    65     } else if (fraction >= key[limit]) {
    66         *ret = keyValue[limit];
     63    if (fraction <= keys[0]) {
     64        *ret = keyValues[0];
     65    } else if (fraction >= keys[limit]) {
     66        *ret = keyValues[limit];
    6767    } else {
    6868        int n;
    69         for (n = 0; n < limit; n++){
    70             if (fraction >= key[n] && fraction < key[n+1]) break;
     69        for (n = 0; n < limit; n++) {
     70            if (fraction >= keys[n] && fraction < keys[n+1]) break;
    7171        }
    7272        if (n >= limit) {
    73             *ret = keyValue[limit];
     73            *ret = keyValues[limit];
    7474        } else {
    75             float inter = (fraction - key[n]) / (key[n + 1] - key[n]);
    76             ret->set(inter * (keyValue[n + 1].x - keyValue[n].x) + keyValue[n].x,
    77                      inter * (keyValue[n + 1].y - keyValue[n].y) + keyValue[n].y,
    78                      inter * (keyValue[n + 1].z - keyValue[n].z) + keyValue[n].z);
     75            float inter = (fraction - keys[n]) / (keys[n + 1] - keys[n]);
     76            ret->set(inter * (keyValues[n + 1].x - keyValues[n].x) + keyValues[n].x,
     77                     inter * (keyValues[n + 1].y - keyValues[n].y) + keyValues[n].y,
     78                     inter * (keyValues[n + 1].z - keyValues[n].z) + keyValues[n].z);
    7979        }
    8080    }
     
    8282
    8383void
    84 TransferFunction::sample(float fraction, float *key, int count, float *keyValue, float *ret)
     84TransferFunction::sample(float fraction, float *keys, float *keyValues, int count, float *ret)
    8585{
    8686    int limit = count - 1;
    87     if (fraction <= key[0]) {
    88         *ret = keyValue[0];
    89     } else if (fraction >= key[limit]) {
    90         *ret = keyValue[limit];
     87    if (fraction <= keys[0]) {
     88        *ret = keyValues[0];
     89    } else if (fraction >= keys[limit]) {
     90        *ret = keyValues[limit];
    9191    } else {
    9292        int n;
    93         for (n = 0; n < limit; n++){
    94             if (fraction >= key[n] && fraction < key[n+1]) break;
     93        for (n = 0; n < limit; n++) {
     94            if (fraction >= keys[n] && fraction < keys[n+1]) break;
    9595        }
    9696        if (n >= limit) {
    97             *ret = keyValue[limit];
     97            *ret = keyValues[limit];
    9898        } else {
    99             float inter = (fraction - key[n]) / (key[n + 1] - key[n]);
    100             *ret = inter * (keyValue[n + 1] - keyValue[n]) + keyValue[n];
     99            float inter = (fraction - keys[n]) / (keys[n + 1] - keys[n]);
     100            *ret = inter * (keyValues[n + 1] - keyValues[n]) + keyValues[n];
    101101        }
    102102    }
  • nanovis/branches/1.1/TransferFunction.h

    r3568 r4819  
    6262    }
    6363
    64     static void sample(float fraction, float *key, int count, vrmath::Vector3f *keyValue, vrmath::Vector3f *ret);
     64    static void sample(float fraction, float *keys, vrmath::Vector3f *keyValues, int count, vrmath::Vector3f *ret);
    6565
    66     static void sample(float fraction, float *key, int count, float *keyValue, float *ret);
     66    static void sample(float fraction, float *keys, float *keyValues, int count, float *ret);
    6767
    6868protected :
Note: See TracChangeset for help on using the changeset viewer.