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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // A list of positions
18 /****************************************************************************/
19 #ifndef PositionVector_h
20 #define PositionVector_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <vector>
29 #include <limits>
30 #include "AbstractPoly.h"
31 
32 
33 // ===========================================================================
34 // class declarations
35 // ===========================================================================
36 
37 class Boundary;
38 
39 // ===========================================================================
40 // class definitions
41 // ===========================================================================
46 class PositionVector : public AbstractPoly, private std::vector<Position> {
47 
48 private:
50  typedef std::vector<Position> vp;
51 
52 public:
55 
58  PositionVector(const std::vector<Position>& v);
59 
63  PositionVector(const std::vector<Position>::const_iterator beg, const std::vector<Position>::const_iterator end);
64 
68  PositionVector(const Position& p1, const Position& p2);
69 
72 
74  static const PositionVector EMPTY;
75 
79  using vp::iterator;
80 
82  using vp::const_iterator;
83 
85  using vp::const_reference;
86 
88  using vp::value_type;
89 
91  using vp::begin;
92 
94  using vp::end;
95 
97  using vp::push_back;
98 
100  using vp::pop_back;
101 
103  using vp::clear;
105  using vp::size;
106 
108  using vp::front;
109 
111  using vp::back;
112 
114  using vp::reference;
115 
117  using vp::erase;
118 
120  using vp::insert;
122 
125  bool around(const Position& p, double offset = 0) const;
126 
129  bool overlapsWith(const AbstractPoly& poly, double offset = 0) const;
130 
132  double getOverlapWith(const PositionVector& poly, double zThreshold) const;
133 
135  bool intersects(const Position& p1, const Position& p2) const;
136 
138  bool intersects(const PositionVector& v1) const;
139 
141  Position intersectionPosition2D(const Position& p1, const Position& p2, const double withinDist = 0.) const;
142 
144  std::vector<double> intersectsAtLengths2D(const PositionVector& other) const;
145 
147  std::vector<double> intersectsAtLengths2D(const Position& lp1, const Position& lp2) const;
148 
151 
153  void closePolygon();
154 
157  const Position& operator[](int index) const;
158 
160  Position& operator[](int index);
161 
163  Position positionAtOffset(double pos, double lateralOffset = 0) const;
164 
166  Position positionAtOffset2D(double pos, double lateralOffset = 0) const;
167 
169  double rotationAtOffset(double pos) const;
170 
172  double rotationDegreeAtOffset(double pos) const;
173 
175  double slopeDegreeAtOffset(double pos) const;
176 
178  static Position positionAtOffset(const Position& p1, const Position& p2, double pos, double lateralOffset = 0.);
179 
181  static Position positionAtOffset2D(const Position& p1, const Position& p2, double pos, double lateralOffset = 0.);
182 
184  Boundary getBoxBoundary() const;
185 
188  Position getPolygonCenter() const;
189 
191  Position getCentroid() const;
192 
194  void scaleRelative(double factor);
195 
197  void scaleAbsolute(double offset);
198 
200  Position getLineCenter() const;
201 
203  double length() const;
204 
206  double length2D() const;
207 
209  double area() const;
210 
212  bool partialWithin(const AbstractPoly& poly, double offset = 0) const;
213 
215  std::pair<PositionVector, PositionVector> splitAt(double where, bool use2D = false) const;
216 
218  friend std::ostream& operator<<(std::ostream& os, const PositionVector& geom);
219 
221  bool crosses(const Position& p1, const Position& p2) const;
222 
224  void add(double xoff, double yoff, double zoff);
225 
227  void add(const Position& offset);
228 
230  void mirrorX();
231 
233  void rotate2D(double angle);
234 
236  void append(const PositionVector& v, double sameThreshold = 2.0);
237 
239  PositionVector getSubpart(double beginOffset, double endOffset) const;
240 
242  PositionVector getSubpart2D(double beginOffset, double endOffset) const;
243 
245  PositionVector getSubpartByIndex(int beginIndex, int count) const;
246 
248  void sortAsPolyCWByAngle();
249 
251  void sortByIncreasingXY();
252 
254  void extrapolate(const double val, const bool onlyFirst = false, const bool onlyLast = false);
255 
257  void extrapolate2D(const double val, const bool onlyFirst = false);
258 
260  PositionVector reverse() const;
261 
263  static Position sideOffset(const Position& beg, const Position& end, const double amount);
264 
266  void move2side(double amount);
267 
269  void move2side(std::vector<double> amount);
270 
272  double angleAt2D(int pos) const;
273 
275  int insertAtClosest(const Position& p);
276 
278  int removeClosest(const Position& p);
279 
281  bool operator==(const PositionVector& v2) const;
282 
284  bool operator!=(const PositionVector& v2) const;
285 
287  PositionVector operator-(const PositionVector& v2) const;
288 
290  PositionVector operator+(const PositionVector& v2) const;
291 
294  public:
297 
299  int operator()(const Position& p1, const Position& p2) const;
300  };
301 
304  public:
306  explicit increasing_x_y_sorter();
307 
309  int operator()(const Position& p1, const Position& p2) const;
310  };
311 
314  double isLeft(const Position& P0, const Position& P1, const Position& P2) const;
315 
317  double beginEndAngle() const;
318 
320  double nearest_offset_to_point2D(const Position& p, bool perpendicular = true) const;
321 
329  Position transformToVectorCoordinates(const Position& p, bool extend = false) const;
330 
333  int indexOfClosest(const Position& p) const;
334 
337  std::vector<double> distances(const PositionVector& s, bool perpendicular = false) const;
338 
340  double distance2D(const Position& p, bool perpendicular = false) const;
341 
343  void push_back_noDoublePos(const Position& p);
344 
346  void push_front_noDoublePos(const Position& p);
347 
349  void insert_noDoublePos(const std::vector<Position>::iterator& at, const Position& p);
350 
352  bool isClosed() const;
353 
355  bool isNAN() const;
356 
361  void removeDoublePoints(double minDist = POSITION_EPS, bool assertLength = false);
362 
364  bool hasElevation() const;
365 
367  PositionVector simplified() const;
368 
375  PositionVector getOrthogonal(const Position& p, double extend, bool before, double length = 1.0) const;
376 
378  PositionVector smoothedZFront(double dist = std::numeric_limits<double>::max()) const;
379 
381  PositionVector interpolateZ(double zStart, double zEnd) const;
382 
384  PositionVector resample(double maxLength) const;
385 
387  double offsetAtIndex2D(int index) const;
388 
389  /* @brief return the maximum grade of all segments as a fraction of zRange/length2D
390  * @param[out] maxJump The maximum vertical jump (with grade infinity)
391  */
392  double getMaxGrade(double& maxJump) 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) ...
double getMaxGrade(double &maxJump) const
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.
std::pair< PositionVector, PositionVector > splitAt(double where, bool use2D=false) const
Returns the two lists made when this list vector is splitted at the given point.
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
bool operator!=(const PositionVector &v2) const
comparing operation
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
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:39
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:172
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
bool isNAN() const
check if PositionVector is NAN
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
bool crosses(const Position &p1, const Position &p2) const
Returns whether the AbstractPoly crosses the given line.
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.