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-2016 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 "AbstractPoly.h"
37 
38 
39 // ===========================================================================
40 // class declarations
41 // ===========================================================================
42 
43 class Boundary;
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
52 class PositionVector : public AbstractPoly, private std::vector<Position> {
53 
54 private:
56  typedef std::vector<Position> vp;
57 
58 public:
61 
64  PositionVector(const std::vector<Position>& v);
65 
69  PositionVector(const std::vector<Position>::const_iterator beg, const std::vector<Position>::const_iterator end);
70 
74  PositionVector(const Position& p1, const Position& p2);
75 
78 
82  using vp::iterator;
83 
85  using vp::const_iterator;
86 
88  using vp::const_reference;
89 
91  using vp::value_type;
92 
94  using vp::begin;
95 
97  using vp::end;
98 
100  using vp::push_back;
101 
103  using vp::pop_back;
104 
106  using vp::clear;
108  using vp::size;
109 
111  using vp::front;
112 
114  using vp::back;
115 
117  using vp::reference;
118 
120  using vp::erase;
121 
123  using vp::insert;
125 
128  bool around(const Position& p, SUMOReal offset = 0) const;
129 
132  bool overlapsWith(const AbstractPoly& poly, SUMOReal offset = 0) 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 SUMOReal withinDist = 0.) const;
142 
144  std::vector<SUMOReal> intersectsAtLengths2D(const PositionVector& other) const;
145 
147  std::vector<SUMOReal> intersectsAtLengths2D(const Position& lp1, const Position& lp2) const;
148 
151 
153  void closePolygon();
154 
157  const Position& operator[](int index) const;
158 
161  Position& operator[](int index);
162 
164  Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset = 0) const;
165 
167  Position positionAtOffset2D(SUMOReal pos, SUMOReal lateralOffset = 0) const;
168 
171 
174 
177 
179  static Position positionAtOffset(const Position& p1, const Position& p2, SUMOReal pos, SUMOReal lateralOffset = 0.);
180 
182  static Position positionAtOffset2D(const Position& p1, const Position& p2, SUMOReal pos, SUMOReal lateralOffset = 0.);
183 
185  Boundary getBoxBoundary() const;
186 
189  Position getPolygonCenter() const;
190 
192  Position getCentroid() const;
193 
195  void scaleRelative(SUMOReal factor);
196 
198  void scaleAbsolute(SUMOReal offset);
199 
201  Position getLineCenter() const;
202 
204  SUMOReal length() const;
205 
207  SUMOReal length2D() const;
208 
210  SUMOReal area() const;
211 
213  bool partialWithin(const AbstractPoly& poly, SUMOReal offset = 0) const;
214 
216  std::pair<PositionVector, PositionVector> splitAt(SUMOReal where) const;
217 
219  friend std::ostream& operator<<(std::ostream& os, const PositionVector& geom);
220 
222  bool crosses(const Position& p1, const Position& p2) const;
223 
225  void add(SUMOReal xoff, SUMOReal yoff, SUMOReal zoff);
226 
228  void add(const Position& offset);
229 
231  void mirrorX();
232 
234  void rotate2D(SUMOReal angle);
235 
237  PositionVector convexHull() const;
238 
240  void append(const PositionVector& v, SUMOReal sameThreshold = 2.0);
241 
243  PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const;
244 
246  PositionVector getSubpart2D(SUMOReal beginOffset, SUMOReal endOffset) const;
247 
249  PositionVector getSubpartByIndex(int beginIndex, int count) const;
250 
252  void sortAsPolyCWByAngle();
253 
255  void sortByIncreasingXY();
256 
258  void extrapolate(const SUMOReal val, const bool onlyFirst = false);
259 
261  void extrapolate2D(const SUMOReal val, const bool onlyFirst = false);
262 
264  PositionVector reverse() const;
265 
267  static Position sideOffset(const Position& beg, const Position& end, const SUMOReal amount);
268 
270  void move2side(SUMOReal amount);
271 
273  SUMOReal angleAt2D(int pos) const;
274 
276  int insertAtClosest(const Position& p);
277 
279  int removeClosest(const Position& p);
280 
282  bool operator==(const PositionVector& v2) const;
283 
286  public:
289 
291  int operator()(const Position& p1, const Position& p2) const;
292  };
293 
296  public:
298  explicit increasing_x_y_sorter();
299 
301  int operator()(const Position& p1, const Position& p2) const;
302  };
303 
306  SUMOReal isLeft(const Position& P0, const Position& P1, const Position& P2) const;
307 
309  SUMOReal beginEndAngle() const;
310 
312  SUMOReal nearest_offset_to_point2D(const Position& p, bool perpendicular = true) const;
313 
321  Position transformToVectorCoordinates(const Position& p, bool extend = false) const;
322 
325  int indexOfClosest(const Position& p) const;
326 
329  std::vector<SUMOReal> distances(const PositionVector& s, bool perpendicular = false) const;
330 
332  SUMOReal distance2D(const Position& p, bool perpendicular = false) const;
333 
335  void push_back_noDoublePos(const Position& p);
336 
338  void push_front_noDoublePos(const Position& p);
339 
341  bool isClosed() const;
342 
347  void removeDoublePoints(SUMOReal minDist = POSITION_EPS, bool assertLength = false);
348 
350  bool hasElevation() const;
351 
353  PositionVector simplified() const;
354 
360  PositionVector getOrthogonal(const Position& p, SUMOReal extend, SUMOReal& distToClosest) const;
361 
362 private:
364  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);
365 };
366 
367 
368 #endif
369 
370 /****************************************************************************/
371 
PositionVector getOrthogonal(const Position &p, SUMOReal extend, SUMOReal &distToClosest) const
return orthogonal through p (extending this vector if necessary)
bool overlapsWith(const AbstractPoly &poly, SUMOReal offset=0) const
Returns the information whether the given polygon overlaps with this.
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
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
int indexOfClosest(const Position &p) const
index of the closest position to p
SUMOReal slopeDegreeAtOffset(SUMOReal pos) const
Returns the slope at the given length.
SUMOReal length() const
Returns the length.
friend std::ostream & operator<<(std::ostream &os, const PositionVector &geom)
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
void scaleRelative(SUMOReal factor)
enlarges/shrinks the polygon by a factor based at the centroid
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
std::pair< PositionVector, PositionVector > splitAt(SUMOReal where) const
Returns the two lists made when this list vector is splitted at the given point.
PositionVector reverse() const
reverse position vector
bool hasElevation() const
return whether two positions differ in z-coordinate
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
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
SUMOReal rotationAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
Position getLineCenter() const
get line center
SUMOReal nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
SUMOReal beginEndAngle() const
returns the angle in radians of the line connecting the first and the last position ...
void rotate2D(SUMOReal angle)
~PositionVector()
Destructor.
void extrapolate2D(const SUMOReal 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
SUMOReal angleAt2D(int pos) const
get angle in certain position of position vector
bool operator==(const PositionVector &v2) const
comparing operation
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)
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
int operator()(const Position &p1, const Position &p2) const
comparing operation for sort
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const
get subpart of a position vector
#define POSITION_EPS
Definition: config.h:187
SUMOReal length2D() const
Returns the length.
const Position & operator[](int index) const
returns the constat position at the given index !!! exceptions?
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) ...
int insertAtClosest(const Position &p)
inserts p between the two closest positions and returns the insertion index
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
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 ...
PositionVector simplified() const
return the same shape with intermediate colinear points removed
PositionVector()
Constructor. Creates an empty position vector.
void removeDoublePoints(SUMOReal minDist=POSITION_EPS, bool assertLength=false)
Removes positions if too near.
SUMOReal area() const
Returns the area (0 for non-closed)
bool isClosed() const
check if PositionVector is closed
void scaleAbsolute(SUMOReal offset)
enlarges/shrinks the polygon by an absolute offset based at the centroid
bool around(const Position &p, SUMOReal offset=0) const
Returns the information whether the position vector describes a polygon lying around the given point...
Position positionAtOffset2D(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
PositionVector convexHull() const
void move2side(SUMOReal amount)
move position vector to side using certain ammount
#define SUMOReal
Definition: config.h:213
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
Position intersectionPosition2D(const Position &p1, const Position &p2, const SUMOReal withinDist=0.) const
Returns the position of the intersection.
bool partialWithin(const AbstractPoly &poly, SUMOReal offset=0) const
Returns the information whether this polygon lies partially within the given polygon.
void closePolygon()
ensures that the last position equals the first
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.
SUMOReal isLeft(const Position &P0, const Position &P1, const Position &P2) const
get left
void append(const PositionVector &v, SUMOReal sameThreshold=2.0)
void extrapolate(const SUMOReal val, const bool onlyFirst=false)
extrapolate position vector