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
|
#include <hdf5.h>
#include <visit-hdf5.h>
#if HDF5_VERSION_GE(1, 8, 1)
/**
* @file VsMeta.h
*
* @class VsMeta
*
* @brief VsMeta represents vizschema metadata
*
* Copyright © 2007 by Tech-X Corporation
*/
#ifndef VS_META_H
#define VS_META_H
#include <string>
#include <map>
#include <iostream>
#include <vector>
// HDF5
#include <hdf5.h>
#include <VsH5Meta.h>
#include <VsSchema.h>
struct VsVariableMeta {
// Constructor
VsVariableMeta() {
indexOrder = VsSchema::compMinorCKey; //default
dataset = 0;
centering = "nodal";
}
// Name of the mesh
std::string mesh;
// Component order, if defined
std::string indexOrder;
bool isZonal() const {
return (centering == VsSchema::zonalCenteringKey);
}
bool isCompMinor() const {
if ((indexOrder == VsSchema::compMinorCKey) ||
(indexOrder == VsSchema::compMinorFKey))
return true;
return false;
}
bool isCompMajor() const {
if ((indexOrder == VsSchema::compMajorCKey) ||
(indexOrder == VsSchema::compMajorFKey))
return true;
return false;
}
// Get user-specified component names
std::vector<std::string> labelNames;
std::string getLabel (unsigned int i) const {
if ((i >= 0) && (i < labelNames.size()) && !labelNames[i].empty()) {
return makeCanonicalName(path, labelNames[i]);
}
return "";
}
// Centering, if defined
std::string centering;
// Dataset
VsDMeta* dataset;
//fully qualified path to this object
std::string path;
// Get dims
std::vector<int> getDims() const {
return dataset->dims;
}
// Get mesh name
std::string getMesh() const {
return mesh;
}
// Get hdf5 type
hid_t getType() const {
return dataset->type;
}
// Get length needed to store all elements in their format
size_t getLength() const {
return dataset->getLength();
}
// Get name
std::string getName () const {
return dataset->name;
}
// Get full name
std::string getFullName() const {
return dataset->getFullName();
}
// Find attribute by name, or return NULL if not found
const VsAMeta* find(const std::string name) const {
return dataset->find(name);
}
std::string getStringAttribute(const std::string name) const {
const VsAMeta* foundAtt = find(name);
if (foundAtt == NULL)
return "";
std::string result = "";
herr_t err = getAttributeHelper((foundAtt)->aid, &result, 0, 0);
if (err < 0 ) {
result = "";
}
/*
if (result.empty()) {
std::string msg = "VsVariableMeta::getStringAttribute(" + attName + ") - failed to find attribute in object " + getFullName();
//debugStrmRef << msg << std::endl;
}
else {
std::string msg = "VsMeta::getStringAttribute(" + attName + ") - found attribute in object " + getFullName();
msg += " - value is " + result;
//debugStrmRef << msg << std::endl;
}*/
return result;
}
// Write
void write(std::ostream& os) const {
if (dataset) dataset->write(os);
os << " indexOrder = " << indexOrder << std::endl;
os << " centering = " << centering << std::endl;
os << " mesh = " << mesh << std::endl;
}
};
struct VsMDVariableMeta {
/** List of all subordinate blocks in this var
* Order is important (block 0 = blocks[0], etc)*/
std::vector<VsVariableMeta*> blocks;
// Constructor
VsMDVariableMeta(std::string meshString, std::string centeringString, std::string indexOrderString) {
mesh = meshString;
indexOrder = indexOrderString;
centering = centeringString;
//default behaviors
//indexOrder = VsSchema::compMinorCKey;
//centering = "nodal";
}
//Destructor
~VsMDVariableMeta() {
for (std::vector<VsVariableMeta*>::iterator it = blocks.begin(); it != blocks.end(); it++) {
delete (*it);
}
blocks.clear();
}
//we look for user-specified component names in each subordinate variable
//we return the first one we find
std::string getLabel(int componentIndex) const {
std::string name;
name.clear();
for (unsigned int i = 0; i < blocks.size(); i++) {
name = blocks[i]->getLabel(componentIndex);
if (!name.empty())
return name;
}
return "";
}
std::string name;
// Name of the mesh
std::string mesh;
// Component order, if defined
std::string indexOrder;
bool isZonal() const {
return (centering == VsSchema::zonalCenteringKey);
}
// Centering, if defined
std::string centering;
//fully qualified path to this object
std::string path;
std::string addBlock(VsVariableMeta* newBlock) {
//all blocks must match
//Special note here: the mesh of newBlock will be the NON-MD mesh
//But all we know is the name of the MD mesh
//In theory we can look up the subordinate mesh here,
//but I'm leaving it as a todo for now
///TODO: look up subordinate mesh name
// if (newBlock->mesh != mesh)
// return "VsMDVariableMeta rejected new block " + newBlock->getFullName() + " because meshes did not match (" + newBlock->mesh + " vs " + mesh + ")";
if (newBlock->centering != centering)
return "VsMDVariableMeta rejected new block " + newBlock->getFullName() + " because centering did not match (" + newBlock->centering + " vs " + centering + ")";
if (newBlock->indexOrder != indexOrder)
return "VsMDVariableMeta rejected new block " + newBlock->getFullName() + " because indexOrder did not match (" + newBlock->indexOrder + " vs " + indexOrder + ")";
blocks.push_back(newBlock);
return "";
}
unsigned int getNumBlocks() const {
return blocks.size();
}
std::string getNameForBlock(unsigned int domain) const {
if (domain >= blocks.size())
return NULL;
VsVariableMeta* foundVar = blocks[domain];
return foundVar->getFullName();
}
VsVariableMeta* getBlock(unsigned int domain) const {
if (domain >= blocks.size())
return NULL;
VsVariableMeta* foundVar = blocks[domain];
return foundVar;
}
// Get mesh name
std::string getMesh() const {
return mesh;
}
// Get hdf5 type
hid_t getType() const {
if (!blocks.empty()) {
return blocks[0]->getType();
}
return 0;
}
/*
// Get length needed to store all elements in their format
size_t getLength() const {
return dataset->getLength();
}
*/
// Get name
std::string getName() const {
return name;
}
// Get full name
std::string getFullName() const {
return makeCanonicalName(path, name);
}
// Write
void write(std::ostream& os) const {
os <<" MDVar: " <<getFullName() <<std::endl;
for (unsigned int i = 0; i < blocks.size(); i++) {
os <<" block #" <<i <<std::endl;
blocks[i]->write(os);
}
os << " indexOrder = " << indexOrder << std::endl;
os << " centering = " << centering << std::endl;
os << " MD mesh = " << mesh << std::endl;
}
};
// Metadata for particles should include number of spatial dims.
struct VsVariableWithMeshMeta {
// Constructor
VsVariableWithMeshMeta() {
indexOrder = VsSchema::compMinorCKey;
dataset = 0;
}
// We now maintain a list of the indices of the spatial dims
std::vector<int> spatialIndices;
unsigned int getNumSpatialDims() const {
return spatialIndices.size();
}
//retrieve a particular spatial dimension index from the list
//returns -1 on failure
int getSpatialDim(size_t index) const {
if ((index < 0) || (index > spatialIndices.size())) {
return -1;
}
return spatialIndices[index];
}
//retrieve the entire list of spatial indices
std::vector<int> getSpatialIndices() const {
return spatialIndices;
}
bool isCompMinor() const {
if ((indexOrder == VsSchema::compMinorCKey) ||
(indexOrder == VsSchema::compMinorFKey))
return true;
return false;
}
bool isCompMajor() const {
if ((indexOrder == VsSchema::compMajorCKey) ||
(indexOrder == VsSchema::compMajorFKey))
return true;
return false;
}
// Order if defined
std::string indexOrder;
// Dataset
VsDMeta* dataset;
// Get dims
std::vector<int> getDims() const {
return dataset->dims;
}
// Get type
hid_t getType() const {
return dataset->type;
}
// Get length
size_t getLength() const {
return dataset->getLength();
}
// Get name
std::string getName () const {
return dataset->name;
}
// Get user-specified component names
std::vector<std::string> labelNames;
std::string getLabel (unsigned int i) const {
if ((i >= 0) && (i < labelNames.size()) && !labelNames[i].empty()) {
return makeCanonicalName(getPath(), labelNames[i]);
}
return "";
}
//get full name
std::string getFullName() const {
return dataset->getFullName();
}
//get path
std::string getPath() const {
return dataset->path;
}
void write(std::ostream& os) const {
if (dataset) dataset->write(os);
os << " numSpatialDims = " << getNumSpatialDims() << std::endl;
os << " spatialIndices = [";
for (unsigned int i = 0; i < getNumSpatialDims(); i++) {
os << spatialIndices[i];
if (i + 1 < getNumSpatialDims()) {
os <<", ";
}
}
os <<"]" <<std::endl;
os << " indexOrder = " << indexOrder << std::endl;
}
};
// Metadata for geometry should include a list of its components.
struct VsMeshMeta {
VsMeshMeta() {
numSpatialDims = 0;
indexOrder = VsSchema::compMinorCKey;
}
void write(std::ostream& os) const {
os << " Index Order: " << indexOrder << std::endl;
os << " NumSpatialDims: " <<numSpatialDims <<std::endl;
os << " Datasets:" << std::endl;
std::map<std::string, VsDMeta*>::const_iterator i;
for (i = dComps.begin(); i != dComps.end(); ++i)
os << " " << i->first << std::endl;
os << " Attributes:" << std::endl;
std::map<std::string, VsAMeta*>::const_iterator k;
for (k = aComps.begin(); k != aComps.end(); ++k)
os << " " << k->first << std::endl;
}
bool isFortranOrder() const {
if ((indexOrder == VsSchema::compMinorFKey) ||
(indexOrder == VsSchema::compMajorFKey))
return true;
return false;
}
bool isCompMinor() const {
if ((indexOrder == VsSchema::compMinorCKey) ||
(indexOrder == VsSchema::compMinorFKey))
return true;
return false;
}
bool isCompMajor() const {
if ((indexOrder == VsSchema::compMajorCKey) ||
(indexOrder == VsSchema::compMajorFKey))
return true;
return false;
}
bool isUniformMesh() const {
return ((kind == VsSchema::Uniform::key) || (kind == VsSchema::Uniform::deprecated_key));
}
bool isUnstructuredMesh() const {
return (kind == VsSchema::Unstructured::key);
}
bool isRectilinearMesh() const {
return (kind == VsSchema::Rectilinear::key);
}
bool isStructuredMesh() const {
return (kind == VsSchema::structuredMeshKey);
}
/** The kind of the mesh (e.g., structured, uniform, ... */
std::string kind;
/** The spatial dimensionality */
size_t numSpatialDims;
/** Index order (Fortran vs C style) */
std::string indexOrder;
/* name */
std::string name;
/* path */
std::string path;
/** Map of names of data sets to the metadata for that dataset */
std::map<std::string, VsDMeta*> dComps;
/** Map of names of attributes to the metadata for that attribute */
std::map<std::string, VsAMeta*> aComps;
std::string getFullName() const {
return makeCanonicalName(path, name);
}
std::string getStringAttribute(std::string attName) const {
std::map<std::string, VsAMeta*>::const_iterator it = aComps.find(attName);
std::string result = "";
if (it != aComps.end()) {
VsAMeta* foundAtt = it->second;
herr_t err = getAttributeHelper((foundAtt)->aid, &result, 0, 0);
if (err < 0 ) {
result = "";
}
}
/*
if (result.empty()) {
std::string msg = "VsMeta::getStringAttribute(" + attName + ") - failed to find attribute in object " + getFullName();
debugStrmRef << msg << std::endl;
}
else {
std::string msg = "VsMeta::getStringAttribute(" + attName + ") - found attribute in object " + getFullName();
msg += " - value is " + result;
debugStrmRef << msg << std::endl;
}
*/
return result;
}
VsDMeta* getDataset(std::string name) const {
std::map<std::string, VsDMeta*>::const_iterator i;
for (i = dComps.begin(); i != dComps.end(); ++i) {
if (i->first == name)
return i->second;
}
return NULL;
}
VsAMeta* getAttribute(std::string name) const {
std::map<std::string, VsAMeta*>::const_iterator i;
for (i = aComps.begin(); i != aComps.end(); ++i) {
if (i->first == name)
return i->second;
}
return NULL;
}
int numnodes;
};
struct VsRectilinearMesh : public VsMeshMeta {
hid_t getDataType() const {
VsDMeta* axis0 = getAxisDataset(0);
if (axis0 == NULL) {
//ERROR!
return H5T_NATIVE_DOUBLE; //?
}
return axis0->type;
}
std::string getAxisDatasetName(int axisNumber) const {
if ((axisNumber < 0) || (axisNumber > 2)) {
return "";
}
std::string axisKey;
switch (axisNumber) {
case 0: axisKey = VsSchema::Rectilinear::axis0Key;
break;
case 1: axisKey = VsSchema::Rectilinear::axis1Key;
break;
case 2: axisKey = VsSchema::Rectilinear::axis2Key;
break;
default:
return "";
break;
}
//First see if the user has specified a name for the dataset
std::string axisName = getStringAttribute(axisKey);
if (!axisName.empty()) {
return axisName;
}
//if we didn't find a user supplied name, try the default name
std::string defaultAxisName;
switch (axisNumber) {
case 0: defaultAxisName = VsSchema::Rectilinear::axis0DefaultName;
break;
case 1: defaultAxisName = VsSchema::Rectilinear::axis1DefaultName;
break;
case 2: defaultAxisName = VsSchema::Rectilinear::axis2DefaultName;
break;
default:
return "";
break;
}
axisName = getStringAttribute(defaultAxisName);
//axisName
return axisName;
}
//NOTE - cannot be used to get datasets that are not members of this group
VsDMeta* getAxisDataset(int axisNumber) const {
std::string axisDatasetName = getAxisDatasetName(axisNumber);
if (axisDatasetName.empty()) {
return NULL;
}
//We look inside our own datasets
VsDMeta* answer = getDataset(axisDatasetName);
//At this point
return answer; //could be NULL
}
};
struct VsUniformMesh : public VsMeshMeta {
hid_t getDataType() const {
VsAMeta* lowerBounds = getAttribute(VsSchema::Uniform::lowerBounds);
if (lowerBounds == NULL) {
//ERROR!
return H5T_NATIVE_DOUBLE; //?
}
return lowerBounds->type;
}
};
struct VsUnstructuredMesh : public VsMeshMeta {
bool usesSplitPoints() const {
if (getPointsDatasetName().empty())
return true;
return false;
}
std::string getPointsDatasetName() const {
//First see if the user has specified a name for the dataset
std::string pointsName = getStringAttribute(VsSchema::Unstructured::vsPoints);
if (!pointsName.empty()) {
return pointsName;
}
//if we didn't find vsPoints, try the default name
pointsName = getStringAttribute(VsSchema::Unstructured::defaultPointsName);
if (!pointsName.empty()) {
return pointsName;
}
return "";
}
hid_t getDataType() const {
VsDMeta* pointsDataset = getPointsDataset();
if (pointsDataset != NULL) {
return pointsDataset->type;
}
//TODO: cache the type of points0, points1, points2?
//TODO: make sure all are the same type
return H5T_NATIVE_FLOAT;
}
std::string getPointsDatasetName(int i) const {
//Ok, try vspoints0, vspoints1, vspoints2
std::string attributeName = VsSchema::Unstructured::vsPoints0;
if (i == 1)
attributeName = VsSchema::Unstructured::vsPoints1;
else if (i == 2)
attributeName = VsSchema::Unstructured::vsPoints2;
std::string fullName = getStringAttribute(attributeName); //might be empty
//if the name was found, make sure it's fully qualified
if (!fullName.empty()) {
fullName = makeCanonicalName(path, fullName);
}
return fullName;
}
//NOTE - cannot be used to get vspoints0, vspoints1, vspoints2
//because they are not dataset members of this group
VsDMeta* getPointsDataset() const {
std::string pointsName = getPointsDatasetName();
if (pointsName.empty()) {
return NULL;
}
//We look inside our own datasets
VsDMeta* answer = getDataset(pointsName);
//At this point
return answer; //could be NULL
}
/*
VsDMeta* getPointsDataset() {
return getPointsDataset(0);
}
VsDMeta* getPointsDataset(int i) {
std::string pointsName = getPointsDatasetName(i);
if (pointsName.empty()) {
return NULL;
}
//first we look inside our own datasets
VsDMeta* answer = getDataset(pointsName);
//next we try the global registry
if (answer == NULL) {
answer = VsH5Meta::getDataset(pointsName);
}
return answer; //could be NULL
}*/
std::string getPolygonsDatasetName() const {
//First see if the user has specified a name for the dataset
std::string polygonsName = getStringAttribute(VsSchema::Unstructured::vsPolygons);
if (!polygonsName.empty()) {
return polygonsName;
}
//if we didn't find anything, try the default name
polygonsName = getStringAttribute(VsSchema::Unstructured::defaultPolygonsName);
return polygonsName; //could be empty
}
VsDMeta* getPolygonsDataset() const {
std::string polygonsName = getPolygonsDatasetName();
if (polygonsName.empty()) {
return NULL;
}
return getDataset(polygonsName);
}
std::string getPolyhedraDatasetName() const {
//First see if the user has specified a name for the dataset
std::string polyhedraName = getStringAttribute(VsSchema::Unstructured::vsPolyhedra);
if (!polyhedraName.empty()) {
return polyhedraName;
}
//if we didn't find anything, try the default name
polyhedraName = getStringAttribute(VsSchema::Unstructured::defaultPolyhedraName);
return polyhedraName; //could be empty
}
VsDMeta* getPolyhedraDataset() const {
std::string polyhedraName = getPolyhedraDatasetName();
if (polyhedraName.empty()) {
return NULL;
}
return getDataset(polyhedraName);
}
std::string getLinesDatasetName() const {
//First see if the user has specified a name for the dataset
std::string linesName = getStringAttribute(VsSchema::Unstructured::vsLines);
if (!linesName.empty()) {
return linesName;
}
//if we didn't find anything, try the default name
linesName = getStringAttribute(VsSchema::Unstructured::defaultLinesName);
return linesName; //could be empty
}
VsDMeta* getLinesDataset() const {
std::string linesName = getLinesDatasetName();
if (linesName.empty()) {
return NULL;
}
return getDataset(linesName);
}
std::string getTrianglesDatasetName() const {
//First see if the user has specified a name for the dataset
std::string trianglesName = getStringAttribute(VsSchema::Unstructured::vsTriangles);
if (!trianglesName.empty()) {
return trianglesName;
}
//if we didn't find anything, try the default name
trianglesName = getStringAttribute(VsSchema::Unstructured::defaultTrianglesName);
return trianglesName; //could be empty
}
VsDMeta* getTrianglesDataset() const {
std::string trianglesName = getTrianglesDatasetName();
if (trianglesName.empty()) {
return NULL;
}
return getDataset(trianglesName);
}
std::string getQuadrilateralsDatasetName() const {
//First see if the user has specified a name for the dataset
std::string quadrilateralsName = getStringAttribute(VsSchema::Unstructured::vsQuadrilaterals);
if (!quadrilateralsName.empty()) {
return quadrilateralsName;
}
//if we didn't find anything, try the default name
quadrilateralsName = getStringAttribute(VsSchema::Unstructured::defaultQuadrilateralsName);
return quadrilateralsName; //could be empty
}
VsDMeta* getQuadrilateralsDataset() const {
std::string quadrilateralsName = getQuadrilateralsDatasetName();
if (quadrilateralsName.empty()) {
return NULL;
}
return getDataset(quadrilateralsName);
}
std::string getTetrahedralsDatasetName() const {
//First see if the user has specified a name for the dataset
std::string tetrahedralsName = getStringAttribute(VsSchema::Unstructured::vsTetrahedrals);
if (!tetrahedralsName.empty()) {
return tetrahedralsName;
}
//if we didn't find anything, try the default name
tetrahedralsName = getStringAttribute(VsSchema::Unstructured::defaultTetrahedralsName);
return tetrahedralsName; //could be empty
}
VsDMeta* getTetrahedralsDataset() const {
std::string tetrahedralsName = getTetrahedralsDatasetName();
if (tetrahedralsName.empty()) {
return NULL;
}
return getDataset(tetrahedralsName);
}
std::string getPyramidsDatasetName() const {
//First see if the user has specified a name for the dataset
std::string pyramidsName = getStringAttribute(VsSchema::Unstructured::vsPyramids);
if (!pyramidsName.empty()) {
return pyramidsName;
}
//if we didn't find anything, try the default name
pyramidsName = getStringAttribute(VsSchema::Unstructured::defaultPyramidsName);
return pyramidsName; //could be empty
}
VsDMeta* getPyramidsDataset() const {
std::string pyramidsName = getPyramidsDatasetName();
if (pyramidsName.empty()) {
return NULL;
}
return getDataset(pyramidsName);
}
std::string getPrismsDatasetName() const {
//First see if the user has specified a name for the dataset
std::string prismsName = getStringAttribute(VsSchema::Unstructured::vsPrisms);
if (!prismsName.empty()) {
return prismsName;
}
//if we didn't find anything, try the default name
prismsName = getStringAttribute(VsSchema::Unstructured::defaultPrismsName);
return prismsName; //could be empty
}
VsDMeta* getPrismsDataset() const {
std::string prismsName = getPrismsDatasetName();
if (prismsName.empty()) {
return NULL;
}
return getDataset(prismsName);
}
std::string getHexahedralsDatasetName() const {
//First see if the user has specified a name for the dataset
std::string hexahedralsName = getStringAttribute(VsSchema::Unstructured::vsHexahedrals);
if (!hexahedralsName.empty()) {
return hexahedralsName;
}
//if we didn't find anything, try the default name
hexahedralsName = getStringAttribute(VsSchema::Unstructured::defaultHexahedralsName);
return hexahedralsName; //could be empty
}
VsDMeta* getHexahedralsDataset() const {
std::string hexahedralsName = getHexahedralsDatasetName();
if (hexahedralsName.empty()) {
return NULL;
}
return getDataset(hexahedralsName);
}
bool isPointMesh() const {
return ((getPolygonsDataset() == NULL) &&
(getPolyhedraDataset() == NULL) &&
(getLinesDataset() == NULL) &&
(getTrianglesDataset() == NULL) &&
(getQuadrilateralsDataset() == NULL) &&
(getTetrahedralsDataset() == NULL) &&
(getPyramidsDataset() == NULL) &&
(getPrismsDataset() == NULL) &&
(getHexahedralsDataset() == NULL));
}
};
// Metadata for geometry should include a list of its components.
struct VsMDMeshMeta {
VsMDMeshMeta(std::string meshName, std::string meshKind, int dims, std::string meshIndexOrder = VsSchema::compMinorCKey) {
//Note: MD meshes do not have a path. Their name is exactly what is declared in the "vsMD" attribute
//This is because an MD mesh may be made up of meshes in different paths, and we would have to choose one over the other.
//So, to avoid conflicts, we just use the name as given
numSpatialDims = dims;
indexOrder = meshIndexOrder;
kind = meshKind;
name = meshName;
}
//Destructor
~VsMDMeshMeta() {
for(std::vector<VsMeshMeta*>::iterator it = blocks.begin(); it!= blocks.end(); it++) {
delete (*it);
}
blocks.clear();
}
void write(std::ostream& os) const {
os << " Index Order: " << indexOrder << std::endl;
os << " Spatial Dimensionality: " << numSpatialDims <<std::endl;
os << " Kind: " << kind <<std::endl;
os << " Blocks:" <<std::endl;
for (unsigned int i = 0; i < blocks.size(); i++) {
os << " Block #" << i << std::endl;
blocks[i]->write(os);
}
}
std::string addBlock(VsMeshMeta* newBlock) {
if (newBlock->indexOrder != indexOrder)
return "VsMDMeshMeta rejected new block " + newBlock->getFullName() + " because indexOrder did not match - (" + newBlock->indexOrder + " vs " + indexOrder + ")";
if (newBlock->numSpatialDims != numSpatialDims)
return "VsMDMeshMeta rejected new block " + newBlock->getFullName() + " because numSpatialDims did not match";
if (newBlock->kind != kind)
return "VsMDMeshMeta rejected new block " + newBlock->getFullName() + " because kind did not match (" + newBlock->kind + " vs " + kind + ")";
blocks.push_back(newBlock);
return "";
}
unsigned int getNumBlocks() const {
return blocks.size();
}
std::string getNameForBlock(unsigned int domain) const {
if (domain >= blocks.size())
return NULL;
VsMeshMeta* foundMesh = blocks[domain];
return foundMesh->getFullName();
}
VsMeshMeta* getBlock(unsigned int domain) const {
if (domain >= blocks.size())
return NULL;
VsMeshMeta* foundMesh = blocks[domain];
return foundMesh;
}
std::string getMeshKind() const {
return kind;
}
bool isUniformMesh() const {
return ((kind == VsSchema::Uniform::key) || (kind == VsSchema::Uniform::deprecated_key));
}
bool isRectilinearMesh() const {
return (kind == VsSchema::Rectilinear::key);
}
bool isUnstructuredMesh() const {
return (kind == VsSchema::Unstructured::key);
}
bool isStructuredMesh() const {
return (kind == VsSchema::structuredMeshKey);
}
int getDims() const {
return numSpatialDims;
}
/** The kind of the mesh (e.g., structured, uniform, ... */
std::string kind;
/** The spatial dimensionality */
size_t numSpatialDims;
/** Index order (Fortran vs C style) */
std::string indexOrder;
/* name */
std::string name;
/** List of all subordinate blocks in this mesh
* Order is important (block 0 = blocks[0], etc)*/
std::vector<VsMeshMeta*> blocks;
std::string getFullName() const {
//Note: MD meshes do not have a path. Their name is exactly what is declared in the "vsMD" attribute
//This is because an MD mesh may be made up of meshes in different paths, and we would have to choose one over the other.
//So, to avoid conflicts, we just use the name as given
return makeCanonicalName(name);
}
};
struct VsMeta {
VsMeta () {
}
~VsMeta() {
clear();
}
// List of group-meshes
std::map<std::string, VsMeshMeta*> meshes;
VsMeshMeta* getMesh(const std::string& name) const {
//if the name does not start with a "/",
// it is not fully qualified
// and we assume it is in the root group
// If not found in root, we search the namespace
// and if we find that mesh, and it's unique, we return it
// If there is a name conflict, we return the "closest" object
// Make name fully qualified
std::string fullName = makeCanonicalName(name);
// std::cerr << "Meshes - Looking for " << fullName << " from " << name << std::endl;
// std::map<std::string, VsMeshMeta*>::const_iterator i;
// for (i = meshes.begin(); i != meshes.end(); ++i) std::cerr << (const std::string)i->first << std::endl;
//look for fully qualified name
std::map<std::string, VsMeshMeta*>::const_iterator it = meshes.find(fullName);
if (it != meshes.end()) {
return (VsMeshMeta*)(it->second);
}
//fully qualified name does not show up
//search by simple name
// - but be careful for naming conflicts -
VsMeshMeta* foundMesh = 0;
for (it = meshes.begin(); it != meshes.end(); ++it) {
if (name.compare(it->second->getFullName()) == 0) {
//found a match
//but is there already a match?
//if so, choose the one with a path that is closer to the requested full name
// i.e. if we requested /a/b/c
// and we have found /a/c and /d/c
// we want /a/c because it's "closer" to /a/b/c
if (foundMesh != 0) {
std::string candidate = it->second->getFullName();
if (candidate == getClosestName(foundMesh->getFullName(), candidate, fullName)) {
//the candidate name is closer to the target name than foundMesh
// so switch
foundMesh = it->second;
}
else {
//candidate name is farther from the target than foundMesh
//so keep foundMesh
}
}
else {
//we don't have a foundMesh yet, so just save it and continue
foundMesh = it->second;
}
}
}
return foundMesh;
}
//md meshes
std::map<std::string, VsMDMeshMeta*> mdMeshes;
VsMDMeshMeta* getMDMesh(const std::string& name) const {
//if the name does not start with a "/",
// it is not fully qualified
// and we assume it is in the root group
// If not found in root, we search the namespace
// and if we find that mesh, and it's unique, we return it
// If there is a name conflict, we return the "closest" object
// Make name fully qualified
std::string fullName = makeCanonicalName(name);
//look for fully qualified name
std::map<std::string, VsMDMeshMeta*>::const_iterator it = mdMeshes.find(fullName);
if (it != mdMeshes.end()) {
return (VsMDMeshMeta*)(it->second);
}
//fully qualified name does not show up
//search by simple name
// - but be careful for naming conflicts -
VsMDMeshMeta* foundMesh = 0;
for (it = mdMeshes.begin(); it != mdMeshes.end(); ++it) {
if (name.compare(it->second->getFullName()) == 0) {
//found a match
//but is there already a match?
//if so, choose the one with a path that is closer to the requested full name
// i.e. if we requested /a/b/c
// and we have found /a/c and /d/c
// we want /a/c because it's "closer" to /a/b/c
if (foundMesh != 0) {
std::string candidate = it->second->getFullName();
if (candidate == getClosestName(foundMesh->getFullName(), candidate, fullName)) {
//the candidate name is closer to the target name than foundMesh
// so switch
foundMesh = it->second;
}
else {
//candidate name is farther from the target than foundMesh
//so keep foundMesh
}
}
else {
//we don't have a foundMesh yet, so just save it and continue
foundMesh = it->second;
}
}
}
return foundMesh;
}
//md meshes
std::map<std::string, VsMDVariableMeta*> mdVars;
VsMDVariableMeta* getMDVar(const std::string& name) const {
//if the name does not start with a "/",
// it is not fully qualified
// and we assume it is in the root group
// If not found in root, we search the namespace
// and if we find that mesh, and it's unique, we return it
// If there is a name conflict, we return the "closest" object
// Make name fully qualified
std::string fullName = makeCanonicalName(name);
//look for fully qualified name
std::map<std::string, VsMDVariableMeta*>::const_iterator it = mdVars.find(fullName);
if (it != mdVars.end()) {
return (VsMDVariableMeta*)(it->second);
}
//fully qualified name does not show up
//search by simple name
// - but be careful for naming conflicts -
VsMDVariableMeta* foundVar = 0;
for (it = mdVars.begin(); it != mdVars.end(); ++it) {
if (name.compare(it->second->getFullName()) == 0) {
//found a match
//but is there already a match?
//if so, choose the one with a path that is closer to the requested full name
// i.e. if we requested /a/b/c
// and we have found /a/c and /d/c
// we want /a/c because it's "closer" to /a/b/c
if (foundVar != 0) {
std::string candidate = it->second->getFullName();
if (candidate == getClosestName(foundVar->getFullName(), candidate, fullName)) {
//the candidate name is closer to the target name than foundMesh
// so switch
foundVar = it->second;
}
else {
//candidate name is farther from the target than foundMesh
//so keep foundMesh
}
}
else {
//we don't have a foundMesh yet, so just save it and continue
foundVar = it->second;
}
}
}
return foundVar;
}
// List of variables
std::map<std::string, VsVariableMeta*> vars;
const VsVariableMeta* getVar(const std::string& name) const {
// Make name fully qualified
std::string fullName = makeCanonicalName(name);
//look for fully qualified name
std::map<std::string, VsVariableMeta*>::const_iterator it = vars.find(fullName);
if (it != vars.end()) {
return (const VsVariableMeta*) it->second;
}
//fully qualified name does not show up
//search by simple name
// - but be careful for naming conflicts -
// update 09.02.26 marc
// I'm pretty sure this can never happen as part of the VisIt plugin
// because VisIt pre-filters names based on what we supply
const VsVariableMeta* foundVar = 0;
for (it = vars.begin(); it != vars.end(); ++it) {
if (name.compare(it->second->getName()) == 0) {
//found a match
//but is there already a match?
//if so, choose the one with a path that is closer to the requested full name
// i.e. if we requested /a/b/c
// and we have found /a/c and /d/c
// we want /a/c because it's "closer" to /a/b/c
if (foundVar != 0) {
std::string candidate = it->second->getFullName();
if (candidate == getClosestName(foundVar->getFullName(), candidate, fullName)) {
//the candidate name is closer to the target name than foundVar
// so switch
foundVar = it->second;
}
else {
//candidate name is farther from the target than foundVar
//so keep foundVar
}
}
else {
//we don't have a foundVar yet, so just save it and continue
foundVar = it->second;
}
}
}
return foundVar;
}
// List of dataset-variable with meshes
std::map<std::string, VsVariableWithMeshMeta*> varsWithMesh;
const VsVariableWithMeshMeta* getVarWithMesh(const std::string& name) const {
//if the name does not start with a "/",
// it is not fully qualified
// and we assume it is in the root group
// If not found in root, we search the namespace
// and if we find that mesh, and it's unique, we return it
// If there is a name conflict, we return the "closest" name
// Make name fully qualified
std::string fullName = makeCanonicalName(name);
//look for fully qualified name
std::map<std::string, VsVariableWithMeshMeta*>::const_iterator it =
varsWithMesh.find(fullName);
if (it != varsWithMesh.end()) {
return (const VsVariableWithMeshMeta*)(it->second);
}
//fully qualified name does not show up
//search by simple name
// - but be careful for naming conflicts -
const VsVariableWithMeshMeta* foundVar = 0;
for (it = varsWithMesh.begin(); it != varsWithMesh.end(); ++it) {
if (name.compare(it->second->getName()) == 0) {
//found a match
//but is there already a match?
//if so, choose the one with a path that is closer to the requested full name
// i.e. if we requested /a/b/c
// and we have found /a/c and /d/c
// we want /a/c because it's "closer" to /a/b/c
if (foundVar != 0) {
std::string candidate = it->second->getFullName();
if (candidate == getClosestName(foundVar->getFullName(), candidate, fullName)) {
//the candidate name is closer to the target name than foundVar
// so switch
foundVar = it->second;
}
else {
//candidate name is farther from the target than foundVar
//so keep foundVar
}
}
else {
//we don't have a foundVar yet, so just save it and continue
foundVar = it->second;
}
}
}
return foundVar;
}
// List of of derived variables (vsVars)
std::map<std::string, std::string> vsVars;
// Clean itself
void clear() {
// Need to delete all pointers
std::map<std::string, VsMeshMeta*>::const_iterator i;
for (i=meshes.begin(); i != meshes.end(); ++i)
delete i->second;
for (std::map<std::string, VsVariableMeta*>::const_iterator k=vars.begin(); k != vars.end(); ++k)
delete k->second;
for (std::map<std::string, VsVariableWithMeshMeta*>::const_iterator j=varsWithMesh.begin(); j != varsWithMesh.end(); ++j)
delete j->second;
for (std::map<std::string, VsMDVariableMeta*>::const_iterator h=mdVars.begin(); h != mdVars.end(); ++h)
delete h->second;
for (std::map<std::string, VsMDMeshMeta*>::const_iterator j=mdMeshes.begin(); j != mdMeshes.end(); ++j)
delete j->second;
// Clean lists
meshes.clear();
vars.clear();
varsWithMesh.clear();
mdVars.clear();
mdMeshes.clear();
}
// Write
void write(std::ostream& os) const {
os <<"VsMeta::write() - dumping header data from input files." <<std::endl;
os <<"VsMeta::write() ***************************************" <<std::endl;
if (meshes.size()) os << "meshes"<<std::endl;
for (std::map<std::string, VsMeshMeta*>::const_iterator i=meshes.begin(); i != meshes.end(); ++i) {
os <<i->first <<std::endl;
i->second->write(os);
}
if (mdMeshes.size()) os << "mdMeshes"<<std::endl;
for (std::map<std::string, VsMDMeshMeta*>::const_iterator i=mdMeshes.begin(); i != mdMeshes.end(); ++i) {
os <<i->first <<std::endl;
i->second->write(os);
}
std::map<std::string, VsVariableMeta*>::const_iterator k;
if (vars.size()) os << "vars" << std::endl;
for (k=vars.begin(); k != vars.end(); ++k) {
k->second->write(os);
}
if (mdVars.size()) os << "mdVars"<<std::endl;
for (std::map<std::string, VsMDVariableMeta*>::const_iterator i=mdVars.begin(); i != mdVars.end(); ++i) {
os <<i->first <<std::endl;
i->second->write(os);
}
std::map<std::string, VsVariableWithMeshMeta*>::const_iterator j;
if (varsWithMesh.size()) os << "varsWithMesh" << std::endl;
for (j=varsWithMesh.begin(); j != varsWithMesh.end(); ++j) {
j->second->write(os);
}
std::map<std::string, std::string>::const_iterator l;
if (vsVars.size()) os << "vsVars" << std::endl;
for (l=vsVars.begin(); l != vsVars.end(); ++l) {
os << " " << l->first << " = " << l->second << std::endl;
}
os <<"VsMeta::write() ***************************" <<std::endl;
os <<"VsMeta::write() - done dumping header data." <<std::endl;
}
};
#endif
#endif
|