OGS
GEOObjects.h
Go to the documentation of this file.
1
15#pragma once
16
17#include <functional>
18#include <map>
19#include <string>
20#include <vector>
21
22#include "GeoType.h"
23#include "Point.h"
24#include "PointVec.h"
25#include "Polyline.h"
26#include "PolylineVec.h"
27#include "Surface.h"
28#include "SurfaceVec.h"
29
32namespace GeoLib
33{
56class GEOObjects final
57{
58public:
59 struct Callbacks
60 {
61 virtual void addPointVec(std::string const& /*unused*/) {}
62 virtual void removePointVec(std::string const& /*unused*/) {}
63 virtual void addStationVec(std::string const& /*unused*/) {}
64 virtual void removeStationVec(std::string const& /*unused*/) {}
65 virtual void addPolylineVec(std::string const& /*unused*/) {}
66 virtual void appendPolylineVec(std::string const& /*unused*/) {}
67 virtual void removePolylineVec(std::string const& /*unused*/) {}
68 virtual void addSurfaceVec(std::string const& /*unused*/) {}
69 virtual void appendSurfaceVec(std::string const& /*unused*/) {}
70 virtual void removeSurfaceVec(std::string const& /*unused*/) {}
71 virtual void renameGeometry(std::string const& /*unused*/,
72 std::string const& /*unused*/)
73 {
74 }
75 virtual ~Callbacks() = default;
76 };
77
78public:
86 void addPointVec(
87 std::vector<Point*>&& points, std::string& name,
88 PointVec::NameIdMap&& pnt_id_name_map,
89 double const eps = std::sqrt(std::numeric_limits<double>::epsilon()));
90
98 void addPointVec(
99 std::vector<Point*>&& points, std::string& name,
100 double const eps = std::sqrt(std::numeric_limits<double>::epsilon()));
101
105 const std::vector<Point*>* getPointVec(const std::string& name) const;
106
112 const PointVec* getPointVecObj(const std::string& name) const;
113
115 PointVec* getPointVecObj(const std::string& name)
116 {
117 return const_cast<PointVec*>(
118 static_cast<const GEOObjects&>(*this).getPointVecObj(name));
119 }
120
125 bool removePointVec(const std::string& name);
126
128 void addStationVec(std::vector<Point*>&& stations, std::string& name);
129
131 const std::vector<GeoLib::Point*>* getStationVec(
132 const std::string& name) const;
133
135 bool removeStationVec(const std::string& name)
136 {
137 _callbacks->removeStationVec(name);
138 return removePointVec(name);
139 }
140
149 void addPolylineVec(std::vector<Polyline*>&& lines,
150 std::string const& name,
151 PolylineVec::NameIdMap&& ply_names);
152
160 bool appendPolylineVec(const std::vector<Polyline*>& polylines,
161 const std::string& name);
162
166 const std::vector<Polyline*>* getPolylineVec(const std::string& name) const;
167
173 const PolylineVec* getPolylineVecObj(const std::string& name) const;
174
176 PolylineVec* getPolylineVecObj(const std::string& name)
177 {
178 return const_cast<PolylineVec*>(
179 static_cast<const GEOObjects&>(*this).getPolylineVecObj(name));
180 }
181
187 bool removePolylineVec(const std::string& name);
188
190 void addSurfaceVec(std::vector<Surface*>&& sfc,
191 const std::string& name,
192 SurfaceVec::NameIdMap&& sfc_names);
193
201 bool appendSurfaceVec(const std::vector<Surface*>& surfaces,
202 const std::string& name);
203
205 const std::vector<Surface*>* getSurfaceVec(const std::string& name) const;
206
208 SurfaceVec* getSurfaceVecObj(const std::string& name)
209 {
210 return const_cast<SurfaceVec*>(
211 static_cast<const GEOObjects&>(*this).getSurfaceVecObj(name));
212 }
213
215 bool removeSurfaceVec(const std::string& name);
223 const SurfaceVec* getSurfaceVecObj(const std::string& name) const;
224
226 std::vector<std::string> getGeometryNames() const;
227
228 std::string getElementNameByID(const std::string& geometry_name,
229 GeoLib::GEOTYPE type, std::size_t id) const;
230
232 void getStationVectorNames(std::vector<std::string>& names) const;
233
243 bool isUniquePointVecName(std::string& name) const;
244
254 int mergeGeometries(std::vector<std::string> const& geo_names,
255 std::string& merged_geo_name);
256
261 void renameGeometry(std::string const& old_name,
262 std::string const& new_name);
263
267 const std::string& geo_name,
268 GeoLib::GEOTYPE type,
269 const std::string& geo_obj_name) const;
270
272 // It is required that a tuple is a unique key for a geometric object!
273 // If there is another geo object with same name one of them is returned.
274 // In theory different types of geometric objects can have the same name.
275 // For instance it is possible that a point object and a polyline object
276 // share the same name. If there exists several objects sharing the same
277 // name the first object found will be returned.
278 // @param geo_name name of geometry
279 // @param geo_obj_name name of the geo object
281 const std::string& geo_name, const std::string& geo_obj_name) const;
282
286 ~GEOObjects();
287
290 std::size_t exists(const std::string& geometry_name) const;
291
294 bool isPntVecUsed(const std::string& name) const;
295
297 std::vector<PointVec*> const& getPoints() const { return _pnt_vecs; }
299 std::vector<PolylineVec*> const& getPolylines() const { return _ply_vecs; }
301 std::vector<SurfaceVec*> const& getSurfaces() const { return _sfc_vecs; }
302
303 std::unique_ptr<Callbacks> _callbacks{new Callbacks};
304
305 std::function<void(std::string const&)> addPolylineVecCallback =
306 [](std::string const& /*unused*/) {};
307
308 std::function<void(std::string const&)> appendPolylineVecCallback =
309 [](std::string const& /*unused*/) {};
310
311 std::function<void(std::string const&)> removePolylineVecCallback =
312 [](std::string const& /*unused*/) {};
313
314 std::function<void(std::string const&)> addSurfaceVecCallback =
315 [](std::string const& /*unused*/) {};
316
317 std::function<void(std::string const&)> appendSurfaceVecCallback =
318 [](std::string const& /*unused*/) {};
319
320 std::function<void(std::string const&)> removeSurfaceVecCallback =
321 [](std::string const& /*unused*/) {};
322
323private:
332 void mergePoints(std::vector<std::string> const& geo_names,
333 std::string& merged_geo_name,
334 std::vector<std::size_t>& pnt_offsets);
335
348 void mergePolylines(std::vector<std::string> const& geo_names,
349 std::string const& merged_geo_name,
350 std::vector<std::size_t> const& pnt_offsets);
351
362 void mergeSurfaces(std::vector<std::string> const& geo_names,
363 std::string const& merged_geo_name,
364 std::vector<std::size_t> const& pnt_offsets);
365
367 std::vector<PointVec*> _pnt_vecs;
369 std::vector<PolylineVec*> _ply_vecs;
371 std::vector<SurfaceVec*> _sfc_vecs;
372};
373
375// @param geo_obj geometry manager object
376// @param geo_name name of the geometry
377// @param stn_name name of the new station vector
378// @param only_usused_pnts if true only points not in a line or surface are
379// transferred, otherwise all points
380int geoPointsToStations(GEOObjects& geo_objects, std::string const& geo_name,
381 std::string& stn_name,
382 bool const only_unused_pnts = true);
383} // namespace GeoLib
Definition of the Point class.
Definition of the GEOTYPE enumeration.
Definition of the PointVec class.
Definition of the PolylineVec class.
Definition of the PolyLine class.
Definition of the SurfaceVec class.
Container class for geometric objects.
Definition GEOObjects.h:57
void mergeSurfaces(std::vector< std::string > const &geo_names, std::string const &merged_geo_name, std::vector< std::size_t > const &pnt_offsets)
std::function< void(std::string const &)> appendSurfaceVecCallback
Definition GEOObjects.h:317
std::size_t exists(const std::string &geometry_name) const
PointVec * getPointVecObj(const std::string &name)
Returns a pointer to a PointVec object for the given name.
Definition GEOObjects.h:115
void mergePolylines(std::vector< std::string > const &geo_names, std::string const &merged_geo_name, std::vector< std::size_t > const &pnt_offsets)
std::function< void(std::string const &)> addSurfaceVecCallback
Definition GEOObjects.h:314
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()))
std::vector< PolylineVec * > const & getPolylines() const
Read access to polylines w/o using a name.
Definition GEOObjects.h:299
const PointVec * getPointVecObj(const std::string &name) const
void renameGeometry(std::string const &old_name, std::string const &new_name)
std::function< void(std::string const &)> addPolylineVecCallback
Definition GEOObjects.h:305
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.
Definition GEOObjects.h:208
PolylineVec * getPolylineVecObj(const std::string &name)
Returns a pointer to a PolylineVec object for the given name.
Definition GEOObjects.h:176
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
Definition GEOObjects.h:367
std::function< void(std::string const &)> appendPolylineVecCallback
Definition GEOObjects.h:308
std::vector< PolylineVec * > _ply_vecs
Definition GEOObjects.h:369
std::unique_ptr< Callbacks > _callbacks
Definition GEOObjects.h:303
std::vector< PointVec * > const & getPoints() const
Read access to points w/o using a name.
Definition GEOObjects.h:297
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
bool removeStationVec(const std::string &name)
Removes the station vector with the given name from GEOObjects.
Definition GEOObjects.h:135
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
std::function< void(std::string const &)> removePolylineVecCallback
Definition GEOObjects.h:311
bool appendPolylineVec(const std::vector< Polyline * > &polylines, const std::string &name)
std::function< void(std::string const &)> removeSurfaceVecCallback
Definition GEOObjects.h:320
std::vector< SurfaceVec * > _sfc_vecs
Definition GEOObjects.h:371
std::vector< SurfaceVec * > const & getSurfaces() const
Read access to surfaces w/o using a name.
Definition GEOObjects.h:301
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...
Definition PointVec.h:36
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
Definition TemplateVec.h:41
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.
GEOTYPE
Definition GeoType.h:23
virtual void renameGeometry(std::string const &, std::string const &)
Definition GEOObjects.h:71
virtual void appendSurfaceVec(std::string const &)
Definition GEOObjects.h:69
virtual void removePolylineVec(std::string const &)
Definition GEOObjects.h:67
virtual void addSurfaceVec(std::string const &)
Definition GEOObjects.h:68
virtual void addStationVec(std::string const &)
Definition GEOObjects.h:63
virtual void removeSurfaceVec(std::string const &)
Definition GEOObjects.h:70
virtual void appendPolylineVec(std::string const &)
Definition GEOObjects.h:66
virtual ~Callbacks()=default
virtual void addPointVec(std::string const &)
Definition GEOObjects.h:61
virtual void removeStationVec(std::string const &)
Definition GEOObjects.h:64
virtual void removePointVec(std::string const &)
Definition GEOObjects.h:62
virtual void addPolylineVec(std::string const &)
Definition GEOObjects.h:65