Changeset 1493 for trunk/packages
- Timestamp:
- Jun 8, 2009, 8:31:59 AM (15 years ago)
- Location:
- trunk/packages/vizservers/nanovis
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/Command.cpp
r1484 r1493 91 91 extern Texture2D* plane[10]; 92 92 93 extern bool load_volume_stream(Rappture::Outcome &status, int index,94 std::iostream& fin);95 extern bool load_volume_stream_odx(Rappture::Outcome &status, int index,96 const char *buf, int nBytes);97 extern bool load_volume_stream2(Rappture::Outcome &status, int index,98 std::iostream& fin);99 100 extern bool load_vector_stream(Rappture::Outcome &result, int index,101 size_t length, char *bytes);102 extern bool load_vector_stream2(Rappture::Outcome &result, int index,103 size_t length, char *bytes);104 extern bool MakeVectorFieldFromUnirect3d(Rappture::Outcome &result,105 Rappture::Unirect3d &data);106 107 extern void load_volume(int index, int width, int height, int depth,108 int n_component, float* data, double vmin, double vmax,109 double nzero_min);110 93 // Tcl interpreter for incoming messages 111 94 … … 301 284 hmPtr = new HeightMap(); 302 285 hmPtr->setHeight(xMin, yMin, xMax, yMax, xNum, yNum, heights); 303 hmPtr-> setColorMap(NanoVis::get_transfunc("default"));286 hmPtr->transferFunction(NanoVis::get_transfunc("default")); 304 287 hmPtr->setVisible(true); 305 288 hmPtr->setLineContourVisible(true); … … 353 336 hmPtr = NanoVis::heightMap[index]; 354 337 if (hmPtr == NULL) { 355 Tcl_AppendResult(interp, "no heightmap defined for index \"", 356 Tcl_GetString(objPtr), "\"", (char*)NULL); 357 return TCL_ERROR; 338 if (interp != NULL) { 339 Tcl_AppendResult(interp, "no heightmap defined for index \"", 340 Tcl_GetString(objPtr), "\"", (char*)NULL); 341 } 342 return TCL_ERROR; 358 343 } 359 344 *hmPtrPtr = hmPtr; … … 361 346 } 362 347 348 363 349 /* 364 350 * ---------------------------------------------------------------------- 365 * FUNCTION: GetVolume DataID351 * FUNCTION: GetVolumeFromObj 366 352 * 367 353 * Used internally to decode a series of volume index values and … … 375 361 */ 376 362 static int 377 GetVolumeIndex(Tcl_Interp *interp, Tcl_Obj *objPtr, unsigned int *idPtr) 378 { 379 int index; 380 if (Tcl_GetIntFromObj(interp, objPtr, &index) != TCL_OK) { 381 return TCL_ERROR; 382 } 383 if (index < 0) { 384 Tcl_AppendResult(interp, "can't have negative index \"", 385 Tcl_GetString(objPtr), "\"", (char*)NULL); 386 return TCL_ERROR; 387 } 388 if (index >= (int)NanoVis::volumes.size()) { 389 Tcl_AppendResult(interp, "index \"", Tcl_GetString(objPtr), 390 "\" is out of range", (char*)NULL); 391 return TCL_ERROR; 392 } 393 if (NanoVis::volumes[index] == NULL) { 394 Tcl_AppendResult(interp, "can't find volume \"", Tcl_GetString(objPtr), 395 "\"", (char*)NULL); 396 return TCL_ERROR; 397 } 398 *idPtr = (unsigned int)index; 363 GetVolumeFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, Volume **volPtrPtr) 364 { 365 const char *string; 366 string = Tcl_GetString(objPtr); 367 368 Tcl_HashEntry *hPtr; 369 hPtr = Tcl_FindHashEntry(&NanoVis::volumeTable, string); 370 if (hPtr == NULL) { 371 if (interp != NULL) { 372 Tcl_AppendResult(interp, "can't find a volume name \"", 373 string, "\"", (char*)NULL); 374 } 375 return TCL_ERROR; 376 } 377 *volPtrPtr = (Volume *)Tcl_GetHashValue(hPtr); 399 378 return TCL_OK; 400 379 } … … 402 381 /* 403 382 * ---------------------------------------------------------------------- 404 * FUNCTION: GetVolume FromObj383 * FUNCTION: GetVolumes() 405 384 * 406 385 * Used internally to decode a series of volume index values and … … 414 393 */ 415 394 static int 416 GetVolumeFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, Volume **volPtrPtr)417 {418 unsigned int index;419 if (GetVolumeIndex(interp, objPtr, &index) != TCL_OK) {420 return TCL_ERROR;421 }422 Volume *volPtr;423 volPtr = NanoVis::volumes[index];424 if (volPtr == NULL) {425 Tcl_AppendResult(interp, "no volume defined for index \"",426 Tcl_GetString(objPtr), "\"", (char*)NULL);427 return TCL_ERROR;428 }429 *volPtrPtr = volPtr;430 return TCL_OK;431 }432 433 /*434 * ----------------------------------------------------------------------435 * FUNCTION: GetVolumeIndices()436 *437 * Used internally to decode a series of volume index values and438 * store then in the specified vector. If there are no volume index439 * arguments, this means "all volumes" to most commands, so all440 * active volume indices are stored in the vector.441 *442 * Updates pushes index values into the vector. Returns TCL_OK or443 * TCL_ERROR to indicate an error.444 * ----------------------------------------------------------------------445 */446 static int447 GetVolumeIndices(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv,448 vector<unsigned int>* vectorPtr)449 {450 if (objc == 0) {451 vector<Volume *>::iterator iter;452 for (iter = NanoVis::volumes.begin(); iter != NanoVis::volumes.end();453 ++iter) {454 if ((*iter) != NULL) {455 vectorPtr->push_back((*iter)->dataID());456 }457 }458 } else {459 vector<Volume *>::iterator iter;460 for (int n = 0; n < objc; n++) {461 unsigned int index;462 463 if (GetVolumeIndex(interp, objv[n], &index) != TCL_OK) {464 return TCL_ERROR;465 }466 if (NanoVis::volumes[index] != NULL) {467 vectorPtr->push_back(index);468 }469 }470 }471 return TCL_OK;472 }473 474 /*475 * ----------------------------------------------------------------------476 * FUNCTION: GetVolumes()477 *478 * Used internally to decode a series of volume index values and479 * store then in the specified vector. If there are no volume index480 * arguments, this means "all volumes" to most commands, so all481 * active volume indices are stored in the vector.482 *483 * Updates pushes index values into the vector. Returns TCL_OK or484 * TCL_ERROR to indicate an error.485 * ----------------------------------------------------------------------486 */487 static int488 395 GetVolumes(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv, 489 396 vector<Volume *>* vectorPtr) … … 491 398 if (objc == 0) { 492 399 // No arguments. Get all volumes. 493 vector<Volume *>::iterator iter; 494 for (iter = NanoVis::volumes.begin(); iter != NanoVis::volumes.end(); 495 ++iter) { 496 if ((*iter) != NULL) { 497 vectorPtr->push_back((*iter)); 498 } 499 } 400 Tcl_HashSearch iter; 401 Tcl_HashEntry *hPtr; 402 for (hPtr = Tcl_FirstHashEntry(&NanoVis::volumeTable, &iter); 403 hPtr != NULL; hPtr = Tcl_NextHashEntry(&iter)) { 404 Volume *volPtr; 405 volPtr = (Volume *)Tcl_GetHashValue(hPtr); 406 vectorPtr->push_back(volPtr); 407 } 500 408 } else { 501 409 // Get the volumes associated with the given index arguments. … … 947 855 } 948 856 949 const char *string = Tcl_GetString(objv[1]); 857 const char *name; 858 name = Tcl_GetString(objv[1]); 950 859 TransferFunction *tf; 951 tf = NanoVis::get_transfunc( string);860 tf = NanoVis::get_transfunc(name); 952 861 if (tf == NULL) { 953 Tcl_AppendResult(interp, "unknown transfer function \"", string, "\"",862 Tcl_AppendResult(interp, "unknown transfer function \"", name, "\"", 954 863 (char*)NULL); 955 864 return TCL_ERROR; 956 865 } 957 const char *label;958 label = Tcl_GetString(objv[1]);959 866 int w, h; 960 867 if ((Tcl_GetIntFromObj(interp, objv[2], &w) != TCL_OK) || … … 965 872 NanoVis::SetVolumeRanges(); 966 873 } 967 NanoVis::render_legend(tf, Volume::valueMin, Volume::valueMax, w, h, label);874 NanoVis::render_legend(tf, Volume::valueMin, Volume::valueMax, w, h, name); 968 875 return TCL_OK; 969 876 } … … 1201 1108 } 1202 1109 Trace("parsing volume data identifier\n"); 1203 vector<Volume *>::iterator iter; 1204 for (iter = volumes.begin(); iter != volumes.end(); iter++) { 1205 Trace("volDataID: %d\n", (*iter)->dataID()); 1206 NanoVis::vol_renderer->addAnimatedVolume((*iter)); 1110 Tcl_HashSearch iter; 1111 Tcl_HashEntry *hPtr; 1112 for (hPtr = Tcl_FirstHashEntry(&NanoVis::volumeTable, &iter); hPtr != NULL; 1113 hPtr = Tcl_NextHashEntry(&iter)) { 1114 Volume *volPtr; 1115 volPtr = (Volume *)Tcl_GetHashValue(hPtr); 1116 NanoVis::vol_renderer->addAnimatedVolume(volPtr); 1207 1117 } 1208 1118 return TCL_OK; … … 1272 1182 fflush(stdout); 1273 1183 1274 Volume *volPtr = 0;1275 int volDataID = -1;1276 if (str cmp(header, "<HDR>") == 0) {1184 Volume *volPtr; 1185 volPtr = NULL; // Supress compiler warning. 1186 if (strncmp(header, "<HDR>", 5) == 0) { 1277 1187 printf("ZincBlende stream is in\n"); 1278 1188 fflush(stdout); 1279 //std::stringstream fdata(std::ios_base::out|std::ios_base::in|std::ios_base::binary);1189 //std::stringstream fdata(std::ios_base::out|std::ios_base::in|std::ios_base::binary); 1280 1190 //fdata.write(buf.bytes(),buf.size()); 1281 1191 //vol = NvZincBlendeReconstructor::getInstance()->loadFromStream(fdata); … … 1288 1198 if (volPtr == NULL) { 1289 1199 Tcl_AppendResult(interp, "can't get volume instance", (char *)NULL); 1290 return TCL_ OK;1200 return TCL_ERROR; 1291 1201 } 1292 1202 printf("finish loading\n"); … … 1295 1205 // INSOO 1296 1206 // TBD.. 1297 volDataID = NanoVis::volumes.size();// Next identifier available1207 // Next identifier available 1298 1208 float dx0 = -0.5; 1299 1209 float dy0 = -0.5*volPtr->height/volPtr->width; 1300 1210 float dz0 = -0.5*volPtr->depth/volPtr->width; 1301 1211 volPtr->location(Vector3(dx0, dy0, dz0)); 1302 volPtr->dataID(volDataID); 1303 NanoVis::volumes.push_back(volPtr); 1212 int isNew; 1213 Tcl_HashEntry *hPtr; 1214 hPtr = Tcl_CreateHashEntry(&NanoVis::volumeTable, tag, &isNew); 1215 if (!isNew) { 1216 Tcl_AppendResult(interp, "volume \"", tag, "\" already exists.", 1217 (char *)NULL); 1218 return TCL_ERROR; 1219 } 1220 Tcl_SetHashValue(hPtr, volPtr); 1221 volPtr->name(Tcl_GetHashKey(&NanoVis::volumeTable, hPtr)); 1304 1222 #if __TEST_CODE__ 1305 } else if (str cmp(header, "<FET>") == 0) {1223 } else if (strncmp(header, "<FET>", 5) == 0) { 1306 1224 printf("FET loading...\n"); 1307 1225 fflush(stdout); 1308 1226 std::stringstream fdata; 1309 1227 fdata.write(buf.bytes(),buf.size()); 1310 if (!load_volume_stream3(err, n, fdata)) { 1228 volPtr = load_volume_stream3(err, tag, fdata); 1229 if (volPtr == NULL) { 1311 1230 Tcl_AppendResult(interp, err.remark(), (char*)NULL); 1312 1231 return TCL_ERROR; 1313 1232 } 1314 1233 #endif /*__TEST_CODE__*/ 1315 } else if (str cmp(header, "<ODX>") == 0) {1234 } else if (strncmp(header, "<ODX>", 5) == 0) { 1316 1235 /* 1317 1236 Rappture::Outcome err; … … 1319 1238 printf("Loading DX using OpenDX library...\n"); 1320 1239 fflush(stdout); 1321 if (!load_volume_stream_odx(err, n, buf.bytes()+5, buf.size()-5)) { 1240 volPtr = load_volume_stream_odx(err, n, buf.bytes()+5, buf.size()-5); 1241 if (volPtr == NULL) { 1322 1242 Tcl_AppendResult(interp, err.remark(), (char*)NULL); 1323 1243 return TCL_ERROR; … … 1325 1245 */ 1326 1246 } else { 1327 printf("test\n");1328 #ifdef notdef1329 Rappture::Unirect3d *dataPtr;1330 1331 dataPtr = new Rappture::Unirect3d(1);1332 if (!dataPtr->ImportDx(result, 1, buf.size(), (char *)buf.bytes())) {1333 Tcl_AppendResult(interp, result.remark(), (char *)NULL);1334 delete dataPtr;1335 return TCL_ERROR;1336 }1337 #if !ISO_TEST1338 dataPtr->Resample(context, 30);1339 #endif1340 volPtr = NanoVis::load_volume(-1, nx, ny, nz, 4, data, vmin, vmax,1341 nzero_min);1342 1343 volPtr->xAxis.SetRange(dataPtr->xMin(), dataPtr->xMin() + (nx * dx));1344 volPtr->yAxis.SetRange(dataPtr->yMin(), dataPtr->yMin() + (ny * dy));1345 volPtr->zAxis.SetRange(dataPtr->zMin(), dataPtr->zMin() + (nz * dz));1346 volPtr->wAxis.SetRange(vmin, vmax);1347 volPtr->update_pending = true;1348 1349 flowPtr->SetData(dataPtr);1350 #endif1351 1247 printf("OpenDX loading...\n"); 1352 1248 fflush(stdout); 1353 1249 std::stringstream fdata; 1354 fdata.write(buf.bytes(), buf.size());1250 fdata.write(buf.bytes(), buf.size()); 1355 1251 if (buf.size() <= 0) { 1356 1252 fprintf(stderr, "data buffer is empty\n"); 1357 1253 abort(); 1358 1254 } 1359 bool result;1360 1255 Rappture::Outcome context; 1361 1256 #if ISO_TEST 1362 result = load_volume_stream2(context, volPtr->dataID(), fdata);1257 volPtr = load_volume_stream2(context, tag, fdata); 1363 1258 #else 1364 result = load_volume_stream(context, volPtr->dataID(), fdata);1259 volPtr = load_volume_stream(context, tag, fdata); 1365 1260 #endif 1366 if ( !result) {1261 if (volPtr == NULL) { 1367 1262 Tcl_AppendResult(interp, context.remark(), (char*)NULL); 1368 1263 return TCL_ERROR; … … 1379 1274 //volPtr->n_slices(512-n); 1380 1275 //volPtr->n_slices(256-n); 1381 volPtr->n_slices(256);1382 1276 volPtr->disable_cutplane(0); 1383 1277 volPtr->disable_cutplane(1); … … 1394 1288 1395 1289 // FIXME: strlen(info) is the return value of sprintf 1396 sprintf(info, "nv>data tag %s id %d min %g max %g vmin %g vmax %g\n",1397 tag, volDataID,volPtr->wAxis.min(), volPtr->wAxis.max(),1290 sprintf(info, "nv>data tag %s min %g max %g vmin %g vmax %g\n", tag, 1291 volPtr->wAxis.min(), volPtr->wAxis.max(), 1398 1292 Volume::valueMin, Volume::valueMax); 1399 1293 nWritten = write(0, info, strlen(info)); … … 1440 1334 } 1441 1335 return (*proc) (clientData, interp, objc, objv); 1336 } 1337 1338 /* 1339 *--------------------------------------------------------------------------- 1340 * 1341 * VolumeDeleteOp -- 1342 * 1343 *--------------------------------------------------------------------------- 1344 */ 1345 /*ARGSUSED*/ 1346 static int 1347 VolumeDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc, 1348 Tcl_Obj *const *objv) 1349 { 1350 int i; 1351 1352 for (i = 2; i < objc; i++) { 1353 Volume *volPtr; 1354 1355 if (GetVolumeFromObj(interp, objv[i], &volPtr) != TCL_OK) { 1356 return TCL_ERROR; 1357 } 1358 NanoVis::remove_volume(volPtr); 1359 } 1360 NanoVis::EventuallyRedraw(); 1361 return TCL_OK; 1362 } 1363 1364 /* 1365 *--------------------------------------------------------------------------- 1366 * 1367 * VolumeExistsOp -- 1368 * 1369 *--------------------------------------------------------------------------- 1370 */ 1371 /*ARGSUSED*/ 1372 static int 1373 VolumeExistsOp(ClientData clientData, Tcl_Interp *interp, int objc, 1374 Tcl_Obj *const *objv) 1375 { 1376 bool value; 1377 Volume *volPtr; 1378 1379 value = false; 1380 if (GetVolumeFromObj(NULL, objv[2], &volPtr) == TCL_OK) { 1381 value = true; 1382 } 1383 Tcl_SetBooleanObj(Tcl_GetObjResult(interp), (int)value); 1384 return TCL_OK; 1385 } 1386 1387 /* 1388 *--------------------------------------------------------------------------- 1389 * 1390 * VolumeNamesOp -- 1391 * 1392 *--------------------------------------------------------------------------- 1393 */ 1394 /*ARGSUSED*/ 1395 static int 1396 VolumeNamesOp(ClientData clientData, Tcl_Interp *interp, int objc, 1397 Tcl_Obj *const *objv) 1398 { 1399 Tcl_Obj *listObjPtr; 1400 listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL); 1401 Tcl_HashEntry *hPtr; 1402 Tcl_HashSearch iter; 1403 for (hPtr = Tcl_FirstHashEntry(&NanoVis::volumeTable, &iter); hPtr != NULL; 1404 hPtr = Tcl_NextHashEntry(&iter)) { 1405 Volume *volPtr; 1406 volPtr = (Volume *)Tcl_GetHashValue(hPtr); 1407 Tcl_Obj *objPtr; 1408 objPtr = Tcl_NewStringObj(volPtr->name(), -1); 1409 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr); 1410 } 1411 Tcl_SetObjResult(interp, listObjPtr); 1412 return TCL_OK; 1442 1413 } 1443 1414 … … 1585 1556 Tcl_Obj *const *objv) 1586 1557 { 1587 TransferFunction *tf ;1558 TransferFunction *tfPtr; 1588 1559 const char *name = Tcl_GetString(objv[3]); 1589 tf = NanoVis::get_transfunc(name);1590 if (tf == NULL) {1560 tfPtr = NanoVis::get_transfunc(name); 1561 if (tfPtr == NULL) { 1591 1562 Tcl_AppendResult(interp, "transfer function \"", name, 1592 1563 "\" is not defined", (char*)NULL); … … 1599 1570 vector<Volume *>::iterator iter; 1600 1571 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1601 (*iter)->transferFunction(tf); 1572 Trace("setting %s with transfer function %s\n", (*iter)->name(), 1573 tfPtr->name()); 1574 (*iter)->transferFunction(tfPtr); 1602 1575 #ifdef POINTSET 1603 1576 // TBD.. … … 1687 1660 Tcl_Obj *const *objv) 1688 1661 { 1689 Volume *volPtr;1690 size_t i;1691 1692 volPtr = NULL;1693 1662 // Find the first volume in the vector. 1694 for (i = 0; i < NanoVis::volumes.size(); i++) { 1695 if (NanoVis::volumes[i] != NULL) { 1696 volPtr = NanoVis::volumes[i]; 1697 break; 1698 } 1699 } 1700 if (volPtr != NULL) { 1663 Tcl_HashEntry *hPtr; 1664 Tcl_HashSearch iter; 1665 hPtr = Tcl_FirstHashEntry(&NanoVis::volumeTable, &iter); 1666 if (hPtr != NULL) { 1667 Volume *volPtr; 1668 volPtr = (Volume *)Tcl_GetHashValue(hPtr); 1701 1669 volPtr->data_enabled(false); 1702 1670 volPtr->visible(false); … … 1708 1676 {"animation", 2, VolumeAnimationOp, 3, 0, "oper ?args?",}, 1709 1677 {"axis", 2, VolumeAxisOp, 4, 0, "label axis value ?indices?",}, 1710 {"data", 1, VolumeDataOp, 3, 0, "oper ?args?",}, 1678 {"data", 2, VolumeDataOp, 3, 0, "oper ?args?",}, 1679 {"delete", 2, VolumeDeleteOp, 3, 0, "?name...?",}, 1680 {"exists", 1, VolumeExistsOp, 3, 3, "name",}, 1681 {"names", 1, VolumeNamesOp, 2, 3, "?pattern?",}, 1711 1682 {"outline", 1, VolumeOutlineOp, 3, 0, "oper ?args?",}, 1712 1683 {"shading", 2, VolumeShadingOp, 3, 0, "oper ?args?",}, … … 1751 1722 // ============================= FLOW ================================== 1752 1723 1753 static int1754 FlowDataFollowsOp(ClientData clientData, Tcl_Interp *interp, int objc,1755 Tcl_Obj *const *objv)1756 {1757 Rappture::Outcome result;1758 1759 Trace("Flow Data Loading\n");1760 1761 int nbytes;1762 if (Tcl_GetIntFromObj(interp, objv[3], &nbytes) != TCL_OK) {1763 return TCL_ERROR;1764 }1765 int extents;1766 if (Tcl_GetIntFromObj(interp, objv[4], &extents) != TCL_OK) {1767 return TCL_ERROR;1768 }1769 1770 Rappture::Buffer buf;1771 if (GetDataStream(interp, buf, nbytes) != TCL_OK) {1772 return TCL_ERROR;1773 }1774 int n = NanoVis::n_volumes;1775 if (strncmp(buf.bytes(), "<DX>", 4) == 0) {1776 if (!load_vector_stream2(result, n, buf.size(), (char *)buf.bytes())) {1777 Tcl_AppendResult(interp, result.remark(), (char *)NULL);1778 return TCL_ERROR;1779 }1780 #ifdef notdef1781 } else if (strncmp(buf.bytes(), "<unirect3d>", 4) == 0) {1782 1783 Rappture::Unirect3d data;1784 Tcl_CmdInfo cmdInfo;1785 1786 /* Set the clientdata field of the unirect3d command to contain1787 * the local data structure. */1788 if (!Tcl_GetCommandInfo(interp, "unirect3d", &cmdInfo)) {1789 return TCL_ERROR;1790 }1791 data.extents(extents);1792 cmdInfo.objClientData = (ClientData)&data;1793 Tcl_SetCommandInfo(interp, "unirect3d", &cmdInfo);1794 if (Tcl_Eval(interp, (const char *)buf.bytes()) != TCL_OK) {1795 return TCL_ERROR;1796 }1797 if (!data.isInitialized()) {1798 return TCL_ERROR;1799 }1800 if (!MakeVectorFieldFromUnirect3d(result, data)) {1801 Tcl_AppendResult(interp, result.remark(), (char *)NULL);1802 return TCL_ERROR;1803 }1804 #endif1805 }1806 1807 Volume *volPtr = NanoVis::volume[NanoVis::n_volumes];1808 //1809 // BE CAREFUL: Set the number of slices to something1810 // slightly different for each volume. If we have1811 // identical volumes at exactly the same position1812 // with exactly the same number of slices, the second1813 // volume will overwrite the first, so the first won't1814 // appear at all.1815 //1816 volPtr->set_n_slice(256-n);1817 // volPtr->set_n_slice(512-n);1818 volPtr->disable_cutplane(0);1819 volPtr->disable_cutplane(1);1820 volPtr->disable_cutplane(2);1821 volPtr->transferFunction(NanoVis::get_transfunc("default"));1822 1823 float dx0 = -0.5;1824 float dy0 = -0.5*volPtr->height/volPtr->width;1825 float dz0 = -0.5*volPtr->depth/volPtr->width;1826 volPtr->move(Vector3(dx0, dy0, dz0));1827 return TCL_OK;1828 }1829 1830 static Rappture::CmdSpec flowDataOps[] = {1831 {"follows", 1, FlowDataFollowsOp, 4, 4, "size",},1832 };1833 static int nFlowDataOps = NumCmdSpecs(flowDataOps);1834 1835 static int1836 FlowDataOp(ClientData clientData, Tcl_Interp *interp, int objc,1837 Tcl_Obj *const *objv)1838 {1839 Tcl_ObjCmdProc *proc;1840 1841 proc = Rappture::GetOpFromObj(interp, nFlowDataOps, flowDataOps,1842 Rappture::CMDSPEC_ARG2, objc, objv, 0);1843 if (proc == NULL) {1844 return TCL_ERROR;1845 }1846 return (*proc) (clientData, interp, objc, objv);1847 }1848 1724 1849 1725 // INSOO … … 2290 2166 hmPtr->setHeight(grid.xMin(), grid.yMin(), grid.xMax(), grid.yMax(), 2291 2167 grid.xNum(), grid.yNum(), grid.acceptValues()); 2292 hmPtr-> setColorMap(NanoVis::get_transfunc("default"));2168 hmPtr->transferFunction(NanoVis::get_transfunc("default")); 2293 2169 hmPtr->setVisible(true); 2294 2170 hmPtr->setLineContourVisible(true); … … 2431 2307 return TCL_ERROR; 2432 2308 } 2433 TransferFunction *tf ;2434 tf = hmPtr->getColorMap();2435 if (tf == NULL) {2309 TransferFunction *tfPtr; 2310 tfPtr = hmPtr->transferFunction(); 2311 if (tfPtr == NULL) { 2436 2312 Tcl_AppendResult(interp, "no transfer function defined for heightmap \"", 2437 2313 Tcl_GetString(objv[2]), "\"", (char*)NULL); … … 2447 2323 } 2448 2324 2449 NanoVis::render_legend(tf , HeightMap::valueMin, HeightMap::valueMax, w, h,2450 2325 NanoVis::render_legend(tfPtr, HeightMap::valueMin, HeightMap::valueMax, 2326 w, h, "label"); 2451 2327 return TCL_OK; 2452 2328 } … … 2521 2397 float maxy = 3.5f; 2522 2398 hmPtr->setHeight(minx, miny, maxx, maxy, 20, 20, data); 2523 hmPtr-> setColorMap(NanoVis::get_transfunc("default"));2399 hmPtr->transferFunction(NanoVis::get_transfunc("default")); 2524 2400 hmPtr->setVisible(true); 2525 2401 hmPtr->setLineContourVisible(true); … … 2541 2417 const char *name; 2542 2418 name = Tcl_GetString(objv[2]); 2543 TransferFunction *tf ;2544 tf = NanoVis::get_transfunc(name);2545 if (tf == NULL) {2419 TransferFunction *tfPtr; 2420 tfPtr = NanoVis::get_transfunc(name); 2421 if (tfPtr == NULL) { 2546 2422 Tcl_AppendResult(interp, "transfer function \"", name, 2547 2423 "\" is not defined", (char*)NULL); … … 2554 2430 vector<HeightMap *>::iterator iter; 2555 2431 for (iter = imap.begin(); iter != imap.end(); iter++) { 2556 (*iter)-> setColorMap(tf);2432 (*iter)->transferFunction(tfPtr); 2557 2433 } 2558 2434 return TCL_OK; … … 2905 2781 Tcl_CreateObjCommand(interp, "test", TestCmd, NULL, NULL); 2906 2782 #endif 2907 2783 Tcl_InitHashTable(&NanoVis::volumeTable, TCL_STRING_KEYS); 2908 2784 // create a default transfer function 2909 2785 if (Tcl_Eval(interp, def_transfunc) != TCL_OK) { -
trunk/packages/vizservers/nanovis/FlowCmd.cpp
r1484 r1493 53 53 54 54 Rappture::SwitchSpec FlowCmd::_switches[] = { 55 {Rappture::SWITCH_BOOLEAN, "-arrows", "boolean", 56 offsetof(FlowValues, showArrows), 0}, 57 {Rappture::SWITCH_CUSTOM, "-axis", "axis", 58 offsetof(FlowValues, slicePos.axis), 0, 0, &axisSwitch}, 59 {Rappture::SWITCH_FLOAT, "-diffuse", "value", 60 offsetof(FlowValues, diffuse), 0}, 61 {Rappture::SWITCH_BOOLEAN, "-hide", "boolean", 62 offsetof(FlowValues, isHidden), 0}, 63 {Rappture::SWITCH_FLOAT, "-opacity", "value", 64 offsetof(FlowValues, opacity), 0}, 65 {Rappture::SWITCH_BOOLEAN, "-outline", "boolean", 66 offsetof(FlowValues, showOutline), 0}, 67 {Rappture::SWITCH_CUSTOM, "-position", "number", 68 offsetof(FlowValues, slicePos), 0, 0, &positionSwitch}, 55 69 {Rappture::SWITCH_BOOLEAN, "-slice", "boolean", 56 70 offsetof(FlowValues, sliceVisible), 0}, 57 {Rappture::SWITCH_CUSTOM, "-axis", "axis", 58 offsetof(FlowValues, slicePos.axis), 0, 0, &axisSwitch}, 59 {Rappture::SWITCH_BOOLEAN, "-hide", "boolean", 60 offsetof(FlowValues, isHidden), 0}, 61 {Rappture::SWITCH_CUSTOM, "-position", "number", 62 offsetof(FlowValues, slicePos), 0, 0, &positionSwitch}, 71 {Rappture::SWITCH_FLOAT, "-specular", "value", 72 offsetof(FlowValues, specular), 0}, 63 73 {Rappture::SWITCH_CUSTOM, "-transferfunction", "name", 64 74 offsetof(FlowValues, tfPtr), 0, 0, &transferFunctionSwitch}, 65 75 {Rappture::SWITCH_BOOLEAN, "-volume", "boolean", 66 76 offsetof(FlowValues, showVolume), 0}, 67 {Rappture::SWITCH_BOOLEAN, "-outline", "boolean",68 offsetof(FlowValues, showOutline), 0},69 {Rappture::SWITCH_FLOAT, "-diffuse", "value",70 offsetof(FlowValues, diffuse), 0},71 {Rappture::SWITCH_FLOAT, "-opacity", "value",72 offsetof(FlowValues, opacity), 0},73 {Rappture::SWITCH_FLOAT, "-specular", "value",74 offsetof(FlowValues, specular), 0},75 77 {Rappture::SWITCH_END} 76 78 }; … … 295 297 } 296 298 if (_volPtr != NULL) { 297 assert((size_t)_volId == _volPtr->dataID()); 298 fprintf(stderr, "from ~FlowCmd volId=%d\n", _volId); 299 NanoVis::remove_volume(_volId); 299 NanoVis::remove_volume(_volPtr); 300 300 _volPtr = NULL; 301 301 } … … 510 510 { 511 511 if (_volPtr != NULL) { 512 assert((size_t)_volId == _volPtr->dataID()); 513 fprintf(stderr, "from ScaleVectorField volId=%d\n", _volId); 514 NanoVis::remove_volume(_volId); 512 fprintf(stderr, "from ScaleVectorField volId=%s\n", _volPtr->name()); 513 NanoVis::remove_volume(_volPtr); 515 514 _volPtr = NULL; 516 515 } … … 563 562 564 563 if (NanoVis::velocityArrowsSlice != NULL) { 565 NanoVis::velocityArrowsSlice->vectorField( volPtr->id,564 NanoVis::velocityArrowsSlice->vectorField(_volPtr->id, 566 565 //*(volPtr->get_location()), 567 566 1.0f, 568 volPtr->aspect_ratio_height /volPtr->aspect_ratio_width,569 volPtr->aspect_ratio_depth /volPtr->aspect_ratio_width567 _volPtr->aspect_ratio_height / _volPtr->aspect_ratio_width, 568 _volPtr->aspect_ratio_depth / _volPtr->aspect_ratio_width 570 569 //,volPtr->wAxis.max() 571 570 ); 571 Trace("Arrows enabled set to %d\n", _sv.showArrows); 572 NanoVis::velocityArrowsSlice->axis(_sv.slicePos.axis); 573 NanoVis::velocityArrowsSlice->slicePos(_sv.slicePos.value); 574 NanoVis::velocityArrowsSlice->enabled(_sv.showArrows); 572 575 } 573 576 FlowParticles *particlesPtr; … … 628 631 { 629 632 Volume *volPtr; 630 /* Reuse the volume index. The first time it's -1, which means to generate 631 * a new volume slot. */ 632 volPtr = NanoVis::load_volume(_volId, _dataPtr->xNum(), _dataPtr->yNum(), 633 volPtr = NanoVis::load_volume(_name, _dataPtr->xNum(), _dataPtr->yNum(), 633 634 _dataPtr->zNum(), 4, data, NanoVis::magMin, NanoVis::magMax, 0); 634 /* Save the volume index. This only matters the first time through. */635 _volId = volPtr->dataID();636 635 volPtr->xAxis.SetRange(_dataPtr->xMin(), _dataPtr->xMax()); 637 636 volPtr->yAxis.SetRange(_dataPtr->yMin(), _dataPtr->yMax()); … … 646 645 // volPtr->set_n_slice(512- _volIndex); 647 646 // TBD.. 648 volPtr->n_slices(256);647 //volPtr->n_slices(256-n); 649 648 volPtr->disable_cutplane(0); 650 649 volPtr->disable_cutplane(1); -
trunk/packages/vizservers/nanovis/FlowCmd.h
r1478 r1493 136 136 TransferFunction *tfPtr; 137 137 FlowPosition slicePos; 138 int showArrows; 138 139 int sliceVisible; 139 140 int showVolume; -
trunk/packages/vizservers/nanovis/HeightMap.cpp
r1188 r1493 30 30 _contour(0), 31 31 _topContour(0), 32 _ colorMap(0),32 _tfPtr(0), 33 33 _indexBuffer(0), 34 34 _indexCount(0), … … 43 43 _shader = new NvShader(); 44 44 _shader->loadFragmentProgram("heightcolor.cg", "main"); 45 _tf = _shader->getNamedParameterFromFP("tf");45 _tfParam = _shader->getNamedParameterFromFP("tf"); 46 46 } 47 47 … … 55 55 56 56 // TMP 57 //if (_ colorMap) delete _colorMap;57 //if (_tfPtr) delete _tfPtr; 58 58 } 59 59 … … 93 93 glDisableClientState(GL_NORMAL_ARRAY); 94 94 95 if (_ colorMap) {95 if (_tfPtr) { 96 96 // PUT vertex program here 97 97 // … … 101 101 cgGLEnableProfile(CG_PROFILE_FP30); 102 102 103 cgGLSetTextureParameter(_tf , _colorMap->id);104 cgGLEnableTextureParameter(_tf );103 cgGLSetTextureParameter(_tfParam, _tfPtr->id()); 104 cgGLEnableTextureParameter(_tfParam); 105 105 106 106 glEnable(GL_TEXTURE_1D); 107 _ colorMap->getTexture()->activate();107 _tfPtr->getTexture()->activate(); 108 108 109 109 glEnableClientState(GL_TEXTURE_COORD_ARRAY); … … 128 128 129 129 glDisableClientState(GL_VERTEX_ARRAY); 130 if (_ colorMap) {131 _ colorMap->getTexture()->deactivate();130 if (_tfPtr != NULL) { 131 _tfPtr->getTexture()->deactivate(); 132 132 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 133 133 … … 388 388 389 389 ContourLineFilter lineFilter; 390 //lineFilter. setColorMap(_colorMap);390 //lineFilter.transferFunction(_tfPtr); 391 391 _contour = lineFilter.create(0.0f, 1.0f, 10, heightMap, xNum, yNum); 392 392 … … 439 439 } 440 440 return vertices; 441 }442 443 void HeightMap::setColorMap(TransferFunction* colorMap)444 {445 //if (colorMap) colorMap->addRef();446 //if (_colorMap) _colorMap->unrefDelete();447 _colorMap = colorMap;448 441 } 449 442 … … 501 494 502 495 ContourLineFilter lineFilter; 503 //lineFilter. setColorMap(_colorMap);496 //lineFilter.transferFunction(_tfPtr); 504 497 _contour = lineFilter.create(0.0f, 1.0f, 10, vertices, xNum_, yNum_); 505 498 … … 568 561 glDisableClientState(GL_NORMAL_ARRAY); 569 562 570 if (_ colorMap) {563 if (_tfPtr != NULL) { 571 564 cgGLBindProgram(_shader->getFP()); 572 565 cgGLEnableProfile(CG_PROFILE_FP30); 573 566 574 cgGLSetTextureParameter(_tf , _colorMap->id);575 cgGLEnableTextureParameter(_tf );567 cgGLSetTextureParameter(_tfParam, _tfPtr->id()); 568 cgGLEnableTextureParameter(_tfParam); 576 569 577 570 glEnable(GL_TEXTURE_1D); 578 _ colorMap->getTexture()->activate();571 _tfPtr->getTexture()->activate(); 579 572 580 573 glEnableClientState(GL_TEXTURE_COORD_ARRAY); … … 602 595 603 596 glDisableClientState(GL_VERTEX_ARRAY); 604 if (_ colorMap) {605 _ colorMap->getTexture()->deactivate();597 if (_tfPtr != NULL) { 598 _tfPtr->getTexture()->deactivate(); 606 599 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 607 600 -
trunk/packages/vizservers/nanovis/HeightMap.h
r1188 r1493 26 26 unsigned int _textureBufferObjectID; 27 27 int _vertexCount; 28 CGparameter _tf ;28 CGparameter _tfParam; 29 29 R2Geometry* _contour; 30 30 R2Geometry* _topContour; 31 TransferFunction* _ colorMap;31 TransferFunction* _tfPtr; 32 32 NvShader* _shader; 33 33 int *_indexBuffer; … … 90 90 *@brief Define a color map for color shading of heightmap 91 91 */ 92 void setColorMap(TransferFunction* colorMap); 93 92 void transferFunction(TransferFunction* tfPtr) { 93 _tfPtr = tfPtr; 94 } 94 95 /** 95 96 *@brief Get the color map defined for shading of this heightmap 96 97 */ 97 TransferFunction * getColorMap(void) {98 return _ colorMap;98 TransferFunction *transferFunction(void) { 99 return _tfPtr; 99 100 } 100 101 /** -
trunk/packages/vizservers/nanovis/NvColorTableShader.h
r580 r1493 25 25 { 26 26 cgGLSetTextureParameter(_dataParam, plane->id); 27 cgGLSetTextureParameter(_tfParam, tf->id );27 cgGLSetTextureParameter(_tfParam, tf->id()); 28 28 cgGLEnableTextureParameter(_dataParam); 29 29 cgGLEnableTextureParameter(_tfParam); -
trunk/packages/vizservers/nanovis/PlaneRenderer.cpp
r1478 r1493 50 50 51 51 int 52 PlaneRenderer::add_plane(Texture2D* _p, TransferFunction* _tf)52 PlaneRenderer::add_plane(Texture2D* _p, TransferFunction* tfPtr) 53 53 { 54 54 int ret = n_planes; 55 55 56 56 plane.push_back(_p); 57 tf.push_back( _tf);57 tf.push_back(tfPtr); 58 58 59 59 if(ret==0) … … 95 95 96 96 //if no active plane 97 if (active_plane == -1)97 if (active_plane == -1) 98 98 return; 99 99 … … 112 112 PlaneRenderer::activate_shader(int index) 113 113 { 114 115 114 cgGLSetTextureParameter(m_data_param, plane[index]->id); 116 cgGLSetTextureParameter(m_tf_param, tf[index]->id );115 cgGLSetTextureParameter(m_tf_param, tf[index]->id()); 117 116 cgGLEnableTextureParameter(m_data_param); 118 117 cgGLEnableTextureParameter(m_tf_param); -
trunk/packages/vizservers/nanovis/TransferFunction.cpp
r1475 r1493 28 28 _data = new float[_size]; 29 29 memcpy(_data, data, sizeof(float) * _size); 30 31 30 _tex->initialize_float_rgba(_data); 32 id = _tex->id;31 _id = _tex->id; 33 32 } 34 33 -
trunk/packages/vizservers/nanovis/TransferFunction.h
r1475 r1493 28 28 float* _data; 29 29 Texture1D* _tex; //the texture storing the colors 30 30 const char *_name; 31 GLuint _id; //OpenGL's texture identifier 31 32 protected : 32 33 ~TransferFunction(); 33 34 public: 34 GLuint id; //OpenGL's texture identifier35 36 35 TransferFunction(int size, float *data); 37 36 void update(float *data); 38 37 void update(int size, float *data); 38 GLuint id(void) { 39 return _id; 40 } 41 void id(GLuint id) { 42 _id = id; 43 } 39 44 Texture1D* getTexture(void) { 40 45 return _tex; … … 43 48 return _data; 44 49 } 45 int getSize() const; 50 int getSize() const { 51 return _size; 52 } 53 const char *name(void) const { 54 return _name; 55 } 56 void name(const char *name) { 57 _name = name; 58 } 46 59 }; 47 60 48 inline int TransferFunction::getSize() const49 {50 return _size;51 }52 61 #endif -
trunk/packages/vizservers/nanovis/VelocityArrowsSlice.cpp
r1490 r1493 265 265 void VelocityArrowsSlice::render() 266 266 { 267 //if (!_enabled || (_vectorFieldGraphicsID == 0)) return; 268 if (!_enabled) return; 269 270 if (_dirty) 271 { 272 computeSamplingTicks(); 273 queryVelocity(); 274 _dirty = false; 275 } 276 277 278 glPushMatrix(); 279 280 glScalef(_vfXscale,_vfYscale, _vfZscale); 281 glTranslatef(-0.5f, -0.5f, -0.5f); 282 if (_renderMode == LINES) 283 { 284 285 glDisable(GL_TEXTURE_2D); 286 glLineWidth(2.0); 287 glColor3f(_arrowColor.x, _arrowColor.y, _arrowColor.z); 288 glBegin(GL_LINES); 289 Vector3 pos; 290 Vector3 pos2; 291 Vector3 vel(1, 0, 0); 292 Vector3 v, v2; 293 if (_axis == 2) 294 { 295 int index = 0; 296 for (int y = 1; y <= _tickCountY; ++y) 297 for (int x = 1; x <= _tickCountX; ++x, ++index) 298 { 299 pos = this->_samplingPositions[index]; 300 pos2 = this->_velocities[index].scale(_projectionVector).scale(_maxVelocityScale) + pos; 301 glVertex3f(pos.x, pos.y, pos.z); 302 glVertex3f(pos2.x, pos2.y, pos2.z); 303 /*v = pos - pos2; 304 305 306 v2.x = 1; 307 v2.y = 1; 308 v2.z = (-(x1-x2)-(y1-y2))/(z1-z2) 309 adj = v.length() / (4 * sqrt((x3^2)+(y3^2)+(z3^2))); 310 x3 *= adj 311 y3 *= adj 312 z3 *= adj 313 */ 314 315 } 316 } 317 else if (_axis == 1) 318 { 319 int index = 0; 320 for (int z = 1; z <= _tickCountZ; ++z) 321 for (int x = 1; x <= _tickCountX; ++x, ++index) 322 { 323 pos = _samplingPositions[index]; 324 pos2 = this->_velocities[index].scale(_projectionVector).scale(_maxVelocityScale) + pos; 325 326 glVertex3f(pos.x, pos.y, pos.z); 327 glVertex3f(pos2.x, pos2.y, pos2.z); 328 } 329 } 330 else if (_axis == 0) 331 { 332 int index = 0; 333 for (int z = 1; z <= _tickCountZ; ++z) 334 for (int y = 1; y <= _tickCountY; ++y, ++index) 335 { 336 pos = _samplingPositions[index]; 337 pos2 = this->_velocities[index].scale(_projectionVector).scale(_maxVelocityScale) + pos; 338 339 glVertex3f(pos.x, pos.y, pos.z); 340 glVertex3f(pos2.x, pos2.y, pos2.z); 341 } 342 } 343 344 glEnd(); 345 glLineWidth(1.0); 346 } 347 else 348 { 349 glColor3f(_arrowColor.x, _arrowColor.y, _arrowColor.z); 350 glEnable(GL_BLEND); 351 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 352 glEnable(GL_POINT_SPRITE_NV); 353 glPointSize(20); 354 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV); 355 356 #ifdef USE_NANOVIS_LIB 357 _arrowsTex->activate(); 358 #else 359 _arrowsTex->bind(0); 360 glEnable(GL_TEXTURE_2D); 361 #endif 362 glPointParameterfARB( GL_POINT_FADE_THRESHOLD_SIZE_ARB, 0.0f ); 363 364 glPointParameterfARB( GL_POINT_SIZE_MIN_ARB, 1.0f); 365 glPointParameterfARB( GL_POINT_SIZE_MAX_ARB, 100.0f); 366 glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE ); 367 368 cgGLBindProgram(_particleVP); 369 cgGLBindProgram(_particleFP); 370 cgGLEnableProfile(CG_PROFILE_VP40); 371 cgGLEnableProfile(CG_PROFILE_FP40); 372 373 cgGLSetTextureParameter(_vectorParticleParam, _vectorFieldGraphicsID); 374 cgGLEnableTextureParameter(_vectorParticleParam); 375 376 377 //cgSetParameter1f(_mvTanHalfFOVParam, -tan(_fov * 0.5) * _screenHeight * 0.5); 378 379 cgGLSetStateMatrixParameter(_mvpParticleParam, 380 CG_GL_MODELVIEW_PROJECTION_MATRIX, 381 CG_GL_MATRIX_IDENTITY); 382 cgGLSetStateMatrixParameter(_mvParticleParam, 383 CG_GL_MODELVIEW_MATRIX, 384 CG_GL_MATRIX_IDENTITY); 385 386 glEnableClientState(GL_VERTEX_ARRAY); 387 glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vertexBufferGraphicsID); 388 glVertexPointer(3, GL_FLOAT, 0, 0); 389 //glEnableClientState(GL_COLOR_ARRAY); 390 391 // TBD.. 392 glDrawArrays(GL_POINTS, 0, _pointCount); 393 glPointSize(1); 394 glDrawArrays(GL_POINTS, 0, _pointCount); 395 396 glDisableClientState(GL_VERTEX_ARRAY); 397 398 cgGLDisableProfile(CG_PROFILE_VP40); 399 cgGLDisableProfile(CG_PROFILE_FP40); 400 401 glDepthMask(GL_TRUE); 402 403 glDisable(GL_POINT_SPRITE_NV); 404 glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_NV); 405 406 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 407 glDisable(GL_BLEND); 408 #ifdef USE_NANOVIS_LIB 409 _arrowsTex->deactivate(); 410 #else 411 _arrowsTex->unbind(); 412 #endif 413 } 414 glPopMatrix(); 415 } 416 417 void VelocityArrowsSlice::enabled(bool e) 418 { 419 _enabled = e; 420 } 421 422 void VelocityArrowsSlice::vectorField(unsigned int vfGraphicsID, 423 float xScale, float yScale, float zScale) 267 //if (!_enabled || (_vectorFieldGraphicsID == 0)) return; 268 if (!_enabled) return; 269 270 if (_dirty) { 271 computeSamplingTicks(); 272 queryVelocity(); 273 _dirty = false; 274 } 275 276 277 glPushMatrix(); 278 279 glScalef(_vfXscale,_vfYscale, _vfZscale); 280 glTranslatef(-0.5f, -0.5f, -0.5f); 281 if (_renderMode == LINES) { 282 283 glDisable(GL_TEXTURE_2D); 284 glLineWidth(2.0); 285 glColor3f(_arrowColor.x, _arrowColor.y, _arrowColor.z); 286 glBegin(GL_LINES); 287 Vector3 pos; 288 Vector3 pos2; 289 Vector3 vel(1, 0, 0); 290 Vector3 v, v2; 291 if (_axis == 2) { 292 int index = 0; 293 for (int y = 1; y <= _tickCountY; ++y) { 294 for (int x = 1; x <= _tickCountX; ++x, ++index) { 295 pos = this->_samplingPositions[index]; 296 pos2 = this->_velocities[index].scale(_projectionVector).scale(_maxVelocityScale) + pos; 297 glVertex3f(pos.x, pos.y, pos.z); 298 glVertex3f(pos2.x, pos2.y, pos2.z); 299 /*v = pos - pos2; 300 301 302 v2.x = 1; 303 v2.y = 1; 304 v2.z = (-(x1-x2)-(y1-y2))/(z1-z2) 305 adj = v.length() / (4 * sqrt((x3^2)+(y3^2)+(z3^2))); 306 x3 *= adj 307 y3 *= adj 308 z3 *= adj 309 */ 310 311 } 312 } 313 } else if (_axis == 1) { 314 int index = 0; 315 for (int z = 1; z <= _tickCountZ; ++z) 316 for (int x = 1; x <= _tickCountX; ++x, ++index) { 317 pos = _samplingPositions[index]; 318 pos2 = this->_velocities[index].scale(_projectionVector).scale(_maxVelocityScale) + pos; 319 320 glVertex3f(pos.x, pos.y, pos.z); 321 glVertex3f(pos2.x, pos2.y, pos2.z); 322 } 323 } else if (_axis == 0) { 324 int index = 0; 325 for (int z = 1; z <= _tickCountZ; ++z) 326 for (int y = 1; y <= _tickCountY; ++y, ++index) { 327 pos = _samplingPositions[index]; 328 pos2 = this->_velocities[index].scale(_projectionVector).scale(_maxVelocityScale) + pos; 329 330 glVertex3f(pos.x, pos.y, pos.z); 331 glVertex3f(pos2.x, pos2.y, pos2.z); 332 } 333 } 334 335 glEnd(); 336 glLineWidth(1.0); 337 } else { 338 glColor3f(_arrowColor.x, _arrowColor.y, _arrowColor.z); 339 glEnable(GL_BLEND); 340 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 341 glEnable(GL_POINT_SPRITE_NV); 342 glPointSize(20); 343 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV); 344 345 #ifdef USE_NANOVIS_LIB 346 _arrowsTex->activate(); 347 #else 348 _arrowsTex->bind(0); 349 glEnable(GL_TEXTURE_2D); 350 #endif 351 glPointParameterfARB( GL_POINT_FADE_THRESHOLD_SIZE_ARB, 0.0f ); 352 353 glPointParameterfARB( GL_POINT_SIZE_MIN_ARB, 1.0f); 354 glPointParameterfARB( GL_POINT_SIZE_MAX_ARB, 100.0f); 355 glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE ); 356 357 cgGLBindProgram(_particleVP); 358 cgGLBindProgram(_particleFP); 359 cgGLEnableProfile(CG_PROFILE_VP40); 360 cgGLEnableProfile(CG_PROFILE_FP40); 361 362 cgGLSetTextureParameter(_vectorParticleParam, _vectorFieldGraphicsID); 363 cgGLEnableTextureParameter(_vectorParticleParam); 364 365 366 //cgSetParameter1f(_mvTanHalfFOVParam, -tan(_fov * 0.5) * _screenHeight * 0.5); 367 368 cgGLSetStateMatrixParameter(_mvpParticleParam, 369 CG_GL_MODELVIEW_PROJECTION_MATRIX, 370 CG_GL_MATRIX_IDENTITY); 371 cgGLSetStateMatrixParameter(_mvParticleParam, 372 CG_GL_MODELVIEW_MATRIX, 373 CG_GL_MATRIX_IDENTITY); 374 375 glEnableClientState(GL_VERTEX_ARRAY); 376 glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vertexBufferGraphicsID); 377 glVertexPointer(3, GL_FLOAT, 0, 0); 378 //glEnableClientState(GL_COLOR_ARRAY); 379 380 // TBD.. 381 glDrawArrays(GL_POINTS, 0, _pointCount); 382 glPointSize(1); 383 glDrawArrays(GL_POINTS, 0, _pointCount); 384 385 glDisableClientState(GL_VERTEX_ARRAY); 386 387 cgGLDisableProfile(CG_PROFILE_VP40); 388 cgGLDisableProfile(CG_PROFILE_FP40); 389 390 glDepthMask(GL_TRUE); 391 392 glDisable(GL_POINT_SPRITE_NV); 393 glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_NV); 394 395 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 396 glDisable(GL_BLEND); 397 #ifdef USE_NANOVIS_LIB 398 _arrowsTex->deactivate(); 399 #else 400 _arrowsTex->unbind(); 401 #endif 402 } 403 glPopMatrix(); 404 } 405 406 407 void 408 VelocityArrowsSlice::vectorField(unsigned int vfGraphicsID, 409 float xScale, float yScale, float zScale) 424 410 { 425 411 _vectorFieldGraphicsID = vfGraphicsID; -
trunk/packages/vizservers/nanovis/VelocityArrowsSlice.h
r1489 r1493 132 132 void queryVelocity(); 133 133 void render(); 134 void enabled(bool e); 135 bool enabled() const; 136 void tickCountForMinSizeAxis(int tickCount); 134 void enabled(bool enabled) { 135 _enabled = enabled; 136 } 137 bool enabled(void) const { 138 return _enabled; 139 } 140 void tickCountForMinSizeAxis(int tickCount); 137 141 int tickCountForMinSizeAxis() const; 138 142 void arrowColor(const Vector3& color); 139 140 143 void renderMode(RenderMode mode); 144 RenderMode renderMode() const; 141 145 }; 142 146 … … 151 155 } 152 156 153 154 inline bool VelocityArrowsSlice::enabled() const155 {156 return _enabled;157 }158 157 159 158 inline int VelocityArrowsSlice::tickCountForMinSizeAxis() const -
trunk/packages/vizservers/nanovis/Volume.cpp
r1478 r1493 31 31 _diffuse(3.), // default value 32 32 _opacity_scale(10.), // default value 33 _name(NULL), 33 34 _n_components(n), 34 35 _nonzero_min(nz_min), … … 47 48 size(s) 48 49 { 49 _volumeDataID = -1;50 51 50 _tex = new Texture3D(w, h, d, NVIS_FLOAT, NVIS_LINEAR_INTERP, n); 52 51 int fcount = width * height * depth * _n_components; -
trunk/packages/vizservers/nanovis/Volume.h
r1478 r1493 1 1 2 /* 2 3 * ---------------------------------------------------------------------- … … 54 55 // the object is to appear like 55 56 // plastic 56 int _volumeDataID;57 const char *_name; 57 58 Vector3 _physical_min; 58 59 Vector3 _physical_max; … … 222 223 Vector3& getPhysicalBBoxMax(); 223 224 224 void dataID(size_t index) {225 _volumeDataID = index;226 } 227 size_t dataID(void) const{228 return _volumeDataID;225 const char *name(void) { 226 return _name; 227 } 228 void name(const char *name) { 229 _name = name; 229 230 } 230 231 }; -
trunk/packages/vizservers/nanovis/VolumeInterpolator.cpp
r1478 r1493 144 144 refPtr->wAxis.max(), 145 145 refPtr->nonzero_min()); 146 /* 146 147 _referenceOfVolume = refPtr->dataID(); 148 */ 147 149 _volume->n_slices(256-1); 148 150 _volume->disable_cutplane(0); … … 155 157 _volume->opacity_scale(refPtr->opacity_scale()); 156 158 _volume->isosurface(0); 157 Trace("VOL : location %f %f %f\n\tid : % d\n", loc.x, loc.y, loc.z,158 refPtr-> dataID());159 Trace("VOL : location %f %f %f\n\tid : %s\n", loc.x, loc.y, loc.z, 160 refPtr->name()); 159 161 } 160 162 _volumes.push_back(_volume); 161 Trace("a Volume[% d] is added to VolumeInterpolator\n", refPtr->dataID());163 Trace("a Volume[%s] is added to VolumeInterpolator\n", refPtr->name()); 162 164 } 163 165 -
trunk/packages/vizservers/nanovis/VolumeRenderer.cpp
r1478 r1493 88 88 } 89 89 90 void VolumeRenderer::render_all_points()91 {92 #ifdef notdef93 double x0 = 0;94 double y0 = 0;95 double z0 = 0;96 97 for(int i=0; i<n_volumes; i++){98 int volume_index = i;99 if(!volume[i]->visible())100 continue; //skip this volume101 102 Vector3* location = volume[volume_index]->get_location();103 Vector4 shift_4d(location->x, location->y, location->z, 0);104 105 glPushMatrix();106 glTranslatef(shift_4d.x, shift_4d.y, shift_4d.z);107 108 if (volume[volume_index]->outline()) {109 float olcolor[3];110 volume[volume_index]->get_outline_color(olcolor);111 draw_bounding_box(x0, y0, z0, x0+1, y0+1, z0+1,112 (double)olcolor[0], (double)olcolor[1], (double)olcolor[2], 1.5);113 }114 115 glPopMatrix();116 }117 #endif118 }119 90 120 91 void … … 132 103 // Determine the volumes that are to be rendered. 133 104 vector<Volume *> volumes; 134 for (size_t i = 0; i < NanoVis::volumes.size(); i++) { 105 Tcl_HashEntry *hPtr; 106 Tcl_HashSearch iter; 107 for (hPtr = Tcl_FirstHashEntry(&NanoVis::volumeTable, &iter); hPtr != NULL; 108 hPtr = Tcl_NextHashEntry(&iter)) { 135 109 Volume* volPtr; 136 137 volPtr = NanoVis::volumes[i]; 138 Trace("volume %d: %x id=%d\n", i, volPtr, 139 (volPtr != NULL) ? volPtr->dataID() : -1); 140 if (volPtr == NULL) { 141 continue; // Empty slot in volume vector. 142 } 110 volPtr = (Volume *)Tcl_GetHashValue(hPtr); 111 Trace("volume %s addr=%x\n", volPtr->name(), volPtr); 143 112 if(!volPtr->visible()) { 144 Trace("volume [%d] %d skipped, size=%d id=%d\n", volPtr->dataID(),145 volPtr->visible(), volumes.size(), volPtr->dataID());146 113 continue; // Skip this volume 147 114 } 115 // BE CAREFUL: Set the number of slices to something slightly 116 // different for each volume. If we have identical volumes at exactly 117 // the same position with exactly the same number of slices, the 118 // second volume will overwrite the first, so the first won't appear 119 // at all. 148 120 volumes.push_back(volPtr); 121 volPtr->n_slices(256 - volumes.size()); 149 122 } 150 123 … … 162 135 volPtr = volumes[i]; 163 136 164 Trace("render: volume [%d] rendering visible=%d\n", volPtr->dataID(),165 volPtr->visible());166 137 int n_slices = volPtr->n_slices(); 167 138 if (volPtr->isosurface()) { … … 249 220 size_t n_actual_slices; 250 221 251 if (volPtr->data ()) {222 if (volPtr->data_enabled()) { 252 223 n_actual_slices = (int)(fabs(zNear-zFar)/z_step + 1); 253 224 polys[i] = new ConvexPolygon*[n_actual_slices]; … … 380 351 381 352 } //iterate all volumes 382 //fprintf(stderr, "total slices: %d\n", total_rendered_slices);353 fprintf(stderr, "total slices: %d\n", total_rendered_slices); 383 354 Trace("end loop\n"); 384 355 385 //We sort all the polygons according to their eye-space depth, from farthest to the closest. 386 //This step is critical for correct blending 387 388 SortElement* slices = (SortElement*)malloc(sizeof(SortElement)*total_rendered_slices); 356 // We sort all the polygons according to their eye-space depth, from 357 // farthest to the closest. This step is critical for correct blending 358 359 SortElement* slices = (SortElement*) 360 malloc(sizeof(SortElement) * total_rendered_slices); 389 361 390 362 size_t counter = 0; … … 405 377 glEnable(GL_BLEND); 406 378 407 for(size_t i = 0; i < total_rendered_slices; i++){379 for(size_t i = 0; i < total_rendered_slices; i++){ 408 380 Volume* volPtr; 409 381 … … 417 389 volPtr->aspect_ratio_depth); 418 390 391 #ifdef notdef 392 Trace("shading slice: volume %s addr=%x slice=%d, volume=%d\n", 393 volPtr->name(), volPtr, slice_index, volume_index); 394 #endif 419 395 activate_volume_shader(volPtr, false); 420 396 glPopMatrix(); … … 426 402 deactivate_volume_shader(); 427 403 } 428 429 404 430 405 glDisable(GL_DEPTH_TEST); … … 445 420 } 446 421 447 void448 VolumeRenderer::render(int volDataID)449 {450 assert(volDataID >= 0 && (size_t)volDataID < NanoVis::volumes.size());451 Volume* vol;452 vol = NanoVis::volumes[volDataID];453 if ((vol == NULL) || (!vol->visible())) {454 Trace("volume [%d] skipped\n", volDataID);455 return; // Empty slot or volume is not to be456 // rendered.457 }458 Trace("volume [%d] rendering visible=%d\n", vol->dataID(),459 vol->visible());460 int n_slices = vol->n_slices();461 462 //volume start location463 Vector3 loc = vol->location();464 Vector4 shift_4d(loc.x, loc.y, loc.z, 0);465 466 double x0 = 0;467 double y0 = 0;468 double z0 = 0;469 470 Mat4x4 model_view_no_trans, model_view_trans;471 Mat4x4 model_view_no_trans_inverse, model_view_trans_inverse;472 473 double zNear, zFar;474 475 //initialize volume plane with world coordinates476 Plane volume_planes[6];477 volume_planes[0].set_coeffs(1, 0, 0, -x0);478 volume_planes[1].set_coeffs(-1, 0, 0, x0+1);479 volume_planes[2].set_coeffs(0, 1, 0, -y0);480 volume_planes[3].set_coeffs(0, -1, 0, y0+1);481 volume_planes[4].set_coeffs(0, 0, 1, -z0);482 volume_planes[5].set_coeffs(0, 0, -1, z0+1);483 484 glPushMatrix();485 486 glScalef(vol->aspect_ratio_width,487 vol->aspect_ratio_height,488 vol->aspect_ratio_depth);489 490 glEnable(GL_DEPTH_TEST);491 492 GLfloat mv_no_trans[16];493 glGetFloatv(GL_MODELVIEW_MATRIX, mv_no_trans);494 495 model_view_no_trans = Mat4x4(mv_no_trans);496 model_view_no_trans_inverse = model_view_no_trans.inverse();497 498 glPopMatrix();499 500 //get modelview matrix with translation501 glPushMatrix();502 glTranslatef(shift_4d.x, shift_4d.y, shift_4d.z);503 glScalef(vol->aspect_ratio_width,504 vol->aspect_ratio_height,505 vol->aspect_ratio_depth);506 GLfloat mv_trans[16];507 glGetFloatv(GL_MODELVIEW_MATRIX, mv_trans);508 509 model_view_trans = Mat4x4(mv_trans);510 model_view_trans_inverse = model_view_trans.inverse();511 512 //draw volume bounding box513 if (vol->outline()) {514 draw_bounding_box(x0, y0, z0, x0+1, y0+1, z0+1, 0.8, 0.1, 0.1, 1.5);515 }516 glPopMatrix();517 518 //transform volume_planes to eye coordinates.519 for(int i=0; i<6; i++)520 volume_planes[i].transform(model_view_no_trans);521 522 get_near_far_z(mv_no_trans, zNear, zFar);523 //fprintf(stderr, "zNear:%f, zFar:%f\n", zNear, zFar);524 //fflush(stderr);525 526 //compute actual rendering slices527 float z_step = fabs(zNear-zFar)/n_slices;528 int n_actual_slices = (int)(fabs(zNear-zFar)/z_step + 1);529 //fprintf(stderr, "slices: %d\n", n_actual_slices);530 //fflush(stderr);531 532 static ConvexPolygon staticPoly;533 float slice_z;534 535 Vector4 vert1 = (Vector4(-10, -10, -0.5, 1));536 Vector4 vert2 = (Vector4(-10, +10, -0.5, 1));537 Vector4 vert3 = (Vector4(+10, +10, -0.5, 1));538 Vector4 vert4 = (Vector4(+10, -10, -0.5, 1));539 540 glEnable(GL_BLEND);541 542 if(slice_mode){543 glEnable(GL_DEPTH_TEST);544 545 //render the cut planes546 for(int i=0; i<vol->get_cutplane_count(); i++){547 float offset = vol->get_cutplane(i)->offset;548 int axis = vol->get_cutplane(i)->orient;549 550 if (axis==1) {551 vert1 = Vector4(-10, -10, offset, 1);552 vert2 = Vector4(-10, +10, offset, 1);553 vert3 = Vector4(+10, +10, offset, 1);554 vert4 = Vector4(+10, -10, offset, 1);555 } else if(axis==2){556 vert1 = Vector4(offset, -10, -10, 1);557 vert2 = Vector4(offset, +10, -10, 1);558 vert3 = Vector4(offset, +10, +10, 1);559 vert4 = Vector4(offset, -10, +10, 1);560 } else if(axis==3) {561 vert1 = Vector4(-10, offset, -10, 1);562 vert2 = Vector4(+10, offset, -10, 1);563 vert3 = Vector4(+10, offset, +10, 1);564 vert4 = Vector4(-10, offset, +10, 1);565 }566 567 vert1 = model_view_no_trans.transform(vert1);568 vert2 = model_view_no_trans.transform(vert2);569 vert3 = model_view_no_trans.transform(vert3);570 vert4 = model_view_no_trans.transform(vert4);571 572 ConvexPolygon *poly;573 poly = &staticPoly;574 poly->vertices.clear();575 576 poly->append_vertex(vert1);577 poly->append_vertex(vert2);578 poly->append_vertex(vert3);579 poly->append_vertex(vert4);580 581 for(int k=0; k<6; k++){582 poly->clip(volume_planes[k], true);583 }584 585 //poly->transform(model_view_inverse);586 //poly->translate(shift_4d);587 //poly->transform(model_view);588 poly->transform(model_view_no_trans_inverse);589 poly->transform(model_view_trans);590 591 glPushMatrix();592 glScalef(vol->aspect_ratio_width, vol->aspect_ratio_height,593 vol->aspect_ratio_depth);594 595 activate_volume_shader(vol, true);596 glPopMatrix();597 598 glBegin(GL_POLYGON);599 poly->Emit(true);600 glEnd();601 602 deactivate_volume_shader();603 }604 } //slice_mode605 606 607 if(volume_mode){608 glEnable(GL_DEPTH_TEST);609 610 for (int i=0; i<n_actual_slices; i++){611 slice_z = zFar + i * z_step; //back to front612 613 ConvexPolygon *poly;614 poly = &staticPoly;615 poly->vertices.clear();616 617 //Setting Z-coordinate618 vert1.z = slice_z;619 vert2.z = slice_z;620 vert3.z = slice_z;621 vert4.z = slice_z;622 623 poly->append_vertex(vert1);624 poly->append_vertex(vert2);625 poly->append_vertex(vert3);626 poly->append_vertex(vert4);627 628 for(int k=0; k<6; k++){629 poly->clip(volume_planes[k], true);630 }631 632 //move the volume to the proper location633 //poly->transform(model_view_inverse);634 //poly->translate(shift_4d);635 //poly->transform(model_view);636 637 poly->transform(model_view_no_trans_inverse);638 poly->transform(model_view_trans);639 640 glPushMatrix();641 glScalef(vol->aspect_ratio_width, vol->aspect_ratio_height,642 vol->aspect_ratio_depth);643 644 /*645 //draw slice lines only646 glDisable(GL_BLEND);647 glDisable(GL_TEXTURE_3D);648 glDisable(GL_TEXTURE_2D);649 glLineWidth(1.0);650 glColor3f(1,1,1);651 glBegin(GL_LINE_LOOP);652 poly->Emit(false);653 glEnd();654 */655 656 activate_volume_shader(vol, true);657 glPopMatrix();658 659 glBegin(GL_POLYGON);660 poly->Emit(true);661 glEnd();662 663 deactivate_volume_shader();664 665 }666 } //volume_mode667 668 glDisable(GL_BLEND);669 glDisable(GL_DEPTH_TEST);670 }671 672 422 void 673 423 VolumeRenderer::draw_bounding_box(float x0, float y0, float z0, … … 793 543 794 544 void 795 VolumeRenderer::activate_volume_shader(Volume* vol , bool slice_mode)545 VolumeRenderer::activate_volume_shader(Volume* volPtr, bool slice_mode) 796 546 { 797 547 //vertex shader 798 548 _stdVertexShader->bind(); 799 TransferFunction *tf = vol->transferFunction(); 800 if (vol->volume_type() == Volume::CUBIC) { 801 //regular cubic volume 802 _regularVolumeShader->bind(tf->id, vol, slice_mode); 803 } else if (vol->volume_type() == Volume::ZINCBLENDE) { 804 _zincBlendeShader->bind(tf->id, vol, slice_mode); 549 TransferFunction *tfPtr = volPtr->transferFunction(); 550 if (volPtr->volume_type() == Volume::CUBIC) { 551 Trace("regular volume shader: volume=%s tf=%s slice_mode=%d\n", 552 volPtr->name(), tfPtr->name(), slice_mode); 553 _regularVolumeShader->bind(tfPtr->id(), volPtr, slice_mode); 554 } else if (volPtr->volume_type() == Volume::ZINCBLENDE) { 555 Trace("zincblende volume shader: volume=%s tf=%s slice_mode=%d\n", 556 volPtr->name(), tfPtr->name(), slice_mode); 557 _zincBlendeShader->bind(tfPtr->id(), volPtr, slice_mode); 805 558 } 806 559 } … … 879 632 880 633 if (fread(&bfType, sizeof(short int), 1, f) != 1) { 881 fprintf(stderr, "can't read % dbytes from font file \"%s\"\n",882 sizeof(short int), filename);634 fprintf(stderr, "can't read %lu bytes from font file \"%s\"\n", 635 (unsigned long)sizeof(short int), filename); 883 636 goto error; 884 637 } -
trunk/packages/vizservers/nanovis/VolumeRenderer.h
r1478 r1493 100 100 ~VolumeRenderer(); 101 101 102 void add_volume(Volume* _vol, TransferFunction* _tf); 103 void render(int volumeID); 104 void render_all(); //render all enabled volumes; 105 void render_all_points(void); //render all enabled volumes; 102 void render_all(); //render all enabled volumes; 106 103 void specular(float val); 107 104 void diffuse(float val); 108 void set_slice_mode(bool val); 105 void set_slice_mode(bool val); //control independently. 109 106 void set_volume_mode(bool val); 110 void switch_slice_mode(); 107 void switch_slice_mode(); //switch_cutplane_mode 111 108 void switch_volume_mode(); 112 109 -
trunk/packages/vizservers/nanovis/dxReader.cpp
r1478 r1493 47 47 /* Load a 3D volume from a dx-format file 48 48 */ 49 bool 50 load_volume_stream2(Rappture::Outcome &result, int volDataID, std::iostream& fin) 49 Volume * 50 load_volume_stream2(Rappture::Outcome &result, const char *tag, 51 std::iostream& fin) 51 52 { 52 printf("load_volume_stream2 \n");53 printf("load_volume_stream2 %s\n", tag); 53 54 Rappture::MeshTri2D xymesh; 54 55 int dummy, nx, ny, nz, nxy, npts; … … 118 119 } else { 119 120 result.error("triangularization failed"); 120 return false;121 return NULL; 121 122 } 122 123 unlink(fpts), unlink(fcells); … … 143 144 result.addError("don't know how to handle multiple non-zero" 144 145 " delta values"); 145 return false;146 return NULL; 146 147 } 147 148 } else if (sscanf(start, "object %d class array type %s rank 0 items %d data follows", &dummy, type, &npts) == 3) { … … 149 150 result.addError("inconsistent data: expected %d points " 150 151 " but found %d points", nx*ny*nz, npts); 151 return false;152 return NULL; 152 153 } else if (!isrect && (npts != nxy*nz)) { 153 154 result.addError("inconsistent data: expected %d points " 154 155 " but found %d points", nxy*nz, npts); 155 return false;156 return NULL; 156 157 } 157 158 break; … … 160 161 result.addError("inconsistent data: expected %d points " 161 162 " but found %d points", nx*ny*nz, npts); 162 return false;163 return NULL; 163 164 } 164 165 break; … … 172 173 if (fin.eof()) { 173 174 result.addError("EOF found: expecting %d points", npts); 174 return false;175 return NULL; 175 176 } 176 Volume *volPtr = 0;177 Volume *volPtr = NULL; 177 178 if (isrect) { 178 179 double dval[6]; … … 220 221 result.addError("inconsistent data: expected %d points " 221 222 " but found %d points", nx*ny*nz, nread); 222 return false;223 return NULL; 223 224 } 224 225 … … 247 248 dz = nz; 248 249 249 volPtr = NanoVis::load_volume( volDataID, nx, ny, nz, 4, data,250 volPtr = NanoVis::load_volume(tag, nx, ny, nz, 4, data, 250 251 vmin, vmax, nzero_min); 251 252 volPtr->xAxis.SetRange(x0, x0 + (nx * dx)); … … 269 270 result.addError("after %d of %d points: can't read number", 270 271 nread, npts); 271 return false;272 return NULL; 272 273 } else { 273 274 int nid = nxy*iz + ixy; … … 286 287 result.addError("inconsistent data: expected %d points " 287 288 "but found %d points", nxy*nz, nread); 288 return false;289 return NULL; 289 290 } 290 291 … … 387 388 } 388 389 389 volPtr = NanoVis::load_volume( volDataID, nx, ny, nz, 4, data,390 390 volPtr = NanoVis::load_volume(tag, nx, ny, nz, 4, data, 391 field.valueMin(), field.valueMax(), nzero_min); 391 392 volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis), 392 393 field.rangeMax(Rappture::xaxis)); … … 409 410 printf("volume moved\n"); 410 411 } 411 return true;412 return volPtr; 412 413 } 413 414 414 bool 415 load_volume_stream(Rappture::Outcome &result, int volDataID, std::iostream& fin) 415 Volume * 416 load_volume_stream(Rappture::Outcome &result, const char *tag, 417 std::iostream& fin) 416 418 { 417 419 printf("load_volume_stream\n"); … … 431 433 if (fin.fail()) { 432 434 result.error("error in data stream"); 433 return false;435 return NULL; 434 436 } 435 437 for (start=line; *start == ' ' || *start == '\t'; start++) … … 490 492 } else { 491 493 result.error("triangularization failed"); 492 return false;494 return NULL; 493 495 } 494 496 unlink(fpts); … … 507 509 result.addError("inconsistent data: expected %d points" 508 510 " but found %d points", nx*ny*nz, npts); 509 return false;511 return NULL; 510 512 } else if (!isrect && (npts != nxy*nz)) { 511 513 result.addError("inconsistent data: expected %d points" 512 514 " but found %d points", nx*ny*nz, npts); 513 return false;515 return NULL; 514 516 } 515 517 break; … … 518 520 result.addError("inconsistent data: expected %d points" 519 521 " but found %d points", nx*ny*nz, npts); 520 return false;522 return NULL; 521 523 } 522 524 break; … … 527 529 if (fin.eof()) { 528 530 result.error("data not found in stream"); 529 return false;531 return NULL; 530 532 } 531 533 Volume *volPtr = 0; … … 545 547 if (fin.fail()) { 546 548 result.addError("error reading data points"); 547 return false;549 return NULL; 548 550 } 549 551 int n = sscanf(line, "%lg %lg %lg %lg %lg %lg", &dval[0], &dval[1], &dval[2], &dval[3], &dval[4], &dval[5]); … … 568 570 result.addError("inconsistent data: expected %d points" 569 571 " but found %d points", nx*ny*nz, npts); 570 return false;572 return NULL; 571 573 } 572 574 … … 653 655 } 654 656 #endif 655 fprintf(stdout,"End Data Stats DataID = %i\n",volDataID);656 657 fprintf(stdout,"nx = %i ny = %i nz = %i\n",nx,ny,nz); 657 658 fprintf(stdout,"dx = %lg dy = %lg dz = %lg\n",dx,dy,dz); … … 659 660 fflush(stdout); 660 661 661 volPtr = NanoVis::load_volume( volDataID, nx, ny, nz, 4, data,662 662 volPtr = NanoVis::load_volume(tag, nx, ny, nz, 4, data, 663 field.valueMin(), field.valueMax(), nzero_min); 663 664 volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis), 664 665 field.rangeMax(Rappture::xaxis)); … … 695 696 result.addError("after %d of %d points: can't read number", 696 697 nread, npts); 697 return false;698 return NULL; 698 699 } else { 699 700 int nid = nxy*iz + ixy; … … 712 713 result.addError("inconsistent data: expected %d points" 713 714 " but found %d points", nx*ny*nz, npts); 714 return false;715 return NULL; 715 716 } 716 717 … … 804 805 } 805 806 806 volPtr = NanoVis::load_volume( volDataID, nx, ny, nz, 4, data,807 807 volPtr = NanoVis::load_volume(tag, nx, ny, nz, 4, data, 808 field.valueMin(), field.valueMax(), nzero_min); 808 809 volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis), 809 810 field.rangeMax(Rappture::xaxis)); … … 838 839 volPtr->location(Vector3(dx0, dy0, dz0)); 839 840 } 840 return true;841 return volPtr; 841 842 } 842 843 843 844 844 bool 845 load_volume_stream_insoo(Rappture::Outcome &result, int volDataID,845 Volume * 846 load_volume_stream_insoo(Rappture::Outcome &result, const char *tag, 846 847 std::iostream& fin) 847 848 { … … 862 863 if (fin.fail()) { 863 864 result.addError("line \"%s\"error in data stream"); 864 return false;865 return NULL; 865 866 } 866 867 for (start=line; *start == ' ' || *start == '\t'; start++) … … 921 922 } else { 922 923 result.error("triangularization failed"); 923 return false;924 return NULL; 924 925 } 925 926 unlink(fpts), unlink(fcells); … … 937 938 result.addError("inconsistent data: expected %d points" 938 939 " but found %d points", nx*ny*nz, npts); 939 return false;940 return NULL; 940 941 } else if (!isrect && (npts != nxy*nz)) { 941 942 result.addError("inconsistent data: expected %d points" 942 943 " but found %d points", nx*ny*nz, npts); 943 return false;944 return NULL; 944 945 } 945 946 break; … … 948 949 result.addError("inconsistent data: expected %d points" 949 950 " but found %d points", nx*ny*nz, npts); 950 return false;951 return NULL; 951 952 } 952 953 break; … … 958 959 if (fin.eof()) { 959 960 result.error("data not found in stream"); 960 return false;961 return NULL; 961 962 } 962 963 … … 977 978 if (fin.fail()) { 978 979 result.error("error reading data points"); 979 return false;980 return NULL; 980 981 } 981 982 int n = sscanf(line, "%lg %lg %lg %lg %lg %lg", &dval[0], &dval[1], &dval[2], &dval[3], &dval[4], &dval[5]); … … 1002 1003 result.addError("inconsistent data: expected %d points" 1003 1004 " but found %d points", nx*ny*nz, npts); 1004 return false;1005 return NULL; 1005 1006 } 1006 1007 … … 1132 1133 */ 1133 1134 1134 volPtr = NanoVis::load_volume( volDataID, nx, ny, nz, 4, data,1135 1135 volPtr = NanoVis::load_volume(tag, nx, ny, nz, 4, data, 1136 field.valueMin(), field.valueMax(), nzero_min); 1136 1137 volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis), 1137 1138 field.rangeMax(Rappture::xaxis)); … … 1170 1171 nread, npts); 1171 1172 result.error(mesg); 1172 return false;1173 return NULL; 1173 1174 } else { 1174 1175 int nid = nxy*iz + ixy; … … 1187 1188 result.addError("inconsistent data: expected %d points" 1188 1189 " but found %d points", nx*ny*nz, npts); 1189 return false;1190 return NULL; 1190 1191 } 1191 1192 … … 1279 1280 } 1280 1281 1281 volPtr = NanoVis::load_volume( volDataID, nx, ny, nz, 4, data,1282 1282 volPtr = NanoVis::load_volume(tag, nx, ny, nz, 4, data, 1283 field.valueMin(), field.valueMax(), nzero_min); 1283 1284 volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis), 1284 1285 field.rangeMax(Rappture::xaxis)); … … 1313 1314 volPtr->location(Vector3(dx0, dy0, dz0)); 1314 1315 } 1315 return true;1316 return volPtr; 1316 1317 } -
trunk/packages/vizservers/nanovis/dxReader2.cpp
r1478 r1493 16 16 /* Load a 3D volume from a dx-format file the new way 17 17 */ 18 bool 19 load_volume_stream_odx(Rappture::Outcome &context, int userID, const char *buf,20 18 Volume * 19 load_volume_stream_odx(Rappture::Outcome &context, const char *tag, 20 const char *buf, int nBytes) 21 21 { 22 22 char dxfilename[128]; … … 24 24 if (nBytes <= 0) { 25 25 context.error("empty data buffer\n"); 26 return false;26 return NULL; 27 27 } 28 28 … … 42 42 context.addError("Can't read %d bytes from file \"%s\"\n", 43 43 nBytes, dxfilename); 44 return false;44 return NULL; 45 45 } 46 46 … … 49 49 if (unlink(dxfilename) != 0) { 50 50 context.addError("Error deleting dx file: %s\n", dxfilename); 51 return false;51 return NULL; 52 52 } 53 53 … … 88 88 computeSimpleGradient(data, nx, ny, nz); 89 89 90 fprintf(stdout,"End Data Stats userID = %i\n",userID);91 90 fprintf(stdout,"nx = %i ny = %i nz = %i\n",nx,ny,nz); 92 91 fprintf(stdout,"dx = %lg dy = %lg dz = %lg\n",dx,dy,dz); … … 95 94 96 95 Volume *volPtr; 97 volPtr = NanoVis::load_volume( userID, nx, ny, nz, 4, data,96 volPtr = NanoVis::load_volume(tag, nx, ny, nz, 4, data, 98 97 dxObj.dataMin(), 99 98 dxObj.dataMax(), … … 117 116 float dz0 = -0.5*dz/dx; 118 117 volPtr->location(Vector3(dx0, dy0, dz0)); 119 return true;118 return volPtr; 120 119 } -
trunk/packages/vizservers/nanovis/nanovis.cpp
r1484 r1493 77 77 78 78 extern void NvInitCG(); // in Shader.cpp 79 extern bool load_vector_stream2(Rappture::Outcome &result, int index,80 size_t length, char *string);81 79 82 80 // Indicates "up" axis: x=1, y=2, z=3, -x=-1, -y=-2, -z=-3 … … 107 105 int NanoVis::updir = Y_POS; 108 106 NvCamera* NanoVis::cam = NULL; 109 vector<Volume *> NanoVis::volumes;107 Tcl_HashTable NanoVis::volumeTable; 110 108 vector<HeightMap*> NanoVis::heightMap; 111 109 VolumeRenderer* NanoVis::vol_renderer = NULL; … … 174 172 175 173 // maps transfunc name to TransferFunction object 176 static Tcl_HashTable tftable;174 Tcl_HashTable NanoVis::tfTable; 177 175 178 176 // pointers to 2D planes, currently handle up 10 … … 513 511 */ 514 512 Volume * 515 NanoVis::load_volume(int dataID, int width, int height, int depth, 516 int n_component, float* data, double vmin, 517 double vmax, double nzero_min) 518 { 519 // Check if we're attempting to load the volume into an already 520 // occupied slot. 521 522 523 Volume* volPtr = new Volume(0.f, 0.f, 0.f, width, height, depth, 1., 524 n_component, data, vmin, vmax, nzero_min); 525 if (dataID < 0) { 526 dataID = volumes.size(); 527 volumes.push_back(volPtr); 528 } else { 529 int i; 530 // Create new slots it needed. 531 for (i = volumes.size(); i <= dataID; i++) { 532 volumes.push_back(NULL); 533 } 534 assert (volumes[dataID] == NULL); 535 volumes[dataID] = volPtr; 536 } 537 volPtr->dataID(dataID); 538 fprintf(stderr, "VOLID=%d, # of volume slots=%d\n", dataID, 539 volumes.size()); 513 NanoVis::load_volume(const char *name, int width, int height, int depth, 514 int n_component, float* data, double vmin, double vmax, 515 double nzero_min) 516 { 517 Tcl_HashEntry *hPtr; 518 hPtr = Tcl_FindHashEntry(&NanoVis::volumeTable, name); 519 if (hPtr != NULL) { 520 Volume *volPtr; 521 Trace("volume \"%s\" already exists", name); 522 volPtr = (Volume *)Tcl_GetHashValue(hPtr); 523 remove_volume(volPtr); 524 } 525 int isNew; 526 hPtr = Tcl_CreateHashEntry(&NanoVis::volumeTable, name, &isNew); 527 Volume* volPtr; 528 volPtr = new Volume(0.f, 0.f, 0.f, width, height, depth, 1., n_component, 529 data, vmin, vmax, nzero_min); 530 Tcl_SetHashValue(hPtr, volPtr); 531 volPtr->name(Tcl_GetHashKey(&NanoVis::volumeTable, hPtr)); 540 532 return volPtr; 541 533 } … … 547 539 Tcl_HashEntry *hPtr; 548 540 549 hPtr = Tcl_FindHashEntry(&tf table, name);541 hPtr = Tcl_FindHashEntry(&tfTable, name); 550 542 if (hPtr == NULL) { 551 543 return NULL; … … 560 552 int isNew; 561 553 Tcl_HashEntry *hPtr; 562 TransferFunction *tf ;563 564 hPtr = Tcl_CreateHashEntry(&tf table, name, &isNew);554 TransferFunction *tfPtr; 555 556 hPtr = Tcl_CreateHashEntry(&tfTable, name, &isNew); 565 557 if (isNew) { 566 tf = new TransferFunction(n, data); 567 Tcl_SetHashValue(hPtr, (ClientData)tf); 558 tfPtr = new TransferFunction(n, data); 559 tfPtr->name(Tcl_GetHashKey(&tfTable, hPtr)); 560 Tcl_SetHashValue(hPtr, tfPtr); 568 561 } else { 569 562 /* … … 571 564 * objects may be holding its pointer. We must update it. 572 565 */ 573 tf = (TransferFunction *)Tcl_GetHashValue(hPtr);574 tf ->update(n, data);575 } 576 return tf ;566 tfPtr = (TransferFunction *)Tcl_GetHashValue(hPtr); 567 tfPtr->update(n, data); 568 } 569 return tfPtr; 577 570 } 578 571 … … 916 909 917 910 // init table of transfer functions 918 Tcl_InitHashTable(&tf table, TCL_STRING_KEYS);911 Tcl_InitHashTable(&tfTable, TCL_STRING_KEYS); 919 912 920 913 //check if performance query is supported … … 1542 1535 xMin = yMin = zMin = wMin = DBL_MAX; 1543 1536 xMax = yMax = zMax = wMax = -DBL_MAX; 1544 vector<Volume *>::iterator iter; 1545 for (iter = volumes.begin(); iter != volumes.end(); ++iter) { 1537 Tcl_HashEntry *hPtr; 1538 Tcl_HashSearch iter; 1539 for (hPtr = Tcl_FirstHashEntry(&volumeTable, &iter); hPtr != NULL; 1540 hPtr = Tcl_NextHashEntry(&iter)) { 1546 1541 Volume *volPtr; 1547 1542 1548 volPtr = (*iter); 1549 if (volPtr == NULL) { 1550 continue; // Empty slot. 1551 } 1543 volPtr = (Volume *)Tcl_GetHashValue(hPtr); 1552 1544 if (xMin > volPtr->xAxis.min()) { 1553 1545 xMin = volPtr->xAxis.min(); … … 2555 2547 2556 2548 void 2557 NanoVis::remove_volume(size_t index) 2558 { 2559 fprintf(stderr, "index=%d #volumes=%d\n", index, volumes.size()); 2560 assert(index < volumes.size()); 2561 Volume* volPtr; 2562 volPtr = volumes[index]; 2563 if (volPtr == NULL) { 2564 return; // Empty slot 2565 } 2566 delete volPtr; // Delete the volume and mark the 2567 volumes[index] = NULL; // slot as empty. 2549 NanoVis::remove_volume(Volume *volPtr) 2550 { 2551 Tcl_HashEntry *hPtr; 2552 hPtr = Tcl_FindHashEntry(&volumeTable, volPtr->name()); 2553 if (hPtr != NULL) { 2554 Tcl_DeleteHashEntry(hPtr); 2555 } 2556 delete volPtr; 2568 2557 } 2569 2558 -
trunk/packages/vizservers/nanovis/nanovis.h
r1484 r1493 43 43 #include "global.h" 44 44 #include "socket/Socket.h" 45 #include "rappture.h" 45 46 #include "NvCamera.h" 46 47 #include "ConvexPolygon.h" … … 131 132 static vector<HeightMap*> heightMap; 132 133 static unsigned char* screen_buffer; 133 static vector<Volume *> volumes;134 static Tcl_HashTable volumeTable; 134 135 static vector<NvVectorField*> flow; 135 136 static Grid* grid; 136 137 static R2Fonts* fonts; 137 static int n_volumes;138 138 static int updir; 139 139 static NvCamera *cam; … … 155 155 static Tcl_DString cmdbuffer; 156 156 157 static int _last_data_id;158 157 public : 159 158 static TransferFunction* get_transfunc(const char *name); … … 184 183 static int render_legend(TransferFunction *tf, double min, double max, 185 184 int width, int height, const char* volArg); 186 static Volume *load_volume(int volDataID, int width, int height, int depth, 187 int n, float* data, double vmin, double vmax, double nzero_min); 185 static Volume *load_volume(const char *tag, int width, int height, 186 int depth, int n, float* data, double vmin, double vmax, 187 double nzero_min); 188 188 static void xinetd_listen(void); 189 189 static int render_2d_contour(HeightMap* heightmap, int width, int height); … … 233 233 }; 234 234 static void EventuallyRedraw(unsigned int flag = 0); 235 static void remove_volume( size_t index);236 static int generate_data_identifier();235 static void remove_volume(Volume *volPtr); 236 static Tcl_HashTable tfTable; 237 237 }; 238 238 239 extern Volume *load_volume_stream(Rappture::Outcome &status, const char *tag, 240 std::iostream& fin); 241 extern Volume *load_volume_stream_odx(Rappture::Outcome &status, 242 const char *tag, const char *buf, int nBytes); 243 extern Volume *load_volume_stream2(Rappture::Outcome &status, const char *tag, 244 std::iostream& fin); 245 246 extern Volume *load_vector_stream(Rappture::Outcome &result, const char *tag, 247 size_t length, char *bytes); 248 extern Volume *load_vector_stream2(Rappture::Outcome &result, const char *tag, 249 size_t length, char *bytes); 250 239 251 240 252 #endif /* __NANOVIS_H__ */
Note: See TracChangeset
for help on using the changeset viewer.