SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
12 // Copyright (C) 2001-2013 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 Line;
43 class Boundary;
44 
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
53 class PositionVector : public AbstractPoly, private std::vector<Position> {
54 
55 private:
56  typedef std::vector<Position> vp;
57 
58 public:
64 
65 
69  PositionVector(const std::vector<Position>& v);
70 
71 
74 
75  using vp::iterator;
76  using vp::const_iterator;
77  using vp::const_reference;
78  using vp::value_type;
79  using vp::begin;
80  using vp::end;
81  using vp::push_back;
82  using vp::pop_back;
83  using vp::clear;
84  using vp::size;
85  using vp::front;
86  using vp::back;
87  using vp::reference;
88 
89 
92 
93 
97  void push_back(const PositionVector& p);
99 
100 
102  void push_front(const Position& p);
103 
106 
107  void insertAt(int index, const Position& p);
108 
109  void replaceAt(int index, const Position& by);
110 
111  void eraseAt(int i);
112 
115  bool around(const Position& p, SUMOReal offset = 0) const;
116 
119  bool overlapsWith(const AbstractPoly& poly, SUMOReal offset = 0) const;
120 
122  bool intersects(const Position& p1, const Position& p2) const;
123 
125  bool intersects(const PositionVector& v1) const;
126 
129  const Position& p2) const; // !!!
130 
132  PositionVector intersectionPoints2D(const Line& line) const;
133 
136  std::vector<SUMOReal> intersectsAtLengths2D(const PositionVector& other) const; // !!!
137 
140  std::vector<SUMOReal> intersectsAtLengths2D(const Line& line) const; // !!!
141 
143  Position intersectsAtPoint(const PositionVector& v1) const; // !!!
144 
146  void closePolygon();
147 
150  const Position& operator[](int index) const;
151  Position& operator[](int index);
152 
155 
158 
161 
164 
166  static Position positionAtOffset(const Position& p1,
167  const Position& p2, SUMOReal pos);
168 
170  static Position positionAtOffset2D(const Position& p1,
171  const Position& p2, SUMOReal pos);
172 
174  Boundary getBoxBoundary() const;
175 
178  Position getPolygonCenter() const;
179 
181  Position getCentroid() const;
182 
184  void scaleSize(SUMOReal factor);
185 
186  Position getLineCenter() const;
187 
189  SUMOReal length() const;
191  SUMOReal length2D() const;
192 
193 
195  SUMOReal area() const;
196 
198  bool partialWithin(const AbstractPoly& poly, SUMOReal offset = 0) const;
199 
201  std::pair<PositionVector, PositionVector> splitAt(SUMOReal where) const;
202 
204  friend std::ostream& operator<<(std::ostream& os, const PositionVector& geom);
205 
206  bool crosses(const Position& p1, const Position& p2) const;
207 
208  void add(SUMOReal xoff, SUMOReal yoff, SUMOReal zoff);
209 
210  void reshiftRotate(SUMOReal xoff, SUMOReal yoff, SUMOReal rot);
211 
212  PositionVector convexHull() const;
213 
215 
216  // @brief append the given vector to this one
217  void append(const PositionVector& v);
218 
219  PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const;
220 
221  PositionVector getSubpart2D(SUMOReal beginOffset, SUMOReal endOffset) const;
222 
223  void sortAsPolyCWByAngle();
224 
225  void sortByIncreasingXY();
226 
227  void extrapolate(SUMOReal val);
228 
229  PositionVector reverse() const;
230 
231  void move2side(SUMOReal amount);
232 
233  Line lineAt(int pos) const;
234 
235  Line getBegLine() const;
236 
237  Line getEndLine() const;
238 
239 
240  // @brief inserts p between the two closest positions and returns the insertion index
241  int insertAtClosest(const Position& p);
242 
244  bool operator==(const PositionVector& v2) const;
245 
247  public:
250 
251  public:
253  int operator()(const Position& p1, const Position& p2) const;
254 
255  };
256 
258  public:
260  explicit increasing_x_y_sorter();
261 
262  public:
264  int operator()(const Position& p1, const Position& p2) const;
265 
266  };
267 
268  // !!!
269  SUMOReal isLeft(const Position& P0, const Position& P1, const Position& P2) const;
270 
271  void pruneFromBeginAt(const Position& p);
272  void pruneFromEndAt(const Position& p);
273 
274  SUMOReal beginEndAngle() const;
275 
276  SUMOReal nearest_offset_to_point2D(const Position& p, bool perpendicular = true) const;
277 
278  /* @brief index of the closest position to p
279  * @note: may only be called for a non-empty vector */
280  int indexOfClosest(const Position& p) const;
281 
282  // distances of all my points to s and all of s points to myself
283  std::vector<SUMOReal> distances(const PositionVector& s) const;
284 
285  SUMOReal distance(const Position& p) const;
286 
287  void push_back_noDoublePos(const Position& p);
288  void push_front_noDoublePos(const Position& p);
289 
290  bool isClosed() const;
291 
296  void removeDoublePoints(SUMOReal minDist = POSITION_EPS, bool assertLength = false);
297 
298  void removeColinearPoints();
299 
300 };
301 
302 
303 #endif
304 
305 /****************************************************************************/
306 
void pruneFromBeginAt(const Position &p)
SUMOReal nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
PositionVector getSubpart2D(SUMOReal beginOffset, SUMOReal endOffset) const
Position positionAtOffset(SUMOReal pos) const
Returns the position at the given length.
void sortAsPolyCWByAngle()
void replaceAt(int index, const Position &by)
void insertAt(int index, const Position &p)
friend std::ostream & operator<<(std::ostream &os, const PositionVector &geom)
Output operator.
std::vector< SUMOReal > distances(const PositionVector &s) const
Line getEndLine() const
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
bool intersects(const Position &p1, const Position &p2) const
bool partialWithin(const AbstractPoly &poly, SUMOReal offset=0) const
Returns the information whether this polygon lies partially within the given polygon.
void eraseAt(int i)
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
bool isClosed() const
const Position & operator[](int index) const
returns the position at the given index !!! exceptions?
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.
SUMOReal length2D() const
Returns the length.
void scaleSize(SUMOReal factor)
enlarges/shrinks the polygon based at the centroid
Line lineAt(int pos) const
void push_front_noDoublePos(const Position &p)
void reshiftRotate(SUMOReal xoff, SUMOReal yoff, SUMOReal rot)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
Position pop_front()
Removes and returns the position at the fron of the list.
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
void push_front(const Position &p)
Puts the given position at the front of the list.
SUMOReal distance(const Position &p) const
Definition: Line.h:51
#define POSITION_EPS
Definition: config.h:186
int insertAtClosest(const Position &p)
Position intersectsAtPoint(const Position &p1, const Position &p2) const
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.
void extrapolate(SUMOReal val)
PositionVector()
Constructor.
SUMOReal length() const
Returns the length.
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
void push_back(const PositionVector &p)
Appends all positions from the given vector.
void removeDoublePoints(SUMOReal minDist=POSITION_EPS, bool assertLength=false)
Removes positions if too near.
PositionVector intersectionPoints2D(const Line &line) const
int appendWithCrossingPoint(const PositionVector &v)
Position positionAtOffset2D(SUMOReal pos) const
Returns the position at the given length.
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...
Line getBegLine() const
void pruneFromEndAt(const Position &p)
Position getLineCenter() const
void move2side(SUMOReal amount)
#define SUMOReal
Definition: config.h:215
void push_back_noDoublePos(const Position &p)
int operator()(const Position &p1, const Position &p2) const
comparing operation
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.
void append(const PositionVector &v)
bool crosses(const Position &p1, const Position &p2) const
PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const
SUMOReal isLeft(const Position &P0, const Position &P1, const Position &P2) const