Changeset 973 for trunk/vizservers
- Timestamp:
- Mar 29, 2008, 10:40:15 PM (16 years ago)
- Location:
- trunk/vizservers/nanovis
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/vizservers/nanovis/Command.cpp
r958 r973 973 973 */ 974 974 static int 975 TransfuncCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST *objv) 975 TransfuncCmd(ClientData cdata, Tcl_Interp *interp, int objc, 976 Tcl_Obj *CONST *objv) 976 977 { 977 978 if (objc < 2) { 978 979 Tcl_AppendResult(interp, "wrong # args: should be \"", 979 980 Tcl_GetString(objv[0]), " option arg arg...\"", (char*)NULL); 980 981 return TCL_ERROR; 981 982 } … … 986 987 if (objc != 5) { 987 988 Tcl_AppendResult(interp, "wrong # args: should be \"", 988 Tcl_GetString(objv[0]), " define name colormap alphamap\"",989 989 Tcl_GetString(objv[0]), " define name colorMap alphaMap\"", 990 (char*)NULL); 990 991 return TCL_ERROR; 991 992 } … … 1002 1003 } 1003 1004 if ((cmapc % 4) != 0) { 1004 Tcl_AppendResult(interp, " bad colormap in transfunc: should be ",1005 1005 Tcl_AppendResult(interp, "wrong # elements is colormap: should be ", 1006 "{ v r g b ... }", (char*)NULL); 1006 1007 return TCL_ERROR; 1007 1008 } … … 1011 1012 if ((wmapc % 2) != 0) { 1012 1013 Tcl_AppendResult(interp, "wrong # elements in alphamap: should be ", 1013 1014 " { v w ... }", (char*)NULL); 1014 1015 return TCL_ERROR; 1015 1016 } 1016 1017 for (i = 0; i < cmapc; i += 4) { 1017 1018 int j; 1018 double vals[4];1019 double q[4]; 1019 1020 1020 1021 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) { 1022 1023 return TCL_ERROR; 1023 1024 } 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); 1027 1029 return TCL_ERROR; 1028 1030 } 1029 1031 } 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]); 1033 1035 } 1034 1036 for (i=0; i < wmapc; i += 2) { 1035 double vals[2];1037 double q[2]; 1036 1038 int j; 1037 1039 1038 1040 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) { 1040 1042 return TCL_ERROR; 1041 1043 } 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); 1045 1048 return TCL_ERROR; 1046 1049 } 1047 1050 } 1048 wFunc.define( vals[0], vals[1]);1051 wFunc.define(q[0], q[1]); 1049 1052 } 1050 1053 // sample the given function into discrete slots … … 1052 1055 float data[4*nslots]; 1053 1056 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 } 1061 1063 // 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); 1069 1065 } else { 1070 1066 Tcl_AppendResult(interp, "bad option \"", string, 1071 1067 "\": should be define", (char*)NULL); 1072 1068 return TCL_ERROR; 1073 1069 } -
trunk/vizservers/nanovis/RpDX.cpp
r969 r973 49 49 // error 50 50 } 51 52 51 // open the file with libdx 53 52 fprintf(stdout, "Calling DXImportDX(%s)\n", filename); -
trunk/vizservers/nanovis/TransferFunction.cpp
r830 r973 18 18 #include "TransferFunction.h" 19 19 #include <memory.h> 20 #include <assert.h> 20 21 21 22 TransferFunction::TransferFunction(int _size, float* data) 22 TransferFunction::TransferFunction(int size, float *data) 23 23 { 24 tex = new Texture1D(_size, GL_FLOAT);24 _tex = new Texture1D(size, GL_FLOAT); 25 25 26 26 // _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); 30 30 31 tex->initialize_float_rgba(data);32 id = tex->id;31 _tex->initialize_float_rgba(_data); 32 id = _tex->id; 33 33 } 34 34 … … 36 36 TransferFunction::~TransferFunction() 37 37 { 38 delete [] data;39 delete tex;38 delete [] _data; 39 delete _tex; 40 40 } 41 41 42 void TransferFunction::update(float* data) 42 void 43 TransferFunction::update(float* data) 43 44 { 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); 47 47 } 48 48 49 49 50 void 51 TransferFunction::update(int size, float *data) 52 { 53 assert((size*4) == _size); 54 update(data); 55 } 56 -
trunk/vizservers/nanovis/TransferFunction.h
r830 r973 23 23 24 24 class 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 30 public: 31 GLuint id; //OpenGL's texture identifier 28 32 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 } 36 43 }; 37 44 38 inline Texture1D* TransferFunction::getTexture()39 {40 return tex;41 }42 43 45 #endif -
trunk/vizservers/nanovis/nanovis.cpp
r955 r973 319 319 // Creates of updates a colormap 1D texture by name. 320 320 TransferFunction* 321 NanoVis:: set_transfunc(const char *name, int nSlots, float *data)321 NanoVis::DefineTransferFunction(const char *name, size_t n, float *data) 322 322 { 323 323 int isNew; … … 327 327 hPtr = Tcl_CreateHashEntry(&tftable, name, &isNew); 328 328 if (isNew) { 329 tf = new TransferFunction(nSlots, data);330 329 tf = new TransferFunction(n, data); 330 Tcl_SetHashValue(hPtr, (ClientData)tf); 331 331 } 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); 334 338 } 335 339 return tf; -
trunk/vizservers/nanovis/nanovis.h
r932 r973 140 140 141 141 static TransferFunction* get_transfunc(const char *name); 142 static TransferFunction* set_transfunc(const char *name, int nSlots,143 142 static TransferFunction* DefineTransferFunction(const char *name, 143 size_t n, float *data); 144 144 static void SetVolumeRanges(void); 145 145 static void SetHeightmapRanges(void);
Note: See TracChangeset
for help on using the changeset viewer.