OGS
GEOObjects.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 #include <map>
18 #include <functional>
19 #include <string>
20 #include <vector>
21 
22 #include "Point.h"
23 #include "PointVec.h"
24 #include "Polyline.h"
25 #include "PolylineVec.h"
26 #include "Surface.h"
27 #include "SurfaceVec.h"
28 #include "GeoType.h"
29 
30 namespace GeoLib
31 {
33 
60 class GEOObjects final
61 {
62 public:
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 
82 public:
90  void addPointVec(
91  std::unique_ptr<std::vector<Point*>> points,
92  std::string& name,
93  std::unique_ptr<std::map<std::string, std::size_t>> pnt_id_name_map =
94  nullptr,
95  double eps = std::sqrt(std::numeric_limits<double>::epsilon()));
96 
100  const std::vector<Point*>* getPointVec(const std::string &name) const;
101 
107  const PointVec* getPointVecObj(const std::string &name) const;
108 
110  PointVec* getPointVecObj(const std::string &name)
111  {
112  return const_cast<PointVec*>(static_cast<const GEOObjects&>(*this).
114  }
115 
120  bool removePointVec(const std::string &name);
121 
123  void addStationVec(
124  std::unique_ptr<std::vector<Point *>> stations, std::string &name);
125 
127  const std::vector<GeoLib::Point*>* getStationVec(
128  const std::string& name) const;
129 
131  bool removeStationVec(const std::string &name)
132  {
133  _callbacks->removeStationVec(name);
134  return removePointVec(name);
135  }
136 
143  void addPolylineVec(std::unique_ptr<std::vector<Polyline*>> lines,
144  const std::string& name,
145  std::unique_ptr<std::map<std::string, std::size_t>>
146  ply_names = nullptr);
147 
156  bool appendPolylineVec(const std::vector<Polyline*> &polylines,
157  const std::string &name);
158 
162  const std::vector<Polyline*>* getPolylineVec(const std::string &name) const;
163 
169  const PolylineVec* getPolylineVecObj(const std::string &name) const;
170 
172  PolylineVec* getPolylineVecObj(const std::string &name)
173  {
174  return const_cast<PolylineVec*>(static_cast<const GEOObjects&>(*this).
176  }
177 
183  bool removePolylineVec(const std::string &name);
184 
186  void addSurfaceVec(std::unique_ptr<std::vector<Surface*>> sfc,
187  const std::string& name,
188  std::unique_ptr<std::map<std::string, std::size_t>>
189  sfc_names = nullptr);
190 
198  bool appendSurfaceVec(const std::vector<Surface*>& surfaces,
199  const std::string& name);
200 
202  const std::vector<Surface*>* getSurfaceVec(const std::string &name) const;
203 
205  SurfaceVec* getSurfaceVecObj(const std::string &name)
206  {
207  return const_cast<SurfaceVec*>(static_cast<const GEOObjects&>(*this).
209  }
210 
212  bool removeSurfaceVec(const std::string &name);
219  const SurfaceVec* getSurfaceVecObj(const std::string &name) const;
220 
222  std::vector<std::string> getGeometryNames() const;
223 
224  std::string getElementNameByID(const std::string& geometry_name,
225  GeoLib::GEOTYPE type, std::size_t id) const;
226 
228  void getStationVectorNames(std::vector<std::string>& names) const;
229 
237  bool isUniquePointVecName(std::string &name) const;
238 
246  int mergeGeometries(std::vector<std::string> const& geo_names,
247  std::string& merged_geo_name);
248 
253  void renameGeometry(std::string const& old_name,
254  std::string const& new_name);
255 
257  const GeoLib::GeoObject* getGeoObject(const std::string &geo_name,
258  GeoLib::GEOTYPE type,
259  const std::string &geo_obj_name) const;
260 
262  // It is required that a tuple is a unique key for a geometric object!
263  // If there is another geo object with same name one of them is returned.
264  // In theory different types of geometric objects can have the same name.
265  // For instance it is possible that a point object and a polyline object
266  // share the same name. If there exists several objects sharing the same
267  // name the first object found will be returned.
268  // @param geo_name name of geometry
269  // @param geo_obj_name name of the geo object
270  GeoLib::GeoObject const* getGeoObject(const std::string &geo_name,
271  const std::string &geo_obj_name) const;
272 
276  ~GEOObjects();
277 
280  std::size_t exists(const std::string &geometry_name) const;
281 
283  bool isPntVecUsed (const std::string &name) const;
284 
286  std::vector<PointVec*> const& getPoints() const { return _pnt_vecs; }
288  std::vector<PolylineVec*> const& getPolylines() const { return _ply_vecs; }
290  std::vector<SurfaceVec*> const& getSurfaces() const { return _sfc_vecs; }
291 
295  std::vector<PointVec*> _pnt_vecs;
296 
298  std::vector<PolylineVec*> _ply_vecs;
300  std::vector<SurfaceVec*> _sfc_vecs;
301 
302  std::unique_ptr<Callbacks> _callbacks{new Callbacks};
303 
304  std::function<void(std::string const&)> addPolylineVecCallback =
305  [](std::string const& /*unused*/) {};
306 
307  std::function<void(std::string const&)> appendPolylineVecCallback =
308  [](std::string const& /*unused*/) {};
309 
310  std::function<void(std::string const&)> removePolylineVecCallback =
311  [](std::string const& /*unused*/) {};
312 
313  std::function<void(std::string const&)> addSurfaceVecCallback =
314  [](std::string const& /*unused*/) {};
315 
316  std::function<void(std::string const&)> appendSurfaceVecCallback =
317  [](std::string const& /*unused*/) {};
318 
319  std::function<void(std::string const&)> removeSurfaceVecCallback =
320  [](std::string const& /*unused*/) {};
321 
322 private:
332  bool 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 };
366 
368 // @param geo_obj geometry manager object
369 // @param geo_name name of the geometry
370 // @param stn_name name of the new station vector
371 // @param only_usused_pnts if true only points not in a line or surface are
372 // transferred, otherwise all points
373 int geoPointsToStations(GEOObjects& geo_objects, std::string const& geo_name,
374  std::string& stn_name,
375  bool const only_unused_pnts = true);
376 
377 } // 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:571
std::function< void(std::string const &)> appendSurfaceVecCallback
Definition: GEOObjects.h:316
std::vector< PointVec * > const & getPoints() const
Read access to points w/o using a name.
Definition: GEOObjects.h:286
std::size_t exists(const std::string &geometry_name) const
Definition: GEOObjects.cpp:831
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:512
std::function< void(std::string const &)> addSurfaceVecCallback
Definition: GEOObjects.h:313
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
Definition: GEOObjects.cpp:401
bool appendSurfaceVec(const std::vector< Surface * > &surfaces, const std::string &name)
Definition: GEOObjects.cpp:272
void addStationVec(std::unique_ptr< std::vector< Point * >> stations, std::string &name)
Adds a vector of stations with the given name and colour to GEOObjects.
Definition: GEOObjects.cpp:122
void addSurfaceVec(std::unique_ptr< std::vector< Surface * >> sfc, const std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> sfc_names=nullptr)
Definition: GEOObjects.cpp:261
const std::vector< Point * > * getPointVec(const std::string &name) const
Definition: GEOObjects.cpp:71
PolylineVec * getPolylineVecObj(const std::string &name)
Returns a pointer to a PolylineVec object for the given name.
Definition: GEOObjects.h:172
const PointVec * getPointVecObj(const std::string &name) const
Definition: GEOObjects.cpp:84
void renameGeometry(std::string const &old_name, std::string const &new_name)
Definition: GEOObjects.cpp:630
bool mergePoints(std::vector< std::string > const &geo_names, std::string &merged_geo_name, std::vector< std::size_t > &pnt_offsets)
Definition: GEOObjects.cpp:459
std::function< void(std::string const &)> addPolylineVecCallback
Definition: GEOObjects.h:304
bool removePointVec(const std::string &name)
Definition: GEOObjects.cpp:97
bool isUniquePointVecName(std::string &name) const
Definition: GEOObjects.cpp:356
bool removeSurfaceVec(const std::string &name)
Definition: GEOObjects.cpp:323
void addPointVec(std::unique_ptr< std::vector< Point * >> points, std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> pnt_id_name_map=nullptr, double eps=std::sqrt(std::numeric_limits< double >::epsilon()))
Definition: GEOObjects.cpp:51
std::vector< SurfaceVec * > const & getSurfaces() const
Read access to surfaces w/o using a name.
Definition: GEOObjects.h:290
const std::vector< Surface * > * getSurfaceVec(const std::string &name) const
Returns the surface vector with the given name as a const.
Definition: GEOObjects.cpp:307
std::vector< PointVec * > _pnt_vecs
Definition: GEOObjects.h:295
std::function< void(std::string const &)> appendPolylineVecCallback
Definition: GEOObjects.h:307
std::vector< PolylineVec * > _ply_vecs
Definition: GEOObjects.h:298
std::unique_ptr< Callbacks > _callbacks
Definition: GEOObjects.h:302
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
Definition: GEOObjects.h:205
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:369
const PolylineVec * getPolylineVecObj(const std::string &name) const
Definition: GEOObjects.cpp:227
bool removeStationVec(const std::string &name)
Removes the station vector with the given name from GEOObjects.
Definition: GEOObjects.h:131
int mergeGeometries(std::vector< std::string > const &geo_names, std::string &merged_geo_name)
Definition: GEOObjects.cpp:435
void getStationVectorNames(std::vector< std::string > &names) const
Returns the names of all station vectors.
Definition: GEOObjects.cpp:390
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
Definition: GEOObjects.cpp:210
std::function< void(std::string const &)> removePolylineVecCallback
Definition: GEOObjects.h:310
void addPolylineVec(std::unique_ptr< std::vector< Polyline * >> lines, const std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> ply_names=nullptr)
Definition: GEOObjects.cpp:150
bool appendPolylineVec(const std::vector< Polyline * > &polylines, const std::string &name)
Definition: GEOObjects.cpp:180
std::function< void(std::string const &)> removeSurfaceVecCallback
Definition: GEOObjects.h:319
std::vector< SurfaceVec * > _sfc_vecs
Definition: GEOObjects.h:300
PointVec * getPointVecObj(const std::string &name)
Returns a pointer to a PointVec object for the given name.
Definition: GEOObjects.h:110
std::vector< PolylineVec * > const & getPolylines() const
Read access to polylines w/o using a name.
Definition: GEOObjects.h:288
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:746
const std::vector< GeoLib::Point * > * getStationVec(const std::string &name) const
Returns the station vector with the given name.
Definition: GEOObjects.cpp:131
bool removePolylineVec(const std::string &name)
Definition: GEOObjects.cpp:243
std::string getElementNameByID(const std::string &geometry_name, GeoLib::GEOTYPE type, std::size_t id) const
Definition: GEOObjects.cpp:414
This class manages pointers to Points in a std::vector along with a name. It also handles the deletin...
Definition: PointVec.h:39
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
Definition: TemplateVec.h:40
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:698
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