OGS
GeoLib::Polyline Class Reference

Detailed Description

Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices in the point vector. A polyline consists of at least one line segment. The polyline is specified by the points of the line segments. The class Polyline stores ids of pointers to the points in the _ply_pnt_ids vector.

Definition at line 28 of file Polyline.h.

#include <Polyline.h>

Inheritance diagram for GeoLib::Polyline:
[legend]
Collaboration diagram for GeoLib::Polyline:
[legend]

Classes

class  SegmentIterator

Public Member Functions

 Polyline (const std::vector< Point * > &pnt_vec)
 Polyline (const Polyline &ply)
Polylineoperator= (Polyline const &other)=delete
 ~Polyline () override=default
GEOTYPE getGeoType () const override
 return a geometry type
virtual bool addPoint (std::size_t pnt_id)
virtual bool insertPoint (std::size_t pos, std::size_t pnt_id)
void removePoint (std::size_t pos)
void closePolyline ()
std::size_t getNumberOfPoints () const
std::size_t getNumberOfSegments () const
bool isClosed () const
bool isCoplanar () const
bool isPointIDInPolyline (std::size_t pnt_id) const
std::size_t getPointID (std::size_t const i) const
void setPointID (std::size_t idx, std::size_t id)
const PointgetPoint (std::size_t i) const
 returns the i-th point contained in the polyline
SegmentIterator begin () const
SegmentIterator end () const
std::vector< Point * > const & getPointsVec () const
double getDistanceAlongPolyline (const MathLib::Point3d &pnt, const double epsilon_radius) const
Public Member Functions inherited from GeoLib::GeoObject
virtual ~GeoObject ()=default

Static Public Member Functions

static PolylineconstructPolylineFromSegments (const std::vector< Polyline * > &ply_vec, double prox=0.0)

Protected Member Functions

void reverseOrientation ()
std::vector< std::size_t > const & getPolylinePointIDs () const

Protected Attributes

const std::vector< Point * > & _ply_pnts

Private Member Functions

LineSegment getSegment (std::size_t i) const

Private Attributes

std::vector< std::size_t > _ply_pnt_ids

Friends

class Polygon

Constructor & Destructor Documentation

◆ Polyline() [1/2]

GeoLib::Polyline::Polyline ( const std::vector< Point * > & pnt_vec)
explicit

◆ Polyline() [2/2]

GeoLib::Polyline::Polyline ( const Polyline & ply)

Copy constructor

Parameters
plyPolyline

Definition at line 19 of file Polyline.cpp.

20 : _ply_pnts(ply._ply_pnts), _ply_pnt_ids(ply._ply_pnt_ids)
21{
22}
std::vector< std::size_t > _ply_pnt_ids
Definition Polyline.h:211

References Polyline(), _ply_pnt_ids, and _ply_pnts.

◆ ~Polyline()

GeoLib::Polyline::~Polyline ( )
overridedefault

Member Function Documentation

◆ addPoint()

bool GeoLib::Polyline::addPoint ( std::size_t pnt_id)
virtual

Adds an id of a point at the end of the polyline if and only if the resulting segment won't be empty. The id have to be inside the (internal) _ply_pnts vector the polyline is based on.

Returns
If the point could be added the return value is true. If the addition of the point would result in empty line segment false is returned.

Reimplemented in GeoLib::PolygonWithSegmentMarker, and GeoLib::PolylineWithSegmentMarker.

Definition at line 24 of file Polyline.cpp.

25{
26 if (pnt_id >= _ply_pnts.size())
27 {
28 return false;
29 }
30 std::size_t const n_pnts(_ply_pnt_ids.size());
31
32 // don't insert point if this would result in identical IDs for two adjacent
33 // points
34 if (n_pnts > 0 && _ply_pnt_ids.back() == pnt_id)
35 {
36 return false;
37 }
38
39 _ply_pnt_ids.push_back(pnt_id);
40
41 return true;
42}

References _ply_pnt_ids, and _ply_pnts.

