Changeset 1429
- Timestamp:
- May 11, 2009, 4:39:13 PM (16 years ago)
- Location:
- trunk/packages/vizservers/nanovis
- Files:
-
- 2 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/Command.cpp
r1382 r1429 141 141 static Tcl_ObjCmdProc CameraCmd; 142 142 static Tcl_ObjCmdProc CutplaneCmd; 143 static Tcl_ObjCmdProc FlowCmd;143 extern Tcl_AppInitProc FlowCmdInitProc; 144 144 static Tcl_ObjCmdProc GridCmd; 145 145 static Tcl_ObjCmdProc LegendCmd; … … 1725 1725 // ========================= VOLUME END ================================== 1726 1726 1727 #ifdef notdef 1727 1728 // ============================= FLOW ================================== 1728 1729 … … 1957 1958 return TCL_ERROR; 1958 1959 } 1959 NanoVis::lic_on = state;1960 /* NanoVis::lic_on = state; */ 1960 1961 return TCL_OK; 1961 1962 } … … 1973 1974 return TCL_ERROR; 1974 1975 } 1976 #ifdef notdef 1975 1977 switch (axis) { 1976 1978 case 0 : … … 1984 1986 break; 1985 1987 } 1988 #endif 1986 1989 return TCL_OK; 1987 1990 } … … 2053 2056 } 2054 2057 2055 NanoVis::particle_on = state;2058 /* NanoVis::particle_on = state; */ 2056 2059 return TCL_OK; 2057 2060 } … … 2199 2202 2200 2203 // ============================ FLOW END ================================== 2204 #endif 2201 2205 2202 2206 static int … … 2832 2836 Tcl_Interp *interp; 2833 2837 interp = Tcl_CreateInterp(); 2838 /* 2834 2839 Tcl_MakeSafe(interp); 2835 2840 */ 2836 2841 Tcl_CreateObjCommand(interp, "axis", AxisCmd, NULL, NULL); 2837 2842 Tcl_CreateObjCommand(interp, "camera", CameraCmd, NULL, NULL); 2838 2843 Tcl_CreateObjCommand(interp, "cutplane", CutplaneCmd, NULL, NULL); 2839 Tcl_CreateObjCommand(interp, "flow", FlowCmd, NULL, NULL); 2844 if (FlowCmdInitProc(interp) != TCL_OK) { 2845 return NULL; 2846 } 2840 2847 Tcl_CreateObjCommand(interp, "grid", GridCmd, NULL, NULL); 2841 2848 Tcl_CreateObjCommand(interp, "heightmap", HeightMapCmd, NULL, NULL); -
trunk/packages/vizservers/nanovis/FlowCmds.cpp
r1380 r1429 42 42 #include <assert.h> 43 43 #include <stdlib.h> 44 #include <tcl.h> 44 #include <stddef.h> 45 /*#include <tcl.h>*/ 46 #include "Vector4.h" 45 47 #include "Switch.h" 48 #include "Unirect.h" 49 #include "FlowCmd.h" 50 46 51 #include <RpField1D.h> 47 52 #include <RpFieldRect3D.h> … … 70 75 #include "RenderContext.h" 71 76 #include "NvLIC.h" 72 #include "Unirect.h"73 #include "FlowCmd.h"74 77 75 78 static Tcl_HashTable flowTable; 76 79 77 static int 78 GetFlowFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, FlowCmd **flowPtrPtr) 79 { 80 Tcl_HashEntry *hPtr; 81 hPtr = Tcl_FindHashEntry(&flowTable, Tcl_GetString(objPtr)); 82 if (hPtr == NULL) { 83 if (interp != NULL) { 84 Tcl_AppendResult(interp, "can't find a flow \"", 85 Tcl_GetString(objPtr), "\"", (char *)NULL); 86 } 87 return TCL_ERROR; 88 } 89 *flowPtrPtr = (FlowCmd *)Tcl_GetHashValue(hPtr); 90 return TCL_OK; 91 } 80 extern bool load_vector_stream2(Rappture::Outcome &result, int index, 81 size_t length, Rappture::Unirect3d *dataPtr); 82 83 /* 84 physicalMin.set(dataPtr->xMin(), dataPtr->yMin(), dataPtr->zMin()); 85 physicalMax.set(dataPtr->xMax(), dataPtr->yMax(), dataPtr->zMax()); 86 */ 87 static float * 88 MakeFlowVector(Rappture::Unirect3d *dataPtr, double minMag, double maxMag) 89 { 90 float *data = new float[4* dataPtr->nValues()]; 91 if (data == NULL) { 92 return NULLL; 93 } 94 memset(data, 0, sizeof(float) * 4 * dataPtr->nValues()); 95 float *destPtr = data; 96 float *srcPtr = dataPtr->values(); 97 for (size_t iz=0; iz < dataPtr->zNum(); iz++) { 98 for (size_t iy=0; iy < dataPtr->yNum(); iy++) { 99 for (size_t ix=0; ix < dataPtr->xNum(); ix++) { 100 double vx, vy, vz, vm; 101 vx = values[0]; 102 vy = values[1]; 103 vz = values[2]; 104 vm = sqrt(vx*vx + vy*vy + vz*vz); 105 destPtr[0] = vm / maxMag; 106 destPtr[1] = vx /(2.0*maxMag) + 0.5; 107 destPtr[2] = vy /(2.0*maxMag) + 0.5; 108 destPtr[3] = vz /(2.0*maxMag) + 0.5; 109 srcPtr += 3; 110 destPtr += 4; 111 } 112 } 113 } 114 return data; 115 } 116 117 static Volume * 118 MakeFlowVolume(Rappture::Unirect3d *dataPtr, double minMag, double maxMag, 119 float *data) 120 { 121 Volume *volPtr; 122 123 ivol = NanoVis::n_volumes; 124 volPtr = NanoVis::load_volume(ivol, dataPtr->xNum(), dataPtr->yNum(), 125 dataPtr->zNum(), 4, data, minMag, maxMag, 0); 126 volPtr->xAxis.SetRange(dataPtr->xMin(), dataPtr->xMax()); 127 volPtr->yAxis.SetRange(dataPtr->yMin(), dataPtr->yMax()); 128 volPtr->zAxis.SetRange(dataPtr->zMin(), dataPtr->zMax()); 129 volPtr->wAxis.SetRange(minMag, maxMag); 130 volPtr->update_pending = true; 131 volPtr->setPhysicalBBox(physicalMin, physicalMax); 132 // 133 // BE CAREFUL: Set the number of slices to something 134 // slightly different for each volume. If we have 135 // identical volumes at exactly the same position 136 // with exactly the same number of slices, the second 137 // volume will overwrite the first, so the first won't 138 // appear at all. 139 // 140 volPtr->set_n_slice(256-n); 141 // volPtr->set_n_slice(512-n); 142 volPtr->disable_cutplane(0); 143 volPtr->disable_cutplane(1); 144 volPtr->disable_cutplane(2); 145 146 NanoVis::vol_renderer->add_volume(volPtr, 147 NanoVis::get_transfunc("default")); 148 149 float dx0 = -0.5; 150 float dy0 = -0.5*volPtr->height/volPtr->width; 151 float dz0 = -0.5*volPtr->depth/volPtr->width; 152 volPtr->move(Vector3(dx0, dy0, dz0)); 153 return volPtr; 154 } 155 92 156 93 157 static int … … 95 159 Tcl_Obj *const *objv) 96 160 { 97 Rappture::Outcome context;161 Rappture::Outcome result; 98 162 99 163 const char *fileName; … … 106 170 } 107 171 Rappture::Buffer buf; 108 if (!buf.load( context, fileName)) {172 if (!buf.load(result, fileName)) { 109 173 Tcl_AppendResult(interp, "can't load data from \"", fileName, "\": ", 110 context.remark(), (char *)NULL);174 result.remark(), (char *)NULL); 111 175 return TCL_ERROR; 112 176 } … … 114 178 FlowCmd *flowPtr = (FlowCmd *)clientData; 115 179 if (strncmp(buf.bytes(), "<DX>", 4) == 0) { 116 Rappture::Unirect3d data; 117 if (!load_vector_stream2(context, buf.size(), (char *)buf.bytes(), 118 data)) { 119 Tcl_AppendResult(interp, context.remark(), (char *)NULL); 180 Rappture::Unirect3d *dataPtr; 181 182 dataPtr = new Rappture::Unirect3d(); 183 if (!dataPtr->ReadVectorDataFromDx(result, buf.size(), 184 (char *)buf.bytes())) { 185 Tcl_AppendResult(interp, result.remark(), (char *)NULL); 186 delete dataPtr; 120 187 return TCL_ERROR; 121 188 } 122 flowPtr->dataPtr = &data;189 flowPtr->dataPtr = dataPtr; 123 190 } else if (strncmp(buf.bytes(), "<unirect3d>", 4) == 0) { 124 Rappture::Unirect3d data;191 Rappture::Unirect3d *dataPtr; 125 192 Tcl_CmdInfo cmdInfo; 126 193 … … 130 197 return TCL_ERROR; 131 198 } 132 data.extents(extents); 133 cmdInfo.objClientData = (ClientData)&data; 199 dataPtr = new Rappture::Unirect3d(); 200 dataPtr->extents(extents); 201 cmdInfo.objClientData = (ClientData)dataPtr; 134 202 Tcl_SetCommandInfo(interp, "unirect3d", &cmdInfo); 135 203 if (Tcl_Eval(interp, (const char *)buf.bytes()) != TCL_OK) { 204 delete dataPtr; 136 205 return TCL_ERROR; 137 206 } 138 if (!data.isInitialized()) { 207 if (!dataPtr->isInitialized()) { 208 delete dataPtr; 139 209 return TCL_ERROR; 140 210 } 141 flowPtr->dataPtr = &data;211 flowPtr->dataPtr = dataPtr; 142 212 } 143 213 … … 174 244 Tcl_Obj *const *objv) 175 245 { 176 Rappture::Outcome context;246 Rappture::Outcome result; 177 247 178 248 Trace("Flow Data Loading\n"); … … 192 262 FlowCmd *flowPtr = (FlowCmd *)clientData; 193 263 if (strncmp(buf.bytes(), "<DX>", 4) == 0) { 194 if (!load_vector_stream2(context, buf.size(), (char *)buf.bytes(), 195 flowPtr)) { 196 Tcl_AppendResult(interp, context.remark(), (char *)NULL); 264 Rappture::Unirect3d *dataPtr; 265 266 dataPtr = new Rappture::Unirect3d(); 267 if (!dataPtr->ReadVectorDataFromDx(result, buf.size(), 268 (char *)buf.bytes())) { 269 Tcl_AppendResult(interp, result.remark(), (char *)NULL); 270 delete dataPtr; 197 271 return TCL_ERROR; 198 272 } 273 flowPtr->dataPtr = dataPtr; 199 274 } else if (strncmp(buf.bytes(), "<unirect3d>", 4) == 0) { 200 Rappture::Unirect3d data;275 Rappture::Unirect3d *dataPtr; 201 276 Tcl_CmdInfo cmdInfo; 202 277 203 278 /* Set the clientdata field of the unirect3d command to contain 204 279 * the local data structure. */ 280 dataPtr = new Rappture::Unirect3d(); 205 281 if (!Tcl_GetCommandInfo(interp, "unirect3d", &cmdInfo)) { 206 282 return TCL_ERROR; 207 283 } 208 data .extents(extents);209 cmdInfo.objClientData = (ClientData) &data;284 dataPtr->extents(extents); 285 cmdInfo.objClientData = (ClientData)dataPtr; 210 286 Tcl_SetCommandInfo(interp, "unirect3d", &cmdInfo); 211 287 if (Tcl_Eval(interp, (const char *)buf.bytes()) != TCL_OK) { 288 delete dataPtr; 212 289 return TCL_ERROR; 213 290 } 214 if (!data.isInitialized()) { 291 if (!dataPtr->isInitialized()) { 292 delete dataPtr; 215 293 return TCL_ERROR; 216 294 } 217 if (!SetVectorFieldDataFromUnirect3d(context, data, flowPtr)) { 218 Tcl_AppendResult(interp, context.remark(), (char *)NULL); 219 return TCL_ERROR; 220 } 221 } 222 if (flowPtr->volPtr != NULL) { 223 delete flowPtr->volPtr; 224 } 225 #ifdef notdef 295 flowPtr->dataPtr = dataPtr; 296 } 297 #ifdef notdef 226 298 // FIXME: Move this to flow pending routine. 227 299 … … 249 321 float dz0 = -0.5*flowPtr->volPtr->depth/flowPtr->volPtr->width; 250 322 flowPtr->volPtr->move(Vector3(dx0, dy0, dz0)); 251 323 #endif 252 324 return TCL_OK; 253 325 } … … 273 345 } 274 346 275 347 /* 348 * Can configure axis of stream plane, the position on the axis, and if 349 * the stream plane is visible. 350 * 351 */ 276 352 static Rappture::SwitchSpec streamSwitches[] = 277 353 { … … 284 360 285 361 static int 286 FlowS treamConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc,362 FlowSliceConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc, 287 363 Tcl_Obj *const *objv) 288 364 { … … 295 371 streamPtr = flowPtr->streams + axis; 296 372 297 if ( Rappture::ParseSwitches(interp, streamSwitches, objc - 3, objv + 3,373 if (flowPtr->ParseRappture::ParseSwitches(interp, streamSwitches, objc - 3, objv + 3, 298 374 streamPtr, SWITCH_DEFAULTS) < 0) { 299 375 return TCL_ERROR; 300 376 } 377 // Save the values in the stream 378 streamPtr->axis; 301 379 NanoVis::lic_slice_x = streamPtr->position; 302 380 NanoVis::licRenderer->set_axis(axis); … … 324 402 return (*proc) (clientData, interp, objc, objv); 325 403 } 326 327 static int328 FlowParticlesVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc,329 Tcl_Obj *const *objv)330 {331 bool state;332 if (GetBooleanFromObj(interp, objv[3], &state) != TCL_OK) {333 return TCL_ERROR;334 }335 336 NanoVis::particle_on = state;337 return TCL_OK;338 }339 340 static Rappture::CmdSpec flowParticlesOps[] = {341 {"visible", 1, FlowParticlesVisibleOp, 4, 4, "on|off",},342 };343 static int nFlowParticlesOps = NumCmdSpecs(flowParticlesOps);344 345 static int346 FlowParticlesOp(ClientData clientData, Tcl_Interp *interp, int objc,347 Tcl_Obj *const *objv)348 {349 Tcl_ObjCmdProc *proc;350 351 proc = Rappture::GetOpFromObj(interp, nFlowParticlesOps, flowParticlesOps,352 Rappture::CMDSPEC_ARG2, objc, objv, 0);353 if (proc == NULL) {354 return TCL_ERROR;355 }356 return (*proc) (clientData, interp, objc, objv);357 }358 359 404 360 405 static int … … 387 432 } 388 433 389 static Rappture::SwitchSpec flowSwitches[] = 390 { 391 {Rappture::SWITCH_BOOLEAN, "-lic", "boolean", 392 offsetof(FlowCmd, lic), 0}, 434 static Rappture::SwitchSpec streamSwitches[] = 435 { 393 436 {Rappture::SWITCH_BOOLEAN, "-hide", "boolean", 394 offsetof(FlowCmd, hidden), 0}, 437 offsetof(Stream, hidden), 0}, 438 {Rappture::SWITCH_FLOAT, "-position", "number", 439 offsetof(Stream, position), 0}, 395 440 {Rappture::SWITCH_END} 396 441 }; 397 442 443 static Rappture::SwitchParseProc AxisSwitchProc; 444 445 static Rappture:;SwitchCustom axisSwitch = { 446 AxisSwitchProc, NULL, 0, 447 }; 448 449 /* 450 *--------------------------------------------------------------------------- 451 * 452 * AxisSwitch -- 453 * 454 * Convert a Tcl_Obj representing the label of a child node into its 455 * integer node id. 456 * 457 * Results: 458 * The return value is a standard Tcl result. 459 * 460 *--------------------------------------------------------------------------- 461 */ 462 /*ARGSUSED*/ 463 static int 464 AxisSwitch( 465 ClientData clientData, /* Flag indicating if the node is considered 466 * before or after the insertion position. */ 467 Tcl_Interp *interp, /* Interpreter to send results back to */ 468 const char *switchName, /* Not used. */ 469 Tcl_Obj *objPtr, /* String representation */ 470 char *record, /* Structure record */ 471 int offset, /* Not used. */ 472 int flags) /* Not used. */ 473 { 474 const char *string = Tcl_GetString(objPtr); 475 if (string[1] == '\0') { 476 FlowCmd::SliceAxis *axisPtr = (FlowCmd::SliceAxis *)(record + offset); 477 char c; 478 c = tolower((unsigned char)string[0]); 479 if (c == 'x') { 480 *axisPtr = FlowCmd::SliceAxis::AXIS_X; 481 return TCL_OK; 482 } else if (c == 'y') { 483 *axisPtr = FlowCmd::SliceAxis::AXIS_Y; 484 return TCL_OK; 485 } else if (c == 'z') { 486 *axisPtr = FlowCmd::SliceAxis::AXIS_Z; 487 return TCL_OK; 488 } 489 /*FALLTHRU*/ 490 } 491 Tcl_AppendResult(interp, "bad axis \"", string, 492 "\": should be x, y, or z", (char*)NULL); 493 return TCL_ERROR; 494 } 495 398 496 static int 399 497 FlowConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc, 400 498 Tcl_Obj *const *objv) 401 499 { 402 int axis;403 if (GetAxisFromObj(interp, objv[3], &axis) != TCL_OK) { 404 return TCL_ERROR;405 } 406 FlowCmd *flowPtr = (FlowCmd *)clientData;407 if (Rappture::ParseSwitches(interp, flowSwitches, objc - 3, objv + 3,408 flowPtr, SWITCH_DEFAULTS) < 0) { 409 return TCL_ERROR;410 }500 FlowCmd *flowPtr = (FlowCmd *)clientData; 501 502 if (flowPtr->ParseSwitches(interp, objc - 3, objv + 3) != TCL_OK) { 503 return TCL_ERROR; 504 } 505 flowPtr->SetAxis(); 506 flowPtr->SetSlicePosition(); 507 flowPtr->SliceVisible(); 508 flowPtr->Visible(); 411 509 return TCL_OK; 412 510 } … … 421 519 }; 422 520 423 static int 424 FlowInjectorAddOp(ClientData clientData, Tcl_Interp *interp, int objc, 425 Tcl_Obj *const *objv) 521 522 static int 523 FlowParticlesAddOp(ClientData clientData, Tcl_Interp *interp, int objc, 524 Tcl_Obj *const *objv) 525 { 526 FlowCmd *flowPtr = (FlowCmd *)clientData; 527 528 if (flowPtr->CreatePlane(interp, objv[3])) { 529 return TCL_ERROR; 530 } 531 Particles *particlesPtr; 532 if (flowPtr->GetPlane(interp, objv[3], &particlesPtr) != TCL_OK) { 533 return TCL_ERROR; 534 } 535 if (particlesPtr->ParseSwitches(interp, objc - 4, objv + 4) != TCL_OK) { 536 flowPtr->DestroyPlane(particlesPtr); 537 return TCL_ERROR; 538 } 539 particlesPtr->SetPosition(); 540 particlesPtr->SetColor(); 541 particlesPtr->SetAxis(); 542 particlesPtr->Visible(); 543 return TCL_OK; 544 } 545 546 static int 547 FlowParticlesConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc, 548 Tcl_Obj *const *objv) 549 { 550 FlowCmd *flowPtr = (FlowCmd *)clientData; 551 552 Particles *particlesPtr; 553 if (flowPtr->GetPlane(interp, objv[3], &particlesPtr) != TCL_OK) { 554 return TCL_ERROR; 555 } 556 if (particlesPtr->ParseSwitches(interp, objc - 4, objv + 4) != TCL_OK) { 557 return TCL_ERROR; 558 } 559 particlesPtr->SetPosition(); 560 particlesPtr->SetColor(); 561 particlesPtr->SetAxis(); 562 particlesPtr->Visible(); 563 return TCL_OK; 564 } 565 566 static int 567 FlowParticlesDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc, 568 Tcl_Obj *const *objv) 569 { 570 FlowCmd *flowPtr = (FlowCmd *)clientData; 571 int i; 572 for (i = 3; i < objc; i++) { 573 Particles *particlesPtr; 574 575 if (flowPtr->GetPlane(interp, objv[i], &particlesPtr)!=TCL_OK) { 576 return TCL_ERROR; 577 } 578 flowPtr->DestroyPlane(particlesPtr); 579 } 580 return TCL_OK; 581 } 582 583 static int 584 FlowParticlesNamesOp(ClientData clientData, Tcl_Interp *interp, int objc, 585 Tcl_Obj *const *objv) 586 { 587 FlowCmd *flowPtr = (FlowCmd *)clientData; 588 Tcl_Obj *listObjPtr; 589 listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL); 590 ParticlesIterator iter; 591 Particles *particlesPtr; 592 for (particlesPtr = flowPtr->FirstPlane(&iter); particlesPtr != NULL; 593 particlesPtr = flowPtr->NextPlane(&iter)) { 594 595 objPtr = Tcl_NewStringObj(particlesPtr->Name(), -1); 596 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr); 597 } 598 Tcl_SetObjResult(interp, listObjPtr); 599 return TCL_OK; 600 } 601 602 /* 603 *--------------------------------------------------------------------------- 604 * 605 * FlowParticlesObjCmd -- 606 * 607 * This procedure is invoked to process commands on behalf of the flow 608 * object. 609 * 610 * Results: 611 * A standard Tcl result. 612 * 613 * Side effects: 614 * See the user documentation. 615 * 616 * $flow particles oper $name 617 *--------------------------------------------------------------------------- 618 */ 619 static Rappture::CmdSpec flowParticlesOps[] = { 620 {"add", 1, FlowParticlesAddOp, 3, 0, "name ?switches?",}, 621 {"configure", 1, FlowParticlesConfigureOp, 3, 0, "name ?switches?",}, 622 {"delete", 1, FlowParticlesDeleteOp, 3, 0, "?name...?"}, 623 {"names", 1, FlowParticlesNamesOp, 3, 4, "?pattern?"}, 624 }; 625 626 static int nFlowInjectorOps = NumCmdSpecs(flowInjectorOps); 627 628 static int 629 FlowInjectorOp(ClientData clientData, Tcl_Interp *interp, int objc, 630 Tcl_Obj *const *objv) 631 { 632 Tcl_ObjCmdProc *proc; 633 proc = Rappture::GetOpFromObj(interp, nFlowInjectorOps, flowInjectorOps, 634 Rappture::CMDSPEC_ARG1, objc, objv, 0); 635 if (proc == NULL) { 636 return TCL_ERROR; 637 } 638 FlowCmd *flowPtr = (FlowCmd *)clientData; 639 Tcl_Preserve(flowPtr); 640 int result; 641 result = (*proc) (clientData, interp, objc, objv); 642 Tcl_Release(flowPtr); 643 return result; 644 } 645 646 static int 647 FlowShapeAddOp(ClientData clientData, Tcl_Interp *interp, int objc, 648 Tcl_Obj *const *objv) 426 649 { 427 650 FlowCmd *flowPtr = (FlowCmd *)clientData; … … 456 679 457 680 static int 458 Flow InjectorDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,681 FlowShapeDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc, 459 682 Tcl_Obj *const *objv) 460 683 { … … 476 699 477 700 static int 478 Flow InjectorNamesOp(ClientData clientData, Tcl_Interp *interp, int objc,701 FlowShapeNamesOp(ClientData clientData, Tcl_Interp *interp, int objc, 479 702 Tcl_Obj *const *objv) 480 703 { … … 483 706 Tcl_HashSearch iter; 484 707 Tcl_Obj *listObjPtr; 708 485 709 listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL); 486 710 for (hPtr = Tcl_FirstHashEntry(&flowPtr->injectTable, &iter); … … 498 722 499 723 static int 500 Flow InjectorConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc,724 FlowShapeConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc, 501 725 Tcl_Obj *const *objv) 502 726 { … … 519 743 } 520 744 521 522 /* 523 *--------------------------------------------------------------------------- 524 * 525 * FlowInjectorObjCmd -- 745 /* 746 *--------------------------------------------------------------------------- 747 * 748 * FlowShapeOp-- 526 749 * 527 750 * This procedure is invoked to process commands on behalf of the flow … … 536 759 *--------------------------------------------------------------------------- 537 760 */ 538 static Rappture::CmdSpec flow InjectorOps[] = {539 {"add", 1, Flow InjectorAddOp, 3, 0, "name ?switches?",},540 {"configure", 1, Flow InjectorConfigureOp, 3, 5, "name ?switches?",},541 {"delete", 1, Flow InjectorDeleteOp, 3, 0, "?name...?"},542 {"names", 1, Flow InjectorNamesOp, 3, 4, "?pattern?"},761 static Rappture::CmdSpec flowShapeOps[] = { 762 {"add", 1, FlowShapeAddOp, 3, 0, "name ?switches?",}, 763 {"configure", 1, FlowShapeConfigureOp, 3, 5, "name ?switches?",}, 764 {"delete", 1, FlowShapeDeleteOp, 3, 0, "?name...?"}, 765 {"names", 1, FlowShapeNamesOp, 3, 4, "?pattern?"}, 543 766 }; 544 767 545 static int nFlow InjectorOps = NumCmdSpecs(flowInjectorOps);546 547 static int 548 Flow InjectorOp(ClientData clientData, Tcl_Interp *interp, int objc,768 static int nFlowShapeOps = NumCmdSpecs(flowShapeOps); 769 770 static int 771 FlowShapeOp(ClientData clientData, Tcl_Interp *interp, int objc, 549 772 Tcl_Obj *const *objv) 550 773 { 551 774 Tcl_ObjCmdProc *proc; 552 proc = Rappture::GetOpFromObj(interp, nFlow InjectorOps, flowInjectorOps,775 proc = Rappture::GetOpFromObj(interp, nFlowShapeOps, flowShapeOps, 553 776 Rappture::CMDSPEC_ARG1, objc, objv, 0); 554 777 if (proc == NULL) { … … 566 789 *--------------------------------------------------------------------------- 567 790 * 568 * Flow ShapeOp--791 * FlowInstObjCmd -- 569 792 * 570 793 * This procedure is invoked to process commands on behalf of the flow … … 579 802 *--------------------------------------------------------------------------- 580 803 */ 581 static Rappture::CmdSpec flow ShapeOps[] = {582 {" add", 1, FlowInjectorAddOp, 3, 0, "name?switches?",},583 {" configure", 1, FlowInjectorConfigureOp, 3, 5, "name ?switches?",},584 {" delete", 1, FlowInjectorDeleteOp, 3, 0, "?name...?"},585 {" names", 1, FlowInjectorNamesOp, 3, 4, "?pattern?"},804 static Rappture::CmdSpec flowInstOps[] = { 805 {"configure", 1, FlowConfigureOp, 3, 5, "?switches?",}, 806 {"data", 1, FlowDataOp, 4, 0, "oper ?args?"}, 807 {"particles", 1, FlowParticlesOp, 3, 0, "oper ?args?",}, 808 {"shape", 2, FlowShapeOp, 3, 0, "oper ?args?",}, 586 809 }; 587 588 static int nFlowShapeOps = NumCmdSpecs(flowShapeOps); 589 590 static int 591 FlowShapeOp(ClientData clientData, Tcl_Interp *interp, int objc, 810 static int nFlowInstOps = NumCmdSpecs(flowInstOps); 811 812 static int 813 FlowInstObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, 592 814 Tcl_Obj *const *objv) 593 815 { 594 816 Tcl_ObjCmdProc *proc; 595 proc = Rappture::GetOpFromObj(interp, nFlow ShapeOps, flowShapeOps,817 proc = Rappture::GetOpFromObj(interp, nFlowInstOps, flowInstOps, 596 818 Rappture::CMDSPEC_ARG1, objc, objv, 0); 597 819 if (proc == NULL) { … … 609 831 *--------------------------------------------------------------------------- 610 832 * 611 * FlowInstObjCmd --612 *613 * This procedure is invoked to process commands on behalf of the flow614 * object.615 *616 * Results:617 * A standard Tcl result.618 *619 * Side effects:620 * See the user documentation.621 *622 *---------------------------------------------------------------------------623 */624 static Rappture::CmdSpec flowInstOps[] = {625 {"configure", 1, FlowConfigureOp, 3, 5, "?switches?",},626 {"data", 1, FlowDataOp, 4, 0, "oper ?args?"},627 {"injector", 1, FlowInjectorOp, 3, 0, "oper ?args?",},628 {"particles", 1, FlowParticlesOp, 3, 0, "oper ?args?",},629 {"shape", 2, FlowShapeOp, 3, 0, "oper ?args?",},630 {"stream", 2, FlowStreamOp, 4, 0, "oper axis ?args?",},631 };632 static int nFlowInstOps = NumCmdSpecs(flowInstOps);633 634 static int635 FlowInstObjCmd(ClientData clientData, Tcl_Interp *interp, int objc,636 Tcl_Obj *const *objv)637 {638 Tcl_ObjCmdProc *proc;639 proc = Rappture::GetOpFromObj(interp, nFlowInstOps, flowInstOps,640 Rappture::CMDSPEC_ARG1, objc, objv, 0);641 if (proc == NULL) {642 return TCL_ERROR;643 }644 FlowCmd *flowPtr = (FlowCmd *)clientData;645 Tcl_Preserve(flowPtr);646 int result;647 result = (*proc) (clientData, interp, objc, objv);648 Tcl_Release(flowPtr);649 return result;650 }651 652 /*653 *---------------------------------------------------------------------------654 *655 833 * FlowInstDeleteProc -- 656 834 * … … 667 845 { 668 846 FlowCmd *flowPtr = (FlowCmd *)clientData; 669 670 if (flowPtr->hashPtr != NULL) {671 Tcl_DeleteHashEntry(flowPtr->hashPtr);672 }673 847 delete flowPtr; 674 848 } … … 686 860 Tcl_Obj *const *objv) 687 861 { 688 const char *name; 689 name = Tcl_GetString(objv[2]); 690 691 Tcl_HashEntry *hPtr; 692 int isNew; 693 hPtr = Tcl_CreateHashEntry(&flowTable, name, &isNew); 694 if (!isNew) { 695 Tcl_AppendResult(interp, "flow \"", name, "\" already exists.", 696 (char *)NULL); 697 return TCL_ERROR; 698 } 699 Tcl_CmdInfo cmdInfo; 700 if (Tcl_GetCommandInfo(interp, name, &cmdInfo)) { 701 Tcl_AppendResult(interp, "an another command \"", name, 702 "\" already exists.", (char *)NULL); 703 return TCL_ERROR; 704 } 705 FlowCmd *flowPtr; 706 flowPtr = new FlowCmd; 707 if (flowPtr == NULL) { 708 Tcl_AppendResult(interp, "can't allocate a flow object \"", name, 709 "\"", (char *)NULL); 710 return TCL_ERROR; 711 } 712 flowPtr->hashPtr = hPtr; 713 flowPtr->name = Tcl_GetHashKey(&flowTable, hPtr); 714 flowPtr->cmdToken = Tcl_CreateObjCommand(interp, (char *)name, 715 (Tcl_ObjCmdProc *)FlowInstObjCmd, flowPtr, FlowInstDeleteProc); 716 Tcl_SetHashValue(hPtr, flowPtr); 717 flowPtr->volPtr = NULL; 718 return TCL_OK; 862 return FlowCmd::NewFlow(interp, Tcl_GetString(objv[2])); 719 863 } 720 864 … … 736 880 FlowCmd *flowPtr; 737 881 738 if ( GetFlowFromObj(interp, objv[i], &flowPtr) != TCL_OK) {882 if (FlowCmd::GetFlowFromObj(interp, objv[i], &flowPtr) != TCL_OK) { 739 883 return TCL_ERROR; 740 884 } 741 Tcl_DeleteCommandFromToken(interp, flowPtr->cmdToken);742 #ifdef notdef743 NanoVis::flowVisRenderer->removeVectorField(flowPtr);744 #endif745 885 delete flowPtr; 746 886 } … … 890 1030 891 1031 // Generate the latest frame and send it back to the client 892 if (NanoVis::licRenderer->isActivated()) { 893 NanoVis::licRenderer->convolve(); 894 } 895 NanoVis::flowVisRenderer->advect(); 1032 NanoVis::licRenderer->convolve(); 1033 FlowCmd::AdvectFlows(); 896 1034 NanoVis::offscreen_buffer_capture(); //enable offscreen render 897 1035 NanoVis::display(); … … 943 1081 return TCL_ERROR; 944 1082 } 945 946 if (NanoVis::licRenderer) { 947 NanoVis::licRenderer->activate(); 948 } 949 if (NanoVis::flowVisRenderer) { 950 NanoVis::flowVisRenderer->activate(); 951 } 1083 if (NanoVis::licRenderer == NULL) { 1084 Tcl_AppendResult(interp, "no lic renderer.", (char *)NULL); 1085 return TCL_ERROR; 1086 } 1087 if (NanoVis::flowVisRenderer == NULL) { 1088 Tcl_AppendResult(interp, "no flow renderer.", (char *)NULL); 1089 return TCL_ERROR; 1090 } 1091 NanoVis::licRenderer->activate(); 1092 NanoVis::flowVisRenderer->activate(); 952 1093 953 1094 // Save the old dimensions of the offscreen buffer. … … 966 1107 Trace("FLOW started\n"); 967 1108 968 Rappture::Outcome context;1109 Rappture::Outcome result; 969 1110 Rappture::AVTranslate movie(width, height, frameRate, bitRate); 970 1111 … … 974 1115 } 975 1116 976 movie.init( context, fileName);1117 movie.init(result, fileName); 977 1118 978 1119 for (int i = 0; i < numFrames; i++) { 979 1120 // Generate the latest frame and send it back to the client 980 if (NanoVis::licRenderer && 981 NanoVis::licRenderer->isActivated()) { 982 NanoVis::licRenderer->convolve(); 983 } 984 if (NanoVis::flowVisRenderer && 985 NanoVis::flowVisRenderer->isActivated()) { 986 NanoVis::flowVisRenderer->advect(); 987 } 1121 NanoVis::licRenderer->convolve(); 1122 FlowCmd::AdvectFlows(); 988 1123 NanoVis::offscreen_buffer_capture(); //enable offscreen render 989 1124 NanoVis::display(); … … 994 1129 // This is done before bmp_write_to_file because bmp_write_to_file 995 1130 // turns rgb data to bgr 996 movie.append( context, NanoVis::screen_buffer, pad);1131 movie.append(result, NanoVis::screen_buffer, pad); 997 1132 // NanoVis::bmp_write_to_file(frame_count, fileName); 998 1133 } 999 1134 1000 movie.done( context);1135 movie.done(result); 1001 1136 Trace("FLOW end\n"); 1002 1137 … … 1011 1146 // FIXME: find a way to get the data from the movie object as a void* 1012 1147 Rappture::Buffer data; 1013 if (!data.load( context, fileName)) {1148 if (!data.load(result, fileName)) { 1014 1149 Tcl_AppendResult(interp, "can't load data from temporary movie file \"", 1015 fileName, "\": ", context.remark(), (char *)NULL);1150 fileName, "\": ", result.remark(), (char *)NULL); 1016 1151 return TCL_ERROR; 1017 1152 } … … 1088 1223 } 1089 1224 1090 #ifdef notdef1091 void1092 MapFlowVectors(Tcl_Interp *interp)1093 {1094 double xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax;1095 1096 if (debug_flag) {1097 fprintf(stderr, "in SetHeightmapRanges\n");1098 }1099 xMin = yMin = zMin = wMin = DBL_MAX;1100 xMax = yMax = zMax = wMax = -DBL_MAX;1101 Tcl_HashEntry *hPtr;1102 Tcl_HashSearch iter;1103 for (hPtr = Tcl_FirstHashEntry(&flowTable, &iter); hPtr != NULL;1104 hPtr = Tcl_NextHashEntry(&iter)) {1105 FlowCmd *flowPtr;1106 flowPtr = (FlowCmd *)Tcl_GetHashValue(hPtr);1107 1108 flowPtr->1109 1110 for (unsigned int i = 0; i < heightMap.size(); i++) {1111 HeightMap *hmPtr;1112 1113 hmPtr = heightMap[i];1114 if (hmPtr == NULL) {1115 continue;1116 }1117 if (xMin > hmPtr->xAxis.min()) {1118 xMin = hmPtr->xAxis.min();1119 }1120 if (xMax < hmPtr->xAxis.max()) {1121 xMax = hmPtr->xAxis.max();1122 }1123 if (yMin > hmPtr->yAxis.min()) {1124 yMin = hmPtr->yAxis.min();1125 }1126 if (yMax < hmPtr->yAxis.max()) {1127 yMax = hmPtr->yAxis.max();1128 }1129 if (zMin > hmPtr->zAxis.min()) {1130 zMin = hmPtr->zAxis.min();1131 }1132 if (zMax < hmPtr->zAxis.max()) {1133 zMax = hmPtr->zAxis.max();1134 }1135 if (wMin > hmPtr->wAxis.min()) {1136 wMin = hmPtr->wAxis.min();1137 }1138 if (wMax < hmPtr->wAxis.max()) {1139 wMax = hmPtr->wAxis.max();1140 }1141 }1142 if ((xMin < DBL_MAX) && (xMax > -DBL_MAX)) {1143 grid->xAxis.SetScale(xMin, xMax);1144 }1145 if ((yMin < DBL_MAX) && (yMax > -DBL_MAX)) {1146 grid->yAxis.SetScale(yMin, yMax);1147 }1148 if ((zMin < DBL_MAX) && (zMax > -DBL_MAX)) {1149 grid->zAxis.SetScale(zMin, zMax);1150 }1151 if ((wMin < DBL_MAX) && (wMax > -DBL_MAX)) {1152 HeightMap::valueMin = grid->yAxis.min();1153 HeightMap::valueMax = grid->yAxis.max();1154 }1155 for (unsigned int i = 0; i < heightMap.size(); i++) {1156 HeightMap *hmPtr;1157 1158 hmPtr = heightMap[i];1159 if (hmPtr == NULL) {1160 continue;1161 }1162 hmPtr->MapToGrid(grid);1163 }1164 HeightMap::update_pending = false;1165 if (debug_flag) {1166 fprintf(stderr, "leaving SetHeightmapRanges\n");1167 }1168 }1169 1170 Tcl_Obj *listObjPtr;1171 listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);1172 1173 Tcl_HashEntry *hPtr;1174 Tcl_HashSearch iter;1175 for (hPtr = Tcl_FirstHashEntry(&flowTable, &iter); hPtr != NULL;1176 hPtr = Tcl_NextHashEntry(&iter)) {1177 FlowCmd *flowPtr;1178 flowPtr = (FlowCmd *)Tcl_GetHashValue(hPtr);1179 if (flowPtr->fieldPtr != NULL) {1180 delete flowPtr->fieldPtr; // Remove the vector field.1181 flowPtr->fieldPtr = NULL;1182 }1183 }1184 1185 1186 Volume *volPtr;1187 volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data,1188 field.valueMin(), field.valueMax(), nzero_min);1189 volPtr->xAxis.SetRange(field.rangeMin(Rappture::xaxis),1190 field.rangeMax(Rappture::xaxis));1191 volPtr->yAxis.SetRange(field.rangeMin(Rappture::yaxis),1192 field.rangeMax(Rappture::yaxis));1193 volPtr->zAxis.SetRange(field.rangeMin(Rappture::zaxis),1194 field.rangeMax(Rappture::zaxis));1195 volPtr->wAxis.SetRange(field.valueMin(), field.valueMax());1196 volPtr->update_pending = true;1197 delete [] data;1198 #endif -
trunk/packages/vizservers/nanovis/LoadVector.cpp
r1380 r1429 12 12 #include "FlowCmd.h" 13 13 14 static INLINE char * 15 skipspaces(char *string) 14 15 16 bool 17 ScaleVectorFieldData(Rappture::Outcome &context, Rappture::Unirect3d *dataPtr) 16 18 { 17 while (isspace(*string)) { 18 string++; 19 } 20 return string; 21 } 22 23 static INLINE char * 24 getline(char **stringPtr, char *endPtr) 25 { 26 char *line, *p; 27 28 line = skipspaces(*stringPtr); 29 for (p = line; p < endPtr; p++) { 30 if (*p == '\n') { 31 *p++ = '\0'; 32 *stringPtr = p; 33 return line; 34 } 35 } 36 *stringPtr = p; 37 return line; 38 } 39 40 bool 41 SetVectorFieldData(Rappture::Outcome &context, 42 float xMin, float xMax, size_t xNum, 43 float yMin, float yMax, size_t yNum, 44 float zMin, float zMax, size_t zNum, 45 size_t nValues, float *values, Unirect3d *dataPtr) 46 { 19 float *values = dataPtr->values(); 20 float *nValues = dataPtr->nValues(); 47 21 #ifdef notdef 48 22 double max_x = -1e21, min_x = 1e21; … … 74 48 xNum, yNum, zNum, xNum * yNum * zNum); 75 49 76 // Generate the uniformly sampled rectangle that we need for a volume77 50 float *destPtr = data; 78 51 float *srcPtr = values; … … 97 70 } 98 71 } 99 dataPtr->xMin(xMin); 100 dataPtr->xMax(xMax); 101 dataPtr->xNum(xNum); 102 dataPtr->yMin(yMin); 103 dataPtr->yMax(yMax); 72 dataPtr->SetValues(xMin, xMax, xNum, yMin, yMax(yMax); 104 73 dataPtr->yNum(yNum); 105 74 dataPtr->yMin(zMin); … … 113 82 114 83 bool 115 SetResampledVectorFieldData(Rappture::Outcome &context, 116 float xMin, float xMax, size_t xNum, 117 float yMin, float yMax, size_t yNum, 118 float zMin, float zMax, size_t zNum, 119 size_t nValues, float *values, FlowCmd *flowPtr) 84 ScaleResampledVectorFieldData(Rappture::Outcome &context, 85 Rappture::Unirect3d *dataPtr) 120 86 { 121 Rappture::Mesh1D xgrid( xMin, xMax, xNum);122 Rappture::Mesh1D ygrid( yMin, yMax, yNum);123 Rappture::Mesh1D zgrid( zMin, zMax, zNum);87 Rappture::Mesh1D xgrid(dataPtr->xMin(), dataPtr->xMax(), dataPtr->xNum()); 88 Rappture::Mesh1D ygrid(dataPtr->yMin(), dataPtr->yMax(), dataPtr->yNum()); 89 Rappture::Mesh1D zgrid(dataPtr->zMin(), dataPtr->zMax(), dataPtr->zNum()); 124 90 Rappture::FieldRect3D xfield(xgrid, ygrid, zgrid); 125 91 Rappture::FieldRect3D yfield(xgrid, ygrid, zgrid); … … 135 101 max_mag = -1e21, nzero_min = min_mag = 1e21; 136 102 size_t i, j; 137 for (i = j = 0; i < nValues; i += 3, j++) {103 for (i = j = 0; i < dataPtr->nValues(); i += 3, j++) { 138 104 double vx, vy, vz, vm; 139 105 140 vx = values[i];141 vy = values[i+1];142 vz = values[i+2];106 vx = dataPtr->values[i]; 107 vy = dataPtr->values[i+1]; 108 vz = dataPtr->values[i+2]; 143 109 144 110 xfield.define(j, vx); … … 217 183 } 218 184 } 219 185 dataPtr->zMin() 220 186 flowPtr->xMin = xMin; 221 187 flowPtr->xMax = xMax; … … 246 212 247 213 248 #ifdef notdef249 214 /* 250 215 * Load a 3D vector field from a dx-format file … … 371 336 } 372 337 373 #endif -
trunk/packages/vizservers/nanovis/Makefile.in
r1392 r1429 104 104 Event.o \ 105 105 Unirect.o \ 106 FlowCmd.o \ 107 FlowCmds.o \ 108 LoadVector.o \ 109 Switch.o \ 106 110 GradientFilter.o \ 107 111 Grid.o \ -
trunk/packages/vizservers/nanovis/NvFlowVisRenderer.h
r1370 r1429 44 44 void reset(); 45 45 void render(); 46 47 void addVectorField(Volume* volPtr, const Vector3& ori, float scaleX, 48 float scaleY, float scaleZ, float max); 46 49 47 50 void addVectorField(const std::string& vfName, Volume* volPtr, const Vector3& ori, float scaleX, float scaleY, float scaleZ, float max); -
trunk/packages/vizservers/nanovis/NvLIC.cpp
r1370 r1429 308 308 float x1, x2, y, px, py; 309 309 310 glPushMatrix(); 310 311 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 311 312 … … 313 314 glLoadIdentity(); 314 315 glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT); 316 317 /*glPushMatrix();*/ 315 318 glViewport(0, 0, (GLsizei) NPIX, (GLsizei) NPIX); 316 319 //glTranslatef(-1.0, -1.0, 0.0); … … 397 400 glPopMatrix(); 398 401 glMatrixMode(GL_PROJECTION); 399 glPopMatrix();402 /*glPopMatrix();*/ 400 403 glMatrixMode(GL_MODELVIEW); 401 404 } … … 488 491 489 492 void 490 NvLIC::setVectorField(unsigned int texID, const Vector3& ori, float scaleX, float scaleY,491 493 NvLIC::setVectorField(unsigned int texID, const Vector3& ori, 494 float scaleX, float scaleY, float scaleZ, float max) 492 495 { 493 496 Trace("NvLIC: vector field is assigned [%d]\n", texID); … … 531 534 NvLIC::set_offset(float v) 532 535 { 533 switch (axis) 534 { 535 case 0 : offset.x = v; break; 536 case 1 : offset.y = v; break; 537 case 2 : offset.z = v; break; 538 } 539 540 get_slice(); 536 switch (axis) { 537 case 0 : offset.x = v; break; 538 case 1 : offset.y = v; break; 539 case 2 : offset.z = v; break; 540 } 541 get_slice(); 541 542 } 542 543 -
trunk/packages/vizservers/nanovis/NvParticleRenderer.cpp
r1380 r1429 25 25 #include <stdlib.h> 26 26 27 28 27 #define NV_32 29 28 … … 51 50 m_vertex_array = new RenderVertexArray(psys_width*psys_height, 3, GL_FLOAT); 52 51 53 assert( glGetError()==0);52 assert(CheckGL(AT)); 54 53 55 54 glGenFramebuffersEXT(2, psys_fbo); … … 131 130 glDeleteFramebuffersEXT(2, psys_fbo); 132 131 132 delete m_vertex_array; 133 delete _advectionShader; 133 134 free(data); 134 135 } … … 244 245 if (reborn) 245 246 reset(); 246 247 247 248 glDisable(GL_BLEND); 248 249 glDisable(GL_DEPTH_TEST); -
trunk/packages/vizservers/nanovis/Switch.h
r1384 r1429 34 34 # include <stddef.h> 35 35 #endif /* HAVE_STDDEF_H */ 36 37 #ifdef offsetof38 #define SwitchOffset(type, field) ((int) offsetof(type, field))39 #else40 #define SwitchOffset(type, field) ((int) ((char *) &((type *) 0)->field))41 #endif42 36 43 37 namespace Rappture { -
trunk/packages/vizservers/nanovis/Trace.h
r1200 r1429 5 5 #include <GL/glut.h> 6 6 7 #define MAKE_STRING(x) #x 8 #define NEWSTRING(x) MAKE_STRING(x) 9 #define AT __FILE__ ":" NEWSTRING(__LINE__) 10 7 11 extern void Trace(const char* format, ...); 8 12 extern bool CheckFBO(GLenum *statusPtr); -
trunk/packages/vizservers/nanovis/Unirect.cpp
r1381 r1429 1 1 2 #include <float.h> 2 3 #include <tcl.h> 3 4 #include <Unirect.h> 5 #include "RpField1D.h" 6 #include "RpFieldRect3D.h" 4 7 5 8 extern int GetFloatFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, 6 9 float *valuePtr); 7 10 extern int GetAxisFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *indexPtr); 11 12 static INLINE char * 13 skipspaces(char *string) 14 { 15 while (isspace(*string)) { 16 string++; 17 } 18 return string; 19 } 20 21 static INLINE char * 22 getline(char **stringPtr, char *endPtr) 23 { 24 char *line, *p; 25 26 line = skipspaces(*stringPtr); 27 for (p = line; p < endPtr; p++) { 28 if (*p == '\n') { 29 *p++ = '\0'; 30 *stringPtr = p; 31 return line; 32 } 33 } 34 *stringPtr = p; 35 return line; 36 } 8 37 9 38 int … … 30 59 axis3 = 0; /* X-axis */ 31 60 32 int extents = 1;33 61 values = NULL; 34 62 num[0] = num[1] = num[2] = nValues = 0; … … 115 143 } 116 144 } else if ((c == 'u') && (strcmp(string, "units") == 0)) { 117 vUnits_= strdup(Tcl_GetString(objv[i+1]));145 _vUnits = strdup(Tcl_GetString(objv[i+1])); 118 146 } else if ((c == 'o') && (strcmp(string, "order") == 0)) { 119 147 Tcl_Obj **axes; … … 142 170 return TCL_ERROR; 143 171 } 144 if ( nValues != (num[0] * num[1] * num[2] * extents)) {172 if ((size_t)nValues != (num[0] * num[1] * num[2] * _nComponents)) { 145 173 Tcl_AppendResult(interp, 146 174 "wrong number of values: must be xnum*ynum*znum*extents", … … 149 177 } 150 178 151 fprintf(stderr, "generating %dx%dx%dx%d = %d points\n",152 num[0], num[1], num[2], extents, num[0]*num[1]*num[2]*extents);153 154 179 if ((axis1 != 2) || (axis2 != 1) || (axis3 != 0)) { 155 180 // Reorder the data into x, y, z where x varies fastest and so on. … … 165 190 166 191 for (x = 0; x < num[2]; x++) { 167 int i , v;192 int i; 168 193 169 194 /* Compute the index from the data's described ordering. */ 170 195 i = ((z*num[axis2]*num[axis3]) + (y*num[axis3]) + x) * 3; 171 for( v = 0; v < extents; v++) {196 for(size_t v = 0; v < _nComponents; v++) { 172 197 dp[v] = values[i+v]; 173 198 } 174 dp += extents;199 dp += _nComponents; 175 200 } 176 201 } … … 180 205 } 181 206 182 values_ = values; 183 nValues_ = nValues; 184 extents_ = extents; 207 _values = values; 208 _nValues = nValues; 185 209 if (units[3] != NULL) { 186 vUnits_= strdup(units[3]);187 } 188 xMin_= min[axis3];189 xMax_= max[axis3];190 xNum_= num[axis3];210 _vUnits = strdup(units[3]); 211 } 212 _xMin = min[axis3]; 213 _xMax = max[axis3]; 214 _xNum = num[axis3]; 191 215 if (units[axis3] != NULL) { 192 xUnits_= strdup(units[axis3]);193 } 194 yMin_= min[axis2];195 yMax_= max[axis2];196 yNum_= num[axis2];216 _xUnits = strdup(units[axis3]); 217 } 218 _yMin = min[axis2]; 219 _yMax = max[axis2]; 220 _yNum = num[axis2]; 197 221 if (units[axis2] != NULL) { 198 yUnits_= strdup(units[axis2]);199 } 200 zMin_= min[axis1];201 zMax_= max[axis1];202 zNum_= num[axis1];222 _yUnits = strdup(units[axis2]); 223 } 224 _zMin = min[axis1]; 225 _zMax = max[axis1]; 226 _zNum = num[axis1]; 203 227 if (units[axis1] != NULL) { 204 zUnits_= strdup(units[axis1]);205 } 206 initialized_= true;228 _zUnits = strdup(units[axis1]); 229 } 230 _initialized = true; 207 231 return TCL_OK; 208 232 } … … 225 249 axis[1] = 0; /* Y-axis */ 226 250 227 extents_ = 1; 228 xNum_ = yNum_ = nValues_ = 0; 229 xMin_ = yMin_ = xMax_ = yMax_ = 0.0f; 230 if (xUnits_ != NULL) { 231 free(xUnits_); 232 } 233 if (yUnits_ != NULL) { 234 free(yUnits_); 235 } 236 if (vUnits_ != NULL) { 237 free(vUnits_); 238 } 239 xUnits_ = yUnits_ = vUnits_ = NULL; 240 if (values_ != NULL) { 241 delete [] values_; 242 } 243 values_ = NULL; 251 _xNum = _yNum = _nValues = 0; 252 _xMin = _yMin = _xMax = _yMax = 0.0f; 253 if (_xUnits != NULL) { 254 free(_xUnits); 255 } 256 if (_yUnits != NULL) { 257 free(_yUnits); 258 } 259 if (_vUnits != NULL) { 260 free(_vUnits); 261 } 262 _xUnits = _yUnits = _vUnits = NULL; 263 if (_values != NULL) { 264 delete [] _values; 265 } 266 _values = NULL; 244 267 245 268 int i; … … 251 274 c = string[0]; 252 275 if ((c == 'x') && (strcmp(string, "xmin") == 0)) { 253 if (GetFloatFromObj(interp, objv[i+1], & xMin_) != TCL_OK) {276 if (GetFloatFromObj(interp, objv[i+1], &_xMin) != TCL_OK) { 254 277 return TCL_ERROR; 255 278 } 256 279 } else if ((c == 'x') && (strcmp(string, "xmax") == 0)) { 257 if (GetFloatFromObj(interp, objv[i+1], & xMax_) != TCL_OK) {280 if (GetFloatFromObj(interp, objv[i+1], &_xMax) != TCL_OK) { 258 281 return TCL_ERROR; 259 282 } … … 268 291 return TCL_ERROR; 269 292 } 270 xNum_= n;293 _xNum = n; 271 294 } else if ((c == 'x') && (strcmp(string, "xunits") == 0)) { 272 xUnits_= strdup(Tcl_GetString(objv[i+1]));295 _xUnits = strdup(Tcl_GetString(objv[i+1])); 273 296 } else if ((c == 'y') && (strcmp(string, "ymin") == 0)) { 274 if (GetFloatFromObj(interp, objv[i+1], & yMin_) != TCL_OK) {297 if (GetFloatFromObj(interp, objv[i+1], &_yMin) != TCL_OK) { 275 298 return TCL_ERROR; 276 299 } 277 300 } else if ((c == 'y') && (strcmp(string, "ymax") == 0)) { 278 if (GetFloatFromObj(interp, objv[i+1], & yMax_) != TCL_OK) {301 if (GetFloatFromObj(interp, objv[i+1], &_yMax) != TCL_OK) { 279 302 return TCL_ERROR; 280 303 } … … 289 312 return TCL_ERROR; 290 313 } 291 yNum_= n;314 _yNum = n; 292 315 } else if ((c == 'y') && (strcmp(string, "yunits") == 0)) { 293 yUnits_= strdup(Tcl_GetString(objv[i+1]));316 _yUnits = strdup(Tcl_GetString(objv[i+1])); 294 317 } else if ((c == 'v') && (strcmp(string, "values") == 0)) { 295 318 Tcl_Obj **vobj; … … 304 327 return TCL_ERROR; 305 328 } 306 nValues_= n;307 values_ = new float[nValues_];329 _nValues = n; 330 _values = new float[_nValues]; 308 331 size_t j; 309 for (j = 0; j < nValues_; j++) {310 if (GetFloatFromObj(interp, vobj[j], values_+ j)!=TCL_OK) {332 for (j = 0; j < _nValues; j++) { 333 if (GetFloatFromObj(interp, vobj[j], _values + j)!=TCL_OK) { 311 334 return TCL_ERROR; 312 335 } 313 336 } 314 337 } else if ((c == 'u') && (strcmp(string, "units") == 0)) { 315 vUnits_= strdup(Tcl_GetString(objv[i+1]));338 _vUnits = strdup(Tcl_GetString(objv[i+1])); 316 339 } else if ((c == 'e') && (strcmp(string, "extents") == 0)) { 317 340 int n; … … 325 348 return TCL_ERROR; 326 349 } 327 extents_= n;350 _nComponents = n; 328 351 } else if ((c == 'a') && (strcmp(string, "axisorder") == 0)) { 329 352 Tcl_Obj **order; … … 350 373 } 351 374 } 352 if ( values_== NULL) {375 if (_values == NULL) { 353 376 Tcl_AppendResult(interp, "missing \"values\" key", (char *)NULL); 354 377 return TCL_ERROR; 355 378 } 356 if ( nValues_ != (xNum_ * yNum_ * extents_)) {379 if (_nValues != (_xNum * _yNum * _nComponents)) { 357 380 Tcl_AppendResult(interp, 358 381 "wrong number of values: must be xnum*ynum*extents", … … 361 384 } 362 385 363 fprintf(stderr, "generating %dx%dx%d = %d points\n",364 xNum_, yNum_, extents_, xNum_ * yNum_ * extents_);365 366 386 #ifndef notdef 367 387 if ((axis[0] != 1) || (axis[1] != 0)) { … … 371 391 float *data, *dp; 372 392 373 dp = data = new float[ nValues_];374 for (y = 0; y < yNum_; y++) {393 dp = data = new float[_nValues]; 394 for (y = 0; y < _yNum; y++) { 375 395 size_t x; 376 396 377 for (x = 0; x < xNum_; x++) {397 for (x = 0; x < _xNum; x++) { 378 398 size_t i, v; 379 399 380 400 /* Compute the index from the data's described ordering. */ 381 i = (y + ( yNum_ * x)) * extents_;382 for(v = 0; v < extents_; v++) {383 dp[v] = values_[i+v];401 i = (y + (_yNum * x)) * _nComponents; 402 for(v = 0; v < _nComponents; v++) { 403 dp[v] = _values[i+v]; 384 404 } 385 dp += extents_;386 } 387 } 388 delete [] values_;389 values_= data;405 dp += _nComponents; 406 } 407 } 408 delete [] _values; 409 _values = data; 390 410 } 391 411 #endif 392 initialized_= true;412 _initialized = true; 393 413 return TCL_OK; 394 414 } 415 416 417 bool 418 Rappture::Unirect3d::ReadVectorDataFromDx(Rappture::Outcome &result, 419 size_t length, char *string) 420 { 421 size_t nx, ny, nz, npts; 422 double x0, y0, z0, dx, dy, dz, ddx, ddy, ddz; 423 char *p, *endPtr; 424 425 dx = dy = dz = 0.0; // Suppress compiler warning. 426 x0 = y0 = z0 = 0.0; // May not have an origin line. 427 for (p = string, endPtr = p + length; p < endPtr; /*empty*/) { 428 char *line; 429 430 line = getline(&p, endPtr); 431 if (line == endPtr) { 432 break; 433 } 434 if ((line[0] == '#') || (line == '\0')) { 435 continue; // Skip blank or comment lines. 436 } 437 if (sscanf(line, "object %*d class gridpositions counts %d %d %d", 438 &nx, &ny, &nz) == 3) { 439 if ((nx < 0) || (ny < 0) || (nz < 0)) { 440 result.addError("invalid grid size: x=%d, y=%d, z=%d", 441 nx, ny, nz); 442 return false; 443 } 444 } else if (sscanf(line, "origin %lg %lg %lg", &x0, &y0, &z0) == 3) { 445 // found origin 446 } else if (sscanf(line, "delta %lg %lg %lg", &ddx, &ddy, &ddz) == 3) { 447 // found one of the delta lines 448 if (ddx != 0.0) { 449 dx = ddx; 450 } else if (ddy != 0.0) { 451 dy = ddy; 452 } else if (ddz != 0.0) { 453 dz = ddz; 454 } 455 } else if (sscanf(line, "object %*d class array type %*s shape 3" 456 " rank 1 items %d data follows", &npts) == 1) { 457 printf("#points=%d\n", npts); 458 if (npts != nx*ny*nz) { 459 result.addError("inconsistent data: expected %d points" 460 " but found %d points", nx*ny*nz, npts); 461 return false; 462 } 463 break; 464 } else if (sscanf(line, "object %*d class array type %*s rank 0" 465 " times %d data follows", &npts) == 1) { 466 if (npts != nx*ny*nz) { 467 result.addError("inconsistent data: expected %d points" 468 " but found %d points", nx*ny*nz, npts); 469 return false; 470 } 471 break; 472 } 473 } 474 if (npts != nx*ny*nz) { 475 result.addError("inconsistent data: expected %d points" 476 " but found %d points", nx*ny*nz, npts); 477 return false; 478 } 479 480 _initialized = false; 481 _xValueMin = _yValueMin = _zValueMin = FLT_MAX; 482 _xValueMax = _yValueMax = _zValueMax = -FLT_MAX; 483 _xMin = x0, _yMin = y0, _zMin = z0; 484 _xNum = nx, _yNum = ny, _zNum = nz; 485 _xMax = _xMin + dx * _xNum; 486 _yMax = _yMin + dy * _yNum; 487 _zMax = _zMin + dz * _zNum; 488 if (_values != NULL) { 489 delete [] _values; 490 } 491 _values = new float[npts * _nComponents]; 492 _nValues = 0; 493 for (size_t ix = 0; ix < _xNum; ix++) { 494 for (size_t iy = 0; iy < _yNum; iy++) { 495 for (size_t iz = 0; iz < _zNum; iz++) { 496 char *line; 497 if ((p == endPtr) || (_nValues > (size_t)npts)) { 498 break; 499 } 500 line = getline(&p, endPtr); 501 if ((line[0] == '#') || (line[0] == '\0')) { 502 continue; // Skip blank or comment lines. 503 } 504 double vx, vy, vz; 505 if (sscanf(line, "%lg %lg %lg", &vx, &vy, &vz) == 3) { 506 int nindex = (iz*nx*ny + iy*nx + ix) * 3; 507 if (vx < _xValueMin) { 508 _xValueMin = vx; 509 } else if (vx > _xValueMax) { 510 _xValueMax = vx; 511 } 512 if (vy < _yValueMin) { 513 _yValueMin = vy; 514 } else if (vy > _yValueMax) { 515 _yValueMax = vy; 516 } 517 if (vz < _zValueMin) { 518 _zValueMin = vz; 519 } else if (vz > _zValueMax) { 520 _zValueMax = vz; 521 } 522 if (nindex >= (npts*3)) { 523 fprintf(stderr, "nindex=%d, npts=%d, z=%d, y=%d, x=%d\n", 524 nindex, npts, iz, iy, ix); 525 } 526 _values[nindex] = vx; 527 _values[nindex+1] = vy; 528 _values[nindex+2] = vz; 529 _nValues++; 530 } 531 } 532 } 533 } 534 // make sure that we read all of the expected points 535 if (_nValues != npts) { 536 result.addError("inconsistent data: expected %d points" 537 " but found %d points", npts, _nValues); 538 delete [] _values; 539 _values = NULL; 540 return false; 541 } 542 _nValues *= _nComponents; 543 _initialized = true; 544 return true; 545 } 546 547 548 bool 549 Rappture::Unirect3d::Resample(Rappture::Outcome &result, int nSamples) 550 { 551 Rappture::Mesh1D xgrid(_xMin, _xMax, _xNum); 552 Rappture::Mesh1D ygrid(_yMin, _yMax, _yNum); 553 Rappture::Mesh1D zgrid(_zMin, _zMax, _zNum); 554 Rappture::FieldRect3D xfield(xgrid, ygrid, zgrid); 555 Rappture::FieldRect3D yfield(xgrid, ygrid, zgrid); 556 Rappture::FieldRect3D zfield(xgrid, ygrid, zgrid); 557 558 size_t i, j; 559 for (i = 0, j = 0; i < _nValues; i += _nComponents, j++) { 560 double vx, vy, vz; 561 562 vx = _values[i]; 563 vy = _values[i+1]; 564 vz = _values[i+2]; 565 566 xfield.define(j, vx); 567 yfield.define(j, vy); 568 zfield.define(j, vz); 569 } 570 // Figure out a good mesh spacing 571 double dx, dy, dz; 572 dx = xfield.rangeMax(Rappture::xaxis) - xfield.rangeMin(Rappture::xaxis); 573 dy = xfield.rangeMax(Rappture::yaxis) - xfield.rangeMin(Rappture::yaxis); 574 dz = xfield.rangeMax(Rappture::zaxis) - xfield.rangeMin(Rappture::zaxis); 575 576 double dmin; 577 dmin = pow((dx*dy*dz)/(nSamples*nSamples*nSamples), 0.333); 578 579 printf("dx:%lf dy:%lf dz:%lf dmin:%lf\n", dx, dy, dz, dmin); 580 581 /* Recompute new number of points for each axis. */ 582 _xNum = (size_t)ceil(dx/dmin); 583 _yNum = (size_t)ceil(dy/dmin); 584 _zNum = (size_t)ceil(dz/dmin); 585 586 #ifndef NV40 587 // must be an even power of 2 for older cards 588 _xNum = (int)pow(2.0, ceil(log10((double)_xNum)/log10(2.0))); 589 _yNum = (int)pow(2.0, ceil(log10((double)_yNum)/log10(2.0))); 590 _zNum = (int)pow(2.0, ceil(log10((double)_zNum)/log10(2.0))); 591 #endif 592 593 size_t n = _nComponents * _xNum * _yNum * _zNum; 594 float *data = new float[n]; 595 memset(data, 0, sizeof(float) * n); 596 597 // Generate the uniformly sampled rectangle that we need for a volume 598 float *destPtr = data; 599 for (size_t i = 0; i < _zNum; i++) { 600 double z; 601 602 z = _zMin + (i * dmin); 603 for (size_t j = 0; j < _yNum; j++) { 604 double y; 605 606 y = _yMin + (j * dmin); 607 for (size_t k = 0; k < _xNum; k++) { 608 double x; 609 610 x = _xMin + (k * dmin); 611 destPtr[0] = xfield.value(x, y, z); 612 destPtr[1] = yfield.value(x, y, z); 613 destPtr[2] = zfield.value(x, y, z); 614 } 615 } 616 } 617 delete [] _values; 618 _values = data; 619 _nValues = _xNum * _yNum * _zNum * _nComponents; 620 return true; 621 } 622 -
trunk/packages/vizservers/nanovis/Unirect.h
r1381 r1429 7 7 8 8 class Unirect3d { 9 size_t xNum_, yNum_, zNum_; 10 size_t nValues_; 11 int extents_; 12 13 float xMin_, xMax_; 14 float yMin_, yMax_; 15 float zMin_, zMax_; 16 float vMin_, vMax_; 17 18 char *xUnits_; 19 char *yUnits_; 20 char *zUnits_; 21 char *vUnits_; 22 23 float *values_; 24 bool initialized_; 9 size_t _xNum, _yNum, _zNum; 10 size_t _nValues; 11 size_t _nComponents; 12 float _xMin, _xMax, _yMin, _yMax, _zMin, _zMax; 13 float _xValueMin, _xValueMax; 14 float _yValueMin, _yValueMax; 15 float _zValueMin, _zValueMax; 16 char *_xUnits; 17 char *_yUnits; 18 char *_zUnits; 19 char *_vUnits; 20 21 float *_values; 22 bool _initialized; 25 23 26 24 public: … … 28 26 float yMin, float yMax, size_t yNum, 29 27 float zMin, float zMax, size_t zNum, 30 size_t nValues, float *values) { 31 xMax_ = xMax; 32 xMin_ = xMin; 33 xNum_ = xNum; 34 yMax_ = yMax; 35 yMin_ = yMin; 36 yNum_ = yNum; 37 zMax_ = zMax; 38 zMin_ = zMin; 39 zNum_ = zNum; 40 nValues_ = nValues; 41 values_ = values; 42 initialized_ = true; 43 } 44 45 Unirect3d(void) { 46 values_ = NULL; 47 initialized_ = false; 48 xNum_ = yNum_ = zNum_ = 0; 49 nValues_ = 0; 50 xUnits_ = yUnits_ = zUnits_ = vUnits_ = NULL; 28 size_t nValues, float *values, size_t nComponents) 29 { 30 SetValues(xMin, xMax, xNum, yMin, yMax, yNum, zMin, zMax, zNum, 31 nValues, values, nComponents); 32 } 33 34 Unirect3d(size_t nComponents = 1) { 35 _values = NULL; 36 _initialized = false; 37 _xNum = _yNum = _zNum = 0; 38 _nValues = 0; 39 _xUnits = _yUnits = _zUnits = _vUnits = NULL; 40 _nComponents = nComponents; 51 41 } 52 42 ~Unirect3d(void) { 53 if (values_ != NULL) { 54 delete [] values_; 55 } 56 if (xUnits_ != NULL) { 57 free(xUnits_); 58 } 59 if (yUnits_ != NULL) { 60 free(yUnits_); 61 } 62 if (zUnits_ != NULL) { 63 free(zUnits_); 64 } 65 if (vUnits_ != NULL) { 66 free(vUnits_); 67 } 43 if (_values != NULL) { 44 delete [] _values; 45 } 46 if (_xUnits != NULL) { 47 free(_xUnits); 48 } 49 if (_yUnits != NULL) { 50 free(_yUnits); 51 } 52 if (_zUnits != NULL) { 53 free(_zUnits); 54 } 55 if (_vUnits != NULL) { 56 free(_vUnits); 57 } 58 } 59 void SetValues(float xMin, float xMax, size_t xNum, 60 float yMin, float yMax, size_t yNum, 61 float zMin, float zMax, size_t zNum, 62 size_t nValues, float *values, size_t nComponents) { 63 _xMax = xMax; 64 _xMin = xMin; 65 _xNum = xNum; 66 _yMax = yMax; 67 _yMin = yMin; 68 _yNum = yNum; 69 _zMax = zMax; 70 _zMin = zMin; 71 _zNum = zNum; 72 _nValues = nValues; 73 _values = values; 74 _initialized = true; 75 _nComponents = nComponents; 68 76 } 69 77 size_t xNum(void) { 70 return xNum_;78 return _xNum; 71 79 } 72 80 size_t yNum(void) { 73 return yNum_;81 return _yNum; 74 82 } 75 83 size_t zNum(void) { 76 return zNum_;84 return _zNum; 77 85 } 78 86 float xMin(void) { 79 return xMin_;87 return _xMin; 80 88 } 81 89 float yMin(void) { 82 return yMin_;90 return _yMin; 83 91 } 84 92 float zMin(void) { 85 return zMin_;93 return _zMin; 86 94 } 87 95 float xMax(void) { 88 return xMax_;96 return _xMax; 89 97 } 90 98 float yMax(void) { 91 return yMax_;99 return _yMax; 92 100 } 93 101 float zMax(void) { 94 return zMax_; 102 return _zMax; 103 } 104 float xValueMin(void) { 105 return _xValueMin; 106 } 107 float yValueMin(void) { 108 return _yValueMin; 109 } 110 float zValueMin(void) { 111 return _zValueMin; 112 } 113 float xValueMax(void) { 114 return _xValueMax; 115 } 116 float yValueMax(void) { 117 return _yValueMax; 118 } 119 float zValueMax(void) { 120 return _zValueMax; 121 } 122 size_t nComponents(void) { 123 return _nComponents; 95 124 } 96 125 const char *xUnits(void) { 97 return xUnits_;126 return _xUnits; 98 127 } 99 128 const char *yUnits(void) { 100 return yUnits_;129 return _yUnits; 101 130 } 102 131 const char *zUnits(void) { 103 return zUnits_;132 return _zUnits; 104 133 } 105 134 const char *vUnits(void) { 106 return vUnits_; 135 return _vUnits; 136 } 137 const float *values(void) { 138 return _values; 139 } 140 const float *SaveValues(void) { 141 float *values; 142 values = _values; 143 _values = NULL; 144 _nValues = 0; 145 return values; 146 } 147 size_t nValues(void) { 148 return _nValues; 149 } 150 int LoadData(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv); 151 152 bool ReadVectorDataFromDx(Rappture::Outcome &result, size_t length, 153 char *string); 154 bool Resample(Rappture::Outcome &context, int nSamples = 30); 155 bool isInitialized(void) { 156 return _initialized; 157 } 158 }; 159 160 class Unirect2d { 161 size_t _xNum, _yNum; 162 size_t _nValues; 163 size_t _nComponents; 164 165 float _xMin, _xMax; 166 float _yMin, _yMax; 167 float _xValueMin, _xValueMax; 168 float _yValueMin, _yValueMax; 169 170 char *_xUnits; 171 char *_yUnits; 172 char *_vUnits; 173 174 float *_values; 175 bool _initialized; 176 177 public: 178 Unirect2d(size_t nComponents = 1) { 179 _values = NULL; 180 _initialized = false; 181 _xNum = _yNum = 0; 182 _nValues = 0; 183 _xUnits = _yUnits = _vUnits = NULL; 184 _nComponents = nComponents; 185 } 186 ~Unirect2d(void) { 187 if (_values != NULL) { 188 delete [] _values; 189 } 190 if (_xUnits != NULL) { 191 free(_xUnits); 192 } 193 if (_yUnits != NULL) { 194 free(_yUnits); 195 } 196 if (_vUnits != NULL) { 197 free(_vUnits); 198 } 199 } 200 size_t xNum(void) { 201 return _xNum; 202 } 203 size_t yNum(void) { 204 return _yNum; 205 } 206 float xMin(void) { 207 return _xMin; 208 } 209 float yMin(void) { 210 return _yMin; 211 } 212 float xMax(void) { 213 return _xMax; 214 } 215 float yMax(void) { 216 return _yMax; 217 } 218 const char *xUnits(void) { 219 return _xUnits; 220 } 221 const char *yUnits(void) { 222 return _yUnits; 223 } 224 const char *vUnits(void) { 225 return _vUnits; 107 226 } 108 227 float *values(void) { 109 return values_;110 } 111 float * SaveValues(void) {228 return _values; 229 } 230 float *acceptValues(void) { 112 231 float *values; 113 values = values_;114 values_= NULL;115 nValues_= 0;232 values = _values; 233 _values = NULL; 234 _nValues = 0; 116 235 return values; 117 236 } 118 237 size_t nValues(void) { 119 return nValues_; 120 } 121 size_t extents(void) { 122 return extents_; 123 } 124 void extents(size_t extents) { 125 extents_ = extents; 238 return _nValues; 126 239 } 127 240 int LoadData(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv); 128 241 bool isInitialized(void) { 129 return initialized_;242 return _initialized; 130 243 } 131 244 }; 132 245 133 class Unirect2d {134 size_t xNum_, yNum_;135 size_t nValues_;136 size_t extents_;137 138 float xMin_, xMax_;139 float yMin_, yMax_;140 float vMin_, vMax_;141 142 char *xUnits_;143 char *yUnits_;144 char *vUnits_;145 146 float *values_;147 bool initialized_;148 149 public:150 Unirect2d(void) {151 values_ = NULL;152 initialized_ = false;153 xNum_ = yNum_ = 0;154 nValues_ = 0;155 xUnits_ = yUnits_ = vUnits_ = NULL;156 }157 ~Unirect2d(void) {158 if (values_ != NULL) {159 delete [] values_;160 }161 if (xUnits_ != NULL) {162 free(xUnits_);163 }164 if (yUnits_ != NULL) {165 free(yUnits_);166 }167 if (vUnits_ != NULL) {168 free(vUnits_);169 }170 }171 size_t xNum(void) {172 return xNum_;173 }174 size_t yNum(void) {175 return yNum_;176 }177 float xMin(void) {178 return xMin_;179 }180 float yMin(void) {181 return yMin_;182 }183 float xMax(void) {184 return xMax_;185 }186 float yMax(void) {187 return yMax_;188 }189 const char *xUnits(void) {190 return xUnits_;191 }192 const char *yUnits(void) {193 return yUnits_;194 }195 const char *vUnits(void) {196 return vUnits_;197 }198 float *values(void) {199 return values_;200 }201 float *acceptValues(void) {202 float *values;203 values = values_;204 values_ = NULL;205 nValues_ = 0;206 return values;207 }208 size_t nValues(void) {209 return nValues_;210 }211 size_t extents(void) {212 return extents_;213 }214 void extents(size_t extents) {215 extents_ = extents;216 }217 int LoadData(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv);218 bool isInitialized(void) {219 return initialized_;220 }221 };222 223 246 } 224 247 -
trunk/packages/vizservers/nanovis/Volume.cpp
r1370 r1429 49 49 int fcount = width * height * depth * n_components; 50 50 _data = new float[fcount]; 51 if (data ) {51 if (data != NULL) { 52 52 Trace("data is copied\n"); 53 53 memcpy(_data, data, fcount * sizeof(float)); -
trunk/packages/vizservers/nanovis/VolumeRenderer.cpp
r1374 r1429 89 89 } 90 90 91 /* 92 * FIXME: This is a good example of the wrong data structures being used. 93 * The volumes should be in a list not a vector. Each list 94 * element should contain pointers to both the volume and the 95 * transfer function. The shouldn't be parallel vectors. 96 * 97 * And there shouldn't be one vector for "all" volumes and another 98 * for those being rendered, unless you work to keep them in sync. 99 * Use one master list instead. 100 */ 101 void 102 VolumeRenderer::remove_volume(size_t volIndex) 103 { 104 vector<Volume *>::iterator vIter; 105 vector<TransferFunction *>::iterator tfIter; 106 107 assert(volIndex < volume.size()); 108 assert(volIndex < tf.size()); 109 110 vIter = volume.begin(); 111 tfIter = tf.begin(); 112 size_t i; 113 for (i = 0; i < volIndex; i++) { 114 tfIter++; 115 vIter++; 116 } 117 volume.erase(vIter); 118 tf.erase(tfIter); 119 n_volumes--; 120 } 121 91 122 void 92 123 VolumeRenderer::shade_volume(Volume* _vol, TransferFunction* _tf) … … 177 208 178 209 for(int vol_index = 0; vol_index< num_volumes; vol_index++) { 210 cur_vol = NULL; 211 cur_tf = NULL; 212 #ifdef notdef 179 213 if (vol_index != n_volumes) { 180 214 cur_vol = volume[vol_index]; … … 184 218 cur_tf = ani_tf; 185 219 } 186 220 #else 221 cur_vol = volume[vol_index]; 222 cur_tf = tf[vol_index]; 223 #endif 224 187 225 polys[vol_index] = NULL; 188 226 actual_slices[vol_index] = 0; 189 227 190 if(!cur_vol->is_enabled()) 228 if(!cur_vol->is_enabled()) { 191 229 continue; //skip this volume 230 } 192 231 193 232 int n_slices = cur_vol->get_n_slice(); -
trunk/packages/vizservers/nanovis/VolumeRenderer.h
r1374 r1429 106 106 107 107 int add_volume(Volume* _vol, TransferFunction* _tf); 108 void remove_volume(size_t volIndex); 108 109 // add a volume and its transfer function 109 110 // we require a transfer function when a -
trunk/packages/vizservers/nanovis/config.h
r1370 r1429 31 31 #define PROTOTYPE 1 32 32 33 //#define NEW_FLOW_ENGINE 33 #define NEW_FLOW_ENGINE 1 34 34 35 35 /* -
trunk/packages/vizservers/nanovis/dxReader.cpp
r1384 r1429 162 162 } 163 163 return new Rappture::Unirect3d(x0, x0 + dx * nx, nx, y0, y0 + dy * ny, ny, 164 z0, z0 + dz * nz, nz, nValues, values );164 z0, z0 + dz * nz, nz, nValues, values, 3); 165 165 } 166 166 167 167 168 #ifdef notdef 168 169 /* 169 170 * Load a 3D vector field from a dx-format file … … 363 364 return true; 364 365 } 366 #endif 365 367 366 368 /* Load a 3D volume from a dx-format file … … 744 746 while (!fin.eof()) { 745 747 fin.getline(line, sizeof(line) - 1); 746 fprintf(stderr, "line is %s\n", line);747 748 if (fin.fail()) { 748 749 result.error("error in data stream"); … … 840 841 } 841 842 } 842 fprintf(stderr, "found nx=%d ny=%d, nz=%d, x0=%f, y0=%f, z0=%f\n",843 nx, ny, nz, x0, y0, z0);844 843 // read data points 845 844 if (fin.eof()) { … … 869 868 int nindex = iz*nx*ny + iy*nx + ix; 870 869 field.define(nindex, dval[p]); 871 fprintf(stderr,"nindex = %i\tdval[%i] = %lg\n", nindex, p,872 dval[p]);873 870 fflush(stderr); 874 871 nread++; … … 1177 1174 while (!fin.eof()) { 1178 1175 fin.getline(line, sizeof(line) - 1); 1179 fprintf(stderr, "line is %s\n", line);1180 1176 if (fin.fail()) { 1181 1177 result.addError("line \"%s\"error in data stream"); … … 1273 1269 } 1274 1270 1275 fprintf(stderr, "found nx=%d ny=%d, nz=%d, x0=%f, y0=%f, z0=%f\n",1276 nx, ny, nz, x0, y0, z0);1277 1271 // read data points 1278 1272 if (fin.eof()) { -
trunk/packages/vizservers/nanovis/nanovis.cpp
r1381 r1429 69 69 #include <R2/R2Fonts.h> 70 70 71 #include "Unirect.h" 72 #include "Switch.h" 73 #include "FlowCmd.h" 74 71 75 #define SIZEOF_BMP_HEADER 54 72 76 … … 126 130 FILE *NanoVis::recfile = NULL; 127 131 128 bool NanoVis::lic_on = false;129 bool NanoVis::particle_on = false;130 bool NanoVis::vector_on = false;131 132 bool NanoVis::axis_on = true; 132 133 bool NanoVis::config_pending = false; 133 134 bool NanoVis::debug_flag = false; 134 bool NanoVis::lic_slice_x_visible = false;135 bool NanoVis::lic_slice_y_visible = false;136 bool NanoVis::lic_slice_z_visible = false;137 135 138 136 Tcl_Interp *NanoVis::interp; … … 427 425 int result; 428 426 427 #ifdef notdef 429 428 if (NanoVis::debug_flag) { 430 429 fprintf(stderr, "in ExecuteCommand(%s)\n", Tcl_DStringValue(dsPtr)); 431 430 } 432 431 #endif 433 432 gettimeofday(&tv, NULL); 434 433 start = CVT2SECS(tv); 435 434 435 #ifdef notdef 436 436 if (NanoVis::logfile != NULL) { 437 437 fprintf(NanoVis::logfile, "%s", Tcl_DStringValue(dsPtr)); 438 438 fflush(NanoVis::logfile); 439 439 } 440 #endif 440 441 if (NanoVis::recfile != NULL) { 441 442 fprintf(NanoVis::recfile, "%s", Tcl_DStringValue(dsPtr)); … … 450 451 stats.cmdTime += finish - start; 451 452 stats.nCommands++; 453 #ifdef notdef 452 454 if (NanoVis::debug_flag) { 453 455 fprintf(stderr, "leaving ExecuteCommand status=%d\n", result); 454 456 } 457 #endif 455 458 return result; 456 459 } … … 506 509 volume[index] = new Volume(0.f, 0.f, 0.f, width, height, depth, 1., 507 510 n_component, data, vmin, vmax, nzero_min); 511 fprintf(stderr, "VOLINDEX=%d, n_volumes=%d\n", index, n_volumes); 508 512 return volume[index]; 509 513 } … … 665 669 } 666 670 667 if (screen_buffer ) {668 delete [] screen_buffer;671 if (screen_buffer != NULL) { 672 delete [] screen_buffer; 669 673 screen_buffer = NULL; 670 674 } … … 827 831 828 832 829 #if PROTOTYPE 830 licRenderer = new NvLIC(NMESH, NPIX, NPIX, lic_axis, Vector3(lic_slice_x, lic_slice_y, lic_slice_z), g_context); 831 #endif 833 licRenderer = new NvLIC(NMESH, NPIX, NPIX, lic_axis, 834 Vector3(lic_slice_x, lic_slice_y, lic_slice_z), 835 g_context); 832 836 833 837 ImageLoaderFactory::getInstance()->addLoaderImpl("bmp", new BMPImageLoaderImpl()); … … 835 839 grid->setFont(fonts); 836 840 841 #ifdef notdef 837 842 pointset_renderer = new PointSetRenderer(); 843 #endif 838 844 } 839 845 … … 1041 1047 sprintf(filename, "/tmp/flow_animation/image%03d.bmp", frame_number); 1042 1048 1043 printf("Writing %s\n", filename);1049 fprintf(stderr, "Writing %s\n", filename); 1044 1050 f = fopen(filename, "wb"); 1045 1051 if (f == 0) { … … 1052 1058 } 1053 1059 } 1054 ssize_t nWritten; 1055 nWritten = fwrite(header, SIZEOF_BMP_HEADER, 1, f); 1056 assert(nWritten == SIZEOF_BMP_HEADER); 1057 nWritten = fwrite(screen_buffer, (3*win_width+pad)*win_height, 1, f); 1058 assert(nWritten == (3*win_width+pad)*win_height); 1060 if (fwrite(header, SIZEOF_BMP_HEADER, 1, f) != 1) { 1061 Trace("can't write header: short write\n"); 1062 } 1063 if (fwrite(screen_buffer, (3*win_width+pad)*win_height, 1, f) != 1) { 1064 Trace("can't write data: short write\n"); 1065 } 1059 1066 fclose(f); 1060 1067 } … … 1633 1640 fprintf(stderr, "in display\n"); 1634 1641 } 1642 1643 if (FlowCmd::flags & FlowCmd::MAP_PENDING) { 1644 FlowCmd::MapFlows(); 1645 } 1635 1646 //assert(glGetError()==0); 1636 1647 if (HeightMap::update_pending) { … … 1701 1712 if ((licRenderer != NULL) && (licRenderer->isActivated())) { 1702 1713 licRenderer->render(); 1703 } 1704 1714 /*FlowCmd::SetupFlows();*/ 1715 } 1716 #ifdef notdef 1705 1717 if ((flowVisRenderer != NULL) && (flowVisRenderer->isActivated())) { 1706 1718 flowVisRenderer->render(); 1719 } 1720 #endif 1721 if (FlowCmd::flags & FlowCmd::REDRAW_PENDING) { 1722 FlowCmd::RenderFlows(); 1707 1723 } 1708 1724 … … 1732 1748 perf->disable(); 1733 1749 } 1734 1735 1750 perf->reset(); 1736 1751 if (debug_flag) { 1737 1752 fprintf(stderr, "leaving display\n"); 1738 1753 } 1754 1739 1755 1740 1756 } … … 1923 1939 break; 1924 1940 case '5' : 1925 {1926 printf("vector field deleted (vf_name2)\n");1941 86 { 1942 a printf("vector field deleted (vf_name2)\n"); 1927 1943 NanoVis::flowVisRenderer->removeVectorField("vf_name2"); 1928 1944 } … … 2063 2079 int status = TCL_OK; 2064 2080 2065 //2066 2081 // Read and execute as many commands as we can from stdin... 2067 // 2082 2068 2083 bool isComplete = false; 2069 while ( status == TCL_OK) {2084 while ((!feof(NanoVis::stdin)) && (status == TCL_OK)) { 2070 2085 // 2071 2086 // Read the next command from the buffer. First time through we … … 2088 2103 break; 2089 2104 } 2090 DoExit(0);2105 DoExit(100); 2091 2106 } 2092 2107 ch = (char)c; … … 2103 2118 break; 2104 2119 } 2105 2106 2120 if (isComplete) { 2107 2121 // back to original flags during command evaluation... … … 2167 2181 #endif 2168 2182 if (feof(NanoVis::stdin)) { 2169 DoExit( 0);2183 DoExit(90); 2170 2184 } 2171 2185 if (debug_flag) { … … 2336 2350 2337 2351 glutMainLoop(); 2338 DoExit( 0);2352 DoExit(80); 2339 2353 } 2340 2354 -
trunk/packages/vizservers/nanovis/nanovis.h
r1370 r1429 137 137 static float lic_slice_y; 138 138 static float lic_slice_z; 139 static bool lic_slice_x_visible;140 static bool lic_slice_y_visible;141 static bool lic_slice_z_visible;142 139 static int lic_axis; /* 0:x, 1:y, 2:z */ 143 140 … … 149 146 150 147 static bool debug_flag; 151 static bool lic_on;152 static bool particle_on;153 static bool vector_on;154 148 155 149 static Tcl_Interp *interp;
Note: See TracChangeset
for help on using the changeset viewer.