OGS
OGSIOVer4.cpp
Go to the documentation of this file.
1
15 #include "OGSIOVer4.h"
16
17 #include <iomanip>
18 #include <limits>
19 #include <sstream>
20
22 #include "BaseLib/FileTools.h"
23 #include "BaseLib/Logging.h"
24 #include "BaseLib/StringTools.h"
26 #include "GeoLib/GEOObjects.h"
27 #include "GeoLib/IO/TINInterface.h"
28 #include "GeoLib/Point.h"
29 #include "GeoLib/PointVec.h"
30 #include "GeoLib/Polygon.h"
31 #include "GeoLib/Polyline.h"
32 #include "GeoLib/Station.h"
33 #include "GeoLib/Surface.h"
34 #include "GeoLib/Triangle.h"
35
36 namespace FileIO
37 {
38 namespace Legacy
39 {
40 /**************************************************************************
42  Aufgabe: Lesen der GLI Points und schreiben in einen Vector
43  08/2005 CC Implementation
44  01/2010 TF big modifications
45 **************************************************************************/
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)
51 {
52  std::string line;
53  std::size_t cnt(0);
54
55  std::getline(in, line);
58  while (line.find('#') == std::string::npos && !in.eof() && !in.fail())
59  {
60  // read id and point coordinates
61  std::stringstream inss(line);
62  std::size_t id;
63  double x;
64  double y;
65  double z;
66  inss >> id >> x >> y >> z;
67  if (!inss.fail())
68  {
69  if (cnt == 0)
70  {
71  zero_based_indexing = id == 0;
72  }
73  pnt_vec->push_back(new GeoLib::Point(x, y, z, id));
74
76  if (line.find("$MD") != std::string::npos) 77 { 78 double mesh_density; 79 std::size_t pos1(line.find_first_of('M')); 80 inss.str(line.substr(pos1 + 2, std::string::npos)); 81 inss >> mesh_density; 82 } 83 84 // read name of point 85 std::size_t pos(line.find("$NAME"));
86  if (pos != std::string::npos) // OK
87  {
88  std::size_t end_pos((line.substr(pos + 6)).find(' '));
89  if (end_pos != std::string::npos)
90  {
91  (*pnt_id_name_map)[line.substr(pos + 6, end_pos)] = id;
92  }
93  else
94  {
95  (*pnt_id_name_map)[line.substr(pos + 6)] = id;
96  }
97  }
98
99  std::size_t id_pos(line.find("$ID")); 100 if (id_pos != std::string::npos) 101 { 102 WARN( 103 "readPoints(): found tag$ID - please use tag $NAME for " 104 "reading point names in point {:d}.", 105 cnt); 106 } 107 cnt++; 108 } 109 std::getline(in, line); 110 } 111 112 return line; 113 } 114 116 void readPolylinePointVector(const std::string& fname, 117 std::vector<GeoLib::Point*>& pnt_vec, 118 GeoLib::Polyline* ply, 119 const std::string& path, 120 std::vector<std::string>& errors) 121 { 122 // open file 123 std::ifstream in(BaseLib::joinPaths(path, fname).c_str()); 124 if (!in) 125 { 126 WARN("readPolylinePointVector(): error opening stream from {:s}", 127 fname); 128 errors.push_back( 129 "[readPolylinePointVector] error opening stream from " + fname); 130 return; 131 } 132 133 double x; 134 double y; 135 double z; 136 while (in) 137 { 138 in >> x >> y >> z; 139 std::size_t pnt_id(pnt_vec.size()); 140 pnt_vec.push_back(new GeoLib::Point(x, y, z)); 141 ply->addPoint(pnt_id); 142 } 143 } 144 145 /************************************************************************** 146 GeoLib-Method: Read 147 Task: Read polyline data from file 148 Programming: 149 03/2004 CC Implementation 150 09/2004 OK file path for PLY files 151 07/2005 CC PLY id 152 08/2005 CC parameter 153 09/2005 CC itoa - convert integer to string 154 01/2010 TF cleaned method from unused variables 155 **************************************************************************/ 157 std::string readPolyline(std::istream& in, 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) 165 { 166 std::string line; 167 std::string name_of_ply; 168 auto* ply(new GeoLib::Polyline(pnt_vec)); 169 std::size_t type = 2; // need an initial value 170 171 // Loop over all phases or components 172 do 173 { 174 in >> line; 175 if (line.find("$ID") != std::string::npos)
176  { // subkeyword found CC
177  in >> line; // read value
178  }
179  //....................................................................
180  if (line.find("$NAME") != std::string::npos) // subkeyword found 181 { 182 in >> line; 183 name_of_ply = line; // read value 184 } 185 //.................................................................... 186 if (line.find("$TYPE") != std::string::npos) // subkeyword found
187  {
188  in >> line; // read value
189  type = static_cast<std::size_t>(strtol(line.c_str(), nullptr, 0));
190  }
191  //....................................................................
192  if (line.find("$EPSILON") != std::string::npos) 193 { // subkeyword found 194 in >> line; // read value 195 } 196 //.................................................................... 197 if (line.find("$MAT_GROUP") != std::string::npos)
198  { // subkeyword found
199  in >> line; // read value
200  }
201  //....................................................................
202  if (line.find("$POINTS") != std::string::npos) // subkeyword found 203 { // read the point ids 204 in >> line; 205 if (type != 100) 206 { 207 while (!in.eof() && !in.fail() && !line.empty() && 208 (line.find('#') == std::string::npos) && 209 (line.find('$') == std::string::npos))
210  {
211  auto pnt_id(BaseLib::str2number<std::size_t>(line));
212  if (!zero_based_indexing)
213  {
214  pnt_id--; // one based indexing
215  }
216  std::size_t ply_size(ply->getNumberOfPoints());
217  if (ply_size > 0)
218  {
219  if (ply->getPointID(ply_size - 1) != pnt_id_map[pnt_id])
220  {
222  }
223  }
224  else
225  {
227  }
228  in >> line;
229  }
230  }
231  else
232  {
233  WARN(
235  "implemented");
236  errors.emplace_back(
238  "implemented");
239  }
240  // empty line or the keyword or subkeyword or end of file
241  }
242  //....................................................................
243  if (line.find("$POINT_VECTOR") != 244 std::string::npos) // subkeyword found 245 { 246 in >> line; // read file name 247 line = BaseLib::joinPaths(path, line); 248 readPolylinePointVector(line, pnt_vec, ply, path, errors); 249 } // subkeyword found 250 } while (line.find('#') == std::string::npos && !line.empty() && in); 251 252 if (type != 100) 253 { 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); 257 } 258 259 return line; 260 } 261 262 /************************************************************************** 263 GEOLib-Function: 264 Task: polyline read function 265 Programming: 266 03/2004 CC Implementation 267 05/2004 CC Modification 268 04/2005 CC Modification calculate the minimal distance between points 269 reference for mesh density of line element calculation 07/2005 CC read ID of 270 polyline 08/2005 CC parameter 01/2010 TF changed signature of function 271 **************************************************************************/ 273 std::string readPolylines(std::istream& in, 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) 281 { 282 if (!in) 283 { 284 WARN("readPolylines(): input stream error."); 285 return std::string(""); 286 } 287 std::string tag("#POLYLINE"); 288 289 while (!in.eof() && !in.fail() && 290 tag.find("#POLYLINE") != std::string::npos) 291 { 292 tag = readPolyline(in, ply_vec, ply_vec_names, pnt_vec, 293 zero_based_indexing, pnt_id_map, path, errors); 294 } 295 296 return tag; 297 } 298 299 /************************************************************************** 300 GeoLib-Method: readSurface 301 Task: Read surface data from input stream 302 Programming: 303 03/2004 OK Implementation 304 05/2005 OK EPSILON 305 09/2005 CC file_path_base 306 01/2010 TF signature modification, reimplementation 307 **************************************************************************/ 309 std::string readSurface(std::istream& in, 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, 315 GeoLib::PointVec& pnt_vec, std::string const& path, 316 std::vector<std::string>& errors) 317 { 318 std::string line; 319 GeoLib::Surface* sfc(nullptr); 320 321 int type(-1); 322 std::string name; 323 std::size_t ply_id(std::numeric_limits<std::size_t>::max()); 324 325 do 326 { 327 in >> line; 328 if (line.find("$ID") != std::string::npos)
329  { // subkeyword found CC
330  in >> line; // read value
331  }
332  //....................................................................
333  if (line.find("$NAME") != std::string::npos) // subkeyword found 334 { 335 in >> line; // read value 336 name = line; 337 } 338 //.................................................................... 339 if (line.find("$TYPE") != std::string::npos) // subkeyword found
340  {
341  in >> line; // read value
342  type = strtol(line.c_str(), nullptr, 0);
343  }
344  //....................................................................
345  if (line.find("$EPSILON") != std::string::npos) 346 { // subkeyword found 347 in >> line; // read value 348 } 349 //.................................................................... 350 if (line.find("$TIN") != std::string::npos) // subkeyword found
351  {
352  in >> line; // read value (file name)
353  std::string const file_name = BaseLib::joinPaths(path, line);
354  sfc =
356  }
357  //....................................................................
358  if (line.find("$MAT_GROUP") != std::string::npos) 359 { // subkeyword found 360 in >> line; // read value 361 } 362 //.................................................................... 363 if (line.find("$POLYLINES") != std::string::npos) // subkeyword found
364  { // read the name of the polyline(s)
365  in >> line;
366  while (!in.eof() && !in.fail() && !line.empty() &&
367  (line.find('#') == std::string::npos) &&
368  (line.find('$') == std::string::npos)) 369 { 370 // we did read the name of a polyline -> search the id for 371 // polyline 372 auto it(ply_vec_names.find(line)); 373 if (it != ply_vec_names.end()) 374 { 375 ply_id = it->second; 376 } 377 else 378 { 379 ply_id = ply_vec.size(); 380 } 381 382 if (ply_id == ply_vec.size()) 383 { 384 WARN("readSurface(): polyline for surface not found!"); 385 errors.emplace_back( 386 "[readSurface] polyline for surface not found!"); 387 } 388 else 389 { 390 if (type == 3) 391 { 392 WARN( 393 "readSurface(): surface type 3: flat surface with " 394 "any normal direction - reading not implemented."); 395 errors.emplace_back( 396 "[readSurface] surface type 3: flat surface with " 397 "any normal direction - reading not implemented"); 398 } 399 if (type == 2) 400 { 401 WARN( 402 "readSurface(): vertical surface (type 2) - " 403 "reading not implemented"); 404 errors.emplace_back( 405 "[readSurface] vertical surface (type 2) - reading " 406 "not implemented"); 407 } 408 } 409 in >> line; 410 } 411 // empty line or a keyword is found 412 } 413 } while (line.find('#') == std::string::npos && !line.empty() && in); 414 415 if (!name.empty()) 416 { 417 sfc_names.insert( 418 std::pair<std::string, std::size_t>(name, sfc_vec.size())); 419 } 420 421 if (sfc) 422 { 423 // surface create by TIN 424 sfc_vec.push_back(sfc); 425 } 426 else 427 { 428 // surface created by polygon 429 if (ply_id != std::numeric_limits<std::size_t>::max() && 430 ply_id != ply_vec.size()) 431 { 432 if (ply_vec[ply_id]->isClosed()) 433 { 434 polygon_vec.push_back( 435 new GeoLib::Polygon(*(ply_vec[ply_id]), true)); 436 } 437 else 438 { 439 WARN( 440 "readSurface(): cannot create surface {:s} from polyline " 441 "{:d} since polyline is not closed.", 442 name, ply_id); 443 } 444 } 445 } 446 447 return line; 448 } 449 450 /************************************************************************** 451 GEOLib-Method: 452 Task: Surface read function 453 Programming: 454 03/2004 OK Implementation 455 05/2004 CC Modification 456 01/2010 TF changed signature of function, big modifications 457 **************************************************************************/ 458 std::string readSurfaces( 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, 463 GeoLib::PointVec& pnt_vec, const std::string& path, 464 std::vector<std::string>& errors, GeoLib::GEOObjects& geo, 465 std::string const& unique_name, std::string const& gmsh_path) 466 { 467 if (!in.good()) 468 { 469 WARN("readSurfaces(): input stream error."); 470 return std::string(""); 471 } 472 std::string tag("#SURFACE"); 473 474 std::vector<GeoLib::Polygon*> polygon_vec; 475 476 while (!in.eof() && !in.fail() && tag.find("#SURFACE") != std::string::npos) 477 { 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()) 482 { 483 INFO("Creating a surface by triangulation of the polyline ..."); 485 *(dynamic_cast<GeoLib::Polyline*>(polygon_vec.back())), geo, 486 unique_name, gmsh_path)) 487 { 488 INFO("\t done"); 489 } 490 else 491 { 492 WARN( 493 "\t Creating a surface by triangulation of the polyline " 494 "failed."); 495 } 496 } 497 } 498 for (auto& k : polygon_vec) 499 { 500 delete k; 501 } 502 503 return tag; 504 } 505 506 bool readGLIFileV4(const std::string& fname, 507 GeoLib::GEOObjects& geo, 508 std::string& unique_name, 509 std::vector<std::string>& errors, 510 std::string const& gmsh_path) 511 { 512 INFO("GeoLib::readGLIFile(): open stream from file {:s}.", fname); 513 std::ifstream in(fname.c_str()); 514 if (!in) 515 { 516 WARN("GeoLib::readGLIFile(): could not open file {:s}.", fname); 517 errors.push_back("[readGLIFileV4] error opening stream from " + fname); 518 return false; 519 } 520 INFO("GeoLib::readGLIFile(): \t done."); 521 522 std::string tag; 523 while (tag.find("#POINTS") == std::string::npos && !in.eof()) 524 { 525 std::getline(in, tag); 526 } 527 528 // read names of points into vector of strings 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>}; 531 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()); 537 538 unique_name = BaseLib::extractBaseName(fname); 539 if (!pnt_vec->empty()) 540 { 541 geo.addPointVec(std::move(pnt_vec), unique_name, 542 std::move(pnt_id_names_map), 1e-6); 543 } 544 545 // extract path for reading external files 546 const std::string path = BaseLib::extractPath(fname); 547 548 // read names of plys into temporary string-vec 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*>>(); 551 GeoLib::PointVec& point_vec( 552 *const_cast<GeoLib::PointVec*>(geo.getPointVecObj(unique_name))); 553 auto* geo_pnt_vec( 554 const_cast<std::vector<GeoLib::Point*>*>(point_vec.getVector())); 555 if (tag.find("#POLYLINE") != std::string::npos && in) 556 { 557 INFO("GeoLib::readGLIFile(): read polylines from stream."); 558 tag = readPolylines( 559 in, ply_vec.get(), *ply_names, *geo_pnt_vec, zero_based_idx, 560 geo.getPointVecObj(unique_name)->getIDMap(), path, errors); 561 INFO("GeoLib::readGLIFile(): \t ok, {:d} polylines read.", 562 ply_vec->size()); 563 } 564 else 565 { 566 INFO("GeoLib::readGLIFile(): tag #POLYLINE not found."); 567 } 568 569 if (!ply_vec->empty()) 570 { 571 geo.addPolylineVec(std::move(ply_vec), unique_name, 572 std::move(ply_names)); 573 } 574 575 // Since ply_names is a unique_ptr and is given to the GEOObject instance 576 // geo it is not usable anymore. For this reason a copy is necessary. 577 std::map<std::string, std::size_t> ply_names_copy; 578 if (geo.getPolylineVecObj(unique_name)) 579 { 580 ply_names_copy = std::map<std::string, std::size_t>{ 581 geo.getPolylineVecObj(unique_name)->getNameIDMapBegin(), 582 geo.getPolylineVecObj(unique_name)->getNameIDMapEnd()}; 583 } 584 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) 588 { 589 INFO("GeoLib::readGLIFile(): read surfaces from stream."); 590 591 readSurfaces(in, *sfc_vec, *sfc_names, *geo.getPolylineVec(unique_name), 592 ply_names_copy, point_vec, path, errors, geo, unique_name, 593 gmsh_path); 594 INFO("GeoLib::readGLIFile(): \tok, {:d} surfaces read.", 595 sfc_vec->size()); 596 } 597 else 598 { 599 INFO("GeoLib::readGLIFile(): tag #SURFACE not found."); 600 } 601 in.close(); 602 603 if (!sfc_vec->empty()) 604 { 605 geo.addSurfaceVec( 606 std::move(sfc_vec), unique_name, 607 std::move(sfc_names)); // KR: insert into GEOObjects if not empty 608 } 609 610 return errors.empty(); 611 } 612 613 std::size_t writeTINSurfaces(std::ofstream& os, 614 GeoLib::SurfaceVec const* sfcs_vec, 615 std::size_t sfc_count, std::string const& path) 616 { 617 const std::vector<GeoLib::Surface*>* sfcs(sfcs_vec->getVector()); 618 for (auto 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
648 void writeGLIFileV4(const std::string& fname,
649  const std::string& geo_name,
650  const GeoLib::GEOObjects& geo)
651 {
652  GeoLib::PointVec const* const pnt_vec(geo.getPointVecObj(geo_name));
653  std::vector<GeoLib::Point*> const* const pnts(pnt_vec->getVector());
654  std::ofstream os(fname.c_str());
655  if (pnts)
656  {
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>::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 const GeoLib::PolylineVec* plys_vec(geo.getPolylineVecObj(geo_name)); 676 if (plys_vec) 677 { 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) 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 const GeoLib::SurfaceVec* sfcs_vec(geo.getSurfaceVecObj(geo_name)); 701 if (sfcs_vec) 702 { 703 writeTINSurfaces(os, sfcs_vec, 0, BaseLib::extractPath(fname)); 704 } 705 706 os << "#STOP" 707 << "\n"; 708 os.close(); 709 } 710 711 void 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& geo_name : geo_names) 729 { 730 os.precision(std::numeric_limits<double>::digits10); 731 GeoLib::PointVec const* const pnt_vec(geo.getPointVecObj(geo_name)); 732 std::vector<GeoLib::Point*> const* const pnts(pnt_vec->getVector()); 733 if (pnts) 734 { 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>::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 const std::vector<GeoLib::Polyline*>* 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& 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
Definition of analytical geometry functions.
Filename manipulation routines.
Definition of the GEOObjects class.
Definition of the Point class.
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:37
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.
Definition of string helper functions.
std::string getName(std::string const &line)
Returns the name/title from the "Zone"-description.
Container class for geometric objects.
Definition: GEOObjects.h:61
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
Definition: GEOObjects.cpp:401
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)
Definition: GEOObjects.cpp:261
const PointVec * getPointVecObj(const std::string &name) const
Definition: GEOObjects.cpp:84
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()))
Definition: GEOObjects.cpp:51
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
Definition: GEOObjects.h:205
const PolylineVec * getPolylineVecObj(const std::string &name) const
Definition: GEOObjects.cpp:227
void getStationVectorNames(std::vector< std::string > &names) const
Returns the names of all station vectors.
Definition: GEOObjects.cpp:390
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
Definition: GEOObjects.cpp:210
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)
Definition: GEOObjects.cpp:150
const std::vector< GeoLib::Point * > * getStationVec(const std::string &name) const
Returns the station vector with the given name.
Definition: GEOObjects.cpp:131
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...
Definition: PointVec.h:39
const std::vector< std::size_t > & getIDMap() const
Definition: PointVec.h:97
std::string const & getItemNameByID(std::size_t id) const
Definition: PointVec.cpp:244
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition: Polyline.h:51
Definition: Polyline.cpp:34
A Station (observation site) is basically a Point with some additional information.
Definition: Station.h:37
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
Definition: Surface.h:34
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
Definition: TemplateVec.h:40
const std::vector< T * > * getVector() const
Definition: TemplateVec.h:112
NameIdMap::const_iterator getNameIDMapBegin() const
Returns the begin of the name id mapping structure.
Definition: TemplateVec.h:98
bool getNameOfElementByID(std::size_t id, std::string &element_name) const
Definition: TemplateVec.h:153
bool getNameOfElement(const T *data, std::string &name) const
Definition: TemplateVec.h:178
NameIdMap::const_iterator getNameIDMapEnd() const
Returns the end of the name id mapping structure.
Definition: TemplateVec.h:101
std::string extractPath(std::string const &pathname)
Definition: FileTools.cpp:207
std::string joinPaths(std::string const &pathA, std::string const &pathB)
Definition: FileTools.cpp:212
std::string extractBaseName(std::string const &pathname)
Definition: FileTools.cpp:175
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)
Definition: OGSIOVer4.cpp:458
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)
Definition: OGSIOVer4.cpp:309
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)
Definition: OGSIOVer4.cpp:273
std::size_t writeTINSurfaces(std::ofstream &os, GeoLib::SurfaceVec const *sfcs_vec, std::size_t sfc_count, std::string const &path)
Definition: OGSIOVer4.cpp:613
bool readGLIFileV4(const std::string &fname, GeoLib::GEOObjects &geo, std::string &unique_name, std::vector< std::string > &errors, std::string const &gmsh_path)
Definition: OGSIOVer4.cpp:506
void readPolylinePointVector(const std::string &fname, std::vector< GeoLib::Point * > &pnt_vec, GeoLib::Polyline *ply, const std::string &path, std::vector< std::string > &errors)
Definition: OGSIOVer4.cpp:116
void writeGLIFileV4(const std::string &fname, const std::string &geo_name, const GeoLib::GEOObjects &geo)
Definition: OGSIOVer4.cpp:648
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:48
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)
Definition: OGSIOVer4.cpp:157
void writeAllDataToGLIFileV4(const std::string &fname, const GeoLib::GEOObjects &geo)
Definition: OGSIOVer4.cpp:711
bool createSurface(GeoLib::Polyline const &ply, GeoLib::GEOObjects &geometries, std::string const &geometry_name, std::string const &gmsh_binary)