Referenced by GeoLib::PolygonWithSegmentMarker::addPoint(), GeoLib::PolylineWithSegmentMarker::addPoint(), closePolyline(), createPolyline(), insertPoint(), MeshGeoToolsLib::markNodesOutSideOfPolygon(), mergeGeometries(), FileIO::SwmmInterface::readLinksAsPolylines(), FileIO::SwmmInterface::readPolygons(), FileIO::Legacy::readPolylinePointVector(), GeoLib::Polygon::splitPolygonAtIntersection(), and GeoLib::Polygon::splitPolygonAtPoint().

◆ begin()

◆ closePolyline()

void GeoLib::Polyline::closePolyline ( )

Closes a polyline by adding a line segment that connects start- and end-point.

Definition at line 291 of file Polyline.cpp.

292{
293 if (getNumberOfPoints() < 2)
294 {
295 ERR("Polyline::closePolyline(): Input polyline needs to be composed of "
296 "at least three points.");
297 }
298 if (!isClosed())
299 {
301 }
302}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
std::size_t getPointID(std::size_t const i) const
Definition Polyline.cpp:149
std::size_t getNumberOfPoints() const
Definition Polyline.cpp:98
bool isClosed() const
Definition Polyline.cpp:108
virtual bool addPoint(std::size_t pnt_id)
Definition Polyline.cpp:24

References addPoint(), ERR(), getNumberOfPoints(), getPointID(), and isClosed().

Referenced by GEOModels::connectPolylineSegments().

◆ constructPolylineFromSegments()

Polyline * GeoLib::Polyline::constructPolylineFromSegments ( const std::vector< Polyline * > & ply_vec,
double prox = 0.0 )
static

Constructs one polyline from a vector of connected polylines. All polylines in this vector need to reference the same point vector.

Definition at line 179 of file Polyline.cpp.

181{
182 std::size_t nLines = ply_vec.size();
183
184 auto* new_ply = new Polyline(*ply_vec[0]);
185 std::vector<GeoLib::Point*> pnt_vec(new_ply->getPointsVec());
186
187 std::vector<Polyline*> local_ply_vec;
188 for (std::size_t i = 1; i < nLines; i++)
189 {
190 local_ply_vec.push_back(ply_vec[i]);
191 }
192
193 while (!local_ply_vec.empty())
194 {
195 bool ply_found(false);
196 prox *= prox; // square distance once to save time later
197 for (auto it = local_ply_vec.begin(); it != local_ply_vec.end(); ++it)
198 {
199 if (pnt_vec == (*it)->getPointsVec())
200 {
201 std::size_t nPoints((*it)->getNumberOfPoints());
202
203 // if (new_ply->getPointID(0) == (*it)->getPointID(0))
204 if (pointsAreIdentical(pnt_vec, new_ply->getPointID(0),
205 (*it)->getPointID(0), prox))
206 {
207 auto* tmp = new Polyline((*it)->getPointsVec());
208 for (std::size_t k = 0; k < nPoints; k++)
209 {
210 tmp->addPoint((*it)->getPointID(nPoints - k - 1));
211 }
212
213 std::size_t new_ply_size(new_ply->getNumberOfPoints());
214 for (std::size_t k = 1; k < new_ply_size; k++)
215 {
216 tmp->addPoint(new_ply->getPointID(k));
217 }
218 delete new_ply;
219 new_ply = tmp;
220 ply_found = true;
221 }
222 // else if (new_ply->getPointID(0) ==
223 // (*it)->getPointID(nPoints-1))
224 else if (pointsAreIdentical(pnt_vec, new_ply->getPointID(0),
225 (*it)->getPointID(nPoints - 1),
226 prox))
227 {
228 auto* tmp = new Polyline(**it);
229 std::size_t new_ply_size(new_ply->getNumberOfPoints());
230 for (std::size_t k = 1; k < new_ply_size; k++)
231 {
232 tmp->addPoint(new_ply->getPointID(k));
233 }
234 delete new_ply;
235 new_ply = tmp;
236 ply_found = true;
237 }
238 // else if (new_ply->getPointID(new_ply->getNumberOfPoints()-1)
239 // == (*it)->getPointID(0))
240 else if (pointsAreIdentical(
241 pnt_vec,
242 new_ply->getPointID(new_ply->getNumberOfPoints() -
243 1),
244 (*it)->getPointID(0), prox))
245 {
246 for (std::size_t k = 1; k < nPoints; k++)
247 {
248 new_ply->addPoint((*it)->getPointID(k));
249 }
250 ply_found = true;
251 }
252 // else if (new_ply->getPointID(new_ply->getNumberOfPoints()-1)
253 // == (*it)->getPointID(nPoints-1))
254 else if (pointsAreIdentical(
255 pnt_vec,
256 new_ply->getPointID(new_ply->getNumberOfPoints() -
257 1),
258 (*it)->getPointID(nPoints - 1), prox))
259 {
260 for (std::size_t k = 1; k < nPoints; k++)
261 {
262 new_ply->addPoint((*it)->getPointID(nPoints - k - 1));
263 }
264 ply_found = true;
265 }
266 if (ply_found)
267 {
268 local_ply_vec.erase(it);
269 break;
270 }
271 }
272 else
273 {
274 ERR("Error in Polyline::contructPolylineFromSegments() - Line "
275 "segments use different point vectors.");
276 }
277 }
278
279 if (!ply_found)
280 {
281 ERR("Error in Polyline::contructPolylineFromSegments() - Not all "
282 "segments are connected.");
283 delete new_ply;
284 new_ply = nullptr;
285 break;
286 }
287 }
288 return new_ply;
289}
Polyline(const std::vector< Point * > &pnt_vec)
Definition Polyline.cpp:17
bool pointsAreIdentical(const std::vector< Point * > &pnt_vec, std::size_t i, std::size_t j, double prox)
Definition Polyline.cpp:541

