38std::string
readPoints(std::istream& in, std::vector<GeoLib::Point*>* pnt_vec,
39 bool& zero_based_indexing,
40 std::map<std::string, std::size_t>* pnt_id_name_map)
45 std::getline(in, line);
48 while (line.find(
'#') == std::string::npos && !in.eof() && !in.fail())
51 std::stringstream inss(line);
56 inss >>
id >> x >> y >> z;
61 zero_based_indexing =
id == 0;
66 if (line.find(
"$MD") != std::string::npos)
69 std::size_t pos1(line.find_first_of(
'M'));
70 inss.str(line.substr(pos1 + 2, std::string::npos));
75 std::size_t pos(line.find(
"$NAME"));
76 if (pos != std::string::npos)
78 std::size_t end_pos((line.substr(pos + 6)).find(
' '));
79 if (end_pos != std::string::npos)
81 (*pnt_id_name_map)[line.substr(pos + 6, end_pos)] = id;
85 (*pnt_id_name_map)[line.substr(pos + 6)] = id;
89 std::size_t id_pos(line.find(
"$ID"));
90 if (id_pos != std::string::npos)
93 "readPoints(): found tag $ID - please use tag $NAME for "
94 "reading point names in point {:d}.",
99 std::getline(in, line);
107 std::vector<GeoLib::Point*>& pnt_vec,
109 const std::string& path,
110 std::vector<std::string>& errors)
116 WARN(
"readPolylinePointVector(): error opening stream from {:s}",
119 "[readPolylinePointVector] error opening stream from " + fname);
129 std::size_t pnt_id(pnt_vec.size());
148 std::vector<GeoLib::Polyline*>& ply_vec,
150 std::vector<GeoLib::Point*>& pnt_vec,
151 bool zero_based_indexing,
152 const std::vector<std::size_t>& pnt_id_map,
153 const std::string& path,
154 std::vector<std::string>& errors)
157 std::string name_of_ply;
159 std::size_t type = 2;
165 if (line.find(
"$ID") != std::string::npos)
170 if (line.find(
"$NAME") != std::string::npos)
176 if (line.find(
"$TYPE") != std::string::npos)
179 type =
static_cast<std::size_t
>(strtol(line.c_str(),
nullptr, 0));
182 if (line.find(
"$EPSILON") != std::string::npos)
187 if (line.find(
"$MAT_GROUP") != std::string::npos)
192 if (line.find(
"$POINTS") != std::string::npos)
197 while (!in.eof() && !in.fail() && !line.empty() &&
198 (line.find(
'#') == std::string::npos) &&
199 (line.find(
'$') == std::string::npos))
202 if (!zero_based_indexing)
206 std::size_t ply_size(ply->getNumberOfPoints());
209 if (ply->getPointID(ply_size - 1) != pnt_id_map[pnt_id])
211 ply->addPoint(pnt_id_map[pnt_id]);
216 ply->addPoint(pnt_id_map[pnt_id]);
224 "readPolyline(): polyline is an arc *** reading not "
227 "[readPolyline] reading polyline as an arc is not "
233 if (line.find(
"$POINT_VECTOR") !=
240 }
while (line.find(
'#') == std::string::npos && !line.empty() && in);
244 ply_vec_names.insert(
245 std::pair<std::string, std::size_t>(name_of_ply, ply_vec.size()));
246 ply_vec.push_back(ply);
264 std::vector<GeoLib::Polyline*>& ply_vec,
265 std::map<std::string, std::size_t>& ply_vec_names,
266 std::vector<GeoLib::Point*>& pnt_vec,
267 bool zero_based_indexing,
268 const std::vector<std::size_t>& pnt_id_map,
269 const std::string& path,
270 std::vector<std::string>& errors)
274 WARN(
"readPolylines(): input stream error.");
275 return std::string(
"");
277 std::string tag(
"#POLYLINE");
279 while (!in.eof() && !in.fail() &&
280 tag.find(
"#POLYLINE") != std::string::npos)
283 zero_based_indexing, pnt_id_map, path, errors);
300 std::vector<GeoLib::Polygon*>& polygon_vec,
301 std::vector<GeoLib::Surface*>& sfc_vec,
302 std::map<std::string, std::size_t>& sfc_names,
303 const std::vector<GeoLib::Polyline*>*
const ply_vec,
304 const std::map<std::string, std::size_t>& ply_vec_names,
306 std::vector<std::string>& errors)
313 std::size_t ply_id(std::numeric_limits<std::size_t>::max());
318 if (line.find(
"$ID") != std::string::npos)
323 if (line.find(
"$NAME") != std::string::npos)
329 if (line.find(
"$TYPE") != std::string::npos)
332 type = strtol(line.c_str(),
nullptr, 0);
335 if (line.find(
"$EPSILON") != std::string::npos)
340 if (line.find(
"$TIN") != std::string::npos)
348 if (line.find(
"$MAT_GROUP") != std::string::npos)
353 if (line.find(
"$POLYLINES") != std::string::npos)
356 while (!in.eof() && !in.fail() && !line.empty() &&
357 (line.find(
'#') == std::string::npos) &&
358 (line.find(
'$') == std::string::npos))
360 if (ply_vec ==
nullptr)
362 OGS_FATAL(
"The polyline vector is not allocated.");
367 auto it(ply_vec_names.find(line));
368 if (it != ply_vec_names.end())
374 ply_id = ply_vec->size();
377 if (ply_id == ply_vec->size())
379 WARN(
"readSurface(): polyline for surface not found!");
381 "[readSurface] polyline for surface not found!");
388 "readSurface(): surface type 3: flat surface with "
389 "any normal direction - reading not implemented.");
391 "[readSurface] surface type 3: flat surface with "
392 "any normal direction - reading not implemented");
397 "readSurface(): vertical surface (type 2) - "
398 "reading not implemented");
400 "[readSurface] vertical surface (type 2) - reading "
408 }
while (line.find(
'#') == std::string::npos && !line.empty() && in);
413 std::pair<std::string, std::size_t>(name, sfc_vec.size()));
419 sfc_vec.push_back(sfc);
424 if (ply_id != std::numeric_limits<std::size_t>::max())
426 if (ply_vec ==
nullptr)
428 OGS_FATAL(
"The polyline vector is not allocated.");
431 if (ply_id != ply_vec->size())
433 if ((*ply_vec)[ply_id]->isClosed())
435 polygon_vec.push_back(
441 "readSurface(): cannot create surface {:s} from "
442 "polyline {:d} since polyline is not closed.",
461 std::istream& in, std::vector<GeoLib::Surface*>& sfc_vec,
462 std::map<std::string, std::size_t>& sfc_names,
463 const std::vector<GeoLib::Polyline*>*
const ply_vec,
464 const std::map<std::string, std::size_t>& ply_vec_names,
467 std::string
const& unique_name, std::string
const& gmsh_path)
471 WARN(
"readSurfaces(): input stream error.");
472 return std::string(
"");
474 std::string tag(
"#SURFACE");
476 std::vector<GeoLib::Polygon*> polygon_vec;
478 while (!in.eof() && !in.fail() && tag.find(
"#SURFACE") != std::string::npos)
480 std::size_t n_polygons(polygon_vec.size());
481 tag =
readSurface(in, polygon_vec, sfc_vec, sfc_names, ply_vec,
482 ply_vec_names, pnt_vec, path, errors);
483 if (n_polygons < polygon_vec.size())
485 INFO(
"Creating a surface by triangulation of the polyline ...");
488 unique_name, gmsh_path))
495 "\t Creating a surface by triangulation of the polyline "
500 for (
auto& k : polygon_vec)
510 std::string& unique_name,
511 std::vector<std::string>& errors,
512 std::string
const& gmsh_path)
514 INFO(
"GeoLib::readGLIFile(): open stream from file {:s}.", fname);
515 std::ifstream in(fname.c_str());
518 WARN(
"GeoLib::readGLIFile(): could not open file {:s}.", fname);
519 errors.push_back(
"[readGLIFileV4] error opening stream from " + fname);
522 INFO(
"GeoLib::readGLIFile(): \t done.");
525 while (tag.find(
"#POINTS") == std::string::npos && !in.eof())
527 std::getline(in, tag);
531 std::map<std::string, std::size_t> pnt_id_names_map;
533 bool zero_based_idx(
true);
534 std::vector<GeoLib::Point*> pnt_vec;
535 INFO(
"GeoLib::readGLIFile(): read points from stream.");
536 tag =
readPoints(in, &pnt_vec, zero_based_idx, &pnt_id_names_map);
537 INFO(
"GeoLib::readGLIFile(): \t ok, {:d} points read.", pnt_vec.size());
540 if (!pnt_vec.empty())
543 std::move(pnt_id_names_map), 1e-6);
551 std::vector<GeoLib::Polyline*> ply_vec;
555 const_cast<std::vector<GeoLib::Point*>&
>(point_vec.
getVector()));
556 if (tag.find(
"#POLYLINE") != std::string::npos && in)
558 INFO(
"GeoLib::readGLIFile(): read polylines from stream.");
559 tag =
readPolylines(in, ply_vec, ply_names, geo_pnt_vec, zero_based_idx,
562 INFO(
"GeoLib::readGLIFile(): \t ok, {:d} polylines read.",
567 INFO(
"GeoLib::readGLIFile(): tag #POLYLINE not found.");
570 if (!ply_vec.empty())
573 std::move(ply_names));
578 std::map<std::string, std::size_t> ply_names_copy;
581 ply_names_copy = std::map<std::string, std::size_t>{
586 std::vector<GeoLib::Surface*> sfc_vec;
588 if (tag.find(
"#SURFACE") != std::string::npos && in)
590 INFO(
"GeoLib::readGLIFile(): read surfaces from stream.");
593 ply_names_copy, point_vec, path, errors, geo, unique_name,
595 INFO(
"GeoLib::readGLIFile(): \tok, {:d} surfaces read.",
600 INFO(
"GeoLib::readGLIFile(): tag #SURFACE not found.");
604 if (!sfc_vec.empty())
607 std::move(sfc_names));
610 return errors.empty();
615 std::size_t sfc_count, std::string
const& path)
618 for (
auto const* sfc : sfcs)
622 std::string sfc_name;
627 <<
"\t\t" << sfc_name <<
"\n";
633 <<
"\t\t" << sfc_count <<
"\n";
634 sfc_name = std::to_string(sfc_count);
639 os <<
"\t\t" << sfc_name <<
"\n";
649 const std::string& geo_name,
652 std::ofstream os(fname.c_str());
656 auto const& pnts(pnt_vec->getVector());
657 const std::size_t n_pnts(pnts.size());
658 INFO(
"GeoLib::writeGLIFileV4(): writing {:d} points to file {:s}.",
662 os.precision(std::numeric_limits<double>::max_digits10);
663 for (std::size_t k(0); k < n_pnts; k++)
665 os << k <<
" " << *(pnts[k]);
666 std::string
const& pnt_name(pnt_vec->getItemNameByID(k));
667 if (!pnt_name.empty())
669 os <<
" $NAME " << pnt_name;
678 auto const& plys(plys_vec->getVector());
679 INFO(
"GeoLib::writeGLIFileV4(): {:d} polylines to file {:s}.",
681 for (
auto ply : plys)
685 std::string polyline_name;
686 plys_vec->getNameOfElement(ply, polyline_name);
689 <<
" " << polyline_name <<
"\n";
692 for (std::size_t j(0); j < ply->getNumberOfPoints(); j++)
694 os <<
" " << ply->getPointID(j) <<
"\n";
719 std::ofstream os(fname.c_str());
721 std::size_t pnts_offset(0);
722 std::vector<std::size_t> pnts_id_offset;
723 pnts_id_offset.push_back(0);
728 for (
auto const& geo_name : geo_names)
730 os.precision(std::numeric_limits<double>::max_digits10);
735 const std::size_t n_pnts(pnts.size());
736 for (std::size_t k(0); k < n_pnts; k++)
738 os << pnts_offset + k <<
" " << *(pnts[k]);
740 if (!pnt_name.empty())
742 os <<
"$NAME " << pnt_name;
746 pnts_offset += pnts.size();
747 pnts_id_offset.push_back(pnts_offset);
751 INFO(
"GeoLib::writeAllDataToGLIFileV4(): wrote {:d} points.", pnts_offset);
754 std::vector<std::string> stn_names;
756 for (
auto& stn_name : stn_names)
758 os.precision(std::numeric_limits<double>::max_digits10);
759 const std::vector<GeoLib::Point*>* pnts(geo.
getStationVec(stn_name));
762 for (std::size_t k(0); k < pnts->size(); k++)
764 os << k + pnts_offset <<
" " << *((*pnts)[k]) <<
" $NAME "
768 pnts_offset += pnts->size();
769 pnts_id_offset.push_back(pnts_offset);
773 std::size_t plys_cnt(0);
776 for (std::size_t j(0); j < geo_names.size(); j++)
783 for (
auto ply : plys)
787 std::string ply_name;
791 os <<
" " << ply_name <<
"\n";
795 os <<
" " << geo_names[j] <<
"-" << plys_cnt <<
"\n";
799 for (std::size_t l(0); l < ply->getNumberOfPoints(); l++)
801 os <<
" " << pnts_id_offset[j] + ply->getPointID(l)
810 std::size_t sfcs_cnt(0);
811 for (
auto const& geo_name : geo_names)
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Container class for geometric objects.
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
void addPolylineVec(std::vector< Polyline * > &&lines, std::string const &name, PolylineVec::NameIdMap &&ply_names)
void addPointVec(std::vector< Point * > &&points, std::string &name, PointVec::NameIdMap &&pnt_id_name_map, double const eps=std::sqrt(std::numeric_limits< double >::epsilon()))
const PointVec * getPointVecObj(const std::string &name) const
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
void addSurfaceVec(std::vector< Surface * > &&sfc, const std::string &name, SurfaceVec::NameIdMap &&sfc_names)
const PolylineVec * getPolylineVecObj(const std::string &name) const
void getStationVectorNames(std::vector< std::string > &names) const
Returns the names of all station vectors.
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
const std::vector< GeoLib::Point * > * getStationVec(const std::string &name) const
Returns the station vector with the given name.
static GeoLib::Surface * readTIN(std::string const &fname, GeoLib::PointVec &pnt_vec, std::vector< std::string > *errors=nullptr)
static void writeSurfaceAsTIN(GeoLib::Surface const &surface, std::string const &file_name)
This class manages pointers to Points in a std::vector along with a name. It also handles the deletio...
const std::vector< std::size_t > & getIDMap() const
std::string const & getItemNameByID(std::size_t id) const
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
virtual bool addPoint(std::size_t pnt_id)
A Station (observation site) is basically a Point with some additional information.
std::string const & getName() const
Returns the name of the station.
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
std::map< std::string, std::size_t > NameIdMap
NameIdMap::const_iterator getNameIDMapBegin() const
Returns the begin of the name id mapping structure.
bool getNameOfElementByID(std::size_t id, std::string &element_name) const
std::vector< T * > const & getVector() const
NameIdMap::const_iterator getNameIDMapEnd() const
Returns the end of the name id mapping structure.
std::string extractPath(std::string const &pathname)
std::string joinPaths(std::string const &pathA, std::string const &pathB)
std::string extractBaseName(std::string const &pathname)
T str2number(const std::string &str)
std::size_t writeTINSurfaces(std::ofstream &os, GeoLib::SurfaceVec const *sfcs_vec, std::size_t sfc_count, std::string const &path)
std::string readPolyline(std::istream &in, std::vector< GeoLib::Polyline * > &ply_vec, GeoLib::PolylineVec::NameIdMap &ply_vec_names, std::vector< GeoLib::Point * > &pnt_vec, bool zero_based_indexing, const std::vector< std::size_t > &pnt_id_map, const std::string &path, std::vector< std::string > &errors)
std::string readPolylines(std::istream &in, std::vector< GeoLib::Polyline * > &ply_vec, std::map< std::string, std::size_t > &ply_vec_names, std::vector< GeoLib::Point * > &pnt_vec, bool zero_based_indexing, const std::vector< std::size_t > &pnt_id_map, const std::string &path, std::vector< std::string > &errors)
bool readGLIFileV4(const std::string &fname, GeoLib::GEOObjects &geo, std::string &unique_name, std::vector< std::string > &errors, std::string const &gmsh_path)
void readPolylinePointVector(const std::string &fname, std::vector< GeoLib::Point * > &pnt_vec, GeoLib::Polyline *ply, const std::string &path, std::vector< std::string > &errors)
void writeGLIFileV4(const std::string &fname, const std::string &geo_name, const GeoLib::GEOObjects &geo)
std::string readSurfaces(std::istream &in, std::vector< GeoLib::Surface * > &sfc_vec, std::map< std::string, std::size_t > &sfc_names, const std::vector< GeoLib::Polyline * > *const ply_vec, const std::map< std::string, std::size_t > &ply_vec_names, GeoLib::PointVec &pnt_vec, const std::string &path, std::vector< std::string > &errors, GeoLib::GEOObjects &geo, std::string const &unique_name, std::string const &gmsh_path)
std::string readPoints(std::istream &in, std::vector< GeoLib::Point * > *pnt_vec, bool &zero_based_indexing, std::map< std::string, std::size_t > *pnt_id_name_map)
void writeAllDataToGLIFileV4(const std::string &fname, const GeoLib::GEOObjects &geo)
std::string readSurface(std::istream &in, std::vector< GeoLib::Polygon * > &polygon_vec, std::vector< GeoLib::Surface * > &sfc_vec, std::map< std::string, std::size_t > &sfc_names, const std::vector< GeoLib::Polyline * > *const ply_vec, const std::map< std::string, std::size_t > &ply_vec_names, GeoLib::PointVec &pnt_vec, std::string const &path, std::vector< std::string > &errors)
bool createSurface(GeoLib::Polyline const &ply, GeoLib::GEOObjects &geometries, std::string const &geometry_name, std::string const &gmsh_binary)
TemplateVec< GeoLib::Surface > SurfaceVec
TemplateVec< GeoLib::Polyline > PolylineVec
class PolylineVec encapsulate a std::vector of Polylines additional one can give the vector of polyli...