Changeset 4067
- Timestamp:
- Nov 15, 2013, 7:29:27 PM (11 years ago)
- Location:
- trunk/packages/vizservers/nanovis
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/Command.cpp
r4063 r4067 39 39 #include <tcl.h> 40 40 41 #include <RpField1D.h>42 41 #include <RpEncode.h> 43 42 #include <RpBuffer.h> … … 1038 1037 1039 1038 // 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; 1042 1040 Tcl_Obj **cmapv; 1043 Tcl_Obj ** wmapv;1044 1045 wmapv = cmapv = NULL;1041 Tcl_Obj **amapv; 1042 1043 amapv = cmapv = NULL; 1046 1044 if (Tcl_ListObjGetElements(interp, objv[3], &cmapc, &cmapv) != TCL_OK) { 1047 1045 return TCL_ERROR; … … 1052 1050 return TCL_ERROR; 1053 1051 } 1054 if (Tcl_ListObjGetElements(interp, objv[4], & wmapc, &wmapv) != TCL_OK) {1052 if (Tcl_ListObjGetElements(interp, objv[4], &amapc, &amapv) != TCL_OK) { 1055 1053 return TCL_ERROR; 1056 1054 } 1057 if (( wmapc % 2) != 0) {1055 if ((amapc % 2) != 0) { 1058 1056 Tcl_AppendResult(interp, "wrong # elements in alphamap: should be ", 1059 1057 " { v w ... }", (char*)NULL); 1060 1058 return TCL_ERROR; 1061 1059 } 1060 1061 int numColors = cmapc/4; 1062 float *colorKeys = new float[numColors]; 1063 Vector3f *colors = new Vector3f[numColors]; 1062 1064 for (i = 0; i < cmapc; i += 4) { 1063 1065 int j; … … 1075 1077 } 1076 1078 } 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) { 1082 1087 double q[2]; 1083 1088 int j; 1084 1089 1085 1090 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) { 1087 1092 return TCL_ERROR; 1088 1093 } 1089 1094 if ((q[j] < 0.0) || (q[j] > 1.0)) { 1090 1095 Tcl_AppendResult(interp, "bad alphamap value \"", 1091 Tcl_GetString( wmapv[i+j]),1096 Tcl_GetString(amapv[i+j]), 1092 1097 "\": should be in the range 0-1", (char*)NULL); 1093 1098 return TCL_ERROR; 1094 1099 } 1095 1100 } 1096 wFunc.define(q[0], q[1]); 1101 1102 alphaKeys[i/2] = (float)q[0]; 1103 alphas[i/2] = (float)q[1]; 1097 1104 } 1098 1105 // sample the given function into discrete slots … … 1100 1107 float data[4*nslots]; 1101 1108 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; 1108 1124 // find or create this transfer function 1109 1125 NanoVis::defineTransferFunction(Tcl_GetString(objv[2]), nslots, data); -
trunk/packages/vizservers/nanovis/TransferFunction.cpp
r3611 r4067 59 59 60 60 void 61 TransferFunction::sample(float fraction, float *key , int count, Vector3f *keyValue, Vector3f *ret)61 TransferFunction::sample(float fraction, float *keys, Vector3f *keyValues, int count, Vector3f *ret) 62 62 { 63 63 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]; 68 68 } else { 69 69 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; 72 72 } 73 73 if (n >= limit) { 74 *ret = keyValue [limit];74 *ret = keyValues[limit]; 75 75 } 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); 80 80 } 81 81 } … … 83 83 84 84 void 85 TransferFunction::sample(float fraction, float *key , int count, float *keyValue, float *ret)85 TransferFunction::sample(float fraction, float *keys, float *keyValues, int count, float *ret) 86 86 { 87 87 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]; 92 92 } else { 93 93 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; 96 96 } 97 97 if (n >= limit) { 98 *ret = keyValue [limit];98 *ret = keyValues[limit]; 99 99 } 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]; 102 102 } 103 103 } -
trunk/packages/vizservers/nanovis/TransferFunction.h
r3613 r4067 64 64 } 65 65 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); 67 67 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); 69 69 70 70 protected :
Note: See TracChangeset
for help on using the changeset viewer.