1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 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 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 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 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 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 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkGenericEnSightReader.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkGenericEnSightReader.h"
#include "vtkCallbackCommand.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkDataArrayCollection.h"
#include "vtkDataArraySelection.h"
#include "vtkEnSight6BinaryReader.h"
#include "vtkEnSight6Reader.h"
#include "vtkEnSightGoldBinaryReader.h"
#include "vtkEnSightGoldReader.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkIdListCollection.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include <string>
#include <map>
#include <cassert>
#include <ctype.h> /* isspace */
vtkStandardNewMacro(vtkGenericEnSightReader);
vtkCxxSetObjectMacro(vtkGenericEnSightReader,TimeSets,
vtkDataArrayCollection);
class TranslationTableType
{
public:
std::map<int,int> PartIdMap;
};
//----------------------------------------------------------------------------
vtkGenericEnSightReader::vtkGenericEnSightReader()
{
this->Reader = NULL;
this->IS = NULL;
this->IFile = NULL;
this->CaseFileName = NULL;
this->GeometryFileName = NULL;
this->FilePath = NULL;
this->VariableTypes = NULL;
this->ComplexVariableTypes = NULL;
this->VariableDescriptions = NULL;
this->ComplexVariableDescriptions = NULL;
this->NumberOfVariables = 0;
this->NumberOfComplexVariables = 0;
this->NumberOfScalarsPerNode = 0;
this->NumberOfVectorsPerNode = 0;
this->NumberOfTensorsSymmPerNode = 0;
this->NumberOfScalarsPerElement = 0;
this->NumberOfVectorsPerElement = 0;
this->NumberOfTensorsSymmPerElement = 0;
this->NumberOfScalarsPerMeasuredNode = 0;
this->NumberOfVectorsPerMeasuredNode = 0;
this->NumberOfComplexScalarsPerNode = 0;
this->NumberOfComplexVectorsPerNode = 0;
this->NumberOfComplexScalarsPerElement = 0;
this->NumberOfComplexVectorsPerElement = 0;
this->TimeValue = 0;
this->MinimumTimeValue = 0;
this->MaximumTimeValue = 0;
this->TimeValueInitialized = 0;
this->TimeSets = NULL;
this->ReadAllVariables = 1;
this->ByteOrder = FILE_UNKNOWN_ENDIAN;
this->ParticleCoordinatesByIndex = 0;
this->EnSightVersion = -1;
this->PointDataArraySelection = vtkDataArraySelection::New();
this->CellDataArraySelection = vtkDataArraySelection::New();
// Setup the selection callback to modify this object when an array
// selection is changed.
this->SelectionObserver = vtkCallbackCommand::New();
this->SelectionObserver->SetCallback(
&vtkGenericEnSightReader::SelectionModifiedCallback);
this->SelectionObserver->SetClientData(this);
this->PointDataArraySelection->AddObserver(vtkCommand::ModifiedEvent,
this->SelectionObserver);
this->CellDataArraySelection->AddObserver(vtkCommand::ModifiedEvent,
this->SelectionObserver);
this->SelectionModifiedDoNotCallModified = 0;
this->TranslationTable = new TranslationTableType;
this->SetNumberOfInputPorts(0);
}
//----------------------------------------------------------------------------
vtkGenericEnSightReader::~vtkGenericEnSightReader()
{
int i;
if (this->Reader)
{
this->Reader->Delete();
this->Reader = NULL;
}
delete this->IS;
this->IS = NULL;
delete [] this->CaseFileName;
this->CaseFileName = NULL;
delete [] this->GeometryFileName;
this->GeometryFileName = NULL;
delete [] this->FilePath;
this->FilePath = NULL;
if (this->NumberOfVariables > 0)
{
for (i = 0; i < this->NumberOfVariables; i++)
{
delete [] this->VariableDescriptions[i];
}
delete [] this->VariableDescriptions;
delete [] this->VariableTypes;
this->VariableDescriptions = NULL;
this->VariableTypes = NULL;
}
if (this->NumberOfComplexVariables > 0)
{
for (i = 0; i < this->NumberOfComplexVariables; i++)
{
delete [] this->ComplexVariableDescriptions[i];
}
delete [] this->ComplexVariableDescriptions;
delete [] this->ComplexVariableTypes;
this->ComplexVariableDescriptions = NULL;
this->ComplexVariableTypes = NULL;
}
this->SetTimeSets(0);
this->CellDataArraySelection->RemoveObserver(this->SelectionObserver);
this->PointDataArraySelection->RemoveObserver(this->SelectionObserver);
this->SelectionObserver->Delete();
this->CellDataArraySelection->Delete();
this->PointDataArraySelection->Delete();
delete this->TranslationTable;
}
//-----------------------------------------------------------------------------
int vtkGenericEnSightReader::CanReadFile(const char *casefilename)
{
vtkGenericEnSightReader *reader = vtkGenericEnSightReader::New();
reader->SetCaseFileName(casefilename);
int type = reader->DetermineEnSightVersion(1);
reader->Delete();
return (type != -1);
}
//----------------------------------------------------------------------------
int vtkGenericEnSightReader::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **vtkNotUsed(inputVector),
vtkInformationVector *outputVector)
{
int i;
if ( !this->Reader )
{
return 0;
}
vtkInformation *outInfo = outputVector->GetInformationObject(0);
// Set the real reader's data array selections from ours.
this->SetReaderDataArraySelectionSetsFromSelf();
this->Reader->SetTimeValue(this->GetTimeValue());
this->Reader->UpdateInformation();
vtkInformation* tmpOutInfo =
this->Reader->GetExecutive()->GetOutputInformation(0);
if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()))
{
tmpOutInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP(),
outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()));
}
// GHOST LEVEL
// uncomment these lines below if you want to active
// the ghost level system
/*
if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_GHOST_LEVELS()))
{
tmpOutInfo->CopyEntry(
outInfo,
vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_GHOST_LEVELS());
}
*/
this->Reader->Update();
this->NumberOfScalarsPerNode = this->Reader->GetNumberOfScalarsPerNode();
this->NumberOfVectorsPerNode = this->Reader->GetNumberOfVectorsPerNode();
this->NumberOfTensorsSymmPerNode =
this->Reader->GetNumberOfTensorsSymmPerNode();
this->NumberOfScalarsPerElement =
this->Reader->GetNumberOfScalarsPerElement();
this->NumberOfVectorsPerElement =
this->Reader->GetNumberOfVectorsPerElement();
this->NumberOfTensorsSymmPerElement =
this->Reader->GetNumberOfTensorsSymmPerElement();
this->NumberOfScalarsPerMeasuredNode =
this->Reader->GetNumberOfScalarsPerMeasuredNode();
this->NumberOfVectorsPerMeasuredNode =
this->Reader->GetNumberOfVectorsPerMeasuredNode();
this->NumberOfComplexScalarsPerNode =
this->Reader->GetNumberOfComplexScalarsPerNode();
this->NumberOfComplexVectorsPerNode =
this->Reader->GetNumberOfComplexVectorsPerNode();
this->NumberOfComplexScalarsPerElement =
this->Reader->GetNumberOfComplexScalarsPerElement();
this->NumberOfComplexVectorsPerElement =
this->Reader->GetNumberOfComplexScalarsPerElement();
vtkMultiBlockDataSet *output = vtkMultiBlockDataSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
output->ShallowCopy(this->Reader->GetOutput());
if (this->NumberOfVariables > 0)
{
for (i = 0; i < this->NumberOfVariables; i++)
{
delete [] this->VariableDescriptions[i];
}
delete [] this->VariableDescriptions;
delete [] this->VariableTypes;
this->VariableDescriptions = NULL;
this->VariableTypes = NULL;
this->NumberOfVariables = 0;
}
if (this->NumberOfComplexVariables > 0)
{
for (i = 0; i < this->NumberOfComplexVariables; i++)
{
delete [] this->ComplexVariableDescriptions[i];
}
delete [] this->ComplexVariableDescriptions;
delete [] this->ComplexVariableTypes;
this->ComplexVariableDescriptions = NULL;
this->ComplexVariableTypes = NULL;
this->NumberOfComplexVariables = 0;
}
for (i = 0; i < this->Reader->GetNumberOfVariables(); i++)
{
this->AddVariableDescription(this->Reader->GetDescription(i));
this->AddVariableType(this->Reader->GetVariableType(i));
this->NumberOfVariables++;
}
for (i = 0; i < this->Reader->GetNumberOfComplexVariables(); i++)
{
this->AddComplexVariableDescription(
this->Reader->GetComplexDescription(i));
this->AddComplexVariableType(this->Reader->GetComplexVariableType(i));
this->NumberOfComplexVariables++;
}
return 1;
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::SetTimeValue(float value)
{
vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting TimeValue to " << value);
if (this->TimeValue != value)
{
this->TimeValue = value;
this->Modified();
}
this->TimeValueInitialized = 1;
}
//----------------------------------------------------------------------------
int vtkGenericEnSightReader::DetermineEnSightVersion(int quiet)
{
char line[256], subLine[256], subLine1[256], subLine2[256], binaryLine[81];
char *binaryLinePtr;
int stringRead;
int timeSet = 1, fileSet = 1;
int xtimeSet= 1, xfileSet= 1;
char *fileName = NULL;
int lineRead;
if (!this->CaseFileName)
{
if (!quiet) vtkErrorMacro("A case file name must be specified.");
return -1;
}
std::string sfilename = "";
if (this->FilePath)
{
sfilename = this->FilePath;
if (sfilename.at(sfilename.length()-1) != '/')
{
sfilename += "/";
}
sfilename += this->CaseFileName;
vtkDebugMacro("full path to case file: "
<< sfilename.c_str());
}
else
{
sfilename = this->CaseFileName;
}
this->IS = new ifstream(sfilename.c_str(), ios::in);
if (this->IS->fail())
{
if (!quiet) vtkErrorMacro("Unable to open file: " << sfilename.c_str());
delete this->IS;
this->IS = NULL;
return -1;
}
this->ReadNextDataLine(line);
if (strncmp(line, "FORMAT", 6) == 0)
{
// found the FORMAT section
vtkDebugMacro("*** FORMAT section");
this->ReadNextDataLine(line);
stringRead = sscanf(line, " %*s %*s %s", subLine);
if (stringRead == 1)
{
sscanf(line, " %*s %s %s", subLine1, subLine2);
if (strncmp(subLine1,"ensight",7) == 0)
{
if (strncmp(subLine2,"gold",4) == 0)
{
lineRead = this->ReadNextDataLine(line);
while (strncmp(line, "GEOMETRY", 8) != 0 && lineRead != 0)
{
lineRead = this->ReadNextDataLine(line);
}
if (lineRead == 0)
{
return -1;
}
if (strncmp(line, "GEOMETRY", 8) == 0)
{
// found the GEOMETRY section
vtkDebugMacro("*** GEOMETRY section");
this->ReadNextDataLine(line);
if (strncmp(line, "model:", 6) == 0)
{
if (sscanf(line, " %*s %d %d %s", &xtimeSet, &fileSet, subLine) == 3)
{
timeSet = xtimeSet;
fileSet = xfileSet;
this->SetGeometryFileName(subLine);
}
else if (sscanf(line, " %*s %d%*[ \t]%s", &xtimeSet, subLine) == 2)
{
timeSet = xtimeSet;
this->SetGeometryFileName(subLine);
}
else if (sscanf(line, " %*s %s", subLine) == 1)
{
this->SetGeometryFileName(subLine);
}
} // geometry file name set
delete this->IS;
this->IS = NULL;
if (!this->GeometryFileName || this->GeometryFileName[0] == '\0')
{
if (!quiet)
{
vtkErrorMacro(
"A GeometryFileName must be specified in the case file.");
}
return 0;
}
fileName = new char[strlen(this->GeometryFileName) + 1];
strcpy(fileName, this->GeometryFileName);
if (strrchr(fileName, '*') != NULL)
{
// RE-open case file; find right time set and fill in
// wildcards from there if possible; if not, then find right
// file set and fill in wildcards from there.
if ( this->ReplaceWildcards(fileName, timeSet, fileSet) == 0 )
{
if (!quiet)
{
vtkErrorMacro(
"upon DetermineEnSightVersion()'s call to ReplaceWildCards()");
}
return -1;
}
}
sfilename = "";
if (this->FilePath)
{
sfilename = this->FilePath;
if (sfilename.at(sfilename.length()-1) != '/')
{
sfilename += "/";
}
sfilename += fileName;
vtkDebugMacro("full path to geometry file: "
<< sfilename.c_str());
}
else
{
sfilename = fileName;
}
// got full path to geometry file
this->IFile = fopen(sfilename.c_str(), "rb");
if (this->IFile == NULL)
{
if (!quiet)
{
vtkErrorMacro("Unable to open file: " << sfilename.c_str());
vtkWarningMacro("Assuming binary file.");
}
this->IFile = NULL;
delete [] fileName;
return vtkGenericEnSightReader::ENSIGHT_GOLD_BINARY;
} // end if IFile == NULL
this->ReadBinaryLine(binaryLine);
binaryLine[80] = '\0';
// because fortran stores 4 length bytes at the start,
// if the strlen is less than 4, skip the first 4
// and jump to the start of the actual string
binaryLinePtr = &binaryLine[0];
if (strlen(binaryLine)<4)
{
binaryLinePtr = &binaryLine[4];
}
sscanf(binaryLinePtr, " %*s %s", subLine);
// If the file is ascii, there might not be a null
// terminator. This leads to a UMR in sscanf
if (strncmp(subLine,"Binary",6) == 0 ||
strncmp(subLine,"binary",6) == 0)
{
fclose(this->IFile);
this->IFile = NULL;
delete [] fileName;
return vtkGenericEnSightReader::ENSIGHT_GOLD_BINARY;
} //end if binary
fclose(this->IFile);
this->IFile = NULL;
delete [] fileName;
return vtkGenericEnSightReader::ENSIGHT_GOLD;
} // if we found the geometry section in the case file
} // if ensight gold file
} // if regular ensight file (not master_server)
else if (strncmp(subLine1,"master_server",13) == 0)
{
return vtkGenericEnSightReader::ENSIGHT_MASTER_SERVER;
}
} // if the type line is like "type: xxxx xxxx"
else
{
this->ReadNextDataLine(line);
if (strncmp(line, "GEOMETRY", 8) == 0)
{
// found the GEOMETRY section
vtkDebugMacro("*** GEOMETRY section");
this->ReadNextDataLine(line);
if (strncmp(line, "model:", 6) == 0)
{
if (sscanf(line, " %*s %d %d %s", &xtimeSet, &fileSet, subLine) == 3)
{
timeSet = xtimeSet;
fileSet = xfileSet;
this->SetGeometryFileName(subLine);
}
else if (sscanf(line, " %*s %d%*[ \t]%s", &xtimeSet, subLine) == 2)
{
timeSet = xtimeSet;
this->SetGeometryFileName(subLine);
}
else if (sscanf(line, " %*s %s", subLine) == 1)
{
this->SetGeometryFileName(subLine);
}
} // geometry file name set
delete this->IS;
this->IS = NULL;
if (!this->GeometryFileName || this->GeometryFileName[0] == '\0')
{
if (!quiet)
{
vtkErrorMacro(
"A GeometryFileName must be specified in the case file.");
}
return 0;
}
fileName = new char[strlen(this->GeometryFileName) + 1];
strcpy(fileName, this->GeometryFileName);
if (strrchr(fileName, '*') != NULL)
{
// reopen case file; find right time set and fill in wildcards from
// there if possible; if not, then find right file set and fill in
// wildcards from there.
this->ReplaceWildcards(fileName, timeSet, fileSet);
}
sfilename = "";
if (this->FilePath)
{
sfilename = this->FilePath;
if (sfilename.at(sfilename.length()-1) != '/')
{
sfilename += "/";
}
sfilename += fileName;
vtkDebugMacro("full path to geometry file: "
<< sfilename.c_str());
}
else
{
sfilename = fileName;
}
// got full path to geometry file
this->IFile = fopen(sfilename.c_str(), "rb");
if (this->IFile == NULL)
{
if (!quiet)
{
vtkErrorMacro("Unable to open file: " << sfilename.c_str());
vtkWarningMacro("Assuming binary file.");
}
this->IFile = NULL;
delete [] fileName;
return vtkGenericEnSightReader::ENSIGHT_6_BINARY;
} // end if IFile == NULL
this->ReadBinaryLine(binaryLine);
// If the file is ascii, there might not be a null
// terminator. This leads to a UMR in sscanf
binaryLine[80] = '\0';
sscanf(binaryLine, " %*s %s", subLine);
if (strncmp(subLine,"Binary",6) == 0)
{
fclose(this->IFile);
this->IFile = NULL;
delete [] fileName;
return vtkGenericEnSightReader::ENSIGHT_6_BINARY;
} //end if binary
fclose(this->IFile);
this->IFile = NULL;
delete [] fileName;
return vtkGenericEnSightReader::ENSIGHT_6;
} // if we found the geometry section in the case file
} // not ensight gold
} // if we found the format section in the case file
delete [] fileName;
return -1;
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::ClearForNewCaseFileName()
{
this->TranslationTable->PartIdMap.clear();
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::SetCaseFileName(const char* fileName)
{
char *endingSlash;
char *path, *newFileName;
int position, numChars;
if ( this->CaseFileName && fileName &&
(!strcmp(this->CaseFileName, fileName)))
{
return;
}
delete [] this->CaseFileName;
if (fileName)
{
this->CaseFileName = new char[strlen(fileName)+1];
strcpy(this->CaseFileName, fileName);
}
else
{
this->CaseFileName = NULL;
}
this->ClearForNewCaseFileName();
this->Modified();
if (!this->CaseFileName)
{
return;
}
// strip off the path and save it as FilePath if it was included in the
// filename
endingSlash = strrchr(this->CaseFileName, '/');
if(endingSlash == NULL)
{
// check Windows directory separator
endingSlash = strrchr(this->CaseFileName, '\\');
}
if (endingSlash)
{
position = endingSlash - this->CaseFileName + 1;
path = new char[position + 1];
numChars = static_cast<int>(strlen(this->CaseFileName));
newFileName = new char[numChars - position + 1];
strcpy(path, "");
strncat(path, this->CaseFileName, position);
this->SetFilePath(path);
strcpy(newFileName, this->CaseFileName + position);
strcpy(this->CaseFileName, newFileName);
delete [] path;
delete [] newFileName;
}
}
//----------------------------------------------------------------------------
// Internal function to read in a line up to 256 characters.
// Returns zero if there was an error.
int vtkGenericEnSightReader::ReadLine(char result[256])
{
this->IS->getline(result,256);
// if (this->IS->eof())
if (this->IS->fail())
{
// Reset the error flag before returning. This way, we can keep working
// if we handle the error downstream.
this->IS->clear();
return 0;
}
return 1;
}
//----------------------------------------------------------------------------
// Internal function to read in a line (from a binary file) up
// to 80 characters. Returns zero if there was an error.
int vtkGenericEnSightReader::ReadBinaryLine(char result[80])
{
int n = static_cast<int>(fread(result, sizeof(char), 80, this->IFile));
if ((n<80) || feof(this->IFile) || ferror(this->IFile))
{
return 0;
}
return 1;
}
//----------------------------------------------------------------------------
// Internal function that skips blank lines and comment lines
// and reads the next line it finds (up to 256 characters).
// Returns 0 is there was an error.
int vtkGenericEnSightReader::ReadNextDataLine(char result[256])
{
int isComment = 1;
int value = 1;
while( isComment && value )
{
value = this->ReadLine(result);
if( *result && result[0] != '#' )
{
size_t len = strlen( result );
unsigned int i = 0;
while( i < len && (static_cast<unsigned int>(result[i]) <= 255) && isspace(result[i]) )
{
++i;
}
// If there was only space characters this is a comment, thus skip it
if( i != len )
{
// The line was not empty, not beginning by '#' and not composed
// of only white space, this is not a comment
isComment = 0;
}
}
}
return value;
}
//----------------------------------------------------------------------------
int vtkGenericEnSightReader::RequestInformation(
vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
int version = this->DetermineEnSightVersion();
int createReader = 1;
if (version == vtkGenericEnSightReader::ENSIGHT_6)
{
vtkDebugMacro("EnSight6");
if (this->Reader)
{
if (strcmp(this->Reader->GetClassName(), "vtkEnSight6Reader") == 0)
{
createReader = 0;
}
else
{
this->Reader->Delete();
}
}
if (createReader)
{
this->Reader = vtkEnSight6Reader::New();
}
}
else if (version == vtkGenericEnSightReader::ENSIGHT_6_BINARY)
{
vtkDebugMacro("EnSight6 binary");
if (this->Reader)
{
if (strcmp(this->Reader->GetClassName(), "vtkEnSight6BinaryReader") == 0)
{
createReader = 0;
}
else
{
this->Reader->Delete();
}
}
if (createReader)
{
this->Reader = vtkEnSight6BinaryReader::New();
}
}
else if (version == vtkGenericEnSightReader::ENSIGHT_GOLD)
{
vtkDebugMacro("EnSightGold");
if (this->Reader)
{
if (strcmp(this->Reader->GetClassName(), "vtkEnSightGoldReader") == 0)
{
createReader = 0;
}
else
{
this->Reader->Delete();
}
}
if (createReader)
{
this->Reader = vtkEnSightGoldReader::New();
}
}
else if (version == vtkGenericEnSightReader::ENSIGHT_GOLD_BINARY)
{
vtkDebugMacro("EnSightGold binary");
if (this->Reader)
{
if (strcmp(this->Reader->GetClassName(),
"vtkEnSightGoldBinaryReader") == 0)
{
createReader = 0;
}
else
{
this->Reader->Delete();
}
}
if (createReader)
{
this->Reader = vtkEnSightGoldBinaryReader::New();
}
}
else
{
vtkErrorMacro("Error determining EnSightVersion");
this->EnSightVersion = -1;
return 0;
}
this->EnSightVersion = version;
// Copy current array selections to internal reader.
this->SetReaderDataArraySelectionSetsFromSelf();
this->Reader->SetReadAllVariables(this->ReadAllVariables);
this->Reader->SetCaseFileName(this->GetCaseFileName());
this->Reader->SetFilePath(this->GetFilePath());
// The following line, explicitly initializing this->ByteOrder to
// FILE_UNKNOWN_ENDIAN, MUST !!NOT!! be removed as it is used to
// force vtkEnSightGoldBinaryReader::ReadPartId(...) to determine
// the actual endian type. Otherwise the endian type, the default
// value from combobox 'Byte Order' of the user interface -------
// FILE_BIG_ENDIAN unless the user manually toggles the combobox,
// would be forwarded to this->Reader->ByteOrder through the next
// line and therefore would prevent vtkEnSightGoldBinaryReader::
// ReadPartId(...) from automatically checking the endian type. As
// a consequence, little-endian files such as the one mentioned in
// bug #0008237 would not be loadable. The following line might be
// removed ONLY WHEN the combobox is removed through
// ParaViews\Servers\ServerManager\Resources\readers.xml.
// Thus it is highly suggested that the following line be retained
// to guarantee the fix to bug #0007424 -- automatic determination
// of the endian type.
this->ByteOrder = FILE_UNKNOWN_ENDIAN;
this->Reader->SetByteOrder(this->ByteOrder);
this->Reader->RequestInformation(request, inputVector, outputVector);
this->Reader->SetParticleCoordinatesByIndex(this->ParticleCoordinatesByIndex);
this->SetTimeSets(this->Reader->GetTimeSets());
if(!this->TimeValueInitialized)
{
this->SetTimeValue(this->Reader->GetTimeValue());
}
this->MinimumTimeValue = this->Reader->GetMinimumTimeValue();
this->MaximumTimeValue = this->Reader->GetMaximumTimeValue();
// Copy new data array selections from internal reader.
this->SetDataArraySelectionSetsFromReader();
return 1;
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::AddVariableDescription(const char* description)
{
int size = this->NumberOfVariables;
int i;
char ** newDescriptionList = new char *[size]; // temporary array
// copy descriptions to temporary array
for (i = 0; i < size; i++)
{
newDescriptionList[i] =
new char[strlen(this->VariableDescriptions[i]) + 1];
strcpy(newDescriptionList[i], this->VariableDescriptions[i]);
delete [] this->VariableDescriptions[i];
}
delete [] this->VariableDescriptions;
// make room for new description
this->VariableDescriptions = new char *[size+1];
// copy existing descriptions back to first array
for (i = 0; i < size; i++)
{
this->VariableDescriptions[i] =
new char[strlen(newDescriptionList[i]) + 1];
strcpy(this->VariableDescriptions[i], newDescriptionList[i]);
delete [] newDescriptionList[i];
}
delete [] newDescriptionList;
// add new description at end of first array
this->VariableDescriptions[size] = new char[strlen(description) + 1];
strcpy(this->VariableDescriptions[size], description);
vtkDebugMacro("description: " << this->VariableDescriptions[size]);
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::AddComplexVariableDescription(const char* description)
{
int i;
int size = this->NumberOfComplexVariables;
char ** newDescriptionList = new char *[size]; // temporary array
// copy descriptions to temporary array
for (i = 0; i < size; i++)
{
newDescriptionList[i] =
new char[strlen(this->ComplexVariableDescriptions[i]) + 1];
strcpy(newDescriptionList[i], this->ComplexVariableDescriptions[i]);
delete [] this->ComplexVariableDescriptions[i];
}
delete [] this->ComplexVariableDescriptions;
// make room for new description
this->ComplexVariableDescriptions = new char *[size+1];
// copy existing descriptions back to first array
for (i = 0; i < size; i++)
{
this->ComplexVariableDescriptions[i] =
new char[strlen(newDescriptionList[i]) + 1];
strcpy(this->ComplexVariableDescriptions[i], newDescriptionList[i]);
delete [] newDescriptionList[i];
}
delete [] newDescriptionList;
// add new description at end of first array
this->ComplexVariableDescriptions[size] =
new char[strlen(description) + 1];
strcpy(this->ComplexVariableDescriptions[size], description);
vtkDebugMacro("description: "
<< this->ComplexVariableDescriptions[size]);
}
//----------------------------------------------------------------------------
int vtkGenericEnSightReader::GetNumberOfVariables(int type)
{
switch (type)
{
case vtkEnSightReader::SCALAR_PER_NODE:
return this->GetNumberOfScalarsPerNode();
case vtkEnSightReader::VECTOR_PER_NODE:
return this->GetNumberOfVectorsPerNode();
case vtkEnSightReader::TENSOR_SYMM_PER_NODE:
return this->GetNumberOfTensorsSymmPerNode();
case vtkEnSightReader::SCALAR_PER_ELEMENT:
return this->GetNumberOfScalarsPerElement();
case vtkEnSightReader::VECTOR_PER_ELEMENT:
return this->GetNumberOfVectorsPerElement();
case vtkEnSightReader::TENSOR_SYMM_PER_ELEMENT:
return this->GetNumberOfTensorsSymmPerElement();
case vtkEnSightReader::SCALAR_PER_MEASURED_NODE:
return this->GetNumberOfScalarsPerMeasuredNode();
case vtkEnSightReader::VECTOR_PER_MEASURED_NODE:
return this->GetNumberOfVectorsPerMeasuredNode();
case vtkEnSightReader::COMPLEX_SCALAR_PER_NODE:
return this->GetNumberOfComplexScalarsPerNode();
case vtkEnSightReader::COMPLEX_VECTOR_PER_NODE:
return this->GetNumberOfComplexVectorsPerNode();
case vtkEnSightReader::COMPLEX_SCALAR_PER_ELEMENT:
return this->GetNumberOfComplexScalarsPerElement();
case vtkEnSightReader::COMPLEX_VECTOR_PER_ELEMENT:
return this->GetNumberOfComplexVectorsPerElement();
default:
vtkWarningMacro("unknow variable type");
return -1;
}
}
//----------------------------------------------------------------------------
const char* vtkGenericEnSightReader::GetDescription(int n)
{
if (n < this->NumberOfVariables)
{
return this->VariableDescriptions[n];
}
return NULL;
}
//----------------------------------------------------------------------------
const char* vtkGenericEnSightReader::GetComplexDescription(int n)
{
if (n < this->NumberOfComplexVariables)
{
return this->ComplexVariableDescriptions[n];
}
return NULL;
}
//----------------------------------------------------------------------------
const char* vtkGenericEnSightReader::GetDescription(int n, int type)
{
int i, numMatches = 0;
if (type < 8)
{
for (i = 0; i < this->NumberOfVariables; i++)
{
if (this->VariableTypes[i] == type)
{
if (numMatches == n)
{
return this->VariableDescriptions[i];
}
else
{
numMatches++;
}
}
}
}
else
{
for (i = 0; i < this->NumberOfVariables; i++)
{
if (this->ComplexVariableTypes[i] == type)
{
if (numMatches == n)
{
return this->ComplexVariableDescriptions[i];
}
else
{
numMatches++;
}
}
}
}
return NULL;
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::AddVariableType(int variableType)
{
int size;
int i;
int *types;
size = this->NumberOfVariables;
types = new int[size];
for (i = 0; i < size; i++)
{
types[i] = this->VariableTypes[i];
}
delete [] this->VariableTypes;
this->VariableTypes = new int[size+1];
for (i = 0; i < size; i++)
{
this->VariableTypes[i] = types[i];
}
delete [] types;
this->VariableTypes[size] = variableType;
vtkDebugMacro("variable type: " << this->VariableTypes[size]);
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::AddComplexVariableType(int variableType)
{
int i;
int* types = NULL;
int size = this->NumberOfComplexVariables;
if (size > 0)
{
types = new int[size];
for (i = 0; i < size; i++)
{
types[i] = this->ComplexVariableTypes[i];
}
delete [] this->ComplexVariableTypes;
}
this->ComplexVariableTypes = new int[size+1];
for (i = 0; i < size; i++)
{
this->ComplexVariableTypes[i] = types[i];
}
if (size > 0)
{
delete [] types;
}
this->ComplexVariableTypes[size] = variableType;
vtkDebugMacro("complex variable type: "
<< this->ComplexVariableTypes[size]);
}
//----------------------------------------------------------------------------
int vtkGenericEnSightReader::GetVariableType(int n)
{
if (n < this->NumberOfVariables)
{
return this->VariableTypes[n];
}
return -1;
}
//----------------------------------------------------------------------------
int vtkGenericEnSightReader::GetComplexVariableType(int n)
{
if (n < this->NumberOfComplexVariables)
{
return this->ComplexVariableTypes[n];
}
return -1;
}
//----------------------------------------------------------------------------
int vtkGenericEnSightReader::ReplaceWildcards(char* fileName, int timeSet,
int fileSet)
{
char line[256], subLine[256];
int cmpTimeSet, cmpFileSet, fileNameNum, lineReadResult, lineScanResult;
std::string sfilename;
if ( this->FilePath )
{
sfilename = this->FilePath;
if ( sfilename.at( sfilename.length() - 1 ) != '/' )
{
sfilename += "/";
}
sfilename += this->CaseFileName;
vtkDebugMacro( "full path to case file: " << sfilename.c_str() );
}
else
{
sfilename = this->CaseFileName;
}
// We have got a valid CASE file name
this->IS = new ifstream( sfilename.c_str(), ios::in );
// Below is a revamped version of the code in support of inline & non-inline
// file name numbers, in a CASE file, of which the first one is obtained to
// make a geometry file name, through wildcards replacement, used to determine
// the specific EnSight version.
// Locate the 'TIME' section
do
{
if ( this->ReadNextDataLine(line) == 0 )
{
vtkErrorMacro(
"ReplaceWildCards() failed to find the 'TIME' section!" );
delete this->IS;
this->IS = NULL;
return 0;
}
} while ( strncmp(line, "TIME", 4) != 0 );
// Locate the very 'time set' entry by the index
cmpTimeSet = -10000;
do
{
if ( this->ReadNextDataLine(line) == 0 )
{
vtkErrorMacro(
"ReplaceWildCards() failed to find the target 'time set' entry!" );
delete this->IS;
this->IS = NULL;
return 0;
}
// 'time set: <int>' --- where to obtain cmpTimeSet, a time set index
lineScanResult = sscanf(line, "%*s %s %d", subLine, &cmpTimeSet);
} while ( lineScanResult != 2 || strncmp(line, "time", 4) != 0 ||
strncmp(subLine, "set", 3) != 0 || cmpTimeSet != timeSet );
// Skip 'time set: <int>' and 'number of steps: <int>' to go to
// 'filename xxx: ...' --- where to obtain the actual file name number(s)
for ( int i = 0; i < 2; i ++ )
{
lineReadResult = this->ReadNextDataLine(line);
if ( lineReadResult == 0 ||
// check 'filename xxx: ...' upon the second line (i = 1)
( i == 1 &&
( strncmp(line, "filename", 8) != 0 ||
sscanf(line, "%*s %s", subLine) != 1
)
)
)
{
vtkErrorMacro(
"ReplaceWildCards() failed to find the target 'filename ...: ...' entry!" );
delete this->IS;
this->IS = NULL;
return 0;
}
}
fileNameNum = -10000;
// 'filename numbers: ...'
if ( strncmp(subLine, "numbers", 7) == 0 )
{
// The filename number(s) may be provided on the line(s) following
// 'filename numbers:', as is usually the case --- not "inline". Thus we
// need to go to the FIRST line that indeed contains the filename number(s).
// Note that we only need to obtain the FIRST file name number since a
// single geometry file allows us to determine the EnSight version. This is
// based on the reasonable assumption that all geometry files referenced by
// a CASE file have the same EnSight version.
// not "inline"
if ( sscanf(line, "%*s %*s %d", &fileNameNum) != 1 )
{
// let's go to the next VALID line that might be several empty lines apart
if ( this->ReadNextDataLine(line) == 0 )
{
vtkErrorMacro(
"ReplaceWildCards() failed to obtain any non-inline file name number!" );
delete this->IS;
this->IS = NULL;
return 0;
}
// obtain the first file name number from the next valid line
sscanf(line, "%d", &fileNameNum);
}
}
// 'filename start number: ...' --- followed by 'filename increment: ...'
else
{
char subSubLine[256];
lineScanResult = sscanf( line, "%*s %s %s %d",
subLine, subSubLine, &fileNameNum );
if ( lineScanResult != 3 ||
strncmp(subLine, "start", 5) != 0 ||
strncmp(subSubLine, "number", 6) != 0
)
{
vtkErrorMacro(
"ReplaceWildCards() failed to find 'filename start number: <int>'!" );
delete this->IS;
this->IS = NULL;
return 0;
}
}
// Let's resort to the 'FILE' section, just in case of a failure so far
if ( fileNameNum == -10000 )
{
// Locate the 'FILE' section
do
{
if ( this->ReadNextDataLine(line) == 0 )
{
vtkErrorMacro(
"ReplaceWildCards() failed to find the optional 'FILE' section!" );
delete this->IS;
this->IS = NULL;
return 0;
}
} while ( strncmp(line, "FILE", 4) != 0 );
// Locate the very 'file set' entry by the index
cmpFileSet = -10000;
do
{
if ( this->ReadNextDataLine(line) == 0 )
{
vtkErrorMacro(
"ReplaceWildCards() failed to find the target 'file set' entry!" );
delete this->IS;
this->IS = NULL;
return 0;
}
// 'file set: <int>' --- to obtain cmpFileSet, a file set index
lineScanResult = sscanf(line, "%*s %s %d", subLine, &cmpFileSet);
} while ( lineScanResult != 2 || strncmp(line, "file", 4) != 0 ||
strncmp(subLine, "set", 3) != 0 || cmpFileSet != fileSet );
// Skip 'file set: <int>' to go to
// 'filename index: <int>' --- where to obtain ONE actual file name
// Note that we here do NOT allow any non-'inline' scenarios since
// there is ONE AND ONLY ONE integer value, within a 'filename index: <int>'
// entry, that is used to specify a file name index. Thus any violation
// of this reasonable assumption is considered to use an invalid EnSight
// format that needs to be corrected by the EnSight CASE file user.
lineReadResult = this->ReadNextDataLine(line);
lineScanResult = sscanf( line, "%*s %s %d", subLine, &fileNameNum );
if ( lineReadResult == 0 || lineScanResult != 2 ||
strncmp(line, "filename", 8) != 0 || strncmp(subLine, "index", 5) != 0
)
{
vtkErrorMacro(
"ReplaceWildCards() failed to find 'filename index: <int>'!" );
delete this->IS;
this->IS = NULL;
return 0;
}
}
// So far we have got a file name index
this->ReplaceWildcardsHelper(fileName, fileNameNum);
delete this->IS;
this->IS = NULL;
return 1;
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::ReplaceWildcardsHelper(char* fileName, int num)
{
int wildcardPos, numWildcards, numDigits = 1, i;
int tmpNum = num, multTen = 1;
char newChar;
int newNum;
wildcardPos = static_cast<int>(strcspn(fileName, "*"));
numWildcards = static_cast<int>(strspn(fileName + wildcardPos, "*"));
tmpNum /= 10;
while (tmpNum >= 1)
{
numDigits++;
multTen *= 10;
tmpNum /= 10;
}
for (i = 0; i < numWildcards - numDigits; i++)
{
fileName[i + wildcardPos] = '0';
}
tmpNum = num;
for (i = numWildcards - numDigits; i < numWildcards; i++)
{
newNum = tmpNum / multTen;
switch (newNum)
{
case 0:
newChar = '0';
break;
case 1:
newChar = '1';
break;
case 2:
newChar = '2';
break;
case 3:
newChar = '3';
break;
case 4:
newChar = '4';
break;
case 5:
newChar = '5';
break;
case 6:
newChar = '6';
break;
case 7:
newChar = '7';
break;
case 8:
newChar = '8';
break;
case 9:
newChar = '9';
break;
default:
// This case should never be reached.
return;
}
assert( newChar == ('0' + newNum) );
fileName[i + wildcardPos] = newChar;
tmpNum -= multTen * newNum;
multTen /= 10;
}
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::SetByteOrderToBigEndian()
{
this->ByteOrder = FILE_BIG_ENDIAN;
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::SetByteOrderToLittleEndian()
{
this->ByteOrder = FILE_LITTLE_ENDIAN;
}
//----------------------------------------------------------------------------
const char *vtkGenericEnSightReader::GetByteOrderAsString()
{
if ( this->ByteOrder == FILE_LITTLE_ENDIAN)
{
return "LittleEndian";
}
else
{
return "BigEndian";
}
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "CaseFileName: "
<< (this->CaseFileName ? this->CaseFileName : "(none)") << endl;
os << indent << "FilePath: "
<< (this->FilePath ? this->FilePath : "(none)") << endl;
os << indent << "EnSight Version: "
<< this->EnSightVersion << endl;
os << indent << "NumberOfComplexVariables: "
<< this->NumberOfComplexVariables << endl;
os << indent << "NumberOfVariables: "
<< this->NumberOfVariables << endl;
os << indent << "NumberOfComplexScalarsPerNode: "
<< this->NumberOfComplexScalarsPerNode << endl;
os << indent << "NumberOfVectorsPerElement :"
<< this->NumberOfVectorsPerElement << endl;
os << indent << "NumberOfTensorsSymmPerElement: "
<< this->NumberOfTensorsSymmPerElement << endl;
os << indent << "NumberOfComplexVectorsPerNode: "
<< this->NumberOfComplexVectorsPerNode << endl;
os << indent << "NumberOfScalarsPerElement: "
<< this->NumberOfScalarsPerElement << endl;
os << indent << "NumberOfComplexVectorsPerElement: "
<< this->NumberOfComplexVectorsPerElement << endl;
os << indent << "NumberOfComplexScalarsPerElement: "
<< this->NumberOfComplexScalarsPerElement << endl;
os << indent << "NumberOfTensorsSymmPerNode: "
<< this->NumberOfTensorsSymmPerNode << endl;
os << indent << "NumberOfScalarsPerMeasuredNode: "
<< this->NumberOfScalarsPerMeasuredNode << endl;
os << indent << "NumberOfVectorsPerMeasuredNode: "
<< this->NumberOfVectorsPerMeasuredNode << endl;
os << indent << "NumberOfScalarsPerNode: "
<< this->NumberOfScalarsPerNode << endl;
os << indent << "NumberOfVectorsPerNode: "
<< this->NumberOfVectorsPerNode << endl;
os << indent << "TimeValue: " << this->TimeValue << endl;
os << indent << "MinimumTimeValue: " << this->MinimumTimeValue << endl;
os << indent << "MaximumTimeValue: " << this->MaximumTimeValue << endl;
os << indent << "TimeSets: " << this->TimeSets << endl;
os << indent << "ReadAllVariables: " << this->ReadAllVariables << endl;
os << indent << "ByteOrder: " << this->ByteOrder << endl;
os << indent << "ParticleCoordinatesByIndex: " << this->ParticleCoordinatesByIndex << endl;
os << indent << "CellDataArraySelection: " << this->CellDataArraySelection
<< endl;
os << indent << "PointDataArraySelection: " << this->PointDataArraySelection
<< endl;
os << indent << "GeometryFileName: " <<
(this->GeometryFileName ? this->GeometryFileName : "(none)") << endl;
}
//----------------------------------------------------------------------------
char** vtkGenericEnSightReader::CreateStringArray(int numStrings)
{
char** strings = new char*[numStrings];
int i;
for(i=0; i < numStrings; ++i)
{
strings[i] = 0;
}
return strings;
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::DestroyStringArray(int numStrings,
char** strings)
{
for(int i=0; i < numStrings; ++i)
{
delete [] strings[i];
}
delete[] strings;
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::SetDataArraySelectionSetsFromVariables()
{
int numPointArrays = (this->NumberOfScalarsPerNode +
this->NumberOfVectorsPerNode +
this->NumberOfTensorsSymmPerNode +
this->NumberOfScalarsPerMeasuredNode +
this->NumberOfVectorsPerMeasuredNode +
this->NumberOfComplexScalarsPerNode +
this->NumberOfComplexVectorsPerNode);
int numCellArrays = (this->NumberOfScalarsPerElement +
this->NumberOfVectorsPerElement +
this->NumberOfTensorsSymmPerElement +
this->NumberOfComplexScalarsPerElement +
this->NumberOfComplexVectorsPerElement);
char** pointNames = this->CreateStringArray(numPointArrays);
char** cellNames = this->CreateStringArray(numCellArrays);
int pointArrayCount = 0;
int cellArrayCount = 0;
int i;
for(i=0; i < this->NumberOfVariables; ++i)
{
switch (this->VariableTypes[i])
{
case vtkEnSightReader::SCALAR_PER_NODE:
case vtkEnSightReader::VECTOR_PER_NODE:
case vtkEnSightReader::TENSOR_SYMM_PER_NODE:
case vtkEnSightReader::SCALAR_PER_MEASURED_NODE:
case vtkEnSightReader::VECTOR_PER_MEASURED_NODE:
pointNames[pointArrayCount] =
new char[strlen(this->VariableDescriptions[i])+1];
strcpy(pointNames[pointArrayCount], this->VariableDescriptions[i]);
++pointArrayCount;
break;
case vtkEnSightReader::SCALAR_PER_ELEMENT:
case vtkEnSightReader::VECTOR_PER_ELEMENT:
case vtkEnSightReader::TENSOR_SYMM_PER_ELEMENT:
cellNames[cellArrayCount] =
new char[strlen(this->VariableDescriptions[i])+1];
strcpy(cellNames[cellArrayCount], this->VariableDescriptions[i]);
++cellArrayCount;
break;
}
}
for(i=0; i < this->NumberOfComplexVariables; ++i)
{
switch(this->ComplexVariableTypes[i])
{
case vtkEnSightReader::COMPLEX_SCALAR_PER_NODE:
case vtkEnSightReader::COMPLEX_VECTOR_PER_NODE:
pointNames[pointArrayCount] =
new char[strlen(this->ComplexVariableDescriptions[i])+1];
strcpy(pointNames[pointArrayCount],
this->ComplexVariableDescriptions[i]);
++pointArrayCount;
break;
case vtkEnSightReader::COMPLEX_SCALAR_PER_ELEMENT:
case vtkEnSightReader::COMPLEX_VECTOR_PER_ELEMENT:
cellNames[cellArrayCount] =
new char[strlen(this->ComplexVariableDescriptions[i])+1];
strcpy(cellNames[cellArrayCount],
this->ComplexVariableDescriptions[i]);
++cellArrayCount;
break;
}
}
this->PointDataArraySelection->SetArraysWithDefault(pointNames,
numPointArrays,
this->ReadAllVariables);
this->CellDataArraySelection->SetArraysWithDefault(cellNames,
numCellArrays,
this->ReadAllVariables);
this->DestroyStringArray(numPointArrays, pointNames);
this->DestroyStringArray(numCellArrays, cellNames);
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::SetDataArraySelectionSetsFromReader()
{
this->SelectionModifiedDoNotCallModified = 1;
this->PointDataArraySelection->CopySelections(
this->Reader->GetPointDataArraySelection());
this->CellDataArraySelection->CopySelections(
this->Reader->GetCellDataArraySelection());
this->SelectionModifiedDoNotCallModified = 0;
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::SetReaderDataArraySelectionSetsFromSelf()
{
// Set the real reader's data array selections from ours.
this->Reader->GetPointDataArraySelection()->CopySelections(
this->PointDataArraySelection);
this->Reader->GetCellDataArraySelection()->CopySelections(
this->CellDataArraySelection);
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::SelectionModifiedCallback(vtkObject*,
unsigned long,
void* clientdata,
void*)
{
static_cast<vtkGenericEnSightReader*>(clientdata)->SelectionModified();
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::SelectionModified()
{
if(!this->SelectionModifiedDoNotCallModified)
{
this->Modified();
}
}
//----------------------------------------------------------------------------
int vtkGenericEnSightReader::GetNumberOfPointArrays()
{
return this->PointDataArraySelection->GetNumberOfArrays();
}
//----------------------------------------------------------------------------
const char* vtkGenericEnSightReader::GetPointArrayName(int index)
{
return this->PointDataArraySelection->GetArrayName(index);
}
//----------------------------------------------------------------------------
int vtkGenericEnSightReader::GetPointArrayStatus(const char* name)
{
return this->PointDataArraySelection->ArrayIsEnabled(name);
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::SetPointArrayStatus(const char* name, int status)
{
if(status)
{
this->PointDataArraySelection->EnableArray(name);
}
else
{
this->PointDataArraySelection->DisableArray(name);
}
}
//----------------------------------------------------------------------------
int vtkGenericEnSightReader::GetNumberOfCellArrays()
{
return this->CellDataArraySelection->GetNumberOfArrays();
}
//----------------------------------------------------------------------------
const char* vtkGenericEnSightReader::GetCellArrayName(int index)
{
return this->CellDataArraySelection->GetArrayName(index);
}
//----------------------------------------------------------------------------
int vtkGenericEnSightReader::GetCellArrayStatus(const char* name)
{
return this->CellDataArraySelection->ArrayIsEnabled(name);
}
//----------------------------------------------------------------------------
void vtkGenericEnSightReader::SetCellArrayStatus(const char* name, int status)
{
if(status)
{
this->CellDataArraySelection->EnableArray(name);
}
else
{
this->CellDataArraySelection->DisableArray(name);
}
}
//----------------------------------------------------------------------------
int vtkGenericEnSightReader::InsertNewPartId(int partId)
{
int lastId = static_cast<int>(this->TranslationTable->PartIdMap.size());
this->TranslationTable->PartIdMap.insert(
std::map<int,int>::value_type(partId, lastId));
lastId = this->TranslationTable->PartIdMap[partId];
//assert( lastId == this->PartIdTranslationTable[partId] );
return lastId;
}
//----------------------------------------------------------------------------
int vtkGenericEnSightReader::FillOutputPortInformation(int vtkNotUsed(port),
vtkInformation* info)
{
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkMultiBlockDataSet");
return 1;
}
|