bool Foam::triSurface::readGTS(const fileName& GTSfileName) { IFstream GTSfile(GTSfileName); if (!GTSfile.good()) { FatalErrorIn("triSurface::readGTS(const fileName&)") << "Cannot read file " << GTSfileName << exit(FatalError); } // Read header label nPoints, nEdges, nElems; string line = getLineNoComment(GTSfile); { IStringStream lineStream(line); lineStream >> nPoints >> nEdges >> nElems; } // Read points pointField& points_ = const_cast<pointField&>(points()); points_.setSize(nPoints); forAll(points_, pointi) { scalar x, y, z; line = getLineNoComment(GTSfile); { IStringStream lineStream(line); lineStream >> x >> y >> z; } points_[pointi] = point(x, y, z); }
forAll(edges, edgei) { label start, end; line = getLineNoComment(GTSfile); { IStringStream lineStream(line); lineStream >> start >> end; } edges[edgei] = edge(start - 1, end - 1); }
bool Foam::triSurface::readOFF(const fileName& OFFfileName) { IFstream OFFfile(OFFfileName); if (!OFFfile.good()) { FatalErrorIn("triSurface::readOFF(const fileName&)") << "Cannot read file " << OFFfileName << exit(FatalError); } // Read header string hdr = getLineNoComment(OFFfile); if (hdr != "OFF") { FatalErrorIn("triSurface::readOFF(const fileName&)") << "OFF file " << OFFfileName << " does not start with 'OFF'" << exit(FatalError); } label nPoints, nEdges, nElems; string line = getLineNoComment(OFFfile); { IStringStream lineStream(line); lineStream >> nPoints >> nElems >> nEdges; } // Read points pointField points(nPoints); forAll(points, pointi) { scalar x, y, z; line = getLineNoComment(OFFfile); { IStringStream lineStream(line); lineStream >> x >> y >> z; } points[pointi] = point(x, y, z); }
line = getLineNoComment(GTSfile); { IStringStream lineStream(line); lineStream >> start >> end; } edges[edgei] = edge(start - 1, end - 1); } // Read triangles. Convert references to edges into pointlabels setSize(nElems); forAll(*this, trianglei) { label e0Label, e1Label, e2Label; label region = 0; line = getLineNoComment(GTSfile); { IStringStream lineStream(line); lineStream >> e0Label >> e1Label >> e2Label; // Optional region number: read first, then check state on stream if (lineStream) { label num; lineStream >> num; if (!lineStream.bad()) { region = num; } } }