Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <triSurface/triSurface.H>
00029 #include <OpenFOAM/IFstream.H>
00030 #include <OpenFOAM/IStringStream.H>
00031
00032
00033
00034 namespace Foam
00035 {
00036
00037
00038
00039 bool triSurface::readGTS(const fileName& GTSfileName)
00040 {
00041 IFstream GTSfile(GTSfileName);
00042
00043 if (!GTSfile.good())
00044 {
00045 FatalErrorIn("triSurface::readGTS(const fileName&)")
00046 << "Cannot read file " << GTSfileName
00047 << exit(FatalError);
00048 }
00049
00050
00051 label nPoints, nEdges, nElems;
00052
00053 string line = getLineNoComment(GTSfile);
00054 {
00055 IStringStream lineStream(line);
00056 lineStream >> nPoints >> nEdges >> nElems;
00057 }
00058
00059
00060 pointField& points_ = const_cast<pointField&>(points());
00061 points_.setSize(nPoints);
00062
00063 forAll(points_, pointi)
00064 {
00065 scalar x, y, z;
00066 line = getLineNoComment(GTSfile);
00067 {
00068 IStringStream lineStream(line);
00069 lineStream >> x >> y >> z;
00070 }
00071 points_[pointi] = point(x, y, z);
00072 }
00073
00074
00075 edgeList edges(nEdges);
00076 forAll(edges, edgei)
00077 {
00078 label start, end;
00079 line = getLineNoComment(GTSfile);
00080 {
00081 IStringStream lineStream(line);
00082 lineStream >> start >> end;
00083 }
00084 edges[edgei] = edge(start - 1, end - 1);
00085 }
00086
00087
00088 setSize(nElems);
00089 forAll(*this, trianglei)
00090 {
00091 label e0Label, e1Label, e2Label;
00092 label region = 0;
00093
00094 line = getLineNoComment(GTSfile);
00095 {
00096 IStringStream lineStream(line);
00097 lineStream >> e0Label >> e1Label >> e2Label;
00098
00099
00100 if (lineStream)
00101 {
00102 label num;
00103 lineStream >> num;
00104 if (!lineStream.bad())
00105 {
00106 region = num;
00107 }
00108 }
00109 }
00110
00111
00112
00113
00114
00115 const edge& e0 = edges[e0Label - 1];
00116 const edge& e1 = edges[e1Label - 1];
00117 const edge& e2 = edges[e2Label - 1];
00118
00119 label common01 = e0.commonVertex(e1);
00120 if (common01 == -1)
00121 {
00122 FatalErrorIn("triSurface::readGTS(const fileName&)")
00123 << "Edges 0 and 1 of triangle " << trianglei
00124 << " do not share a point.\n"
00125 << " edge0:" << e0 << endl
00126 << " edge1:" << e1
00127 << exit(FatalError);
00128 }
00129
00130 label e0Far = e0.otherVertex(common01);
00131 label e1Far = e1.otherVertex(common01);
00132
00133 label common12 = e1.commonVertex(e2);
00134 if (common12 == -1)
00135 {
00136 FatalErrorIn("triSurface::readGTS(const fileName&)")
00137 << "Edges 1 and 2 of triangle " << trianglei
00138 << " do not share a point.\n"
00139 << " edge1:" << e1 << endl
00140 << " edge2:" << e2
00141 << exit(FatalError);
00142 }
00143 label e2Far = e2.otherVertex(common12);
00144
00145
00146 if ((common12 != e1Far) || (e2Far != e0Far))
00147 {
00148 FatalErrorIn("triSurface::readGTS(const fileName&)")
00149 << "Edges of triangle " << trianglei
00150 << " reference more than three points.\n"
00151 << " edge0:" << e0 << endl
00152 << " edge1:" << e1 << endl
00153 << " edge2:" << e2 << endl
00154 << exit(FatalError);
00155 }
00156
00157 operator[](trianglei) = labelledTri(e0Far, common01, e1Far, region);
00158 }
00159
00160
00161 setDefaultPatches();
00162
00163 return true;
00164 }
00165
00166
00167
00168
00169 }
00170
00171