Changeset 2843 for trunk/packages/vizservers
- Timestamp:
- Mar 12, 2012, 1:13:51 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/Unirect.cpp
r2831 r2843 18 18 { 19 19 while (isspace(*string)) { 20 20 string++; 21 21 } 22 22 return string; … … 30 30 line = skipspaces(*stringPtr); 31 31 for (p = line; p < endPtr; p++) { 32 33 34 35 36 32 if (*p == '\n') { 33 *p++ = '\0'; 34 *stringPtr = p; 35 return line; 36 } 37 37 } 38 38 *stringPtr = p; … … 48 48 int objc; 49 49 if (Tcl_ListObjGetElements(interp, objPtr, &objc, &objv) != TCL_OK) { 50 50 return TCL_ERROR; 51 51 } 52 52 int result; … … 54 54 Tcl_DecrRefCount(objPtr); 55 55 if ((result != TCL_OK) || (!isInitialized())) { 56 56 return TCL_ERROR; 57 57 } 58 58 return TCL_OK; … … 67 67 int objc; 68 68 if (Tcl_ListObjGetElements(interp, objPtr, &objc, &objv) != TCL_OK) { 69 69 return TCL_ERROR; 70 70 } 71 71 int result; … … 73 73 Tcl_DecrRefCount(objPtr); 74 74 if ((result != TCL_OK) || (!isInitialized())) { 75 75 return TCL_ERROR; 76 76 } 77 77 return TCL_OK; … … 80 80 int 81 81 Rappture::Unirect3d::LoadData(Tcl_Interp *interp, int objc, 82 82 Tcl_Obj *const *objv) 83 83 { 84 84 int num[3], nValues; … … 174 174 175 175 if (Tcl_ListObjGetElements(interp, objv[i+1], &nValues, &vobj) 176 176 != TCL_OK) { 177 177 return TCL_ERROR; 178 178 } … … 182 182 if (GetFloatFromObj(interp, vobj[j], _values + j)!=TCL_OK) { 183 183 return TCL_ERROR; 184 185 184 } 185 } 186 186 } else if ((c == 'u') && (strcmp(string, "units") == 0)) { 187 187 _vUnits = strdup(Tcl_GetString(objv[i+1])); 188 188 } else if ((c == 'c') && (strcmp(string, "components") == 0)) { 189 190 191 192 return TCL_ERROR; 193 } 194 189 int n; 190 191 if (Tcl_GetIntFromObj(interp, objv[i+1], &n) != TCL_OK) { 192 return TCL_ERROR; 193 } 194 if (n <= 0) { 195 195 Tcl_AppendResult(interp, "bad extents value: must be > 0", 196 196 (char *)NULL); 197 197 return TCL_ERROR; 198 198 } 199 199 _nComponents = n; 200 200 } else if ((c == 'a') && (strcmp(string, "axisorder") == 0)) { 201 202 203 204 205 206 return TCL_ERROR; 207 } 208 209 return TCL_ERROR; 210 211 212 213 214 215 201 Tcl_Obj **axes; 202 int n; 203 204 if (Tcl_ListObjGetElements(interp, objv[i+1], &n, &axes) 205 != TCL_OK) { 206 return TCL_ERROR; 207 } 208 if (n != 3) { 209 return TCL_ERROR; 210 } 211 if ((GetAxisFromObj(interp, axes[0], &axis1) != TCL_OK) || 212 (GetAxisFromObj(interp, axes[1], &axis2) != TCL_OK) || 213 (GetAxisFromObj(interp, axes[2], &axis3) != TCL_OK)) { 214 return TCL_ERROR; 215 } 216 216 } else { 217 217 Tcl_AppendResult(interp, "unknown key \"", string, … … 225 225 } 226 226 if ((size_t)nValues != (num[0] * num[1] * num[2] * _nComponents)) { 227 228 227 TRACE("num[0]=%d num[1]=%d num[2]=%d ncomponents=%d nValues=%d\n", 228 num[0], num[1], num[2], _nComponents, nValues); 229 229 Tcl_AppendResult(interp, 230 231 230 "wrong # of values: must be xnum*ynum*znum*extents", 231 (char *)NULL); 232 232 return TCL_ERROR; 233 233 } … … 235 235 #ifdef notdef 236 236 if ((axis1 != 0) || (axis2 != 1) || (axis3 != 2)) { 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 237 // Reorder the data into x, y, z where x varies fastest and so on. 238 int z; 239 float *data, *dp; 240 241 dp = data = new float[nValues]; 242 for (z = 0; z < num[0]; z++) { 243 int y; 244 245 for (y = 0; y < num[1]; y++) { 246 int x; 247 248 for (x = 0; x < num[2]; x++) { 249 int i; 250 251 /* Compute the index from the data's described ordering. */ 252 i = ((z*num[axis2]*num[axis3]) + (y*num[axis3]) + x) * 3; 253 for(size_t v = 0; v < _nComponents; v++) { 254 dp[v] = values[i+v]; 255 } 256 dp += _nComponents; 257 } 258 } 259 } 260 delete [] values; 261 values = data; 262 262 } 263 263 #endif 264 264 _nValues = nValues; 265 265 if (units[3] != NULL) { 266 267 268 269 266 if (_vUnits != NULL) { 267 free(_vUnits); 268 } 269 _vUnits = strdup(units[3]); 270 270 } 271 271 _xMin = min[axis3]; … … 273 273 _xNum = num[axis3]; 274 274 if (units[axis3] != NULL) { 275 276 277 278 275 if (_xUnits != NULL) { 276 free(_xUnits); 277 } 278 _xUnits = strdup(units[axis3]); 279 279 } 280 280 _yMin = min[axis2]; … … 282 282 _yNum = num[axis2]; 283 283 if (units[axis2] != NULL) { 284 285 286 287 284 if (_yUnits != NULL) { 285 free(_yUnits); 286 } 287 _yUnits = strdup(units[axis2]); 288 288 } 289 289 _zMin = min[axis1]; … … 291 291 _zNum = num[axis1]; 292 292 if (units[axis1] != NULL) { 293 294 295 296 293 if (_zUnits != NULL) { 294 free(_zUnits); 295 } 296 _zUnits = strdup(units[axis1]); 297 297 } 298 298 _initialized = true; 299 299 #ifdef notdef 300 300 { 301 302 303 304 305 306 307 308 309 310 311 301 FILE *f; 302 f = fopen("/tmp/unirect3d.txt", "w"); 303 fprintf(f, "unirect3d xmin %g xmax %g xnum %d ", _xMin, _xMax, _xNum); 304 fprintf(f, "ymin %g ymax %g ynum %d ", _yMin, _yMax, _yNum); 305 fprintf(f, "zmin %g zmax %g znum %d ", _zMin, _zMax, _zNum); 306 fprintf(f, "components %d values {\n", _nComponents); 307 for (size_t i = 0; i < _nValues; i+= 3) { 308 fprintf(f, "%g %g %g\n", _values[i], _values[i+1], _values[i+2]); 309 } 310 fprintf(f, "}\n"); 311 fclose(f); 312 312 } 313 313 #endif … … 318 318 int 319 319 Rappture::Unirect2d::LoadData(Tcl_Interp *interp, int objc, 320 320 Tcl_Obj *const *objv) 321 321 { 322 322 if ((objc & 0x01) == 0) { … … 328 328 329 329 int axis[2]; 330 axis[0] = 1; 330 axis[0] = 1; /* X-axis */ 331 331 axis[1] = 0; /* Y-axis */ 332 332 … … 334 334 _xMin = _yMin = _xMax = _yMax = 0.0f; 335 335 if (_xUnits != NULL) { 336 336 free(_xUnits); 337 337 } 338 338 if (_yUnits != NULL) { 339 339 free(_yUnits); 340 340 } 341 341 if (_vUnits != NULL) { 342 342 free(_vUnits); 343 343 } 344 344 _xUnits = _yUnits = _vUnits = NULL; … … 361 361 } 362 362 } else if ((c == 'x') && (strcmp(string, "xnum") == 0)) { 363 363 int n; 364 364 if (Tcl_GetIntFromObj(interp, objv[i+1], &n) != TCL_OK) { 365 365 return TCL_ERROR; … … 370 370 return TCL_ERROR; 371 371 } 372 372 _xNum = n; 373 373 } else if ((c == 'x') && (strcmp(string, "xunits") == 0)) { 374 374 _xUnits = strdup(Tcl_GetString(objv[i+1])); … … 382 382 } 383 383 } else if ((c == 'y') && (strcmp(string, "ynum") == 0)) { 384 384 int n; 385 385 if (Tcl_GetIntFromObj(interp, objv[i+1], &n) != TCL_OK) { 386 386 return TCL_ERROR; … … 391 391 return TCL_ERROR; 392 392 } 393 393 _yNum = n; 394 394 } else if ((c == 'y') && (strcmp(string, "yunits") == 0)) { 395 395 _yUnits = strdup(Tcl_GetString(objv[i+1])); 396 396 } else if ((c == 'v') && (strcmp(string, "values") == 0)) { 397 397 Tcl_Obj **vobj; 398 399 400 398 int n; 399 400 Tcl_IncrRefCount(objv[i+1]); 401 401 if (Tcl_ListObjGetElements(interp, objv[i+1], &n, &vobj) != TCL_OK){ 402 402 return TCL_ERROR; 403 403 } 404 404 if (n <= 0) { 405 405 Tcl_AppendResult(interp, "empty values list : must be > 0", 406 406 (char *)NULL); 407 407 return TCL_ERROR; 408 409 408 } 409 _nValues = n; 410 410 _values = (float *)realloc(_values, sizeof(float) * _nValues); 411 411 size_t j; … … 413 413 if (GetFloatFromObj(interp, vobj[j], _values + j)!=TCL_OK) { 414 414 return TCL_ERROR; 415 416 417 415 } 416 } 417 Tcl_DecrRefCount(objv[i+1]); 418 418 } else if ((c == 'u') && (strcmp(string, "units") == 0)) { 419 419 _vUnits = strdup(Tcl_GetString(objv[i+1])); 420 420 } else if ((c == 'c') && (strcmp(string, "components") == 0)) { 421 422 423 424 return TCL_ERROR; 425 } 426 421 int n; 422 423 if (Tcl_GetIntFromObj(interp, objv[i+1], &n) != TCL_OK) { 424 return TCL_ERROR; 425 } 426 if (n <= 0) { 427 427 Tcl_AppendResult(interp, "bad extents value: must be > 0", 428 428 (char *)NULL); 429 429 return TCL_ERROR; 430 430 } 431 431 _nComponents = n; 432 432 } else if ((c == 'a') && (strcmp(string, "axisorder") == 0)) { 433 434 435 436 437 438 return TCL_ERROR; 439 } 440 441 442 443 444 return TCL_ERROR; 445 446 447 448 449 433 Tcl_Obj **order; 434 int n; 435 436 if (Tcl_ListObjGetElements(interp, objv[i+1], &n, &order) 437 != TCL_OK) { 438 return TCL_ERROR; 439 } 440 if (n != 2) { 441 Tcl_AppendResult(interp, 442 "wrong # of axes defined for ordering the data", 443 (char *)NULL); 444 return TCL_ERROR; 445 } 446 if ((GetAxisFromObj(interp, order[0], axis) != TCL_OK) || 447 (GetAxisFromObj(interp, order[1], axis+1) != TCL_OK)) { 448 return TCL_ERROR; 449 } 450 450 } else { 451 451 Tcl_AppendResult(interp, "unknown key \"", string, … … 460 460 if (_nValues != (_xNum * _yNum * _nComponents)) { 461 461 Tcl_AppendResult(interp, 462 463 462 "wrong number of values: must be xnum*ynum*components", 463 (char *)NULL); 464 464 return TCL_ERROR; 465 465 } 466 466 467 467 if ((axis[0] != 1) || (axis[1] != 0)) { 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 468 TRACE("reordering data\n"); 469 /* Reorder the data into x, y where x varies fastest and so on. */ 470 size_t y; 471 float *dp; 472 473 dp = _values = (float *)realloc(_values, sizeof(float) * _nValues); 474 for (y = 0; y < _yNum; y++) { 475 size_t x; 476 477 for (x = 0; x < _xNum; x++) { 478 size_t i, v; 479 480 /* Compute the index from the data's described ordering. */ 481 i = (y + (_yNum * x)) * _nComponents; 482 for(v = 0; v < _nComponents; v++) { 483 dp[v] = _values[i+v]; 484 } 485 dp += _nComponents; 486 } 487 } 488 488 } 489 489 _initialized = true; … … 494 494 bool 495 495 Rappture::Unirect3d::ImportDx(Rappture::Outcome &result, size_t nComponents, 496 496 size_t length, char *string) 497 497 { 498 498 int nx, ny, nz, npts; … … 504 504 nx = ny = nz = npts = 0; /* Suppress compiler warning. */ 505 505 for (p = string, pend = p + length; p < pend; /*empty*/) { 506 507 508 506 char *line; 507 508 line = getline(&p, pend); 509 509 if (line == pend) { 510 break;/* EOF */511 510 break; /* EOF */ 511 } 512 512 if ((line[0] == '#') || (line == '\0')) { 513 continue;/* Skip blank or comment lines. */514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 } 539 printf("#points=%d\n", npts);540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 513 continue; /* Skip blank or comment lines. */ 514 } 515 if (sscanf(line, "object %*d class gridpositions counts %d %d %d", 516 &nx, &ny, &nz) == 3) { 517 if ((nx < 0) || (ny < 0) || (nz < 0)) { 518 result.addError("invalid grid size: x=%d, y=%d, z=%d", 519 nx, ny, nz); 520 return false; 521 } 522 } else if (sscanf(line, "origin %lg %lg %lg", &x0, &y0, &z0) == 3) { 523 /* Found origin. */ 524 } else if (sscanf(line, "delta %lg %lg %lg", &ddx, &ddy, &ddz) == 3) { 525 /* Found one of the delta lines. */ 526 if (ddx != 0.0) { 527 dx = ddx; 528 } else if (ddy != 0.0) { 529 dy = ddy; 530 } else if (ddz != 0.0) { 531 dz = ddz; 532 } 533 } else if (sscanf(line, "object %*d class array type %*s shape 3" 534 " rank 1 items %d data follows", &npts) == 1) { 535 if (npts < 0) { 536 result.addError("bad # points %d", npts); 537 return false; 538 } 539 TRACE("#points=%d\n", npts); 540 if (npts != nx*ny*nz) { 541 result.addError("inconsistent data: expected %d points" 542 " but found %d points", nx*ny*nz, npts); 543 return false; 544 } 545 break; 546 } else if (sscanf(line, "object %*d class array type %*s rank 0" 547 " times %d data follows", &npts) == 1) { 548 if (npts != nx*ny*nz) { 549 result.addError("inconsistent data: expected %d points" 550 " but found %d points", nx*ny*nz, npts); 551 return false; 552 } 553 break; 554 } 555 555 } 556 556 if (npts != nx*ny*nz) { 557 558 559 557 result.addError("inconsistent data: expected %d points" 558 " but found %d points", nx*ny*nz, npts); 559 return false; 560 560 } 561 561 … … 573 573 _nValues = 0; 574 574 for (size_t ix = 0; ix < _xNum; ix++) { 575 576 577 578 579 580 581 582 583 continue;/* Skip blank or comment lines. */584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 575 for (size_t iy = 0; iy < _yNum; iy++) { 576 for (size_t iz = 0; iz < _zNum; iz++) { 577 char *line; 578 if ((p == pend) || (_nValues > (size_t)npts)) { 579 break; 580 } 581 line = getline(&p, pend); 582 if ((line[0] == '#') || (line[0] == '\0')) { 583 continue; /* Skip blank or comment lines. */ 584 } 585 double vx, vy, vz; 586 if (sscanf(line, "%lg %lg %lg", &vx, &vy, &vz) == 3) { 587 int nindex = (iz*nx*ny + iy*nx + ix) * 3; 588 if (vx < _xValueMin) { 589 _xValueMin = vx; 590 } else if (vx > _xValueMax) { 591 _xValueMax = vx; 592 } 593 if (vy < _yValueMin) { 594 _yValueMin = vy; 595 } else if (vy > _yValueMax) { 596 _yValueMax = vy; 597 } 598 if (vz < _zValueMin) { 599 _zValueMin = vz; 600 } else if (vz > _zValueMax) { 601 _zValueMax = vz; 602 } 603 _values[nindex] = vx; 604 _values[nindex+1] = vy; 605 _values[nindex+2] = vz; 606 _nValues++; 607 } 608 } 609 } 610 610 } 611 611 /* Make sure that we read all of the expected points. */ 612 612 if (_nValues != (size_t)npts) { 613 614 615 616 617 613 result.addError("inconsistent data: expected %d points" 614 " but found %d points", npts, _nValues); 615 free(_values); 616 _values = NULL; 617 return false; 618 618 } 619 619 _nValues *= _nComponents; … … 621 621 #ifdef notdef 622 622 { 623 624 625 626 627 628 629 630 631 632 633 623 FILE *f; 624 f = fopen("/tmp/dx.txt", "w"); 625 fprintf(f, "unirect3d xmin %g xmax %g xnum %d ", _xMin, _xMax, _xNum); 626 fprintf(f, "ymin %g ymax %g ynum %d ", _yMin, _yMax, _yNum); 627 fprintf(f, "zmin %g zmax %g znum %d ", _zMin, _zMax, _zNum); 628 fprintf(f, "components %d values {\n", _nComponents); 629 for (size_t i = 0; i < _nValues; i+= 3) { 630 fprintf(f, "%g %g %g\n", _values[i], _values[i+1], _values[i+2]); 631 } 632 fprintf(f, "}\n"); 633 fclose(f); 634 634 } 635 635 #endif … … 650 650 size_t i, j; 651 651 for (i = 0, j = 0; i < _nValues; i += _nComponents, j++) { 652 653 654 655 656 657 658 659 660 652 double vx, vy, vz; 653 654 vx = _values[i]; 655 vy = _values[i+1]; 656 vz = _values[i+2]; 657 658 xfield.define(j, vx); 659 yfield.define(j, vy); 660 zfield.define(j, vz); 661 661 } 662 662 // Figure out a good mesh spacing … … 690 690 float *destPtr = _values; 691 691 for (size_t i = 0; i < _zNum; i++) { 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 692 double z; 693 694 z = _zMin + (i * dmin); 695 for (size_t j = 0; j < _yNum; j++) { 696 double y; 697 698 y = _yMin + (j * dmin); 699 for (size_t k = 0; k < _xNum; k++) { 700 double x; 701 702 x = _xMin + (k * dmin); 703 destPtr[0] = xfield.value(x, y, z); 704 destPtr[1] = yfield.value(x, y, z); 705 destPtr[2] = zfield.value(x, y, z); 706 } 707 } 708 708 } 709 709 _nValues = _xNum * _yNum * _zNum * _nComponents; … … 720 720 size_t i; 721 721 for (i = 0; i < _nValues; i += _nComponents) { 722 723 724 725 726 727 728 729 730 731 732 733 734 722 double vx, vy, vz, vm; 723 724 vx = _values[i]; 725 vy = _values[i+1]; 726 vz = _values[i+2]; 727 728 vm = sqrt(vx*vx + vy*vy + vz*vz); 729 if (vm > _magMax) { 730 _magMax = vm; 731 } 732 if (vm < _magMin) { 733 _magMin = vm; 734 } 735 735 } 736 736 } … … 756 756 case 1: 757 757 case 3: 758 759 760 761 762 763 764 765 758 _values = (float *)realloc(_values, sizeof(float) * dataPtr->nValues()); 759 if (_values == NULL) { 760 return false; 761 } 762 memcpy(_values, dataPtr->values(), dataPtr->nValues()); 763 _nValues = dataPtr->nValues(); 764 _nComponents = dataPtr->nComponents(); 765 break; 766 766 case 2: 767 768 769 770 771 772 773 774 775 for(j = i = 0; i < dataPtr->nValues(); i += 2, j+= 3) {776 777 778 779 } 780 781 767 float *values; 768 _nValues = 3 * _xNum * _yNum * _zNum; 769 _values = (float *)realloc(_values, sizeof(float) * _nValues); 770 if (_values == NULL) { 771 return false; 772 } 773 values = dataPtr->values(); 774 size_t i, j; 775 for (j = i = 0; i < dataPtr->nValues(); i += 2, j+= 3) { 776 _values[j] = values[i]; 777 _values[j+1] = values[i+1]; 778 _values[j+2] = 0.0f; 779 } 780 _nComponents = 3; 781 break; 782 782 } 783 783 return true;
Note: See TracChangeset
for help on using the changeset viewer.