OGS
FileIO::Legacy Namespace Reference

Functions

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 readPolylinePointVector (const std::string &fname, std::vector< GeoLib::Point * > &pnt_vec, GeoLib::Polyline *ply, const std::string &path, std::vector< std::string > &errors)
 
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)
 
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)
 
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)
 
bool readGLIFileV4 (const std::string &fname, GeoLib::GEOObjects &geo, std::string &unique_name, std::vector< std::string > &errors, std::string const &gmsh_path)
 
std::size_t writeTINSurfaces (std::ofstream &os, GeoLib::SurfaceVec const *sfcs_vec, std::size_t sfc_count, std::string const &path)
 
void writeGLIFileV4 (const std::string &fname, const std::string &geo_name, const GeoLib::GEOObjects &geo)
 
void writeAllDataToGLIFileV4 (const std::string &fname, const GeoLib::GEOObjects &geo)
 

Function Documentation

◆ readGLIFileV4()

bool FileIO::Legacy::readGLIFileV4 ( const std::string & fname,
GeoLib::GEOObjects & geo,
std::string & unique_name,
std::vector< std::string > & errors,
std::string const & gmsh_path )

Interface for handling geometry from OGS-5 and below (*.gli files) Reads geometric objects from file in gli format

Definition at line 519 of file OGSIOVer4.cpp.

524{
525 INFO("GeoLib::readGLIFile(): open stream from file {:s}.", fname);
526 std::ifstream in(fname.c_str());
527 if (!in)
528 {
529 WARN("GeoLib::readGLIFile(): could not open file {:s}.", fname);
530 errors.push_back("[readGLIFileV4] error opening stream from " + fname);
531 return false;
532 }
533 INFO("GeoLib::readGLIFile(): \t done.");
534
535 std::string tag;
536 while (tag.find("#POINTS") == std::string::npos && !in.eof())
537 {
538 std::getline(in, tag);
539 }
540
541 // read names of points into vector of strings
542 std::map<std::string, std::size_t> pnt_id_names_map;
543
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());
549
550 unique_name = BaseLib::extractBaseName(fname);
551 if (!pnt_vec.empty())
552 {
553 geo.addPointVec(std::move(pnt_vec), unique_name,
554 std::move(pnt_id_names_map), 1e-6);
555 }
556
557 // extract path for reading external files
558 const std::string path = BaseLib::extractPath(fname);
559
560 // read names of plys into temporary string-vec
562 std::vector<GeoLib::Polyline*> ply_vec;
563 GeoLib::PointVec& point_vec(
564 *const_cast<GeoLib::PointVec*>(geo.getPointVecObj(unique_name)));
565 auto geo_pnt_vec(
566 const_cast<std::vector<GeoLib::Point*>&>(point_vec.getVector()));
567 if (tag.find("#POLYLINE") != std::string::npos && in)
568 {
569 INFO("GeoLib::readGLIFile(): read polylines from stream.");
570 tag = readPolylines(in, ply_vec, ply_names, geo_pnt_vec, zero_based_idx,
571 geo.getPointVecObj(unique_name)->getIDMap(), path,
572 errors);
573 INFO("GeoLib::readGLIFile(): \t ok, {:d} polylines read.",
574 ply_vec.size());
575 }
576 else
577 {
578 INFO("GeoLib::readGLIFile(): tag #POLYLINE not found.");
579 }
580
581 if (!ply_vec.empty())
582 {
583 geo.addPolylineVec(std::move(ply_vec), unique_name,
584 std::move(ply_names));
585 }
586
587 // Since ply_names is a unique_ptr and is given to the GEOObject instance
588 // geo it is not usable anymore. For this reason a copy is necessary.
589 std::map<std::string, std::size_t> ply_names_copy;
590 if (geo.getPolylineVecObj(unique_name))
591 {
592 ply_names_copy = std::map<std::string, std::size_t>{
593 geo.getPolylineVecObj(unique_name)->getNameIDMapBegin(),
594 geo.getPolylineVecObj(unique_name)->getNameIDMapEnd()};
595 }
596
597 std::vector<GeoLib::Surface*> sfc_vec;
599 if (tag.find("#SURFACE") != std::string::npos && in)
600 {
601 INFO("GeoLib::readGLIFile(): read surfaces from stream.");
602
603 readSurfaces(in, sfc_vec, sfc_names, geo.getPolylineVec(unique_name),
604 ply_names_copy, point_vec, path, errors, geo, unique_name,
605 gmsh_path);
606 INFO("GeoLib::readGLIFile(): \tok, {:d} surfaces read.",
607 sfc_vec.size());
608 }
609 else
610 {
611 INFO("GeoLib::readGLIFile(): tag #SURFACE not found.");
612 }
613 in.close();
614
615 if (!sfc_vec.empty())
616 {
617 geo.addSurfaceVec(std::move(sfc_vec), unique_name,
618 std::move(sfc_names));
619 }
620
621 return errors.empty();
622}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
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
void addSurfaceVec(std::vector< Surface * > &&sfc, const std::string &name, SurfaceVec::NameIdMap &&sfc_names)
const PolylineVec * getPolylineVecObj(const std::string &name) const
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
This class manages pointers to Points in a std::vector along with a name. It also handles the deletio...
Definition PointVec.h:36
const std::vector< std::size_t > & getIDMap() const
Definition PointVec.h:97
std::map< std::string, std::size_t > NameIdMap
Definition TemplateVec.h:41
NameIdMap::const_iterator getNameIDMapBegin() const
Returns the begin of the name id mapping structure.
Definition TemplateVec.h:85
NameIdMap::const_iterator getNameIDMapEnd() const
Returns the end of the name id mapping structure.
Definition TemplateVec.h:91
std::string extractPath(std::string const &pathname)
std::string extractBaseName(std::string const &pathname)
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::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)

