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*>(static_cast<const GEOObjects&>(*this).
122 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
151 void addPolylineVec(std::vector<Polyline*>&& lines,
152 std::string const& name,
153 PolylineVec::NameIdMap&& ply_names);
154
163 bool appendPolylineVec(const std::vector<Polyline*>& polylines,
164 const std::string& name);
165
169 const std::vector<Polyline*>* getPolylineVec(const std::string &name) const;
170
176 const PolylineVec* getPolylineVecObj(const std::string &name) const;
177
179 PolylineVec* getPolylineVecObj(const std::string &name)
180 {
181 return const_cast<PolylineVec*>(static_cast<const GEOObjects&>(*this).
182 getPolylineVecObj(name));
183 }
184
190 bool removePolylineVec(const std::string &name);
191
193 void addSurfaceVec(std::vector<Surface*>&& sfc,
194 const std::string& name,
195 SurfaceVec::NameIdMap&& sfc_names);
196
204 bool appendSurfaceVec(const std::vector<Surface*>& surfaces,
205 const std::string& name);
206
208 const std::vector<Surface*>* getSurfaceVec(const std::string &name) const;
209
211 SurfaceVec* getSurfaceVecObj(const std::string &name)
212 {
213 return const_cast<SurfaceVec*>(static_cast<const GEOObjects&>(*this).
214 getSurfaceVecObj(name));
215 }
216
218 bool removeSurfaceVec(const std::string &name);
225 const SurfaceVec* getSurfaceVecObj(const std::string &name) const;
226
228 std::vector<std::string> getGeometryNames() const;
229
230 std::string getElementNameByID(const std::string& geometry_name,
231 GeoLib::GEOTYPE type, std::size_t id) const;
232
234 void getStationVectorNames(std::vector<std::string>& names) const;
235
243 bool isUniquePointVecName(std::string &name) const;
244
252 int mergeGeometries(std::vector<std::string> const& geo_names,
253 std::string& merged_geo_name);
254
259 void renameGeometry(std::string const& old_name,
260 std::string const& new_name);
261
263 const GeoLib::GeoObject* getGeoObject(const std::string &geo_name,
264 GeoLib::GEOTYPE type,
265 const std::string &geo_obj_name) const;
266
268 // It is required that a tuple is a unique key for a geometric object!
269 // If there is another geo object with same name one of them is returned.
270 // In theory different types of geometric objects can have the same name.
271 // For instance it is possible that a point object and a polyline object
272 // share the same name. If there exists several objects sharing the same
273 // name the first object found will be returned.
274 // @param geo_name name of geometry
275 // @param geo_obj_name name of the geo object
276 GeoLib::GeoObject const* getGeoObject(const std::string &geo_name,
277 const std::string &geo_obj_name) const;
278
282 ~GEOObjects();
283
286 std::size_t exists(const std::string &geometry_name) const;
287
289 bool isPntVecUsed (const std::string &name) const;
290
292 std::vector<PointVec*> const& getPoints() const { return _pnt_vecs; }
294 std::vector<PolylineVec*> const& getPolylines() const { return _ply_vecs; }
296 std::vector<SurfaceVec*> const& getSurfaces() const { return _sfc_vecs; }
297
298 std::unique_ptr<Callbacks> _callbacks{new Callbacks};
299
300 std::function<void(std::string const&)> addPolylineVecCallback =
301 [](std::string const& /*unused*/) {};
302
303 std::function<void(std::string const&)> appendPolylineVecCallback =
304 [](std::string const& /*unused*/) {};
305
306 std::function<void(std::string const&)> removePolylineVecCallback =
307 [](std::string const& /*unused*/) {};
308
309 std::function<void(std::string const&)> addSurfaceVecCallback =
310 [](std::string const& /*unused*/) {};
311
312 std::function<void(std::string const&)> appendSurfaceVecCallback =
313 [](std::string const& /*unused*/) {};
314
315 std::function<void(std::string const&)> removeSurfaceVecCallback =
316 [](std::string const& /*unused*/) {};
317
318private:
327 void mergePoints(std::vector<std::string> const& geo_names,
328 std::string& merged_geo_name,
329 std::vector<std::size_t>& pnt_offsets);
330
343 void mergePolylines(std::vector<std::string> const& geo_names,
344 std::string const& merged_geo_name,
345 std::vector<std::size_t> const& pnt_offsets);
346
357 void mergeSurfaces(std::vector<std::string> const& geo_names,
358 std::string const& merged_geo_name,
359 std::vector<std::size_t> const& pnt_offsets);
360
362 std::vector<PointVec*> _pnt_vecs;
364 std::vector<PolylineVec*> _ply_vecs;
366 std::vector<SurfaceVec*> _sfc_vecs;
367};
368
370// @param geo_obj geometry manager object
371// @param geo_name name of the geometry
372// @param stn_name name of the new station vector
373// @param only_usused_pnts if true only points not in a line or surface are
374// transferred, otherwise all points
375int geoPointsToStations(GEOObjects& geo_objects, std::string const& geo_name,
376 std::string& stn_name,
377 bool const only_unused_pnts = true);
378} // 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:312
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:309
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:294
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:300
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:211
PolylineVec * getPolylineVecObj(const std::string &name)
Returns a pointer to a PolylineVec object for the given name.
Definition: GEOObjects.h:179
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:362
std::function< void(std::string const &)> appendPolylineVecCallback
Definition: GEOObjects.h:303
std::vector< PolylineVec * > _ply_vecs
Definition: GEOObjects.h:364
std::unique_ptr< Callbacks > _callbacks
Definition: GEOObjects.h:298
std::vector< PointVec * > const & getPoints() const
Read access to points w/o using a name.
Definition: GEOObjects.h:292
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
Checks if the point vector with the given name is referenced in a polyline- or surface vector.
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:306
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:315
std::vector< SurfaceVec * > _sfc_vecs
Definition: GEOObjects.h:366
std::vector< SurfaceVec * > const & getSurfaces() const
Read access to surfaces w/o using a name.
Definition: GEOObjects.h:296
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: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:41
std::map< std::string, std::size_t > NameIdMap
Definition: TemplateVec.h:44
GEOTYPE
Definition: GeoType.h:25
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