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 // ===========================================================================
53 class PositionVector : public AbstractPoly {
54 public:
56  typedef std::vector<Position> ContType;
57 
58 public:
64 
65 
69  PositionVector(const std::vector<Position>& v);
70 
71 
74 
75 
78 
82  void push_back(const Position& p);
83 
84 
88  void push_back(const PositionVector& p);
90 
91 
92 
94  void push_front(const Position& p);
95 
98  bool around(const Position& p, SUMOReal offset = 0) const;
99 
102  bool overlapsWith(const AbstractPoly& poly, SUMOReal offset = 0) const;
103 
105  bool intersects(const Position& p1, const Position& p2) const;
106 
108  bool intersects(const PositionVector& v1) const;
109 
112  const Position& p2) const; // !!!
113 
115  PositionVector intersectionPoints2D(const Line& line) const;
116 
119  std::vector<SUMOReal> intersectsAtLengths2D(const PositionVector& other) const; // !!!
120 
123  std::vector<SUMOReal> intersectsAtLengths2D(const Line& line) const; // !!!
124 
126  Position intersectsAtPoint(const PositionVector& v1) const; // !!!
127 
129  void clear();
130 
131  void closePolygon();
132 
135  const Position& operator[](int index) const;
136  Position& operator[](int index);
137 
139  size_t size() const;
140 
143 
146 
149 
152 
154  static Position positionAtLengthPosition(const Position& p1,
155  const Position& p2, SUMOReal pos);
156 
159  const Position& p2, SUMOReal pos);
160 
162  Boundary getBoxBoundary() const;
163 
166  Position getPolygonCenter() const;
167 
169  Position getCentroid() const;
170 
172  void scaleSize(SUMOReal factor);
173 
174  Position getLineCenter() const;
175 
176  Position pop_back();
178 
180  SUMOReal length() const;
181 
182 
184  SUMOReal area() const;
185 
187  bool partialWithin(const AbstractPoly& poly, SUMOReal offset = 0) const;
188 
190  const Position& getBegin() const;
191 
193  const Position& getEnd() const;
194 
196  std::pair<PositionVector, PositionVector> splitAt(SUMOReal where) const;
197 
199  friend std::ostream& operator<<(std::ostream& os, const PositionVector& geom);
200 
201  bool crosses(const Position& p1, const Position& p2) const;
202 
203  void add(SUMOReal xoff, SUMOReal yoff, SUMOReal zoff);
204 
205  void reshiftRotate(SUMOReal xoff, SUMOReal yoff, SUMOReal rot);
206 
207  PositionVector convexHull() const;
208 
210 
211  ContType::const_iterator begin() const {
212  return myCont.begin();
213  }
214 
215  ContType::const_iterator end() const {
216  return myCont.end();
217  }
218 
220 
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(size_t pos) const;
234 
235  Line getBegLine() const;
236 
237  Line getEndLine() const;
238 
239 
240  void insertAt(int index, const Position& p);
241 
242  // @brief inserts p between the two closest positions and returns the insertion index
243  int insertAtClosest(const Position& p);
244 
246  bool operator==(const PositionVector& v2) const;
247 
249  public:
252 
253  public:
255  int operator()(const Position& p1, const Position& p2) const;
256 
257  };
258 
260  public:
262  explicit increasing_x_y_sorter();
263 
264  public:
266  int operator()(const Position& p1, const Position& p2) const;
267 
268  };
269 
270  // !!!
271  SUMOReal isLeft(const Position& P0, const Position& P1, const Position& P2) const;
272 
273  void set(size_t pos, const Position& p);
274 
275  void pruneFromBeginAt(const Position& p);
276  void pruneFromEndAt(const Position& p);
277 
278  SUMOReal beginEndAngle() const;
279 
280  void eraseAt(int i);
281 
282  SUMOReal nearest_position_on_line_to_point2D(const Position& p, bool perpendicular = true) const;
283 
284  /* @brief index of the closest position to p
285  * @note: may only be called for a non-empty vector */
286  int indexOfClosest(const Position& p) const;
287 
288  // distances of all my points to s and all of s points to myself
289  std::vector<SUMOReal> distances(const PositionVector& s) const;
290 
291  SUMOReal distance(const Position& p) const;
292 
293  void push_back_noDoublePos(const Position& p);
294  void push_front_noDoublePos(const Position& p);
295 
296  void replaceAt(size_t index, const Position& by);
297 
298  bool isClosed() const;
299 
300  void removeDoublePoints();
301 
302  void removeColinearPoints();
303 
304 private:
305 
308 
309 };
310 
311 
312 #endif
313 
314 /****************************************************************************/
315