References GeoLib::GEOObjects::addPointVec(), GeoLib::GEOObjects::addPolylineVec(), GeoLib::GEOObjects::addSurfaceVec(), BaseLib::extractBaseName(), BaseLib::extractPath(), GeoLib::PointVec::getIDMap(), GeoLib::TemplateVec< T >::getNameIDMapBegin(), GeoLib::TemplateVec< T >::getNameIDMapEnd(), GeoLib::GEOObjects::getPointVecObj(), GeoLib::GEOObjects::getPolylineVec(), GeoLib::GEOObjects::getPolylineVecObj(), GeoLib::TemplateVec< T >::getVector(), INFO(), readPoints(), readPolylines(), readSurfaces(), and WARN().

Referenced by OGSFileConverter::convertGLI2GML(), MainWindow::loadFile(), and FileIO::readGeometryFromFile().

◆ readPoints()

std::string FileIO::Legacy::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 )

reads the points inclusive their names from input stream in using the OGS-4 file format

Definition at line 49 of file OGSIOVer4.cpp.

52{
53 std::string line;
54 std::size_t cnt(0);
55
56 std::getline(in, line);
57 // geometric key words start with the hash #
58 // while not found a new key word do ...
59 while (line.find('#') == std::string::npos && !in.eof() && !in.fail())
60 {
61 // read id and point coordinates
62 std::stringstream inss(line);
63 std::size_t id;
64 double x;
65 double y;
66 double z;
67 inss >> id >> x >> y >> z;
68 if (!inss.fail())
69 {
70 if (cnt == 0)
71 {
72 zero_based_indexing = id == 0;
73 }
74 pnt_vec->push_back(new GeoLib::Point(x, y, z, id));
75
76 // read mesh density
77 if (line.find("$MD") != std::string::npos)
78 {
79 double mesh_density;
80 std::size_t pos1(line.find_first_of('M'));
81 inss.str(line.substr(pos1 + 2, std::string::npos));
82 inss >> mesh_density;
83 }
84
85 // read name of point
86 std::size_t pos(line.find("$NAME"));
87 if (pos != std::string::npos) // OK
88 {
89 std::size_t end_pos((line.substr(pos + 6)).find(' '));
90 if (end_pos != std::string::npos)
91 {
92 (*pnt_id_name_map)[line.substr(pos + 6, end_pos)] = id;
93 }
94 else
95 {
96 (*pnt_id_name_map)[line.substr(pos + 6)] = id;
97 }
98 }
99
100 std::size_t id_pos(line.find("$ID"));
101 if (id_pos != std::string::npos)
102 {
103 WARN(
104 "readPoints(): found tag $ID - please use tag $NAME for "
105 "reading point names in point {:d}.",
106 cnt);
107 }
108 cnt++;
109 }
110 std::getline(in, line);
111 }
112
113 return line;
114}

