SUMO - Simulation of Urban MObility
PositionVector.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A list of positions
20 /****************************************************************************/
21 #ifndef PositionVector_h
22 #define PositionVector_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <vector>
35 #include <limits>
36 #include "AbstractPoly.h"
37 
38 
39 // ===========================================================================
40 // class declarations
41 // ===========================================================================
42 
43 class Boundary;
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
52 class PositionVector : public AbstractPoly, private std::vector<Position> {
53 
54 private:
56  typedef std::vector<Position> vp;
57 
58 public:
61 
64  PositionVector(const std::vector<Position>& v);
65 
69  PositionVector(const std::vector<Position>::const_iterator beg, const std::vector<Position>::const_iterator end);
70 
74  PositionVector(const Position& p1, const Position& p2);
75 
78 
80  static const PositionVector EMPTY;
81 
85  using vp::iterator;
86 
88  using vp::const_iterator;
89 
91  using vp::const_reference;
92 
94  using vp::value_type;
95 
97  using vp::begin;
98 
100  using vp::end;
101 
103  using vp::push_back;
104 
106  using vp::pop_back;
107 
109  using vp::clear;
111  using vp::size;
112 
114  using vp::front;
115 
117  using vp::back;
118 
120  using vp::reference;
121 
123  using vp::erase;
124 
126  using vp::insert;
128 
131  bool around(const Position& p, double offset = 0) const;
132 
135  bool overlapsWith(const AbstractPoly& poly, double offset = 0) const;
136 
138  double getOverlapWith(const PositionVector& poly, double zThreshold) const;
139 
141  bool intersects(const Position& p1, const Position& p2) const;
142 
144  bool intersects(const PositionVector& v1) const;
145 
147  Position intersectionPosition2D(const Position& p1, const Position& p2, const double withinDist = 0.) const;
148 
150  std::vector<double> intersectsAtLengths2D(const PositionVector& other) const;
151 
153  std::vector<double> intersectsAtLengths2D(const Position& lp1, const Position& lp2) const;
154 
157 
159  void closePolygon();
160 
163  const Position& operator[](int index) const;
164 
167  Position& operator[](int index);
168 
170  Position positionAtOffset(double pos, double lateralOffset = 0) const;
171 
173  Position positionAtOffset2D(double pos, double lateralOffset = 0) const;
174 
176  double rotationAtOffset(double pos) const;
177 
179  double rotationDegreeAtOffset(double pos) const;
180 
182  double slopeDegreeAtOffset(double pos) const;
183 
185  static Position positionAtOffset(const Position& p1, const Position& p2, double pos, double lateralOffset = 0.);
186 
188  static Position positionAtOffset2D(const Position& p1, const Position& p2, double pos, double lateralOffset = 0.);
189 
191  Boundary getBoxBoundary() const;
192 
195  Position getPolygonCenter() const;
196 
198  Position getCentroid() const;
199 
201  void scaleRelative(double factor);
202 
204  void scaleAbsolute(double offset);
205 
207  Position getLineCenter() const;
208 
210  double length() const;
211 
213  double length2D() const;
214 
216  double area() const;
217 
219  bool partialWithin(const AbstractPoly& poly, double offset = 0) const;
220 
222  std::pair<PositionVector, PositionVector> splitAt(double where) const;
223 
225  friend std::ostream& operator<<(std::ostream& os, const PositionVector& geom);
226 
228  bool crosses(const Position& p1, const Position& p2) const;
229 
231  void add(double xoff, double yoff, double zoff);
232 
234  void add(const Position& offset);
235 
237  void mirrorX();
238 
240  void rotate2D(double angle);
241 
243  void append(const PositionVector& v, double sameThreshold = 2.0);
244 
246  PositionVector getSubpart(double beginOffset, double endOffset) const;
247 
249  PositionVector getSubpart2D(double beginOffset, double endOffset) const;
250 
252  PositionVector getSubpartByIndex(int beginIndex, int count) const;
253 
255  void sortAsPolyCWByAngle();
256 
258  void sortByIncreasingXY();
259 
261  void extrapolate(const double val, const bool onlyFirst = false, const bool onlyLast = false);
262 
264  void extrapolate2D(const double val, const bool onlyFirst = false);
265 
267  PositionVector reverse() const;
268 
270  static Position sideOffset(const Position& beg, const Position& end, const double amount);
271 
273  void move2side(double amount);
274 
276  double angleAt2D(int pos) const;
277 
279  int insertAtClosest(const Position& p);
280 
282  int removeClosest(const Position& p);
283 
285  bool operator==(const PositionVector& v2) const;
286 
288  bool operator!=(const PositionVector& v2) const;
289 
291  PositionVector operator-(const PositionVector& v2) const;
292 
294  PositionVector operator+(const PositionVector& v2) const;
295 
298  public:
301 
303  int operator()(const Position& p1, const Position& p2) const;
304  };
305 
308  public:
310  explicit increasing_x_y_sorter();
311 
313  int operator()(const Position& p1, const Position& p2) const;
314  };
315 
318  double isLeft(const Position& P0, const Position& P1, const Position& P2) const;
319 
321  double beginEndAngle() const;
322 
324  double nearest_offset_to_point2D(const Position& p, bool perpendicular = true) const;
325 
333  Position transformToVectorCoordinates(const Position& p, bool extend = false) const;
334 
337  int indexOfClosest(const Position& p) const;
338 
341  std::vector<double> distances(const PositionVector& s, bool perpendicular = false) const;
342 
344  double distance2D(const Position& p, bool perpendicular = false) const;
345 
347  void push_back_noDoublePos(const Position& p);
348 
350  void push_front_noDoublePos(const Position& p);
351 
353  void insert_noDoublePos(const std::vector<Position>::iterator& at, const Position& p);
354 
356  bool isClosed() const;
357 
362  void removeDoublePoints(double minDist = POSITION_EPS, bool assertLength = false);
363 
365  bool hasElevation() const;
366 
368  PositionVector simplified() const;
369 
376  PositionVector getOrthogonal(const Position& p, double extend, bool before, double length = 1.0) const;
377 
378 
380  PositionVector smoothedZFront(double dist = std::numeric_limits<double>::max()) const;
381 
383  PositionVector interpolateZ(double zStart, double zEnd) const;
384 
386  PositionVector resample(double maxLength) const;
387 
389  double offsetAtIndex2D(int index) const;
390 
392  double getMaxGrade() const;
393 
394 private:
396  static bool intersects(const Position& p11, const Position& p12, const Position& p21, const Position& p22, const double withinDist = 0., double* x = 0, double* y = 0, double* mu = 0);
397 };
398 
399 
400 #endif
401 
402 /****************************************************************************/
403 
PositionVector operator+(const PositionVector &v2) const
adds two vectors (requires vectors of the same length)
bool around(const Position &p, double offset=0) const
Returns the information whether the position vector describes a polygon lying around the given point...
static const PositionVector EMPTY
empty Vector
clase for increasing Sorter
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
double length2D() const
Returns the length.
void append(const PositionVector &v, double sameThreshold=2.0)
PositionVector getOrthogonal(const Position &p, double extend, bool before, double length=1.0) const
return orthogonal through p (extending this vector if necessary)
void sortAsPolyCWByAngle()
short as polygon CV by angle
double distance2D(const Position &p, bool perpendicular=false) const
closest 2D-distance to point p (or -1 if perpendicular is true and the point is beyond this vector) ...
int indexOfClosest(const Position &p) const
index of the closest position to p
friend std::ostream & operator<<(std::ostream &os, const PositionVector &geom)
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
PositionVector resample(double maxLength) const
resample shape with the given number of points (equal spacing)
Position intersectionPosition2D(const Position &p1, const Position &p2, const double withinDist=0.) const
Returns the position of the intersection.
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
bool partialWithin(const AbstractPoly &poly, double offset=0) const
Returns the information whether this polygon lies partially within the given polygon.
PositionVector reverse() const
reverse position vector
double rotationAtOffset(double pos) const
Returns the rotation at the given length.
PositionVector interpolateZ(double zStart, double zEnd) const
returned vector that varies z smoothly over its length
void insert_noDoublePos(const std::vector< Position >::iterator &at, const Position &p)
insert in front a non double position
std::vector< double > distances(const PositionVector &s, bool perpendicular=false) const
distances of all my points to s and all of s points to myself
bool hasElevation() const
return whether two positions differ in z-coordinate
std::pair< PositionVector, PositionVector > splitAt(double where) const
Returns the two lists made when this list vector is splitted at the given point.
bool operator!=(const PositionVector &v2) const
comparing operation
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:47
Position getLineCenter() const
get line center
double area() const
Returns the area (0 for non-closed)
~PositionVector()
Destructor.
void extrapolate2D(const double val, const bool onlyFirst=false)
extrapolate position vector in two dimensions (Z is ignored)
void push_front_noDoublePos(const Position &p)
insert in front a non double position
void removeDoublePoints(double minDist=POSITION_EPS, bool assertLength=false)
Removes positions if too near.
void scaleAbsolute(double offset)
enlarges/shrinks the polygon by an absolute offset based at the centroid
bool operator==(const PositionVector &v2) const
comparing operation
double beginEndAngle() const
returns the angle in radians of the line connecting the first and the last position ...
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
std::vector< Position > vp
vector of position
A list of positions.
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
int operator()(const Position &p1, const Position &p2) const
comparing operation for sort
#define POSITION_EPS
Definition: config.h:175
std::vector< double > intersectsAtLengths2D(const PositionVector &other) const
For all intersections between this vector and other, return the 2D-length of the subvector from this ...
const Position & operator[](int index) const
returns the constat position at the given index !!! exceptions?
int insertAtClosest(const Position &p)
inserts p between the two closest positions and returns the insertion index
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
bool overlapsWith(const AbstractPoly &poly, double offset=0) const
Returns the information whether the given polygon overlaps with this.
PositionVector smoothedZFront(double dist=std::numeric_limits< double >::max()) const
returned vector that is smoothed at the front (within dist)
PositionVector getSubpartByIndex(int beginIndex, int count) const
get subpart of a position vector using index and a cout
void sortByIncreasingXY()
shory by increasing X-Y Psitions
void move2side(double amount)
move position vector to side using certain ammount
PositionVector operator-(const PositionVector &v2) const
substracts two vectors (requires vectors of the same length)
PositionVector simplified() const
return the same shape with intermediate colinear points removed
double slopeDegreeAtOffset(double pos) const
Returns the slope at the given length.
PositionVector()
Constructor. Creates an empty position vector.
double isLeft(const Position &P0, const Position &P1, const Position &P2) const
get left
PositionVector getSubpart2D(double beginOffset, double endOffset) const
get subpart of a position vector in two dimensions (Z is ignored)
void rotate2D(double angle)
void extrapolate(const double val, const bool onlyFirst=false, const bool onlyLast=false)
extrapolate position vector
double length() const
Returns the length.
bool isClosed() const
check if PositionVector is closed
static Position sideOffset(const Position &beg, const Position &end, const double amount)
get a side position of position vector using a offset
void scaleRelative(double factor)
enlarges/shrinks the polygon by a factor based at the centroid
double angleAt2D(int pos) const
get angle in certain position of position vector
double offsetAtIndex2D(int index) const
return the offset at the given index
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
void push_back_noDoublePos(const Position &p)
insert in back a non double position
double getMaxGrade() const
return the maximum grade of all segments as a fraction of zRange/length2D
bool crosses(const Position &p1, const Position &p2) const
double getOverlapWith(const PositionVector &poly, double zThreshold) const
Returns the maximum overlaps between this and the given polygon (when not separated by at least zThre...
void add(double xoff, double yoff, double zoff)
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
void closePolygon()
ensures that the last position equals the first
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
int removeClosest(const Position &p)
removes the point closest to p and return the removal index
Position transformToVectorCoordinates(const Position &p, bool extend=false) const
return position p within the length-wise coordinate system defined by this position vector...
bool intersects(const Position &p1, const Position &p2) const
Returns the information whether this list of points interesects the given line.