19 #include <boost/bimap.hpp> 50 typedef boost::bimap<std::string, int> CellNameToType;
56 const CellNameToType& iCellTypeStringIntPair()
58 static CellNameToType cellNameToInt;
59 if (cellNameToInt.empty())
62 cellNameToInt.insert(CellNameToType::value_type(
"INVALID_CELL_TYPE", XMU_INVALID_CELL_TYPE));
63 cellNameToInt.insert(CellNameToType::value_type(
"EMPTY_CELL", XMU_EMPTY_CELL));
64 cellNameToInt.insert(CellNameToType::value_type(
"VERTEX", XMU_VERTEX));
65 cellNameToInt.insert(CellNameToType::value_type(
"POLY_VERTEX", XMU_POLY_VERTEX));
66 cellNameToInt.insert(CellNameToType::value_type(
"LINE", XMU_LINE));
67 cellNameToInt.insert(CellNameToType::value_type(
"POLY_LINE", XMU_POLY_LINE));
68 cellNameToInt.insert(CellNameToType::value_type(
"TRIANGLE", XMU_TRIANGLE));
69 cellNameToInt.insert(CellNameToType::value_type(
"TRIANGLE_STRIP", XMU_TRIANGLE_STRIP));
70 cellNameToInt.insert(CellNameToType::value_type(
"POLYGON", XMU_POLYGON));
71 cellNameToInt.insert(CellNameToType::value_type(
"PIXEL", XMU_PIXEL));
72 cellNameToInt.insert(CellNameToType::value_type(
"QUAD", XMU_QUAD));
73 cellNameToInt.insert(CellNameToType::value_type(
"TETRA", XMU_TETRA));
74 cellNameToInt.insert(CellNameToType::value_type(
"VOXEL", XMU_VOXEL));
75 cellNameToInt.insert(CellNameToType::value_type(
"HEXAHEDRON", XMU_HEXAHEDRON));
76 cellNameToInt.insert(CellNameToType::value_type(
"WEDGE", XMU_WEDGE));
77 cellNameToInt.insert(CellNameToType::value_type(
"PYRAMID", XMU_PYRAMID));
78 cellNameToInt.insert(CellNameToType::value_type(
"PENTAGONAL_PRISM", XMU_PENTAGONAL_PRISM));
79 cellNameToInt.insert(CellNameToType::value_type(
"HEXAGONAL_PRISM", XMU_HEXAGONAL_PRISM));
80 cellNameToInt.insert(CellNameToType::value_type(
"QUADRATIC_EDGE", XMU_QUADRATIC_EDGE));
81 cellNameToInt.insert(CellNameToType::value_type(
"QUADRATIC_TRIANGLE", XMU_QUADRATIC_TRIANGLE));
82 cellNameToInt.insert(CellNameToType::value_type(
"QUADRATIC_QUAD", XMU_QUADRATIC_QUAD));
83 cellNameToInt.insert(CellNameToType::value_type(
"QUADRATIC_POLYGON", XMU_QUADRATIC_POLYGON));
84 cellNameToInt.insert(CellNameToType::value_type(
"QUADRATIC_TETRA", XMU_QUADRATIC_TETRA));
85 cellNameToInt.insert(CellNameToType::value_type(
"QUADRATIC_HEXAHEDRON", XMU_QUADRATIC_HEXAHEDRON));
86 cellNameToInt.insert(CellNameToType::value_type(
"QUADRATIC_WEDGE", XMU_QUADRATIC_WEDGE));
87 cellNameToInt.insert(CellNameToType::value_type(
"QUADRATIC_PYRAMID", XMU_QUADRATIC_PYRAMID));
88 cellNameToInt.insert(CellNameToType::value_type(
"BIQUADRATIC_QUAD", XMU_BIQUADRATIC_QUAD));
89 cellNameToInt.insert(CellNameToType::value_type(
"TRIQUADRATIC_HEXAHEDRON", XMU_TRIQUADRATIC_HEXAHEDRON));
90 cellNameToInt.insert(CellNameToType::value_type(
"QUADRATIC_LINEAR_QUAD", XMU_QUADRATIC_LINEAR_QUAD));
91 cellNameToInt.insert(CellNameToType::value_type(
"QUADRATIC_LINEAR_WEDGE", XMU_QUADRATIC_LINEAR_WEDGE));
92 cellNameToInt.insert(CellNameToType::value_type(
"BIQUADRATIC_QUADRATIC_WEDGE", XMU_BIQUADRATIC_QUADRATIC_WEDGE));
93 cellNameToInt.insert(CellNameToType::value_type(
"BIQUADRATIC_QUADRATIC_HEXAHEDRON", XMU_BIQUADRATIC_QUADRATIC_HEXAHEDRON));
94 cellNameToInt.insert(CellNameToType::value_type(
"BIQUADRATIC_TRIANGLE", XMU_BIQUADRATIC_TRIANGLE));
95 cellNameToInt.insert(CellNameToType::value_type(
"CUBIC_LINE", XMU_CUBIC_LINE));
96 cellNameToInt.insert(CellNameToType::value_type(
"CONVEX_POINT_SET", XMU_CONVEX_POINT_SET));
97 cellNameToInt.insert(CellNameToType::value_type(
"POLYHEDRON", XMU_POLYHEDRON));
98 cellNameToInt.insert(CellNameToType::value_type(
"PARAMETRIC_CURVE", XMU_PARAMETRIC_CURVE));
99 cellNameToInt.insert(CellNameToType::value_type(
"PARAMETRIC_SURFACE", XMU_PARAMETRIC_SURFACE));
100 cellNameToInt.insert(CellNameToType::value_type(
"PARAMETRIC_TRI_SURFACE", XMU_PARAMETRIC_TRI_SURFACE));
101 cellNameToInt.insert(CellNameToType::value_type(
"PARAMETRIC_QUAD_SURFACE", XMU_PARAMETRIC_QUAD_SURFACE));
102 cellNameToInt.insert(CellNameToType::value_type(
"PARAMETRIC_TETRA_REGION", XMU_PARAMETRIC_TETRA_REGION));
103 cellNameToInt.insert(CellNameToType::value_type(
"PARAMETRIC_HEX_REGION", XMU_PARAMETRIC_HEX_REGION));
104 cellNameToInt.insert(CellNameToType::value_type(
"HIGHER_ORDER_EDGE", XMU_HIGHER_ORDER_EDGE));
105 cellNameToInt.insert(CellNameToType::value_type(
"HIGHER_ORDER_TRIANGLE", XMU_HIGHER_ORDER_TRIANGLE));
106 cellNameToInt.insert(CellNameToType::value_type(
"HIGHER_ORDER_QUAD", XMU_HIGHER_ORDER_QUAD));
107 cellNameToInt.insert(CellNameToType::value_type(
"HIGHER_ORDER_POLYGON", XMU_HIGHER_ORDER_POLYGON));
108 cellNameToInt.insert(CellNameToType::value_type(
"HIGHER_ORDER_TETRAHEDRON", XMU_HIGHER_ORDER_TETRAHEDRON));
109 cellNameToInt.insert(CellNameToType::value_type(
"HIGHER_ORDER_WEDGE", XMU_HIGHER_ORDER_WEDGE));
110 cellNameToInt.insert(CellNameToType::value_type(
"HIGHER_ORDER_PYRAMID", XMU_HIGHER_ORDER_PYRAMID));
111 cellNameToInt.insert(CellNameToType::value_type(
"HIGHER_ORDER_HEXAHEDRON", XMU_HIGHER_ORDER_HEXAHEDRON));
115 return cellNameToInt;
123 std::string iStringFromCellType(
int a_type)
125 const CellNameToType& biMap = iCellTypeStringIntPair();
126 auto it = biMap.right.find(a_type);
127 if (it != biMap.right.end())
130 return std::string();
138 int iCellTypeFromString(
const std::string& a_type)
140 const CellNameToType& biMap = iCellTypeStringIntPair();
141 auto it = biMap.left.find(a_type);
142 if (it != biMap.left.end())
144 return XMU_INVALID_CELL_TYPE;
156 if (!a_reader.
ReadIntLine(
"NUM_POINTS", pointCount))
162 locations.reserve(pointCount);
163 for (
int pointIdx = 0; pointIdx < pointCount; ++pointIdx)
168 locations.push_back(point);
186 bool iReadCellStreamSizeVersion1(
DaStreamReader& a_reader,
int& cellStreamSize)
188 if (!a_reader.
ReadIntLine(
"NUM_CELL_ITEMS", cellStreamSize))
202 bool iReadCellStreamSizeVersion2(
DaStreamReader& a_reader,
int& cellStreamSize)
204 if (!a_reader.
ReadIntLine(
"CELL_STREAM", cellStreamSize))
219 bool iReadCellLineVersion1(
DaStreamReader& a_reader, std::string& a_cellLine,
int& a_cellType)
221 a_cellType = XMU_INVALID_CELL_TYPE;
224 std::string cellTypeString = iStringFromCellType(a_cellType);
225 if (cellTypeString.empty())
226 a_cellType = XMU_INVALID_CELL_TYPE;
230 a_cellType = XMU_INVALID_CELL_TYPE;
233 if (a_cellType == XMU_INVALID_CELL_TYPE)
248 bool iReadCellLineVersion2(
DaStreamReader& a_reader,
int a_cellIdx,
int& a_cellType)
250 int readCellIdx = -1;
251 if (!a_reader.
ReadInt(readCellIdx) || readCellIdx != a_cellIdx)
257 a_cellType = XMU_INVALID_CELL_TYPE;
258 std::string cellTypeString;
261 a_cellType = iCellTypeFromString(cellTypeString);
265 a_cellType = XMU_INVALID_CELL_TYPE;
268 if (a_cellType == XMU_INVALID_CELL_TYPE)
286 std::string& a_cellLine,
290 a_cellstream.push_back(a_cellType);
291 if (a_cellType == XMU_POLYHEDRON)
294 std::string faceString;
296 a_cellstream.push_back(numFaces);
297 for (
int faceIdx = 0; faceIdx < numFaces; ++faceIdx)
307 a_cellstream.push_back(numPoints);
308 for (
int i = 0; i < numPoints; ++i)
312 a_cellstream.push_back(ptIdx);
320 a_cellstream.push_back(numPoints);
321 for (
int i = 0; i < numPoints; ++i)
325 a_cellstream.push_back(ptIdx);
340 a_cellstream.push_back(a_cellType);
341 if (a_cellType == XMU_POLYHEDRON)
344 std::string faceString;
347 a_cellstream.push_back(numFaces);
348 for (
int faceIdx = 0; faceIdx < numFaces; ++faceIdx)
357 if (faceString !=
"FACE")
365 if (faceIdxRead != faceIdx)
373 a_cellstream.push_back(numPoints);
374 for (
int i = 0; i < numPoints; ++i)
378 a_cellstream.push_back(ptIdx);
386 a_cellstream.push_back(numPoints);
387 for (
int i = 0; i < numPoints; ++i)
391 a_cellstream.push_back(ptIdx);
406 if (!iReadCellStreamSizeVersion1(a_reader, cellStreamSize))
409 cellstream.reserve(cellStreamSize);
410 while ((
int)cellstream.size() < cellStreamSize)
412 std::string cellLine;
414 std::string cardName;
416 if (cardName !=
"CELL")
423 if (!iReadCellLineVersion1(a_reader, cellLine, cellType))
426 if (!iReadCellStreamVersion1(a_reader, cellLine, cellType, cellstream))
442 if (!iReadCellStreamSizeVersion2(a_reader, cellStreamSize))
445 cellstream.reserve(cellStreamSize);
447 while ((
int)cellstream.size() < cellStreamSize)
449 std::string cardName;
451 if (cardName !=
"CELL")
458 if (!iReadCellLineVersion2(a_reader, cellIdx, cellType))
461 if (!iReadCellStreamVersion2(a_reader, cellType, cellstream))
478 int cellstreamSize = (int)a_cellstream.size();
482 std::ostringstream out;
485 while (currIdx < cellstreamSize)
487 int cellType = a_cellstream[currIdx++];
490 std::string cellTypeString = iStringFromCellType(cellType);
491 if (!cellTypeString.empty())
497 std::ostringstream err;
498 err <<
"Unknown cell type (" << cellType <<
").";
503 int numItems = a_cellstream[currIdx++];
504 if (cellType == XMU_POLYHEDRON)
506 int numFaces = numItems;
509 for (
int faceIdx = 0; faceIdx < numFaces; ++faceIdx)
513 numItems = a_cellstream[currIdx++];
515 a_writer.
AppendInts(&a_cellstream[currIdx], numItems);
523 a_writer.
AppendInts(&a_cellstream[currIdx], numItems);
537 void iWriteUGridToStream(
const XmUGrid& a_ugrid,
538 std::ostream& a_outStream,
540 int a_blockSize = 32 * 1024)
543 a_outStream <<
"Binary XmUGrid Version 2\n";
545 a_outStream <<
"ASCII XmUGrid Version 2\n";
547 writer.SetBinaryBlockSize(a_blockSize);
548 writer.WriteVecPt3d(
"LOCATIONS", a_ugrid.
GetLocations());
565 std::ifstream inFile(a_filePath);
576 if (a_inStream.eof())
581 std::string versionString;
588 if (versionString ==
"ASCII XmUGrid Version 1.0")
592 bool success = iReadPointsVersion1(reader, locations);
594 success = success && iReadCellsVersion1(reader, cellstream);
600 if (versionString ==
"ASCII XmUGrid Version 2")
602 else if (versionString ==
"Binary XmUGrid Version 2")
612 bool success = reader.
ReadVecPt3d(
"LOCATIONS", locations);
615 success = success && reader.
ReadVecInt(
"CELL_STREAM", cellstream);
617 success = success && iReadCellsVersion2(reader, cellstream);
632 std::ofstream outFile(a_filePath);
651 std::ostream& a_outStream,
654 iWriteUGridToStream(a_ugrid, a_outStream, a_binary);
676 std::string TestFilesPath()
678 return std::string(XMS_TEST_PATH);
692 std::ostringstream output;
695 std::string outputBase =
696 "ASCII XmUGrid Version 2\n" 699 TS_ASSERT_EQUALS(outputBase, output.str());
707 std::ostringstream output;
710 std::string outputBase =
711 "ASCII XmUGrid Version 2\n" 713 " POINT 0 0.0 0.0 0.0\n" 714 " POINT 1 20.0 0.0 0.0\n" 715 " POINT 2 0.0 20.0 0.0\n" 717 " CELL 0 TRIANGLE 3 0 1 2\n";
718 TS_ASSERT_EQUALS(outputBase, output.str());
726 std::ostringstream output;
729 std::string outputBase =
730 "ASCII XmUGrid Version 2\n" 732 " POINT 0 0.0 0.0 10.0\n" 733 " POINT 1 10.0 0.0 10.0\n" 734 " POINT 2 10.0 10.0 10.0\n" 735 " POINT 3 0.0 10.0 10.0\n" 736 " POINT 4 0.0 0.0 0.0\n" 737 " POINT 5 10.0 0.0 0.0\n" 738 " POINT 6 10.0 10.0 0.0\n" 739 " POINT 7 0.0 10.0 0.0\n" 741 " CELL 0 POLYHEDRON 6\n" 742 " FACE 0 4 0 1 2 3\n" 743 " FACE 1 4 4 5 7 2\n" 744 " FACE 2 4 5 6 2 1\n" 745 " FACE 3 4 6 7 3 2\n" 746 " FACE 4 4 7 4 0 3\n" 747 " FACE 5 4 4 7 6 5\n";
748 TS_ASSERT_EQUALS(outputBase, output.str());
757 std::ostringstream output;
760 std::string outputBase =
761 "ASCII XmUGrid Version 2\n" 763 " POINT 0 0.0 0.0 0.0\n" 764 " POINT 1 10.0 0.0 0.0\n" 765 " POINT 2 20.0 0.0 0.0\n" 766 " POINT 3 30.0 0.0 0.0\n" 767 " POINT 4 40.0 0.0 0.0\n" 768 " POINT 5 0.0 10.0 0.0\n" 769 " POINT 6 10.0 10.0 0.0\n" 770 " POINT 7 20.0 10.0 0.0\n" 771 " POINT 8 40.0 10.0 0.0\n" 772 " POINT 9 0.0 20.0 0.0\n" 773 " POINT 10 10.0 20.0 0.0\n" 774 " POINT 11 20.0 20.0 0.0\n" 775 " POINT 12 30.0 20.0 0.0\n" 776 " POINT 13 40.0 20.0 0.0\n" 778 " CELL 0 QUAD 4 0 1 6 5\n" 779 " CELL 1 PIXEL 4 1 2 6 7\n" 780 " CELL 2 TRIANGLE 3 2 3 7\n" 781 " CELL 3 POLYGON 6 3 4 8 13 12 7\n" 782 " CELL 4 POLY_LINE 3 7 11 10\n" 783 " CELL 5 LINE 2 5 9\n";
784 TS_ASSERT_EQUALS(outputBase, output.str());
793 std::ostringstream output;
796 std::string outputBase =
797 "ASCII XmUGrid Version 2\n" 799 " POINT 0 0.0 0.0 0.0\n" 800 " POINT 1 10.0 0.0 0.0\n" 801 " POINT 2 20.0 0.0 0.0\n" 802 " POINT 3 30.0 0.0 0.0\n" 803 " POINT 4 40.0 0.0 0.0\n" 804 " POINT 5 0.0 10.0 0.0\n" 805 " POINT 6 10.0 10.0 0.0\n" 806 " POINT 7 20.0 10.0 0.0\n" 807 " POINT 8 30.0 10.0 0.0\n" 808 " POINT 9 40.0 10.0 0.0\n" 809 " POINT 10 0.0 20.0 0.0\n" 810 " POINT 11 10.0 20.0 0.0\n" 811 " POINT 12 20.0 20.0 0.0\n" 812 " POINT 13 30.0 20.0 0.0\n" 813 " POINT 14 40.0 20.0 0.0\n" 814 " POINT 15 0.0 0.0 10.0\n" 815 " POINT 16 10.0 0.0 10.0\n" 816 " POINT 17 20.0 0.0 10.0\n" 817 " POINT 18 30.0 0.0 10.0\n" 818 " POINT 19 40.0 0.0 10.0\n" 819 " POINT 20 0.0 10.0 10.0\n" 820 " POINT 21 10.0 10.0 10.0\n" 821 " POINT 22 20.0 10.0 10.0\n" 822 " POINT 23 30.0 10.0 10.0\n" 823 " POINT 24 40.0 10.0 10.0\n" 824 " POINT 25 0.0 20.0 10.0\n" 825 " POINT 26 10.0 20.0 10.0\n" 826 " POINT 27 20.0 20.0 10.0\n" 827 " POINT 28 30.0 20.0 10.0\n" 828 " POINT 29 40.0 20.0 10.0\n" 830 " CELL 0 TETRA 4 0 1 5 15\n" 831 " CELL 1 VOXEL 8 1 2 6 7 16 17 21 22\n" 832 " CELL 2 HEXAHEDRON 8 2 3 8 7 17 18 23 22\n" 833 " CELL 3 POLYHEDRON 6\n" 834 " FACE 0 4 9 8 13 14\n" 835 " FACE 1 4 8 9 24 23\n" 836 " FACE 2 4 9 14 29 24\n" 837 " FACE 3 4 14 13 28 29\n" 838 " FACE 4 4 8 13 28 23\n" 839 " FACE 5 4 23 24 29 28\n" 840 " CELL 4 WEDGE 6 3 4 18 8 9 23\n" 841 " CELL 5 PYRAMID 5 5 6 11 10 20\n";
842 std::string outputString = output.str();
843 TS_ASSERT_EQUALS(outputBase, outputString);
850 std::string inputText =
851 "ASCII XmUGrid Version 2\n" 854 std::istringstream input;
855 input.str(inputText);
859 TS_ASSERT(ugrid->GetLocations().empty());
860 TS_ASSERT(ugrid->GetCellstream().empty());
867 std::string inputText =
868 "ASCII XmUGrid Version 2\n" 870 " POINT 0 0.0 0.0 0.0\n" 871 " POINT 1 20.0 0.0 0.0\n" 872 " POINT 2 0.0 20.0 0.0\n" 874 " CELL 0 TRIANGLE 3 0 1 2\n";
875 std::istringstream input;
876 input.str(inputText);
881 VecPt3d locations = ugrid->GetLocations();
882 TS_ASSERT_EQUALS(ugridBase->GetLocations(), locations);
883 VecInt cellstream = ugrid->GetCellstream();
884 TS_ASSERT_EQUALS(ugridBase->GetCellstream(), cellstream);
891 std::string inputText =
892 "ASCII XmUGrid Version 2\n" 894 " POINT 0 0.0 0.0 10.0\n" 895 " POINT 1 10.0 0.0 10.0\n" 896 " POINT 2 10.0 10.0 10.0\n" 897 " POINT 3 0.0 10.0 10.0\n" 898 " POINT 4 0.0 0.0 0.0\n" 899 " POINT 5 10.0 0.0 0.0\n" 900 " POINT 6 10.0 10.0 0.0\n" 901 " POINT 7 0.0 10.0 0.0\n" 903 " CELL 0 POLYHEDRON 6\n" 904 " FACE 0 4 0 1 2 3\n" 905 " FACE 1 4 4 5 7 2\n" 906 " FACE 2 4 5 6 2 1\n" 907 " FACE 3 4 6 7 3 2\n" 908 " FACE 4 4 7 4 0 3\n" 909 " FACE 5 4 4 7 6 5\n";
910 std::istringstream input;
911 input.str(inputText);
916 TS_ASSERT_EQUALS(ugridBase->GetLocations(), ugrid->GetLocations());
917 TS_ASSERT_EQUALS(ugridBase->GetCellstream(), ugrid->GetCellstream());
927 std::ostringstream output;
931 std::istringstream input;
932 input.str(output.str());
935 TS_ASSERT_EQUALS(ugridBase->GetLocations(), ugridOut->GetLocations());
936 TS_ASSERT_EQUALS(ugridBase->GetCellstream(), ugridOut->GetCellstream());
946 std::ostringstream output;
950 std::istringstream input;
951 input.str(output.str());
954 TS_ASSERT_EQUALS(ugridBase->GetLocations(), ugridOut->GetLocations());
955 TS_ASSERT_EQUALS(ugridBase->GetCellstream(), ugridOut->GetCellstream());
965 std::string outFileName(TestFilesPath() +
"3d_grid_linear.xmugrid");
966 std::ofstream output(outFileName);
971 std::ifstream input(TestFilesPath() +
"3d_grid_linear.xmugrid");
976 TS_ASSERT_EQUALS(ugridBase->GetLocations(), ugridOut->GetLocations());
977 TS_ASSERT_EQUALS(ugridBase->GetCellstream(), ugridOut->GetCellstream());
988 std::string outFileName(TestFilesPath() +
"3d_grid_linear.xmugrid");
992 std::string input(TestFilesPath() +
"3d_grid_linear.xmugrid");
996 TS_ASSERT_EQUALS(ugridBase->GetLocations(), ugridOut->GetLocations());
997 TS_ASSERT_EQUALS(ugridBase->GetCellstream(), ugridOut->GetCellstream());
1005 std::string inputText =
1006 "ASCII XmUGrid Version 1.0\n" 1008 " POINT 0.0 0.0 0.0\n" 1009 " POINT 10.0 0.0 0.0\n" 1010 " POINT 20.0 0.0 0.0\n" 1011 " POINT 30.0 0.0 0.0\n" 1012 " POINT 40.0 0.0 0.0\n" 1013 " POINT 0.0 10.0 0.0\n" 1014 " POINT 10.0 10.0 0.0\n" 1015 " POINT 20.0 10.0 0.0\n" 1016 " POINT 30.0 10.0 0.0\n" 1017 " POINT 40.0 10.0 0.0\n" 1018 " POINT 0.0 20.0 0.0\n" 1019 " POINT 10.0 20.0 0.0\n" 1020 " POINT 20.0 20.0 0.0\n" 1021 " POINT 30.0 20.0 0.0\n" 1022 " POINT 40.0 20.0 0.0\n" 1023 " POINT 0.0 0.0 10.0\n" 1024 " POINT 10.0 0.0 10.0\n" 1025 " POINT 20.0 0.0 10.0\n" 1026 " POINT 30.0 0.0 10.0\n" 1027 " POINT 40.0 0.0 10.0\n" 1028 " POINT 0.0 10.0 10.0\n" 1029 " POINT 10.0 10.0 10.0\n" 1030 " POINT 20.0 10.0 10.0\n" 1031 " POINT 30.0 10.0 10.0\n" 1032 " POINT 40.0 10.0 10.0\n" 1033 " POINT 0.0 20.0 10.0\n" 1034 " POINT 10.0 20.0 10.0\n" 1035 " POINT 20.0 20.0 10.0\n" 1036 " POINT 30.0 20.0 10.0\n" 1037 " POINT 40.0 20.0 10.0\n" 1038 "NUM_CELL_ITEMS 73\n" 1039 " CELL 10 4 0 1 5 15\n" 1040 " CELL 11 8 1 2 6 7 16 17 21 22\n" 1041 " CELL 12 8 2 3 8 7 17 18 23 22\n" 1049 " CELL 13 6 3 4 18 8 9 23\n" 1050 " CELL 14 5 5 6 11 10 20\n";
1051 std::istringstream input(inputText);
1056 TS_ASSERT_EQUALS(ugridBase->GetLocations(), ugrid->GetLocations());
1057 TS_ASSERT_EQUALS(ugridBase->GetCellstream(), ugrid->GetCellstream());
1065 std::ostringstream output;
1067 iWriteUGridToStream(*ugridOut, output, binary, 120);
1069 std::string outputBase =
1070 "Binary XmUGrid Version 2\n" 1072 "BINARY_BLOCK 34 120\n" 1073 "eAFjYMAHVBywy5rgELfDIe6CIQ4AXnwB2w\n" 1074 "BINARY_BLOCK 46 120\n" 1075 "eAFjYEAGKg7IPAYGGB9Gw2RNoOrQxe1wiLtgiAMAzoQDzw\n" 1076 "BINARY_BLOCK 46 120\n" 1077 "eAFjYEAGJg7IPAYGFSgfXRzGh9EwXXY41LtgiAMA4KQEHw\n" 1078 "BINARY_BLOCK 43 120\n" 1079 "eAFjYMAGVBwgojAapgbGN4HKo4vb4RB3wRAHAL7kA88\n" 1080 "BINARY_BLOCK 35 120\n" 1081 "eAFjYEAGKg4QHiHaBIc6OxziLhjiAC77BcM\n" 1082 "BINARY_BLOCK 44 120\n" 1083 "eAFjYEAGJg4QngoajS4O48NomHo7qD50cRcMcQBBGwYT\n" 1085 "BINARY_BLOCK 90 120\n" 1086 "eAEtzQEKgCAQAMGrzLKCTMj+0P8f2C4kDBzHcm4RkeAbMOPEjhXuRmQsqLhwo+OAnc30z3Y2DQ/sXnjDvwo+QSwBSA\n" 1087 "BINARY_BLOCK 82 120\n" 1088 "eAE1yzEOACAIBEEKY7DQVgv9/zfdLSgmhIPLiJhYaEgMHGyYuXt/MDdzt3dhXt3Kquu044+/3js+aLQB2w\n" 1089 "BINARY_BLOCK 52 52\n" 1090 "eAFjZmBgYAFiISDmAGJOIBYHYj4gZoViNiDNDcRcQCwCxAAN9ACJ\n";
1091 std::string outputString = output.str();
1092 TS_ASSERT_EQUALS(outputBase, outputString);
1094 std::istringstream input(outputString);
1097 TS_ASSERT_EQUALS(ugridOut->GetLocations(), ugridIn->GetLocations());
1098 TS_ASSERT_EQUALS(ugridOut->GetCellstream(), ugridIn->GetCellstream());
1105 TS_ASSERT_EQUALS(
"INVALID_CELL_TYPE", iStringFromCellType(XMU_INVALID_CELL_TYPE));
1106 TS_ASSERT_EQUALS(
"EMPTY_CELL", iStringFromCellType(XMU_EMPTY_CELL));
1107 TS_ASSERT_EQUALS(
"VERTEX", iStringFromCellType(XMU_VERTEX));
1108 TS_ASSERT_EQUALS(
"POLY_VERTEX", iStringFromCellType(XMU_POLY_VERTEX));
1109 TS_ASSERT_EQUALS(
"LINE", iStringFromCellType(XMU_LINE));
1110 TS_ASSERT_EQUALS(
"POLY_LINE", iStringFromCellType(XMU_POLY_LINE));
1111 TS_ASSERT_EQUALS(
"TRIANGLE", iStringFromCellType(XMU_TRIANGLE));
1112 TS_ASSERT_EQUALS(
"TRIANGLE_STRIP", iStringFromCellType(XMU_TRIANGLE_STRIP));
1113 TS_ASSERT_EQUALS(
"POLYGON", iStringFromCellType(XMU_POLYGON));
1114 TS_ASSERT_EQUALS(
"PIXEL", iStringFromCellType(XMU_PIXEL));
1115 TS_ASSERT_EQUALS(
"QUAD", iStringFromCellType(XMU_QUAD));
1116 TS_ASSERT_EQUALS(
"TETRA", iStringFromCellType(XMU_TETRA));
1117 TS_ASSERT_EQUALS(
"VOXEL", iStringFromCellType(XMU_VOXEL));
1118 TS_ASSERT_EQUALS(
"HEXAHEDRON", iStringFromCellType(XMU_HEXAHEDRON));
1119 TS_ASSERT_EQUALS(
"WEDGE", iStringFromCellType(XMU_WEDGE));
1120 TS_ASSERT_EQUALS(
"PYRAMID", iStringFromCellType(XMU_PYRAMID));
1121 TS_ASSERT_EQUALS(
"PENTAGONAL_PRISM", iStringFromCellType(XMU_PENTAGONAL_PRISM));
1122 TS_ASSERT_EQUALS(
"HEXAGONAL_PRISM", iStringFromCellType(XMU_HEXAGONAL_PRISM));
1123 TS_ASSERT_EQUALS(
"QUADRATIC_EDGE", iStringFromCellType(XMU_QUADRATIC_EDGE));
1124 TS_ASSERT_EQUALS(
"QUADRATIC_TRIANGLE", iStringFromCellType(XMU_QUADRATIC_TRIANGLE));
1125 TS_ASSERT_EQUALS(
"QUADRATIC_QUAD", iStringFromCellType(XMU_QUADRATIC_QUAD));
1126 TS_ASSERT_EQUALS(
"QUADRATIC_POLYGON", iStringFromCellType(XMU_QUADRATIC_POLYGON));
1127 TS_ASSERT_EQUALS(
"QUADRATIC_TETRA", iStringFromCellType(XMU_QUADRATIC_TETRA));
1128 TS_ASSERT_EQUALS(
"QUADRATIC_HEXAHEDRON", iStringFromCellType(XMU_QUADRATIC_HEXAHEDRON));
1129 TS_ASSERT_EQUALS(
"QUADRATIC_WEDGE", iStringFromCellType(XMU_QUADRATIC_WEDGE));
1130 TS_ASSERT_EQUALS(
"QUADRATIC_PYRAMID", iStringFromCellType(XMU_QUADRATIC_PYRAMID));
1131 TS_ASSERT_EQUALS(
"BIQUADRATIC_QUAD", iStringFromCellType(XMU_BIQUADRATIC_QUAD));
1132 TS_ASSERT_EQUALS(
"TRIQUADRATIC_HEXAHEDRON", iStringFromCellType(XMU_TRIQUADRATIC_HEXAHEDRON));
1133 TS_ASSERT_EQUALS(
"QUADRATIC_LINEAR_QUAD", iStringFromCellType(XMU_QUADRATIC_LINEAR_QUAD));
1134 TS_ASSERT_EQUALS(
"QUADRATIC_LINEAR_WEDGE", iStringFromCellType(XMU_QUADRATIC_LINEAR_WEDGE));
1135 TS_ASSERT_EQUALS(
"BIQUADRATIC_QUADRATIC_WEDGE",
1136 iStringFromCellType(XMU_BIQUADRATIC_QUADRATIC_WEDGE));
1137 TS_ASSERT_EQUALS(
"BIQUADRATIC_QUADRATIC_HEXAHEDRON",
1138 iStringFromCellType(XMU_BIQUADRATIC_QUADRATIC_HEXAHEDRON));
1139 TS_ASSERT_EQUALS(
"BIQUADRATIC_TRIANGLE", iStringFromCellType(XMU_BIQUADRATIC_TRIANGLE));
1140 TS_ASSERT_EQUALS(
"CUBIC_LINE", iStringFromCellType(XMU_CUBIC_LINE));
1141 TS_ASSERT_EQUALS(
"CONVEX_POINT_SET", iStringFromCellType(XMU_CONVEX_POINT_SET));
1142 TS_ASSERT_EQUALS(
"POLYHEDRON", iStringFromCellType(XMU_POLYHEDRON));
1143 TS_ASSERT_EQUALS(
"PARAMETRIC_CURVE", iStringFromCellType(XMU_PARAMETRIC_CURVE));
1144 TS_ASSERT_EQUALS(
"PARAMETRIC_SURFACE", iStringFromCellType(XMU_PARAMETRIC_SURFACE));
1145 TS_ASSERT_EQUALS(
"PARAMETRIC_TRI_SURFACE", iStringFromCellType(XMU_PARAMETRIC_TRI_SURFACE));
1146 TS_ASSERT_EQUALS(
"PARAMETRIC_QUAD_SURFACE", iStringFromCellType(XMU_PARAMETRIC_QUAD_SURFACE));
1147 TS_ASSERT_EQUALS(
"PARAMETRIC_TETRA_REGION", iStringFromCellType(XMU_PARAMETRIC_TETRA_REGION));
1148 TS_ASSERT_EQUALS(
"PARAMETRIC_HEX_REGION", iStringFromCellType(XMU_PARAMETRIC_HEX_REGION));
1149 TS_ASSERT_EQUALS(
"HIGHER_ORDER_EDGE", iStringFromCellType(XMU_HIGHER_ORDER_EDGE));
1150 TS_ASSERT_EQUALS(
"HIGHER_ORDER_TRIANGLE", iStringFromCellType(XMU_HIGHER_ORDER_TRIANGLE));
1151 TS_ASSERT_EQUALS(
"HIGHER_ORDER_QUAD", iStringFromCellType(XMU_HIGHER_ORDER_QUAD));
1152 TS_ASSERT_EQUALS(
"HIGHER_ORDER_POLYGON", iStringFromCellType(XMU_HIGHER_ORDER_POLYGON));
1153 TS_ASSERT_EQUALS(
"HIGHER_ORDER_TETRAHEDRON", iStringFromCellType(XMU_HIGHER_ORDER_TETRAHEDRON));
1154 TS_ASSERT_EQUALS(
"HIGHER_ORDER_WEDGE", iStringFromCellType(XMU_HIGHER_ORDER_WEDGE));
1155 TS_ASSERT_EQUALS(
"HIGHER_ORDER_PYRAMID", iStringFromCellType(XMU_HIGHER_ORDER_PYRAMID));
1156 TS_ASSERT_EQUALS(
"HIGHER_ORDER_HEXAHEDRON", iStringFromCellType(XMU_HIGHER_ORDER_HEXAHEDRON));
1158 TS_ASSERT_EQUALS(XMU_INVALID_CELL_TYPE, iCellTypeFromString(
"INVALID_CELL_TYPE"));
1159 TS_ASSERT_EQUALS(XMU_EMPTY_CELL, iCellTypeFromString(
"EMPTY_CELL"));
1160 TS_ASSERT_EQUALS(XMU_VERTEX, iCellTypeFromString(
"VERTEX"));
1161 TS_ASSERT_EQUALS(XMU_POLY_VERTEX, iCellTypeFromString(
"POLY_VERTEX"));
1162 TS_ASSERT_EQUALS(XMU_LINE, iCellTypeFromString(
"LINE"));
1163 TS_ASSERT_EQUALS(XMU_POLY_LINE, iCellTypeFromString(
"POLY_LINE"));
1164 TS_ASSERT_EQUALS(XMU_TRIANGLE, iCellTypeFromString(
"TRIANGLE"));
1165 TS_ASSERT_EQUALS(XMU_TRIANGLE_STRIP, iCellTypeFromString(
"TRIANGLE_STRIP"));
1166 TS_ASSERT_EQUALS(XMU_POLYGON, iCellTypeFromString(
"POLYGON"));
1167 TS_ASSERT_EQUALS(XMU_PIXEL, iCellTypeFromString(
"PIXEL"));
1168 TS_ASSERT_EQUALS(XMU_QUAD, iCellTypeFromString(
"QUAD"));
1169 TS_ASSERT_EQUALS(XMU_TETRA, iCellTypeFromString(
"TETRA"));
1170 TS_ASSERT_EQUALS(XMU_VOXEL, iCellTypeFromString(
"VOXEL"));
1171 TS_ASSERT_EQUALS(XMU_HEXAHEDRON, iCellTypeFromString(
"HEXAHEDRON"));
1172 TS_ASSERT_EQUALS(XMU_WEDGE, iCellTypeFromString(
"WEDGE"));
1173 TS_ASSERT_EQUALS(XMU_PYRAMID, iCellTypeFromString(
"PYRAMID"));
1174 TS_ASSERT_EQUALS(XMU_PENTAGONAL_PRISM, iCellTypeFromString(
"PENTAGONAL_PRISM"));
1175 TS_ASSERT_EQUALS(XMU_HEXAGONAL_PRISM, iCellTypeFromString(
"HEXAGONAL_PRISM"));
1176 TS_ASSERT_EQUALS(XMU_QUADRATIC_EDGE, iCellTypeFromString(
"QUADRATIC_EDGE"));
1177 TS_ASSERT_EQUALS(XMU_QUADRATIC_TRIANGLE, iCellTypeFromString(
"QUADRATIC_TRIANGLE"));
1178 TS_ASSERT_EQUALS(XMU_QUADRATIC_QUAD, iCellTypeFromString(
"QUADRATIC_QUAD"));
1179 TS_ASSERT_EQUALS(XMU_QUADRATIC_POLYGON, iCellTypeFromString(
"QUADRATIC_POLYGON"));
1180 TS_ASSERT_EQUALS(XMU_QUADRATIC_TETRA, iCellTypeFromString(
"QUADRATIC_TETRA"));
1181 TS_ASSERT_EQUALS(XMU_QUADRATIC_HEXAHEDRON, iCellTypeFromString(
"QUADRATIC_HEXAHEDRON"));
1182 TS_ASSERT_EQUALS(XMU_QUADRATIC_WEDGE, iCellTypeFromString(
"QUADRATIC_WEDGE"));
1183 TS_ASSERT_EQUALS(XMU_QUADRATIC_PYRAMID, iCellTypeFromString(
"QUADRATIC_PYRAMID"));
1184 TS_ASSERT_EQUALS(XMU_BIQUADRATIC_QUAD, iCellTypeFromString(
"BIQUADRATIC_QUAD"));
1185 TS_ASSERT_EQUALS(XMU_TRIQUADRATIC_HEXAHEDRON, iCellTypeFromString(
"TRIQUADRATIC_HEXAHEDRON"));
1186 TS_ASSERT_EQUALS(XMU_QUADRATIC_LINEAR_QUAD, iCellTypeFromString(
"QUADRATIC_LINEAR_QUAD"));
1187 TS_ASSERT_EQUALS(XMU_QUADRATIC_LINEAR_WEDGE, iCellTypeFromString(
"QUADRATIC_LINEAR_WEDGE"));
1188 TS_ASSERT_EQUALS(XMU_BIQUADRATIC_QUADRATIC_WEDGE,
1189 iCellTypeFromString(
"BIQUADRATIC_QUADRATIC_WEDGE"));
1190 TS_ASSERT_EQUALS(XMU_BIQUADRATIC_QUADRATIC_HEXAHEDRON,
1191 iCellTypeFromString(
"BIQUADRATIC_QUADRATIC_HEXAHEDRON"));
1192 TS_ASSERT_EQUALS(XMU_BIQUADRATIC_TRIANGLE, iCellTypeFromString(
"BIQUADRATIC_TRIANGLE"));
1193 TS_ASSERT_EQUALS(XMU_CUBIC_LINE, iCellTypeFromString(
"CUBIC_LINE"));
1194 TS_ASSERT_EQUALS(XMU_CONVEX_POINT_SET, iCellTypeFromString(
"CONVEX_POINT_SET"));
1195 TS_ASSERT_EQUALS(XMU_POLYHEDRON, iCellTypeFromString(
"POLYHEDRON"));
1196 TS_ASSERT_EQUALS(XMU_PARAMETRIC_CURVE, iCellTypeFromString(
"PARAMETRIC_CURVE"));
1197 TS_ASSERT_EQUALS(XMU_PARAMETRIC_SURFACE, iCellTypeFromString(
"PARAMETRIC_SURFACE"));
1198 TS_ASSERT_EQUALS(XMU_PARAMETRIC_TRI_SURFACE, iCellTypeFromString(
"PARAMETRIC_TRI_SURFACE"));
1199 TS_ASSERT_EQUALS(XMU_PARAMETRIC_QUAD_SURFACE, iCellTypeFromString(
"PARAMETRIC_QUAD_SURFACE"));
1200 TS_ASSERT_EQUALS(XMU_PARAMETRIC_TETRA_REGION, iCellTypeFromString(
"PARAMETRIC_TETRA_REGION"));
1201 TS_ASSERT_EQUALS(XMU_PARAMETRIC_HEX_REGION, iCellTypeFromString(
"PARAMETRIC_HEX_REGION"));
1202 TS_ASSERT_EQUALS(XMU_HIGHER_ORDER_EDGE, iCellTypeFromString(
"HIGHER_ORDER_EDGE"));
1203 TS_ASSERT_EQUALS(XMU_HIGHER_ORDER_TRIANGLE, iCellTypeFromString(
"HIGHER_ORDER_TRIANGLE"));
1204 TS_ASSERT_EQUALS(XMU_HIGHER_ORDER_QUAD, iCellTypeFromString(
"HIGHER_ORDER_QUAD"));
1205 TS_ASSERT_EQUALS(XMU_HIGHER_ORDER_POLYGON, iCellTypeFromString(
"HIGHER_ORDER_POLYGON"));
1206 TS_ASSERT_EQUALS(XMU_HIGHER_ORDER_TETRAHEDRON, iCellTypeFromString(
"HIGHER_ORDER_TETRAHEDRON"));
1207 TS_ASSERT_EQUALS(XMU_HIGHER_ORDER_WEDGE, iCellTypeFromString(
"HIGHER_ORDER_WEDGE"));
1208 TS_ASSERT_EQUALS(XMU_HIGHER_ORDER_PYRAMID, iCellTypeFromString(
"HIGHER_ORDER_PYRAMID"));
1209 TS_ASSERT_EQUALS(XMU_HIGHER_ORDER_HEXAHEDRON, iCellTypeFromString(
"HIGHER_ORDER_HEXAHEDRON"));
1210 TS_ASSERT_EQUALS(50, iCellTypeStringIntPair().size());
1218 #include <boost/timer/timer.hpp> 1226 std::shared_ptr<xms::XmUGrid> grid;
1228 boost::timer::cpu_timer timer;
1230 std::cerr <<
"Build time: " + timer.format();
1234 std::ofstream output(
"speed_test_out.txt");
1235 boost::timer::cpu_timer timer;
1238 std::cerr <<
"Write time: " + timer.format();
1241 std::shared_ptr<XmUGrid> gridRead;
1243 std::ifstream input(
"speed_test_out.txt");
1244 boost::timer::cpu_timer timer;
1246 std::cerr <<
"Read time: " + timer.format();
1249 TS_ASSERT_EQUALS(grid->GetLocations(), gridRead->GetLocations());
1250 TS_ASSERT_EQUALS(grid->GetCellstream(), gridRead->GetCellstream());
1260 std::string inputText =
1261 "ASCII XmUGrid Version 2\n" 1263 " POINT 0 0.0 0.0 0.0\n" 1264 " POINT 1 20.0 0.0 0.0\n" 1265 " POINT 2 0.0 20.0 0.0\n" 1267 " CELL 0 TRIANGLE 3 0 1 2\n" 1269 std::istringstream input;
1270 input.str(inputText);
1275 VecPt3d locations = ugrid->GetLocations();
1276 TS_ASSERT_EQUALS(ugridBase->GetLocations(), locations);
1277 VecInt cellstream = ugrid->GetCellstream();
1278 TS_ASSERT_EQUALS(ugridBase->GetCellstream(), cellstream);
1283 TS_ASSERT_EQUALS(
"LEFT OVER LINE", line);
std::shared_ptr< XmUGrid > TEST_XmUGrid1Left90Tri()
Builds a 1 cell (left 90 degree triangle) 2D XmUGrid for testing.
std::shared_ptr< XmUGrid > TEST_XmUGrid3dLinear()
Builds an XmUGrid with supported 3D linear cells for testing.
Contains the XmUGrid Class and supporting data types.
bool daReadLine(std::istream &a_inStream, std::string &a_line)
std::vector< int > VecInt
bool ReadString(std::string &a_val)
void testLinear2dWriteThenRead()
Test reading an ASCII file for a single triangle UGrid.
std::shared_ptr< XmUGrid > XmReadUGridFromStream(std::istream &a_inStream)
Read an XmUGrid from ASCII text from an input stream.
void testReadBasicUGrid()
Test reading an ASCII file for a single triangle UGrid.
std::shared_ptr< xms::XmUGrid > TEST_XmUBuildPolyhedronUgrid(int a_rows, int a_cols, int a_lays)
Builds a UGrid of Quads at 1 spacing for rows & cols specified.
void AppendInts(const int *a_vals, int a_numVals)
void testReadPolyhedronUGrid()
Test reading an ASCII file for a single triangle UGrid.
void testWriteLinear2dCells()
Test writing an ASCII file for UGrid with supported 1D and 2D linear cell types.
Contains IO functions as well as several utility functions for XmUGrid.
void WriteIntLine(const char *a_name, int a_val)
void XmWriteUGridToStream(std::shared_ptr< XmUGrid > a_ugrid, std::ostream &a_outStream)
Save an XmUGrid ASCII text to output stream.
void testWriteEmptyUGrid()
Test writing an ASCII file for an empty UGrid.
const VecPt3d & GetLocations() const
Get vector of UGrid points.
void testWriteThenReadUGridBinary()
Test writing then reading an XmUGrid binary file.
std::shared_ptr< XmUGrid > TEST_XmUGrid2dLinear()
Builds an XmUGrid with supported 1D and 2D linear cells for testing.
void testWriteBasicUGrid()
Test writing an ASCII file for a single triangle UGrid.
void testWriteLinear3dCells()
Test writing an ASCII file for UGrid with supported 1D and 2D linear cell types.
bool ReadIntLine(const char *a_name, int &a_val)
bool ReadLine(std::string &a_line)
void WriteString(const char *a_string)
bool ReadVecInt(const char *a_name, VecInt &a_vec)
void XmWriteUGridToAsciiFile(std::shared_ptr< XmUGrid > a_ugrid, const std::string &a_filePath)
Write an XmUGrid to an ASCII file.
void testLinear3dWriteThenRead()
Test reading an ASCII file for a single triangle UGrid.
bool Read3DoubleLine(const char *a_name, double &a_val1, double &a_val2, double &a_val3)
void testWriteThenReadUGridFileToAscii()
[snip_test_WriteReadAscii]
std::shared_ptr< XmUGrid > TEST_XmUGridHexagonalPolyhedron()
Builds a 1 cell hexagon with cell type polyhedron.
void testWriteThenReadUGridFile()
Test reading from file.
void AppendString(const std::string &a_val)
void testCellStringToEnum()
Test conversion between cell type string and cell type enum.
void testLargeUGridBinarySpeed()
Tests creating a large UGrid and checks the time spent.
Geometry for an unstructured grid. An XmUGrid is defined as a vector of 3d points and a stream of cel...
void AppendInt(int a_val)
const VecInt & GetCellstream() const
Get cell stream vector for the entire UGrid. A cellstream is defined as follows: Polyhedrons: Cell ty...
void testWritePolyhedronUGrid()
Test writing an ASCII file for a single polyhedron UGrid.
static bool ReadStringFromLine(std::string &a_line, std::string &a_val)
void testReadReadyAtNextLine()
Test reading XmUGrid to make sure it doesn't read the whole file. Should leave stream at next line af...
bool ReadVecPt3d(const char *a_name, VecPt3d &a_vec)
void testReadEmptyUGridAsciiFile()
Test reading an ASCII file for an empty UGrid.
static std::shared_ptr< XmUGrid > New()
Create a new XmUGrid.
bool daReadIntFromLine(std::string &a_line, int &a_val)
std::vector< Pt3d > VecPt3d
std::shared_ptr< XmUGrid > XmReadUGridFromAsciiFile(const std::string &a_filePath)
Read XmUGrid from an ASCII file.
void testReadVersion1Dot0File()
[snip_test_WriteReadAscii]