References Polyline(), ERR(), and GeoLib::pointsAreIdentical().

Referenced by GEOModels::connectPolylineSegments().

◆ end()

◆ getDistanceAlongPolyline()

double GeoLib::Polyline::getDistanceAlongPolyline ( const MathLib::Point3d & pnt,
const double epsilon_radius ) const

returns the distance along the polyline from the beginning of the polyline

Parameters
pntthe point on the polyline
epsilon_radiusthe epsilon
Returns
the distance along the polyline between the given point and the beginning of the polyline. If the given point is not on the polyine, negative value is returned.

Definition at line 304 of file Polyline.cpp.

306{
307 double dist(-1.0);
308 double lambda;
309 bool found = false;
310 double act_length_of_ply = 0.0;
311 // loop over all line segments of the polyline
312 for (std::size_t k = 0; k < getNumberOfSegments(); k++)
313 {
314 auto const& a = getPoint(k)->asEigenVector3d();
315 auto const& b = getPoint(k + 1)->asEigenVector3d();
316 double const seg_length((b - a).norm());
317 act_length_of_ply += seg_length;
318 // is the orthogonal projection of the j-th node to the
319 // line g(lambda) = _ply->getPoint(k) + lambda * (_ply->getPoint(k+1) -
320 // _ply->getPoint(k)) at the k-th line segment of the polyline, i.e. 0
321 // <= lambda <= 1?
323 *getPoint(k + 1), lambda,
324 dist) <= epsilon_radius)
325 {
326 double const lower_lambda(-epsilon_radius / seg_length);
327 double const upper_lambda(1 + epsilon_radius / seg_length);
328
329 if (lower_lambda <= lambda && lambda <= upper_lambda)
330 {
331 found = true;
332 dist = act_length_of_ply + dist;
333 break;
334 } // end if lambda
335 }
336 } // end line segment loop
337
338 if (!found)
339 {
340 dist = -1.0;
341 }
342 return dist;
343}
const Point * getPoint(std::size_t i) const
returns the i-th point contained in the polyline
Definition Polyline.cpp:168
Eigen::Vector3d const & asEigenVector3d() const
Definition Point3d.h:55
double norm(MatrixOrVector const &x, MathLib::VecNormType type)
Definition LinAlg.h:89
double calcProjPntToLineAndDists(Point3d const &pp, Point3d const &pa, Point3d const &pb, double &lambda, double &d0)
Definition MathTools.cpp:13

References MathLib::Point3d::asEigenVector3d(), MathLib::calcProjPntToLineAndDists(), getNumberOfSegments(), and getPoint().

◆ getGeoType()

GEOTYPE GeoLib::Polyline::getGeoType ( ) const
inlineoverridevirtual

return a geometry type

Implements GeoLib::GeoObject.

