SUMO - Simulation of Urban MObility
PositionVector.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // A list of positions
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef PositionVector_h
23 #define PositionVector_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <vector>
36 #include <limits>
37 #include "AbstractPoly.h"
38 
39 
40 // ===========================================================================
41 // class declarations
42 // ===========================================================================
43 
44 class Boundary;
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
53 class PositionVector : public AbstractPoly, private std::vector<Position> {
54 
55 private:
57  typedef std::vector<Position> vp;
58 
59 public:
62 
65  PositionVector(const std::vector<Position>& v);
66 
70  PositionVector(const std::vector<Position>::const_iterator beg, const std::vector<Position>::const_iterator end);
71 
75  PositionVector(const Position& p1, const Position& p2);
76 
79 
83  using vp::iterator;
84 
86  using vp::const_iterator;
87 
89  using vp::const_reference;
90 
92  using vp::value_type;
93 
95  using vp::begin;
96 
98  using vp::end;
99 
101  using vp::push_back;
102 
104  using vp::pop_back;
105 
107  using vp::clear;
109  using vp::size;
110 
112  using vp::front;
113 
115  using vp::back;
116 
118  using vp::reference;
119 
121  using vp::erase;
122 
124  using vp::insert;
126 
129  bool around(const Position& p, SUMOReal offset = 0) const;
130 
133  bool overlapsWith(const AbstractPoly& poly, SUMOReal offset = 0) const;
134 
136  SUMOReal getOverlapWith(const PositionVector& poly, SUMOReal zThreshold) const;
137 
139  bool intersects(const Position& p1, const Position& p2) const;
140 
142  bool intersects(const PositionVector& v1) const;
143 
145  Position intersectionPosition2D(const Position& p1, const Position& p2, const SUMOReal withinDist = 0.) const;
146 
148  std::vector<SUMOReal> intersectsAtLengths2D(const PositionVector& other) const;
149 
151  std::vector<SUMOReal> intersectsAtLengths2D(const Position& lp1, const Position& lp2) const;
152 
155 
157  void closePolygon();
158 
161  const Position& operator[](int index) const;
162 
165  Position& operator[](int index);
166 
168  Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset = 0) const;
169 
171  Position positionAtOffset2D(SUMOReal pos, SUMOReal lateralOffset = 0) const;
172 
175 
178 
181 
183  static Position positionAtOffset(const Position& p1, const Position& p2, SUMOReal pos, SUMOReal lateralOffset = 0.);
184 
186  static Position positionAtOffset2D(const Position& p1, const Position& p2, SUMOReal pos, SUMOReal lateralOffset = 0.);
187 
189  Boundary getBoxBoundary() const;
190 
193  Position getPolygonCenter() const;
194 
196  Position getCentroid() const;
197 
199  void scaleRelative(SUMOReal factor);
200 
202  void scaleAbsolute(SUMOReal offset);
203 
205  Position getLineCenter() const;
206 
208  SUMOReal length() const;
209 
211  SUMOReal length2D() const;
212 
214  SUMOReal area() const;
215 
217  bool partialWithin(const AbstractPoly& poly, SUMOReal offset = 0) const;
218 
220  std::pair<PositionVector, PositionVector> splitAt(SUMOReal where) const;
221 
223  friend std::ostream& operator<<(std::ostream& os, const PositionVector& geom);
224 
226  bool crosses(const Position& p1, const Position& p2) const;
227 
229  void add(SUMOReal xoff, SUMOReal yoff, SUMOReal zoff);
230 
232  void add(const Position& offset);
233 
235  void mirrorX();
236 
238  void rotate2D(SUMOReal angle);
239 
241  PositionVector convexHull() const;
242 
244  void append(const PositionVector& v, SUMOReal sameThreshold = 2.0);
245 
247  PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const;
248 
250  PositionVector getSubpart2D(SUMOReal beginOffset, SUMOReal endOffset) const;
251 
253  PositionVector getSubpartByIndex(int beginIndex, int count) const;
254 
256  void sortAsPolyCWByAngle();
257 
259  void sortByIncreasingXY();
260 
262  void extrapolate(const SUMOReal val, const bool onlyFirst = false);
263 
265  void extrapolate2D(const SUMOReal val, const bool onlyFirst = false);
266 
268  PositionVector reverse() const;
269 
271  static Position sideOffset(const Position& beg, const Position& end, const SUMOReal amount);
272 
274  void move2side(SUMOReal amount);
275 
277  SUMOReal angleAt2D(int pos) const;
278 
280  int insertAtClosest(const Position& p);
281 
283  int removeClosest(const Position& p);
284 
286  bool operator==(const PositionVector& v2) const;
287 
290  public:
293 
295  int operator()(const Position& p1, const Position& p2) const;
296  };
297 
300  public:
302  explicit increasing_x_y_sorter();
303 
305  int operator()(const Position& p1, const Position& p2) const;
306  };
307 
310  SUMOReal isLeft(const Position& P0, const Position& P1, const Position& P2) const;
311 
313  SUMOReal beginEndAngle() const;
314 
316  SUMOReal nearest_offset_to_point2D(const Position& p, bool perpendicular = true) const;
317 
325  Position transformToVectorCoordinates(const Position& p, bool extend = false) const;
326 
329  int indexOfClosest(const Position& p) const;
330 
333  std::vector<SUMOReal> distances(const PositionVector& s, bool perpendicular = false) const;
334 
336  SUMOReal distance2D(const Position& p, bool perpendicular = false) const;
337 
339  void push_back_noDoublePos(const Position& p);
340 
342  void push_front_noDoublePos(const Position& p);
343 
345  bool isClosed() const;
346 
351  void removeDoublePoints(SUMOReal minDist = POSITION_EPS, bool assertLength = false);
352 
354  bool hasElevation() const;
355 
357  PositionVector simplified() const;
358 
364  PositionVector getOrthogonal(const Position& p, SUMOReal extend, SUMOReal& distToClosest) const;
365 
366 
369 
371  SUMOReal offsetAtIndex2D(int index) const;
372 
374  SUMOReal getMaxGrade() const;
375 
376 private:
378  static bool intersects(const Position& p11, const Position& p12, const Position& p21, const Position& p22, const SUMOReal withinDist = 0., SUMOReal* x = 0, SUMOReal* y = 0, SUMOReal* mu = 0);
379 };
380 
381 
382 #endif
383 
384 /****************************************************************************/
385 
clase for increasing Sorter
static Position sideOffset(const Position &beg, const Position &end, const SUMOReal amount)
get a side position of position vector using a offset
bool hasElevation() const
return whether two positions differ in z-coordinate
SUMOReal rotationAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
SUMOReal nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
PositionVector getSubpart2D(SUMOReal beginOffset, SUMOReal endOffset) const
get subpart of a position vector in two dimensions (Z is ignored)
void sortAsPolyCWByAngle()
short as polygon CV by angle
PositionVector getOrthogonal(const Position &p, SUMOReal extend, SUMOReal &distToClosest) const
return orthogonal through p (extending this vector if necessary)
friend std::ostream & operator<<(std::ostream &os, const PositionVector &geom)
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
bool intersects(const Position &p1, const Position &p2) const
Returns the information whether this list of points interesects the given line.
void scaleRelative(SUMOReal factor)
enlarges/shrinks the polygon by a factor based at the centroid
SUMOReal getOverlapWith(const PositionVector &poly, SUMOReal zThreshold) const
Returns the maximum overlaps between this and the given polygon (when not separated by at least zThre...
PositionVector getSubpartByIndex(int beginIndex, int count) const
get subpart of a position vector using index and a cout
bool partialWithin(const AbstractPoly &poly, SUMOReal offset=0) const
Returns the information whether this polygon lies partially within the given polygon.
bool around(const Position &p, SUMOReal offset=0) const
Returns the information whether the position vector describes a polygon lying around the given point...
SUMOReal beginEndAngle() const
returns the angle in radians of the line connecting the first and the last position ...
bool isClosed() const
check if PositionVector is closed
const Position & operator[](int index) const
returns the constat position at the given index !!! exceptions?
Position positionAtOffset2D(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
SUMOReal distance2D(const Position &p, bool perpendicular=false) const
closest 2D-distance to point p (or -1 if perpendicular is true and the point is beyond this vector) ...
PositionVector reverse() const
reverse position vector
SUMOReal slopeDegreeAtOffset(SUMOReal pos) const
Returns the slope at the given length.
void rotate2D(SUMOReal angle)
PositionVector convexHull() const
~PositionVector()
Destructor.
void extrapolate2D(const SUMOReal val, const bool onlyFirst=false)
extrapolate position vector in two dimensions (Z is ignored)
SUMOReal length2D() const
Returns the length.
std::vector< SUMOReal > distances(const PositionVector &s, bool perpendicular=false) const
distances of all my points to s and all of s points to myself
void push_front_noDoublePos(const Position &p)
insert in front a non double position
#define max(a, b)
Definition: polyfonts.c:65
PositionVector simplified() const
return the same shape with intermediate colinear points removed
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
std::vector< Position > vp
vector of position
A list of positions.
void add(SUMOReal xoff, SUMOReal yoff, SUMOReal zoff)
int indexOfClosest(const Position &p) const
index of the closest position to p
int operator()(const Position &p1, const Position &p2) const
comparing operation for sort
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
#define POSITION_EPS
Definition: config.h:182
int insertAtClosest(const Position &p)
inserts p between the two closest positions and returns the insertion index
void sortByIncreasingXY()
shory by increasing X-Y Psitions
bool operator==(const PositionVector &v2) const
comparing operation
std::pair< PositionVector, PositionVector > splitAt(SUMOReal where) const
Returns the two lists made when this list vector is splitted at the given point.
PositionVector()
Constructor. Creates an empty position vector.
SUMOReal length() const
Returns the length.
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
void removeDoublePoints(SUMOReal minDist=POSITION_EPS, bool assertLength=false)
Removes positions if too near.
PositionVector smoothedZFront(SUMOReal dist=std::numeric_limits< SUMOReal >::max()) const
returned vector that is smoothed at the front (within dist)
SUMOReal offsetAtIndex2D(int index) const
return the offset at the given index
SUMOReal angleAt2D(int pos) const
get angle in certain position of position vector
void scaleAbsolute(SUMOReal offset)
enlarges/shrinks the polygon by an absolute offset based at the centroid
bool overlapsWith(const AbstractPoly &poly, SUMOReal offset=0) const
Returns the information whether the given polygon overlaps with this.
Position intersectionPosition2D(const Position &p1, const Position &p2, const SUMOReal withinDist=0.) const
Returns the position of the intersection.
Position getLineCenter() const
get line center
void move2side(SUMOReal amount)
move position vector to side using certain ammount
#define SUMOReal
Definition: config.h:208
void push_back_noDoublePos(const Position &p)
insert in back a non double position
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
SUMOReal area() const
Returns the area (0 for non-closed)
std::vector< SUMOReal > intersectsAtLengths2D(const PositionVector &other) const
For all intersections between this vector and other, return the 2D-length of the subvector from this ...
SUMOReal getMaxGrade() const
return the maximum grade of all segments as a fraction of zRange/length2D
void closePolygon()
ensures that the last position equals the first
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
bool crosses(const Position &p1, const Position &p2) const
int removeClosest(const Position &p)
removes the point closest to p and return the removal index
PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const
get subpart of a position vector
void append(const PositionVector &v, SUMOReal sameThreshold=2.0)
void extrapolate(const SUMOReal val, const bool onlyFirst=false)
extrapolate position vector
SUMOReal isLeft(const Position &P0, const Position &P1, const Position &P2) const
get left
Position transformToVectorCoordinates(const Position &p, bool extend=false) const
return position p within the length-wise coordinate system defined by this position vector...