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