Definition at line 94 of file Polyline.h.

94{ return GEOTYPE::POLYLINE; }

References GeoLib::POLYLINE.

◆ getNumberOfPoints()

◆ getNumberOfSegments()

std::size_t GeoLib::Polyline::getNumberOfSegments ( ) const

◆ getPoint()

const Point * GeoLib::Polyline::getPoint ( std::size_t i) const

◆ getPointID()

◆ getPointsVec()

std::vector< Point * > const & GeoLib::Polyline::getPointsVec ( ) const

◆ getPolylinePointIDs()

std::vector< std::size_t > const & GeoLib::Polyline::getPolylinePointIDs ( ) const
inlineprotected

Definition at line 204 of file Polyline.h.

205 {
206 return _ply_pnt_ids;
207 }

References _ply_pnt_ids.

Referenced by GeoLib::Polygon::Polygon().

◆ getSegment()

LineSegment GeoLib::Polyline::getSegment ( std::size_t i) const
private

Definition at line 155 of file Polyline.cpp.

156{
157 assert(i < getNumberOfSegments());
158 return LineSegment(_ply_pnts[_ply_pnt_ids[i]],
159 _ply_pnts[_ply_pnt_ids[i + 1]], false);
160}

References _ply_pnt_ids, _ply_pnts, and getNumberOfSegments().

◆ insertPoint()

bool GeoLib::Polyline::insertPoint ( std::size_t pos,
std::size_t pnt_id )
virtual

Method inserts a new point (that have to be inside the _ply_pnts vector) at the given position in the polyline if and only if the resulting segments won't be empty.

Parameters
posthe position in the polyline, pos have to be a value into the interval [0, number of points)
pnt_idthe id of the new point in the vector of points the polyline is based on
Returns
true if the point could be inserted, else false (if empty line segments would be created).

Reimplemented in GeoLib::PolygonWithSegmentMarker, and GeoLib::PolylineWithSegmentMarker.

Definition at line 44 of file Polyline.cpp.

45{
46 if (pnt_id >= _ply_pnts.size())
47 {
48 return false;
49 }
50 if (pos > _ply_pnt_ids.size())
51 {
52 return false;
53 }
54
55 if (pos == _ply_pnt_ids.size())
56 {
57 return addPoint(pnt_id);
58 }
59
60 // check if inserting pnt_id would result in two identical IDs for adjacent
61 // points
62 if (pos == 0 && pnt_id == _ply_pnt_ids[0])
63 {
64 return false;
65 }
66 if (pos != 0)
67 {
68 if (pos == (_ply_pnt_ids.size() - 1) && pnt_id == _ply_pnt_ids[pos])
69 {
70 return false;
71 }
72 if (pnt_id == _ply_pnt_ids[pos - 1] || pnt_id == _ply_pnt_ids[pos])
73 {
74 return false;
75 }
76 }
77
78 auto const pos_dt(
79 static_cast<std::vector<std::size_t>::difference_type>(pos));
80 auto it(_ply_pnt_ids.begin() + pos_dt);
81 _ply_pnt_ids.insert(it, pnt_id);
82
83 return true;
84}

References _ply_pnt_ids, _ply_pnts, and addPoint().

Referenced by GeoLib::computeAndInsertAllIntersectionPoints(), GeoLib::PolygonWithSegmentMarker::insertPoint(), GeoLib::PolylineWithSegmentMarker::insertPoint(), FileIO::GMSH::GMSHPolygonTree::insertPolyline(), and MeshGeoToolsLib::insertSubSegments().

◆ isClosed()

bool GeoLib::Polyline::isClosed ( ) const

returns true if the polyline is closed

Definition at line 108 of file Polyline.cpp.

109{
110 if (_ply_pnt_ids.size() < 3)
111 {
112 return false;
113 }
114
115 return _ply_pnt_ids.front() == _ply_pnt_ids.back();
116}

References _ply_pnt_ids.

Referenced by closePolyline(), FileIO::createSurface(), FileIO::createSurfaceWithEarClipping(), GeoLib::Polygon::initialise(), main(), anonymous_namespace{BoundaryElementsAlongPolyline.cpp}::modifyEdgeNodeOrdering(), and FileIO::FEFLOWMeshInterface::setMaterialIDs().

