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-2015 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 class Boundary;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
52 class PositionVector : public AbstractPoly, private std::vector<Position> {
53 
54 private:
55  typedef std::vector<Position> vp;
56 
57 public:
63 
64 
68  PositionVector(const std::vector<Position>& v);
69 
70 
75  PositionVector(const std::vector<Position>::const_iterator beg, const std::vector<Position>::const_iterator end);
76 
77 
82  PositionVector(const Position& p1, const Position& p2);
83 
84 
87 
88  using vp::iterator;
89  using vp::const_iterator;
90  using vp::const_reference;
91  using vp::value_type;
92  using vp::begin;
93  using vp::end;
94  using vp::push_back;
95  using vp::pop_back;
96  using vp::clear;
97  using vp::size;
98  using vp::front;
99  using vp::back;
100  using vp::reference;
101  using vp::erase;
102  using vp::insert;
103 
104 
107  bool around(const Position& p, SUMOReal offset = 0) const;
108 
111  bool overlapsWith(const AbstractPoly& poly, SUMOReal offset = 0) const;
112 
114  bool intersects(const Position& p1, const Position& p2) const;
115 
117  bool intersects(const PositionVector& v1) const;
118 
121  const Position& p2,
122  const SUMOReal withinDist = 0.) const;
123 
126  std::vector<SUMOReal> intersectsAtLengths2D(const PositionVector& other) const;
127 
130  std::vector<SUMOReal> intersectsAtLengths2D(const Position& lp1, const Position& lp2) const;
131 
134 
136  void closePolygon();
137 
140  const Position& operator[](int index) const;
141  Position& operator[](int index);
142 
144  Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset = 0) const;
145 
147  Position positionAtOffset2D(SUMOReal pos, SUMOReal lateralOffset = 0) const;
148 
151 
154 
157 
159  static Position positionAtOffset(const Position& p1,
160  const Position& p2, SUMOReal pos, SUMOReal lateralOffset = 0.);
161 
163  static Position positionAtOffset2D(const Position& p1,
164  const Position& p2, SUMOReal pos, SUMOReal lateralOffset = 0.);
165 
167  Boundary getBoxBoundary() const;
168 
171  Position getPolygonCenter() const;
172 
174  Position getCentroid() const;
175 
177  void scaleRelative(SUMOReal factor);
178 
180  void scaleAbsolute(SUMOReal offset);
181 
182  Position getLineCenter() const;
183 
185  SUMOReal length() const;
187  SUMOReal length2D() const;
188 
189 
191  SUMOReal area() const;
192 
194  bool partialWithin(const AbstractPoly& poly, SUMOReal offset = 0) const;
195 
197  std::pair<PositionVector, PositionVector> splitAt(SUMOReal where) const;
198 
200  friend std::ostream& operator<<(std::ostream& os, const PositionVector& geom);
201 
202  bool crosses(const Position& p1, const Position& p2) const;
203 
204  void add(SUMOReal xoff, SUMOReal yoff, SUMOReal zoff);
205 
207  void mirrorX();
208 
209  PositionVector convexHull() const;
210 
211  // @brief append the given vector to this one
212  void append(const PositionVector& v, SUMOReal sameThreshold = 2.0);
213 
214  PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const;
215 
216  PositionVector getSubpart2D(SUMOReal beginOffset, SUMOReal endOffset) const;
217 
218  PositionVector getSubpartByIndex(int beginIndex, int count) const;
219 
220  void sortAsPolyCWByAngle();
221 
222  void sortByIncreasingXY();
223 
224  void extrapolate(const SUMOReal val, const bool onlyFirst = false);
225 
226  void extrapolate2D(const SUMOReal val, const bool onlyFirst = false);
227 
228  PositionVector reverse() const;
229 
230  static Position sideOffset(const Position& beg, const Position& end, const SUMOReal amount);
231 
232  void move2side(SUMOReal amount);
233 
234  SUMOReal angleAt2D(int pos) const;
235 
236 
237  // @brief inserts p between the two closest positions and returns the insertion index
238  int insertAtClosest(const Position& p);
239 
241  bool operator==(const PositionVector& v2) const;
242 
244  public:
247 
248  public:
250  int operator()(const Position& p1, const Position& p2) const;
251 
252  };
253 
255  public:
257  explicit increasing_x_y_sorter();
258 
259  public:
261  int operator()(const Position& p1, const Position& p2) const;
262 
263  };
264 
265  // !!!
266  SUMOReal isLeft(const Position& P0, const Position& P1, const Position& P2) const;
267 
269  SUMOReal beginEndAngle() const;
270 
271  SUMOReal nearest_offset_to_point2D(const Position& p, bool perpendicular = true) const;
272 
280  Position transformToVectorCoordinates(const Position& p, bool extend = false) const;
281 
282  /* @brief index of the closest position to p
283  * @note: may only be called for a non-empty vector */
284  int indexOfClosest(const Position& p) const;
285 
286  /* @brief distances of all my points to s and all of s points to myself
287  * if perpenciualr is set to true, only the perpendicular distances are
288  * returned
289  */
290  std::vector<SUMOReal> distances(const PositionVector& s, bool perpendicular = false) const;
291 
292  /* @brief closest distance to point p
293  * (or -1 if perpendicular is true and the point is beyond this vector)
294  */
295  SUMOReal distance(const Position& p, bool perpendicular = false) const;
296 
297  void push_back_noDoublePos(const Position& p);
298  void push_front_noDoublePos(const Position& p);
299 
300  bool isClosed() const;
301 
306  void removeDoublePoints(SUMOReal minDist = POSITION_EPS, bool assertLength = false);
307 
309  bool hasElevation() const;
310 
311 private:
315  static bool intersects(const Position& p11, const Position& p12,
316  const Position& p21, const Position& p22,
317  const SUMOReal withinDist = 0.,
318  SUMOReal* x = 0, SUMOReal* y = 0, SUMOReal* mu = 0);
319 
320 };
321 
322 
323 #endif
324 
325 /****************************************************************************/
326 
static Position sideOffset(const Position &beg, const Position &end, const SUMOReal amount)
bool hasElevation() const
return whether two positions differ in z-coordinate
SUMOReal distance(const Position &p, bool perpendicular=false) const
SUMOReal rotationAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
SUMOReal nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
PositionVector getSubpart2D(SUMOReal beginOffset, SUMOReal endOffset) const
void sortAsPolyCWByAngle()
friend std::ostream & operator<<(std::ostream &os, const PositionVector &geom)
Output operator.
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
bool intersects(const Position &p1, const Position &p2) const
void scaleRelative(SUMOReal factor)
enlarges/shrinks the polygon by a factor based at the centroid
PositionVector getSubpartByIndex(int beginIndex, int count) const
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
const Position & operator[](int index) const
returns the 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
PositionVector reverse() const
SUMOReal slopeDegreeAtOffset(SUMOReal pos) const
Returns the slope at the given length.
PositionVector convexHull() const
~PositionVector()
Destructor.
void extrapolate2D(const SUMOReal val, const bool onlyFirst=false)
SUMOReal length2D() const
Returns the length.
std::vector< SUMOReal > distances(const PositionVector &s, bool perpendicular=false) const
void push_front_noDoublePos(const Position &p)
void mirrorX()
mirror coordinates along the x-axis
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
std::vector< Position > vp
A list of positions.
void add(SUMOReal xoff, SUMOReal yoff, SUMOReal zoff)
int indexOfClosest(const Position &p) const
int operator()(const Position &p1, const Position &p2) const
comparing operation
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
#define POSITION_EPS
Definition: config.h:188
int insertAtClosest(const Position &p)
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.
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.
SUMOReal angleAt2D(int pos) const
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 Again a boundary may be specifie...
Position intersectionPosition2D(const Position &p1, const Position &p2, const SUMOReal withinDist=0.) const
Position getLineCenter() const
void move2side(SUMOReal amount)
#define SUMOReal
Definition: config.h:214
void push_back_noDoublePos(const Position &p)
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 ...
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
PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const
void append(const PositionVector &v, SUMOReal sameThreshold=2.0)
void extrapolate(const SUMOReal val, const bool onlyFirst=false)
SUMOReal isLeft(const Position &P0, const Position &P1, const Position &P2) const
Position transformToVectorCoordinates(const Position &p, bool extend=false) const
return position p within the length-wise coordinate system defined by this position vector...