48 std::string
readPoints(std::istream& in, std::vector<GeoLib::Point*>* pnt_vec,
49 bool& zero_based_indexing,
50 std::map<std::string, std::size_t>* pnt_id_name_map)
55 std::getline(in, line);
58 while (line.find(
'#') == std::string::npos && !in.eof() && !in.fail())
61 std::stringstream inss(line);
66 inss >>
id >> x >> y >> z;
71 zero_based_indexing =
id == 0;
76 if (line.find(
"$MD") != std::string::npos)
79 std::size_t pos1(line.find_first_of(
'M'));
80 inss.str(line.substr(pos1 + 2, std::string::npos));
85 std::size_t pos(line.find(
"$NAME"));
86 if (pos != std::string::npos)
88 std::size_t end_pos((line.substr(pos + 6)).find(
' '));
89 if (end_pos != std::string::npos)
91 (*pnt_id_name_map)[line.substr(pos + 6, end_pos)] = id;
95 (*pnt_id_name_map)[line.substr(pos + 6)] = id;
99 std::size_t id_pos(line.find(
"$ID"));
100 if (id_pos != std::string::npos)
103 "readPoints(): found tag $ID - please use tag $NAME for "
104 "reading point names in point {:d}.",
109 std::getline(in, line);
117 std::vector<GeoLib::Point*>& pnt_vec,
119 const std::string& path,
120 std::vector<std::string>& errors)
126 WARN(
"readPolylinePointVector(): error opening stream from {:s}",
129 "[readPolylinePointVector] error opening stream from " + fname);
139 std::size_t pnt_id(pnt_vec.size());
158 std::vector<GeoLib::Polyline*>* ply_vec,
159 std::map<std::string, std::size_t>& ply_vec_names,
160 std::vector<GeoLib::Point*>& pnt_vec,
161 bool zero_based_indexing,
162 const std::vector<std::size_t>& pnt_id_map,
163 const std::string& path,
164 std::vector<std::string>& errors)
167 std::string name_of_ply;
169 std::size_t type = 2;
175 if (line.find(
"$ID") != std::string::npos)
180 if (line.find(
"$NAME") != std::string::npos)
186 if (line.find(
"$TYPE") != std::string::npos)
189 type =
static_cast<std::size_t
>(strtol(line.c_str(),
nullptr, 0));
192 if (line.find(
"$EPSILON") != std::string::npos)
197 if (line.find(
"$MAT_GROUP") != std::string::npos)
202 if (line.find(
"$POINTS") != std::string::npos)
207 while (!in.eof() && !in.fail() && !line.empty() &&
208 (line.find(
'#') == std::string::npos) &&
209 (line.find(
'$') == std::string::npos))
211 auto pnt_id(BaseLib::str2number<std::size_t>(line));
212 if (!zero_based_indexing)
216 std::size_t ply_size(ply->getNumberOfPoints());
219 if (ply->getPointID(ply_size - 1) != pnt_id_map[pnt_id])
221 ply->addPoint(pnt_id_map[pnt_id]);
226 ply->addPoint(pnt_id_map[pnt_id]);
234 "readPolyline(): polyline is an arc *** reading not "
237 "[readPolyline] reading polyline as an arc is not "
243 if (line.find(
"$POINT_VECTOR") !=
250 }
while (line.find(
'#') == std::string::npos && !line.empty() && in);
254 ply_vec_names.insert(
255 std::pair<std::string, std::size_t>(name_of_ply, ply_vec->size()));
256 ply_vec->push_back(ply);
274 std::vector<GeoLib::Polyline*>* ply_vec,
275 std::map<std::string, std::size_t>& ply_vec_names,
276 std::vector<GeoLib::Point*>& pnt_vec,
277 bool zero_based_indexing,
278 const std::vector<std::size_t>& pnt_id_map,
279 const std::string& path,
280 std::vector<std::string>& errors)
284 WARN(
"readPolylines(): input stream error.");
285 return std::string(
"");
287 std::string tag(
"#POLYLINE");
289 while (!in.eof() && !in.fail() &&
290 tag.find(
"#POLYLINE") != std::string::npos)
293 zero_based_indexing, pnt_id_map, path, errors);
310 std::vector<GeoLib::Polygon*>& polygon_vec,
311 std::vector<GeoLib::Surface*>& sfc_vec,
312 std::map<std::string, std::size_t>& sfc_names,
313 const std::vector<GeoLib::Polyline*>& ply_vec,
314 const std::map<std::string, std::size_t>& ply_vec_names,
316 std::vector<std::string>& errors)
323 std::size_t ply_id(std::numeric_limits<std::size_t>::max());
328 if (line.find(
"$ID") != std::string::npos)
333 if (line.find(
"$NAME") != std::string::npos)
339 if (line.find(
"$TYPE") != std::string::npos)
342 type = strtol(line.c_str(),
nullptr, 0);
345 if (line.find(
"$EPSILON") != std::string::npos)
350 if (line.find(
"$TIN") != std::string::npos)
358 if (line.find(
"$MAT_GROUP") != std::string::npos)
363 if (line.find(
"$POLYLINES") != std::string::npos)
366 while (!in.eof() && !in.fail() && !line.empty() &&
367 (line.find(
'#') == std::string::npos) &&
368 (line.find(
'$') == std::string::npos))
372 auto it(ply_vec_names.find(line));
373 if (it != ply_vec_names.end())
379 ply_id = ply_vec.size();
382 if (ply_id == ply_vec.size())
384 WARN(
"readSurface(): polyline for surface not found!");
386 "[readSurface] polyline for surface not found!");
393 "readSurface(): surface type 3: flat surface with "
394 "any normal direction - reading not implemented.");
396 "[readSurface] surface type 3: flat surface with "
397 "any normal direction - reading not implemented");
402 "readSurface(): vertical surface (type 2) - "
403 "reading not implemented");
405 "[readSurface] vertical surface (type 2) - reading "
413 }
while (line.find(
'#') == std::string::npos && !line.empty() && in);
418 std::pair<std::string, std::size_t>(
name, sfc_vec.size()));
424 sfc_vec.push_back(sfc);
429 if (ply_id != std::numeric_limits<std::size_t>::max() &&
430 ply_id != ply_vec.size())
432 if (ply_vec[ply_id]->isClosed())
434 polygon_vec.push_back(
440 "readSurface(): cannot create surface {:s} from polyline "
441 "{:d} since polyline is not closed.",
459 std::istream& in, std::vector<GeoLib::Surface*>& sfc_vec,
460 std::map<std::string, std::size_t>& sfc_names,
461 const std::vector<GeoLib::Polyline*>& ply_vec,
462 const std::map<std::string, std::size_t>& ply_vec_names,
465 std::string
const& unique_name, std::string
const& gmsh_path)
469 WARN(
"readSurfaces(): input stream error.");
470 return std::string(
"");
472 std::string tag(
"#SURFACE");
474 std::vector<GeoLib::Polygon*> polygon_vec;
476 while (!in.eof() && !in.fail() && tag.find(
"#SURFACE") != std::string::npos)
478 std::size_t n_polygons(polygon_vec.size());
479 tag =
readSurface(in, polygon_vec, sfc_vec, sfc_names, ply_vec,
480 ply_vec_names, pnt_vec, path, errors);
481 if (n_polygons < polygon_vec.size())
483 INFO(
"Creating a surface by triangulation of the polyline ...");
486 unique_name, gmsh_path))
493 "\t Creating a surface by triangulation of the polyline "
498 for (
auto& k : polygon_vec)
508 std::string& unique_name,
509 std::vector<std::string>& errors,
510 std::string
const& gmsh_path)
512 INFO(
"GeoLib::readGLIFile(): open stream from file {:s}.", fname);
513 std::ifstream in(fname.c_str());
516 WARN(
"GeoLib::readGLIFile(): could not open file {:s}.", fname);
517 errors.push_back(
"[readGLIFileV4] error opening stream from " + fname);
520 INFO(
"GeoLib::readGLIFile(): \t done.");
523 while (tag.find(
"#POINTS") == std::string::npos && !in.eof())
525 std::getline(in, tag);
529 auto pnt_id_names_map = std::unique_ptr<std::map<std::string, std::size_t>>{
530 new std::map<std::string, std::size_t>};
532 bool zero_based_idx(
true);
533 auto pnt_vec = std::make_unique<std::vector<GeoLib::Point*>>();
534 INFO(
"GeoLib::readGLIFile(): read points from stream.");
535 tag =
readPoints(in, pnt_vec.get(), zero_based_idx, pnt_id_names_map.get());
536 INFO(
"GeoLib::readGLIFile(): \t ok, {:d} points read.", pnt_vec->size());
539 if (!pnt_vec->empty())
542 std::move(pnt_id_names_map), 1e-6);
549 auto ply_names = std::make_unique<std::map<std::string, std::size_t>>();
550 auto ply_vec = std::make_unique<std::vector<GeoLib::Polyline*>>();
554 const_cast<std::vector<GeoLib::Point*>*
>(point_vec.getVector()));
555 if (tag.find(
"#POLYLINE") != std::string::npos && in)
557 INFO(
"GeoLib::readGLIFile(): read polylines from stream.");
559 in, ply_vec.get(), *ply_names, *geo_pnt_vec, zero_based_idx,
561 INFO(
"GeoLib::readGLIFile(): \t ok, {:d} polylines read.",
566 INFO(
"GeoLib::readGLIFile(): tag #POLYLINE not found.");
569 if (!ply_vec->empty())
572 std::move(ply_names));
577 std::map<std::string, std::size_t> ply_names_copy;
580 ply_names_copy = std::map<std::string, std::size_t>{
585 auto sfc_vec = std::make_unique<std::vector<GeoLib::Surface*>>();
586 auto sfc_names = std::make_unique<std::map<std::string, std::size_t>>();
587 if (tag.find(
"#SURFACE") != std::string::npos && in)
589 INFO(
"GeoLib::readGLIFile(): read surfaces from stream.");
592 ply_names_copy, point_vec, path, errors, geo, unique_name,
594 INFO(
"GeoLib::readGLIFile(): \tok, {:d} surfaces read.",
599 INFO(
"GeoLib::readGLIFile(): tag #SURFACE not found.");
603 if (!sfc_vec->empty())
606 std::move(sfc_vec), unique_name,
607 std::move(sfc_names));
610 return errors.empty();
615 std::size_t sfc_count, std::string
const& path)
617 const std::vector<GeoLib::Surface*>* sfcs(sfcs_vec->
getVector());
618 for (
auto 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,
653 std::vector<GeoLib::Point*>
const*
const pnts(pnt_vec->
getVector());
654 std::ofstream os(fname.c_str());
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>::digits10);
663 for (std::size_t k(0); k < n_pnts; k++)
665 os << k <<
" " << *((*pnts)[k]);
667 if (!pnt_name.empty())
669 os <<
" $NAME " << pnt_name;
678 const std::vector<GeoLib::Polyline*>* plys(plys_vec->
getVector());
679 INFO(
"GeoLib::writeGLIFileV4(): {:d} polylines to file {:s}.",
680 plys->size(), fname);
681 for (
auto ply : *plys)
685 std::string 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& geo_name : geo_names)
730 os.precision(std::numeric_limits<double>::digits10);
732 std::vector<GeoLib::Point*>
const*
const pnts(pnt_vec->
getVector());
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>::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++)
782 const std::vector<GeoLib::Polyline*>* plys(plys_vec->
getVector());
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& geo_name : geo_names)
Definition of analytical geometry functions.
Definition of the GEOObjects class.
Definition of the Point class.
void INFO(char const *fmt, Args const &... args)
void WARN(char const *fmt, Args const &... 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 addSurfaceVec(std::unique_ptr< std::vector< Surface * >> sfc, const std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> sfc_names=nullptr)
const PointVec * getPointVecObj(const std::string &name) const
void addPointVec(std::unique_ptr< std::vector< Point * >> points, std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> pnt_id_name_map=nullptr, double eps=std::sqrt(std::numeric_limits< double >::epsilon()))
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
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
void addPolylineVec(std::unique_ptr< std::vector< Polyline * >> lines, const std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> ply_names=nullptr)
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 deletin...
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...
const std::vector< T * > * getVector() const
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
bool getNameOfElement(const T *data, std::string &name) 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)
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 * > &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 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 * > &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)
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)
std::size_t writeTINSurfaces(std::ofstream &os, GeoLib::SurfaceVec const *sfcs_vec, std::size_t sfc_count, std::string const &path)
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 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)
std::string readPolyline(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)
void writeAllDataToGLIFileV4(const std::string &fname, const GeoLib::GEOObjects &geo)
bool createSurface(GeoLib::Polyline const &ply, GeoLib::GEOObjects &geometries, std::string const &geometry_name, std::string const &gmsh_binary)