Changeset 865
- Timestamp:
- Feb 5, 2008, 1:44:27 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/vizservers/nanovis/Command.cpp
r862 r865 56 56 // FOR testing new functions 57 57 //#define _LOCAL_ZINC_TEST_ 58 #ifdef _LOCAL_ZINC_TEXT_ 58 59 #include "Test.h" 59 60 #endif 60 61 // EXTERN DECLARATIONS 61 62 // in Nv.cpp … … 143 144 static int GetAxis(Tcl_Interp *interp, const char *string, int *valPtr); 144 145 static int GetColor(Tcl_Interp *interp, const char *string, float *rgbPtr); 145 static int FillBufferFromStdin(Tcl_Interp *interp, Rappture::Buffer &buf,146 static int GetDataStream(Tcl_Interp *interp, Rappture::Buffer &buf, 146 147 int nBytes); 147 148 static HeightMap *CreateHeightMap(ClientData clientData, Tcl_Interp *interp, … … 158 159 } 159 160 *valuePtr = (float)value; 161 return TCL_OK; 162 } 163 164 static int 165 GetCullMode(Tcl_Interp *interp, const char *string, 166 graphics::RenderContext::CullMode *modePtr) 167 { 168 if (strcmp(string, "none") == 0) { 169 *modePtr = graphics::RenderContext::NO_CULL; 170 } else if (strcmp(string, "front") == 0) { 171 *modePtr = graphics::RenderContext::FRONT; 172 } else if (strcmp(string, "back") == 0) { 173 *modePtr = graphics::RenderContext::BACK; 174 } else { 175 Tcl_AppendResult(interp, "invalid cull mode \"", string, 176 "\": should be front, back, or none\"", (char *)NULL); 177 return TCL_ERROR; 178 } 179 return TCL_OK; 180 } 181 182 static int 183 GetShadingModel(Tcl_Interp *interp, const char *string, 184 graphics::RenderContext::ShadingModel *modelPtr) 185 { 186 if (strcmp(string,"flat") == 0) { 187 *modelPtr = graphics::RenderContext::FLAT; 188 } else if (strcmp(string,"smooth") == 0) { 189 *modelPtr = graphics::RenderContext::SMOOTH; 190 } else { 191 Tcl_AppendResult(interp, "bad shading model \"", string, 192 "\": should be flat or smooth", (char *)NULL); 193 return TCL_ERROR; 194 } 195 return TCL_OK; 196 } 197 198 static int 199 GetPolygonMode(Tcl_Interp *interp, const char *string, 200 graphics::RenderContext::PolygonMode *modePtr) 201 { 202 if (strcmp(string,"wireframe") == 0) { 203 *modePtr = graphics::RenderContext::LINE; 204 } else if (strcmp(string,"fill") == 0) { 205 *modePtr = graphics::RenderContext::FILL; 206 } else { 207 Tcl_AppendResult(interp, "invalid polygon mode \"", string, 208 "\": should be wireframe or fill\"", (char *)NULL); 209 return TCL_ERROR; 210 } 160 211 return TCL_OK; 161 212 } … … 704 755 return TCL_ERROR; 705 756 } 706 707 757 vector<unsigned int>::iterator iter = ivol.begin(); 708 while (iter != ivol.end()) 709 { 710 if(NanoVis::volume[*iter] != 0) 711 { 758 while (iter != ivol.end()) { 759 if(NanoVis::volume[*iter] != 0) { 712 760 if (state) { 713 761 NanoVis::volume[*iter]->enable_data(); … … 725 773 */ 726 774 } 727 728 775 ++iter; 729 776 } … … 738 785 } 739 786 740 Rappture::Outcome err; 741 Rappture::Buffer buf; 742 743 // DEBUG 744 char buffer[8096]; 745 while (nbytes > 0) { 746 unsigned int chunk; 747 int status; 748 749 chunk = (sizeof(buffer) < (unsigned int) nbytes) ? sizeof(buffer) : nbytes; 750 status = fread(buffer, 1, chunk, stdin); 751 //printf("Begin Reading [%d Read : %d Left]\n", status, nbytes - status); 752 fflush(stdout); 753 if (status > 0) { 754 buf.append(buffer,status); 755 nbytes -= status; 756 } else { 757 printf("data unpacking failed\n"); 758 Tcl_AppendResult(interp, "data unpacking failed: unexpected EOF", 759 (char*)NULL); 760 return TCL_ERROR; 761 } 762 } 763 err = Rappture::encoding::decode(buf,RPENC_Z|RPENC_B64|RPENC_HDR); 764 if (err) { 765 printf("ERROR -- DECODING\n"); 766 fflush(stdout); 767 Tcl_AppendResult(interp, err.remark().c_str(), (char*)NULL); 768 return TCL_ERROR; 769 } 770 787 Rappture::Buffer buf; 788 if (GetDataStream(interp, buf, nbytes) != TCL_OK) { 789 return TCL_ERROR; 790 } 771 791 int n = NanoVis::n_volumes; 772 792 char header[6]; … … 841 861 #endif 842 862 } else { 863 Rappture::Outcome err; 864 843 865 printf("OpenDX loading...\n"); 844 866 fflush(stdout); … … 1100 1122 } 1101 1123 1102 static int getDataStream(int nbytes, Rappture::Buffer* buf)1103 {1104 Rappture::Outcome err;1105 1106 char buffer[8096];1107 while (nbytes > 0) {1108 unsigned int chunk;1109 int status;1110 1111 chunk = (sizeof(buffer) < (unsigned int) nbytes) ? sizeof(buffer) : nbytes;1112 status = fread(buffer, 1, chunk, stdin);1113 if (status > 0) {1114 buf->append(buffer,status);1115 nbytes -= status;1116 } else {1117 printf("data unpacking failed\n");1118 Tcl_AppendResult(interp, "data unpacking failed: unexpected EOF",1119 (char*)NULL);1120 return TCL_ERROR;1121 }1122 }1123 1124 err = Rappture::encoding::decode(*buf,RPENC_Z|RPENC_B64|RPENC_HDR);1125 if (err) {1126 printf("ERROR -- DECODING\n");1127 fflush(stdout);1128 Tcl_AppendResult(interp, err.remark().c_str(), (char*)NULL);1129 return TCL_ERROR;1130 }1131 return TCL_OK;1132 }1133 1134 1124 static int 1135 1125 FlowCmd(ClientData cdata, Tcl_Interp *interp, int argc, const char *argv[]) … … 1138 1128 1139 1129 char c = argv[1][0]; 1140 if ((c == 'v') && (strcmp(argv[1], "vectorid") == 0)) 1141 { 1142 int n = 0; 1143 if (Tcl_GetInt(interp, argv[2], &n) != TCL_OK) { 1130 if ((c == 'v') && (strcmp(argv[1], "vectorid") == 0)) { 1131 if (argc != 3) { 1132 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1133 " vectorid volume", (char *)NULL); 1134 return TCL_ERROR; 1135 } 1136 Volume *volPtr; 1137 1138 if (GetVolume(interp, argv[2], &volPtr) != TCL_OK) { 1139 return TCL_ERROR; 1140 } 1141 if (NanoVis::particleRenderer != NULL) { 1142 NanoVis::particleRenderer->setVectorField(volPtr->id, 1.0f, 1143 volPtr->height / (float)volPtr->width, 1144 volPtr->depth / (float)volPtr->width, 1145 volPtr->range_max()); 1146 NanoVis::initParticle(); 1147 } 1148 if (NanoVis::licRenderer != NULL) { 1149 NanoVis::licRenderer->setVectorField(volPtr->id, 1150 1.0f / volPtr->aspect_ratio_width, 1151 1.0f / volPtr->aspect_ratio_height, 1152 1.0f / volPtr->aspect_ratio_depth, 1153 volPtr->range_max()); 1154 NanoVis::licRenderer->set_offset(NanoVis::lic_slice_z); 1155 } 1156 } else if (c == 'l' && strcmp(argv[1], "lic") == 0) { 1157 if (argc != 3) { 1158 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1159 " lic on|off\"", (char*)NULL); 1144 1160 return TCL_ERROR; 1145 1161 } 1146 1147 if (NanoVis::particleRenderer) 1148 { 1149 1150 NanoVis::particleRenderer->setVectorField( 1151 NanoVis::volume[n]->id, 1152 1.0f, 1153 NanoVis::volume[n]->height / (float) NanoVis::volume[n]->width, 1154 NanoVis::volume[n]->depth / (float) NanoVis::volume[n]->width, 1155 NanoVis::volume[n]->range_max()); 1156 1157 NanoVis::initParticle(); 1158 1159 } 1160 1161 if (NanoVis::licRenderer) 1162 { 1163 NanoVis::licRenderer->setVectorField( 1164 NanoVis::volume[n]->id, 1165 1.0f/NanoVis::volume[n]->aspect_ratio_width, 1166 1.0f/NanoVis::volume[n]->aspect_ratio_height, 1167 1.0f/NanoVis::volume[n]->aspect_ratio_depth, 1168 NanoVis::volume[n]->range_max()); 1169 NanoVis::licRenderer->set_offset(NanoVis::lic_slice_z); 1170 } 1171 } 1172 else if (c == 'l' && strcmp(argv[1],"lic") == 0) 1173 { 1162 int ibool; 1163 if (Tcl_GetBoolean(interp, argv[2], &ibool) != TCL_OK) { 1164 return TCL_ERROR; 1165 } 1166 NanoVis::lic_on = (bool)ibool; 1167 } else if ((c == 'p') && (strcmp(argv[1], "particle") == 0)) { 1174 1168 if (argc < 3) { 1175 1169 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1176 argv[1], " on|off\"", (char*)NULL);1170 " particle visible|slice|slicepos arg \"", (char*)NULL); 1177 1171 return TCL_ERROR; 1178 1172 } 1179 1180 char ch = argv[2][0]; 1181 if (ch == 'o' && strcmp(argv[2],"on") == 0) 1182 { 1183 NanoVis::lic_on = true; 1184 } 1185 else if (ch == 'o' && strcmp(argv[2],"off") == 0) 1186 { 1187 NanoVis::lic_on = false; 1188 } 1189 else 1190 { 1191 return TCL_ERROR; 1192 } 1193 } 1194 else if (c == 'p' && strcmp(argv[1],"particle") == 0) 1195 { 1196 if (argc < 4) { 1173 c = argv[2][0]; 1174 if ((c == 'v') && (strcmp(argv[2], "visible") == 0)) { 1175 if (argc != 4) { 1176 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1177 " particle visible on|off\"", (char*)NULL); 1178 return TCL_ERROR; 1179 } 1180 int state; 1181 if (Tcl_GetBoolean(interp, argv[2], &state) != TCL_OK) { 1182 return TCL_ERROR; 1183 } 1184 NanoVis::particle_on = state; 1185 } else if ((c == 's') && (strcmp(argv[2], "slice") == 0)) { 1186 if (argc != 4) { 1187 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1188 " particle slice volume\"", (char*)NULL); 1189 return TCL_ERROR; 1190 } 1191 int axis; 1192 if (GetAxis(interp, argv[3], &axis) != TCL_OK) { 1193 return TCL_ERROR; 1194 } 1195 NanoVis::lic_axis = axis; 1196 } else if ((c == 's') && (strcmp(argv[2], "slicepos") == 0)) { 1197 if (argc != 4) { 1198 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1199 " particle slicepos value\"", (char*)NULL); 1200 return TCL_ERROR; 1201 } 1202 float pos; 1203 if (GetFloat(interp, argv[2], &pos) != TCL_OK) { 1204 return TCL_ERROR; 1205 } 1206 if (pos < 0.0f) { 1207 pos = 0.0f; 1208 } else if (pos > 1.0f) { 1209 pos = 1.0f; 1210 } 1211 switch (NanoVis::lic_axis) { 1212 case 0 : 1213 NanoVis::lic_slice_x = pos; 1214 break; 1215 case 1 : 1216 NanoVis::lic_slice_y = pos; 1217 break; 1218 case 2 : 1219 NanoVis::lic_slice_z = pos; 1220 break; 1221 } 1222 } else { 1223 Tcl_AppendResult(interp, "unknown operation \"", argv[2], 1224 "\": should be \"", argv[0], " visible, slice, or slicepos\"", 1225 (char *)NULL); 1226 return TCL_ERROR; 1227 } 1228 } else if ((c == 'r') && (strcmp(argv[1],"reset") == 0)) { 1229 NanoVis::initParticle(); 1230 } else if ((c == 'c') && (strcmp(argv[1],"capture") == 0)) { 1231 if (argc != 3) { 1197 1232 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1198 argv[1], " more parameters\"", (char*)NULL);1233 " capture numframes\"", (char*)NULL); 1199 1234 return TCL_ERROR; 1200 1235 } 1201 1202 char ch = argv[2][0]; 1203 if (ch == 'v' && strcmp(argv[2],"visible") == 0) 1204 { 1205 int state; 1206 if (Tcl_GetBoolean(interp, argv[2], &state) != TCL_OK) 1207 { 1208 return TCL_ERROR; 1209 } 1210 NanoVis::particle_on = state; 1211 } 1212 else if (ch == 's' && strcmp(argv[2],"slice") == 0) 1213 { 1214 if (argv[3][0] == 'x') 1215 { 1216 NanoVis::lic_axis = 0; 1217 } 1218 else if (argv[3][0] == 'y') 1219 { 1220 NanoVis::lic_axis = 1; 1221 } 1222 else if (argv[3][0] == 'z') 1223 { 1224 NanoVis::lic_axis = 2; 1225 } 1226 else 1227 { 1228 // TBD.. put error message 1229 return TCL_ERROR; 1230 } 1231 1232 } 1233 else if (ch == 's' && strcmp(argv[2],"slicepos") == 0) 1234 { 1235 float pos; 1236 if (GetFloat(interp, argv[2], &pos) != TCL_OK) 1237 { 1238 return TCL_ERROR; 1239 } 1240 1241 if (pos < 0.0f) pos = 0.0f; 1242 if (pos > 1.0f) pos = 1.0f; 1243 1244 switch (NanoVis::lic_axis) 1245 { 1246 case 0 : 1247 NanoVis::lic_slice_x = pos; 1248 break; 1249 case 1 : 1250 NanoVis::lic_slice_y = pos; 1251 break; 1252 case 2 : 1253 NanoVis::lic_slice_z = pos; 1254 break; 1255 } 1256 } 1257 else 1258 { 1259 return TCL_ERROR; 1260 } 1261 } 1262 else if (c == 'r' && strcmp(argv[1],"reset") == 0) 1263 { 1264 NanoVis::initParticle(); 1265 } 1266 else if (c == 'c' && strcmp(argv[1],"capture") == 0) 1267 { 1268 int total_frame_count = 0; 1269 if (Tcl_GetInt(interp, argv[2], &total_frame_count) != TCL_OK) 1270 { 1271 return TCL_ERROR; 1272 } 1273 1274 if (NanoVis::licRenderer) NanoVis::licRenderer->activate(); 1275 if (NanoVis::particleRenderer) NanoVis::particleRenderer->activate(); 1276 1236 int total_frame_count; 1237 1238 if (Tcl_GetInt(interp, argv[2], &total_frame_count) != TCL_OK) { 1239 return TCL_ERROR; 1240 } 1241 if (NanoVis::licRenderer) { 1242 NanoVis::licRenderer->activate(); 1243 } 1244 if (NanoVis::particleRenderer) { 1245 NanoVis::particleRenderer->activate(); 1246 } 1277 1247 // Karl 1278 { 1279 1280 for (int frame_count = 0; frame_count<total_frame_count; frame_count++) { 1281 1282 // Generate the latest frame and send it back to the client 1283 if (NanoVis::licRenderer && NanoVis::licRenderer->isActivated()) 1284 NanoVis::licRenderer->convolve(); 1285 1286 if (NanoVis::particleRenderer && NanoVis::particleRenderer->isActivated()) 1287 NanoVis::particleRenderer->advect(); 1288 1289 NanoVis::offscreen_buffer_capture(); //enable offscreen render 1290 NanoVis::display(); 1291 1292 // printf("Read Screen for Writing to file...\n"); 1293 1294 NanoVis::read_screen(); 1295 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1296 1297 NanoVis::bmp_write_to_file(frame_count); 1298 // printf("Writing to file...\n"); 1299 } 1300 1301 1302 }// put your code... 1303 1304 if (NanoVis::licRenderer) NanoVis::licRenderer->deactivate(); 1305 if (NanoVis::particleRenderer) NanoVis::particleRenderer->deactivate(); 1248 for (int frame_count = 0; frame_count < total_frame_count; 1249 frame_count++) { 1250 1251 // Generate the latest frame and send it back to the client 1252 if (NanoVis::licRenderer && 1253 NanoVis::licRenderer->isActivated()) { 1254 NanoVis::licRenderer->convolve(); 1255 } 1256 if (NanoVis::particleRenderer && 1257 NanoVis::particleRenderer->isActivated()) { 1258 NanoVis::particleRenderer->advect(); 1259 } 1260 NanoVis::offscreen_buffer_capture(); //enable offscreen render 1261 NanoVis::display(); 1262 1263 // printf("Read Screen for Writing to file...\n"); 1264 1265 NanoVis::read_screen(); 1266 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1267 1268 NanoVis::bmp_write_to_file(frame_count); 1269 // printf("Writing to file...\n"); 1270 } 1271 // put your code... 1272 if (NanoVis::licRenderer) { 1273 NanoVis::licRenderer->deactivate(); 1274 } 1275 if (NanoVis::particleRenderer) { 1276 NanoVis::particleRenderer->deactivate(); 1277 } 1306 1278 NanoVis::initParticle(); 1307 } 1308 else if (c == 'd' && strcmp(argv[1],"data") == 0) 1309 { 1310 char ch = argv[2][0]; 1311 if (ch == 'f' && strcmp(argv[2],"follows") == 0) { 1279 } else if (c == 'd' && strcmp(argv[1],"data") == 0) { 1280 if (argc < 3) { 1281 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1282 " data follows ?args?", (char *)NULL); 1283 return TCL_ERROR; 1284 } 1285 c = argv[2][0]; 1286 if ((c == 'f') && (strcmp(argv[2],"follows") == 0)) { 1287 if (argc != 4) { 1288 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1289 " data follows length", (char *)NULL); 1290 return TCL_ERROR; 1291 } 1312 1292 int nbytes; 1313 if (Tcl_GetInt(interp, argv[3], &nbytes) != TCL_OK) 1314 { 1315 return TCL_ERROR; 1316 } 1317 1318 Rappture::Buffer buf; 1319 if (getDataStream(nbytes, &buf) != TCL_OK) 1320 { 1321 /// TBD.. 1322 //Tcl_AppendResult(interp, err.remark().c_str(), (char*)NULL); 1323 return TCL_ERROR; 1324 } 1325 1293 if (Tcl_GetInt(interp, argv[3], &nbytes) != TCL_OK) { 1294 return TCL_ERROR; 1295 } 1296 Rappture::Buffer buf; 1297 if (GetDataStream(interp, buf, nbytes) != TCL_OK) { 1298 return TCL_ERROR; 1299 } 1326 1300 int n = NanoVis::n_volumes; 1327 1301 std::stringstream fdata; 1328 1302 fdata.write(buf.bytes(),buf.size()); 1329 1303 load_vector_stream(n, fdata); 1330 1304 Volume *volPtr = NanoVis::volume[n]; 1305 1331 1306 // 1332 1307 // BE CAREFUL: Set the number of slices to something … … 1337 1312 // appear at all. 1338 1313 // 1339 if (NanoVis::volume[n] != NULL) 1340 { 1341 NanoVis::volume[n]->set_n_slice(256-n); 1342 NanoVis::volume[n]->disable_cutplane(0); 1343 NanoVis::volume[n]->disable_cutplane(1); 1344 NanoVis::volume[n]->disable_cutplane(2); 1345 1346 NanoVis::vol_renderer->add_volume(NanoVis::volume[n],NanoVis::get_transfunc("default")); 1347 } 1348 } 1349 } 1350 else 1351 { 1314 if (volPtr != NULL) { 1315 volPtr->set_n_slice(256-n); 1316 volPtr->disable_cutplane(0); 1317 volPtr->disable_cutplane(1); 1318 volPtr->disable_cutplane(2); 1319 1320 NanoVis::vol_renderer->add_volume(volPtr, 1321 NanoVis::get_transfunc("default")); 1322 } 1323 } 1324 } else { 1352 1325 return TCL_ERROR; 1353 1326 } 1354 1355 1327 return TCL_OK; 1356 1328 } … … 1375 1347 1376 1348 HeightMap* heightMap = new HeightMap(); 1377 1378 1379 1380 1349 float minx = 0.0f; 1350 float maxx = 1.0f; 1351 float miny = 0.5f; 1352 float maxy = 3.5f; 1381 1353 heightMap->setHeight(minx, miny, maxx, maxy, 20, 200, data); 1382 1354 heightMap->setColorMap(NanoVis::get_transfunc("default")); … … 1386 1358 1387 1359 1388 1389 1390 1391 1392 1393 1360 Vector3 min(minx, (float) heightMap->range_min(), miny); 1361 Vector3 max(maxx, (float) heightMap->range_max(), maxy); 1362 1363 NanoVis::grid->setMinMax(min, max); 1364 NanoVis::grid->setVisible(true); 1365 1394 1366 return TCL_OK; 1395 1367 } … … 1409 1381 return TCL_OK; 1410 1382 } else if ((c == 'd') && (strcmp(argv[1],"data") == 0)) { 1383 if (argc < 3) { 1384 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1385 " data follows|visible ?args?", (char *)NULL); 1386 return TCL_ERROR; 1387 } 1411 1388 //bytes 1412 1389 char c; 1413 1390 c = argv[2][0]; 1414 1391 if ((c == 'v') && (strcmp(argv[2],"visible") == 0)) { 1392 if (argc < 4) { 1393 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1394 " data visible bool ?indices?", (char *)NULL); 1395 return TCL_ERROR; 1396 } 1415 1397 int ivisible; 1416 1398 vector<unsigned int> indices; … … 1431 1413 } 1432 1414 } else if ((c == 'f') && (strcmp(argv[2],"follows") == 0)) { 1415 if (argc != 4) { 1416 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1417 " data follow length", (char *)NULL); 1418 return TCL_ERROR; 1419 } 1433 1420 Rappture::Buffer buf; 1434 1421 int nBytes; … … 1437 1424 return TCL_ERROR; 1438 1425 } 1439 if ( FillBufferFromStdin(interp, buf, nBytes) != TCL_OK) {1426 if (GetDataStream(interp, buf, nBytes) != TCL_OK) { 1440 1427 return TCL_ERROR; 1441 1428 } … … 1452 1439 } 1453 1440 } else if ((c == 'l') && (strcmp(argv[1], "linecontour") == 0)) { 1454 //bytes 1441 if (argc < 3) { 1442 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1443 " linecontour visible|color ?args?", (char *)NULL); 1444 return TCL_ERROR; 1445 } 1455 1446 vector<unsigned int> indices; 1456 1447 char c; 1457 1448 c = argv[2][0]; 1458 1449 if ((c == 'v') && (strcmp(argv[2],"visible") == 0)) { 1450 if (argc < 4) { 1451 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1452 " linecontour visible boolean ?indices?", (char *)NULL); 1453 return TCL_ERROR; 1454 } 1459 1455 int ivisible; 1460 1456 bool visible; 1461 1462 1457 if (Tcl_GetBoolean(interp, argv[3], &ivisible) != TCL_OK) { 1463 1458 return TCL_ERROR; … … 1474 1469 } 1475 1470 } else if ((c == 'c') && (strcmp(argv[2],"color") == 0)) { 1471 if (argc < 6) { 1472 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1473 " linecontour color r g b ?indices?", (char *)NULL); 1474 return TCL_ERROR; 1475 } 1476 1476 float r, g, b; 1477 1477 if ((GetFloat(interp, argv[3], &r) != TCL_OK) || … … 1496 1496 } 1497 1497 } else if ((c == 't') && (strcmp(argv[1], "transfunc") == 0)) { 1498 if (argc < 3) { 1499 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1500 " transfunc name ?indices?", (char *)NULL); 1501 return TCL_ERROR; 1502 } 1498 1503 TransferFunction *tf; 1499 1504 1500 1505 tf = NanoVis::get_transfunc(argv[2]); 1501 1506 if (tf == NULL) { 1502 1507 Tcl_AppendResult(interp, "transfer function \"", argv[2], … … 1505 1510 } 1506 1511 vector<unsigned int> indices; 1507 if (GetIndices(interp, argc - 3, argv + 3, &indices) != TCL_OK) 1512 if (GetIndices(interp, argc - 3, argv + 3, &indices) != TCL_OK) { 1508 1513 return TCL_ERROR; 1509 } 1510 for (unsigned int i = 0; i < indices.size(); ++i) { 1511 if ((indices[i] < NanoVis::heightMap.size()) && 1512 (NanoVis::heightMap[indices[i]] != NULL)) { 1513 NanoVis::heightMap[indices[i]]->setColorMap(tf); 1514 } 1515 } 1516 } 1517 else if ((c == 'l') && (strcmp(argv[1], "legend") == 0)) { 1518 if (argc != 5) { 1519 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1514 } 1515 for (unsigned int i = 0; i < indices.size(); ++i) { 1516 if ((indices[i] < NanoVis::heightMap.size()) && 1517 (NanoVis::heightMap[indices[i]] != NULL)) { 1518 NanoVis::heightMap[indices[i]]->setColorMap(tf); 1519 } 1520 } 1521 } else if ((c == 'l') && (strcmp(argv[1], "legend") == 0)) { 1522 if (argc != 5) { 1523 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1520 1524 " legend index width height\"", (char*)NULL); 1521 return TCL_ERROR; 1522 } 1523 HeightMap *hMap; 1524 if (GetHeightMap(interp, argv[2], &hMap) != TCL_OK) { 1525 return TCL_ERROR; 1526 } 1527 TransferFunction *tf; 1528 tf = hMap->getColorMap(); 1529 if (tf == NULL) { 1530 Tcl_AppendResult(interp, 1531 "no transfer function defined for heightmap \"", 1532 argv[1], "\"", (char*)NULL); 1533 return TCL_ERROR; 1534 } 1535 int width, height; 1536 if ((Tcl_GetInt(interp, argv[3], &width) != TCL_OK) || 1537 (Tcl_GetInt(interp, argv[4], &height) != TCL_OK)) { 1538 return TCL_ERROR; 1539 } 1540 NanoVis::render_legend(tf, hMap->range_min(), hMap->range_max(), 1541 width, height, argv[1]); 1542 } 1543 else if ((c == 'p') && (strcmp(argv[1], "polygon") == 0)) 1544 { 1545 if (!strcmp(argv[2],"wireframe")) 1546 { 1547 NanoVis::renderContext->setPolygonMode(graphics::RenderContext::LINE); 1548 return TCL_OK; 1549 } 1550 else if (!strcmp(argv[2],"fill")) 1551 { 1552 NanoVis::renderContext->setPolygonMode(graphics::RenderContext::FILL); 1553 return TCL_OK; 1554 } 1555 return TCL_ERROR; 1556 } 1557 else if ((c == 'c') && (strcmp(argv[1], "cull") == 0)) 1558 { 1559 if (!strcmp(argv[2],"no")) 1560 { 1561 NanoVis::renderContext->setCullMode(graphics::RenderContext::NO_CULL); 1562 return TCL_OK; 1563 } 1564 else if (!strcmp(argv[2],"front")) 1565 { 1566 NanoVis::renderContext->setCullMode(graphics::RenderContext::FRONT); 1567 return TCL_OK; 1568 } 1569 else if (!strcmp(argv[2],"back")) 1570 { 1571 NanoVis::renderContext->setCullMode(graphics::RenderContext::BACK); 1572 return TCL_OK; 1573 } 1574 return TCL_ERROR; 1575 } 1576 else if ((c == 's') && (strcmp(argv[1], "shade") == 0)) 1577 { 1578 if (!strcmp(argv[2],"flat")) 1579 { 1580 NanoVis::renderContext->setShadingModel(graphics::RenderContext::FLAT); 1581 return TCL_OK; 1582 } 1583 else if (!strcmp(argv[2],"smooth")) 1584 { 1585 NanoVis::renderContext->setShadingModel(graphics::RenderContext::SMOOTH); 1586 return TCL_OK; 1587 } 1588 return TCL_ERROR; 1589 } 1590 else { 1591 Tcl_AppendResult(interp, "bad option \"", argv[1], 1592 "\": should be data, linecontour, legend, or transfunc", (char*)NULL); 1593 return TCL_ERROR; 1525 return TCL_ERROR; 1526 } 1527 HeightMap *hMap; 1528 if (GetHeightMap(interp, argv[2], &hMap) != TCL_OK) { 1529 return TCL_ERROR; 1530 } 1531 TransferFunction *tf; 1532 tf = hMap->getColorMap(); 1533 if (tf == NULL) { 1534 Tcl_AppendResult(interp, 1535 "no transfer function defined for heightmap \"", argv[1], "\"", 1536 (char*)NULL); 1537 return TCL_ERROR; 1538 } 1539 int width, height; 1540 if ((Tcl_GetInt(interp, argv[3], &width) != TCL_OK) || 1541 (Tcl_GetInt(interp, argv[4], &height) != TCL_OK)) { 1542 return TCL_ERROR; 1543 } 1544 NanoVis::render_legend(tf, hMap->range_min(), hMap->range_max(), 1545 width, height, argv[1]); 1546 } else if ((c == 'p') && (strcmp(argv[1], "polygon") == 0)) { 1547 if (argc != 3) { 1548 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1549 " polygon mode", (char *)NULL); 1550 return TCL_ERROR; 1551 } 1552 graphics::RenderContext::PolygonMode mode; 1553 if (GetPolygonMode(interp, argv[2], &mode) != TCL_OK) { 1554 return TCL_ERROR; 1555 } 1556 NanoVis::renderContext->setPolygonMode(mode); 1557 } else if ((c == 'c') && (strcmp(argv[1], "cull") == 0)) { 1558 if (argc != 3) { 1559 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1560 " cull mode", (char *)NULL); 1561 return TCL_ERROR; 1562 } 1563 graphics::RenderContext::CullMode mode; 1564 if (GetCullMode(interp, argv[2], &mode) != TCL_OK) { 1565 return TCL_ERROR; 1566 } 1567 NanoVis::renderContext->setCullMode(mode); 1568 } else if ((c == 's') && (strcmp(argv[1], "shade") == 0)) { 1569 if (argc != 3) { 1570 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 1571 " shade model", (char *)NULL); 1572 return TCL_ERROR; 1573 } 1574 graphics::RenderContext::ShadingModel model; 1575 if (GetShadingModel(interp, argv[2], &model) != TCL_OK) { 1576 return TCL_ERROR; 1577 } 1578 NanoVis::renderContext->setShadingModel(model); 1579 } else { 1580 Tcl_AppendResult(interp, "bad option \"", argv[1], 1581 "\": should be data, linecontour, legend, or transfunc", (char*)NULL); 1582 return TCL_ERROR; 1594 1583 } 1595 1584 return TCL_OK; … … 2210 2199 * ----------------------------------------------------------------------- 2211 2200 * 2212 * FillBufferFromStdin--2201 * GetDataStream -- 2213 2202 * 2214 2203 * Read the requested number of bytes from standard input into the given … … 2218 2207 */ 2219 2208 static int 2220 FillBufferFromStdin(Tcl_Interp *interp, Rappture::Buffer &buf, int nBytes)2209 GetDataStream(Tcl_Interp *interp, Rappture::Buffer &buf, int nBytes) 2221 2210 { 2222 2211 char buffer[8096]; … … 2226 2215 int nRead; 2227 2216 2228 chunk = (sizeof(buffer) < (unsigned int) nBytes) ? sizeof(buffer) : nBytes; 2217 chunk = (sizeof(buffer) < (unsigned int) nBytes) ? 2218 sizeof(buffer) : nBytes; 2229 2219 nRead = fread(buffer, 1, chunk, stdin); 2230 if (ferror(stdin) && feof(stdin)) { 2231 Tcl_AppendResult(interp, 2232 "data unpacking failed: unexpected EOF", 2233 (char*)NULL); 2234 return TCL_ERROR; 2220 if (feof(stdin)) { 2221 Tcl_AppendResult(interp, "premature EOF while reading data stream", 2222 (char*)NULL); 2223 return TCL_ERROR; 2224 } 2225 if (ferror(stdin)) { 2226 Tcl_AppendResult(interp, "error while reading data stream: ", 2227 Tcl_PosixError(interp), (char*)NULL); 2228 return TCL_ERROR; 2235 2229 } 2236 2230 buf.append(buffer, nRead);
Note: See TracChangeset
for help on using the changeset viewer.