References WARN().

Referenced by readGLIFileV4().

◆ readPolyline()

std::string FileIO::Legacy::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 )

read a single Polyline from stream in into the ply_vec-vector

Definition at line 158 of file OGSIOVer4.cpp.

166{
167 std::string line;
168 std::string name_of_ply;
169 auto* ply(new GeoLib::Polyline(pnt_vec));
170 std::size_t type = 2; // need an initial value
171
172 // Loop over all phases or components
173 do
174 {
175 in >> line;
176 if (line.find("$ID") != std::string::npos)
177 { // subkeyword found CC
178 in >> line; // read value
179 }
180 //....................................................................
181 if (line.find("$NAME") != std::string::npos) // subkeyword found
182 {
183 in >> line;
184 name_of_ply = line; // read value
185 }
186 //....................................................................
187 if (line.find("$TYPE") != std::string::npos) // subkeyword found
188 {
189 in >> line; // read value
190 type = static_cast<std::size_t>(strtol(line.c_str(), nullptr, 0));
191 }
192 //....................................................................
193 if (line.find("$EPSILON") != std::string::npos)
194 { // subkeyword found
195 in >> line; // read value
196 }
197 //....................................................................
198 if (line.find("$MAT_GROUP") != std::string::npos)
199 { // subkeyword found
200 in >> line; // read value
201 }
202 //....................................................................
203 if (line.find("$POINTS") != std::string::npos) // subkeyword found
204 { // read the point ids
205 in >> line;
206 if (type != 100)
207 {
208 while (!in.eof() && !in.fail() && !line.empty() &&
209 (line.find('#') == std::string::npos) &&
210 (line.find('$') == std::string::npos))
211 {
212 auto pnt_id(BaseLib::str2number<std::size_t>(line));
213 if (!zero_based_indexing)
214 {
215 pnt_id--; // one based indexing
216 }
217 std::size_t ply_size(ply->getNumberOfPoints());
218 if (ply_size > 0)
219 {
220 if (ply->getPointID(ply_size - 1) != pnt_id_map[pnt_id])
221 {
222 ply->addPoint(pnt_id_map[pnt_id]);
223 }
224 }
225 else
226 {
227 ply->addPoint(pnt_id_map[pnt_id]);
228 }
229 in >> line;
230 }
231 }
232 else
233 {
234 WARN(
235 "readPolyline(): polyline is an arc *** reading not "
236 "implemented");
237 errors.emplace_back(
238 "[readPolyline] reading polyline as an arc is not "
239 "implemented");
240 }
241 // empty line or the keyword or subkeyword or end of file
242 }
243 //....................................................................
244 if (line.find("$POINT_VECTOR") !=
245 std::string::npos) // subkeyword found
246 {
247 in >> line; // read file name
248 line = BaseLib::joinPaths(path, line);
249 readPolylinePointVector(line, pnt_vec, ply, path, errors);
250 } // subkeyword found
251 } while (line.find('#') == std::string::npos && !line.empty() && in);
252
253 if (type != 100)
254 {
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);
258 }
259
260 return line;
261}
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition Polyline.h:40
std::string joinPaths(std::string const &pathA, std::string const &pathB)
T str2number(const std::string &str)
Definition StringTools.h:60
void readPolylinePointVector(const std::string &fname, std::vector< GeoLib::Point * > &pnt_vec, GeoLib::Polyline *ply, const std::string &path, std::vector< std::string > &errors)

References BaseLib::joinPaths(), readPolylinePointVector(), BaseLib::str2number(), and WARN().

Referenced by readPolylines().

◆ readPolylinePointVector()

void FileIO::Legacy::readPolylinePointVector ( const std::string & fname,
std::vector< GeoLib::Point * > & pnt_vec,
GeoLib::Polyline * ply,
const std::string & path,
std::vector< std::string > & errors )

reads points from a vector

Definition at line 117 of file OGSIOVer4.cpp.

