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  for (auto it(lines->begin()); it != lines->end();)
158  {
159  if ((*it)->getNumberOfPoints() < 2)
160  {
161  auto it_erase(it);
162  it = lines->erase(it_erase);
163  }
164  else
165  {
166  ++it;
167  }
168  }
169 
170  if (lines->empty())
171  {
172  return;
173  }
174 
175  _ply_vecs.push_back(
176  new PolylineVec(name, std::move(lines), std::move(ply_names)));
177  _callbacks->addPolylineVec(name);
178 }
179 
180 bool GEOObjects::appendPolylineVec(const std::vector<Polyline*>& polylines,
181  const std::string& name)
182 {
183  // search vector
184  std::size_t idx(0);
185  bool nfound(true);
186  for (idx = 0; idx < _ply_vecs.size() && nfound; idx++)
187  {
188  if (_ply_vecs[idx]->getName() == name)
189  {
190  nfound = false;
191  }
192  }
193 
194  if (!nfound)
195  {
196  idx--;
197  std::size_t n_plys(polylines.size());
198  // append lines
199  for (std::size_t k(0); k < n_plys; k++)
200  {
201  _ply_vecs[idx]->push_back(polylines[k]);
202  }
203  _callbacks->appendPolylineVec(name);
204  return true;
205  }
206 
207  return false;
208 }
209 
210 const std::vector<Polyline*>* GEOObjects::getPolylineVec(
211  const std::string& name) const
212 {
213  std::size_t size(_ply_vecs.size());
214  for (std::size_t i = 0; i < size; i++)
215  {
216  if (_ply_vecs[i]->getName() == name)
217  {
218  return _ply_vecs[i]->getVector();
219  }
220  }
221 
222  DBUG("GEOObjects::getPolylineVec() - No entry found with name '{:s}'.",
223  name);
224  return nullptr;
225 }
226 
227 const PolylineVec* GEOObjects::getPolylineVecObj(const std::string& name) const
228 {
229  std::size_t size(_ply_vecs.size());
230  for (std::size_t i = 0; i < size; i++)
231  {
232  if (_ply_vecs[i]->getName() == name)
233  {
234  return _ply_vecs[i];
235  }
236  }
237 
238  DBUG("GEOObjects::getPolylineVecObj() - No entry found with name '{:s}'.",
239  name);
240  return nullptr;
241 }
242 
243 bool GEOObjects::removePolylineVec(std::string const& name)
244 {
245  _callbacks->removePolylineVec(name);
246  for (auto it = _ply_vecs.begin(); it != _ply_vecs.end(); ++it)
247  {
248  if ((*it)->getName() == name)
249  {
250  delete *it;
251  _ply_vecs.erase(it);
252  return true;
253  }
254  }
255 
256  DBUG("GEOObjects::removePolylineVec() - No entry found with name '{:s}'.",
257  name);
258  return false;
259 }
260 
262  std::unique_ptr<std::vector<Surface*>> sfc,
263  const std::string& name,
264  std::unique_ptr<std::map<std::string, std::size_t>>
265  sfc_names)
266 {
267  _sfc_vecs.push_back(
268  new SurfaceVec(name, std::move(sfc), std::move(sfc_names)));
269  _callbacks->addSurfaceVec(name);
270 }
271 
272 bool GEOObjects::appendSurfaceVec(const std::vector<Surface*>& surfaces,
273  const std::string& name)
274 {
275  // search vector
276  std::size_t idx(0);
277  bool nfound(true);
278  for (idx = 0; idx < _sfc_vecs.size() && nfound; idx++)
279  {
280  if (_sfc_vecs[idx]->getName() == name)
281  {
282  nfound = false;
283  }
284  }
285 
286  if (!nfound)
287  {
288  idx--;
289  std::size_t n_sfcs(surfaces.size());
290  // append surfaces
291  for (std::size_t k(0); k < n_sfcs; k++)
292  {
293  _sfc_vecs[idx]->push_back(surfaces[k]);
294  }
295  _callbacks->appendSurfaceVec(name);
296  return true;
297  }
298 
299  // the copy is needed because addSurfaceVec is passing it to SurfaceVec
300  // ctor, which needs write access to the surface vector.
301  auto sfc = std::make_unique<std::vector<GeoLib::Surface*>>(begin(surfaces),
302  end(surfaces));
303  addSurfaceVec(std::move(sfc), name);
304  return false;
305 }
306 
307 const std::vector<Surface*>* GEOObjects::getSurfaceVec(
308  const std::string& name) const
309 {
310  std::size_t size(_sfc_vecs.size());
311  for (std::size_t i = 0; i < size; i++)
312  {
313  if (_sfc_vecs[i]->getName() == name)
314  {
315  return _sfc_vecs[i]->getVector();
316  }
317  }
318  DBUG("GEOObjects::getSurfaceVec() - No entry found with name '{:s}'.",
319  name);
320  return nullptr;
321 }
322 
323 bool GEOObjects::removeSurfaceVec(const std::string& name)
324 {
325  _callbacks->removeSurfaceVec(name);
326  for (auto it(_sfc_vecs.begin()); it != _sfc_vecs.end(); ++it)
327  {
328  if ((*it)->getName() == name)
329  {
330  delete *it;
331  _sfc_vecs.erase(it);
332  return true;
333  }
334  }
335 
336  DBUG("GEOObjects::removeSurfaceVec() - No entry found with name '{:s}'.",
337  name);
338  return false;
339 }
340 
341 const SurfaceVec* GEOObjects::getSurfaceVecObj(const std::string& name) const
342 {
343  std::size_t size(_sfc_vecs.size());
344  for (std::size_t i = 0; i < size; i++)
345  {
346  if (_sfc_vecs[i]->getName() == name)
347  {
348  return _sfc_vecs[i];
349  }
350  }
351  DBUG("GEOObjects::getSurfaceVecObj() - No entry found with name '{:s}'.",
352  name);
353  return nullptr;
354 }
355 
356 bool GEOObjects::isUniquePointVecName(std::string& name) const
357 {
358  std::vector<std::string> const existing_names = getGeometryNames();
359  auto const& unique_name = BaseLib::getUniqueName(existing_names, name);
360 
361  if (unique_name != name)
362  {
363  name = unique_name;
364  return false;
365  }
366  return true;
367 }
368 
369 bool GEOObjects::isPntVecUsed(const std::string& name) const
370 {
371  // search dependent data structures (Polyline)
372  for (auto polyline : _ply_vecs)
373  {
374  if (polyline->getName() == name)
375  {
376  return true;
377  }
378  }
379  for (auto surface : _sfc_vecs)
380  {
381  if (surface->getName() == name)
382  {
383  return true;
384  }
385  }
386 
387  return false;
388 }
389 
390 void GEOObjects::getStationVectorNames(std::vector<std::string>& names) const
391 {
392  for (auto point : _pnt_vecs)
393  {
394  if (point->getType() == PointVec::PointType::STATION)
395  {
396  names.push_back(point->getName());
397  }
398  }
399 }
400 
401 std::vector<std::string> GEOObjects::getGeometryNames() const
402 {
403  std::vector<std::string> names;
404  for (auto point : _pnt_vecs)
405  {
406  if (point->getType() == PointVec::PointType::POINT)
407  {
408  names.push_back(point->getName());
409  }
410  }
411  return names;
412 }
413 
414 std::string GEOObjects::getElementNameByID(const std::string& geometry_name,
415  GeoLib::GEOTYPE type,
416  std::size_t id) const
417 {
418  std::string name;
419  switch (type)
420  {
422  this->getPointVecObj(geometry_name)->getNameOfElementByID(id, name);
423  break;
425  this->getPolylineVecObj(geometry_name)
426  ->getNameOfElementByID(id, name);
427  break;
429  this->getSurfaceVecObj(geometry_name)
430  ->getNameOfElementByID(id, name);
431  }
432  return name;
433 }
434 
435 int GEOObjects::mergeGeometries(std::vector<std::string> const& geo_names,
436  std::string& merged_geo_name)
437 {
438  const std::size_t n_geo_names(geo_names.size());
439 
440  if (n_geo_names < 2)
441  {
442  return 2;
443  }
444 
445  std::vector<std::size_t> pnt_offsets(n_geo_names, 0);
446 
447  if (!mergePoints(geo_names, merged_geo_name, pnt_offsets))
448  {
449  return 1;
450  }
451 
452  mergePolylines(geo_names, merged_geo_name, pnt_offsets);
453 
454  mergeSurfaces(geo_names, merged_geo_name, pnt_offsets);
455 
456  return 0;
457 }
458 
459 bool GEOObjects::mergePoints(std::vector<std::string> const& geo_names,
460  std::string& merged_geo_name,
461  std::vector<std::size_t>& pnt_offsets)
462 {
463  const std::size_t n_geo_names(geo_names.size());
464 
465  auto merged_points = std::make_unique<std::vector<GeoLib::Point*>>();
466  auto merged_pnt_names =
467  std::make_unique<std::map<std::string, std::size_t>>();
468 
469  for (std::size_t j(0); j < n_geo_names; ++j)
470  {
471  GeoLib::PointVec const* const pnt_vec(
472  this->getPointVecObj(geo_names[j]));
473  if (pnt_vec == nullptr)
474  {
475  continue;
476  }
477  const std::vector<GeoLib::Point*>* pnts(pnt_vec->getVector());
478  if (pnts == nullptr)
479  {
480  return false;
481  }
482 
483  // do not consider stations
484  if (dynamic_cast<GeoLib::Station*>((*pnts)[0]))
485  {
486  continue;
487  }
488 
489  std::size_t const n_pnts(pnts->size());
490  for (std::size_t k(0); k < n_pnts; ++k)
491  {
492  merged_points->push_back(
493  new GeoLib::Point(*(*pnts)[k], pnt_offsets[j] + k));
494  std::string const& item_name(pnt_vec->getItemNameByID(k));
495  if (!item_name.empty())
496  {
497  merged_pnt_names->insert(
498  std::make_pair(item_name, pnt_offsets[j] + k));
499  }
500  }
501  if (n_geo_names - 1 > j)
502  {
503  pnt_offsets[j + 1] = n_pnts + pnt_offsets[j];
504  }
505  }
506 
507  addPointVec(std::move(merged_points), merged_geo_name,
508  std::move(merged_pnt_names), 1e-6);
509  return true;
510 }
511 
512 void GEOObjects::mergePolylines(std::vector<std::string> const& geo_names,
513  std::string const& merged_geo_name,
514  std::vector<std::size_t> const& pnt_offsets)
515 {
516  const std::size_t n_geo_names(geo_names.size());
517  std::vector<std::size_t> ply_offsets(n_geo_names, 0);
518 
519  auto merged_polylines = std::make_unique<std::vector<GeoLib::Polyline*>>();
520  auto merged_ply_names =
521  std::make_unique<std::map<std::string, std::size_t>>();
522 
523  std::vector<GeoLib::Point*> const* merged_points(
524  this->getPointVecObj(merged_geo_name)->getVector());
525  std::vector<std::size_t> const& id_map(
526  this->getPointVecObj(merged_geo_name)->getIDMap());
527 
528  for (std::size_t j(0); j < n_geo_names; j++)
529  {
530  const std::vector<GeoLib::Polyline*>* plys(
531  this->getPolylineVec(geo_names[j]));
532  if (plys)
533  {
534  std::string tmp_name;
535  for (std::size_t k(0); k < plys->size(); k++)
536  {
537  auto* kth_ply_new(new GeoLib::Polyline(*merged_points));
538  GeoLib::Polyline const* const kth_ply_old((*plys)[k]);
539  const std::size_t size_of_kth_ply(
540  kth_ply_old->getNumberOfPoints());
541  // copy point ids from old ply to new ply (considering the
542  // offset)
543  for (std::size_t i(0); i < size_of_kth_ply; i++)
544  {
545  kth_ply_new->addPoint(
546  id_map[pnt_offsets[j] + kth_ply_old->getPointID(i)]);
547  }
548  merged_polylines->push_back(kth_ply_new);
549  if (this->getPolylineVecObj(geo_names[j])
550  ->getNameOfElementByID(k, tmp_name))
551  {
552  merged_ply_names->insert(
553  std::pair<std::string, std::size_t>(
554  tmp_name, ply_offsets[j] + k));
555  }
556  }
557  if (n_geo_names - 1 > j)
558  {
559  ply_offsets[j + 1] = plys->size() + ply_offsets[j];
560  }
561  }
562  }
563 
564  if (!merged_polylines->empty())
565  {
566  this->addPolylineVec(std::move(merged_polylines), merged_geo_name,
567  std::move(merged_ply_names));
568  }
569 }
570 
571 void GEOObjects::mergeSurfaces(std::vector<std::string> const& geo_names,
572  std::string const& merged_geo_name,
573  std::vector<std::size_t> const& pnt_offsets)
574 {
575  std::vector<GeoLib::Point*> const* merged_points(
576  this->getPointVecObj(merged_geo_name)->getVector());
577  std::vector<std::size_t> const& id_map(
578  this->getPointVecObj(merged_geo_name)->getIDMap());
579 
580  const std::size_t n_geo_names(geo_names.size());
581  std::vector<std::size_t> sfc_offsets(n_geo_names, 0);
582  auto merged_sfcs = std::make_unique<std::vector<GeoLib::Surface*>>();
583  auto merged_sfc_names =
584  std::make_unique<std::map<std::string, std::size_t>>();
585  for (std::size_t j(0); j < n_geo_names; j++)
586  {
587  const std::vector<GeoLib::Surface*>* sfcs(
588  this->getSurfaceVec(geo_names[j]));
589  if (sfcs)
590  {
591  std::string tmp_name;
592  for (std::size_t k(0); k < sfcs->size(); k++)
593  {
594  auto* kth_sfc_new(new GeoLib::Surface(*merged_points));
595  GeoLib::Surface const* const kth_sfc_old((*sfcs)[k]);
596  const std::size_t size_of_kth_sfc(
597  kth_sfc_old->getNumberOfTriangles());
598  // clone surface elements using new ids
599  for (std::size_t i(0); i < size_of_kth_sfc; i++)
600  {
601  const GeoLib::Triangle* tri((*kth_sfc_old)[i]);
602  const std::size_t id0(id_map[pnt_offsets[j] + (*tri)[0]]);
603  const std::size_t id1(id_map[pnt_offsets[j] + (*tri)[1]]);
604  const std::size_t id2(id_map[pnt_offsets[j] + (*tri)[2]]);
605  kth_sfc_new->addTriangle(id0, id1, id2);
606  }
607  merged_sfcs->push_back(kth_sfc_new);
608 
609  if (this->getSurfaceVecObj(geo_names[j])
610  ->getNameOfElementByID(k, tmp_name))
611  {
612  merged_sfc_names->insert(
613  std::pair<std::string, std::size_t>(
614  tmp_name, sfc_offsets[j] + k));
615  }
616  }
617  if (n_geo_names - 1 > j)
618  {
619  sfc_offsets[j + 1] = sfcs->size() + sfc_offsets[j];
620  }
621  }
622  }
623  if (!merged_sfcs->empty())
624  {
625  this->addSurfaceVec(std::move(merged_sfcs), merged_geo_name,
626  std::move(merged_sfc_names));
627  }
628 }
629 
630 void GEOObjects::renameGeometry(std::string const& old_name,
631  std::string const& new_name)
632 {
633  _callbacks->renameGeometry(old_name, new_name);
634  for (auto* pnt_vec : _pnt_vecs)
635  {
636  if (pnt_vec->getName() == old_name)
637  {
638  pnt_vec->setName(new_name);
639  break;
640  }
641  }
642  for (auto* ply_vec : _ply_vecs)
643  {
644  if (ply_vec->getName() == old_name)
645  {
646  ply_vec->setName(new_name);
647  break;
648  }
649  }
650  for (auto* sfc_vec : _sfc_vecs)
651  {
652  if (sfc_vec->getName() == old_name)
653  {
654  sfc_vec->setName(new_name);
655  break;
656  }
657  }
658 }
659 
660 void markUnusedPoints(GEOObjects const& geo_objects,
661  std::string const& geo_name,
662  std::vector<bool>& transfer_pnts)
663 {
664  GeoLib::PolylineVec const* const ply_obj(
665  geo_objects.getPolylineVecObj(geo_name));
666  if (ply_obj)
667  {
668  std::vector<GeoLib::Polyline*> const& lines(*ply_obj->getVector());
669  for (auto* line : lines)
670  {
671  std::size_t const n_pnts(line->getNumberOfPoints());
672  for (std::size_t i = 0; i < n_pnts; ++i)
673  {
674  transfer_pnts[line->getPointID(i)] = false;
675  }
676  }
677  }
678 
679  GeoLib::SurfaceVec const* const sfc_obj(
680  geo_objects.getSurfaceVecObj(geo_name));
681  if (sfc_obj)
682  {
683  std::vector<GeoLib::Surface*> const& surfaces = *sfc_obj->getVector();
684  for (auto* sfc : surfaces)
685  {
686  std::size_t const n_tri(sfc->getNumberOfTriangles());
687  for (std::size_t i = 0; i < n_tri; ++i)
688  {
689  GeoLib::Triangle const& t = *(*sfc)[i];
690  transfer_pnts[t[0]] = false;
691  transfer_pnts[t[1]] = false;
692  transfer_pnts[t[2]] = false;
693  }
694  }
695  }
696 }
697 
698 int geoPointsToStations(GEOObjects& geo_objects, std::string const& geo_name,
699  std::string& stn_name, bool const only_unused_pnts)
700 {
701  GeoLib::PointVec const* const pnt_obj(geo_objects.getPointVecObj(geo_name));
702  if (pnt_obj == nullptr)
703  {
704  ERR("Point vector {:s} not found.", geo_name);
705  return -1;
706  }
707  std::vector<GeoLib::Point*> const& pnts = *pnt_obj->getVector();
708  if (pnts.empty())
709  {
710  ERR("Point vector {:s} is empty.", geo_name);
711  return -1;
712  }
713  std::size_t const n_pnts(pnts.size());
714  std::vector<bool> transfer_pnts(n_pnts, true);
715  if (only_unused_pnts)
716  {
717  markUnusedPoints(geo_objects, geo_name, transfer_pnts);
718  }
719 
720  auto stations = std::make_unique<std::vector<GeoLib::Point*>>();
721  for (std::size_t i = 0; i < n_pnts; ++i)
722  {
723  if (!transfer_pnts[i])
724  {
725  continue;
726  }
727  std::string name = pnt_obj->getItemNameByID(i);
728  if (name.empty())
729  {
730  name = "Station " + std::to_string(i);
731  }
732  stations->push_back(new GeoLib::Station(pnts[i], name));
733  }
734  if (!stations->empty())
735  {
736  geo_objects.addStationVec(std::move(stations), stn_name);
737  }
738  else
739  {
740  WARN("No points found to convert.");
741  return 1;
742  }
743  return 0;
744 }
745 
747  const std::string& geo_name,
748  GeoLib::GEOTYPE type,
749  const std::string& geo_obj_name) const
750 {
751  GeoLib::GeoObject* geo_obj(nullptr);
752  switch (type)
753  {
755  {
756  GeoLib::PointVec const* pnt_vec(getPointVecObj(geo_name));
757  if (pnt_vec)
758  {
759  geo_obj = const_cast<GeoLib::GeoObject*>(
760  dynamic_cast<GeoLib::GeoObject const*>(
761  pnt_vec->getElementByName(geo_obj_name)));
762  }
763  break;
764  }
766  {
767  GeoLib::PolylineVec const* ply_vec(getPolylineVecObj(geo_name));
768  if (ply_vec)
769  {
770  geo_obj = const_cast<GeoLib::GeoObject*>(
771  dynamic_cast<GeoLib::GeoObject const*>(
772  ply_vec->getElementByName(geo_obj_name)));
773  }
774  break;
775  }
777  {
778  GeoLib::SurfaceVec const* sfc_vec(getSurfaceVecObj(geo_name));
779  if (sfc_vec)
780  {
781  geo_obj = const_cast<GeoLib::GeoObject*>(
782  dynamic_cast<GeoLib::GeoObject const*>(
783  sfc_vec->getElementByName(geo_obj_name)));
784  }
785  break;
786  }
787  default:
788  ERR("GEOObjects::getGeoObject(): geometric type not handled.");
789  return nullptr;
790  };
791 
792  if (!geo_obj)
793  {
794  DBUG(
795  "GEOObjects::getGeoObject(): Could not find {:s} '{:s}' in "
796  "geometry.",
798  geo_obj_name);
799  }
800  return geo_obj;
801 }
802 
804  const std::string& geo_name, const std::string& geo_obj_name) const
805 {
806  GeoLib::GeoObject const* geo_obj(
807  getGeoObject(geo_name, GeoLib::GEOTYPE::POINT, geo_obj_name));
808 
809  if (!geo_obj)
810  {
811  geo_obj =
812  getGeoObject(geo_name, GeoLib::GEOTYPE::POLYLINE, geo_obj_name);
813  }
814 
815  if (!geo_obj)
816  {
817  geo_obj =
818  getGeoObject(geo_name, GeoLib::GEOTYPE::SURFACE, geo_obj_name);
819  }
820 
821  if (!geo_obj)
822  {
823  DBUG(
824  "GEOObjects::getGeoObject(): Could not find '{:s}' in geometry "
825  "{:s}.",
826  geo_obj_name, geo_name);
827  }
828  return geo_obj;
829 }
830 
831 std::size_t GEOObjects::exists(const std::string& geometry_name) const
832 {
833  std::size_t const size(_pnt_vecs.size());
834  for (std::size_t i = 0; i < size; i++)
835  {
836  if (_pnt_vecs[i]->getName() == geometry_name)
837  {
838  return i;
839  }
840  }
841 
842  // HACK for enabling conversion of files without loading the associated
843  // geometry
844  if (size > 0 && _pnt_vecs[0]->getName() == "conversionTestRun#1")
845  {
846  return 1;
847  }
848 
849  return std::numeric_limits<std::size_t>::max();
850 }
851 
852 } // 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:571
std::size_t exists(const std::string &geometry_name) const
Definition: GEOObjects.cpp:831
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:512
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
Definition: GEOObjects.cpp:401
bool appendSurfaceVec(const std::vector< Surface * > &surfaces, const std::string &name)
Definition: GEOObjects.cpp:272
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:261
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:630
bool mergePoints(std::vector< std::string > const &geo_names, std::string &merged_geo_name, std::vector< std::size_t > &pnt_offsets)
Definition: GEOObjects.cpp:459
bool removePointVec(const std::string &name)
Definition: GEOObjects.cpp:97
bool isUniquePointVecName(std::string &name) const
Definition: GEOObjects.cpp:356
bool removeSurfaceVec(const std::string &name)
Definition: GEOObjects.cpp:323
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:307
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:369
const PolylineVec * getPolylineVecObj(const std::string &name) const
Definition: GEOObjects.cpp:227
int mergeGeometries(std::vector< std::string > const &geo_names, std::string &merged_geo_name)
Definition: GEOObjects.cpp:435
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
bool appendPolylineVec(const std::vector< Polyline * > &polylines, const std::string &name)
Definition: GEOObjects.cpp:180
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:746
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:243
std::string getElementNameByID(const std::string &geometry_name, GeoLib::GEOTYPE type, std::size_t id) const
Definition: GEOObjects.cpp:414
This class manages pointers to Points in a std::vector along with a name. It also handles the deletin...
Definition: PointVec.h:39
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:150
std::size_t getNumberOfPoints() const
Definition: Polyline.cpp:99
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:698
void markUnusedPoints(GEOObjects const &geo_objects, std::string const &geo_name, std::vector< bool > &transfer_pnts)
Definition: GEOObjects.cpp:660
TemplateVec< GeoLib::Surface > SurfaceVec
Definition: SurfaceVec.h:27