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.sourceforge.net/
12 // Copyright (C) 2001-2012 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 // ===========================================================================
54  : public AbstractPoly {
55 public:
57  typedef std::vector<Position> ContType;
58 
59 public:
64  PositionVector() ;
65 
66 
70  PositionVector(const std::vector<Position> &v) ;
71 
72 
74  ~PositionVector() ;
75 
76 
79 
83  void push_back(const Position& p) ;
84 
85 
89  void push_back(const PositionVector& p) ;
91 
92 
93 
95  void push_front(const Position& p);
96 
99  bool around(const Position& p, SUMOReal offset = 0) const;
100 
103  bool overlapsWith(const AbstractPoly& poly, SUMOReal offset = 0) const;
104 
106  bool intersects(const Position& p1, const Position& p2) const;
107 
109  bool intersects(const PositionVector& v1) const;
110 
113  const Position& p2) const; // !!!
114 
116  PositionVector intersectionPoints2D(const Line& line) const;
117 
120  std::vector<SUMOReal> intersectsAtLengths2D(const PositionVector& other) const; // !!!
121 
124  std::vector<SUMOReal> intersectsAtLengths2D(const Line& line) const; // !!!
125 
127  Position intersectsAtPoint(const PositionVector& v1) const; // !!!
128 
130  void clear();
131 
132  void closePolygon();
133 
136  const Position& operator[](int index) const;
137  Position& operator[](int index);
138 
140  size_t size() const;
141 
144 
147 
150 
152  static Position positionAtLengthPosition(const Position& p1,
153  const Position& p2, SUMOReal pos);
154 
157  const Position& p2, SUMOReal pos);
158 
160  Boundary getBoxBoundary() const;
161 
164  Position getPolygonCenter() const;
165 
167  Position getCentroid() const;
168 
170  void scaleSize(SUMOReal factor);
171 
172  Position getLineCenter() const;
173 
174  Position pop_back();
176 
178  SUMOReal length() const;
179 
180 
182  SUMOReal area() const;
183 
185  bool partialWithin(const AbstractPoly& poly, SUMOReal offset = 0) const;
186 
188  const Position& getBegin() const;
189 
191  const Position& getEnd() const;
192 
194  std::pair<PositionVector, PositionVector> splitAt(SUMOReal where) const;
195 
197  friend std::ostream& operator<<(std::ostream& os,
198  const PositionVector& geom);
199 
200  bool crosses(const Position& p1, const Position& p2) const;
201 
202  void add(SUMOReal xoff, SUMOReal yoff, SUMOReal zoff);
203 
204  void reshiftRotate(SUMOReal xoff, SUMOReal yoff, SUMOReal rot);
205 
206  PositionVector convexHull() const;
207 
209 
210  ContType::const_iterator begin() const {
211  return myCont.begin();
212  }
213 
214  ContType::const_iterator end() const {
215  return myCont.end();
216  }
217 
219 
221 
222  void sortAsPolyCWByAngle();
223 
224  void sortByIncreasingXY();
225 
226  void extrapolate(SUMOReal val);
227 
228  PositionVector reverse() const;
229 
230  void move2side(SUMOReal amount);
231 
232  Line lineAt(size_t pos) const;
233 
234  Line getBegLine() const;
235 
236  Line getEndLine() const;
237 
238 
239  void insertAt(int index, const Position& p);
240 
241  // brief inserts p between the two closest positions
242  void insertAtClosest(const Position& p);
243 
245  bool operator==(const PositionVector& v2) const;
246 
248  public:
251 
252  public:
254  int operator()(const Position& p1, const Position& p2) const;
255 
256  };
257 
259  public:
261  explicit increasing_x_y_sorter();
262 
263  public:
265  int operator()(const Position& p1, const Position& p2) const;
266 
267  };
268 
269  // !!!
270  SUMOReal isLeft(const Position& P0, const Position& P1, const Position& P2) const;
271 
272  void set(size_t pos, const Position& p);
273 
274  void pruneFromBeginAt(const Position& p);
275  void pruneFromEndAt(const Position& p);
276 
277  SUMOReal beginEndAngle() const;
278 
279  void eraseAt(int i);
280 
281  SUMOReal nearest_position_on_line_to_point2D(const Position& p, bool perpendicular = true) const;
282 
283  /* @brief index of the closest position to p
284  * @note: may only be called for a non-empty vector */
285  int indexOfClosest(const Position& p) const;
286 
287  // distances of all my points to s and all of s points to myself
288  std::vector<SUMOReal> distances(const PositionVector& s) const;
289 
290  SUMOReal distance(const Position& p) const;
291 
292  void push_back_noDoublePos(const Position& p);
293  void push_front_noDoublePos(const Position& p);
294 
295  void replaceAt(size_t index, const Position& by);
296 
297  bool isClosed() const;
298 
299  void removeDoublePoints();
300 
301  void removeColinearPoints();
302 
303 private:
304 
307 
308 };
309 
310 
311 #endif
312 
313 /****************************************************************************/
314