122{
123 // open file
124 std::ifstream in(BaseLib::joinPaths(path, fname).c_str());
125 if (!in)
126 {
127 WARN("readPolylinePointVector(): error opening stream from {:s}",
128 fname);
129 errors.push_back(
130 "[readPolylinePointVector] error opening stream from " + fname);
131 return;
132 }
133
134 double x;
135 double y;
136 double z;
137 while (in)
138 {
139 in >> x >> y >> z;
140 std::size_t pnt_id(pnt_vec.size());
141 pnt_vec.push_back(new GeoLib::Point(x, y, z));
142 ply->addPoint(pnt_id);
143 }
144}
virtual bool addPoint(std::size_t pnt_id)
Definition Polyline.cpp:35

References GeoLib::Polyline::addPoint(), BaseLib::joinPaths(), and WARN().

Referenced by readPolyline().

◆ readPolylines()

std::string FileIO::Legacy::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 )

reads polylines

Definition at line 274 of file OGSIOVer4.cpp.

282{
283 if (!in)
284 {
285 WARN("readPolylines(): input stream error.");
286 return std::string("");
287 }
288 std::string tag("#POLYLINE");
289
290 while (!in.eof() && !in.fail() &&
291 tag.find("#POLYLINE") != std::string::npos)
292 {
293 tag = readPolyline(in, ply_vec, ply_vec_names, pnt_vec,
294 zero_based_indexing, pnt_id_map, path, errors);
295 }
296
297 return tag;
298}

References readPolyline(), and WARN().

Referenced by readGLIFileV4().

◆ readSurface()

std::string FileIO::Legacy::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 )

read a single Surface

Definition at line 310 of file OGSIOVer4.cpp.

318{
319 std::string line;
320 GeoLib::Surface* sfc(nullptr);
321
322 int type(-1);
323 std::string name;
324 std::size_t ply_id(std::numeric_limits<std::size_t>::max());
325
326 do
327 {
328 in >> line;
329 if (line.find("$ID") != std::string::npos)
330 { // subkeyword found CC
331 in >> line; // read value
332 }
333 //....................................................................
334 if (line.find("$NAME") != std::string::npos) // subkeyword found
335 {
336 in >> line; // read value
337 name = line;
338 }
339 //....................................................................
340 if (line.find("$TYPE") != std::string::npos) // subkeyword found
341 {
342 in >> line; // read value
343 type = strtol(line.c_str(), nullptr, 0);
344 }
345 //....................................................................
346 if (line.find("$EPSILON") != std::string::npos)
347 { // subkeyword found
348 in >> line; // read value
349 }
350 //....................................................................
351 if (line.find("$TIN") != std::string::npos) // subkeyword found
352 {
353 in >> line; // read value (file name)
354 std::string const file_name = BaseLib::joinPaths(path, line);
355 sfc =
356 GeoLib::IO::TINInterface::readTIN(file_name, pnt_vec, &errors);
357 }
358 //....................................................................
359 if (line.find("$MAT_GROUP") != std::string::npos)
360 { // subkeyword found
361 in >> line; // read value
362 }
363 //....................................................................
364 if (line.find("$POLYLINES") != std::string::npos) // subkeyword found
365 { // read the name of the polyline(s)
366 in >> line;
367 while (!in.eof() && !in.fail() && !line.empty() &&
368 (line.find('#') == std::string::npos) &&
369 (line.find('$') == std::string::npos))
370 {
371 if (ply_vec == nullptr)
372 {
373 OGS_FATAL("The polyline vector is not allocated.");
374 }
375
376 // we did read the name of a polyline -> search the id for
377 // polyline
378 auto it(ply_vec_names.find(line));
379 if (it != ply_vec_names.end())
380 {
381 ply_id = it->second;
382 }
383 else
384 {
385 ply_id = ply_vec->size();
386 }
387
388 if (ply_id == ply_vec->size())
389 {
390 WARN("readSurface(): polyline for surface not found!");
391 errors.emplace_back(
392 "[readSurface] polyline for surface not found!");
393 }
394 else
395 {
396 if (type == 3)
397 {
398 WARN(
399 "readSurface(): surface type 3: flat surface with "
400 "any normal direction - reading not implemented.");
401 errors.emplace_back(
402 "[readSurface] surface type 3: flat surface with "
403 "any normal direction - reading not implemented");
404 }
405 if (type == 2)
406 {
407 WARN(
408 "readSurface(): vertical surface (type 2) - "
409 "reading not implemented");
410 errors.emplace_back(
411 "[readSurface] vertical surface (type 2) - reading "
412 "not implemented");
413 }
414 }
415 in >> line;
416 }
417 // empty line or a keyword is found
418 }
419 } while (line.find('#') == std::string::npos && !line.empty() && in);
420
421 if (!name.empty())
422 {
423 sfc_names.insert(
424 std::pair<std::string, std::size_t>(name, sfc_vec.size()));
425 }
426
427 if (sfc)
428 {
429 // surface create by TIN
430 sfc_vec.push_back(sfc);
431 }
432 else
433 {
434 // surface created by polygon
435 if (ply_id != std::numeric_limits<std::size_t>::max())
436 {
437 if (ply_vec == nullptr)
438 {
439 OGS_FATAL("The polyline vector is not allocated.");
440 }
441
442 if (ply_id != ply_vec->size())
443 {
444 if ((*ply_vec)[ply_id]->isClosed())
445 {
446 polygon_vec.push_back(
447 new GeoLib::Polygon(*((*ply_vec)[ply_id]), true));
448 }
449 else
450 {
451 WARN(
452 "readSurface(): cannot create surface {:s} from "
453 "polyline {:d} since polyline is not closed.",
454 name, ply_id);
455 }
456 }
457 }
458 }
459
460 return line;
461}
#define OGS_FATAL(...)
Definition Error.h:26
static GeoLib::Surface * readTIN(std::string const &fname, GeoLib::PointVec &pnt_vec, std::vector< std::string > *errors=nullptr)
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
Definition Surface.h:33

References BaseLib::joinPaths(), OGS_FATAL, GeoLib::IO::TINInterface::readTIN(), and WARN().

Referenced by readSurfaces().

◆ readSurfaces()

std::string FileIO::Legacy::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 )

Definition at line 471 of file OGSIOVer4.cpp.

479{
480 if (!in.good())
481 {
482 WARN("readSurfaces(): input stream error.");
483 return std::string("");
484 }
485 std::string tag("#SURFACE");
486
487 std::vector<GeoLib::Polygon*> polygon_vec;
488
489 while (!in.eof() && !in.fail() && tag.find("#SURFACE") != std::string::npos)
490 {
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())
495 {
496 INFO("Creating a surface by triangulation of the polyline ...");
498 *(dynamic_cast<GeoLib::Polyline*>(polygon_vec.back())), geo,
499 unique_name, gmsh_path))
500 {
501 INFO("\t done");
502 }
503 else
504 {
505 WARN(
506 "\t Creating a surface by triangulation of the polyline "
507 "failed.");
508 }
509 }
510 }
511 for (auto& k : polygon_vec)
512 {
513 delete k;
514 }
515
516 return tag;
517}
bool createSurface(GeoLib::Polyline const &ply, GeoLib::GEOObjects &geometries, std::string const &geometry_name, std::string const &gmsh_binary)

References FileIO::createSurface(), INFO(), readSurface(), and WARN().

Referenced by readGLIFileV4().

◆ writeAllDataToGLIFileV4()

void FileIO::Legacy::writeAllDataToGLIFileV4 ( const std::string & fname,
const GeoLib::GEOObjects & geo )

Writes all geometric information to a gli-file

Definition at line 722 of file OGSIOVer4.cpp.

