OGS
FileIO::Legacy Namespace Reference

Detailed Description

Includes the interfaces to OGS legacy file formats (OGS-5 and below).

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 518 of file OGSIOVer4.cpp.

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

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 48 of file OGSIOVer4.cpp.

51 {
52  std::string line;
53  std::size_t cnt(0);
54 
55  std::getline(in, line);
56  // geometric key words start with the hash #
57  // while not found a new key word do ...
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 
75  // read mesh density
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 }

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 157 of file OGSIOVer4.cpp.

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  {
221  ply->addPoint(pnt_id_map[pnt_id]);
222  }
223  }
224  else
225  {
226  ply->addPoint(pnt_id_map[pnt_id]);
227  }
228  in >> line;
229  }
230  }
231  else
232  {
233  WARN(
234  "readPolyline(): polyline is an arc *** reading not "
235  "implemented");
236  errors.emplace_back(
237  "[readPolyline] reading polyline as an arc is not "
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 }
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition: Polyline.h:53
std::string joinPaths(std::string const &pathA, std::string const &pathB)
Definition: FileTools.cpp:212
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

References BaseLib::joinPaths(), readPolylinePointVector(), 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 116 of file OGSIOVer4.cpp.

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 }
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 273 of file OGSIOVer4.cpp.

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 }
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)
Definition: OGSIOVer4.cpp:157

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 309 of file OGSIOVer4.cpp.

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 =
355  GeoLib::IO::TINInterface::readTIN(file_name, pnt_vec, &errors);
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  if (ply_vec == nullptr)
371  {
372  OGS_FATAL("The polyline vector is not allocated.");
373  }
374 
375  // we did read the name of a polyline -> search the id for
376  // polyline
377  auto it(ply_vec_names.find(line));
378  if (it != ply_vec_names.end())
379  {
380  ply_id = it->second;
381  }
382  else
383  {
384  ply_id = ply_vec->size();
385  }
386 
387  if (ply_id == ply_vec->size())
388  {
389  WARN("readSurface(): polyline for surface not found!");
390  errors.emplace_back(
391  "[readSurface] polyline for surface not found!");
392  }
393  else
394  {
395  if (type == 3)
396  {
397  WARN(
398  "readSurface(): surface type 3: flat surface with "
399  "any normal direction - reading not implemented.");
400  errors.emplace_back(
401  "[readSurface] surface type 3: flat surface with "
402  "any normal direction - reading not implemented");
403  }
404  if (type == 2)
405  {
406  WARN(
407  "readSurface(): vertical surface (type 2) - "
408  "reading not implemented");
409  errors.emplace_back(
410  "[readSurface] vertical surface (type 2) - reading "
411  "not implemented");
412  }
413  }
414  in >> line;
415  }
416  // empty line or a keyword is found
417  }
418  } while (line.find('#') == std::string::npos && !line.empty() && in);
419 
420  if (!name.empty())
421  {
422  sfc_names.insert(
423  std::pair<std::string, std::size_t>(name, sfc_vec.size()));
424  }
425 
426  if (sfc)
427  {
428  // surface create by TIN
429  sfc_vec.push_back(sfc);
430  }
431  else
432  {
433  // surface created by polygon
434  if (ply_id != std::numeric_limits<std::size_t>::max())
435  {
436  if (ply_vec == nullptr)
437  {
438  OGS_FATAL("The polyline vector is not allocated.");
439  }
440 
441  if (ply_id != ply_vec->size())
442  {
443  if ((*ply_vec)[ply_id]->isClosed())
444  {
445  polygon_vec.push_back(
446  new GeoLib::Polygon(*((*ply_vec)[ply_id]), true));
447  }
448  else
449  {
450  WARN(
451  "readSurface(): cannot create surface {:s} from "
452  "polyline {:d} since polyline is not closed.",
453  name, ply_id);
454  }
455  }
456  }
457  }
458 
459  return line;
460 }
#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:34

References BaseLib::joinPaths(), MaterialPropertyLib::name, 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 470 of file OGSIOVer4.cpp.

478 {
479  if (!in.good())
480  {
481  WARN("readSurfaces(): input stream error.");
482  return std::string("");
483  }
484  std::string tag("#SURFACE");
485 
486  std::vector<GeoLib::Polygon*> polygon_vec;
487 
488  while (!in.eof() && !in.fail() && tag.find("#SURFACE") != std::string::npos)
489  {
490  std::size_t n_polygons(polygon_vec.size());
491  tag = readSurface(in, polygon_vec, sfc_vec, sfc_names, ply_vec,
492  ply_vec_names, pnt_vec, path, errors);
493  if (n_polygons < polygon_vec.size())
494  {
495  INFO("Creating a surface by triangulation of the polyline ...");
497  *(dynamic_cast<GeoLib::Polyline*>(polygon_vec.back())), geo,
498  unique_name, gmsh_path))
499  {
500  INFO("\t done");
501  }
502  else
503  {
504  WARN(
505  "\t Creating a surface by triangulation of the polyline "
506  "failed.");
507  }
508  }
509  }
510  for (auto& k : polygon_vec)
511  {
512  delete k;
513  }
514 
515  return tag;
516 }
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)
Definition: OGSIOVer4.cpp:309
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 721 of file OGSIOVer4.cpp.

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

References BaseLib::extractPath(), GeoLib::GEOObjects::getGeometryNames(), GeoLib::PointVec::getItemNameByID(), 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 658 of file OGSIOVer4.cpp.

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

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 623 of file OGSIOVer4.cpp.

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