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
30namespace GeoLib
31{
33
60class GEOObjects final
61{
62public:
63 struct Callbacks
64 {
65 virtual void addPointVec(std::string const& /*unused*/) {}
66 virtual void removePointVec(std::string const& /*unused*/) {}
67 virtual void addStationVec(std::string const& /*unused*/) {}
68 virtual void removeStationVec(std::string const& /*unused*/) {}
69 virtual void addPolylineVec(std::string const& /*unused*/) {}
70 virtual void appendPolylineVec(std::string const& /*unused*/) {}
71 virtual void removePolylineVec(std::string const& /*unused*/) {}
72 virtual void addSurfaceVec(std::string const& /*unused*/) {}
73 virtual void appendSurfaceVec(std::string const& /*unused*/) {}
74 virtual void removeSurfaceVec(std::string const& /*unused*/) {}
75 virtual void renameGeometry(std::string const& /*unused*/,
76 std::string const& /*unused*/)
77 {
78 }
79 virtual ~Callbacks() = default;
80 };
81
82public:
90 void addPointVec(
91 std::vector<Point*>&& points, std::string& name,
92 PointVec::NameIdMap&& pnt_id_name_map,
93 double const eps = std::sqrt(std::numeric_limits<double>::epsilon()));
94
102 void addPointVec(
103 std::vector<Point*>&& points, std::string& name,
104 double const eps = std::sqrt(std::numeric_limits<double>::epsilon()));
105
109 const std::vector<Point*>* getPointVec(const std::string& name) const;
110
116 const PointVec* getPointVecObj(const std::string& name) const;
117
119 PointVec* getPointVecObj(const std::string& name)
120 {
121 return const_cast<PointVec*>(
122 static_cast<const GEOObjects&>(*this).getPointVecObj(name));
123 }
124
129 bool removePointVec(const std::string& name);
130
132 void addStationVec(std::vector<Point*>&& stations, std::string& name);
133
135 const std::vector<GeoLib::Point*>* getStationVec(
136 const std::string& name) const;
137
139 bool removeStationVec(const std::string& name)
140 {
141 _callbacks->removeStationVec(name);
142 return removePointVec(name);
143 }
144
153 void addPolylineVec(std::vector<Polyline*>&& lines,
154 std::string const& name,
155 PolylineVec::NameIdMap&& ply_names);
156
164 bool appendPolylineVec(const std::vector<Polyline*>& polylines,
165 const std::string& name);
166
170 const std::vector<Polyline*>* getPolylineVec(const std::string& name) const;
171
177 const PolylineVec* getPolylineVecObj(const std::string& name) const;
178
180 PolylineVec* getPolylineVecObj(const std::string& name)
181 {
182 return const_cast<PolylineVec*>(
183 static_cast<const GEOObjects&>(*this).getPolylineVecObj(name));
184 }
185
191 bool removePolylineVec(const std::string& name);
192
194 void addSurfaceVec(std::vector<Surface*>&& sfc,
195 const std::string& name,
196 SurfaceVec::NameIdMap&& sfc_names);
197
205 bool appendSurfaceVec(const std::vector<Surface*>& surfaces,
206 const std::string& name);
207
209 const std::vector<Surface*>* getSurfaceVec(const std::string& name) const;
210
212 SurfaceVec* getSurfaceVecObj(const std::string& name)
213 {
214 return const_cast<SurfaceVec*>(
215 static_cast<const GEOObjects&>(*this).getSurfaceVecObj(name));
216 }
217
219 bool removeSurfaceVec(const std::string& name);
227 const SurfaceVec* getSurfaceVecObj(const std::string& name) const;
228
230 std::vector<std::string> getGeometryNames() const;
231
232 std::string getElementNameByID(const std::string& geometry_name,
233 GeoLib::GEOTYPE type, std::size_t id) const;
234
236 void getStationVectorNames(std::vector<std::string>& names) const;
237
247 bool isUniquePointVecName(std::string& name) const;
248
258 int mergeGeometries(std::vector<std::string> const& geo_names,
259 std::string& merged_geo_name);
260
265 void renameGeometry(std::string const& old_name,
266 std::string const& new_name);
267
271 const std::string& geo_name,
272 GeoLib::GEOTYPE type,
273 const std::string& geo_obj_name) const;
274
276 // It is required that a tuple is a unique key for a geometric object!
277 // If there is another geo object with same name one of them is returned.
278 // In theory different types of geometric objects can have the same name.
279 // For instance it is possible that a point object and a polyline object
280 // share the same name. If there exists several objects sharing the same
281 // name the first object found will be returned.
282 // @param geo_name name of geometry
283 // @param geo_obj_name name of the geo object
285 const std::string& geo_name, const std::string& geo_obj_name) const;
286
290 ~GEOObjects();
291
294 std::size_t exists(const std::string& geometry_name) const;
295
298 bool isPntVecUsed(const std::string& name) const;
299
301 std::vector<PointVec*> const& getPoints() const { return _pnt_vecs; }
303 std::vector<PolylineVec*> const& getPolylines() const { return _ply_vecs; }
305 std::vector<SurfaceVec*> const& getSurfaces() const { return _sfc_vecs; }
306
307 std::unique_ptr<Callbacks> _callbacks{new Callbacks};
308
309 std::function<void(std::string const&)> addPolylineVecCallback =
310 [](std::string const& /*unused*/) {};
311
312 std::function<void(std::string const&)> appendPolylineVecCallback =
313 [](std::string const& /*unused*/) {};
314
315 std::function<void(std::string const&)> removePolylineVecCallback =
316 [](std::string const& /*unused*/) {};
317
318 std::function<void(std::string const&)> addSurfaceVecCallback =
319 [](std::string const& /*unused*/) {};
320
321 std::function<void(std::string const&)> appendSurfaceVecCallback =
322 [](std::string const& /*unused*/) {};
323
324 std::function<void(std::string const&)> removeSurfaceVecCallback =
325 [](std::string const& /*unused*/) {};
326
327private:
336 void mergePoints(std::vector<std::string> const& geo_names,
337 std::string& merged_geo_name,
338 std::vector<std::size_t>& pnt_offsets);
339
352 void mergePolylines(std::vector<std::string> const& geo_names,
353 std::string const& merged_geo_name,
354 std::vector<std::size_t> const& pnt_offsets);
355
366 void mergeSurfaces(std::vector<std::string> const& geo_names,
367 std::string const& merged_geo_name,
368 std::vector<std::size_t> const& pnt_offsets);
369
371 std::vector<PointVec*> _pnt_vecs;
373 std::vector<PolylineVec*> _ply_vecs;
375 std::vector<SurfaceVec*> _sfc_vecs;
376};
377
379// @param geo_obj geometry manager object
380// @param geo_name name of the geometry
381// @param stn_name name of the new station vector
382// @param only_usused_pnts if true only points not in a line or surface are
383// transferred, otherwise all points
384int geoPointsToStations(GEOObjects& geo_objects, std::string const& geo_name,
385 std::string& stn_name,
386 bool const only_unused_pnts = true);
387} // namespace GeoLib
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: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:499
std::function< void(std::string const &)> appendSurfaceVecCallback
Definition: GEOObjects.h:321
std::size_t exists(const std::string &geometry_name) const
Definition: GEOObjects.cpp:744
PointVec * getPointVecObj(const std::string &name)
Returns a pointer to a PointVec object for the given name.
Definition: GEOObjects.h:119
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:444
std::function< void(std::string const &)> addSurfaceVecCallback
Definition: GEOObjects.h:318
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
Definition: GEOObjects.cpp:342
void addPolylineVec(std::vector< Polyline * > &&lines, std::string const &name, PolylineVec::NameIdMap &&ply_names)
Definition: GEOObjects.cpp:152
bool appendSurfaceVec(const std::vector< Surface * > &surfaces, const std::string &name)
Definition: GEOObjects.cpp:249
const std::vector< Point * > * getPointVec(const std::string &name) const
Definition: GEOObjects.cpp:72
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()))
Definition: GEOObjects.cpp:47
std::vector< PolylineVec * > const & getPolylines() const
Read access to polylines w/o using a name.
Definition: GEOObjects.h:303
const PointVec * getPointVecObj(const std::string &name) const
Definition: GEOObjects.cpp:85
void renameGeometry(std::string const &old_name, std::string const &new_name)
Definition: GEOObjects.cpp:554
std::function< void(std::string const &)> addPolylineVecCallback
Definition: GEOObjects.h:309
bool removePointVec(const std::string &name)
Definition: GEOObjects.cpp:98
bool isUniquePointVecName(std::string &name) const
Definition: GEOObjects.cpp:311
bool removeSurfaceVec(const std::string &name)
Definition: GEOObjects.cpp:283
void addStationVec(std::vector< Point * > &&stations, std::string &name)
Adds a vector of stations with the given name and colour to GEOObjects.
Definition: GEOObjects.cpp:123
void mergePoints(std::vector< std::string > const &geo_names, std::string &merged_geo_name, std::vector< std::size_t > &pnt_offsets)
Definition: GEOObjects.cpp:397
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
Definition: GEOObjects.h:212
PolylineVec * getPolylineVecObj(const std::string &name)
Returns a pointer to a PolylineVec object for the given name.
Definition: GEOObjects.h:180
const std::vector< Surface * > * getSurfaceVec(const std::string &name) const
Returns the surface vector with the given name as a const.
Definition: GEOObjects.cpp:270
std::vector< PointVec * > _pnt_vecs
Definition: GEOObjects.h:371
std::function< void(std::string const &)> appendPolylineVecCallback
Definition: GEOObjects.h:312
std::vector< PolylineVec * > _ply_vecs
Definition: GEOObjects.h:373
std::unique_ptr< Callbacks > _callbacks
Definition: GEOObjects.h:307
std::vector< PointVec * > const & getPoints() const
Read access to points w/o using a name.
Definition: GEOObjects.h:301
void addSurfaceVec(std::vector< Surface * > &&sfc, const std::string &name, SurfaceVec::NameIdMap &&sfc_names)
Definition: GEOObjects.cpp:240
bool isPntVecUsed(const std::string &name) const
Definition: GEOObjects.cpp:324
const PolylineVec * getPolylineVecObj(const std::string &name) const
Definition: GEOObjects.cpp:206
bool removeStationVec(const std::string &name)
Removes the station vector with the given name from GEOObjects.
Definition: GEOObjects.h:139
int mergeGeometries(std::vector< std::string > const &geo_names, std::string &merged_geo_name)
Definition: GEOObjects.cpp:376
void getStationVectorNames(std::vector< std::string > &names) const
Returns the names of all station vectors.
Definition: GEOObjects.cpp:331
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
Definition: GEOObjects.cpp:189
std::function< void(std::string const &)> removePolylineVecCallback
Definition: GEOObjects.h:315
bool appendPolylineVec(const std::vector< Polyline * > &polylines, const std::string &name)
Definition: GEOObjects.cpp:171
std::function< void(std::string const &)> removeSurfaceVecCallback
Definition: GEOObjects.h:324
std::vector< SurfaceVec * > _sfc_vecs
Definition: GEOObjects.h:375
std::vector< SurfaceVec * > const & getSurfaces() const
Read access to surfaces w/o using a name.
Definition: GEOObjects.h:305
const GeoLib::GeoObject * getGeoObject(const std::string &geo_name, GeoLib::GEOTYPE type, const std::string &geo_obj_name) const
Definition: GEOObjects.cpp:659
const std::vector< GeoLib::Point * > * getStationVec(const std::string &name) const
Returns the station vector with the given name.
Definition: GEOObjects.cpp:133
bool removePolylineVec(const std::string &name)
Definition: GEOObjects.cpp:222
std::string getElementNameByID(const std::string &geometry_name, GeoLib::GEOTYPE type, std::size_t id) const
Definition: GEOObjects.cpp:355
This class manages pointers to Points in a std::vector along with a name. It also handles the deletio...
Definition: PointVec.h:38
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
Definition: TemplateVec.h:40
std::map< std::string, std::size_t > NameIdMap
Definition: TemplateVec.h:43
GEOTYPE
Definition: GeoType.h:27
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:611
virtual void renameGeometry(std::string const &, std::string const &)
Definition: GEOObjects.h:75
virtual void appendSurfaceVec(std::string const &)
Definition: GEOObjects.h:73
virtual void removePolylineVec(std::string const &)
Definition: GEOObjects.h:71
virtual void addSurfaceVec(std::string const &)
Definition: GEOObjects.h:72
virtual void addStationVec(std::string const &)
Definition: GEOObjects.h:67
virtual void removeSurfaceVec(std::string const &)
Definition: GEOObjects.h:74
virtual void appendPolylineVec(std::string const &)
Definition: GEOObjects.h:70
virtual ~Callbacks()=default
virtual void addPointVec(std::string const &)
Definition: GEOObjects.h:65
virtual void removeStationVec(std::string const &)
Definition: GEOObjects.h:68
virtual void removePointVec(std::string const &)
Definition: GEOObjects.h:66
virtual void addPolylineVec(std::string const &)
Definition: GEOObjects.h:69