◆ isCoplanar()

bool GeoLib::Polyline::isCoplanar ( ) const

returns true if the polyline is coplanar

Definition at line 118 of file Polyline.cpp.

119{
120 std::size_t const n_points(_ply_pnt_ids.size());
121 if (n_points < 4)
122 {
123 return true;
124 }
125
126 GeoLib::Point const& p0(*this->getPoint(0));
127 GeoLib::Point const& p1(*this->getPoint(1));
128 GeoLib::Point const& p2(*this->getPoint(2));
129 for (std::size_t i = 3; i < n_points; ++i)
130 {
131 if (!MathLib::isCoplanar(p0, p1, p2, *this->getPoint(i)))
132 {
133 DBUG(
134 "Point {:d} is not coplanar to the first three points of the "
135 "line.",
136 i);
137 return false;
138 }
139 }
140 return true;
141}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
bool isCoplanar(const MathLib::Point3d &a, const MathLib::Point3d &b, const MathLib::Point3d &c, const MathLib::Point3d &d)
Checks if the four given points are located on a plane.

References _ply_pnt_ids, DBUG(), getPoint(), and MathLib::isCoplanar().

◆ isPointIDInPolyline()

bool GeoLib::Polyline::isPointIDInPolyline ( std::size_t pnt_id) const

Method tests if the given id of a point (within the vector of points the polyline is based on) is inside the polyline.

Parameters
pnt_idthe id of the point
Returns
true if the point is part of the polyline, else false

Definition at line 143 of file Polyline.cpp.

144{
145 return std::find(_ply_pnt_ids.begin(), _ply_pnt_ids.end(), pnt_id) !=
146 _ply_pnt_ids.end();
147}

References _ply_pnt_ids.

Referenced by FileIO::GMSH::GMSHPolygonTree::insertPolyline().

◆ operator=()

Polyline & GeoLib::Polyline::operator= ( Polyline const & other)
delete

References Polyline().

◆ removePoint()

void GeoLib::Polyline::removePoint ( std::size_t pos)

Method removes a point from the polyline. The connecting line segments will be removed and the length of the polyline will be changed.

Parameters
posa valid position within the polyline

Definition at line 86 of file Polyline.cpp.

87{
88 if (pos >= _ply_pnt_ids.size())
89 {
90 return;
91 }
92
93 auto const pos_dt(
94 static_cast<std::vector<std::size_t>::difference_type>(pos));
95 _ply_pnt_ids.erase(_ply_pnt_ids.begin() + pos_dt);
96}

References _ply_pnt_ids.

◆ reverseOrientation()

void GeoLib::Polyline::reverseOrientation ( )
protected

Definition at line 345 of file Polyline.cpp.

346{
347 std::reverse(_ply_pnt_ids.begin(), _ply_pnt_ids.end());
348}

References _ply_pnt_ids.

Referenced by GeoLib::Polygon::ensureCCWOrientation().

◆ setPointID()

void GeoLib::Polyline::setPointID ( std::size_t idx,
std::size_t id )

Changes a point index for one point in a line

Parameters
idxIndex of point in line
idID of point in PointVec object

Definition at line 162 of file Polyline.cpp.

163{
164 assert(idx < _ply_pnt_ids.size());
165 _ply_pnt_ids[idx] = id;
166}

References _ply_pnt_ids.

Referenced by GeoLib::resetPointIDs().

◆ Polygon

friend class Polygon
friend

Definition at line 79 of file Polyline.h.

References Polyline(), and Polygon.

Referenced by GeoLib::Polygon::Polygon(), Polygon, and GeoLib::Polygon::splitPolygonAtPoint().

Member Data Documentation

◆ _ply_pnt_ids

std::vector<std::size_t> GeoLib::Polyline::_ply_pnt_ids
private

◆ _ply_pnts

const std::vector<Point*>& GeoLib::Polyline::_ply_pnts
protected

a reference to the vector of pointers to the geometric points

Definition at line 200 of file Polyline.h.

Referenced by Polyline(), Polyline(), addPoint(), getPoint(), getPointsVec(), getSegment(), insertPoint(), and GeoLib::Polygon::splitPolygonAtIntersection().


The documentation for this class was generated from the following files: