OGS
OGSIOVer4.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "OGSIOVer4.h"
5
6#include <fstream>
7#include <iomanip>
8#include <limits>
9#include <sstream>
10
12#include "BaseLib/FileTools.h"
13#include "BaseLib/Logging.h"
14#include "BaseLib/StringTools.h"
16#include "GeoLib/GEOObjects.h"
18#include "GeoLib/Point.h"
19#include "GeoLib/PointVec.h"
20#include "GeoLib/Polygon.h"
21#include "GeoLib/Polyline.h"
22#include "GeoLib/Station.h"
23#include "GeoLib/Surface.h"
24#include "GeoLib/Triangle.h"
25
26namespace FileIO
27{
28namespace Legacy
29{
30/**************************************************************************
31 GeoLib- Function: readPoints
32 Aufgabe: Lesen der GLI Points und schreiben in einen Vector
33 08/2005 CC Implementation
34 01/2010 TF big modifications
35**************************************************************************/
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)
41{
42 std::string line;
43 std::size_t cnt(0);
44
45 std::getline(in, line);
46 // geometric key words start with the hash #
47 // while not found a new key word do ...
48 while (line.find('#') == std::string::npos && !in.eof() && !in.fail())
49 {
50 // read id and point coordinates
51 std::stringstream inss(line);
52 std::size_t id;
53 double x;
54 double y;
55 double z;
56 inss >> id >> x >> y >> z;
57 if (!inss.fail())
58 {
59 if (cnt == 0)
60 {
61 zero_based_indexing = id == 0;
62 }
63 pnt_vec->push_back(new GeoLib::Point(x, y, z, id));
64
65 // read mesh density
66 if (line.find("$MD") != std::string::npos)
67 {
68 double mesh_density;
69 std::size_t pos1(line.find_first_of('M'));
70 inss.str(line.substr(pos1 + 2, std::string::npos));
71 inss >> mesh_density;
72 }
73
74 // read name of point
75 std::size_t pos(line.find("$NAME"));
76 if (pos != std::string::npos) // OK
77 {
78 std::size_t end_pos((line.substr(pos + 6)).find(' '));
79 if (end_pos != std::string::npos)
80 {
81 (*pnt_id_name_map)[line.substr(pos + 6, end_pos)] = id;
82 }
83 else
84 {
85 (*pnt_id_name_map)[line.substr(pos + 6)] = id;
86 }
87 }
88
89 std::size_t id_pos(line.find("$ID"));
90 if (id_pos != std::string::npos)
91 {
92 WARN(
93 "readPoints(): found tag $ID - please use tag $NAME for "
94 "reading point names in point {:d}.",
95 cnt);
96 }
97 cnt++;
98 }
99 std::getline(in, line);
100 }
101
102 return line;
103}
104
106void readPolylinePointVector(const std::string& fname,
107 std::vector<GeoLib::Point*>& pnt_vec,
108 GeoLib::Polyline* ply,
109 const std::string& path,
110 std::vector<std::string>& errors)
111{
112 // open file
113 std::ifstream in(BaseLib::joinPaths(path, fname).c_str());
114 if (!in)
115 {
116 WARN("readPolylinePointVector(): error opening stream from {:s}",
117 fname);
118 errors.push_back(
119 "[readPolylinePointVector] error opening stream from " + fname);
120 return;
121 }
122
123 double x;
124 double y;
125 double z;
126 while (in)
127 {
128 in >> x >> y >> z;
129 std::size_t pnt_id(pnt_vec.size());
130 pnt_vec.push_back(new GeoLib::Point(x, y, z));
131 ply->addPoint(pnt_id);
132 }
133}
134
135/**************************************************************************
136 GeoLib-Method: Read
137 Task: Read polyline data from file
138 Programming:
139 03/2004 CC Implementation
140 09/2004 OK file path for PLY files
141 07/2005 CC PLY id
142 08/2005 CC parameter
143 09/2005 CC itoa - convert integer to string
144 01/2010 TF cleaned method from unused variables
145**************************************************************************/
147std::string readPolyline(std::istream& in,
148 std::vector<GeoLib::Polyline*>& ply_vec,
149 GeoLib::PolylineVec::NameIdMap& ply_vec_names,
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)
155{
156 std::string line;
157 std::string name_of_ply;
158 auto* ply(new GeoLib::Polyline(pnt_vec));
159 std::size_t type = 2; // need an initial value
160
161 // Loop over all phases or components
162 do
163 {
164 in >> line;
165 if (line.find("$ID") != std::string::npos)
166 { // subkeyword found CC
167 in >> line; // read value
168 }
169 //....................................................................
170 if (line.find("$NAME") != std::string::npos) // subkeyword found
171 {
172 in >> line;
173 name_of_ply = line; // read value
174 }
175 //....................................................................
176 if (line.find("$TYPE") != std::string::npos) // subkeyword found
177 {
178 in >> line; // read value
179 type = static_cast<std::size_t>(strtol(line.c_str(), nullptr, 0));
180 }
181 //....................................................................
182 if (line.find("$EPSILON") != std::string::npos)
183 { // subkeyword found
184 in >> line; // read value
185 }
186 //....................................................................
187 if (line.find("$MAT_GROUP") != std::string::npos)
188 { // subkeyword found
189 in >> line; // read value
190 }
191 //....................................................................
192 if (line.find("$POINTS") != std::string::npos) // subkeyword found
193 { // read the point ids
194 in >> line;
195 if (type != 100)
196 {
197 while (!in.eof() && !in.fail() && !line.empty() &&
198 (line.find('#') == std::string::npos) &&
199 (line.find('$') == std::string::npos))
200 {
201 auto pnt_id(BaseLib::str2number<std::size_t>(line));
202 if (!zero_based_indexing)
203 {
204 pnt_id--; // one based indexing
205 }
206 std::size_t ply_size(ply->getNumberOfPoints());
207 if (ply_size > 0)
208 {
209 if (ply->getPointID(ply_size - 1) != pnt_id_map[pnt_id])
210 {
211 ply->addPoint(pnt_id_map[pnt_id]);
212 }
213 }
214 else
215 {
216 ply->addPoint(pnt_id_map[pnt_id]);
217 }
218 in >> line;
219 }
220 }
221 else
222 {
223 WARN(
224 "readPolyline(): polyline is an arc *** reading not "
225 "implemented");
226 errors.emplace_back(
227 "[readPolyline] reading polyline as an arc is not "
228 "implemented");
229 }
230 // empty line or the keyword or subkeyword or end of file
231 }
232 //....................................................................
233 if (line.find("$POINT_VECTOR") !=
234 std::string::npos) // subkeyword found
235 {
236 in >> line; // read file name
237 line = BaseLib::joinPaths(path, line);
238 readPolylinePointVector(line, pnt_vec, ply, path, errors);
239 } // subkeyword found
240 } while (line.find('#') == std::string::npos && !line.empty() && in);
241
242 if (type != 100)
243 {
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);
247 }
248
249 return line;
250}
251
252/**************************************************************************
253 GEOLib-Function:
254 Task: polyline read function
255 Programming:
256 03/2004 CC Implementation
257 05/2004 CC Modification
258 04/2005 CC Modification calculate the minimal distance between points
259reference for mesh density of line element calculation 07/2005 CC read ID of
260polyline 08/2005 CC parameter 01/2010 TF changed signature of function
261**************************************************************************/
263std::string readPolylines(std::istream& in,
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)
271{
272 if (!in)
273 {
274 WARN("readPolylines(): input stream error.");
275 return std::string("");
276 }
277 std::string tag("#POLYLINE");
278
279 while (!in.eof() && !in.fail() &&
280 tag.find("#POLYLINE") != std::string::npos)
281 {
282 tag = readPolyline(in, ply_vec, ply_vec_names, pnt_vec,
283 zero_based_indexing, pnt_id_map, path, errors);
284 }
285
286 return tag;
287}
288
289/**************************************************************************
290 GeoLib-Method: readSurface
291 Task: Read surface data from input stream
292 Programming:
293 03/2004 OK Implementation
294 05/2005 OK EPSILON
295 09/2005 CC file_path_base
296 01/2010 TF signature modification, reimplementation
297**************************************************************************/
299std::string readSurface(std::istream& in,
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,
305 GeoLib::PointVec& pnt_vec, std::string const& path,
306 std::vector<std::string>& errors)
307{
308 std::string line;
309 GeoLib::Surface* sfc(nullptr);
310
311 int type(-1);
312 std::string name;
313 std::size_t ply_id(std::numeric_limits<std::size_t>::max());
314
315 do
316 {
317 in >> line;
318 if (line.find("$ID") != std::string::npos)
319 { // subkeyword found CC
320 in >> line; // read value
321 }
322 //....................................................................
323 if (line.find("$NAME") != std::string::npos) // subkeyword found
324 {
325 in >> line; // read value
326 name = line;
327 }
328 //....................................................................
329 if (line.find("$TYPE") != std::string::npos) // subkeyword found
330 {
331 in >> line; // read value
332 type = strtol(line.c_str(), nullptr, 0);
333 }
334 //....................................................................
335 if (line.find("$EPSILON") != std::string::npos)
336 { // subkeyword found
337 in >> line; // read value
338 }
339 //....................................................................
340 if (line.find("$TIN") != std::string::npos) // subkeyword found
341 {
342 in >> line; // read value (file name)
343 std::string const file_name = BaseLib::joinPaths(path, line);
344 sfc =
345 GeoLib::IO::TINInterface::readTIN(file_name, pnt_vec, &errors);
346 }
347 //....................................................................
348 if (line.find("$MAT_GROUP") != std::string::npos)
349 { // subkeyword found
350 in >> line; // read value
351 }
352 //....................................................................
353 if (line.find("$POLYLINES") != std::string::npos) // subkeyword found
354 { // read the name of the polyline(s)
355 in >> line;
356 while (!in.eof() && !in.fail() && !line.empty() &&
357 (line.find('#') == std::string::npos) &&
358 (line.find('$') == std::string::npos))
359 {
360 if (ply_vec == nullptr)
361 {
362 OGS_FATAL("The polyline vector is not allocated.");
363 }
364
365 // we did read the name of a polyline -> search the id for
366 // polyline
367 auto it(ply_vec_names.find(line));
368 if (it != ply_vec_names.end())
369 {
370 ply_id = it->second;
371 }
372 else
373 {
374 ply_id = ply_vec->size();
375 }
376
377 if (ply_id == ply_vec->size())
378 {
379 WARN("readSurface(): polyline for surface not found!");
380 errors.emplace_back(
381 "[readSurface] polyline for surface not found!");
382 }
383 else
384 {
385 if (type == 3)
386 {
387 WARN(
388 "readSurface(): surface type 3: flat surface with "
389 "any normal direction - reading not implemented.");
390 errors.emplace_back(
391 "[readSurface] surface type 3: flat surface with "
392 "any normal direction - reading not implemented");
393 }
394 if (type == 2)
395 {
396 WARN(
397 "readSurface(): vertical surface (type 2) - "
398 "reading not implemented");
399 errors.emplace_back(
400 "[readSurface] vertical surface (type 2) - reading "
401 "not implemented");
402 }
403 }
404 in >> line;
405 }
406 // empty line or a keyword is found
407 }
408 } while (line.find('#') == std::string::npos && !line.empty() && in);
409
410 if (!name.empty())
411 {
412 sfc_names.insert(
413 std::pair<std::string, std::size_t>(name, sfc_vec.size()));
414 }
415
416 if (sfc)
417 {
418 // surface create by TIN
419 sfc_vec.push_back(sfc);
420 }
421 else
422 {
423 // surface created by polygon
424 if (ply_id != std::numeric_limits<std::size_t>::max())
425 {
426 if (ply_vec == nullptr)
427 {
428 OGS_FATAL("The polyline vector is not allocated.");
429 }
430
431 if (ply_id != ply_vec->size())
432 {
433 if ((*ply_vec)[ply_id]->isClosed())
434 {
435 polygon_vec.push_back(
436 new GeoLib::Polygon(*((*ply_vec)[ply_id]), true));
437 }
438 else
439 {
440 WARN(
441 "readSurface(): cannot create surface {:s} from "
442 "polyline {:d} since polyline is not closed.",
443 name, ply_id);
444 }
445 }
446 }
447 }
448
449 return line;
450}
451
452/**************************************************************************
453 GEOLib-Method:
454 Task: Surface read function
455 Programming:
456 03/2004 OK Implementation
457 05/2004 CC Modification
458 01/2010 TF changed signature of function, big modifications
459**************************************************************************/
460std::string readSurfaces(
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,
465 GeoLib::PointVec& pnt_vec, const std::string& path,
466 std::vector<std::string>& errors, GeoLib::GEOObjects& geo,
467 std::string const& unique_name, std::string const& gmsh_path)
468{
469 if (!in.good())
470 {
471 WARN("readSurfaces(): input stream error.");
472 return std::string("");
473 }
474 std::string tag("#SURFACE");
475
476 std::vector<GeoLib::Polygon*> polygon_vec;
477
478 while (!in.eof() && !in.fail() && tag.find("#SURFACE") != std::string::npos)
479 {
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())
484 {
485 INFO("Creating a surface by triangulation of the polyline ...");
487 *(dynamic_cast<GeoLib::Polyline*>(polygon_vec.back())), geo,
488 unique_name, gmsh_path))
489 {
490 INFO("\t done");
491 }
492 else
493 {
494 WARN(
495 "\t Creating a surface by triangulation of the polyline "
496 "failed.");
497 }
498 }
499 }
500 for (auto& k : polygon_vec)
501 {
502 delete k;
503 }
504
505 return tag;
506}
507
508bool readGLIFileV4(const std::string& fname,
510 std::string& unique_name,
511 std::vector<std::string>& errors,
512 std::string const& gmsh_path)
513{
514 INFO("GeoLib::readGLIFile(): open stream from file {:s}.", fname);
515 std::ifstream in(fname.c_str());
516 if (!in)
517 {
518 WARN("GeoLib::readGLIFile(): could not open file {:s}.", fname);
519 errors.push_back("[readGLIFileV4] error opening stream from " + fname);
520 return false;
521 }
522 INFO("GeoLib::readGLIFile(): \t done.");
523
524 std::string tag;
525 while (tag.find("#POINTS") == std::string::npos && !in.eof())
526 {
527 std::getline(in, tag);
528 }
529
530 // read names of points into vector of strings
531 std::map<std::string, std::size_t> pnt_id_names_map;
532
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());
538
539 unique_name = BaseLib::extractBaseName(fname);
540 if (!pnt_vec.empty())
541 {
542 geo.addPointVec(std::move(pnt_vec), unique_name,
543 std::move(pnt_id_names_map), 1e-6);
544 }
545
546 // extract path for reading external files
547 const std::string path = BaseLib::extractPath(fname);
548
549 // read names of plys into temporary string-vec
551 std::vector<GeoLib::Polyline*> ply_vec;
552 GeoLib::PointVec& point_vec(
553 *const_cast<GeoLib::PointVec*>(geo.getPointVecObj(unique_name)));
554 auto geo_pnt_vec(
555 const_cast<std::vector<GeoLib::Point*>&>(point_vec.getVector()));
556 if (tag.find("#POLYLINE") != std::string::npos && in)
557 {
558 INFO("GeoLib::readGLIFile(): read polylines from stream.");
559 tag = readPolylines(in, ply_vec, ply_names, geo_pnt_vec, zero_based_idx,
560 geo.getPointVecObj(unique_name)->getIDMap(), path,
561 errors);
562 INFO("GeoLib::readGLIFile(): \t ok, {:d} polylines read.",
563 ply_vec.size());
564 }
565 else
566 {
567 INFO("GeoLib::readGLIFile(): tag #POLYLINE not found.");
568 }
569
570 if (!ply_vec.empty())
571 {
572 geo.addPolylineVec(std::move(ply_vec), unique_name,
573 std::move(ply_names));
574 }
575
576 // Since ply_names is a unique_ptr and is given to the GEOObject instance
577 // geo it is not usable anymore. For this reason a copy is necessary.
578 std::map<std::string, std::size_t> ply_names_copy;
579 if (geo.getPolylineVecObj(unique_name))
580 {
581 ply_names_copy = std::map<std::string, std::size_t>{
582 geo.getPolylineVecObj(unique_name)->getNameIDMapBegin(),
583 geo.getPolylineVecObj(unique_name)->getNameIDMapEnd()};
584 }
585
586 std::vector<GeoLib::Surface*> sfc_vec;
588 if (tag.find("#SURFACE") != std::string::npos && in)
589 {
590 INFO("GeoLib::readGLIFile(): read surfaces from stream.");
591
592 readSurfaces(in, sfc_vec, sfc_names, geo.getPolylineVec(unique_name),
593 ply_names_copy, point_vec, path, errors, geo, unique_name,
594 gmsh_path);
595 INFO("GeoLib::readGLIFile(): \tok, {:d} surfaces read.",
596 sfc_vec.size());
597 }
598 else
599 {
600 INFO("GeoLib::readGLIFile(): tag #SURFACE not found.");
601 }
602 in.close();
603
604 if (!sfc_vec.empty())
605 {
606 geo.addSurfaceVec(std::move(sfc_vec), unique_name,
607 std::move(sfc_names));
608 }
609
610 return errors.empty();
611}
612
613std::size_t writeTINSurfaces(std::ofstream& os,
614 GeoLib::SurfaceVec const* sfcs_vec,
615 std::size_t sfc_count, std::string const& path)
616{
617 auto const& sfcs(sfcs_vec->getVector());
618 for (auto const* sfc : sfcs)
619 {
620 os << "#SURFACE"
621 << "\n";
622 std::string sfc_name;
623 if (sfcs_vec->getNameOfElementByID(sfc_count, sfc_name))
624 {
625 os << "\t$NAME "
626 << "\n"
627 << "\t\t" << sfc_name << "\n";
628 }
629 else
630 {
631 os << "\t$NAME "
632 << "\n"
633 << "\t\t" << sfc_count << "\n";
634 sfc_name = std::to_string(sfc_count);
635 }
636 sfc_name += ".tin";
637 os << "\t$TIN"
638 << "\n";
639 os << "\t\t" << sfc_name << "\n";
640 // create tin file
641 sfc_name = BaseLib::joinPaths(path, sfc_name);
643 sfc_count++;
644 }
645 return sfc_count;
646}
647
648void writeGLIFileV4(const std::string& fname,
649 const std::string& geo_name,
650 const GeoLib::GEOObjects& geo)
651{
652 std::ofstream os(fname.c_str());
653 if (auto const* const pnt_vec(geo.getPointVecObj(geo_name));
654 pnt_vec != nullptr)
655 {
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}.",
659 n_pnts, fname);
660 os << "#POINTS"
661 << "\n";
662 os.precision(std::numeric_limits<double>::max_digits10);
663 for (std::size_t k(0); k < n_pnts; k++)
664 {
665 os << k << " " << *(pnts[k]);
666 std::string const& pnt_name(pnt_vec->getItemNameByID(k));
667 if (!pnt_name.empty())
668 {
669 os << " $NAME " << pnt_name;
670 }
671 os << "\n";
672 }
673 }
674
675 if (auto const* plys_vec(geo.getPolylineVecObj(geo_name));
676 plys_vec != nullptr)
677 {
678 auto const& plys(plys_vec->getVector());
679 INFO("GeoLib::writeGLIFileV4(): {:d} polylines to file {:s}.",
680 plys.size(), fname);
681 for (auto ply : plys)
682 {
683 os << "#POLYLINE"
684 << "\n";
685 std::string polyline_name;
686 plys_vec->getNameOfElement(ply, polyline_name);
687 os << " $NAME "
688 << "\n"
689 << " " << polyline_name << "\n";
690 os << " $POINTS"
691 << "\n";
692 for (std::size_t j(0); j < ply->getNumberOfPoints(); j++)
693 {
694 os << " " << ply->getPointID(j) << "\n";
695 }
696 }
697 }
698
699 // writing surfaces as TIN files
700 if (const auto* sfcs_vec(geo.getSurfaceVecObj(geo_name));
701 sfcs_vec != nullptr)
702 {
703 writeTINSurfaces(os, sfcs_vec, 0, BaseLib::extractPath(fname));
704 }
705
706 os << "#STOP"
707 << "\n";
708 os.close();
709}
710
711void writeAllDataToGLIFileV4(const std::string& fname,
712 const GeoLib::GEOObjects& geo)
713{
714 auto const geo_names = geo.getGeometryNames();
715
716 // extract path for reading external files
717 const std::string path = BaseLib::extractPath(fname);
718
719 std::ofstream os(fname.c_str());
720
721 std::size_t pnts_offset(0);
722 std::vector<std::size_t> pnts_id_offset;
723 pnts_id_offset.push_back(0);
724
725 // writing all points
726 os << "#POINTS"
727 << "\n";
728 for (auto const& geo_name : geo_names)
729 {
730 os.precision(std::numeric_limits<double>::max_digits10);
731 GeoLib::PointVec const* const pnt_vec(geo.getPointVecObj(geo_name));
732 if (pnt_vec)
733 {
734 auto 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++)
737 {
738 os << pnts_offset + k << " " << *(pnts[k]);
739 std::string const& pnt_name(pnt_vec->getItemNameByID(k));
740 if (!pnt_name.empty())
741 {
742 os << "$NAME " << pnt_name;
743 }
744 os << "\n";
745 }
746 pnts_offset += pnts.size();
747 pnts_id_offset.push_back(pnts_offset);
748 }
749 }
750
751 INFO("GeoLib::writeAllDataToGLIFileV4(): wrote {:d} points.", pnts_offset);
752
753 // writing all stations
754 std::vector<std::string> stn_names;
755 geo.getStationVectorNames(stn_names);
756 for (auto& stn_name : stn_names)
757 {
758 os.precision(std::numeric_limits<double>::max_digits10);
759 const std::vector<GeoLib::Point*>* pnts(geo.getStationVec(stn_name));
760 if (pnts)
761 {
762 for (std::size_t k(0); k < pnts->size(); k++)
763 {
764 os << k + pnts_offset << " " << *((*pnts)[k]) << " $NAME "
765 << static_cast<GeoLib::Station*>((*pnts)[k])->getName()
766 << "\n";
767 }
768 pnts_offset += pnts->size();
769 pnts_id_offset.push_back(pnts_offset);
770 }
771 }
772
773 std::size_t plys_cnt(0);
774
775 // writing all polylines
776 for (std::size_t j(0); j < geo_names.size(); j++)
777 {
778 const GeoLib::PolylineVec* plys_vec(
779 geo.getPolylineVecObj(geo_names[j]));
780 if (plys_vec)
781 {
782 auto const& plys(plys_vec->getVector());
783 for (auto ply : plys)
784 {
785 os << "#POLYLINE"
786 << "\n";
787 std::string ply_name;
788 os << " $NAME\n";
789 if (plys_vec->getNameOfElementByID(plys_cnt, ply_name))
790 {
791 os << " " << ply_name << "\n";
792 }
793 else
794 {
795 os << " " << geo_names[j] << "-" << plys_cnt << "\n";
796 }
797 os << " $POINTS"
798 << "\n";
799 for (std::size_t l(0); l < ply->getNumberOfPoints(); l++)
800 {
801 os << " " << pnts_id_offset[j] + ply->getPointID(l)
802 << "\n";
803 }
804 plys_cnt++;
805 }
806 }
807 }
808
809 // writing surfaces as TIN files
810 std::size_t sfcs_cnt(0);
811 for (auto const& geo_name : geo_names)
812 {
813 const GeoLib::SurfaceVec* sfcs_vec(geo.getSurfaceVecObj(geo_name));
814 if (sfcs_vec)
815 {
816 sfcs_cnt += writeTINSurfaces(os, sfcs_vec, sfcs_cnt, path);
817 }
818 }
819
820 os << "#STOP"
821 << "\n";
822 os.close();
823}
824
825} // namespace Legacy
826} // end namespace FileIO
#define OGS_FATAL(...)
Definition Error.h:19
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34
Container class for geometric objects.
Definition GEOObjects.h:46
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.
Definition GEOObjects.h:197
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...
Definition PointVec.h:25
const std::vector< std::size_t > & getIDMap() const
Definition PointVec.h:86
std::string const & getItemNameByID(std::size_t id) const
Definition PointVec.cpp:239
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition Polyline.h:29
virtual bool addPoint(std::size_t pnt_id)
Definition Polyline.cpp:24
A Station (observation site) is basically a Point with some additional information.
Definition Station.h:26
std::string const & getName() const
Returns the name of the station.
Definition Station.h:49
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
Definition TemplateVec.h:30
NameIdMap::const_iterator getNameIDMapBegin() const
Returns the begin of the name id mapping structure.
Definition TemplateVec.h:74
bool getNameOfElementByID(std::size_t id, std::string &element_name) const
std::vector< T * > const & getVector() const
Definition TemplateVec.h:94
NameIdMap::const_iterator getNameIDMapEnd() const
Returns the end of the name id mapping structure.
Definition TemplateVec.h:80
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)
Definition StringTools.h:53
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)
Definition OGSIOVer4.cpp:38
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
Definition SurfaceVec.h:17
TemplateVec< GeoLib::Polyline > PolylineVec
class PolylineVec encapsulate a std::vector of Polylines additional one can give the vector of polyli...
Definition PolylineVec.h:16