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
28namespace GeoLib
29{
30class PointVec;
31
39class Polyline : public GeoObject
40{
41public:
42 class SegmentIterator final
43 {
44 public:
45 using iterator_category = std::forward_iterator_tag;
47 using difference_type = std::ptrdiff_t;
50
51 explicit SegmentIterator(Polyline const& polyline,
52 std::size_t segment_number);
53
55
56 SegmentIterator() = delete;
57 ~SegmentIterator() = default;
58
60
61 std::size_t getSegmentNumber() const;
62
64
65 LineSegment operator*() const;
66
68
69 bool operator==(SegmentIterator const& other) const;
70
71 bool operator!=(SegmentIterator const& other) const;
72
74 std::vector<GeoLib::Point>::difference_type n);
75
77 std::vector<GeoLib::Point>::difference_type n);
78
80 std::vector<GeoLib::Point>::difference_type n);
81
83 std::vector<GeoLib::Point>::difference_type n);
84
85 private:
87 std::vector<GeoLib::Point*>::size_type _segment_number;
88 };
89
90 friend class Polygon;
94 explicit Polyline(const std::vector<Point*>& pnt_vec);
99 Polyline(const Polyline& ply);
100 Polyline& operator=(Polyline const& other) = delete;
101
102 ~Polyline() override = default;
103
105 GEOTYPE getGeoType() const override { return GEOTYPE::POLYLINE; }
106
115 virtual bool addPoint(std::size_t pnt_id);
116
128 virtual bool insertPoint(std::size_t pos, std::size_t pnt_id);
129
135 void removePoint(std::size_t pos);
136
141 void closePolyline();
142
146 const std::vector<Polyline*>& ply_vec, double prox = 0.0);
147
152 std::size_t getNumberOfPoints() const;
153
154 std::size_t getNumberOfSegments() const;
155
157 bool isClosed() const;
158
160 bool isCoplanar() const;
161
168 bool isPointIDInPolyline(std::size_t pnt_id) const;
169
174 std::size_t getPointID(std::size_t const i) const;
175
181 void setPointID(std::size_t idx, std::size_t id);
182
186 const Point* getPoint(std::size_t i) const;
187
188 SegmentIterator begin() const { return SegmentIterator(*this, 0); }
189
191 {
192 return SegmentIterator(*this, getNumberOfSegments());
193 }
194
195 std::vector<Point*> const& getPointsVec() const;
196
207 const double epsilon_radius) const;
208
209protected:
211 const std::vector<Point*>& _ply_pnts;
212
213 void reverseOrientation();
214
215 std::vector<std::size_t> const& getPolylinePointIDs() const
216 {
217 return _ply_pnt_ids;
218 }
219
220private:
222 std::vector<std::size_t> _ply_pnt_ids;
223
224 LineSegment getSegment(std::size_t i) const;
225};
226
227bool containsEdge(const Polyline& ply, std::size_t id0, std::size_t id1);
228
230void resetPointIDs(Polyline& polyline, std::vector<std::size_t> const& mapping);
231
233void markUsedPoints(Polyline const& polyline, std::vector<bool>& used_points);
234
241bool operator==(Polyline const& lhs, Polyline const& rhs);
242
243bool pointsAreIdentical(const std::vector<Point*>& pnt_vec, std::size_t i,
244 std::size_t j, double prox);
245
247std::unique_ptr<Polyline> createPolyline(GeoLib::PointVec const& points_vec,
248 std::vector<std::size_t>&& point_ids);
249
250} // namespace GeoLib
Definition of the Point class.
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:36
GeoLib::Polyline const * _polyline
Definition Polyline.h:86
std::forward_iterator_tag iterator_category
Definition Polyline.h:45
SegmentIterator & operator++()
Definition Polyline.cpp:392
SegmentIterator operator-(std::vector< GeoLib::Point >::difference_type n)
Definition Polyline.cpp:467
SegmentIterator & operator+=(std::vector< GeoLib::Point >::difference_type n)
Definition Polyline.cpp:419
LineSegment operator*() const
Definition Polyline.cpp:398
SegmentIterator & operator=(SegmentIterator const &rhs)
Definition Polyline.cpp:374
bool operator==(SegmentIterator const &other) const
Definition Polyline.cpp:408
SegmentIterator operator+(std::vector< GeoLib::Point >::difference_type n)
Definition Polyline.cpp:439
std::vector< GeoLib::Point * >::size_type _segment_number
Definition Polyline.h:87
std::size_t getSegmentNumber() const
Definition Polyline.cpp:387
bool operator!=(SegmentIterator const &other) const
Definition Polyline.cpp:413
SegmentIterator & operator-=(std::vector< GeoLib::Point >::difference_type n)
Definition Polyline.cpp:447
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition Polyline.h:40
GEOTYPE getGeoType() const override
return a geometry type
Definition Polyline.h:105
double getDistanceAlongPolyline(const MathLib::Point3d &pnt, const double epsilon_radius) const
Definition Polyline.cpp:315
std::size_t getPointID(std::size_t const i) const
Definition Polyline.cpp:160
~Polyline() override=default
Polyline & operator=(Polyline const &other)=delete
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:190
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:179
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:222
void setPointID(std::size_t idx, std::size_t id)
Definition Polyline.cpp:173
void reverseOrientation()
Definition Polyline.cpp:356
SegmentIterator begin() const
Definition Polyline.h:188
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:211
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
std::vector< std::size_t > const & getPolylinePointIDs() const
Definition Polyline.h:215
bool isCoplanar() const
Definition Polyline.cpp:129
SegmentIterator end() const
Definition Polyline.h:190
void removePoint(std::size_t pos)
Definition Polyline.cpp:97
std::vector< Point * > const & getPointsVec() const
Definition Polyline.cpp:185
bool containsEdge(const Polyline &ply, std::size_t id0, std::size_t id1)
Definition Polyline.cpp:505
bool pointsAreIdentical(const std::vector< Point * > &pnt_vec, std::size_t i, std::size_t j, double prox)
Definition Polyline.cpp:552
void markUsedPoints(Polyline const &polyline, std::vector< bool > &used_points)
Resets the point IDs of the polyline corresponding to the mapping.
Definition Polyline.cpp:490
GEOTYPE
Definition GeoType.h:23
void resetPointIDs(Polyline &polyline, std::vector< std::size_t > const &mapping)
Resets the point IDs of the polyline corresponding to the mapping.
Definition Polyline.cpp:475
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:564