49std::string
readPoints(std::istream& in, std::vector<GeoLib::Point*>* pnt_vec,
50 bool& zero_based_indexing,
51 std::map<std::string, std::size_t>* pnt_id_name_map)
56 std::getline(in, line);
59 while (line.find(
'#') == std::string::npos && !in.eof() && !in.fail())
62 std::stringstream inss(line);
67 inss >>
id >> x >> y >> z;
72 zero_based_indexing =
id == 0;
77 if (line.find(
"$MD") != std::string::npos)
80 std::size_t pos1(line.find_first_of(
'M'));
81 inss.str(line.substr(pos1 + 2, std::string::npos));
86 std::size_t pos(line.find(
"$NAME"));
87 if (pos != std::string::npos)
89 std::size_t end_pos((line.substr(pos + 6)).find(
' '));
90 if (end_pos != std::string::npos)
92 (*pnt_id_name_map)[line.substr(pos + 6, end_pos)] = id;
96 (*pnt_id_name_map)[line.substr(pos + 6)] = id;
100 std::size_t id_pos(line.find(
"$ID"));
101 if (id_pos != std::string::npos)
104 "readPoints(): found tag $ID - please use tag $NAME for "
105 "reading point names in point {:d}.",
110 std::getline(in, line);
118 std::vector<GeoLib::Point*>& pnt_vec,
120 const std::string& path,
121 std::vector<std::string>& errors)
127 WARN(
"readPolylinePointVector(): error opening stream from {:s}",
130 "[readPolylinePointVector] error opening stream from " + fname);
140 std::size_t pnt_id(pnt_vec.size());
159 std::vector<GeoLib::Polyline*>& ply_vec,
161 std::vector<GeoLib::Point*>& pnt_vec,
162 bool zero_based_indexing,
163 const std::vector<std::size_t>& pnt_id_map,
164 const std::string& path,
165 std::vector<std::string>& errors)
168 std::string name_of_ply;
170 std::size_t type = 2;
176 if (line.find(
"$ID") != std::string::npos)
181 if (line.find(
"$NAME") != std::string::npos)
187 if (line.find(
"$TYPE") != std::string::npos)
190 type =
static_cast<std::size_t
>(strtol(line.c_str(),
nullptr, 0));
193 if (line.find(
"$EPSILON") != std::string::npos)
198 if (line.find(
"$MAT_GROUP") != std::string::npos)
203 if (line.find(
"$POINTS") != std::string::npos)
208 while (!in.eof() && !in.fail() && !line.empty() &&
209 (line.find(
'#') == std::string::npos) &&
210 (line.find(
'$') == std::string::npos))
213 if (!zero_based_indexing)
217 std::size_t ply_size(ply->getNumberOfPoints());
220 if (ply->getPointID(ply_size - 1) != pnt_id_map[pnt_id])
222 ply->addPoint(pnt_id_map[pnt_id]);
227 ply->addPoint(pnt_id_map[pnt_id]);
235 "readPolyline(): polyline is an arc *** reading not "
238 "[readPolyline] reading polyline as an arc is not "
244 if (line.find(
"$POINT_VECTOR") !=
251 }
while (line.find(
'#') == std::string::npos && !line.empty() && in);
255 ply_vec_names.insert(
256 std::pair<std::string, std::size_t>(name_of_ply, ply_vec.size()));
257 ply_vec.push_back(ply);
275 std::vector<GeoLib::Polyline*>& ply_vec,
276 std::map<std::string, std::size_t>& ply_vec_names,
277 std::vector<GeoLib::Point*>& pnt_vec,
278 bool zero_based_indexing,
279 const std::vector<std::size_t>& pnt_id_map,
280 const std::string& path,
281 std::vector<std::string>& errors)
285 WARN(
"readPolylines(): input stream error.");
286 return std::string(
"");
288 std::string tag(
"#POLYLINE");
290 while (!in.eof() && !in.fail() &&
291 tag.find(
"#POLYLINE") != std::string::npos)
294 zero_based_indexing, pnt_id_map, path, errors);
311 std::vector<GeoLib::Polygon*>& polygon_vec,
312 std::vector<GeoLib::Surface*>& sfc_vec,
313 std::map<std::string, std::size_t>& sfc_names,
314 const std::vector<GeoLib::Polyline*>*
const ply_vec,
315 const std::map<std::string, std::size_t>& ply_vec_names,
317 std::vector<std::string>& errors)
324 std::size_t ply_id(std::numeric_limits<std::size_t>::max());
329 if (line.find(
"$ID") != std::string::npos)
334 if (line.find(
"$NAME") != std::string::npos)
340 if (line.find(
"$TYPE") != std::string::npos)
343 type = strtol(line.c_str(),
nullptr, 0);
346 if (line.find(
"$EPSILON") != std::string::npos)
351 if (line.find(
"$TIN") != std::string::npos)
359 if (line.find(
"$MAT_GROUP") != std::string::npos)
364 if (line.find(
"$POLYLINES") != std::string::npos)
367 while (!in.eof() && !in.fail() && !line.empty() &&
368 (line.find(
'#') == std::string::npos) &&
369 (line.find(
'$') == std::string::npos))
371 if (ply_vec ==
nullptr)
373 OGS_FATAL(
"The polyline vector is not allocated.");
378 auto it(ply_vec_names.find(line));
379 if (it != ply_vec_names.end())
385 ply_id = ply_vec->size();
388 if (ply_id == ply_vec->size())
390 WARN(
"readSurface(): polyline for surface not found!");
392 "[readSurface] polyline for surface not found!");
399 "readSurface(): surface type 3: flat surface with "
400 "any normal direction - reading not implemented.");
402 "[readSurface] surface type 3: flat surface with "
403 "any normal direction - reading not implemented");
408 "readSurface(): vertical surface (type 2) - "
409 "reading not implemented");
411 "[readSurface] vertical surface (type 2) - reading "
419 }
while (line.find(
'#') == std::string::npos && !line.empty() && in);
424 std::pair<std::string, std::size_t>(name, sfc_vec.size()));
430 sfc_vec.push_back(sfc);
435 if (ply_id != std::numeric_limits<std::size_t>::max())
437 if (ply_vec ==
nullptr)
439 OGS_FATAL(
"The polyline vector is not allocated.");
442 if (ply_id != ply_vec->size())
444 if ((*ply_vec)[ply_id]->isClosed())
446 polygon_vec.push_back(
452 "readSurface(): cannot create surface {:s} from "
453 "polyline {:d} since polyline is not closed.",
472 std::istream& in, std::vector<GeoLib::Surface*>& sfc_vec,
473 std::map<std::string, std::size_t>& sfc_names,
474 const std::vector<GeoLib::Polyline*>*
const ply_vec,
475 const std::map<std::string, std::size_t>& ply_vec_names,
478 std::string
const& unique_name, std::string
const& gmsh_path)
482 WARN(
"readSurfaces(): input stream error.");
483 return std::string(
"");
485 std::string tag(
"#SURFACE");
487 std::vector<GeoLib::Polygon*> polygon_vec;
489 while (!in.eof() && !in.fail() && tag.find(
"#SURFACE") != std::string::npos)
491 std::size_t n_polygons(polygon_vec.size());
492 tag =
readSurface(in, polygon_vec, sfc_vec, sfc_names, ply_vec,
493 ply_vec_names, pnt_vec, path, errors);
494 if (n_polygons < polygon_vec.size())
496 INFO(
"Creating a surface by triangulation of the polyline ...");
499 unique_name, gmsh_path))
506 "\t Creating a surface by triangulation of the polyline "
511 for (
auto& k : polygon_vec)
521 std::string& unique_name,
522 std::vector<std::string>& errors,
523 std::string
const& gmsh_path)
525 INFO(
"GeoLib::readGLIFile(): open stream from file {:s}.", fname);
526 std::ifstream in(fname.c_str());
529 WARN(
"GeoLib::readGLIFile(): could not open file {:s}.", fname);
530 errors.push_back(
"[readGLIFileV4] error opening stream from " + fname);
533 INFO(
"GeoLib::readGLIFile(): \t done.");
536 while (tag.find(
"#POINTS") == std::string::npos && !in.eof())
538 std::getline(in, tag);
542 std::map<std::string, std::size_t> pnt_id_names_map;
544 bool zero_based_idx(
true);
545 std::vector<GeoLib::Point*> pnt_vec;
546 INFO(
"GeoLib::readGLIFile(): read points from stream.");
547 tag =
readPoints(in, &pnt_vec, zero_based_idx, &pnt_id_names_map);
548 INFO(
"GeoLib::readGLIFile(): \t ok, {:d} points read.", pnt_vec.size());
551 if (!pnt_vec.empty())
554 std::move(pnt_id_names_map), 1e-6);
562 std::vector<GeoLib::Polyline*> ply_vec;
566 const_cast<std::vector<GeoLib::Point*>&
>(point_vec.
getVector()));
567 if (tag.find(
"#POLYLINE") != std::string::npos && in)
569 INFO(
"GeoLib::readGLIFile(): read polylines from stream.");
570 tag =
readPolylines(in, ply_vec, ply_names, geo_pnt_vec, zero_based_idx,
573 INFO(
"GeoLib::readGLIFile(): \t ok, {:d} polylines read.",
578 INFO(
"GeoLib::readGLIFile(): tag #POLYLINE not found.");
581 if (!ply_vec.empty())
584 std::move(ply_names));
589 std::map<std::string, std::size_t> ply_names_copy;
592 ply_names_copy = std::map<std::string, std::size_t>{
597 std::vector<GeoLib::Surface*> sfc_vec;
599 if (tag.find(
"#SURFACE") != std::string::npos && in)
601 INFO(
"GeoLib::readGLIFile(): read surfaces from stream.");
604 ply_names_copy, point_vec, path, errors, geo, unique_name,
606 INFO(
"GeoLib::readGLIFile(): \tok, {:d} surfaces read.",
611 INFO(
"GeoLib::readGLIFile(): tag #SURFACE not found.");
615 if (!sfc_vec.empty())
618 std::move(sfc_names));
621 return errors.empty();
626 std::size_t sfc_count, std::string
const& path)
629 for (
auto const* sfc : sfcs)
633 std::string sfc_name;
638 <<
"\t\t" << sfc_name <<
"\n";
644 <<
"\t\t" << sfc_count <<
"\n";
645 sfc_name = std::to_string(sfc_count);
650 os <<
"\t\t" << sfc_name <<
"\n";
660 const std::string& geo_name,
663 std::ofstream os(fname.c_str());
667 auto const& pnts(pnt_vec->getVector());
668 const std::size_t n_pnts(pnts.size());
669 INFO(
"GeoLib::writeGLIFileV4(): writing {:d} points to file {:s}.",
673 os.precision(std::numeric_limits<double>::max_digits10);
674 for (std::size_t k(0); k < n_pnts; k++)
676 os << k <<
" " << *(pnts[k]);
677 std::string
const& pnt_name(pnt_vec->getItemNameByID(k));
678 if (!pnt_name.empty())
680 os <<
" $NAME " << pnt_name;
689 auto const& plys(plys_vec->getVector());
690 INFO(
"GeoLib::writeGLIFileV4(): {:d} polylines to file {:s}.",
692 for (
auto ply : plys)
696 std::string polyline_name;
697 plys_vec->getNameOfElement(ply, polyline_name);
700 <<
" " << polyline_name <<
"\n";
703 for (std::size_t j(0); j < ply->getNumberOfPoints(); j++)
705 os <<
" " << ply->getPointID(j) <<
"\n";
730 std::ofstream os(fname.c_str());
732 std::size_t pnts_offset(0);
733 std::vector<std::size_t> pnts_id_offset;
734 pnts_id_offset.push_back(0);
739 for (
auto const& geo_name : geo_names)
741 os.precision(std::numeric_limits<double>::max_digits10);
746 const std::size_t n_pnts(pnts.size());
747 for (std::size_t k(0); k < n_pnts; k++)
749 os << pnts_offset + k <<
" " << *(pnts[k]);
751 if (!pnt_name.empty())
753 os <<
"$NAME " << pnt_name;
757 pnts_offset += pnts.size();
758 pnts_id_offset.push_back(pnts_offset);
762 INFO(
"GeoLib::writeAllDataToGLIFileV4(): wrote {:d} points.", pnts_offset);
765 std::vector<std::string> stn_names;
767 for (
auto& stn_name : stn_names)
769 os.precision(std::numeric_limits<double>::max_digits10);
770 const std::vector<GeoLib::Point*>* pnts(geo.
getStationVec(stn_name));
773 for (std::size_t k(0); k < pnts->size(); k++)
775 os << k + pnts_offset <<
" " << *((*pnts)[k]) <<
" $NAME "
779 pnts_offset += pnts->size();
780 pnts_id_offset.push_back(pnts_offset);
784 std::size_t plys_cnt(0);
787 for (std::size_t j(0); j < geo_names.size(); j++)
794 for (
auto ply : plys)
798 std::string ply_name;
802 os <<
" " << ply_name <<
"\n";
806 os <<
" " << geo_names[j] <<
"-" << plys_cnt <<
"\n";
810 for (std::size_t l(0); l < ply->getNumberOfPoints(); l++)
812 os <<
" " << pnts_id_offset[j] + ply->getPointID(l)
821 std::size_t sfcs_cnt(0);
822 for (
auto const& geo_name : geo_names)
Definition of analytical geometry functions.
Definition of the GEOObjects class.
Definition of the Point class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the OGSIOVer4 class.
Definition of the PointVec class.
Definition of the Polygon class.
Definition of the PolyLine class.
Definition of the Station class.
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.
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
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)