16template <
typename Container>
19 return std::find_if(container.begin(), container.end(),
20 [&name](
auto const* vector)
21 { return vector->getName() == name; });
25 std::string
const& geo_name,
26 std::vector<bool>& transfer_pnts);
45 "GEOObjects::addPointVec(): Failed to create PointVec, because "
46 "there aren't any points in the given vector.");
50 std::move(pnt_id_name_map),
62 const std::string& name)
const
64 std::size_t
const idx = this->
exists(name);
65 if (idx != std::numeric_limits<std::size_t>::max())
70 DBUG(
"GEOObjects::getPointVec() - No entry found with name '{:s}'.", name);
76 std::size_t
const idx = this->
exists(name);
77 if (idx != std::numeric_limits<std::size_t>::max())
82 DBUG(
"GEOObjects::getPointVecObj() - No entry found with name '{:s}'.",
92 "GEOObjects::removePointVec() - There are still Polylines or "
93 "Surfaces depending on these points.");
99 if ((*it)->getName() == name)
107 DBUG(
"GEOObjects::removePointVec() - No entry found with name '{:s}'.",
123 const std::string& name)
const
134 return &(*it)->getVector();
136 DBUG(
"GEOObjects::getStationVec() - No entry found with name '{:s}'.",
142 std::string
const& name,
145 auto lines_end = std::remove_if(
146 lines.begin(), lines.end(),
147 [](
auto const* polyline) { return polyline->getNumberOfPoints() < 2; });
148 lines.erase(lines_end, lines.end());
156 new PolylineVec(name, std::move(lines), std::move(ply_names)));
161 const std::string& name)
170 for (
auto* polyline : polylines)
172 (*polyline_vec_it)->push_back(polyline);
179 const std::string& name)
const
182 for (std::size_t i = 0; i < size; i++)
190 DBUG(
"GEOObjects::getPolylineVec() - No entry found with name '{:s}'.",
198 for (std::size_t i = 0; i < size; i++)
206 DBUG(
"GEOObjects::getPolylineVecObj() - No entry found with name '{:s}'.",
216 { return v->getName() == name; });
224 DBUG(
"GEOObjects::removePolylineVec() - No entry found with name '{:s}'.",
230 const std::string& name,
234 new SurfaceVec(name, std::move(sfc), std::move(sfc_names)));
239 const std::string& name)
242 if (surface_vec_to_append_it !=
_sfc_vecs.end())
244 for (
auto& surface : surfaces)
246 (*surface_vec_to_append_it)->push_back(surface);
254 std::vector<GeoLib::Surface*> sfc(begin(surfaces), end(surfaces));
260 const std::string& name)
const
265 return &(*surface_vec_it)->getVector();
267 DBUG(
"GEOObjects::getSurfaceVec() - No entry found with name '{:s}'.",
283 DBUG(
"GEOObjects::removeSurfaceVec() - No entry found with name '{:s}'.",
293 return *surface_vec_it;
295 DBUG(
"GEOObjects::getSurfaceVecObj() - No entry found with name '{:s}'.",
305 if (unique_name != name)
326 names.push_back(point->getName());
333 std::vector<std::string> names;
338 names.push_back(point->getName());
346 std::size_t
id)
const
366 std::string& merged_geo_name)
368 const std::size_t n_geo_names(geo_names.size());
375 std::vector<std::size_t> pnt_offsets(n_geo_names, 0);
377 mergePoints(geo_names, merged_geo_name, pnt_offsets);
387 std::string& merged_geo_name,
388 std::vector<std::size_t>& pnt_offsets)
390 const std::size_t n_geo_names(geo_names.size());
392 std::vector<GeoLib::Point*> merged_points;
395 for (std::size_t j(0); j < n_geo_names; ++j)
399 if (pnt_vec ==
nullptr)
411 std::size_t
const n_pnts(pnts.size());
412 for (std::size_t k(0); k < n_pnts; ++k)
414 merged_points.push_back(
417 if (!item_name.empty())
419 merged_pnt_names.insert(
420 std::make_pair(item_name, pnt_offsets[j] + k));
423 if (n_geo_names - 1 > j)
425 pnt_offsets[j + 1] = n_pnts + pnt_offsets[j];
429 addPointVec(std::move(merged_points), merged_geo_name,
430 std::move(merged_pnt_names), 1e-6);
434 std::string
const& merged_geo_name,
435 std::vector<std::size_t>
const& pnt_offsets)
437 const std::size_t n_geo_names(geo_names.size());
438 std::vector<std::size_t> ply_offsets(n_geo_names, 0);
440 std::vector<GeoLib::Polyline*> merged_polylines;
443 auto const& merged_points(
getPointVecObj(merged_geo_name)->getVector());
444 std::vector<std::size_t>
const& id_map(
447 for (std::size_t j(0); j < n_geo_names; j++)
449 const std::vector<GeoLib::Polyline*>* plys(
453 std::string tmp_name;
454 for (std::size_t k(0); k < plys->size(); k++)
458 const std::size_t size_of_kth_ply(
462 for (std::size_t i(0); i < size_of_kth_ply; i++)
464 kth_ply_new->addPoint(
465 id_map[pnt_offsets[j] + kth_ply_old->
getPointID(i)]);
467 merged_polylines.push_back(kth_ply_new);
469 ->getNameOfElementByID(k, tmp_name))
471 merged_ply_names.emplace(tmp_name, ply_offsets[j] + k);
474 if (n_geo_names - 1 > j)
476 ply_offsets[j + 1] = plys->size() + ply_offsets[j];
481 if (!merged_polylines.empty())
483 this->
addPolylineVec(std::move(merged_polylines), merged_geo_name,
484 std::move(merged_ply_names));
489 std::string
const& merged_geo_name,
490 std::vector<std::size_t>
const& pnt_offsets)
492 auto const& merged_points(
getPointVecObj(merged_geo_name)->getVector());
493 std::vector<std::size_t>
const& id_map(
496 const std::size_t n_geo_names(geo_names.size());
497 std::vector<std::size_t> sfc_offsets(n_geo_names, 0);
498 std::vector<GeoLib::Surface*> merged_sfcs;
500 for (std::size_t j(0); j < n_geo_names; j++)
502 const std::vector<GeoLib::Surface*>* sfcs(
506 std::string tmp_name;
507 for (std::size_t k(0); k < sfcs->size(); k++)
511 const std::size_t size_of_kth_sfc(
514 for (std::size_t i(0); i < size_of_kth_sfc; i++)
517 const std::size_t id0(id_map[pnt_offsets[j] + (*tri)[0]]);
518 const std::size_t id1(id_map[pnt_offsets[j] + (*tri)[1]]);
519 const std::size_t id2(id_map[pnt_offsets[j] + (*tri)[2]]);
520 kth_sfc_new->addTriangle(id0, id1, id2);
522 merged_sfcs.push_back(kth_sfc_new);
525 ->getNameOfElementByID(k, tmp_name))
527 merged_sfc_names.emplace(tmp_name, sfc_offsets[j] + k);
530 if (n_geo_names - 1 > j)
532 sfc_offsets[j + 1] = sfcs->size() + sfc_offsets[j];
536 if (!merged_sfcs.empty())
539 std::move(merged_sfc_names));
544 std::string
const& new_name)
546 _callbacks->renameGeometry(old_name, new_name);
548 auto rename = [&old_name, &new_name](
auto const& container)
551 if (it != container.end())
553 (*it)->setName(new_name);
563 std::string
const& geo_name,
564 std::vector<bool>& transfer_pnts)
570 std::vector<GeoLib::Polyline*>
const& lines(ply_obj->
getVector());
571 for (
auto* line : lines)
573 std::size_t
const n_pnts(line->getNumberOfPoints());
574 for (std::size_t i = 0; i < n_pnts; ++i)
576 transfer_pnts[line->getPointID(i)] =
false;
585 std::vector<GeoLib::Surface*>
const& surfaces = sfc_obj->
getVector();
586 for (
auto* sfc : surfaces)
588 std::size_t
const n_tri(sfc->getNumberOfTriangles());
589 for (std::size_t i = 0; i < n_tri; ++i)
592 transfer_pnts[t[0]] =
false;
593 transfer_pnts[t[1]] =
false;
594 transfer_pnts[t[2]] =
false;
601 std::string& stn_name,
bool const only_unused_pnts)
604 if (pnt_obj ==
nullptr)
606 ERR(
"Point vector {:s} not found.", geo_name);
612 ERR(
"Point vector {:s} is empty.", geo_name);
615 std::size_t
const n_pnts(pnts.size());
616 std::vector<bool> transfer_pnts(n_pnts,
true);
617 if (only_unused_pnts)
622 std::vector<GeoLib::Point*> stations;
623 for (std::size_t i = 0; i < n_pnts; ++i)
625 if (!transfer_pnts[i])
632 name =
"Station " + std::to_string(i);
636 if (!stations.empty())
642 WARN(
"No points found to convert.");
649 const std::string& geo_name,
651 const std::string& geo_obj_name)
const
690 ERR(
"GEOObjects::getGeoObject(): geometric type not handled.");
697 "GEOObjects::getGeoObject(): Could not find {:s} '{:s}' in "
706 const std::string& geo_name,
const std::string& geo_obj_name)
const
726 "GEOObjects::getGeoObject(): Could not find '{:s}' in geometry "
728 geo_obj_name, geo_name);
738 return std::distance(
_pnt_vecs.begin(), it);
744 _pnt_vecs[0]->getName() ==
"conversionTestRun#1")
749 return std::numeric_limits<std::size_t>::max();
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)
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 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.
void mergePoints(std::vector< std::string > const &geo_names, std::string &merged_geo_name, std::vector< std::size_t > &pnt_offsets)
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
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
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...
PointType getType() const
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
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::string getName() 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 ...
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)
TemplateVec< GeoLib::Surface > SurfaceVec
void markUnusedPoints(GEOObjects const &geo_objects, std::string const &geo_name, std::vector< bool > &transfer_pnts)
TemplateVec< GeoLib::Polyline > PolylineVec
class PolylineVec encapsulate a std::vector of Polylines additional one can give the vector of polyli...