724{
725 auto const geo_names = geo.getGeometryNames();
726
727 // extract path for reading external files
728 const std::string path = BaseLib::extractPath(fname);
729
730 std::ofstream os(fname.c_str());
731
732 std::size_t pnts_offset(0);
733 std::vector<std::size_t> pnts_id_offset;
734 pnts_id_offset.push_back(0);
735
736 // writing all points
737 os << "#POINTS"
738 << "\n";
739 for (auto const& geo_name : geo_names)
740 {
741 os.precision(std::numeric_limits<double>::max_digits10);
742 GeoLib::PointVec const* const pnt_vec(geo.getPointVecObj(geo_name));
743 if (pnt_vec)
744 {
745 auto const& pnts(pnt_vec->getVector());
746 const std::size_t n_pnts(pnts.size());
747 for (std::size_t k(0); k < n_pnts; k++)
748 {
749 os << pnts_offset + k << " " << *(pnts[k]);
750 std::string const& pnt_name(pnt_vec->getItemNameByID(k));
751 if (!pnt_name.empty())
752 {
753 os << "$NAME " << pnt_name;
754 }
755 os << "\n";
756 }
757 pnts_offset += pnts.size();
758 pnts_id_offset.push_back(pnts_offset);
759 }
760 }
761
762 INFO("GeoLib::writeAllDataToGLIFileV4(): wrote {:d} points.", pnts_offset);
763
764 // writing all stations
765 std::vector<std::string> stn_names;
766 geo.getStationVectorNames(stn_names);
767 for (auto& stn_name : stn_names)
768 {
769 os.precision(std::numeric_limits<double>::max_digits10);
770 const std::vector<GeoLib::Point*>* pnts(geo.getStationVec(stn_name));
771 if (pnts)
772 {
773 for (std::size_t k(0); k < pnts->size(); k++)
774 {
775 os << k + pnts_offset << " " << *((*pnts)[k]) << " $NAME "
776 << static_cast<GeoLib::Station*>((*pnts)[k])->getName()
777 << "\n";
778 }
779 pnts_offset += pnts->size();
780 pnts_id_offset.push_back(pnts_offset);
781 }
782 }
783
784 std::size_t plys_cnt(0);
785
786 // writing all polylines
787 for (std::size_t j(0); j < geo_names.size(); j++)
788 {
789 const GeoLib::PolylineVec* plys_vec(
790 geo.getPolylineVecObj(geo_names[j]));
791 if (plys_vec)
792 {
793 auto const& plys(plys_vec->getVector());
794 for (auto ply : plys)
795 {
796 os << "#POLYLINE"
797 << "\n";
798 std::string ply_name;
799 os << " $NAME\n";
800 if (plys_vec->getNameOfElementByID(plys_cnt, ply_name))
801 {
802 os << " " << ply_name << "\n";
803 }
804 else
805 {
806 os << " " << geo_names[j] << "-" << plys_cnt << "\n";
807 }
808 os << " $POINTS"
809 << "\n";
810 for (std::size_t l(0); l < ply->getNumberOfPoints(); l++)
811 {
812 os << " " << pnts_id_offset[j] + ply->getPointID(l)
813 << "\n";
814 }
815 plys_cnt++;
816 }
817 }
818 }
819
820 // writing surfaces as TIN files
821 std::size_t sfcs_cnt(0);
822 for (auto const& geo_name : geo_names)
823 {
824 const GeoLib::SurfaceVec* sfcs_vec(geo.getSurfaceVecObj(geo_name));
825 if (sfcs_vec)
826 {
827 sfcs_cnt += writeTINSurfaces(os, sfcs_vec, sfcs_cnt, path);
828 }
829 }
830
831 os << "#STOP"
832 << "\n";
833 os.close();
834}
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
Definition GEOObjects.h:208
void getStationVectorNames(std::vector< std::string > &names) const
Returns the names of all station vectors.
const std::vector< GeoLib::Point * > * getStationVec(const std::string &name) const
Returns the station vector with the given name.
A Station (observation site) is basically a Point with some additional information.
Definition Station.h:37
std::string const & getName() const
Returns the name of the station.
Definition Station.h:60
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
std::size_t writeTINSurfaces(std::ofstream &os, GeoLib::SurfaceVec const *sfcs_vec, std::size_t sfc_count, std::string const &path)

References BaseLib::extractPath(), GeoLib::GEOObjects::getGeometryNames(), GeoLib::PointVec::getItemNameByID(), GeoLib::Station::getName(), GeoLib::TemplateVec< T >::getNameOfElementByID(), GeoLib::GEOObjects::getPointVecObj(), GeoLib::GEOObjects::getPolylineVecObj(), GeoLib::GEOObjects::getStationVec(), GeoLib::GEOObjects::getStationVectorNames(), GeoLib::GEOObjects::getSurfaceVecObj(), GeoLib::TemplateVec< T >::getVector(), INFO(), and writeTINSurfaces().

