27template <
typename Container>
30 return std::find_if(container.begin(), container.end(),
31 [&name](
auto const* vector)
32 { return vector->getName() == name; });
36 std::string
const& geo_name,
37 std::vector<bool>& transfer_pnts);
56 "GEOObjects::addPointVec(): Failed to create PointVec, because "
57 "there aren't any points in the given vector.");
61 std::move(pnt_id_name_map),
73 const std::string& name)
const
75 std::size_t
const idx = this->
exists(name);
76 if (idx != std::numeric_limits<std::size_t>::max())
81 DBUG(
"GEOObjects::getPointVec() - No entry found with name '{:s}'.", name);
87 std::size_t
const idx = this->
exists(name);
88 if (idx != std::numeric_limits<std::size_t>::max())
93 DBUG(
"GEOObjects::getPointVecObj() - No entry found with name '{:s}'.",
103 "GEOObjects::removePointVec() - There are still Polylines or "
104 "Surfaces depending on these points.");
110 if ((*it)->getName() == name)
118 DBUG(
"GEOObjects::removePointVec() - No entry found with name '{:s}'.",
134 const std::string& name)
const
140 return p->getName() == name &&
145 return &(*it)->getVector();
147 DBUG(
"GEOObjects::getStationVec() - No entry found with name '{:s}'.",
153 std::string
const& name,
156 auto lines_end = std::remove_if(
157 lines.begin(), lines.end(),
158 [](
auto const* polyline) { return polyline->getNumberOfPoints() < 2; });
159 lines.erase(lines_end, lines.end());
167 new PolylineVec(name, std::move(lines), std::move(ply_names)));
172 const std::string& name)
181 for (
auto* polyline : polylines)
183 (*polyline_vec_it)->push_back(polyline);
190 const std::string& name)
const
193 for (std::size_t i = 0; i < size; i++)
201 DBUG(
"GEOObjects::getPolylineVec() - No entry found with name '{:s}'.",
209 for (std::size_t i = 0; i < size; i++)
217 DBUG(
"GEOObjects::getPolylineVecObj() - No entry found with name '{:s}'.",
227 if ((*it)->getName() == name)
235 DBUG(
"GEOObjects::removePolylineVec() - No entry found with name '{:s}'.",
241 const std::string& name,
245 new SurfaceVec(name, std::move(sfc), std::move(sfc_names)));
250 const std::string& name)
253 if (surface_vec_to_append_it !=
_sfc_vecs.end())
255 for (
auto& surface : surfaces)
257 (*surface_vec_to_append_it)->push_back(surface);
265 std::vector<GeoLib::Surface*> sfc(begin(surfaces), end(surfaces));
271 const std::string& name)
const
276 return &(*surface_vec_it)->getVector();
278 DBUG(
"GEOObjects::getSurfaceVec() - No entry found with name '{:s}'.",
294 DBUG(
"GEOObjects::removeSurfaceVec() - No entry found with name '{:s}'.",
304 return *surface_vec_it;
306 DBUG(
"GEOObjects::getSurfaceVecObj() - No entry found with name '{:s}'.",
316 if (unique_name != name)
337 names.push_back(point->getName());
344 std::vector<std::string> names;
349 names.push_back(point->getName());
357 std::size_t
id)
const
377 std::string& merged_geo_name)
379 const std::size_t n_geo_names(geo_names.size());
386 std::vector<std::size_t> pnt_offsets(n_geo_names, 0);
388 if (!
mergePoints(geo_names, merged_geo_name, pnt_offsets))
401 std::string& merged_geo_name,
402 std::vector<std::size_t>& pnt_offsets)
404 const std::size_t n_geo_names(geo_names.size());
406 std::vector<GeoLib::Point*> merged_points;
409 for (std::size_t j(0); j < n_geo_names; ++j)
413 if (pnt_vec ==
nullptr)
425 std::size_t
const n_pnts(pnts.size());
426 for (std::size_t k(0); k < n_pnts; ++k)
428 merged_points.push_back(
431 if (!item_name.empty())
433 merged_pnt_names.insert(
434 std::make_pair(item_name, pnt_offsets[j] + k));
437 if (n_geo_names - 1 > j)
439 pnt_offsets[j + 1] = n_pnts + pnt_offsets[j];
443 addPointVec(std::move(merged_points), merged_geo_name,
444 std::move(merged_pnt_names), 1e-6);
449 std::string
const& merged_geo_name,
450 std::vector<std::size_t>
const& pnt_offsets)
452 const std::size_t n_geo_names(geo_names.size());
453 std::vector<std::size_t> ply_offsets(n_geo_names, 0);
455 std::vector<GeoLib::Polyline*> merged_polylines;
458 auto const& merged_points(
getPointVecObj(merged_geo_name)->getVector());
459 std::vector<std::size_t>
const& id_map(
462 for (std::size_t j(0); j < n_geo_names; j++)
464 const std::vector<GeoLib::Polyline*>* plys(
468 std::string tmp_name;
469 for (std::size_t k(0); k < plys->size(); k++)
473 const std::size_t size_of_kth_ply(
477 for (std::size_t i(0); i < size_of_kth_ply; i++)
479 kth_ply_new->addPoint(
480 id_map[pnt_offsets[j] + kth_ply_old->
getPointID(i)]);
482 merged_polylines.push_back(kth_ply_new);
484 ->getNameOfElementByID(k, tmp_name))
486 merged_ply_names.emplace(tmp_name, ply_offsets[j] + k);
489 if (n_geo_names - 1 > j)
491 ply_offsets[j + 1] = plys->size() + ply_offsets[j];
496 if (!merged_polylines.empty())
498 this->
addPolylineVec(std::move(merged_polylines), merged_geo_name,
499 std::move(merged_ply_names));
504 std::string
const& merged_geo_name,
505 std::vector<std::size_t>
const& pnt_offsets)
507 auto const& merged_points(
getPointVecObj(merged_geo_name)->getVector());
508 std::vector<std::size_t>
const& id_map(
511 const std::size_t n_geo_names(geo_names.size());
512 std::vector<std::size_t> sfc_offsets(n_geo_names, 0);
513 std::vector<GeoLib::Surface*> merged_sfcs;
515 for (std::size_t j(0); j < n_geo_names; j++)
517 const std::vector<GeoLib::Surface*>* sfcs(
521 std::string tmp_name;
522 for (std::size_t k(0); k < sfcs->size(); k++)
526 const std::size_t size_of_kth_sfc(
529 for (std::size_t i(0); i < size_of_kth_sfc; i++)
532 const std::size_t id0(id_map[pnt_offsets[j] + (*tri)[0]]);
533 const std::size_t id1(id_map[pnt_offsets[j] + (*tri)[1]]);
534 const std::size_t id2(id_map[pnt_offsets[j] + (*tri)[2]]);
535 kth_sfc_new->addTriangle(id0, id1, id2);
537 merged_sfcs.push_back(kth_sfc_new);
540 ->getNameOfElementByID(k, tmp_name))
542 merged_sfc_names.emplace(tmp_name, sfc_offsets[j] + k);
545 if (n_geo_names - 1 > j)
547 sfc_offsets[j + 1] = sfcs->size() + sfc_offsets[j];
551 if (!merged_sfcs.empty())
554 std::move(merged_sfc_names));
559 std::string
const& new_name)
561 _callbacks->renameGeometry(old_name, new_name);
563 auto rename = [&old_name, &new_name](
auto const& container)
566 if (it != container.end())
568 (*it)->setName(new_name);
578 std::string
const& geo_name,
579 std::vector<bool>& transfer_pnts)
585 std::vector<GeoLib::Polyline*>
const& lines(ply_obj->
getVector());
586 for (
auto* line : lines)
588 std::size_t
const n_pnts(line->getNumberOfPoints());
589 for (std::size_t i = 0; i < n_pnts; ++i)
591 transfer_pnts[line->getPointID(i)] =
false;
600 std::vector<GeoLib::Surface*>
const& surfaces = sfc_obj->
getVector();
601 for (
auto* sfc : surfaces)
603 std::size_t
const n_tri(sfc->getNumberOfTriangles());
604 for (std::size_t i = 0; i < n_tri; ++i)
607 transfer_pnts[t[0]] =
false;
608 transfer_pnts[t[1]] =
false;
609 transfer_pnts[t[2]] =
false;
616 std::string& stn_name,
bool const only_unused_pnts)
619 if (pnt_obj ==
nullptr)
621 ERR(
"Point vector {:s} not found.", geo_name);
627 ERR(
"Point vector {:s} is empty.", geo_name);
630 std::size_t
const n_pnts(pnts.size());
631 std::vector<bool> transfer_pnts(n_pnts,
true);
632 if (only_unused_pnts)
637 std::vector<GeoLib::Point*> stations;
638 for (std::size_t i = 0; i < n_pnts; ++i)
640 if (!transfer_pnts[i])
647 name =
"Station " + std::to_string(i);
651 if (!stations.empty())
657 WARN(
"No points found to convert.");
664 const std::string& geo_name,
666 const std::string& geo_obj_name)
const
705 ERR(
"GEOObjects::getGeoObject(): geometric type not handled.");
712 "GEOObjects::getGeoObject(): Could not find {:s} '{:s}' in "
721 const std::string& geo_name,
const std::string& geo_obj_name)
const
741 "GEOObjects::getGeoObject(): Could not find '{:s}' in geometry "
743 geo_obj_name, geo_name);
750 std::size_t
const size(
_pnt_vecs.size());
754 return std::distance(
_pnt_vecs.begin(), it);
764 return std::numeric_limits<std::size_t>::max();
Definition of the GEOObjects class.
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the Station class.
Container class for geometric objects.
void mergeSurfaces(std::vector< std::string > const &geo_names, std::string const &merged_geo_name, std::vector< std::size_t > const &pnt_offsets)
std::size_t exists(const std::string &geometry_name) const
void mergePolylines(std::vector< std::string > const &geo_names, std::string const &merged_geo_name, std::vector< std::size_t > const &pnt_offsets)
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
void addPolylineVec(std::vector< Polyline * > &&lines, std::string const &name, PolylineVec::NameIdMap &&ply_names)
bool appendSurfaceVec(const std::vector< Surface * > &surfaces, const std::string &name)
const std::vector< Point * > * getPointVec(const std::string &name) const
void addPointVec(std::vector< Point * > &&points, std::string &name, PointVec::NameIdMap &&pnt_id_name_map, double const eps=std::sqrt(std::numeric_limits< double >::epsilon()))
const PointVec * getPointVecObj(const std::string &name) const
void renameGeometry(std::string const &old_name, std::string const &new_name)
bool mergePoints(std::vector< std::string > const &geo_names, std::string &merged_geo_name, std::vector< std::size_t > &pnt_offsets)
bool removePointVec(const std::string &name)
bool isUniquePointVecName(std::string &name) const
bool removeSurfaceVec(const std::string &name)
void addStationVec(std::vector< Point * > &&stations, std::string &name)
Adds a vector of stations with the given name and colour to GEOObjects.
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
const std::vector< Surface * > * getSurfaceVec(const std::string &name) const
Returns the surface vector with the given name as a const.
std::vector< PointVec * > _pnt_vecs
std::vector< PolylineVec * > _ply_vecs
std::unique_ptr< Callbacks > _callbacks
void addSurfaceVec(std::vector< Surface * > &&sfc, const std::string &name, SurfaceVec::NameIdMap &&sfc_names)
bool isPntVecUsed(const std::string &name) const
Checks if the point vector with the given name is referenced in a polyline- or surface vector.
const PolylineVec * getPolylineVecObj(const std::string &name) const
int mergeGeometries(std::vector< std::string > const &geo_names, std::string &merged_geo_name)
void getStationVectorNames(std::vector< std::string > &names) const
Returns the names of all station vectors.
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
bool appendPolylineVec(const std::vector< Polyline * > &polylines, const std::string &name)
std::vector< SurfaceVec * > _sfc_vecs
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.
const std::vector< GeoLib::Point * > * getStationVec(const std::string &name) const
Returns the station vector with the given name.
bool removePolylineVec(const std::string &name)
std::string getElementNameByID(const std::string &geometry_name, GeoLib::GEOTYPE type, std::size_t id) const
This class manages pointers to Points in a std::vector along with a name. It also handles the deletio...
std::string const & getItemNameByID(std::size_t id) const
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
std::size_t getPointID(std::size_t const i) const
std::size_t getNumberOfPoints() const
A Station (observation site) is basically a Point with some additional information.
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
std::size_t getNumberOfTriangles() const
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
std::map< std::string, std::size_t > NameIdMap
const T * getElementByName(const std::string &name) const
Returns an element with the given name.
bool getNameOfElementByID(std::size_t id, std::string &element_name) const
std::vector< T * > const & getVector() const
Class Triangle consists of a reference to a point vector and a vector that stores the indices in the ...
TemplateVec< GeoLib::Polyline > PolylineVec
class PolylineVec encapsulate a std::vector of Polylines additional one can give the vector of polyli...
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.
void cleanupVectorElements(std::vector< T * > &items)
std::string convertGeoTypeToString(GEOTYPE geo_type)
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.
auto findVectorByName(Container const &container, std::string const &name)
void markUnusedPoints(GEOObjects const &geo_objects, std::string const &geo_name, std::vector< bool > &transfer_pnts)
TemplateVec< GeoLib::Surface > SurfaceVec