OGS
Polyline.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 #include <cmath>
18 #include <vector>
19 
20 // GeoLib
21 #include "GeoObject.h"
22 #include "LineSegment.h"
23 #include "Point.h"
24 
25 // MathLib
26 #include "MathLib/Point3d.h"
27 
28 namespace GeoLib
29 {
30 class PointVec;
31 
32 enum class Location
33 {
34  LEFT,
35  RIGHT,
36  BEYOND,
37  BEHIND,
38  BETWEEN,
39  SOURCE,
41 };
42 
52 class Polyline : public GeoObject
53 {
54 public:
55  class SegmentIterator final
56  : public std::iterator<std::forward_iterator_tag, LineSegment>
57  {
58  public:
59  explicit SegmentIterator(Polyline const& polyline,
60  std::size_t segment_number);
61 
62  SegmentIterator(SegmentIterator const& src);
63 
64  SegmentIterator() = delete;
65  ~SegmentIterator() = default;
66 
68 
69  std::size_t getSegmentNumber() const;
70 
72 
73  LineSegment operator*() const;
74 
76 
77  bool operator==(SegmentIterator const& other) const;
78 
79  bool operator!=(SegmentIterator const& other) const;
80 
81  SegmentIterator& operator+=(std::vector<GeoLib::Point>::difference_type n);
82 
83  SegmentIterator operator+(std::vector<GeoLib::Point>::difference_type n);
84 
85  SegmentIterator& operator-=(std::vector<GeoLib::Point>::difference_type n);
86 
87  SegmentIterator operator-(std::vector<GeoLib::Point>::difference_type n);
88 
89  private:
91  std::vector<GeoLib::Point*>::size_type _segment_number;
92  };
93 
94  friend class Polygon;
98  explicit Polyline(const std::vector<Point*>& pnt_vec);
103  Polyline(const Polyline& ply);
104  Polyline& operator=(Polyline const& other) = delete;
105 
106  ~Polyline() override = default;
107 
109  GEOTYPE getGeoType() const override { return GEOTYPE::POLYLINE; }
110 
119  virtual bool addPoint(std::size_t pnt_id);
120 
132  virtual bool insertPoint(std::size_t pos, std::size_t pnt_id);
133 
139  void removePoint(std::size_t pos);
140 
144  void closePolyline();
145 
148  static Polyline* constructPolylineFromSegments(const std::vector<Polyline*> &ply_vec,
149  double prox = 0.0);
150 
155  std::size_t getNumberOfPoints() const;
156 
157  std::size_t getNumberOfSegments() const;
158 
160  bool isClosed() const;
161 
163  bool isCoplanar() const;
164 
171  bool isPointIDInPolyline(std::size_t pnt_id) const;
172 
177  std::size_t getPointID(std::size_t i) const;
178 
184  void setPointID(std::size_t idx, std::size_t id);
185 
189  const Point* getPoint(std::size_t i) const;
190 
192  {
193  return SegmentIterator(*this, 0);
194  }
195 
197  {
198  return SegmentIterator(*this, getNumberOfSegments());
199  }
200 
201  std::vector<Point*> const& getPointsVec () const;
202 
210  double getDistanceAlongPolyline(const MathLib::Point3d& pnt,
211  const double epsilon_radius) const;
212 
213 protected:
223  Location getLocationOfPoint(std::size_t k,
224  MathLib::Point3d const& pnt) const;
225 
227  const std::vector<Point*> &_ply_pnts;
229  std::vector<std::size_t> _ply_pnt_ids;
230 
231 private:
232  LineSegment getSegment(std::size_t i) const;
233  LineSegment getSegment(std::size_t i);
234 };
235 
236 bool containsEdge (const Polyline& ply, std::size_t id0, std::size_t id1);
237 
244 bool operator==(Polyline const& lhs, Polyline const& rhs);
245 
246 bool pointsAreIdentical(const std::vector<Point*> &pnt_vec, std::size_t i, std::size_t j,
247  double prox);
248 
250 std::unique_ptr<Polyline> createPolyline(GeoLib::PointVec const& points_vec,
251  std::vector<std::size_t>&& point_ids);
252 } // namespace GeoLib
Base class for classes Point, Polyline, Surface.
Definition of the Point3d class.
This class manages pointers to Points in a std::vector along with a name. It also handles the deletio...
Definition: PointVec.h:38
GeoLib::Polyline const * _polyline
Definition: Polyline.h:90
SegmentIterator & operator++()
Definition: Polyline.cpp:437
SegmentIterator operator-(std::vector< GeoLib::Point >::difference_type n)
Definition: Polyline.cpp:512
SegmentIterator & operator+=(std::vector< GeoLib::Point >::difference_type n)
Definition: Polyline.cpp:464
LineSegment operator*() const
Definition: Polyline.cpp:443
SegmentIterator & operator=(SegmentIterator const &rhs)
Definition: Polyline.cpp:419
bool operator==(SegmentIterator const &other) const
Definition: Polyline.cpp:453
SegmentIterator operator+(std::vector< GeoLib::Point >::difference_type n)
Definition: Polyline.cpp:484
std::vector< GeoLib::Point * >::size_type _segment_number
Definition: Polyline.h:91
std::size_t getSegmentNumber() const
Definition: Polyline.cpp:432
bool operator!=(SegmentIterator const &other) const
Definition: Polyline.cpp:458
SegmentIterator & operator-=(std::vector< GeoLib::Point >::difference_type n)
Definition: Polyline.cpp:492
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition: Polyline.h:53
GEOTYPE getGeoType() const override
return a geometry type
Definition: Polyline.h:109
double getDistanceAlongPolyline(const MathLib::Point3d &pnt, const double epsilon_radius) const
Definition: Polyline.cpp:363
~Polyline() override=default
std::size_t getPointID(std::size_t i) const
Definition: Polyline.cpp:160
std::size_t getNumberOfSegments() const
Definition: Polyline.cpp:114
static Polyline * constructPolylineFromSegments(const std::vector< Polyline * > &ply_vec, double prox=0.0)
Definition: Polyline.cpp:197
std::size_t getNumberOfPoints() const
Definition: Polyline.cpp:109
const Point * getPoint(std::size_t i) const
returns the i-th point contained in the polyline
Definition: Polyline.cpp:186
virtual bool insertPoint(std::size_t pos, std::size_t pnt_id)
Definition: Polyline.cpp:55
std::vector< std::size_t > _ply_pnt_ids
Definition: Polyline.h:229
void setPointID(std::size_t idx, std::size_t id)
Definition: Polyline.cpp:180
SegmentIterator begin() const
Definition: Polyline.h:191
bool isClosed() const
Definition: Polyline.cpp:119
virtual bool addPoint(std::size_t pnt_id)
Definition: Polyline.cpp:35
const std::vector< Point * > & _ply_pnts
Definition: Polyline.h:227
Polyline & operator=(Polyline const &other)=delete
void closePolyline()
Definition: Polyline.cpp:309
Location getLocationOfPoint(std::size_t k, MathLib::Point3d const &pnt) const
Definition: Polyline.cpp:322
LineSegment getSegment(std::size_t i) const
Definition: Polyline.cpp:166
Polyline(const std::vector< Point * > &pnt_vec)
Definition: Polyline.cpp:28
bool isPointIDInPolyline(std::size_t pnt_id) const
Definition: Polyline.cpp:154
bool isCoplanar() const
Definition: Polyline.cpp:129
SegmentIterator end() const
Definition: Polyline.h:196
void removePoint(std::size_t pos)
Definition: Polyline.cpp:97
std::vector< Point * > const & getPointsVec() const
Definition: Polyline.cpp:192
GEOTYPE
Definition: GeoType.h:25
bool containsEdge(const Polyline &ply, std::size_t id0, std::size_t id1)
Definition: Polyline.cpp:520
bool pointsAreIdentical(const std::vector< Point * > &pnt_vec, std::size_t i, std::size_t j, double prox)
Definition: Polyline.cpp:567
Location
Definition: Polyline.h:33
bool operator==(LineSegment const &s0, LineSegment const &s1)
std::unique_ptr< Polyline > createPolyline(GeoLib::PointVec const &points_vec, std::vector< std::size_t > &&point_ids)
Create a polyline from given point ids.
Definition: Polyline.cpp:579