Eclipse SUMO - Simulation of Urban MObility
PositionVector.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // A list of positions
18 /****************************************************************************/
19 #ifndef PositionVector_h
20 #define PositionVector_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <vector>
29 #include <limits>
30 #include "AbstractPoly.h"
31 
32 
33 // ===========================================================================
34 // class declarations
35 // ===========================================================================
36 
37 class Boundary;
38 
39 // ===========================================================================
40 // class definitions
41 // ===========================================================================
46 class PositionVector : public AbstractPoly, private std::vector<Position> {
47 
48 private:
50  typedef std::vector<Position> vp;
51 
52 public:
55 
58  PositionVector(const std::vector<Position>& v);
59 
63  PositionVector(const std::vector<Position>::const_iterator beg, const std::vector<Position>::const_iterator end);
64 
68  PositionVector(const Position& p1, const Position& p2);
69 
72 
74  static const PositionVector EMPTY;
75 
79  using vp::iterator;
80 
82  using vp::const_iterator;
83 
85  using vp::const_reference;
86 
88  using vp::value_type;
89 
91  using vp::begin;
92 
94  using vp::end;
95 
97  using vp::push_back;
98 
100  using vp::pop_back;
101 
103  using vp::clear;
105  using vp::size;
106 
108  using vp::front;
109 
111  using vp::back;
112 
114  using vp::reference;
115 
117  using vp::erase;
118 
120  using vp::insert;
122 
125  bool around(const Position& p, double offset = 0) const;
126 
129  bool overlapsWith(const AbstractPoly& poly, double offset = 0) const;
130 
132  double getOverlapWith(const PositionVector& poly, double zThreshold) const;
133 
135  bool intersects(const Position& p1, const Position& p2) const;
136 
138  bool intersects(const PositionVector& v1) const;
139 
141  Position intersectionPosition2D(const Position& p1, const Position& p2, const double withinDist = 0.) const;
142 
144  std::vector<double> intersectsAtLengths2D(const PositionVector& other) const;
145 
147  std::vector<double> intersectsAtLengths2D(const Position& lp1, const Position& lp2) const;
148 
151 
153  void closePolygon();
154 
157  const Position& operator[](int index) const;
158 
160  Position& operator[](int index);
161 
163  Position positionAtOffset(double pos, double lateralOffset = 0) const;
164 
166  Position positionAtOffset2D(double pos, double lateralOffset = 0) const;
167 
169  double rotationAtOffset(double pos) const;
170 
172  double rotationDegreeAtOffset(double pos) const;
173 
175  double slopeDegreeAtOffset(double pos) const;
176 
178  static Position positionAtOffset(const Position& p1, const Position& p2, double pos, double lateralOffset = 0.);
179 
181  static Position positionAtOffset2D(const Position& p1, const Position& p2, double pos, double lateralOffset = 0.);
182 
184  Boundary getBoxBoundary() const;
185 
188  Position getPolygonCenter() const;
189 
191  Position getCentroid() const;
192 
194  void scaleRelative(double factor);
195 
197  void scaleAbsolute(double offset);
198 
200  Position getLineCenter() const;
201 
203  double length() const;
204 
206  double length2D() const;
207 
209  double area() const;
210 
212  bool partialWithin(const AbstractPoly& poly, double offset = 0) const;
213 
215  std::pair<PositionVector, PositionVector> splitAt(double where, bool use2D = false) const;
216 
218  friend std::ostream& operator<<(std::ostream& os, const PositionVector& geom);
219 
221  bool crosses(const Position& p1, const Position& p2) const;
222 
224  void add(double xoff, double yoff, double zoff);
225 
227  void add(const Position& offset);
228 
230  void sub(double xoff, double yoff, double zoff);
231 
233  void sub(const Position& offset);
234 
236  PositionVector added(const Position& offset) const;
237 
239  void mirrorX();
240 
242  void rotate2D(double angle);
243 
245  void append(const PositionVector& v, double sameThreshold = 2.0);
246 
248  PositionVector getSubpart(double beginOffset, double endOffset) const;
249 
251  PositionVector getSubpart2D(double beginOffset, double endOffset) const;
252 
254  PositionVector getSubpartByIndex(int beginIndex, int count) const;
255 
257  void sortAsPolyCWByAngle();
258 
260  void sortByIncreasingXY();
261 
263  void extrapolate(const double val, const bool onlyFirst = false, const bool onlyLast = false);
264 
266  void extrapolate2D(const double val, const bool onlyFirst = false);
267 
269  PositionVector reverse() const;
270 
272  static Position sideOffset(const Position& beg, const Position& end, const double amount);
273 
275  void move2side(double amount, double maxExtension = 100);
276 
278  void move2side(std::vector<double> amount, double maxExtension = 100);
279 
281  double angleAt2D(int pos) const;
282 
284  int insertAtClosest(const Position& p);
285 
287  int removeClosest(const Position& p);
288 
290  bool operator==(const PositionVector& v2) const;
291 
293  bool operator!=(const PositionVector& v2) const;
294 
296  PositionVector operator-(const PositionVector& v2) const;
297 
299  PositionVector operator+(const PositionVector& v2) const;
300 
303  public:
306 
308  int operator()(const Position& p1, const Position& p2) const;
309  };
310 
313  public:
315  explicit increasing_x_y_sorter();
316 
318  int operator()(const Position& p1, const Position& p2) const;
319  };
320 
323  double isLeft(const Position& P0, const Position& P1, const Position& P2) const;
324 
326  double beginEndAngle() const;
327 
329  double nearest_offset_to_point2D(const Position& p, bool perpendicular = true) const;
330 
332  double nearest_offset_to_point25D(const Position& p, bool perpendicular = true) const;
333 
341  Position transformToVectorCoordinates(const Position& p, bool extend = false) const;
342 
345  int indexOfClosest(const Position& p) const;
346 
349  std::vector<double> distances(const PositionVector& s, bool perpendicular = false) const;
350 
352  double distance2D(const Position& p, bool perpendicular = false) const;
353 
355  void push_back_noDoublePos(const Position& p);
356 
358  void push_front_noDoublePos(const Position& p);
359 
361  void insert_noDoublePos(const std::vector<Position>::iterator& at, const Position& p);
362 
364  bool isClosed() const;
365 
367  bool isNAN() const;
368 
373  void removeDoublePoints(double minDist = POSITION_EPS, bool assertLength = false);
374 
376  bool hasElevation() const;
377 
379  PositionVector simplified() const;
380 
387  PositionVector getOrthogonal(const Position& p, double extend, bool before, double length = 1.0) const;
388 
390  PositionVector smoothedZFront(double dist = std::numeric_limits<double>::max()) const;
391 
393  PositionVector interpolateZ(double zStart, double zEnd) const;
394 
396  PositionVector resample(double maxLength) const;
397 
399  double offsetAtIndex2D(int index) const;
400 
401  /* @brief return the maximum grade of all segments as a fraction of zRange/length2D
402  * @param[out] maxJump The maximum vertical jump (with grade infinity)
403  */
404  double getMaxGrade(double& maxJump) const;
405 
407  PositionVector bezier(int numPoints);
408 
409 private:
411  static bool intersects(const Position& p11, const Position& p12, const Position& p21, const Position& p22, const double withinDist = 0., double* x = 0, double* y = 0, double* mu = 0);
412 };
413 
414 
415 #endif
416 
417 /****************************************************************************/
418 
PositionVector operator+(const PositionVector &v2) const
adds two vectors (requires vectors of the same length)
bool around(const Position &p, double offset=0) const
Returns the information whether the position vector describes a polygon lying around the given point...
static const PositionVector EMPTY
empty Vector
clase for increasing Sorter
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
double length2D() const
Returns the length.
void append(const PositionVector &v, double sameThreshold=2.0)
PositionVector getOrthogonal(const Position &p, double extend, bool before, double length=1.0) const
return orthogonal through p (extending this vector if necessary)
void sortAsPolyCWByAngle()
short as polygon CV by angle
double 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) ...
double getMaxGrade(double &maxJump) const
int indexOfClosest(const Position &p) const
index of the closest position to p
friend std::ostream & operator<<(std::ostream &os, const PositionVector &geom)
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
PositionVector resample(double maxLength) const
resample shape with the given number of points (equal spacing)
Position intersectionPosition2D(const Position &p1, const Position &p2, const double withinDist=0.) const
Returns the position of the intersection.
std::pair< PositionVector, PositionVector > splitAt(double where, bool use2D=false) const
Returns the two lists made when this list vector is splitted at the given point.
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
bool partialWithin(const AbstractPoly &poly, double offset=0) const
Returns the information whether this polygon lies partially within the given polygon.
PositionVector reverse() const
reverse position vector
double rotationAtOffset(double pos) const
Returns the rotation at the given length.
PositionVector interpolateZ(double zStart, double zEnd) const
returned vector that varies z smoothly over its length
void insert_noDoublePos(const std::vector< Position >::iterator &at, const Position &p)
insert in front a non double position
std::vector< double > distances(const PositionVector &s, bool perpendicular=false) const
distances of all my points to s and all of s points to myself
bool hasElevation() const
return whether two positions differ in z-coordinate
bool operator!=(const PositionVector &v2) const
comparing operation
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
Position getLineCenter() const
get line center
double area() const
Returns the area (0 for non-closed)
PositionVector bezier(int numPoints)
return a bezier interpolation
~PositionVector()
Destructor.
void extrapolate2D(const double val, const bool onlyFirst=false)
extrapolate position vector in two dimensions (Z is ignored)
void push_front_noDoublePos(const Position &p)
insert in front a non double position
void removeDoublePoints(double minDist=POSITION_EPS, bool assertLength=false)
Removes positions if too near.
PositionVector added(const Position &offset) const
double nearest_offset_to_point25D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D projected onto the 3D geometry
void scaleAbsolute(double offset)
enlarges/shrinks the polygon by an absolute offset based at the centroid
bool operator==(const PositionVector &v2) const
comparing operation
double beginEndAngle() const
returns the angle in radians of the line connecting the first and the last position ...
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
std::vector< Position > vp
vector of position
A list of positions.
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
int operator()(const Position &p1, const Position &p2) const
comparing operation for sort
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
#define POSITION_EPS
Definition: config.h:169
std::vector< double > intersectsAtLengths2D(const PositionVector &other) const
For all intersections between this vector and other, return the 2D-length of the subvector from this ...
const Position & operator[](int index) const
returns the constat position at the given index !!! exceptions?
int insertAtClosest(const Position &p)
inserts p between the two closest positions and returns the insertion index
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
bool overlapsWith(const AbstractPoly &poly, double offset=0) const
Returns the information whether the given polygon overlaps with this.
PositionVector smoothedZFront(double dist=std::numeric_limits< double >::max()) const
returned vector that is smoothed at the front (within dist)
PositionVector getSubpartByIndex(int beginIndex, int count) const
get subpart of a position vector using index and a cout
void sortByIncreasingXY()
shory by increasing X-Y Psitions
PositionVector operator-(const PositionVector &v2) const
substracts two vectors (requires vectors of the same length)
PositionVector simplified() const
return the same shape with intermediate colinear points removed
double slopeDegreeAtOffset(double pos) const
Returns the slope at the given length.
PositionVector()
Constructor. Creates an empty position vector.
double isLeft(const Position &P0, const Position &P1, const Position &P2) const
get left
PositionVector getSubpart2D(double beginOffset, double endOffset) const
get subpart of a position vector in two dimensions (Z is ignored)
void rotate2D(double angle)
void extrapolate(const double val, const bool onlyFirst=false, const bool onlyLast=false)
extrapolate position vector
double length() const
Returns the length.
bool isClosed() const
check if PositionVector is closed
static Position sideOffset(const Position &beg, const Position &end, const double amount)
get a side position of position vector using a offset
void scaleRelative(double factor)
enlarges/shrinks the polygon by a factor based at the centroid
bool isNAN() const
check if PositionVector is NAN
double angleAt2D(int pos) const
get angle in certain position of position vector
double offsetAtIndex2D(int index) const
return the offset at the given index
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
void push_back_noDoublePos(const Position &p)
insert in back a non double position
bool crosses(const Position &p1, const Position &p2) const
Returns whether the AbstractPoly crosses the given line.
double getOverlapWith(const PositionVector &poly, double zThreshold) const
Returns the maximum overlaps between this and the given polygon (when not separated by at least zThre...
void add(double xoff, double yoff, double zoff)
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
void closePolygon()
ensures that the last position equals the first
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
void sub(double xoff, double yoff, double zoff)
int removeClosest(const Position &p)
removes the point closest to p and return the removal index
Position transformToVectorCoordinates(const Position &p, bool extend=false) const
return position p within the length-wise coordinate system defined by this position vector...
bool intersects(const Position &p1, const Position &p2) const
Returns the information whether this list of points interesects the given line.