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-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 {
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  std::pair<PositionVector, PositionVector> splitAt(SUMOReal where) const;
191 
193  friend std::ostream& operator<<(std::ostream& os, const PositionVector& geom);
194 
195  bool crosses(const Position& p1, const Position& p2) const;
196 
197  void add(SUMOReal xoff, SUMOReal yoff, SUMOReal zoff);
198 
199  void reshiftRotate(SUMOReal xoff, SUMOReal yoff, SUMOReal rot);
200 
201  PositionVector convexHull() const;
202 
204 
205  // @brief append the given vector to this one
206  void append(const PositionVector& v);
207 
208  ContType::const_iterator begin() const {
209  return myCont.begin();
210  }
211 
212  ContType::const_iterator end() const {
213  return myCont.end();
214  }
215 
216  const Position& front() const {
217  return myCont.front();
218  }
219 
220  const Position& back() const {
221  return myCont.back();
222  }
223 
225 
227 
228  void sortAsPolyCWByAngle();
229 
230  void sortByIncreasingXY();
231 
232  void extrapolate(SUMOReal val);
233 
234  PositionVector reverse() const;
235 
236  void move2side(SUMOReal amount);
237 
238  Line lineAt(size_t pos) const;
239 
240  Line getBegLine() const;
241 
242  Line getEndLine() const;
243 
244 
245  void insertAt(int index, const Position& p);
246 
247  // @brief inserts p between the two closest positions and returns the insertion index
248  int insertAtClosest(const Position& p);
249 
251  bool operator==(const PositionVector& v2) const;
252 
254  public:
257 
258  public:
260  int operator()(const Position& p1, const Position& p2) const;
261 
262  };
263 
265  public:
267  explicit increasing_x_y_sorter();
268 
269  public:
271  int operator()(const Position& p1, const Position& p2) const;
272 
273  };
274 
275  // !!!
276  SUMOReal isLeft(const Position& P0, const Position& P1, const Position& P2) const;
277 
278  void set(size_t pos, const Position& p);
279 
280  void pruneFromBeginAt(const Position& p);
281  void pruneFromEndAt(const Position& p);
282 
283  SUMOReal beginEndAngle() const;
284 
285  void eraseAt(int i);
286 
287  SUMOReal nearest_position_on_line_to_point2D(const Position& p, bool perpendicular = true) const;
288 
289  /* @brief index of the closest position to p
290  * @note: may only be called for a non-empty vector */
291  int indexOfClosest(const Position& p) const;
292 
293  // distances of all my points to s and all of s points to myself
294  std::vector<SUMOReal> distances(const PositionVector& s) const;
295 
296  SUMOReal distance(const Position& p) const;
297 
298  void push_back_noDoublePos(const Position& p);
299  void push_front_noDoublePos(const Position& p);
300 
301  void replaceAt(size_t index, const Position& by);
302 
303  bool isClosed() const;
304 
309  void removeDoublePoints(SUMOReal minDist = POSITION_EPS, bool assertLength = false);
310 
311  void removeColinearPoints();
312 
313 private:
314 
317 
318 };
319 
320 
321 #endif
322 
323 /****************************************************************************/
324