|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // A list of 2D-positions 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 #ifndef PositionVector_h 00023 #define PositionVector_h 00024 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #ifdef _MSC_VER 00030 #include <windows_config.h> 00031 #else 00032 #include <config.h> 00033 #endif 00034 00035 #include <queue> 00036 #include <iostream> 00037 #include <utils/common/VectorHelper.h> 00038 #include "AbstractPoly.h" 00039 #include "Boundary.h" 00040 #include "Position.h" 00041 00042 00043 class Line; 00044 00045 // =========================================================================== 00046 // class definitions 00047 // =========================================================================== 00052 class PositionVector 00053 : public AbstractPoly { 00054 public: 00056 typedef std::vector<Position> ContType; 00057 00058 public: 00063 PositionVector() ; 00064 00065 00069 PositionVector(const std::vector<Position> &v) ; 00070 00071 00073 ~PositionVector() ; 00074 00075 00078 00082 void push_back(const Position& p) ; 00083 00084 00088 void push_back(const PositionVector& p) ; 00090 00091 00092 00094 void push_front(const Position& p); 00095 00098 bool around(const Position& p, SUMOReal offset = 0) const; 00099 00102 bool overlapsWith(const AbstractPoly& poly, SUMOReal offset = 0) const; 00103 00105 bool intersects(const Position& p1, const Position& p2) const; 00106 00108 bool intersects(const PositionVector& v1) const; 00109 00111 Position intersectsAtPoint(const Position& p1, 00112 const Position& p2) const; // !!! 00113 00115 PositionVector intersectionPoints2D(const Line& line) const; 00116 00119 DoubleVector intersectsAtLengths2D(const PositionVector& other) const; // !!! 00120 00123 DoubleVector intersectsAtLengths2D(const Line& line) const; // !!! 00124 00126 Position intersectsAtPoint(const PositionVector& v1) const; // !!! 00127 00129 void clear(); 00130 00131 void closePolygon(); 00132 00135 const Position& operator[](int index) const; 00136 Position& operator[](int index); 00137 00139 size_t size() const; 00140 00142 Position positionAtLengthPosition(SUMOReal pos) const; 00143 00145 SUMOReal rotationDegreeAtLengthPosition(SUMOReal pos) const; 00146 00148 static Position positionAtLengthPosition(const Position& p1, 00149 const Position& p2, SUMOReal pos); 00150 00152 Boundary getBoxBoundary() const; 00153 00156 Position getPolygonCenter() const; 00157 00159 Position getCentroid() const; 00160 00162 void scaleSize(SUMOReal factor); 00163 00164 Position getLineCenter() const; 00165 00166 Position pop_back(); 00167 Position pop_front(); 00168 00170 SUMOReal length() const; 00171 00172 00174 SUMOReal area() const; 00175 00177 bool partialWithin(const AbstractPoly& poly, SUMOReal offset = 0) const; 00178 00180 const Position& getBegin() const; 00181 00183 const Position& getEnd() const; 00184 00186 std::pair<PositionVector, PositionVector> splitAt(SUMOReal where) const; 00187 00189 friend std::ostream& operator<<(std::ostream& os, 00190 const PositionVector& geom); 00191 00192 bool crosses(const Position& p1, const Position& p2) const; 00193 00194 void reshiftRotate(SUMOReal xoff, SUMOReal yoff, SUMOReal rot); 00195 00196 PositionVector convexHull() const; 00197 00198 int appendWithCrossingPoint(const PositionVector& v); 00199 00200 00201 const ContType& getCont() const { 00202 return myCont; 00203 } 00204 00205 PositionVector getSubpart(SUMOReal begin, SUMOReal end) const; 00206 00207 void sortAsPolyCWByAngle(); 00208 00209 void sortByIncreasingXY(); 00210 00211 void extrapolate(SUMOReal val); 00212 00213 PositionVector reverse() const; 00214 00215 void move2side(SUMOReal amount); 00216 void move2side(SUMOReal amount, int index); 00217 00218 Line lineAt(size_t pos) const; 00219 00220 Line getBegLine() const; 00221 00222 Line getEndLine() const; 00223 00224 00225 void insertAt(int index, const Position& p); 00226 00227 // brief inserts p between the two closest positions 00228 void insertAtClosest(const Position& p); 00229 00231 bool operator==(const PositionVector& v2) const; 00232 00233 class as_poly_cw_sorter { 00234 public: 00236 as_poly_cw_sorter() {}; 00237 00238 public: 00240 int operator()(const Position& p1, const Position& p2) const; 00241 00242 }; 00243 00244 class increasing_x_y_sorter { 00245 public: 00247 explicit increasing_x_y_sorter(); 00248 00249 public: 00251 int operator()(const Position& p1, const Position& p2) const; 00252 00253 }; 00254 00255 // !!! 00256 SUMOReal isLeft(const Position& P0, const Position& P1, const Position& P2) const; 00257 00258 void set(size_t pos, const Position& p); 00259 00260 void pruneFromBeginAt(const Position& p); 00261 void pruneFromEndAt(const Position& p); 00262 00263 SUMOReal beginEndAngle() const; 00264 00265 void eraseAt(int i); 00266 00267 SUMOReal nearest_position_on_line_to_point(const Position& p, bool perpendicular = true) const; 00268 00269 /* @brief index of the closest position to p 00270 * @note: may only be called for a non-empty vector */ 00271 int indexOfClosest(const Position& p) const; 00272 00273 // distances of all my points to s and all of s points to myself 00274 DoubleVector distances(const PositionVector& s) const; 00275 00276 SUMOReal distance(const Position& p) const; 00277 00278 void push_back_noDoublePos(const Position& p); 00279 void push_front_noDoublePos(const Position& p); 00280 00281 void replaceAt(size_t index, const Position& by); 00282 00283 bool isClosed() const; 00284 00285 void removeDoublePoints(); 00286 00287 void removeColinearPoints(); 00288 00289 private: 00290 00292 ContType myCont; 00293 00294 }; 00295 00296 00297 #endif 00298 00299 /****************************************************************************/ 00300