OGS
GEOObjects.cpp
Go to the documentation of this file.
1 
15 #include "GEOObjects.h"
16 
17 #include <fstream>
18 
19 #include "BaseLib/Logging.h"
20 #include "BaseLib/StringTools.h"
21 #include "Station.h"
22 #include "Triangle.h"
23 
24 namespace GeoLib
25 {
26 void markUnusedPoints(GEOObjects const& geo_objects,
27  std::string const& geo_name,
28  std::vector<bool>& transfer_pnts);
29 
30 GEOObjects::GEOObjects() = default;
31 
33 {
34  // delete surfaces
35  for (auto& surface : _sfc_vecs)
36  {
37  delete surface;
38  }
39  // delete polylines
40  for (auto& polyline : _ply_vecs)
41  {
42  delete polyline;
43  }
44  // delete points
45  for (auto& point : _pnt_vecs)
46  {
47  delete point;
48  }
49 }
50 
51 void GEOObjects::addPointVec(std::unique_ptr<std::vector<Point*>> points,
52  std::string& name,
53  std::unique_ptr<std::map<std::string, std::size_t>>
54  pnt_id_name_map,
55  double eps)
56 {
58  if (!points || points->empty())
59  {
60  DBUG(
61  "GEOObjects::addPointVec(): Failed to create PointVec, because "
62  "there aren't any points in the given vector.");
63  return;
64  }
65  _pnt_vecs.push_back(new PointVec(name, std::move(points),
66  std::move(pnt_id_name_map),
68  _callbacks->addPointVec(name);
69 }
70 
71 const std::vector<Point*>* GEOObjects::getPointVec(
72  const std::string& name) const
73 {
74  std::size_t const idx = this->exists(name);
75  if (idx != std::numeric_limits<std::size_t>::max())
76  {
77  return _pnt_vecs[idx]->getVector();
78  }
79 
80  DBUG("GEOObjects::getPointVec() - No entry found with name '{:s}'.", name);
81  return nullptr;
82 }
83 
84 const PointVec* GEOObjects::getPointVecObj(const std::string& name) const
85 {
86  std::size_t const idx = this->exists(name);
87  if (idx != std::numeric_limits<std::size_t>::max())
88  {
89  return _pnt_vecs[idx];
90  }
91 
92  DBUG("GEOObjects::getPointVecObj() - No entry found with name '{:s}'.",
93  name);
94  return nullptr;
95 }
96 
97 bool GEOObjects::removePointVec(std::string const& name)
98 {
99  if (isPntVecUsed(name))
100  {
101  DBUG(
102  "GEOObjects::removePointVec() - There are still Polylines or "
103  "Surfaces depending on these points.");
104  return false;
105  }
106 
107  for (auto it(_pnt_vecs.begin()); it != _pnt_vecs.end(); ++it)
108  {
109  if ((*it)->getName() == name)
110  {
111  _callbacks->removePointVec(name);
112  delete *it;
113  _pnt_vecs.erase(it);
114  return true;
115  }
116  }
117  DBUG("GEOObjects::removePointVec() - No entry found with name '{:s}'.",
118  name);
119  return false;
120 }
121 
122 void GEOObjects::addStationVec(std::unique_ptr<std::vector<Point*>> stations,
123  std::string& name)
124 {
126  _pnt_vecs.push_back(new PointVec(name, std::move(stations), nullptr,
128  _callbacks->addStationVec(name);
129 }
130 
131 const std::vector<GeoLib::Point*>* GEOObjects::getStationVec(
132  const std::string& name) const
133 {
134  auto const it =
135  std::find_if(begin(_pnt_vecs), end(_pnt_vecs),
136  [&name](PointVec const* const p)
137  {
138  return p->getName() == name &&
139  p->getType() == PointVec::PointType::STATION;
140  });
141  if (it != end(_pnt_vecs))
142  {
143  return (*it)->getVector();
144  }
145  DBUG("GEOObjects::getStationVec() - No entry found with name '{:s}'.",
146  name);
147  return nullptr;
148 }
149 
151  std::unique_ptr<std::vector<Polyline*>> lines,
152  const std::string& name,
153  std::unique_ptr<std::map<std::string, std::size_t>>
154  ply_names)
155 {
156  assert(lines);
157  auto lines_end = std::remove_if(
158  lines->begin(), lines->end(),
159  [](auto const* polyline) { return polyline->getNumberOfPoints() < 2; });
160  lines->erase(lines_end, lines->end());
161 
162  if (lines->empty())
163  {
164  return;
165  }
166 
167  _ply_vecs.push_back(
168  new PolylineVec(name, std::move(lines), std::move(ply_names)));
169  _callbacks->addPolylineVec(name);
170 }
171 
172 bool GEOObjects::appendPolylineVec(const std::vector<Polyline*>& polylines,
173  const std::string& name)
174 {
175  // find an already existing PolylineVec object the given polylines will be
176  // appended to
177  auto polyline_vec_it =
178  std::find_if(_ply_vecs.begin(), _ply_vecs.end(),
179  [&name](auto* const polyline_vec)
180  { return polyline_vec->getName() == name; });
181  if (polyline_vec_it == _ply_vecs.end())
182  {
183  return false;
184  }
185  for (auto* polyline : polylines)
186  {
187  (*polyline_vec_it)->push_back(polyline);
188  }
189  _callbacks->appendPolylineVec(name);
190  return true;
191 }
192 
193 const std::vector<Polyline*>* GEOObjects::getPolylineVec(
194  const std::string& name) const
195 {
196  std::size_t size(_ply_vecs.size());
197  for (std::size_t i = 0; i < size; i++)
198  {
199  if (_ply_vecs[i]->getName() == name)
200  {
201  return _ply_vecs[i]->getVector();
202  }
203  }
204 
205  DBUG("GEOObjects::getPolylineVec() - No entry found with name '{:s}'.",
206  name);
207  return nullptr;
208 }
209 
210 const PolylineVec* GEOObjects::getPolylineVecObj(const std::string& name) const
211 {
212  std::size_t size(_ply_vecs.size());
213  for (std::size_t i = 0; i < size; i++)
214  {
215  if (_ply_vecs[i]->getName() == name)
216  {
217  return _ply_vecs[i];
218  }
219  }
220 
221  DBUG("GEOObjects::getPolylineVecObj() - No entry found with name '{:s}'.",
222  name);
223  return nullptr;
224 }
225 
226 bool GEOObjects::removePolylineVec(std::string const& name)
227 {
228  _callbacks->removePolylineVec(name);
229  for (auto it = _ply_vecs.begin(); it != _ply_vecs.end(); ++it)
230  {
231  if ((*it)->getName() == name)
232  {
233  delete *it;
234  _ply_vecs.erase(it);
235  return true;
236  }
237  }
238 
239  DBUG("GEOObjects::removePolylineVec() - No entry found with name '{:s}'.",
240  name);
241  return false;
242 }
243 
245  std::unique_ptr<std::vector<Surface*>> sfc,
246  const std::string& name,
247  std::unique_ptr<std::map<std::string, std::size_t>>
248  sfc_names)
249 {
250  _sfc_vecs.push_back(
251  new SurfaceVec(name, std::move(sfc), std::move(sfc_names)));
252  _callbacks->addSurfaceVec(name);
253 }
254 
255 bool GEOObjects::appendSurfaceVec(const std::vector<Surface*>& surfaces,
256  const std::string& name)
257 {
258  // search vector
259  std::size_t idx(0);
260  bool nfound(true);
261  for (idx = 0; idx < _sfc_vecs.size() && nfound; idx++)
262  {
263  if (_sfc_vecs[idx]->getName() == name)
264  {
265  nfound = false;
266  }
267  }
268 
269  if (!nfound)
270  {
271  idx--;
272  std::size_t n_sfcs(surfaces.size());
273  // append surfaces
274  for (std::size_t k(0); k < n_sfcs; k++)
275  {
276  _sfc_vecs[idx]->push_back(surfaces[k]);
277  }
278  _callbacks->appendSurfaceVec(name);
279  return true;
280  }
281 
282  // the copy is needed because addSurfaceVec is passing it to SurfaceVec
283  // ctor, which needs write access to the surface vector.
284  auto sfc = std::make_unique<std::vector<GeoLib::Surface*>>(begin(surfaces),
285  end(surfaces));
286  addSurfaceVec(std::move(sfc), name);
287  return false;
288 }
289 
290 const std::vector<Surface*>* GEOObjects::getSurfaceVec(
291  const std::string& name) const
292 {
293  std::size_t size(_sfc_vecs.size());
294  for (std::size_t i = 0; i < size; i++)
295  {
296  if (_sfc_vecs[i]->getName() == name)
297  {
298  return _sfc_vecs[i]->getVector();
299  }
300  }
301  DBUG("GEOObjects::getSurfaceVec() - No entry found with name '{:s}'.",
302  name);
303  return nullptr;
304 }
305 
306 bool GEOObjects::removeSurfaceVec(const std::string& name)
307 {
308  _callbacks->removeSurfaceVec(name);
309  for (auto it(_sfc_vecs.begin()); it != _sfc_vecs.end(); ++it)
310  {
311  if ((*it)->getName() == name)
312  {
313  delete *it;
314  _sfc_vecs.erase(it);
315  return true;
316  }
317  }
318 
319  DBUG("GEOObjects::removeSurfaceVec() - No entry found with name '{:s}'.",
320  name);
321  return false;
322 }
323 
324 const SurfaceVec* GEOObjects::getSurfaceVecObj(const std::string& name) const
325 {
326  std::size_t size(_sfc_vecs.size());
327  for (std::size_t i = 0; i < size; i++)
328  {
329  if (_sfc_vecs[i]->getName() == name)
330  {
331  return _sfc_vecs[i];
332  }
333  }
334  DBUG("GEOObjects::getSurfaceVecObj() - No entry found with name '{:s}'.",
335  name);
336  return nullptr;
337 }
338 
339 bool GEOObjects::isUniquePointVecName(std::string& name) const
340 {
341  std::vector<std::string> const existing_names = getGeometryNames();
342  auto const& unique_name = BaseLib::getUniqueName(existing_names, name);
343 
344  if (unique_name != name)
345  {
346  name = unique_name;
347  return false;
348  }
349  return true;
350 }
351 
352 bool GEOObjects::isPntVecUsed(const std::string& name) const
353 {
354  // search dependent data structures (Polyline)
355  for (auto polyline : _ply_vecs)
356  {
357  if (polyline->getName() == name)
358  {
359  return true;
360  }
361  }
362  for (auto surface : _sfc_vecs)
363  {
364  if (surface->getName() == name)
365  {
366  return true;
367  }
368  }
369 
370  return false;
371 }
372 
373 void GEOObjects::getStationVectorNames(std::vector<std::string>& names) const
374 {
375  for (auto point : _pnt_vecs)
376  {
377  if (point->getType() == PointVec::PointType::STATION)
378  {
379  names.push_back(point->getName());
380  }
381  }
382 }
383 
384 std::vector<std::string> GEOObjects::getGeometryNames() const
385 {
386  std::vector<std::string> names;
387  for (auto point : _pnt_vecs)
388  {
389  if (point->getType() == PointVec::PointType::POINT)
390  {
391  names.push_back(point->getName());
392  }
393  }
394  return names;
395 }
396 
397 std::string GEOObjects::getElementNameByID(const std::string& geometry_name,
398  GeoLib::GEOTYPE type,
399  std::size_t id) const
400 {
401  std::string name;
402  switch (type)
403  {
405  this->getPointVecObj(geometry_name)->getNameOfElementByID(id, name);
406  break;
408  this->getPolylineVecObj(geometry_name)
409  ->getNameOfElementByID(id, name);
410  break;
412  this->getSurfaceVecObj(geometry_name)
413  ->getNameOfElementByID(id, name);
414  }
415  return name;
416 }
417 
418 int GEOObjects::mergeGeometries(std::vector<std::string> const& geo_names,
419  std::string& merged_geo_name)
420 {
421  const std::size_t n_geo_names(geo_names.size());
422 
423  if (n_geo_names < 2)
424  {
425  return 2;
426  }
427 
428  std::vector<std::size_t> pnt_offsets(n_geo_names, 0);
429 
430  if (!mergePoints(geo_names, merged_geo_name, pnt_offsets))
431  {
432  return 1;
433  }
434 
435  mergePolylines(geo_names, merged_geo_name, pnt_offsets);
436 
437  mergeSurfaces(geo_names, merged_geo_name, pnt_offsets);
438 
439  return 0;
440 }
441 
442 bool GEOObjects::mergePoints(std::vector<std::string> const& geo_names,
443  std::string& merged_geo_name,
444  std::vector<std::size_t>& pnt_offsets)
445 {
446  const std::size_t n_geo_names(geo_names.size());
447 
448  auto merged_points = std::make_unique<std::vector<GeoLib::Point*>>();
449  auto merged_pnt_names =
450  std::make_unique<std::map<std::string, std::size_t>>();
451 
452  for (std::size_t j(0); j < n_geo_names; ++j)
453  {
454  GeoLib::PointVec const* const pnt_vec(
455  this->getPointVecObj(geo_names[j]));
456  if (pnt_vec == nullptr)
457  {
458  continue;
459  }
460  const std::vector<GeoLib::Point*>* pnts(pnt_vec->getVector());
461  if (pnts == nullptr)
462  {
463  return false;
464  }
465 
466  // do not consider stations
467  if (dynamic_cast<GeoLib::Station*>((*pnts)[0]))
468  {
469  continue;
470  }
471 
472  std::size_t const n_pnts(pnts->size());
473  for (std::size_t k(0); k < n_pnts; ++k)
474  {
475  merged_points->push_back(
476  new GeoLib::Point(*(*pnts)[k], pnt_offsets[j] + k));
477  std::string const& item_name(pnt_vec->getItemNameByID(k));
478  if (!item_name.empty())
479  {
480  merged_pnt_names->insert(
481  std::make_pair(item_name, pnt_offsets[j] + k));
482  }
483  }
484  if (n_geo_names - 1 > j)
485  {
486  pnt_offsets[j + 1] = n_pnts + pnt_offsets[j];
487  }
488  }
489 
490  addPointVec(std::move(merged_points), merged_geo_name,
491  std::move(merged_pnt_names), 1e-6);
492  return true;
493 }
494 
495 void GEOObjects::mergePolylines(std::vector<std::string> const& geo_names,
496  std::string const& merged_geo_name,
497  std::vector<std::size_t> const& pnt_offsets)
498 {
499  const std::size_t n_geo_names(geo_names.size());
500  std::vector<std::size_t> ply_offsets(n_geo_names, 0);
501 
502  auto merged_polylines = std::make_unique<std::vector<GeoLib::Polyline*>>();
503  auto merged_ply_names =
504  std::make_unique<std::map<std::string, std::size_t>>();
505 
506  std::vector<GeoLib::Point*> const* merged_points(
507  this->getPointVecObj(merged_geo_name)->getVector());
508  std::vector<std::size_t> const& id_map(
509  this->getPointVecObj(merged_geo_name)->getIDMap());
510 
511  for (std::size_t j(0); j < n_geo_names; j++)
512  {
513  const std::vector<GeoLib::Polyline*>* plys(
514  this->getPolylineVec(geo_names[j]));
515  if (plys)
516  {
517  std::string tmp_name;
518  for (std::size_t k(0); k < plys->size(); k++)
519  {
520  auto* kth_ply_new(new GeoLib::Polyline(*merged_points));
521  GeoLib::Polyline const* const kth_ply_old((*plys)[k]);
522  const std::size_t size_of_kth_ply(
523  kth_ply_old->getNumberOfPoints());
524  // copy point ids from old ply to new ply (considering the
525  // offset)
526  for (std::size_t i(0); i < size_of_kth_ply; i++)
527  {
528  kth_ply_new->addPoint(
529  id_map[pnt_offsets[j] + kth_ply_old->getPointID(i)]);
530  }
531  merged_polylines->push_back(kth_ply_new);
532  if (this->getPolylineVecObj(geo_names[j])
533  ->getNameOfElementByID(k, tmp_name))
534  {
535  merged_ply_names->insert(
536  std::pair<std::string, std::size_t>(
537  tmp_name, ply_offsets[j] + k));
538  }
539  }
540  if (n_geo_names - 1 > j)
541  {
542  ply_offsets[j + 1] = plys->size() + ply_offsets[j];
543  }
544  }
545  }
546 
547  if (!merged_polylines->empty())
548  {
549  this->addPolylineVec(std::move(merged_polylines), merged_geo_name,
550  std::move(merged_ply_names));
551  }
552 }
553 
554 void GEOObjects::mergeSurfaces(std::vector<std::string> const& geo_names,
555  std::string const& merged_geo_name,
556  std::vector<std::size_t> const& pnt_offsets)
557 {
558  std::vector<GeoLib::Point*> const* merged_points(
559  this->getPointVecObj(merged_geo_name)->getVector());
560  std::vector<std::size_t> const& id_map(
561  this->getPointVecObj(merged_geo_name)->getIDMap());
562 
563  const std::size_t n_geo_names(geo_names.size());
564  std::vector<std::size_t> sfc_offsets(n_geo_names, 0);
565  auto merged_sfcs = std::make_unique<std::vector<GeoLib::Surface*>>();
566  auto merged_sfc_names =
567  std::make_unique<std::map<std::string, std::size_t>>();
568  for (std::size_t j(0); j < n_geo_names; j++)
569  {
570  const std::vector<GeoLib::Surface*>* sfcs(
571  this->getSurfaceVec(geo_names[j]));
572  if (sfcs)
573  {
574  std::string tmp_name;
575  for (std::size_t k(0); k < sfcs->size(); k++)
576  {
577  auto* kth_sfc_new(new GeoLib::Surface(*merged_points));
578  GeoLib::Surface const* const kth_sfc_old((*sfcs)[k]);
579  const std::size_t size_of_kth_sfc(
580  kth_sfc_old->getNumberOfTriangles());
581  // clone surface elements using new ids
582  for (std::size_t i(0); i < size_of_kth_sfc; i++)
583  {
584  const GeoLib::Triangle* tri((*kth_sfc_old)[i]);
585  const std::size_t id0(id_map[pnt_offsets[j] + (*tri)[0]]);
586  const std::size_t id1(id_map[pnt_offsets[j] + (*tri)[1]]);
587  const std::size_t id2(id_map[pnt_offsets[j] + (*tri)[2]]);
588  kth_sfc_new->addTriangle(id0, id1, id2);
589  }
590  merged_sfcs->push_back(kth_sfc_new);
591 
592  if (this->getSurfaceVecObj(geo_names[j])
593  ->getNameOfElementByID(k, tmp_name))
594  {
595  merged_sfc_names->insert(
596  std::pair<std::string, std::size_t>(
597  tmp_name, sfc_offsets[j] + k));
598  }
599  }
600  if (n_geo_names - 1 > j)
601  {
602  sfc_offsets[j + 1] = sfcs->size() + sfc_offsets[j];
603  }
604  }
605  }
606  if (!merged_sfcs->empty())
607  {
608  this->addSurfaceVec(std::move(merged_sfcs), merged_geo_name,
609  std::move(merged_sfc_names));
610  }
611 }
612 
613 void GEOObjects::renameGeometry(std::string const& old_name,
614  std::string const& new_name)
615 {
616  _callbacks->renameGeometry(old_name, new_name);
617  for (auto* pnt_vec : _pnt_vecs)
618  {
619  if (pnt_vec->getName() == old_name)
620  {
621  pnt_vec->setName(new_name);
622  break;
623  }
624  }
625  for (auto* ply_vec : _ply_vecs)
626  {
627  if (ply_vec->getName() == old_name)
628  {
629  ply_vec->setName(new_name);
630  break;
631  }
632  }
633  for (auto* sfc_vec : _sfc_vecs)
634  {
635  if (sfc_vec->getName() == old_name)
636  {
637  sfc_vec->setName(new_name);
638  break;
639  }
640  }
641 }
642 
643 void markUnusedPoints(GEOObjects const& geo_objects,
644  std::string const& geo_name,
645  std::vector<bool>& transfer_pnts)
646 {
647  GeoLib::PolylineVec const* const ply_obj(
648  geo_objects.getPolylineVecObj(geo_name));
649  if (ply_obj)
650  {
651  std::vector<GeoLib::Polyline*> const& lines(*ply_obj->getVector());
652  for (auto* line : lines)
653  {
654  std::size_t const n_pnts(line->getNumberOfPoints());
655  for (std::size_t i = 0; i < n_pnts; ++i)
656  {
657  transfer_pnts[line->getPointID(i)] = false;
658  }
659  }
660  }
661 
662  GeoLib::SurfaceVec const* const sfc_obj(
663  geo_objects.getSurfaceVecObj(geo_name));
664  if (sfc_obj)
665  {
666  std::vector<GeoLib::Surface*> const& surfaces = *sfc_obj->getVector();
667  for (auto* sfc : surfaces)
668  {
669  std::size_t const n_tri(sfc->getNumberOfTriangles());
670  for (std::size_t i = 0; i < n_tri; ++i)
671  {
672  GeoLib::Triangle const& t = *(*sfc)[i];
673  transfer_pnts[t[0]] = false;
674  transfer_pnts[t[1]] = false;
675  transfer_pnts[t[2]] = false;
676  }
677  }
678  }
679 }
680 
681 int geoPointsToStations(GEOObjects& geo_objects, std::string const& geo_name,
682  std::string& stn_name, bool const only_unused_pnts)
683 {
684  GeoLib::PointVec const* const pnt_obj(geo_objects.getPointVecObj(geo_name));
685  if (pnt_obj == nullptr)
686  {
687  ERR("Point vector {:s} not found.", geo_name);
688  return -1;
689  }
690  std::vector<GeoLib::Point*> const& pnts = *pnt_obj->getVector();
691  if (pnts.empty())
692  {
693  ERR("Point vector {:s} is empty.", geo_name);
694  return -1;
695  }
696  std::size_t const n_pnts(pnts.size());
697  std::vector<bool> transfer_pnts(n_pnts, true);
698  if (only_unused_pnts)
699  {
700  markUnusedPoints(geo_objects, geo_name, transfer_pnts);
701  }
702 
703  auto stations = std::make_unique<std::vector<GeoLib::Point*>>();
704  for (std::size_t i = 0; i < n_pnts; ++i)
705  {
706  if (!transfer_pnts[i])
707  {
708  continue;
709  }
710  std::string name = pnt_obj->getItemNameByID(i);
711  if (name.empty())
712  {
713  name = "Station " + std::to_string(i);
714  }
715  stations->push_back(new GeoLib::Station(pnts[i], name));
716  }
717  if (!stations->empty())
718  {
719  geo_objects.addStationVec(std::move(stations), stn_name);
720  }
721  else
722  {
723  WARN("No points found to convert.");
724  return 1;
725  }
726  return 0;
727 }
728 
730  const std::string& geo_name,
731  GeoLib::GEOTYPE type,
732  const std::string& geo_obj_name) const
733 {
734  GeoLib::GeoObject* geo_obj(nullptr);
735  switch (type)
736  {
738  {
739  GeoLib::PointVec const* pnt_vec(getPointVecObj(geo_name));
740  if (pnt_vec)
741  {
742  geo_obj = const_cast<GeoLib::GeoObject*>(
743  dynamic_cast<GeoLib::GeoObject const*>(
744  pnt_vec->getElementByName(geo_obj_name)));
745  }
746  break;
747  }
749  {
750  GeoLib::PolylineVec const* ply_vec(getPolylineVecObj(geo_name));
751  if (ply_vec)
752  {
753  geo_obj = const_cast<GeoLib::GeoObject*>(
754  dynamic_cast<GeoLib::GeoObject const*>(
755  ply_vec->getElementByName(geo_obj_name)));
756  }
757  break;
758  }
760  {
761  GeoLib::SurfaceVec const* sfc_vec(getSurfaceVecObj(geo_name));
762  if (sfc_vec)
763  {
764  geo_obj = const_cast<GeoLib::GeoObject*>(
765  dynamic_cast<GeoLib::GeoObject const*>(
766  sfc_vec->getElementByName(geo_obj_name)));
767  }
768  break;
769  }
770  default:
771  ERR("GEOObjects::getGeoObject(): geometric type not handled.");
772  return nullptr;
773  };
774 
775  if (!geo_obj)
776  {
777  DBUG(
778  "GEOObjects::getGeoObject(): Could not find {:s} '{:s}' in "
779  "geometry.",
781  geo_obj_name);
782  }
783  return geo_obj;
784 }
785 
787  const std::string& geo_name, const std::string& geo_obj_name) const
788 {
789  GeoLib::GeoObject const* geo_obj(
790  getGeoObject(geo_name, GeoLib::GEOTYPE::POINT, geo_obj_name));
791 
792  if (!geo_obj)
793  {
794  geo_obj =
795  getGeoObject(geo_name, GeoLib::GEOTYPE::POLYLINE, geo_obj_name);
796  }
797 
798  if (!geo_obj)
799  {
800  geo_obj =
801  getGeoObject(geo_name, GeoLib::GEOTYPE::SURFACE, geo_obj_name);
802  }
803 
804  if (!geo_obj)
805  {
806  DBUG(
807  "GEOObjects::getGeoObject(): Could not find '{:s}' in geometry "
808  "{:s}.",
809  geo_obj_name, geo_name);
810  }
811  return geo_obj;
812 }
813 
814 std::size_t GEOObjects::exists(const std::string& geometry_name) const
815 {
816  std::size_t const size(_pnt_vecs.size());
817  for (std::size_t i = 0; i < size; i++)
818  {
819  if (_pnt_vecs[i]->getName() == geometry_name)
820  {
821  return i;
822  }
823  }
824 
825  // HACK for enabling conversion of files without loading the associated
826  // geometry
827  if (size > 0 && _pnt_vecs[0]->getName() == "conversionTestRun#1")
828  {
829  return 1;
830  }
831 
832  return std::numeric_limits<std::size_t>::max();
833 }
834 
835 } // namespace GeoLib
Definition of the GEOObjects class.
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:37
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
void mergeSurfaces(std::vector< std::string > const &geo_names, std::string const &merged_geo_name, std::vector< std::size_t > const &pnt_offsets)
Definition: GEOObjects.cpp:554
std::size_t exists(const std::string &geometry_name) const
Definition: GEOObjects.cpp:814
void mergePolylines(std::vector< std::string > const &geo_names, std::string const &merged_geo_name, std::vector< std::size_t > const &pnt_offsets)
Definition: GEOObjects.cpp:495
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
Definition: GEOObjects.cpp:384
bool appendSurfaceVec(const std::vector< Surface * > &surfaces, const std::string &name)
Definition: GEOObjects.cpp:255
void addStationVec(std::unique_ptr< std::vector< Point * >> stations, std::string &name)
Adds a vector of stations with the given name and colour to GEOObjects.
Definition: GEOObjects.cpp:122
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:244
const std::vector< Point * > * getPointVec(const std::string &name) const
Definition: GEOObjects.cpp:71
const PointVec * getPointVecObj(const std::string &name) const
Definition: GEOObjects.cpp:84
void renameGeometry(std::string const &old_name, std::string const &new_name)
Definition: GEOObjects.cpp:613
bool mergePoints(std::vector< std::string > const &geo_names, std::string &merged_geo_name, std::vector< std::size_t > &pnt_offsets)
Definition: GEOObjects.cpp:442
bool removePointVec(const std::string &name)
Definition: GEOObjects.cpp:97
bool isUniquePointVecName(std::string &name) const
Definition: GEOObjects.cpp:339
bool removeSurfaceVec(const std::string &name)
Definition: GEOObjects.cpp:306
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
const std::vector< Surface * > * getSurfaceVec(const std::string &name) const
Returns the surface vector with the given name as a const.
Definition: GEOObjects.cpp:290
std::vector< PointVec * > _pnt_vecs
Definition: GEOObjects.h:295
std::vector< PolylineVec * > _ply_vecs
Definition: GEOObjects.h:298
std::unique_ptr< Callbacks > _callbacks
Definition: GEOObjects.h:302
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
Definition: GEOObjects.h:205
bool isPntVecUsed(const std::string &name) const
Checks if the point vector with the given name is referenced in a polyline- or surface vector.
Definition: GEOObjects.cpp:352
const PolylineVec * getPolylineVecObj(const std::string &name) const
Definition: GEOObjects.cpp:210
int mergeGeometries(std::vector< std::string > const &geo_names, std::string &merged_geo_name)
Definition: GEOObjects.cpp:418
void getStationVectorNames(std::vector< std::string > &names) const
Returns the names of all station vectors.
Definition: GEOObjects.cpp:373
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
Definition: GEOObjects.cpp:193
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
bool appendPolylineVec(const std::vector< Polyline * > &polylines, const std::string &name)
Definition: GEOObjects.cpp:172
std::vector< SurfaceVec * > _sfc_vecs
Definition: GEOObjects.h:300
const GeoLib::GeoObject * getGeoObject(const std::string &geo_name, GeoLib::GEOTYPE type, const std::string &geo_obj_name) const
Returns the geo object for a geometric item of the given name and type for the associated geometry.
Definition: GEOObjects.cpp:729
const std::vector< GeoLib::Point * > * getStationVec(const std::string &name) const
Returns the station vector with the given name.
Definition: GEOObjects.cpp:131
bool removePolylineVec(const std::string &name)
Definition: GEOObjects.cpp:226
std::string getElementNameByID(const std::string &geometry_name, GeoLib::GEOTYPE type, std::size_t id) const
Definition: GEOObjects.cpp:397
This class manages pointers to Points in a std::vector along with a name. It also handles the deletio...
Definition: PointVec.h:38
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
std::size_t getPointID(std::size_t i) const
Definition: Polyline.cpp:159
std::size_t getNumberOfPoints() const
Definition: Polyline.cpp:108
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
std::size_t getNumberOfTriangles() const
Definition: Surface.cpp:82
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
bool getNameOfElementByID(std::size_t id, std::string &element_name) const
Definition: TemplateVec.h:153
const T * getElementByName(const std::string &name) const
Returns an element with the given name.
Definition: TemplateVec.h:132
Class Triangle consists of a reference to a point vector and a vector that stores the indices in the ...
Definition: Triangle.h:26
GEOTYPE
Definition: GeoType.h:25
TemplateVec< GeoLib::Polyline > PolylineVec
class PolylineVec encapsulate a std::vector of Polylines additional one can give the vector of polyli...
Definition: PolylineVec.h:29
std::string getUniqueName(std::vector< std::string > const &existing_names, std::string const &input_name)
Append '-' and a number such that the name is unique.
std::string convertGeoTypeToString(GEOTYPE geo_type)
Definition: GeoType.cpp:23
int geoPointsToStations(GEOObjects &geo_objects, std::string const &geo_name, std::string &stn_name, bool const only_unused_pnts)
Constructs a station-vector based on the points of a given geometry.
Definition: GEOObjects.cpp:681
void markUnusedPoints(GEOObjects const &geo_objects, std::string const &geo_name, std::vector< bool > &transfer_pnts)
Definition: GEOObjects.cpp:643
TemplateVec< GeoLib::Surface > SurfaceVec
Definition: SurfaceVec.h:27
static const double t