Changeset 1475 for trunk/packages
- Timestamp:
- May 29, 2009, 1:13:42 PM (15 years ago)
- Location:
- trunk/packages/vizservers/nanovis
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/Command.cpp
r1474 r1475 363 363 /* 364 364 * ---------------------------------------------------------------------- 365 * FUNCTION: GetVolume Index365 * FUNCTION: GetVolumeDataID 366 366 * 367 367 * Used internally to decode a series of volume index values and … … 375 375 */ 376 376 static int 377 GetVolume Index(Tcl_Interp *interp, Tcl_Obj *objPtr, unsigned int *indexPtr)378 { 379 int index;380 if (Tcl_GetIntFromObj(interp, objPtr, & index) != TCL_OK) {377 GetVolumeDataID(Tcl_Interp *interp, Tcl_Obj *objPtr, unsigned int *dataIDPtr) 378 { 379 int volDataID; 380 if (Tcl_GetIntFromObj(interp, objPtr, &volDataID) != TCL_OK) { 381 381 return TCL_ERROR; 382 382 } … … 386 386 return TCL_ERROR; 387 387 } 388 /* 388 389 if (index >= (int)NanoVis::volume.size()) { 389 390 Tcl_AppendResult(interp, "index \"", Tcl_GetString(objPtr), … … 391 392 return TCL_ERROR; 392 393 } 393 *indexPtr = (unsigned int)index; 394 */ 395 396 NanoVis::VolumeMap::iterator iter = NanoVis::volumeMap.find(volDataID); 397 if (iter == NanoVis::volumeMap.end()) 398 { 399 Tcl_AppendResult(interp, "dataID \"", Tcl_GetString(objPtr), 400 "\" is out found", (char*)NULL); 401 return TCL_ERROR; 402 } 403 404 *dataIDPtr = (unsigned int)volDataID; 394 405 return TCL_OK; 395 406 } … … 411 422 GetVolumeFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, Volume **volPtrPtr) 412 423 { 413 unsigned int index;414 if (GetVolume Index(interp, objPtr, &index) != TCL_OK) {424 unsigned int volDataID; 425 if (GetVolumeDataID(interp, objPtr, &volDataID) != TCL_OK) { 415 426 return TCL_ERROR; 416 427 } 417 428 Volume *vol; 418 vol = NanoVis::volume [index];429 vol = NanoVis::volumeMap[volDataID]; 419 430 if (vol == NULL) { 420 Tcl_AppendResult(interp, "no volume defined for index\"",431 Tcl_AppendResult(interp, "no volume defined for volDataID \"", 421 432 Tcl_GetString(objPtr), "\"", (char*)NULL); 422 433 return TCL_ERROR; 423 434 } 424 435 *volPtrPtr = vol; 436 //printf("volume [%d] found\n", vol->getDataID()); 425 437 return TCL_OK; 426 438 } … … 428 440 /* 429 441 * ---------------------------------------------------------------------- 430 * FUNCTION: GetVolume Indices()442 * FUNCTION: GetVolumeDataIDs() 431 443 * 432 444 * Used internally to decode a series of volume index values and … … 440 452 */ 441 453 static int 442 GetVolume Indices(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv,454 GetVolumeDataIDs(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv, 443 455 vector<unsigned int>* vectorPtr) 444 456 { 445 457 if (objc == 0) { 446 for (unsigned int n = 0; n < NanoVis::volume.size(); n++) { 447 if (NanoVis::volume[n] != NULL) { 448 vectorPtr->push_back(n); 449 } 458 NanoVis::VolumeMap::iterator iter; 459 for (iter = NanoVis::volumeMap.begin(); iter != NanoVis::volumeMap.end(); ++iter) { 460 if ((*iter).second != NULL) { 461 vectorPtr->push_back((*iter).first); 462 } 450 463 } 451 464 } else { 465 NanoVis::VolumeMap::iterator iter; 452 466 for (int n = 0; n < objc; n++) { 453 unsigned int index;454 455 if (GetVolume Index(interp, objv[n], &index) != TCL_OK) {467 unsigned int volDataID; 468 469 if (GetVolumeDataID(interp, objv[n], &volDataID) != TCL_OK) { 456 470 return TCL_ERROR; 457 471 } 458 if (NanoVis::volume[index] != NULL) { 459 vectorPtr->push_back(index); 472 473 iter = NanoVis::volumeMap.find(volDataID); 474 if ((iter != NanoVis::volumeMap.end()) && ((*iter).second != 0)) { 475 vectorPtr->push_back(volDataID); 460 476 } 461 477 } … … 482 498 { 483 499 if (objc == 0) { 484 for (unsigned int n = 0; n < NanoVis::volume.size(); n++) { 485 if (NanoVis::volume[n] != NULL) { 486 vectorPtr->push_back(NanoVis::volume[n]); 500 NanoVis::VolumeMap::iterator iter; 501 for (iter = NanoVis::volumeMap.begin(); iter != NanoVis::volumeMap.end(); ++iter) { 502 if ((*iter).second != NULL) { 503 vectorPtr->push_back((*iter).second); 487 504 } 488 505 } … … 1185 1202 { 1186 1203 vector<unsigned int> ivol; 1187 if (GetVolume Indices(interp, objc - 3, objv + 3, &ivol) != TCL_OK) {1188 return TCL_ERROR; 1189 } 1190 Trace("parsing volume index\n");1204 if (GetVolumeDataIDs(interp, objc - 3, objv + 3, &ivol) != TCL_OK) { 1205 return TCL_ERROR; 1206 } 1207 Trace("parsing volume data identifier\n"); 1191 1208 vector<unsigned int>::iterator iter; 1192 1209 for (iter = ivol.begin(); iter != ivol.end(); iter++) { 1193 Trace(" index: %d\n", *iter);1194 NanoVis::vol_renderer->addAnimatedVolume(NanoVis::volume [*iter], *iter);1210 Trace("volDataID: %d\n", *iter); 1211 NanoVis::vol_renderer->addAnimatedVolume(NanoVis::volumeMap[*iter], *iter); 1195 1212 } 1196 1213 return TCL_OK; … … 1239 1256 return TCL_ERROR; 1240 1257 } 1241 int n = NanoVis::n_volumes;1242 1258 char header[6]; 1243 1259 memcpy(header, buf.bytes(), sizeof(char) * 5); … … 1260 1276 printf("Checking header[%s]\n", header); 1261 1277 fflush(stdout); 1278 1279 Volume *volPtr = 0; 1280 int volDataID = -1; 1262 1281 if (strcmp(header, "<HDR>") == 0) { 1263 Volume* vol = NULL;1264 1265 1282 printf("ZincBlende stream is in\n"); 1266 1283 fflush(stdout); … … 1270 1287 1271 1288 #if _LOCAL_ZINC_TEST_ 1272 vol = NvZincBlendeReconstructor::getInstance()->loadFromMemory(b);1289 volPtr = NvZincBlendeReconstructor::getInstance()->loadFromMemory(b); 1273 1290 #else 1274 vol = NvZincBlendeReconstructor::getInstance()->loadFromMemory((void*) buf.bytes());1291 volPtr = NvZincBlendeReconstructor::getInstance()->loadFromMemory((void*) buf.bytes()); 1275 1292 #endif /*_LOCAL_ZINC_TEST_*/ 1276 if (vol == NULL) {1293 if (volPtr == NULL) { 1277 1294 Tcl_AppendResult(interp, "can't get volume instance", (char *)NULL); 1278 1295 return TCL_OK; … … 1280 1297 printf("finish loading\n"); 1281 1298 fflush(stdout); 1282 while (NanoVis::n_volumes <= n) { 1283 NanoVis::volume.push_back((Volume*) NULL); 1284 NanoVis::n_volumes++; 1285 } 1286 1287 if (NanoVis::volume[n] != NULL) { 1288 delete NanoVis::volume[n]; 1289 NanoVis::volume[n] = NULL; 1299 1300 // INSOO 1301 // TBD.. 1302 volDataID = NanoVis::generate_data_identifier(); 1303 NanoVis::VolumeMap::iterator iter; 1304 iter = NanoVis::volumeMap.find(volDataID); 1305 if (iter != NanoVis::volumeMap.end()) 1306 { 1307 if (iter->second != NULL) { 1308 iter->second->unref(); 1309 iter->second = 0; 1310 } 1290 1311 } 1291 1312 1292 1313 float dx0 = -0.5; 1293 float dy0 = -0.5*vol ->height/vol->width;1294 float dz0 = -0.5*vol ->depth/vol->width;1295 vol ->move(Vector3(dx0, dy0, dz0));1296 1297 NanoVis::volume [n] = vol;1314 float dy0 = -0.5*volPtr->height/volPtr->width; 1315 float dz0 = -0.5*volPtr->depth/volPtr->width; 1316 volPtr->move(Vector3(dx0, dy0, dz0)); 1317 1318 NanoVis::volumeMap[volDataID] = volPtr; 1298 1319 #if __TEST_CODE__ 1299 1320 } else if (strcmp(header, "<FET>") == 0) { … … 1308 1329 #endif /*__TEST_CODE__*/ 1309 1330 } else if (strcmp(header, "<ODX>") == 0) { 1331 /* 1310 1332 Rappture::Outcome err; 1311 1333 … … 1316 1338 return TCL_ERROR; 1317 1339 } 1340 */ 1318 1341 } else { 1342 volDataID = NanoVis::generate_data_identifier(); 1343 printf("test\n"); 1319 1344 #ifdef notdef 1320 1345 Rappture::Unirect3d *dataPtr; … … 1329 1354 dataPtr->Resample(context, 30); 1330 1355 #endif 1331 Volume *volPtr; 1332 volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data, vmin, vmax, 1356 volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data, vmin, vmax, 1333 1357 nzero_min); 1334 1358 … … 1353 1377 Rappture::Outcome context; 1354 1378 #if ISO_TEST 1355 result = load_volume_stream2(context, n, fdata);1379 result = load_volume_stream2(context, volDataID, fdata); 1356 1380 #else 1357 result = load_volume_stream(context, n, fdata);1381 result = load_volume_stream(context, volDataID, fdata); 1358 1382 #endif 1359 1383 if (!result) { … … 1361 1385 return TCL_ERROR; 1362 1386 } 1387 volPtr = NanoVis::volumeMap[volDataID]; 1363 1388 } 1364 1389 … … 1369 1394 // overwrite the first, so the first won't appear at all. 1370 1395 // 1371 if (NanoVis::volume[n] != NULL) { 1372 //NanoVis::volume[n]->set_n_slice(512-n); 1373 NanoVis::volume[n]->set_n_slice(256-n); 1374 NanoVis::volume[n]->disable_cutplane(0); 1375 NanoVis::volume[n]->disable_cutplane(1); 1376 NanoVis::volume[n]->disable_cutplane(2); 1377 1378 NanoVis::vol_renderer->add_volume(NanoVis::volume[n], 1396 if (volPtr != NULL) { 1397 //volPtr->set_n_slice(512-n); 1398 //volPtr->set_n_slice(256-n); 1399 volPtr->set_n_slice(256); 1400 volPtr->disable_cutplane(0); 1401 volPtr->disable_cutplane(1); 1402 volPtr->disable_cutplane(2); 1403 1404 NanoVis::vol_renderer->add_volume(volPtr, 1379 1405 NanoVis::get_transfunc("default")); 1380 } 1381 1382 { 1383 Volume *volPtr; 1406 1384 1407 char info[1024]; 1385 1408 ssize_t nWritten; … … 1388 1411 NanoVis::SetVolumeRanges(); 1389 1412 } 1390 volPtr = NanoVis::volume[n]; 1413 1391 1414 // FIXME: strlen(info) is the return value of sprintf 1392 1415 sprintf(info, "nv>data tag %s id %d min %g max %g vmin %g vmax %g\n", 1393 tag, n, volPtr->wAxis.min(), volPtr->wAxis.max(),1416 tag, volDataID, volPtr->wAxis.min(), volPtr->wAxis.max(), 1394 1417 Volume::valueMin, Volume::valueMax); 1395 1418 nWritten = write(0, info, strlen(info)); … … 1683 1706 Tcl_Obj *const *objv) 1684 1707 { 1685 NanoVis::volume[1]->data(false); 1686 NanoVis::volume[1]->visible(false); 1708 NanoVis::VolumeMap::iterator iter = NanoVis::volumeMap.find(1); 1709 if (iter != NanoVis::volumeMap.end()) 1710 { 1711 NanoVis::volumeMap[1]->data(false); 1712 NanoVis::volumeMap[1]->visible(false); 1713 } 1687 1714 return TCL_OK; 1688 1715 } … … 2413 2440 NanoVis::SetHeightmapRanges(); 2414 2441 } 2442 2415 2443 NanoVis::render_legend(tf, HeightMap::valueMin, HeightMap::valueMax, w, h, 2416 2444 "label"); 2417 2445 return TCL_OK; 2418 2446 } -
trunk/packages/vizservers/nanovis/FlowCmd.cpp
r1474 r1475 272 272 _interp = interp; 273 273 _hashPtr = hPtr; 274 _vol Index= -1; /* Indicates that no volume slot has274 _volDataID = -1; /* Indicates that no volume slot has 275 275 * been allocated for this vector. */ 276 276 _sv.sliceVisible = 1; … … 296 296 } 297 297 if (_volPtr != NULL) { 298 delete _volPtr;298 _volPtr->unref(); 299 299 _volPtr = NULL; 300 NanoVis:: volume[_volIndex] = NULL;301 NanoVis::vol_renderer->remove_volume(_vol Index);300 NanoVis::remove_volume(_volDataID); 301 NanoVis::vol_renderer->remove_volume(_volDataID); 302 302 } 303 303 … … 500 500 { 501 501 if (_volPtr != NULL) { 502 delete _volPtr;502 _volPtr->unref(); 503 503 _volPtr = NULL; 504 NanoVis:: volume[_volIndex] = NULL;505 NanoVis::vol_renderer->remove_volume(_vol Index);504 NanoVis::remove_volume(_volDataID); 505 NanoVis::vol_renderer->remove_volume(_volDataID); 506 506 } 507 507 // Remove the associated vector field. … … 528 528 { 529 529 if (_volPtr != NULL) { 530 delete _volPtr;530 _volPtr->unref(); 531 531 _volPtr = NULL; 532 NanoVis:: volume[_volIndex] = NULL;533 NanoVis::vol_renderer->remove_volume(_vol Index);532 NanoVis::remove_volume(_volDataID); 533 NanoVis::vol_renderer->remove_volume(_volDataID); 534 534 } 535 535 float *vdata; … … 632 632 FlowCmd::MakeVolume(float *data) 633 633 { 634 if (_vol Index< 0) {635 _vol Index = NanoVis::n_volumes;636 Trace("Volume Index is %d\n", _volIndex);634 if (_volDataID < 0) { 635 _volDataID = NanoVis::generate_data_identifier(); 636 Trace("VolumeDataID is %d\n", _volDataID); 637 637 } 638 638 Volume *volPtr; 639 volPtr = NanoVis::load_volume(_vol Index, _dataPtr->xNum(),639 volPtr = NanoVis::load_volume(_volDataID, _dataPtr->xNum(), 640 640 _dataPtr->yNum(), _dataPtr->zNum(), 4, data, 641 641 NanoVis::magMin, NanoVis::magMax, 0); … … 650 650 volPtr->setPhysicalBBox(physicalMin, physicalMax); 651 651 652 volPtr->set_n_slice(256 - _volIndex);652 //volPtr->set_n_slice(256 - _volIndex); 653 653 // volPtr->set_n_slice(512- _volIndex); 654 // TBD.. 655 volPtr->set_n_slice(256); 654 656 volPtr->disable_cutplane(0); 655 657 volPtr->disable_cutplane(1); -
trunk/packages/vizservers/nanovis/FlowCmd.h
r1474 r1475 169 169 * flow. This isn't the same thing as 170 170 * a normal volume displayed. */ 171 int _vol Index; /* The index of slot in the volume171 int _volDataID; /* The index of slot in the volume 172 172 * vector. -1 indicates that a slot 173 173 * hasn't been previously allocated. -
trunk/packages/vizservers/nanovis/R2/include/R2/R2Object.h
r580 r1475 37 37 --_referenceCount; 38 38 } 39 delete this; 39 40 if (_referenceCount <= 0) delete this; 40 41 } 41 42 -
trunk/packages/vizservers/nanovis/TransferFunction.cpp
r973 r1475 51 51 TransferFunction::update(int size, float *data) 52 52 { 53 assert((size*4) == _size); 53 // TBD.. 54 //assert((size*4) == _size); 54 55 update(data); 55 56 } -
trunk/packages/vizservers/nanovis/TransferFunction.h
r973 r1475 20 20 21 21 #include "Texture1D.h" 22 #include <R2/R2Object.h> 22 23 23 24 24 class TransferFunction {25 class TransferFunction : public R2Object { 25 26 int _size; //the resolution of the color map, how many 26 27 //(RGBA) quadraples … … 28 29 Texture1D* _tex; //the texture storing the colors 29 30 31 protected : 32 ~TransferFunction(); 30 33 public: 31 34 GLuint id; //OpenGL's texture identifier 32 35 33 36 TransferFunction(int size, float *data); 34 ~TransferFunction();35 37 void update(float *data); 36 38 void update(int size, float *data); … … 41 43 return _data; 42 44 } 45 int getSize() const; 43 46 }; 44 47 48 inline int TransferFunction::getSize() const 49 { 50 return _size; 51 } 45 52 #endif -
trunk/packages/vizservers/nanovis/Volume.cpp
r1474 r1475 46 46 iso_surface(0) 47 47 { 48 _volumeDataID = -1; 49 48 50 tex = new Texture3D(w, h, d, NVIS_FLOAT, NVIS_LINEAR_INTERP, n); 49 51 int fcount = width * height * depth * n_components; -
trunk/packages/vizservers/nanovis/Volume.h
r1474 r1475 25 25 #include "Vector3.h" 26 26 #include "AxisRange.h" 27 #include "R2/R2Object.h" 27 28 28 29 struct CutPlane{ … … 39 40 enum {CUBIC, VOLQD, ZINCBLENDE}; 40 41 41 class Volume {42 class Volume : public R2Object { 42 43 public: 44 int _volumeDataID; 45 43 46 int width; // The resolution of the data (how many points 44 47 // in each direction. … … 103 106 int iso_surface; 104 107 108 public : 105 109 Volume(float x, float y, float z, int width, int height, int depth, 106 110 float size, int n_component, float* data, double vmin, double vmax, 107 111 double nonzero_min); 108 112 109 113 protected : 110 114 ~Volume(); 111 115 116 public : 112 117 void visible(bool value) { 113 118 enabled = value; … … 183 188 Vector3& getPhysicalBBoxMin(); 184 189 Vector3& getPhysicalBBoxMax(); 190 191 void setDataID(int id); 192 int getDataID() const; 185 193 }; 186 194 … … 314 322 } 315 323 324 inline void 325 Volume::setDataID(int id) 326 { 327 _volumeDataID = id; 328 } 329 330 inline int 331 Volume::getDataID() const 332 { 333 return _volumeDataID; 334 } 335 316 336 #endif -
trunk/packages/vizservers/nanovis/VolumeInterpolator.cpp
r1474 r1475 120 120 _volumes.clear(); 121 121 122 if (_volume) delete _volume;122 if (_volume) _volume->unref(); 123 123 } 124 124 -
trunk/packages/vizservers/nanovis/VolumeRenderer.cpp
r1474 r1475 29 29 30 30 VolumeRenderer::VolumeRenderer(): 31 n_volumes(0),32 31 slice_mode(false), 33 32 volume_mode(true) 34 33 { 35 volume.clear(); 36 tf.clear(); 34 volumes.clear(); 37 35 38 36 init_shaders(); … … 50 48 VolumeRenderer::~VolumeRenderer() 51 49 { 50 remove_all_volumes(); 51 52 52 delete _zincBlendeShader; 53 53 delete _regularVolumeShader; … … 76 76 } 77 77 78 79 int 80 VolumeRenderer::add_volume(Volume* _vol, TransferFunction* _tf) 81 { 82 volume.push_back(_vol); 83 tf.push_back(_tf); 84 85 int ret = n_volumes; 86 n_volumes++; 87 return ret; 78 void 79 VolumeRenderer::remove_all_volumes() 80 { 81 vector<VolumeData*>::iterator iter; 82 for (iter = volumes.begin(); iter != volumes.end(); ++iter) 83 { 84 delete (*iter); 85 } 86 volumes.clear(); 87 } 88 89 void 90 VolumeRenderer::add_volume(Volume* vol, TransferFunction* tf) 91 { 92 VolumeData * volData = new VolumeData(vol, tf); 93 volumes.push_back(volData); 94 printf("volume[%d] added\n", volData->volume->getDataID()); 88 95 } 89 96 … … 99 106 */ 100 107 void 101 VolumeRenderer::remove_volume(size_t volIndex) 102 { 103 vector<Volume *>::iterator vIter; 104 vector<TransferFunction *>::iterator tfIter; 105 106 assert(volIndex < volume.size()); 107 assert(volIndex < tf.size()); 108 109 vIter = volume.begin(); 110 tfIter = tf.begin(); 111 size_t i; 112 for (i = 0; i < volIndex; i++) { 113 tfIter++; 114 vIter++; 115 } 116 volume.erase(vIter); 117 tf.erase(tfIter); 118 n_volumes--; 108 VolumeRenderer::remove_volume(size_t volDataID) 109 { 110 std::vector<VolumeData*>::iterator iter; 111 for (iter = volumes.begin(); iter != volumes.end(); ++iter) 112 { 113 if ((*iter)->volume->getDataID() == volDataID) 114 { 115 delete (*iter); 116 volumes.erase(iter); 117 break; 118 } 119 } 119 120 } 120 121 … … 122 123 VolumeRenderer::shade_volume(Volume* _vol, TransferFunction* _tf) 123 124 { 124 for (unsigned int i=0; i < volume.size(); i++) { 125 if (volume[i] == _vol) { 126 tf[i] = _tf; 127 } 128 } 129 } 125 if (_vol == 0) printf("shade volume : null vol parameter\n"); 126 for (unsigned int i=0; i < volumes.size(); i++) { 127 if (volumes[i]->volume == _vol) { 128 if (_tf != volumes[i]->tf) 129 { 130 _tf->ref(); 131 132 if (volumes[i]->tf) 133 volumes[i]->tf->unref(); 134 135 volumes[i]->tf = _tf; 136 printf("transfer function changed [volid %d]\n", volumes[i]->volume->getDataID()); 137 } 138 } 139 } 140 } 141 130 142 131 143 TransferFunction* 132 144 VolumeRenderer::get_volume_shading(Volume* _vol) 133 145 { 134 for (unsigned int i=0; i < volume .size(); i++) {135 if (volume [i]== _vol) {136 return tf[i];146 for (unsigned int i=0; i < volumes.size(); i++) { 147 if (volumes[i]->volume == _vol) { 148 return volumes[i]->tf; 137 149 } 138 150 } 139 151 return NULL; 140 152 } 153 141 154 142 155 struct SortElement { … … 193 206 TransferFunction* ani_tf = 0; 194 207 int total_rendered_slices = 0; 195 int num_volumes = n_volumes;208 int num_volumes = volumes.size(); 196 209 197 210 if (_volumeInterpolator->is_started()) { 198 211 ++num_volumes; 199 ani_tf = tf[_volumeInterpolator->getReferenceVolumeID()];212 ani_tf = volumes[_volumeInterpolator->getReferenceVolumeID()]->tf; 200 213 ani_vol = _volumeInterpolator->getVolume(); 201 214 } … … 206 219 int* actual_slices = new int[num_volumes]; 207 220 208 for(int vol_index = 0; vol_index< num_volumes; vol_index++) { 221 222 Volume* vol; 223 int vol_index = 0; 224 std::vector<VolumeData*>::iterator iter; 225 for (iter = volumes.begin(); iter != volumes.end(); ++iter, ++vol_index) { 209 226 cur_vol = NULL; 210 227 cur_tf = NULL; 211 228 #ifdef notdef 212 229 if (vol_index != n_volumes) { 213 cur_vol = volume[vol_index];214 cur_tf = tf[vol_index];230 cur_vol = (*iter)->volume; 231 cur_tf = (*iter)->tf; 215 232 } else { 216 233 cur_vol = ani_vol; … … 218 235 } 219 236 #else 220 cur_vol = volume[vol_index];221 cur_tf = tf[vol_index];237 cur_vol = (*iter)->volume; 238 cur_tf = (*iter)->tf; 222 239 #endif 223 240 … … 226 243 227 244 if(!cur_vol->visible()) { 245 //printf("volume [%d] skipped\n", cur_vol->getDataID()); 228 246 continue; //skip this volume 229 247 } … … 474 492 ConvexPolygon* cur = polys[volume_index][slice_index]; 475 493 494 #ifdef notdef 476 495 if (volume_index == n_volumes) { 477 496 cur_vol = ani_vol; 478 497 cur_tf = ani_tf; 479 498 } else { 480 cur_vol = volume [volume_index];481 cur_tf = tf[volume_index];499 cur_vol = volumes[volume_index]->volume; 500 cur_tf = volumes[volume_index]->tf; 482 501 } 502 #else 503 cur_vol = volumes[volume_index]->volume; 504 cur_tf = volumes[volume_index]->tf; 505 #endif 483 506 484 507 … … 516 539 } 517 540 518 void VolumeRenderer::render(int volume_index) 519 { 520 int n_slices = volume[volume_index]->get_n_slice(); 541 void VolumeRenderer::render(int volDataID) 542 { 543 Volume* vol = 0; 544 TransferFunction* tf = 0; 545 std::vector<VolumeData*>::iterator iter; 546 for (iter = volumes.begin(); iter != volumes.end(); ++iter) 547 { 548 if ((*iter)->volume && ((*iter)->volume->getDataID() == volDataID)) 549 { 550 vol = (*iter)->volume; 551 tf = (*iter)->tf; 552 break; 553 } 554 } 555 556 if (vol == 0) return; 557 558 int n_slices = vol->get_n_slice(); 521 559 522 560 //volume start location 523 Vector4 shift_4d(vol ume[volume_index]->location.x,524 vol ume[volume_index]->location.y,525 vol ume[volume_index]->location.z, 0);561 Vector4 shift_4d(vol->location.x, 562 vol->location.y, 563 vol->location.z, 0); 526 564 527 565 double x0 = 0; … … 545 583 glPushMatrix(); 546 584 547 glScalef(vol ume[volume_index]->aspect_ratio_width,548 vol ume[volume_index]->aspect_ratio_height,549 vol ume[volume_index]->aspect_ratio_depth);585 glScalef(vol->aspect_ratio_width, 586 vol->aspect_ratio_height, 587 vol->aspect_ratio_depth); 550 588 551 589 glEnable(GL_DEPTH_TEST); … … 562 600 glPushMatrix(); 563 601 glTranslatef(shift_4d.x, shift_4d.y, shift_4d.z); 564 glScalef(vol ume[volume_index]->aspect_ratio_width,565 vol ume[volume_index]->aspect_ratio_height,566 vol ume[volume_index]->aspect_ratio_depth);602 glScalef(vol->aspect_ratio_width, 603 vol->aspect_ratio_height, 604 vol->aspect_ratio_depth); 567 605 GLfloat mv_trans[16]; 568 606 glGetFloatv(GL_MODELVIEW_MATRIX, mv_trans); … … 572 610 573 611 //draw volume bounding box 574 if (vol ume[volume_index]->outline()) {612 if (vol->outline()) { 575 613 draw_bounding_box(x0, y0, z0, x0+1, y0+1, z0+1, 0.8, 0.1, 0.1, 1.5); 576 614 } … … 605 643 606 644 //render the cut planes 607 for(int i=0; i<vol ume[volume_index]->get_cutplane_count(); i++){608 float offset = vol ume[volume_index]->get_cutplane(i)->offset;609 int axis = vol ume[volume_index]->get_cutplane(i)->orient;645 for(int i=0; i<vol->get_cutplane_count(); i++){ 646 float offset = vol->get_cutplane(i)->offset; 647 int axis = vol->get_cutplane(i)->orient; 610 648 611 649 if (axis==1) { … … 651 689 652 690 glPushMatrix(); 653 glScalef(vol ume[volume_index]->aspect_ratio_width, volume[volume_index]->aspect_ratio_height, volume[volume_index]->aspect_ratio_depth);654 655 activate_volume_shader(vol ume[volume_index], tf[volume_index], true);691 glScalef(vol->aspect_ratio_width, vol->aspect_ratio_height, vol->aspect_ratio_depth); 692 693 activate_volume_shader(vol, tf, true); 656 694 glPopMatrix(); 657 695 … … 699 737 700 738 glPushMatrix(); 701 glScalef(vol ume[volume_index]->aspect_ratio_width, volume[volume_index]->aspect_ratio_height, volume[volume_index]->aspect_ratio_depth);739 glScalef(vol->aspect_ratio_width, vol->aspect_ratio_height, vol->aspect_ratio_depth); 702 740 703 741 /* … … 713 751 */ 714 752 715 activate_volume_shader(vol ume[volume_index], tf[volume_index], true);753 activate_volume_shader(vol, tf, true); 716 754 glPopMatrix(); 717 755 … … 919 957 void VolumeRenderer::switch_volume_mode() { volume_mode = (!volume_mode); } 920 958 921 void VolumeRenderer::enable_volume(int index){ 922 volume[index]->visible(true); 923 } 924 925 void VolumeRenderer::disable_volume(int index){ 926 volume[index]->visible(false); 959 void VolumeRenderer::enable_volume(int volDataID) 960 { 961 printf("enable volume [%d]\n", volDataID); 962 std::vector<VolumeData*>::iterator iter; 963 for (iter = volumes.begin(); iter != volumes.end(); ++iter) 964 { 965 if ((*iter)->volume && ((*iter)->volume->getDataID() == volDataID)) 966 { 967 (*iter)->volume->visible(true); 968 printf("volume [%d] is visible\n", volDataID); 969 } 970 } 971 } 972 973 void VolumeRenderer::disable_volume(int volDataID) 974 { 975 printf("disable volume [%d]\n", volDataID); 976 std::vector<VolumeData*>::iterator iter; 977 for (iter = volumes.begin(); iter != volumes.end(); ++iter) 978 { 979 if ((*iter)->volume && ((*iter)->volume->getDataID() == volDataID)) 980 { 981 (*iter)->volume->visible(false); 982 printf("volume [%d] is visible\n", volDataID); 983 } 984 } 927 985 } 928 986 -
trunk/packages/vizservers/nanovis/VolumeRenderer.h
r1474 r1475 39 39 #include "VolumeInterpolator.h" 40 40 41 class VolumeData { 42 friend class VolumeRenderer; 43 friend class NanoVis; 44 private : 45 Volume* volume; 46 TransferFunction* tf; 47 public : 48 VolumeData() : volume(0), tf(0) {} 49 VolumeData(Volume* vol, TransferFunction* t) : volume(vol), tf(t) 50 { 51 if (volume) volume->ref(); 52 if (tf) tf->ref(); 53 } 54 ~VolumeData() 55 { 56 if (volume) volume->unref(); 57 if (tf) tf->unref(); 58 } 59 }; 60 41 61 class VolumeRenderer { 42 62 friend class NanoVis; 43 63 private: 44 std::vector <Volume*> volume; //!<- array of volumes 45 std::vector <TransferFunction*> tf; //!<- array of corresponding transfer functions 64 std::vector<VolumeData*> volumes; //!<- array of volumes 46 65 VolumeInterpolator* _volumeInterpolator; 47 48 int n_volumes;49 66 50 67 bool slice_mode; //!<- enable cut planes … … 105 122 ~VolumeRenderer(); 106 123 107 int add_volume(Volume* _vol, TransferFunction* _tf); 108 void remove_volume(size_t volIndex); 124 void add_volume(Volume* _vol, TransferFunction* _tf); 125 void remove_all_volumes(); 126 void remove_volume(size_t volDataID); 109 127 // add a volume and its transfer function 110 128 // we require a transfer function when a … … 113 131 TransferFunction* get_volume_shading(Volume* _vol); 114 132 115 void render(int volume _index);133 void render(int volumeID); 116 134 void render_all(); //render all enabled volumes; 117 135 void render_all_points(void); //render all enabled volumes; … … 122 140 void switch_slice_mode(); //switch_cutplane_mode 123 141 void switch_volume_mode(); 124 void enable_volume(int index); //enable a volume125 void disable_volume(int index); //disable a volume142 void enable_volume(int volumeDataID); //enable a volume 143 void disable_volume(int volumeDataID); //disable a volume 126 144 127 145 void clearAnimatedVolumeInfo(void) { -
trunk/packages/vizservers/nanovis/dxReader.cpp
r1474 r1475 48 48 */ 49 49 bool 50 load_volume_stream2(Rappture::Outcome &result, int index, std::iostream& fin)50 load_volume_stream2(Rappture::Outcome &result, int volDataID, std::iostream& fin) 51 51 { 52 52 printf("load_volume_stream2\n"); … … 174 174 return false; 175 175 } 176 Volume *volPtr = 0; 176 177 if (isrect) { 177 178 double dval[6]; … … 246 247 dz = nz; 247 248 248 Volume *volPtr; 249 volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data, 249 volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data, 250 250 vmin, vmax, nzero_min); 251 251 volPtr->xAxis.SetRange(x0, x0 + (nx * dx)); … … 387 387 } 388 388 389 Volume *volPtr; 390 volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data, 389 volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data, 391 390 field.valueMin(), field.valueMax(), nzero_min); 392 391 volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis), … … 406 405 float dy0 = -0.5*dy/dx; 407 406 float dz0 = -0.5*dz/dx; 408 NanoVis::volume[index]->move(Vector3(dx0, dy0, dz0)); 407 if (volPtr) volPtr->move(Vector3(dx0, dy0, dz0)); 408 printf("volume moved\n"); 409 409 return true; 410 410 } 411 411 412 412 bool 413 load_volume_stream(Rappture::Outcome &result, int index, std::iostream& fin)413 load_volume_stream(Rappture::Outcome &result, int volDataID, std::iostream& fin) 414 414 { 415 415 printf("load_volume_stream\n"); … … 527 527 return false; 528 528 } 529 Volume *volPtr = 0; 529 530 if (isrect) { 530 531 Rappture::Mesh1D xgrid(x0, x0+nx*dx, nx); … … 650 651 } 651 652 #endif 652 fprintf(stdout,"End Data Stats index = %i\n",index);653 fprintf(stdout,"End Data Stats DataID = %i\n",volDataID); 653 654 fprintf(stdout,"nx = %i ny = %i nz = %i\n",nx,ny,nz); 654 655 fprintf(stdout,"dx = %lg dy = %lg dz = %lg\n",dx,dy,dz); … … 656 657 fflush(stdout); 657 658 658 Volume *volPtr; 659 volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data, 659 volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data, 660 660 field.valueMin(), field.valueMax(), nzero_min); 661 661 volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis), … … 802 802 } 803 803 804 Volume *volPtr; 805 volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data, 804 volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data, 806 805 field.valueMin(), field.valueMax(), nzero_min); 807 806 volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis), … … 834 833 float dy0 = -0.5*dy/dx; 835 834 float dz0 = -0.5*dz/dx; 836 NanoVis::volume[index]->move(Vector3(dx0, dy0, dz0));835 if (volPtr) volPtr->move(Vector3(dx0, dy0, dz0)); 837 836 return true; 838 837 } … … 840 839 841 840 bool 842 load_volume_stream_insoo(Rappture::Outcome &result, int index,841 load_volume_stream_insoo(Rappture::Outcome &result, int volDataID, 843 842 std::iostream& fin) 844 843 { … … 958 957 } 959 958 959 Volume* volPtr = 0; 960 960 if (isrect) { 961 961 Rappture::Mesh1D xgrid(x0, x0+nx*dx, nx); … … 1121 1121 } 1122 1122 1123 fprintf(stdout,"End Data Stats index = %i\n",index);1123 fprintf(stdout,"End Data Stats volDataID = %i\n",volDataID); 1124 1124 fprintf(stdout,"nx = %i ny = %i nz = %i\n",nx,ny,nz); 1125 1125 fprintf(stdout,"dx = %lg dy = %lg dz = %lg\n",dx,dy,dz); … … 1128 1128 */ 1129 1129 1130 Volume *volPtr; 1131 volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data, 1130 volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data, 1132 1131 field.valueMin(), field.valueMax(), nzero_min); 1133 1132 volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis), … … 1276 1275 } 1277 1276 1278 Volume *volPtr; 1279 volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data, 1277 volPtr = NanoVis::load_volume(volDataID, nx, ny, nz, 4, data, 1280 1278 field.valueMin(), field.valueMax(), nzero_min); 1281 1279 volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis), … … 1308 1306 float dy0 = -0.5*dy/dx; 1309 1307 float dz0 = -0.5*dz/dx; 1310 NanoVis::volume[index]->move(Vector3(dx0, dy0, dz0));1308 if (volPtr) volPtr->move(Vector3(dx0, dy0, dz0)); 1311 1309 return true; 1312 1310 } -
trunk/packages/vizservers/nanovis/dxReader2.cpp
r1382 r1475 17 17 */ 18 18 bool 19 load_volume_stream_odx(Rappture::Outcome &context, int index, const char *buf,19 load_volume_stream_odx(Rappture::Outcome &context, int userID, const char *buf, 20 20 int nBytes) 21 21 { … … 88 88 computeSimpleGradient(data, nx, ny, nz); 89 89 90 fprintf(stdout,"End Data Stats index = %i\n",index);90 fprintf(stdout,"End Data Stats userID = %i\n",userID); 91 91 fprintf(stdout,"nx = %i ny = %i nz = %i\n",nx,ny,nz); 92 92 fprintf(stdout,"dx = %lg dy = %lg dz = %lg\n",dx,dy,dz); … … 95 95 96 96 Volume *volPtr; 97 volPtr = NanoVis::load_volume( index, nx, ny, nz, 4, data,97 volPtr = NanoVis::load_volume(userID, nx, ny, nz, 4, data, 98 98 dxObj.dataMin(), 99 99 dxObj.dataMax(), … … 116 116 float dy0 = -0.5*dy/dx; 117 117 float dz0 = -0.5*dz/dx; 118 NanoVis::volume[index]->move(Vector3(dx0, dy0, dz0));118 volPtr->move(Vector3(dx0, dy0, dz0)); 119 119 return true; 120 120 } -
trunk/packages/vizservers/nanovis/nanovis.cpp
r1474 r1475 106 106 int NanoVis::updir = Y_POS; 107 107 NvCamera* NanoVis::cam = NULL; 108 int NanoVis::n_volumes = 0;109 vector<Volume*> NanoVis::volume;108 NanoVis::VolumeMap NanoVis::volumeMap; 109 int NanoVis::_last_data_id = 0; 110 110 vector<HeightMap*> NanoVis::heightMap; 111 111 VolumeRenderer* NanoVis::vol_renderer = 0; … … 514 514 */ 515 515 Volume * 516 NanoVis::load_volume(int index, int width, int height, int depth,516 NanoVis::load_volume(int volDataID, int width, int height, int depth, 517 517 int n_component, float* data, double vmin, 518 518 double vmax, double nzero_min) 519 519 { 520 while (n_volumes <= index) { 521 volume.push_back(NULL); 522 n_volumes++; 523 } 524 525 Volume* vol = volume[index]; 526 if (vol != NULL) { 527 volume[index] = NULL; 528 529 if (vol->pointsetIndex != -1) { 530 if (((unsigned int) vol->pointsetIndex) < pointSet.size() && 531 pointSet[vol->pointsetIndex] != NULL) { 532 delete pointSet[vol->pointsetIndex]; 533 pointSet[vol->pointsetIndex] = 0; 520 NanoVis::VolumeMap::iterator iter = volumeMap.find(volDataID); 521 if (iter != volumeMap.end()) 522 { 523 Volume* vol = iter->second; 524 if (vol != NULL) 525 { 526 iter->second = NULL; 527 528 if (vol->pointsetIndex != -1) 529 { 530 // TBD 531 /* 532 if (((unsigned int) vol->pointsetIndex) < pointSet.size() && 533 pointSet[vol->pointsetIndex] != NULL) { 534 delete pointSet[vol->pointsetIndex]; 535 pointSet[vol->pointsetIndex] = 0; 536 } 537 */ 534 538 } 535 539 } 536 delete vol; 537 } 538 volume[index] = new Volume(0.f, 0.f, 0.f, width, height, depth, 1., 540 vol->unref(); 541 } 542 543 Volume* newVol = new Volume(0.f, 0.f, 0.f, width, height, depth, 1., 539 544 n_component, data, vmin, vmax, nzero_min); 540 fprintf(stderr, "VOLINDEX=%d, n_volumes=%d\n", index, n_volumes); 541 return volume[index]; 545 newVol->setDataID(volDataID); 546 volumeMap[volDataID] = newVol; 547 548 549 fprintf(stderr, "VOLID=%d, # of volumes=%d\n", volDataID, volumeMap.size()); 550 return newVol; 542 551 } 543 552 … … 1538 1547 xMin = yMin = zMin = wMin = DBL_MAX; 1539 1548 xMax = yMax = zMax = wMax = -DBL_MAX; 1540 for (unsigned int i = 0; i < volume.size(); i++) { 1541 Volume *volPtr; 1542 1543 volPtr = volume[i]; 1549 NanoVis::VolumeMap::iterator iter; 1550 for (iter = volumeMap.begin(); iter != volumeMap.end(); ++iter) 1551 { 1552 Volume *volPtr = iter->second; 1553 1544 1554 if (volPtr == NULL) { 1545 1555 continue; … … 2546 2556 return TCL_OK; 2547 2557 } 2558 2559 int NanoVis::generate_data_identifier() 2560 { 2561 return _last_data_id++; 2562 } 2563 2564 void NanoVis::remove_volume(int volDataID) 2565 { 2566 2567 NanoVis::VolumeMap::iterator iter = volumeMap.find(volDataID); 2568 if (iter != volumeMap.end()) 2569 { 2570 (*iter).second->unref(); 2571 volumeMap.erase(iter); 2572 } 2573 } -
trunk/packages/vizservers/nanovis/nanovis.h
r1431 r1475 109 109 static NVISid final_fbo, final_color_tex, final_depth_rb; 110 110 public: 111 typedef std::map<int, Volume*> VolumeMap; 112 public: 111 113 static VolumeRenderer* vol_renderer; 112 114 static PointSetRenderer* pointset_renderer; … … 128 130 static vector<HeightMap*> heightMap; 129 131 static unsigned char* screen_buffer; 130 static vector<Volume*> volume;132 static VolumeMap volumeMap; 131 133 static vector<NvVectorField*> flow; 132 134 static Grid* grid; … … 152 154 static Tcl_DString cmdbuffer; 153 155 156 static int _last_data_id; 157 public : 154 158 static TransferFunction* get_transfunc(const char *name); 155 159 static TransferFunction* DefineTransferFunction(const char *name, … … 179 183 static int render_legend(TransferFunction *tf, double min, double max, 180 184 int width, int height, const char* volArg); 181 static Volume *load_volume(int index, int width, int height, int depth,185 static Volume *load_volume(int volDataID, int width, int height, int depth, 182 186 int n, float* data, double vmin, double vmax, double nzero_min); 183 187 static void xinetd_listen(void); … … 228 232 }; 229 233 static void EventuallyRedraw(unsigned int flag = 0); 234 static void remove_volume(int volUserID); 235 static int generate_data_identifier(); 230 236 }; 231 237
Note: See TracChangeset
for help on using the changeset viewer.