- Timestamp:
- Aug 3, 2008, 11:49:26 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lang/perl/Rappture.xs
r872 r1089 10 10 using namespace std; 11 11 12 MODULE = Rappture 12 MODULE = Rappture PACKAGE = Rappture::RpLibrary 13 13 PROTOTYPES: ENABLE 14 14 … … 16 16 RpLibrary::new(filename = "") 17 17 char *filename 18 18 CODE: 19 19 RpLibrary *library; 20 21 22 23 20 if ((filename == NULL) || (*filename == '\0')) 21 library = new RpLibrary(); 22 else 23 library = new RpLibrary(filename); 24 24 25 25 if (library->isNull()) 26 26 { 27 27 delete library; 28 28 XSRETURN_UNDEF; 29 29 } 30 31 32 33 30 else 31 RETVAL = library; 32 OUTPUT: 33 RETVAL 34 34 35 35 void * 36 36 RpLibrary::DESTROY() 37 38 37 CODE: 38 RETVAL = 0; 39 39 40 40 const char * 41 41 RpLibrary::get( path ) 42 42 char *path 43 44 45 46 47 48 43 CODE: 44 string result; 45 result = THIS->get(path); 46 RETVAL = result.c_str(); 47 OUTPUT: 48 RETVAL 49 49 50 50 void … … 53 53 char *value 54 54 int append 55 56 55 CODE: 56 THIS->put(path,value,"",append); 57 57 58 58 void … … 62 62 int compress 63 63 int append 64 65 64 CODE: 65 THIS->putFile(path,fileName,compress,append); 66 66 67 67 void 68 68 RpLibrary::result() 69 70 71 69 CODE: 70 THIS->put("tool.version.rappture.language", "perl"); 71 THIS->result(); 72 72 73 MODULE = Rappture 73 MODULE = Rappture PACKAGE = Rappture::RpUnits 74 74 75 75 const char * … … 78 78 const char *toUnitsName 79 79 int showUnits 80 81 82 80 CODE: 81 string result; 82 result = RpUnits::convert(fromVal,toUnitsName,showUnits); 83 83 84 84 if (result.empty()) 85 85 XSRETURN_UNDEF; 86 86 87 88 89 87 RETVAL = result.c_str(); 88 OUTPUT: 89 RETVAL 90 90 91 MODULE = Rappture 91 MODULE = Rappture PACKAGE = Rappture::Utils 92 92 93 93 int … … 95 95 int percent 96 96 const char *message 97 98 99 100 97 CODE: 98 RETVAL = Rappture::Utils::progress(percent,message); 99 OUTPUT: 100 RETVAL -
trunk/packages/vizservers/nanovis/Command.cpp
r1072 r1089 28 28 * lots of extra error checking code. (almost there) 29 29 * o Convert GetVolumeIndices to GetVolumes. Goal is to remove 30 * all references of Nanovis::volume[] from this file. Don't 31 * want to know how volumes are stored. Same for heightmaps. 32 * o Rationalize volume id scheme. Right now it's the index in 30 * all references of Nanovis::volume[] from this file. Don't 31 * want to know how volumes are stored. Same for heightmaps. 32 * o Rationalize volume id scheme. Right now it's the index in 33 33 * the vector. 1) Use a list instead of a vector. 2) carry 34 34 * an id field that's a number that gets incremented each new volume. … … 108 108 109 109 // default transfer function 110 static const char def_transfunc[] = 110 static const char def_transfunc[] = 111 111 "transfunc define default {\n\ 112 112 0.0 1 1 1\n\ … … 152 152 153 153 static bool 154 GetBooleanFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, bool *boolPtr) 154 GetBooleanFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, bool *boolPtr) 155 155 { 156 156 int value; … … 176 176 177 177 static int 178 GetCullMode(Tcl_Interp *interp, Tcl_Obj *objPtr, 178 GetCullMode(Tcl_Interp *interp, Tcl_Obj *objPtr, 179 179 graphics::RenderContext::CullMode *modePtr) 180 180 { … … 187 187 *modePtr = graphics::RenderContext::BACK; 188 188 } else { 189 Tcl_AppendResult(interp, "invalid cull mode \"", string, 189 Tcl_AppendResult(interp, "invalid cull mode \"", string, 190 190 "\": should be front, back, or none\"", (char *)NULL); 191 191 return TCL_ERROR; … … 195 195 196 196 static int 197 GetShadingModel(Tcl_Interp *interp, Tcl_Obj *objPtr, 197 GetShadingModel(Tcl_Interp *interp, Tcl_Obj *objPtr, 198 198 graphics::RenderContext::ShadingModel *modelPtr) 199 199 { … … 205 205 *modelPtr = graphics::RenderContext::SMOOTH; 206 206 } else { 207 Tcl_AppendResult(interp, "bad shading model \"", string, 207 Tcl_AppendResult(interp, "bad shading model \"", string, 208 208 "\": should be flat or smooth", (char *)NULL); 209 209 return TCL_ERROR; … … 213 213 214 214 static int 215 GetPolygonMode(Tcl_Interp *interp, Tcl_Obj *objPtr, 215 GetPolygonMode(Tcl_Interp *interp, Tcl_Obj *objPtr, 216 216 graphics::RenderContext::PolygonMode *modePtr) 217 217 { … … 223 223 *modePtr = graphics::RenderContext::FILL; 224 224 } else { 225 Tcl_AppendResult(interp, "invalid polygon mode \"", string, 225 Tcl_AppendResult(interp, "invalid polygon mode \"", string, 226 226 "\": should be wireframe or fill\"", (char *)NULL); 227 227 return TCL_ERROR; … … 246 246 */ 247 247 static HeightMap * 248 CreateHeightMap(ClientData clientData, Tcl_Interp *interp, int objc, 248 CreateHeightMap(ClientData clientData, Tcl_Interp *interp, int objc, 249 249 Tcl_Obj *const *objv) 250 250 { … … 253 253 254 254 if (objc != 7) { 255 Tcl_AppendResult(interp, 255 Tcl_AppendResult(interp, 256 256 "wrong # of values: should be xMin yMin xMax yMax xNum yNum heights", 257 257 (char *)NULL); … … 259 259 } 260 260 if ((GetFloatFromObj(interp, objv[0], &xMin) != TCL_OK) || 261 (GetFloatFromObj(interp, objv[1], &yMin) != TCL_OK) || 261 (GetFloatFromObj(interp, objv[1], &yMin) != TCL_OK) || 262 262 (GetFloatFromObj(interp, objv[2], &xMax) != TCL_OK) || 263 263 (GetFloatFromObj(interp, objv[3], &yMax) != TCL_OK) || … … 283 283 heights = new float[nValues]; 284 284 if (heights == NULL) { 285 Tcl_AppendResult(interp, "can't allocate array of heights", 285 Tcl_AppendResult(interp, "can't allocate array of heights", 286 286 (char *)NULL); 287 287 return NULL; … … 320 320 } 321 321 if (index < 0) { 322 Tcl_AppendResult(interp, "can't have negative index \"", 322 Tcl_AppendResult(interp, "can't have negative index \"", 323 323 Tcl_GetString(objPtr), "\"", (char*)NULL); 324 324 return TCL_ERROR; … … 350 350 hmPtr = NanoVis::heightMap[index]; 351 351 if (hmPtr == NULL) { 352 Tcl_AppendResult(interp, "no heightmap defined for index \"", 352 Tcl_AppendResult(interp, "no heightmap defined for index \"", 353 353 Tcl_GetString(objPtr), "\"", (char*)NULL); 354 354 return TCL_ERROR; … … 379 379 } 380 380 if (index < 0) { 381 Tcl_AppendResult(interp, "can't have negative index \"", 381 Tcl_AppendResult(interp, "can't have negative index \"", 382 382 Tcl_GetString(objPtr), "\"", (char*)NULL); 383 383 return TCL_ERROR; … … 415 415 vol = NanoVis::volume[index]; 416 416 if (vol == NULL) { 417 Tcl_AppendResult(interp, "no volume defined for index \"", 417 Tcl_AppendResult(interp, "no volume defined for index \"", 418 418 Tcl_GetString(objPtr), "\"", (char*)NULL); 419 419 return TCL_ERROR; … … 660 660 int nRead; 661 661 662 chunk = (sizeof(buffer) < (unsigned int) nBytes) ? 662 chunk = (sizeof(buffer) < (unsigned int) nBytes) ? 663 663 sizeof(buffer) : nBytes; 664 664 nRead = fread(buffer, sizeof(char), chunk, stdin); … … 707 707 { 708 708 double xangle, yangle, zangle; 709 if ((Tcl_GetDoubleFromObj(interp, objv[2], &xangle) != TCL_OK) || 709 if ((Tcl_GetDoubleFromObj(interp, objv[2], &xangle) != TCL_OK) || 710 710 (Tcl_GetDoubleFromObj(interp, objv[3], &yangle) != TCL_OK) || 711 711 (Tcl_GetDoubleFromObj(interp, objv[4], &zangle) != TCL_OK)) { … … 752 752 Tcl_ObjCmdProc *proc; 753 753 754 proc = Rappture::GetOpFromObj(interp, nCameraOps, cameraOps, 754 proc = Rappture::GetOpFromObj(interp, nCameraOps, cameraOps, 755 755 Rappture::CMDSPEC_ARG1, objc, objv, 0); 756 756 if (proc == NULL) { … … 762 762 /*ARGSUSED*/ 763 763 static int 764 SnapshotCmd(ClientData cdata, Tcl_Interp *interp, int objc, 764 SnapshotCmd(ClientData cdata, Tcl_Interp *interp, int objc, 765 765 Tcl_Obj *const *objv) 766 766 { … … 785 785 786 786 static int 787 CutplanePositionOp(ClientData cdata, Tcl_Interp *interp, int objc, 787 CutplanePositionOp(ClientData cdata, Tcl_Interp *interp, int objc, 788 788 Tcl_Obj *const *objv) 789 789 { … … 792 792 return TCL_ERROR; 793 793 } 794 794 795 795 // keep this just inside the volume so it doesn't disappear 796 if (relval < 0.01f) { 797 relval = 0.01f; 798 } else if (relval > 0.99f) { 799 relval = 0.99f; 800 } 801 796 if (relval < 0.01f) { 797 relval = 0.01f; 798 } else if (relval > 0.99f) { 799 relval = 0.99f; 800 } 801 802 802 int axis; 803 803 if (GetAxisFromObj(interp, objv[3], &axis) != TCL_OK) { 804 804 return TCL_ERROR; 805 805 } 806 806 807 807 vector<Volume *> ivol; 808 808 if (GetVolumes(interp, objc - 4, objv + 4, &ivol) != TCL_OK) { … … 817 817 818 818 static int 819 CutplaneStateOp(ClientData cdata, Tcl_Interp *interp, int objc, 819 CutplaneStateOp(ClientData cdata, Tcl_Interp *interp, int objc, 820 820 Tcl_Obj *const *objv) 821 821 { … … 824 824 return TCL_ERROR; 825 825 } 826 826 827 827 int axis; 828 828 if (GetAxisFromObj(interp, objv[3], &axis) != TCL_OK) { 829 829 return TCL_ERROR; 830 830 } 831 831 832 832 vector<Volume *> ivol; 833 833 if (GetVolumes(interp, objc - 4, objv + 4, &ivol) != TCL_OK) { … … 838 838 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 839 839 (*iter)->enable_cutplane(axis); 840 } 840 } 841 841 } else { 842 842 vector<Volume *>::iterator iter; 843 843 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 844 844 (*iter)->disable_cutplane(axis); 845 } 845 } 846 846 } 847 847 return TCL_OK; … … 870 870 */ 871 871 static int 872 CutplaneCmd(ClientData cdata, Tcl_Interp *interp, int objc, 872 CutplaneCmd(ClientData cdata, Tcl_Interp *interp, int objc, 873 873 Tcl_Obj *const *objv) 874 874 { 875 875 Tcl_ObjCmdProc *proc; 876 876 877 proc = Rappture::GetOpFromObj(interp, nCutplaneOps, cutplaneOps, 877 proc = Rappture::GetOpFromObj(interp, nCutplaneOps, cutplaneOps, 878 878 Rappture::CMDSPEC_ARG1, objc, objv, 0); 879 879 if (proc == NULL) { … … 898 898 { 899 899 if (objc != 4) { 900 Tcl_AppendResult(interp, "wrong # args: should be \"", 900 Tcl_AppendResult(interp, "wrong # args: should be \"", 901 901 Tcl_GetString(objv[0]), " volIndex width height\"", (char*)NULL); 902 902 return TCL_ERROR; … … 910 910 tf = NanoVis::vol_renderer->get_volume_shading(volPtr); 911 911 if (tf == NULL) { 912 Tcl_AppendResult(interp, "no transfer function defined for volume \"", 912 Tcl_AppendResult(interp, "no transfer function defined for volume \"", 913 913 Tcl_GetString(objv[1]), "\"", (char*)NULL); 914 914 return TCL_ERROR; … … 942 942 { 943 943 if (objc != 3) { 944 Tcl_AppendResult(interp, "wrong # args: should be \"", 944 Tcl_AppendResult(interp, "wrong # args: should be \"", 945 945 Tcl_GetString(objv[0]), " width height\"", (char*)NULL); 946 946 return TCL_ERROR; … … 967 967 */ 968 968 static int 969 TransfuncCmd(ClientData cdata, Tcl_Interp *interp, int objc, 969 TransfuncCmd(ClientData cdata, Tcl_Interp *interp, int objc, 970 970 Tcl_Obj *const *objv) 971 971 { 972 972 if (objc < 2) { 973 Tcl_AppendResult(interp, "wrong # args: should be \"", 973 Tcl_AppendResult(interp, "wrong # args: should be \"", 974 974 Tcl_GetString(objv[0]), " option arg arg...\"", (char*)NULL); 975 975 return TCL_ERROR; … … 980 980 if ((c == 'd') && (strcmp(string, "define") == 0)) { 981 981 if (objc != 5) { 982 Tcl_AppendResult(interp, "wrong # args: should be \"", 983 Tcl_GetString(objv[0]), " define name colorMap alphaMap\"", 982 Tcl_AppendResult(interp, "wrong # args: should be \"", 983 Tcl_GetString(objv[0]), " define name colorMap alphaMap\"", 984 984 (char*)NULL); 985 985 return TCL_ERROR; … … 1018 1018 } 1019 1019 if ((q[j] < 0.0) || (q[j] > 1.0)) { 1020 Tcl_AppendResult(interp, "bad colormap value \"", 1021 Tcl_GetString(cmapv[i+j]), 1020 Tcl_AppendResult(interp, "bad colormap value \"", 1021 Tcl_GetString(cmapv[i+j]), 1022 1022 "\": should be in the range 0-1", (char*)NULL); 1023 1023 return TCL_ERROR; … … 1037 1037 } 1038 1038 if ((q[j] < 0.0) || (q[j] > 1.0)) { 1039 Tcl_AppendResult(interp, "bad alphamap value \"", 1039 Tcl_AppendResult(interp, "bad alphamap value \"", 1040 1040 Tcl_GetString(wmapv[i+j]), 1041 1041 "\": should be in the range 0-1", (char*)NULL); … … 1078 1078 { 1079 1079 if (objc != 2) { 1080 Tcl_AppendResult(interp, "wrong # args: should be \"", 1080 Tcl_AppendResult(interp, "wrong # args: should be \"", 1081 1081 Tcl_GetString(objv[0]), " x|y|z|-x|-y|-z\"", (char*)NULL); 1082 1082 return TCL_ERROR; … … 1094 1094 1095 1095 static int 1096 VolumeAnimationCaptureOp(ClientData cdata, Tcl_Interp *interp, int objc, 1096 VolumeAnimationCaptureOp(ClientData cdata, Tcl_Interp *interp, int objc, 1097 1097 Tcl_Obj *const *objv) 1098 1098 { … … 1102 1102 } 1103 1103 VolumeInterpolator* interpolator; 1104 interpolator = NanoVis::vol_renderer->getVolumeInterpolator(); 1104 interpolator = NanoVis::vol_renderer->getVolumeInterpolator(); 1105 1105 interpolator->start(); 1106 1106 if (interpolator->is_started()) { … … 1108 1108 for (int frame_num = 0; frame_num < total; ++frame_num) { 1109 1109 float fraction; 1110 1110 1111 1111 fraction = ((float)frame_num) / (total - 1); 1112 1112 Trace("fraction : %f\n", fraction); 1113 1113 //interpolator->update(((float)frame_num) / (total - 1)); 1114 1114 interpolator->update(fraction); 1115 1115 1116 1116 NanoVis::offscreen_buffer_capture(); //enable offscreen render 1117 1117 1118 1118 NanoVis::display(); 1119 1119 NanoVis::read_screen(); 1120 1120 1121 1121 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1122 1122 1123 1123 NanoVis::bmp_write_to_file(frame_num, fileName); 1124 1124 } … … 1128 1128 1129 1129 static int 1130 VolumeAnimationClearOp(ClientData cdata, Tcl_Interp *interp, int objc, 1130 VolumeAnimationClearOp(ClientData cdata, Tcl_Interp *interp, int objc, 1131 1131 Tcl_Obj *const *objv) 1132 1132 { … … 1136 1136 1137 1137 static int 1138 VolumeAnimationStartOp(ClientData cdata, Tcl_Interp *interp, int objc, 1138 VolumeAnimationStartOp(ClientData cdata, Tcl_Interp *interp, int objc, 1139 1139 Tcl_Obj *const *objv) 1140 1140 { … … 1144 1144 1145 1145 static int 1146 VolumeAnimationStopOp(ClientData cdata, Tcl_Interp *interp, int objc, 1146 VolumeAnimationStopOp(ClientData cdata, Tcl_Interp *interp, int objc, 1147 1147 Tcl_Obj *const *objv) 1148 1148 { … … 1152 1152 1153 1153 static int 1154 VolumeAnimationVolumesOp(ClientData cdata, Tcl_Interp *interp, int objc, 1154 VolumeAnimationVolumesOp(ClientData cdata, Tcl_Interp *interp, int objc, 1155 1155 Tcl_Obj *const *objv) 1156 1156 { … … 1179 1179 1180 1180 static int 1181 VolumeAnimationOp(ClientData cdata, Tcl_Interp *interp, int objc, 1181 VolumeAnimationOp(ClientData cdata, Tcl_Interp *interp, int objc, 1182 1182 Tcl_Obj *const *objv) 1183 1183 { 1184 1184 Tcl_ObjCmdProc *proc; 1185 1185 1186 proc = Rappture::GetOpFromObj(interp, nVolumeAnimationOps, volumeAnimationOps, 1186 proc = Rappture::GetOpFromObj(interp, nVolumeAnimationOps, volumeAnimationOps, 1187 1187 Rappture::CMDSPEC_ARG2, objc, objv, 0); 1188 1188 if (proc == NULL) { … … 1194 1194 1195 1195 static int 1196 VolumeDataFollowsOp(ClientData cdata, Tcl_Interp *interp, int objc, 1196 VolumeDataFollowsOp(ClientData cdata, Tcl_Interp *interp, int objc, 1197 1197 Tcl_Obj *const *objv) 1198 1198 { 1199 1199 printf("Data Loading\n"); 1200 1200 fflush(stdout); 1201 1201 1202 1202 int nbytes; 1203 1203 if (Tcl_GetIntFromObj(interp, objv[3], &nbytes) != TCL_OK) { 1204 1204 return TCL_ERROR; 1205 1205 } 1206 1206 1207 1207 Rappture::Buffer buf; 1208 1208 if (GetDataStream(interp, buf, nbytes) != TCL_OK) { … … 1213 1213 memcpy(header, buf.bytes(), sizeof(char) * 5); 1214 1214 header[5] = '\0'; 1215 1215 1216 1216 #if _LOCAL_ZINC_TEST_ 1217 1217 //FILE* fp = fopen("/home/nanohub/vrinside/nv/data/HOON/QDWL_100_100_50_strain_8000i.nd_zatom_12_1", "rb"); 1218 1218 FILE* fp; 1219 1219 1220 1220 fp = fopen("/home/nanohub/vrinside/nv/data/HOON/GaAs_AlGaAs_2QD_B4.nd_zc_1_wf", "rb"); 1221 1221 if (fp == NULL) { … … 1232 1232 if (strcmp(header, "<HDR>") == 0) { 1233 1233 Volume* vol = NULL; 1234 1234 1235 1235 printf("ZincBlende stream is in\n"); 1236 1236 fflush(stdout); … … 1238 1238 //fdata.write(buf.bytes(),buf.size()); 1239 1239 //vol = NvZincBlendeReconstructor::getInstance()->loadFromStream(fdata); 1240 1240 1241 1241 #if _LOCAL_ZINC_TEST_ 1242 1242 vol = NvZincBlendeReconstructor::getInstance()->loadFromMemory(b); … … 1318 1318 NanoVis::volume[n]->disable_cutplane(1); 1319 1319 NanoVis::volume[n]->disable_cutplane(2); 1320 1320 1321 1321 NanoVis::vol_renderer->add_volume(NanoVis::volume[n], 1322 1322 NanoVis::get_transfunc("default")); 1323 1323 } 1324 1324 1325 1325 { 1326 1326 Volume *volPtr; 1327 1327 char info[1024]; 1328 1328 1329 1329 if (Volume::update_pending) { 1330 1330 NanoVis::SetVolumeRanges(); 1331 1331 } 1332 1332 volPtr = NanoVis::volume[n]; 1333 sprintf(info, "nv>data id %d min %g max %g vmin %g vmax %g\n", 1333 sprintf(info, "nv>data id %d min %g max %g vmin %g vmax %g\n", 1334 1334 n, volPtr->wAxis.Min(), volPtr->wAxis.Max(), 1335 1335 Volume::valueMin, Volume::valueMax); … … 1340 1340 1341 1341 static int 1342 VolumeDataStateOp(ClientData cdata, Tcl_Interp *interp, int objc, 1342 VolumeDataStateOp(ClientData cdata, Tcl_Interp *interp, int objc, 1343 1343 Tcl_Obj *const *objv) 1344 1344 { … … 1372 1372 1373 1373 static int 1374 VolumeDataOp(ClientData cdata, Tcl_Interp *interp, int objc, 1374 VolumeDataOp(ClientData cdata, Tcl_Interp *interp, int objc, 1375 1375 Tcl_Obj *const *objv) 1376 1376 { 1377 1377 Tcl_ObjCmdProc *proc; 1378 1378 1379 proc = Rappture::GetOpFromObj(interp, nVolumeDataOps, volumeDataOps, 1379 proc = Rappture::GetOpFromObj(interp, nVolumeDataOps, volumeDataOps, 1380 1380 Rappture::CMDSPEC_ARG2, objc, objv, 0); 1381 1381 if (proc == NULL) { … … 1386 1386 1387 1387 static int 1388 VolumeOutlineColorOp(ClientData cdata, Tcl_Interp *interp, int objc, 1388 VolumeOutlineColorOp(ClientData cdata, Tcl_Interp *interp, int objc, 1389 1389 Tcl_Obj *const *objv) 1390 1390 { … … 1405 1405 1406 1406 static int 1407 VolumeOutlineStateOp(ClientData cdata, Tcl_Interp *interp, int objc, 1407 VolumeOutlineStateOp(ClientData cdata, Tcl_Interp *interp, int objc, 1408 1408 Tcl_Obj *const *objv) 1409 1409 { … … 1439 1439 1440 1440 static int 1441 VolumeOutlineOp(ClientData cdata, Tcl_Interp *interp, int objc, 1441 VolumeOutlineOp(ClientData cdata, Tcl_Interp *interp, int objc, 1442 1442 Tcl_Obj *const *objv) 1443 1443 { 1444 1444 Tcl_ObjCmdProc *proc; 1445 1445 1446 proc = Rappture::GetOpFromObj(interp, nVolumeOutlineOps, volumeOutlineOps, 1447 1446 proc = Rappture::GetOpFromObj(interp, nVolumeOutlineOps, volumeOutlineOps, 1447 Rappture::CMDSPEC_ARG2, objc, objv, 0); 1448 1448 if (proc == NULL) { 1449 1449 return TCL_ERROR; … … 1453 1453 1454 1454 static int 1455 VolumeShadingDiffuseOp(ClientData cdata, Tcl_Interp *interp, int objc, 1455 VolumeShadingDiffuseOp(ClientData cdata, Tcl_Interp *interp, int objc, 1456 1456 Tcl_Obj *const *objv) 1457 1457 { … … 1473 1473 1474 1474 static int 1475 VolumeShadingIsosurfaceOp(ClientData cdata, Tcl_Interp *interp, int objc, 1475 VolumeShadingIsosurfaceOp(ClientData cdata, Tcl_Interp *interp, int objc, 1476 1476 Tcl_Obj *const *objv) 1477 1477 { … … 1492 1492 1493 1493 static int 1494 VolumeShadingOpacityOp(ClientData cdata, Tcl_Interp *interp, int objc, 1494 VolumeShadingOpacityOp(ClientData cdata, Tcl_Interp *interp, int objc, 1495 1495 Tcl_Obj *const *objv) 1496 1496 { … … 1513 1513 1514 1514 static int 1515 VolumeShadingSpecularOp(ClientData cdata, Tcl_Interp *interp, int objc, 1515 VolumeShadingSpecularOp(ClientData cdata, Tcl_Interp *interp, int objc, 1516 1516 Tcl_Obj *const *objv) 1517 1517 { … … 1532 1532 1533 1533 static int 1534 VolumeShadingTransFuncOp(ClientData cdata, Tcl_Interp *interp, int objc, 1534 VolumeShadingTransFuncOp(ClientData cdata, Tcl_Interp *interp, int objc, 1535 1535 Tcl_Obj *const *objv) 1536 1536 { … … 1571 1571 1572 1572 static int 1573 VolumeShadingOp(ClientData cdata, Tcl_Interp *interp, int objc, 1573 VolumeShadingOp(ClientData cdata, Tcl_Interp *interp, int objc, 1574 1574 Tcl_Obj *const *objv) 1575 1575 { 1576 1576 Tcl_ObjCmdProc *proc; 1577 1577 1578 proc = Rappture::GetOpFromObj(interp, nVolumeShadingOps, volumeShadingOps, 1578 proc = Rappture::GetOpFromObj(interp, nVolumeShadingOps, volumeShadingOps, 1579 1579 Rappture::CMDSPEC_ARG2, objc, objv, 0); 1580 1580 if (proc == NULL) { … … 1585 1585 1586 1586 static int 1587 VolumeAxisOp(ClientData cdata, Tcl_Interp *interp, int objc, 1587 VolumeAxisOp(ClientData cdata, Tcl_Interp *interp, int objc, 1588 1588 Tcl_Obj *const *objv) 1589 1589 { … … 1607 1607 } 1608 1608 } else { 1609 Tcl_AppendResult(interp, "bad option \"", string, 1609 Tcl_AppendResult(interp, "bad option \"", string, 1610 1610 "\": should be label", (char*)NULL); 1611 1611 return TCL_ERROR; … … 1615 1615 1616 1616 static int 1617 VolumeStateOp(ClientData cdata, Tcl_Interp *interp, int objc, 1617 VolumeStateOp(ClientData cdata, Tcl_Interp *interp, int objc, 1618 1618 Tcl_Obj *const *objv) 1619 1619 { … … 1641 1641 1642 1642 static int 1643 VolumeTestOp(ClientData cdata, Tcl_Interp *interp, int objc, 1643 VolumeTestOp(ClientData cdata, Tcl_Interp *interp, int objc, 1644 1644 Tcl_Obj *const *objv) 1645 1645 { … … 1681 1681 Tcl_ObjCmdProc *proc; 1682 1682 1683 proc = Rappture::GetOpFromObj(interp, nVolumeOps, volumeOps, 1683 proc = Rappture::GetOpFromObj(interp, nVolumeOps, volumeOps, 1684 1684 Rappture::CMDSPEC_ARG1, objc, objv, 0); 1685 1685 if (proc == NULL) { … … 1703 1703 if ((c == 'v') && (strcmp(string, "vectorid") == 0)) { 1704 1704 if (objc != 3) { 1705 Tcl_AppendResult(interp, "wrong # args: should be \"", 1705 Tcl_AppendResult(interp, "wrong # args: should be \"", 1706 1706 Tcl_GetString(objv[0]), " vectorid volume", (char *)NULL); 1707 1707 return TCL_ERROR; 1708 1708 } 1709 1709 Volume *volPtr; 1710 if (GetVolumeFromObj(interp, objv[2], &volPtr) != TCL_OK) { 1710 if (GetVolumeFromObj(interp, objv[2], &volPtr) != TCL_OK) { 1711 1711 return TCL_ERROR; 1712 1712 } 1713 1713 if (NanoVis::particleRenderer != NULL) { 1714 NanoVis::particleRenderer->setVectorField(volPtr->id, 1.0f, 1714 NanoVis::particleRenderer->setVectorField(volPtr->id, 1.0f, 1715 1715 volPtr->height / (float)volPtr->width, 1716 1716 volPtr->depth / (float)volPtr->width, … … 1739 1739 } else if ((c == 'p') && (strcmp(string, "particle") == 0)) { 1740 1740 if (objc < 3) { 1741 Tcl_AppendResult(interp, "wrong # args: should be \"", 1741 Tcl_AppendResult(interp, "wrong # args: should be \"", 1742 1742 Tcl_GetString(objv[0]), " particle visible|slice|slicepos arg \"", 1743 1743 (char*)NULL); … … 1748 1748 if ((c == 'v') && (strcmp(string, "visible") == 0)) { 1749 1749 if (objc != 4) { 1750 Tcl_AppendResult(interp, "wrong # args: should be \"", 1751 Tcl_GetString(objv[0]), " particle visible on|off\"", 1750 Tcl_AppendResult(interp, "wrong # args: should be \"", 1751 Tcl_GetString(objv[0]), " particle visible on|off\"", 1752 1752 (char*)NULL); 1753 1753 return TCL_ERROR; … … 1760 1760 } else if ((c == 's') && (strcmp(string, "slice") == 0)) { 1761 1761 if (objc != 4) { 1762 Tcl_AppendResult(interp, "wrong # args: should be \"", 1762 Tcl_AppendResult(interp, "wrong # args: should be \"", 1763 1763 Tcl_GetString(objv[0]), 1764 1764 " particle slice volume\"", (char*)NULL); … … 1772 1772 } else if ((c == 's') && (strcmp(string, "slicepos") == 0)) { 1773 1773 if (objc != 4) { 1774 Tcl_AppendResult(interp, "wrong # args: should be \"", 1775 Tcl_GetString(objv[0]), " particle slicepos value\"", 1774 Tcl_AppendResult(interp, "wrong # args: should be \"", 1775 Tcl_GetString(objv[0]), " particle slicepos value\"", 1776 1776 (char*)NULL); 1777 1777 return TCL_ERROR; … … 1799 1799 } else { 1800 1800 Tcl_AppendResult(interp, "unknown option \"", string, 1801 "\": should be \"", Tcl_GetString(objv[0]), 1801 "\": should be \"", Tcl_GetString(objv[0]), 1802 1802 " visible, slice, or slicepos\"", (char *)NULL); 1803 1803 return TCL_ERROR; … … 1807 1807 } else if ((c == 'c') && (strcmp(string, "capture") == 0)) { 1808 1808 if (objc > 4 || objc < 3) { 1809 Tcl_AppendResult(interp, "wrong # args: should be \"", 1810 Tcl_GetString(objv[0]), " capture numframes [directory]\"", 1809 Tcl_AppendResult(interp, "wrong # args: should be \"", 1810 Tcl_GetString(objv[0]), " capture numframes [directory]\"", 1811 1811 (char*)NULL); 1812 1812 return TCL_ERROR; … … 1828 1828 const char *fileName; 1829 1829 fileName = (objc < 4) ? NULL : Tcl_GetString(objv[3]); 1830 for (int frame_count = 0; frame_count < total_frame_count; 1830 for (int frame_count = 0; frame_count < total_frame_count; 1831 1831 frame_count++) { 1832 1832 1833 1833 // Generate the latest frame and send it back to the client 1834 if (NanoVis::licRenderer && 1834 if (NanoVis::licRenderer && 1835 1835 NanoVis::licRenderer->isActivated()) { 1836 NanoVis::licRenderer->convolve(); 1837 } 1838 if (NanoVis::particleRenderer && 1836 NanoVis::licRenderer->convolve(); 1837 } 1838 if (NanoVis::particleRenderer && 1839 1839 NanoVis::particleRenderer->isActivated()) { 1840 1840 NanoVis::particleRenderer->advect(); … … 1842 1842 NanoVis::offscreen_buffer_capture(); //enable offscreen render 1843 1843 NanoVis::display(); 1844 1844 1845 1845 // printf("Read Screen for Writing to file...\n"); 1846 1846 1847 1847 NanoVis::read_screen(); 1848 1848 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); … … 1851 1851 } 1852 1852 Trace("FLOW end\n"); 1853 // put your code... 1853 // put your code... 1854 1854 if (NanoVis::licRenderer) { 1855 1855 NanoVis::licRenderer->deactivate(); … … 1861 1861 } else if ((c == 'd') && (strcmp(string, "data") == 0)) { 1862 1862 if (objc < 3) { 1863 Tcl_AppendResult(interp, "wrong # args: should be \"", 1863 Tcl_AppendResult(interp, "wrong # args: should be \"", 1864 1864 Tcl_GetString(objv[0]), " data follows ?args?", (char *)NULL); 1865 1865 return TCL_ERROR; … … 1869 1869 if ((c == 'f') && (strcmp(string,"follows") == 0)) { 1870 1870 if (objc != 4) { 1871 Tcl_AppendResult(interp, "wrong # args: should be \"", 1872 Tcl_GetString(objv[0]), " data follows length", 1871 Tcl_AppendResult(interp, "wrong # args: should be \"", 1872 Tcl_GetString(objv[0]), " data follows length", 1873 1873 (char *)NULL); 1874 1874 return TCL_ERROR; … … 1902 1902 volPtr->disable_cutplane(2); 1903 1903 1904 NanoVis::vol_renderer->add_volume(volPtr, 1904 NanoVis::vol_renderer->add_volume(volPtr, 1905 1905 NanoVis::get_transfunc("default")); 1906 1906 } … … 1914 1914 1915 1915 static int 1916 HeightMapDataFollowsOp(ClientData cdata, Tcl_Interp *interp, int objc, 1916 HeightMapDataFollowsOp(ClientData cdata, Tcl_Interp *interp, int objc, 1917 1917 Tcl_Obj *const *objv) 1918 1918 { 1919 1919 Rappture::Buffer buf; 1920 1920 int nBytes; 1921 1921 1922 1922 if (Tcl_GetIntFromObj(interp, objv[3], &nBytes) != TCL_OK) { 1923 1923 return TCL_ERROR; … … 1937 1937 1938 1938 static int 1939 HeightMapDataVisibleOp(ClientData cdata, Tcl_Interp *interp, int objc, 1939 HeightMapDataVisibleOp(ClientData cdata, Tcl_Interp *interp, int objc, 1940 1940 Tcl_Obj *const *objv) 1941 1941 { … … 1961 1961 static int nHeightMapDataOps = NumCmdSpecs(heightMapDataOps); 1962 1962 1963 static int 1964 HeightMapDataOp(ClientData cdata, Tcl_Interp *interp, int objc, 1963 static int 1964 HeightMapDataOp(ClientData cdata, Tcl_Interp *interp, int objc, 1965 1965 Tcl_Obj *const *objv) 1966 1966 { 1967 1967 Tcl_ObjCmdProc *proc; 1968 1968 1969 proc = Rappture::GetOpFromObj(interp, nHeightMapDataOps, heightMapDataOps, 1969 proc = Rappture::GetOpFromObj(interp, nHeightMapDataOps, heightMapDataOps, 1970 1970 Rappture::CMDSPEC_ARG2, objc, objv, 0); 1971 1971 if (proc == NULL) { … … 1977 1977 1978 1978 static int 1979 HeightMapLineContourColorOp(ClientData cdata, Tcl_Interp *interp, int objc, 1979 HeightMapLineContourColorOp(ClientData cdata, Tcl_Interp *interp, int objc, 1980 1980 Tcl_Obj *const *objv) 1981 1981 { … … 1983 1983 if (GetColor(interp, objc - 3, objv + 3, rgb) != TCL_OK) { 1984 1984 return TCL_ERROR; 1985 } 1985 } 1986 1986 vector<HeightMap *> imap; 1987 1987 if (GetHeightMaps(interp, objc - 6, objv + 6, &imap) != TCL_OK) { … … 1996 1996 1997 1997 static int 1998 HeightMapLineContourVisibleOp(ClientData cdata, Tcl_Interp *interp, int objc, 1998 HeightMapLineContourVisibleOp(ClientData cdata, Tcl_Interp *interp, int objc, 1999 1999 Tcl_Obj *const *objv) 2000 2000 { … … 2021 2021 2022 2022 static int 2023 HeightMapLineContourOp(ClientData cdata, Tcl_Interp *interp, int objc, 2023 HeightMapLineContourOp(ClientData cdata, Tcl_Interp *interp, int objc, 2024 2024 Tcl_Obj *const *objv) 2025 2025 { 2026 2026 Tcl_ObjCmdProc *proc; 2027 2027 2028 proc = Rappture::GetOpFromObj(interp, nHeightMapLineContourOps, 2028 proc = Rappture::GetOpFromObj(interp, nHeightMapLineContourOps, 2029 2029 heightMapLineContourOps, Rappture::CMDSPEC_ARG2, objc, objv, 0); 2030 2030 if (proc == NULL) { … … 2035 2035 2036 2036 static int 2037 HeightMapCullOp(ClientData cdata, Tcl_Interp *interp, int objc, 2037 HeightMapCullOp(ClientData cdata, Tcl_Interp *interp, int objc, 2038 2038 Tcl_Obj *const *objv) 2039 2039 { … … 2047 2047 2048 2048 static int 2049 HeightMapCreateOp(ClientData cdata, Tcl_Interp *interp, int objc, 2049 HeightMapCreateOp(ClientData cdata, Tcl_Interp *interp, int objc, 2050 2050 Tcl_Obj *const *objv) 2051 2051 { 2052 2052 HeightMap *hmPtr; 2053 2053 2054 2054 /* heightmap create xmin ymin xmax ymax xnum ynum values */ 2055 2055 hmPtr = CreateHeightMap(cdata, interp, objc - 2, objv + 2); … … 2063 2063 2064 2064 static int 2065 HeightMapLegendOp(ClientData cdata, Tcl_Interp *interp, int objc, 2065 HeightMapLegendOp(ClientData cdata, Tcl_Interp *interp, int objc, 2066 2066 Tcl_Obj *const *objv) 2067 2067 { … … 2073 2073 tf = hmPtr->getColorMap(); 2074 2074 if (tf == NULL) { 2075 Tcl_AppendResult(interp, "no transfer function defined for heightmap \"", 2075 Tcl_AppendResult(interp, "no transfer function defined for heightmap \"", 2076 2076 Tcl_GetString(objv[2]), "\"", (char*)NULL); 2077 2077 return TCL_ERROR; 2078 2078 } 2079 2079 int w, h; 2080 if ((Tcl_GetIntFromObj(interp, objv[3], &w) != TCL_OK) || 2080 if ((Tcl_GetIntFromObj(interp, objv[3], &w) != TCL_OK) || 2081 2081 (Tcl_GetIntFromObj(interp, objv[4], &h) != TCL_OK)) { 2082 2082 return TCL_ERROR; … … 2085 2085 NanoVis::SetHeightmapRanges(); 2086 2086 } 2087 NanoVis::render_legend(tf, HeightMap::valueMin, HeightMap::valueMax, w, h, 2087 NanoVis::render_legend(tf, HeightMap::valueMin, HeightMap::valueMax, w, h, 2088 2088 "label"); 2089 2089 return TCL_OK; … … 2091 2091 2092 2092 static int 2093 HeightMapPolygonOp(ClientData cdata, Tcl_Interp *interp, int objc, 2093 HeightMapPolygonOp(ClientData cdata, Tcl_Interp *interp, int objc, 2094 2094 Tcl_Obj *const *objv) 2095 2095 { … … 2103 2103 2104 2104 static int 2105 HeightMapShadingOp(ClientData cdata, Tcl_Interp *interp, int objc, 2105 HeightMapShadingOp(ClientData cdata, Tcl_Interp *interp, int objc, 2106 2106 Tcl_Obj *const *objv) 2107 2107 { … … 2115 2115 2116 2116 static int 2117 HeightMapTestOp(ClientData cdata, Tcl_Interp *interp, int objc, 2117 HeightMapTestOp(ClientData cdata, Tcl_Interp *interp, int objc, 2118 2118 Tcl_Obj *const *objv) 2119 2119 { … … 2124 2124 double mean = exp(0.0) / (sigma * sqrt(2.0)); 2125 2125 float* data = (float*) malloc(sizeof(float) * size); 2126 2126 2127 2127 float x; 2128 2128 for (int i = 0; i < size; ++i) { 2129 2129 x = - 10 + i%20; 2130 data[i] = exp(- (x * x)/(2 * sigma * sigma)) / 2130 data[i] = exp(- (x * x)/(2 * sigma * sigma)) / 2131 2131 (sigma * sqrt(2.0)) / mean * 2 + 1000; 2132 2132 } 2133 2133 2134 2134 HeightMap* hmPtr = new HeightMap(); 2135 2135 float minx = 0.0f; … … 2147 2147 2148 2148 static int 2149 HeightMapTransFuncOp(ClientData cdata, Tcl_Interp *interp, int objc, 2149 HeightMapTransFuncOp(ClientData cdata, Tcl_Interp *interp, int objc, 2150 2150 Tcl_Obj *const *objv) 2151 2151 { … … 2171 2171 2172 2172 static Rappture::CmdSpec heightMapOps[] = { 2173 {"create", 2, HeightMapCreateOp, 9, 9, 2173 {"create", 2, HeightMapCreateOp, 9, 9, 2174 2174 "xmin ymin xmax ymax xnum ynum values",}, 2175 2175 {"cull", 2, HeightMapCullOp, 3, 3, "mode",}, … … 2184 2184 static int nHeightMapOps = NumCmdSpecs(heightMapOps); 2185 2185 2186 static int 2186 static int 2187 2187 HeightMapCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 2188 { 2188 { 2189 2189 Tcl_ObjCmdProc *proc; 2190 2190 2191 proc = Rappture::GetOpFromObj(interp, nHeightMapOps, heightMapOps, 2191 proc = Rappture::GetOpFromObj(interp, nHeightMapOps, heightMapOps, 2192 2192 Rappture::CMDSPEC_ARG1, objc, objv, 0); 2193 2193 if (proc == NULL) { … … 2198 2198 2199 2199 static int 2200 GridAxisColorOp(ClientData cdata, Tcl_Interp *interp, int objc, 2200 GridAxisColorOp(ClientData cdata, Tcl_Interp *interp, int objc, 2201 2201 Tcl_Obj *const *objv) 2202 2202 { … … 2210 2210 if ((objc == 6) && (GetFloatFromObj(interp, objv[5], &a) != TCL_OK)) { 2211 2211 return TCL_ERROR; 2212 } 2212 } 2213 2213 if (NanoVis::grid) { 2214 2214 NanoVis::grid->setAxisColor(r, g, b, a); … … 2228 2228 Axis *axisPtr; 2229 2229 2230 axisPtr = NULL;/* Suppress compiler warning. */2230 axisPtr = NULL; /* Suppress compiler warning. */ 2231 2231 switch (axis) { 2232 2232 case 0: axisPtr = &NanoVis::grid->xAxis; break; … … 2241 2241 2242 2242 static int 2243 GridLineColorOp(ClientData cdata, Tcl_Interp *interp, int objc, 2243 GridLineColorOp(ClientData cdata, Tcl_Interp *interp, int objc, 2244 2244 Tcl_Obj *const *objv) 2245 2245 { … … 2253 2253 if ((objc == 6) && (GetFloatFromObj(interp, objv[5], &a) != TCL_OK)) { 2254 2254 return TCL_ERROR; 2255 } 2255 } 2256 2256 if (NanoVis::grid) { 2257 2257 NanoVis::grid->setLineColor(r, g, b, a); … … 2279 2279 static int nGridOps = NumCmdSpecs(gridOps); 2280 2280 2281 static int 2281 static int 2282 2282 GridCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 2283 { 2283 { 2284 2284 Tcl_ObjCmdProc *proc; 2285 2285 2286 proc = Rappture::GetOpFromObj(interp, nGridOps, gridOps, 2287 2286 proc = Rappture::GetOpFromObj(interp, nGridOps, gridOps, 2287 Rappture::CMDSPEC_ARG1, objc, objv, 0); 2288 2288 if (proc == NULL) { 2289 2289 return TCL_ERROR; … … 2292 2292 } 2293 2293 2294 static int 2294 static int 2295 2295 AxisCmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) 2296 2296 { 2297 2297 if (objc < 2) { 2298 Tcl_AppendResult(interp, "wrong # args: should be \"", 2298 Tcl_AppendResult(interp, "wrong # args: should be \"", 2299 2299 Tcl_GetString(objv[0]), " option arg arg...\"", (char*)NULL); 2300 2300 return TCL_ERROR; … … 2325 2325 if (objc != 4) { 2326 2326 Tcl_AppendResult(interp, "wrong # args: should be \"", 2327 2327 Tcl_GetString(objv[0]), " plane_index w h \"", (char*)NULL); 2328 2328 return TCL_ERROR; 2329 2329 } … … 2337 2337 return TCL_ERROR; 2338 2338 } 2339 2339 2340 2340 //Now read w*h*4 bytes. The server expects the plane to be a stream of 2341 2341 //floats … … 2357 2357 2358 2358 2359 static int 2360 PlaneLinkOp(ClientData cdata, Tcl_Interp *interp, int objc, 2359 static int 2360 PlaneLinkOp(ClientData cdata, Tcl_Interp *interp, int objc, 2361 2361 Tcl_Obj *const *objv) 2362 2362 { 2363 2363 fprintf(stderr, "link the plane to the 2D renderer command\n"); 2364 2364 2365 2365 int plane_index, tf_index; 2366 2366 2367 if (objc != 3) { 2368 Tcl_AppendResult(interp, "wrong # args: should be \"", 2369 Tcl_GetString(objv[0]), " plane_index tf_index \"", (char*)NULL); 2370 return TCL_ERROR; 2371 } 2372 if (Tcl_GetIntFromObj(interp, objv[1], &plane_index) != TCL_OK) { 2373 return TCL_ERROR; 2374 } 2375 if (Tcl_GetIntFromObj(interp, objv[2], &tf_index) != TCL_OK) { 2376 return TCL_ERROR; 2377 } 2378 //plane_render->add_plane(plane[plane_index], tf[tf_index]); 2379 return TCL_OK; 2380 } 2381 2382 //Enable a 2D plane for render 2383 //The plane_index is the index mantained in the 2D plane renderer 2384 static int 2385 PlaneEnableOp(ClientData cdata, Tcl_Interp *interp, int objc, 2386 Tcl_Obj *const *objv) 2387 { 2388 fprintf(stderr,"enable a plane so the 2D renderer can render it command\n"); 2389 2367 2390 if (objc != 3) { 2368 2391 Tcl_AppendResult(interp, "wrong # args: should be \"", 2369 Tcl_GetString(objv[0]), " plane_index tf_index \"", (char*)NULL); 2370 return TCL_ERROR; 2371 } 2372 if (Tcl_GetIntFromObj(interp, objv[1], &plane_index) != TCL_OK) { 2373 return TCL_ERROR; 2374 } 2375 if (Tcl_GetIntFromObj(interp, objv[2], &tf_index) != TCL_OK) { 2376 return TCL_ERROR; 2377 } 2378 //plane_render->add_plane(plane[plane_index], tf[tf_index]); 2379 return TCL_OK; 2380 } 2381 2382 //Enable a 2D plane for render 2383 //The plane_index is the index mantained in the 2D plane renderer 2384 static int 2385 PlaneEnableOp(ClientData cdata, Tcl_Interp *interp, int objc, 2386 Tcl_Obj *const *objv) 2387 { 2388 fprintf(stderr,"enable a plane so the 2D renderer can render it command\n"); 2389 2390 if (objc != 3) { 2391 Tcl_AppendResult(interp, "wrong # args: should be \"", 2392 Tcl_GetString(objv[0]), " plane_index mode \"", (char*)NULL); 2392 Tcl_GetString(objv[0]), " plane_index mode \"", (char*)NULL); 2393 2393 return TCL_ERROR; 2394 2394 } … … 2420 2420 Tcl_ObjCmdProc *proc; 2421 2421 2422 proc = Rappture::GetOpFromObj(interp, nPlaneOps, planeOps, 2422 proc = Rappture::GetOpFromObj(interp, nPlaneOps, planeOps, 2423 2423 Rappture::CMDSPEC_ARG1, objc, objv, 0); 2424 2424 if (proc == NULL) { … … 2439 2439 * Ideally, the "unirect2d" proc would do a rundimentary parsing of the data 2440 2440 * to verify the structure and then pass it to the appropiate Tcl command 2441 * (heightmap, volume, etc). Our C command always creates a heightmap. 2441 * (heightmap, volume, etc). Our C command always creates a heightmap. 2442 2442 */ 2443 2443 static int 2444 UniRect2dCmd(ClientData clientData, Tcl_Interp *interp, int objc, 2444 UniRect2dCmd(ClientData clientData, Tcl_Interp *interp, int objc, 2445 2445 Tcl_Obj *const *objv) 2446 { 2446 { 2447 2447 int xNum, yNum, zNum; 2448 2448 float xMin, yMin, xMax, yMax; … … 2450 2450 2451 2451 if ((objc & 0x01) == 0) { 2452 Tcl_AppendResult(interp, Tcl_GetString(objv[0]), ": ", 2453 "wrong number of arguments: should be key-value pairs", 2452 Tcl_AppendResult(interp, Tcl_GetString(objv[0]), ": ", 2453 "wrong number of arguments: should be key-value pairs", 2454 2454 (char *)NULL); 2455 2455 return TCL_ERROR; … … 2511 2511 } 2512 2512 } else { 2513 Tcl_AppendResult(interp, "unknown key \"", string, 2513 Tcl_AppendResult(interp, "unknown key \"", string, 2514 2514 "\": should be xmin, xmax, xnum, ymin, ymax, ynum, or zvalues", 2515 2515 (char *)NULL); … … 2581 2581 xinetd_listen() 2582 2582 { 2583 int flags = fcntl(0, F_GETFL, 0); 2583 int flags = fcntl(0, F_GETFL, 0); 2584 2584 fcntl(0, F_SETFL, flags & ~O_NONBLOCK); 2585 2585 … … 2633 2633 2634 2634 if (status != TCL_OK) { 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2635 const char *string; 2636 int nBytes; 2637 string = Tcl_GetStringFromObj(Tcl_GetObjResult(_interp), &nBytes); 2638 2639 struct iovec iov[3]; 2640 iov[0].iov_base = "NanoVis Server Error: "; 2641 iov[0].iov_len = strlen(iov[0].iov_base); 2642 iov[1].iov_base = string; 2643 iov[1].iov_len = nBytes; 2644 iov[2].iov_base = '\n'; 2645 iov[2].iov_len = 1; 2646 writev(0, iov, 3); 2647 2647 return; 2648 2648 } … … 2669 2669 2670 2670 NanoVis::display(); 2671 2671 2672 2672 // INSOO 2673 2673 #ifdef XINETD 2674 2674 NanoVis::read_screen(); 2675 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 2675 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 2676 2676 #else 2677 2677 NanoVis::display_offscreen_buffer(); //display the final rendering on screen 2678 2678 NanoVis::read_screen(); 2679 glutSwapBuffers(); 2680 #endif 2679 glutSwapBuffers(); 2680 #endif 2681 2681 2682 2682 #if DO_RLE 2683 2683 do_rle(); 2684 int sizes[2] = { offsets_size*sizeof(offsets[0]), rle_size }; 2684 int sizes[2] = { offsets_size*sizeof(offsets[0]), rle_size }; 2685 2685 fprintf(stderr, "Writing %d,%d\n", sizes[0], sizes[1]); fflush(stderr); 2686 2686 write(0, &sizes, sizeof(sizes)); -
trunk/packages/vizservers/nanovis/nanovis.cpp
r1028 r1089 70 70 #include <R2/R2Fonts.h> 71 71 72 #define SIZEOF_BMP_HEADER 72 #define SIZEOF_BMP_HEADER 54 73 73 74 74 extern void NvInitCG(); // in Shader.cpp … … 120 120 121 121 // color table for built-in transfer function editor 122 float color_table[256][4]; 122 float color_table[256][4]; 123 123 124 124 /* … … 139 139 // in Command.cpp 140 140 extern void xinetd_listen(); 141 extern void initTcl(); 141 extern void initTcl(); 142 142 143 143 //ParticleSystem* psys; … … 167 167 168 168 // Object rotation angles 169 static float live_rot_x = 90.; 169 static float live_rot_x = 90.; 170 170 static float live_rot_y = 180.; 171 171 static float live_rot_z = -135; 172 172 173 173 // Object translation location from the origin 174 static float live_obj_x = -0.0; 174 static float live_obj_x = -0.0; 175 175 static float live_obj_y = -0.0; 176 176 static float live_obj_z = -2.5; … … 183 183 static int right_last_x; 184 184 static int right_last_y; 185 static bool left_down = false; 185 static bool left_down = false; 186 186 static bool right_down = false; 187 187 #endif /*XINETD*/ … … 190 190 // FLOW 191 191 float NanoVis::lic_slice_x = 1.0f; 192 float NanoVis::lic_slice_y = 0.0f; 193 float NanoVis::lic_slice_z = 0.5f; 194 int NanoVis::lic_axis = 2; 192 float NanoVis::lic_slice_y = 0.0f; 193 float NanoVis::lic_slice_z = 0.5f; 194 int NanoVis::lic_axis = 2; 195 195 196 196 /* … … 258 258 259 259 //report errors related to CG shaders 260 void 260 void 261 261 cgErrorCallback(void) 262 262 { … … 277 277 /* Load a 3D volume 278 278 * index: the index into the volume array, which stores pointers to 3D volume instances 279 * data: pointer to an array of floats. 280 * n_component: the number of scalars for each space point. 281 * All component scalars for a point are placed consequtively in data array 279 * data: pointer to an array of floats. 280 * n_component: the number of scalars for each space point. 281 * All component scalars for a point are placed consequtively in data array 282 282 * width, height and depth: number of points in each dimension 283 283 */ 284 284 Volume * 285 NanoVis::load_volume(int index, int width, int height, int depth, 286 int n_component, float* data, double vmin, 285 NanoVis::load_volume(int index, int width, int height, int depth, 286 int n_component, float* data, double vmin, 287 287 double vmax, double nzero_min) 288 288 { … … 297 297 298 298 if (vol->pointsetIndex != -1) { 299 if (((unsigned int) vol->pointsetIndex) < pointSet.size() && 300 299 if (((unsigned int) vol->pointsetIndex) < pointSet.size() && 300 pointSet[vol->pointsetIndex] != NULL) { 301 301 delete pointSet[vol->pointsetIndex]; 302 302 pointSet[vol->pointsetIndex] = 0; … … 306 306 } 307 307 volume[index] = new Volume(0.f, 0.f, 0.f, width, height, depth, 1., 308 308 n_component, data, vmin, vmax, nzero_min); 309 309 return volume[index]; 310 310 } … … 315 315 { 316 316 Tcl_HashEntry *hPtr; 317 317 318 318 hPtr = Tcl_FindHashEntry(&tftable, name); 319 319 if (hPtr == NULL) { … … 325 325 // Creates of updates a colormap 1D texture by name. 326 326 TransferFunction* 327 NanoVis::DefineTransferFunction(const char *name, size_t n, float *data) 327 NanoVis::DefineTransferFunction(const char *name, size_t n, float *data) 328 328 { 329 329 int isNew; … … 333 333 hPtr = Tcl_CreateHashEntry(&tftable, name, &isNew); 334 334 if (isNew) { 335 336 335 tf = new TransferFunction(n, data); 336 Tcl_SetHashValue(hPtr, (ClientData)tf); 337 337 } else { 338 339 340 341 342 343 338 /* 339 * You can't delete the transfer function because many 340 * objects may be holding its pointer. We must update it. 341 */ 342 tf = (TransferFunction *)Tcl_GetHashValue(hPtr); 343 tf->update(n, data); 344 344 } 345 345 return tf; … … 358 358 { 359 359 glutSetWindow(render_window); 360 360 361 361 //fprintf(stderr, "tf update\n"); 362 362 TransferFunction *tf = NanoVis::get_transfunc("default"); … … 364 364 return; 365 365 } 366 366 367 367 float data[256*4]; 368 368 for(int i=0; i<256; i++) { … … 373 373 //fprintf(stderr, "(%f,%f,%f,%f) ", data[4*i+0], data[4*i+1], data[4*i+2], data[4*i+3]); 374 374 } 375 375 376 376 tf->update(data); 377 377 378 378 #ifdef EVENTLOG 379 379 float param[3] = {0,0,0}; … … 384 384 } 385 385 386 int 386 int 387 387 NanoVis::render_legend( 388 TransferFunction *tf, 389 double min, double max, 390 int width, int height, 388 TransferFunction *tf, 389 double min, double max, 390 int width, int height, 391 391 const char* volArg) 392 392 { … … 426 426 427 427 //initialize frame buffer objects for offscreen rendering 428 void 428 void 429 429 NanoVis::init_offscreen_buffer() 430 430 { … … 433 433 glGenTextures(1, &final_color_tex); 434 434 glGenRenderbuffersEXT(1, &final_depth_rb); 435 435 436 436 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo); 437 437 438 438 //initialize final color texture 439 439 glBindTexture(GL_TEXTURE_2D, final_color_tex); … … 450 450 GL_COLOR_ATTACHMENT0_EXT, 451 451 GL_TEXTURE_2D, final_color_tex, 0); 452 452 453 453 // initialize final depth renderbuffer 454 454 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb); … … 458 458 GL_DEPTH_ATTACHMENT_EXT, 459 459 GL_RENDERBUFFER_EXT, final_depth_rb); 460 460 461 461 // Check framebuffer completeness at the end of initialization. 462 462 CHECK_FRAMEBUFFER_STATUS(); … … 472 472 win_width = w; 473 473 win_height = h; 474 474 475 475 if (fonts) { 476 476 fonts->resize(w, h); 477 477 } 478 478 479 479 //fprintf(stderr, "screen_buffer size: %d\n", sizeof(screen_buffer)); 480 480 printf("screen_buffer size: %d %d\n", w, h); 481 481 482 482 if (screen_buffer) { 483 483 delete[] screen_buffer; 484 484 screen_buffer = NULL; 485 485 } 486 486 487 487 screen_buffer = new unsigned char[4*win_width*win_height]; 488 488 assert(screen_buffer != NULL); 489 489 490 490 //delete the current render buffer resources 491 491 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo); 492 492 glDeleteTextures(1, &final_color_tex); 493 493 glDeleteFramebuffersEXT(1, &final_fbo); 494 494 495 495 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb); 496 496 glDeleteRenderbuffersEXT(1, &final_depth_rb); 497 497 498 498 //change the camera setting 499 499 cam->set_screen_size(0, 0, win_width, win_height); 500 500 plane_render->set_screen_size(win_width, win_height); 501 501 502 502 //Reinitialize final fbo for final display 503 503 glGenFramebuffersEXT(1, &final_fbo); … … 506 506 507 507 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo); 508 508 509 509 //initialize final color texture 510 510 glBindTexture(GL_TEXTURE_2D, final_color_tex); … … 521 521 GL_COLOR_ATTACHMENT0_EXT, 522 522 GL_TEXTURE_2D, final_color_tex, 0); 523 523 524 524 // initialize final depth renderbuffer 525 525 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb); … … 536 536 537 537 /* 538 * FIXME: This routine is fairly expensive (60000 floating pt divides). 539 * 540 * builds don't include it. Define PROTOTYPE to 1 in config.h541 * 538 * FIXME: This routine is fairly expensive (60000 floating pt divides). 539 * I've put an ifdef around the call to it so that the released 540 * builds don't include it. Define PROTOTYPE to 1 in config.h 541 * to turn it back on. 542 542 */ 543 543 void … … 547 547 int h = 200; 548 548 float* data = new float[w*h]; 549 549 550 550 //procedurally make a gradient plane 551 551 for(int j=0; j<h; j++){ … … 566 566 int index; 567 567 //bool particle; 568 for (int i=0; i<particleRenderer->psys_width; i++) { 569 for (int j=0; j<particleRenderer->psys_height; j++) { 568 for (int i=0; i<particleRenderer->psys_width; i++) { 569 for (int j=0; j<particleRenderer->psys_height; j++) { 570 570 index = i + particleRenderer->psys_height*j; 571 571 //particle = rand() % 256 > 150; … … 577 577 data[4*index+1]= j/float(particleRenderer->psys_height); 578 578 data[4*index+2]= i/float(particleRenderer->psys_width); 579 data[4*index+3]= 30; //shorter life span, quicker iterations 580 //data[4*index+3]= 1.0f; //shorter life span, quicker iterations 579 data[4*index+3]= 30; //shorter life span, quicker iterations 580 //data[4*index+3]= 1.0f; //shorter life span, quicker iterations 581 581 } 582 582 /* … … 586 586 data[4*index+1]= 0; 587 587 data[4*index+2]= 0; 588 data[4*index+3]= 0; 588 data[4*index+3]= 0; 589 589 } 590 590 */ … … 646 646 color_table_renderer = new NvColorTableRenderer(); 647 647 color_table_renderer->setFonts(fonts); 648 648 649 649 particleRenderer = new NvParticleRenderer(NMESH, NMESH, g_context); 650 650 … … 661 661 662 662 /*----------------------------------------------------*/ 663 void 664 NanoVis::initGL(void) 665 { 663 void 664 NanoVis::initGL(void) 665 { 666 666 //buffer to store data read from the screen 667 667 if (screen_buffer) { … … 673 673 674 674 //create the camera with default setting 675 cam = new NvCamera(0, 0, win_width, win_height, 675 cam = new NvCamera(0, 0, win_width, win_height, 676 676 live_obj_x, live_obj_y, live_obj_z, 677 677 0., 0., 100., … … 694 694 glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); 695 695 glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); 696 glLightfv(GL_LIGHT0, GL_SPECULAR, white_light); 696 glLightfv(GL_LIGHT0, GL_SPECULAR, white_light); 697 697 glLightfv(GL_LIGHT1, GL_DIFFUSE, green_light); 698 glLightfv(GL_LIGHT1, GL_SPECULAR, white_light); 698 glLightfv(GL_LIGHT1, GL_SPECULAR, white_light); 699 699 700 700 // init table of transfer functions … … 704 704 if(check_query_support()){ 705 705 //create queries to count number of rendered pixels 706 perf = new PerfQuery(); 706 perf = new PerfQuery(); 707 707 } 708 708 … … 734 734 #if PROTOTYPE 735 735 make_test_2D_data(); 736 #endif 736 #endif /* PROTOTYPE */ 737 737 plane_render->add_plane(plane[0], get_transfunc("default")); 738 738 … … 741 741 #ifdef notdef 742 742 init_particle_system(); 743 NanoVis::init_lic(); 743 NanoVis::init_lic(); 744 744 #endif 745 745 } … … 758 758 rle_size = 0; 759 759 offsets_size = 0; 760 760 761 761 int i=0; 762 762 while(i<len){ … … 769 769 i = pos; 770 770 } 771 771 772 772 else { 773 773 int pos; … … 778 778 i = pos; 779 779 } 780 780 781 781 } 782 782 } … … 870 870 char filename[100]; 871 871 if (frame_number >= 0) { 872 873 874 875 872 if (directory_name) 873 sprintf(filename, "%s/image%03d.bmp", directory_name, frame_number); 874 else 875 sprintf(filename, "/tmp/flow_animation/image%03d.bmp", frame_number); 876 876 877 877 printf("Writing %s\n", filename); 878 878 f = fopen(filename, "wb"); 879 880 881 879 if (f == 0) { 880 Trace("cannot create file\n"); 881 } 882 882 } else { 883 883 f = fopen("/tmp/image.bmp", "wb"); 884 885 886 884 if (f == 0) { 885 Trace("cannot create file\n"); 886 } 887 887 } 888 888 fwrite((void*) header, SIZEOF_BMP_HEADER, 1, f); … … 968 968 * ppm_write -- 969 969 * 970 * 971 * client. The PPM binary format is very simple.970 * Writes the screen image as PPM binary data to the nanovisviewer 971 * client. The PPM binary format is very simple. 972 972 * 973 * 974 * 973 * P6 w h 255\n 974 * 3-byte RGB pixel data. 975 975 * 976 * 977 * 978 * 976 * The nanovisviewer client (using the TkImg library) will do less work 977 * to unpack this format, as opposed to BMP or PNG. (This doesn't 978 * eliminate the need to look into DXT compression performed on the GPU). 979 979 * 980 980 * Note that currently the image data from the screen is both row-padded … … 1017 1017 unsigned char *srcRowPtr = screen_buffer; 1018 1018 for (y = win_height + 1; y >= 2; y--) { 1019 1020 1021 1019 iov[y].iov_base = srcRowPtr; 1020 iov[y].iov_len = rowLength; 1021 srcRowPtr += bytesPerRow; 1022 1022 } 1023 1023 writev(0, iov, nRecs); … … 1033 1033 for(int j=0; j<NMESH; j++){ 1034 1034 Vector2 v = grid.get(i, j); 1035 1035 1036 1036 int x1 = i*DM; 1037 1037 int y1 = j*DM; 1038 1038 1039 1039 int x2 = x1 + v.x; 1040 1040 int y2 = y1 + v.y; 1041 1041 1042 1042 glBegin(GL_LINES); 1043 1043 glVertex2d(x1, y1); … … 1051 1051 1052 1052 /*----------------------------------------------------*/ 1053 static void 1053 static void 1054 1054 idle() 1055 1055 { 1056 1056 glutSetWindow(render_window); 1057 1057 1058 1058 #ifdef notdef 1059 1059 struct timespec ts; … … 1075 1075 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1076 1076 glBindTexture(GL_TEXTURE_2D, final_color_tex); 1077 1077 1078 1078 glViewport(0, 0, win_width, win_height); 1079 1079 glMatrixMode(GL_PROJECTION); … … 1082 1082 glMatrixMode(GL_MODELVIEW); 1083 1083 glLoadIdentity(); 1084 1084 1085 1085 glColor3f(1.,1.,1.); //MUST HAVE THIS LINE!!! 1086 1086 glBegin(GL_QUADS); 1087 1087 { 1088 1089 1090 1091 1088 glTexCoord2f(0, 0); glVertex2f(0, 0); 1089 glTexCoord2f(1, 0); glVertex2f(win_width, 0); 1090 glTexCoord2f(1, 1); glVertex2f(win_width, win_height); 1091 glTexCoord2f(0, 1); glVertex2f(0, win_height); 1092 1092 } 1093 1093 glEnd(); … … 1109 1109 void soft_read_verts() 1110 1110 { 1111 glReadPixels(0, 0, psys->psys_width, psys->psys_height, GL_RGB, GL_FLOAT, 1112 1111 glReadPixels(0, 0, psys->psys_width, psys->psys_height, GL_RGB, GL_FLOAT, 1112 vert); 1113 1113 //fprintf(stderr, "soft_read_vert"); 1114 1115 //cpu sort the distance 1114 1115 //cpu sort the distance 1116 1116 Particle* p; 1117 1117 p = (Particle*)malloc(sizeof(Particle)*psys->psys_width*psys->psys_height); … … 1120 1120 float y = vert[3*i+1]; 1121 1121 float z = vert[3*i+2]; 1122 1123 float dis = (x-live_obj_x)*(x-live_obj_x) + (y-live_obj_y)*(y-live_obj_y) + (z-live_obj_z)*(z-live_obj_z); 1122 1123 float dis = (x-live_obj_x)*(x-live_obj_x) + (y-live_obj_y)*(y-live_obj_y) + (z-live_obj_z)*(z-live_obj_z); 1124 1124 p[i].x = x; 1125 1125 p[i].y = y; … … 1127 1127 p[i].aux = dis; 1128 1128 } 1129 1129 1130 1130 qsort(p, psys->psys_width * psys->psys_height, sizeof(Particle), particle_distance_sort); 1131 1131 1132 1132 for(int i=0; i<psys->psys_width * psys->psys_height; i++){ 1133 1133 vert[3*i] = p[i].x; … … 1135 1135 vert[3*i+2] = p[i].z; 1136 1136 } 1137 1137 1138 1138 free(p); 1139 1139 } … … 1146 1146 { 1147 1147 glPushMatrix(); 1148 1148 1149 1149 glEnable(GL_TEXTURE_2D); 1150 1150 glBindTexture(GL_TEXTURE_RECTANGLE_NV, tex); 1151 1151 1152 1152 glViewport(0, 0, width, height); 1153 1153 glMatrixMode(GL_PROJECTION); … … 1156 1156 glMatrixMode(GL_MODELVIEW); 1157 1157 glLoadIdentity(); 1158 1158 1159 1159 cgGLBindProgram(m_passthru_fprog); 1160 1160 cgGLEnableProfile(CG_PROFILE_FP30); 1161 1161 1162 1162 cgGLSetParameter4f(m_passthru_scale_param, 1.0, 1.0, 1.0, 1.0); 1163 1163 cgGLSetParameter4f(m_passthru_bias_param, 0.0, 0.0, 0.0, 0.0); 1164 1164 1165 1165 draw_quad(width, height, width, height); 1166 1166 cgGLDisableProfile(CG_PROFILE_FP30); 1167 1167 1168 1168 glPopMatrix(); 1169 1169 1170 1170 //assert(glGetError()==0); 1171 1171 } … … 1175 1175 //draw vertices in the main memory 1176 1176 #ifdef notdef 1177 void 1177 void 1178 1178 soft_display_verts() 1179 1179 { 1180 1180 glDisable(GL_TEXTURE_2D); 1181 1181 glEnable(GL_BLEND); 1182 1182 1183 1183 glPointSize(0.5); 1184 1184 glColor4f(0,0.8,0.8,0.6); 1185 1185 glBegin(GL_POINTS); 1186 1186 { 1187 1188 1189 1187 for(int i=0; i < psys->psys_width * psys->psys_height; i++){ 1188 glVertex3f(vert[3*i], vert[3*i+1], vert[3*i+2]); 1189 } 1190 1190 } 1191 1191 glEnd(); … … 1196 1196 #if 0 1197 1197 //oddeven sort on GPU 1198 void 1198 void 1199 1199 sortstep() 1200 1200 { 1201 1201 // perform one step of the current sorting algorithm 1202 1202 1203 1203 #ifdef notdef 1204 1204 // swap buffers 1205 1205 int sourceBuffer = targetBuffer; 1206 targetBuffer = (targetBuffer+1)%2; 1206 targetBuffer = (targetBuffer+1)%2; 1207 1207 int pstage = (1<<stage); 1208 1208 int ppass = (1<<pass); 1209 1209 int activeBitonicShader = 0; 1210 1210 1211 1211 #ifdef _WIN32 1212 1212 buffer->BindBuffer(wglTargets[sourceBuffer]); … … 1225 1225 // switch on correct sorting shader 1226 1226 oddevenMergeSort.bind(); 1227 glUniform3fARB(oddevenMergeSort.getUniformLocation("Param1"), float(pstage+pstage), 1227 glUniform3fARB(oddevenMergeSort.getUniformLocation("Param1"), float(pstage+pstage), 1228 1228 float(ppass%pstage), float((pstage+pstage)-(ppass%pstage)-1)); 1229 glUniform3fARB(oddevenMergeSort.getUniformLocation("Param2"), 1230 1229 glUniform3fARB(oddevenMergeSort.getUniformLocation("Param2"), 1230 float(psys_width), float(psys_height), float(ppass)); 1231 1231 glUniform1iARB(oddevenMergeSort.getUniformLocation("Data"), 0); 1232 1232 staticdebugmsg("sort","stage "<<pstage<<" pass "<<ppass); 1233 1233 1234 1234 // This clear is not necessary for sort to function. But if we are in 1235 1235 // interactive mode unused parts of the texture that are visible will look … … 1237 1237 #ifdef notdef 1238 1238 if (!perfTest) glClear(GL_COLOR_BUFFER_BIT); 1239 1239 1240 1240 buffer->Bind(); 1241 1241 buffer->EnableTextureTarget(); 1242 1242 #endif 1243 1243 1244 1244 // Initiate the sorting step on the GPU a full-screen quad 1245 1245 glBegin(GL_QUADS); 1246 1246 { 1247 1247 #ifdef notdef 1248 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,0.0f,0.0f,1.0f); 1249 glVertex2f(-1.0f,-1.0f); 1250 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,float(psys_width),0.0f,1.0f,1.0f); 1251 1252 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,float(psys_width),float(psys_height),1.0f,0.0f); 1253 glVertex2f(1.0f,1.0f); 1254 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,float(psys_height),0.0f,0.0f); 1255 glVertex2f(-1.0f,1.0f); 1256 #endif 1257 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,0.0f,0.0f,1.0f); 1258 glVertex2f(0.,0.); 1259 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,float(psys_width),0.0f,1.0f,1.0f); 1260 1261 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,float(psys_width),float(psys_height),1.0f,0.0f); 1262 glVertex2f(float(psys_width), float(psys_height)); 1263 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,float(psys_height),0.0f,0.0f); 1264 glVertex2f(0., float(psys_height)); 1248 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,0.0f,0.0f,1.0f); 1249 glVertex2f(-1.0f,-1.0f); 1250 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,float(psys_width),0.0f,1.0f,1.0f); 1251 glVertex2f(1.0f,-1.0f); 1252 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,float(psys_width),float(psys_height),1.0f,0.0f); 1253 glVertex2f(1.0f,1.0f); 1254 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,float(psys_height),0.0f,0.0f); 1255 glVertex2f(-1.0f,1.0f); 1256 #endif 1257 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,0.0f,0.0f,1.0f); 1258 glVertex2f(0.,0.); 1259 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,float(psys_width),0.0f,1.0f,1.0f); 1260 glVertex2f(float(psys_width), 0.); 1261 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,float(psys_width),float(psys_height),1.0f,0.0f); 1262 glVertex2f(float(psys_width), float(psys_height)); 1263 glMultiTexCoord4fARB(GL_TEXTURE0_ARB,0.0f,float(psys_height),0.0f,0.0f); 1264 glVertex2f(0., float(psys_height)); 1265 1265 } 1266 1266 glEnd(); … … 1281 1281 glDisable(GL_TEXTURE_2D); 1282 1282 glEnable(GL_DEPTH_TEST); 1283 1283 1284 1284 //draw axes 1285 1285 GLUquadric *obj; 1286 1286 1287 1287 obj = gluNewQuadric(); 1288 1288 1289 1289 glDepthFunc(GL_LESS); 1290 1290 glEnable(GL_COLOR_MATERIAL); 1291 1291 glEnable(GL_DEPTH_TEST); 1292 1292 glDisable(GL_BLEND); 1293 1293 1294 1294 int segments = 50; 1295 1295 1296 1296 glColor3f(0.8, 0.8, 0.8); 1297 1297 glPushMatrix(); … … 1301 1301 glScalef(0.0005, 0.0005, 0.0005); 1302 1302 glutStrokeCharacter(GLUT_STROKE_ROMAN, 'x'); 1303 glPopMatrix(); 1304 1303 glPopMatrix(); 1304 1305 1305 glPushMatrix(); 1306 1306 glTranslatef(0., 0.4, 0.); … … 1309 1309 glScalef(0.0005, 0.0005, 0.0005); 1310 1310 glutStrokeCharacter(GLUT_STROKE_ROMAN, 'y'); 1311 glPopMatrix(); 1312 1311 glPopMatrix(); 1312 1313 1313 glPushMatrix(); 1314 1314 glTranslatef(0., 0., 0.4); … … 1317 1317 glScalef(0.0005, 0.0005, 0.0005); 1318 1318 glutStrokeCharacter(GLUT_STROKE_ROMAN, 'z'); 1319 glPopMatrix(); 1320 1319 glPopMatrix(); 1320 1321 1321 glEnable(GL_LIGHTING); 1322 1322 glEnable(GL_LIGHT0); 1323 1323 1324 1324 //glColor3f(0.2, 0.2, 0.8); 1325 1325 glPushMatrix(); 1326 1326 glutSolidSphere(0.02, segments, segments ); 1327 1327 glPopMatrix(); 1328 1328 1329 1329 glPushMatrix(); 1330 glRotatef(-90, 1, 0, 0); 1330 glRotatef(-90, 1, 0, 0); 1331 1331 gluCylinder(obj, 0.01, 0.01, 0.3, segments, segments); 1332 glPopMatrix(); 1333 1332 glPopMatrix(); 1333 1334 1334 glPushMatrix(); 1335 1335 glTranslatef(0., 0.3, 0.); 1336 glRotatef(-90, 1, 0, 0); 1336 glRotatef(-90, 1, 0, 0); 1337 1337 gluCylinder(obj, 0.02, 0.0, 0.06, segments, segments); 1338 glPopMatrix(); 1339 1338 glPopMatrix(); 1339 1340 1340 glPushMatrix(); 1341 1341 glRotatef(90, 0, 1, 0); 1342 1342 gluCylinder(obj, 0.01, 0.01, 0.3, segments, segments); 1343 glPopMatrix(); 1344 1343 glPopMatrix(); 1344 1345 1345 glPushMatrix(); 1346 1346 glTranslatef(0.3, 0., 0.); 1347 glRotatef(90, 0, 1, 0); 1347 glRotatef(90, 0, 1, 0); 1348 1348 gluCylinder(obj, 0.02, 0.0, 0.06, segments, segments); 1349 glPopMatrix(); 1350 1349 glPopMatrix(); 1350 1351 1351 glPushMatrix(); 1352 1352 gluCylinder(obj, 0.01, 0.01, 0.3, segments, segments); 1353 glPopMatrix(); 1354 1353 glPopMatrix(); 1354 1355 1355 glPushMatrix(); 1356 1356 glTranslatef(0., 0., 0.3); 1357 1357 gluCylinder(obj, 0.02, 0.0, 0.06, segments, segments); 1358 glPopMatrix(); 1359 1358 glPopMatrix(); 1359 1360 1360 glDisable(GL_LIGHTING); 1361 1361 glDisable(GL_DEPTH_TEST); 1362 1362 gluDeleteQuadric(obj); 1363 1363 1364 1364 glEnable(GL_TEXTURE_2D); 1365 1365 glDisable(GL_DEPTH_TEST); … … 1367 1367 1368 1368 #ifdef notdef 1369 void 1369 void 1370 1370 draw_axis() 1371 1371 { 1372 1372 glDisable(GL_TEXTURE_2D); 1373 1373 glEnable(GL_DEPTH_TEST); 1374 1374 1375 1375 //red x 1376 1376 glColor3f(1,0,0); … … 1381 1381 } 1382 1382 glEnd(); 1383 1383 1384 1384 //blue y 1385 1385 glColor3f(0,0,1); … … 1390 1390 } 1391 1391 glEnd(); 1392 1392 1393 1393 //green z 1394 1394 glColor3f(0,1,0); … … 1399 1399 } 1400 1400 glEnd(); 1401 1401 1402 1402 glEnable(GL_TEXTURE_2D); 1403 1403 glDisable(GL_DEPTH_TEST); … … 1412 1412 double elapsed_time; 1413 1413 1414 elapsed_time = clock.tv_sec + clock.tv_usec/1000000.0 - 1415 1416 1414 elapsed_time = clock.tv_sec + clock.tv_usec/1000000.0 - 1415 vol_renderer->_volumeInterpolator->getStartTime(); 1416 1417 1417 Trace("%lf %lf\n", elapsed_time, vol_renderer->_volumeInterpolator->getInterval()); 1418 1418 float fraction; … … 1431 1431 1432 1432 void 1433 NanoVis::SetVolumeRanges() 1433 NanoVis::SetVolumeRanges() 1434 1434 { 1435 1435 double xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax; 1436 1436 1437 1437 xMin = yMin = zMin = wMin = DBL_MAX; 1438 1438 xMax = yMax = zMax = wMax = -DBL_MAX; 1439 1439 for (unsigned int i = 0; i < volume.size(); i++) { 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1440 Volume *volPtr; 1441 1442 volPtr = volume[i]; 1443 if (volPtr == NULL) { 1444 continue; 1445 } 1446 if (!volPtr->enabled) { 1447 continue; 1448 } 1449 if (xMin > volPtr->xAxis.Min()) { 1450 xMin = volPtr->xAxis.Min(); 1451 } 1452 if (xMax < volPtr->xAxis.Max()) { 1453 xMax = volPtr->xAxis.Max(); 1454 } 1455 if (yMin > volPtr->yAxis.Min()) { 1456 yMin = volPtr->yAxis.Min(); 1457 } 1458 if (yMax < volPtr->yAxis.Max()) { 1459 yMax = volPtr->yAxis.Max(); 1460 } 1461 if (zMin > volPtr->zAxis.Min()) { 1462 zMin = volPtr->zAxis.Min(); 1463 } 1464 if (zMax < volPtr->zAxis.Max()) { 1465 zMax = volPtr->zAxis.Max(); 1466 } 1467 if (wMin > volPtr->wAxis.Min()) { 1468 wMin = volPtr->wAxis.Min(); 1469 } 1470 if (wMax < volPtr->wAxis.Max()) { 1471 wMax = volPtr->wAxis.Max(); 1472 } 1473 1473 } 1474 1474 if ((xMin < DBL_MAX) && (xMax > -DBL_MAX)) { 1475 1475 grid->xAxis.SetScale(xMin, xMax); 1476 1476 } 1477 1477 if ((yMin < DBL_MAX) && (yMax > -DBL_MAX)) { 1478 1478 grid->yAxis.SetScale(yMin, yMax); 1479 1479 } 1480 1480 if ((zMin < DBL_MAX) && (zMax > -DBL_MAX)) { 1481 1481 grid->zAxis.SetScale(zMin, zMax); 1482 1482 } 1483 1483 if ((wMin < DBL_MAX) && (wMax > -DBL_MAX)) { 1484 1485 1484 Volume::valueMin = wMin; 1485 Volume::valueMax = wMax; 1486 1486 } 1487 1487 Volume::update_pending = false; … … 1492 1492 { 1493 1493 double xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax; 1494 1494 1495 1495 xMin = yMin = zMin = wMin = DBL_MAX; 1496 1496 xMax = yMax = zMax = wMax = -DBL_MAX; 1497 1497 for (unsigned int i = 0; i < heightMap.size(); i++) { 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1498 HeightMap *hmPtr; 1499 1500 hmPtr = heightMap[i]; 1501 if (hmPtr == NULL) { 1502 continue; 1503 } 1504 if (xMin > hmPtr->xAxis.Min()) { 1505 xMin = hmPtr->xAxis.Min(); 1506 } 1507 if (xMax < hmPtr->xAxis.Max()) { 1508 xMax = hmPtr->xAxis.Max(); 1509 } 1510 if (yMin > hmPtr->yAxis.Min()) { 1511 yMin = hmPtr->yAxis.Min(); 1512 } 1513 if (yMax < hmPtr->yAxis.Max()) { 1514 yMax = hmPtr->yAxis.Max(); 1515 } 1516 if (zMin > hmPtr->zAxis.Min()) { 1517 zMin = hmPtr->zAxis.Min(); 1518 } 1519 if (zMax < hmPtr->zAxis.Max()) { 1520 zMax = hmPtr->zAxis.Max(); 1521 } 1522 if (wMin > hmPtr->wAxis.Min()) { 1523 wMin = hmPtr->wAxis.Min(); 1524 } 1525 if (wMax < hmPtr->wAxis.Max()) { 1526 wMax = hmPtr->wAxis.Max(); 1527 } 1528 1528 } 1529 1529 if ((xMin < DBL_MAX) && (xMax > -DBL_MAX)) { 1530 1530 grid->xAxis.SetScale(xMin, xMax); 1531 1531 } 1532 1532 if ((yMin < DBL_MAX) && (yMax > -DBL_MAX)) { 1533 1533 grid->yAxis.SetScale(yMin, yMax); 1534 1534 } 1535 1535 if ((zMin < DBL_MAX) && (zMax > -DBL_MAX)) { 1536 1536 grid->zAxis.SetScale(zMin, zMax); 1537 1537 } 1538 1538 if ((wMin < DBL_MAX) && (wMax > -DBL_MAX)) { 1539 1540 1539 HeightMap::valueMin = wMin; 1540 HeightMap::valueMax = wMax; 1541 1541 } 1542 1542 HeightMap::update_pending = false; … … 1544 1544 1545 1545 /*----------------------------------------------------*/ 1546 void 1546 void 1547 1547 NanoVis::display() 1548 1548 { 1549 1549 //assert(glGetError()==0); 1550 1550 if (HeightMap::update_pending) { 1551 1551 SetHeightmapRanges(); 1552 1552 } 1553 1553 if (Volume::update_pending) { 1554 1554 SetVolumeRanges(); 1555 1555 } 1556 1556 //start final rendering … … 1564 1564 //camera setting activated 1565 1565 cam->activate(); 1566 1566 1567 1567 //set up the orientation of items in the scene. 1568 1568 glPushMatrix(); … … 1576 1576 // this is the default 1577 1577 break; 1578 1578 1579 1579 case 3: // z 1580 1580 glRotatef(-90, 1, 0, 0); 1581 1581 glRotatef(-90, 0, 0, 1); 1582 1582 break; 1583 1583 1584 1584 case -1: // -x 1585 1585 glRotatef(-90, 0, 0, 1); 1586 1586 break; 1587 1587 1588 1588 case -2: // -y 1589 1589 glRotatef(180, 0, 0, 1); 1590 1590 glRotatef(-90, 0, 1, 0); 1591 1591 break; 1592 1592 1593 1593 case -3: // -z 1594 1594 glRotatef(90, 1, 0, 0); 1595 1595 break; 1596 1596 } 1597 1597 1598 1598 // TBD : This will be removed after being sure that all the functions work well. 1599 1599 //glPushMatrix(); 1600 1600 1601 1601 //now render things in the scene 1602 1602 if (axis_on) { … … 1617 1617 //fprintf(stderr, "particle pixels: %d\n", perf->get_pixel_count()); 1618 1618 //perf->reset(); 1619 1619 1620 1620 //perf->enable(); 1621 1621 vol_renderer->render_all(); 1622 1622 //perf->disable(); 1623 1623 1624 1624 for (unsigned int i = 0; i < heightMap.size(); ++i) { 1625 1625 if (heightMap[i]->isVisible()) { … … 1674 1674 } 1675 1675 1676 void 1676 void 1677 1677 NanoVis::update_rot(int delta_x, int delta_y) 1678 1678 { 1679 1679 live_rot_x += delta_x; 1680 1680 live_rot_y += delta_y; 1681 1681 1682 1682 if (live_rot_x > 360.0) { 1683 live_rot_x -= 360.0; 1683 live_rot_x -= 360.0; 1684 1684 } else if(live_rot_x < -360.0) { 1685 1685 live_rot_x += 360.0; 1686 1686 } 1687 1687 if (live_rot_y > 360.0) { 1688 live_rot_y -= 360.0; 1688 live_rot_y -= 360.0; 1689 1689 } else if(live_rot_y < -360.0) { 1690 1690 live_rot_y += 360.0; … … 1772 1772 default: 1773 1773 break; 1774 } 1774 } 1775 1775 #ifdef EVENTLOG 1776 1776 if(log){ … … 1786 1786 NanoVis::motion(int x, int y) 1787 1787 { 1788 int old_x, old_y; 1788 int old_x, old_y; 1789 1789 1790 1790 if(left_down){ 1791 1791 old_x = left_last_x; 1792 old_y = left_last_y; 1792 old_y = left_last_y; 1793 1793 } else if(right_down){ 1794 1794 old_x = right_last_x; 1795 old_y = right_last_y; 1796 } 1797 1795 old_y = right_last_y; 1796 } 1797 1798 1798 int delta_x = x - old_x; 1799 1799 int delta_y = y - old_y; 1800 1800 1801 1801 //more coarse event handling 1802 1802 //if(abs(delta_x)<10 && abs(delta_y)<10) 1803 1803 //return; 1804 1804 1805 1805 if(left_down){ 1806 1806 left_last_x = x; 1807 1807 left_last_y = y; 1808 1808 1809 1809 update_rot(-delta_y, -delta_x); 1810 1810 } else if (right_down){ 1811 1811 //fprintf(stderr, "right mouse motion (%d,%d)\n", x, y); 1812 1812 1813 1813 right_last_x = x; 1814 1814 right_last_y = y; 1815 1815 1816 1816 update_trans(0, 0, delta_x); 1817 1817 } 1818 1818 1819 1819 #ifdef EVENTLOG 1820 1820 float param[3] = {live_rot_x, live_rot_y, live_rot_z}; … … 1831 1831 1832 1832 #ifdef XINETD 1833 void 1833 void 1834 1834 init_service() 1835 1835 { … … 1839 1839 dup2(fileno(xinetd_log), 2); 1840 1840 dup2(2,1); 1841 1842 //flush junk 1841 1842 //flush junk 1843 1843 fflush(stdout); 1844 1844 fflush(stderr); 1845 1845 } 1846 1846 1847 void 1847 void 1848 1848 end_service() 1849 1849 { … … 1853 1853 #endif /*XINETD*/ 1854 1854 1855 void 1856 init_event_log() 1855 void 1856 init_event_log() 1857 1857 { 1858 1858 event_log = fopen("event.txt", "w"); 1859 1859 assert(event_log!=0); 1860 1860 1861 1861 struct timeval time; 1862 1862 gettimeofday(&time, NULL); … … 1864 1864 } 1865 1865 1866 void 1866 void 1867 1867 end_event_log() 1868 1868 { … … 1870 1870 } 1871 1871 1872 double 1872 double 1873 1873 get_time_interval() 1874 1874 { … … 1876 1876 gettimeofday(&time, NULL); 1877 1877 double new_time = time.tv_sec*1000. + time.tv_usec/1000.; 1878 1878 1879 1879 double interval = new_time - cur_time; 1880 1880 cur_time = new_time; 1881 1881 return interval; 1882 1882 } 1883 #endif 1883 #endif 1884 1884 1885 1885 void removeAllData() … … 1891 1891 /*----------------------------------------------------*/ 1892 1892 int 1893 main(int argc, char** argv) 1893 main(int argc, char** argv) 1894 1894 { 1895 1895 char *path; … … 1918 1918 1919 1919 R2FilePath::getInstance()->setWorkingDirectory(argc, (const char**) argv); 1920 1920 1921 1921 #ifdef XINETD 1922 1922 signal(SIGPIPE,SIG_IGN); 1923 1923 NvInitService(); 1924 1924 #endif 1925 1925 1926 1926 glutInit(&argc, argv); 1927 1927 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); 1928 1928 1929 1929 glutInitWindowSize(NanoVis::win_width, NanoVis::win_height); 1930 1930 1931 1931 glutInitWindowPosition(10, 10); 1932 1932 render_window = glutCreateWindow(argv[0]); 1933 1933 glutDisplayFunc(NanoVis::display); 1934 1934 1935 1935 #ifndef XINETD 1936 1936 glutMouseFunc(NanoVis::mouse); … … 1938 1938 glutKeyboardFunc(NanoVis::keyboard); 1939 1939 #endif 1940 1940 1941 1941 glutIdleFunc(idle); 1942 1942 glutReshapeFunc(NanoVis::resize_offscreen_buffer); 1943 1943 1944 1944 NanoVis::init(path); 1945 1945 NanoVis::initGL(); 1946 1946 initTcl(); 1947 1947 1948 1948 #ifdef EVENTLOG 1949 1949 NvInitEventLog(); … … 1951 1951 //event loop 1952 1952 glutMainLoop(); 1953 1953 1954 1954 removeAllData(); 1955 1955 1956 1956 NvExit(); 1957 1957 1958 1958 return 0; 1959 1959 }
Note: See TracChangeset
for help on using the changeset viewer.