Referenced by MainWindow::writeGeometryToFile().

◆ writeGLIFileV4()

void FileIO::Legacy::writeGLIFileV4 ( const std::string & fname,
const std::string & geo_name,
const GeoLib::GEOObjects & geo )

Writes geometric objects from a specific geometry to a gli-file

Definition at line 659 of file OGSIOVer4.cpp.

662{
663 std::ofstream os(fname.c_str());
664 if (auto const* const pnt_vec(geo.getPointVecObj(geo_name));
665 pnt_vec != nullptr)
666 {
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}.",
670 n_pnts, fname);
671 os << "#POINTS"
672 << "\n";
673 os.precision(std::numeric_limits<double>::max_digits10);
674 for (std::size_t k(0); k < n_pnts; k++)
675 {
676 os << k << " " << *(pnts[k]);
677 std::string const& pnt_name(pnt_vec->getItemNameByID(k));
678 if (!pnt_name.empty())
679 {
680 os << " $NAME " << pnt_name;
681 }
682 os << "\n";
683 }
684 }
685
686 if (auto const* plys_vec(geo.getPolylineVecObj(geo_name));
687 plys_vec != nullptr)
688 {
689 auto const& plys(plys_vec->getVector());
690 INFO("GeoLib::writeGLIFileV4(): {:d} polylines to file {:s}.",
691 plys.size(), fname);
692 for (auto ply : plys)
693 {
694 os << "#POLYLINE"
695 << "\n";
696 std::string polyline_name;
697 plys_vec->getNameOfElement(ply, polyline_name);
698 os << " $NAME "
699 << "\n"
700 << " " << polyline_name << "\n";
701 os << " $POINTS"
702 << "\n";
703 for (std::size_t j(0); j < ply->getNumberOfPoints(); j++)
704 {
705 os << " " << ply->getPointID(j) << "\n";
706 }
707 }
708 }
709
710 // writing surfaces as TIN files
711 if (const auto* sfcs_vec(geo.getSurfaceVecObj(geo_name));
712 sfcs_vec != nullptr)
713 {
714 writeTINSurfaces(os, sfcs_vec, 0, BaseLib::extractPath(fname));
715 }
716
717 os << "#STOP"
718 << "\n";
719 os.close();
720}

References BaseLib::extractPath(), GeoLib::GEOObjects::getPointVecObj(), GeoLib::GEOObjects::getPolylineVecObj(), GeoLib::GEOObjects::getSurfaceVecObj(), INFO(), and writeTINSurfaces().

Referenced by OGSFileConverter::convertGML2GLI(), and FileIO::writeGeometryToFile().

◆ writeTINSurfaces()

std::size_t FileIO::Legacy::writeTINSurfaces ( std::ofstream & os,
GeoLib::SurfaceVec const * sfcs_vec,
std::size_t sfc_count,
std::string const & path )

Definition at line 624 of file OGSIOVer4.cpp.

627{
628 auto const& sfcs(sfcs_vec->getVector());
629 for (auto const* sfc : sfcs)
630 {
631 os << "#SURFACE"
632 << "\n";
633 std::string sfc_name;
634 if (sfcs_vec->getNameOfElementByID(sfc_count, sfc_name))
635 {
636 os << "\t$NAME "
637 << "\n"
638 << "\t\t" << sfc_name << "\n";
639 }
640 else
641 {
642 os << "\t$NAME "
643 << "\n"
644 << "\t\t" << sfc_count << "\n";
645 sfc_name = std::to_string(sfc_count);
646 }
647 sfc_name += ".tin";
648 os << "\t$TIN"
649 << "\n";
650 os << "\t\t" << sfc_name << "\n";
651 // create tin file
652 sfc_name = BaseLib::joinPaths(path, sfc_name);
654 sfc_count++;
655 }
656 return sfc_count;
657}
static void writeSurfaceAsTIN(GeoLib::Surface const &surface, std::string const &file_name)

References GeoLib::TemplateVec< T >::getNameOfElementByID(), GeoLib::TemplateVec< T >::getVector(), BaseLib::joinPaths(), and GeoLib::IO::TINInterface::writeSurfaceAsTIN().

Referenced by writeAllDataToGLIFileV4(), and writeGLIFileV4().