Changeset 1493 for trunk/packages/vizservers/nanovis/nanovis.cpp
- Timestamp:
- Jun 8, 2009, 8:31:59 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.