SUMO - Simulation of Urban MObility
PositionVector.h
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // A list of 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 <vector>
00036 #include "AbstractPoly.h"
00037 
00038 
00039 // ===========================================================================
00040 // class declarations
00041 // ===========================================================================
00042 class Line;
00043 class Boundary;
00044 
00045 
00046 // ===========================================================================
00047 // class definitions
00048 // ===========================================================================
00053 class PositionVector
00054         : public AbstractPoly {
00055 public:
00057     typedef std::vector<Position> ContType;
00058 
00059 public:
00064     PositionVector() ;
00065 
00066 
00070     PositionVector(const std::vector<Position> &v) ;
00071 
00072 
00074     ~PositionVector() ;
00075 
00076 
00079 
00083     void push_back(const Position& p) ;
00084 
00085 
00089     void push_back(const PositionVector& p) ;
00091 
00092 
00093 
00095     void push_front(const Position& p);
00096 
00099     bool around(const Position& p, SUMOReal offset = 0) const;
00100 
00103     bool overlapsWith(const AbstractPoly& poly, SUMOReal offset = 0) const;
00104 
00106     bool intersects(const Position& p1, const Position& p2) const;
00107 
00109     bool intersects(const PositionVector& v1) const;
00110 
00112     Position intersectsAtPoint(const Position& p1,
00113                                const Position& p2) const; // !!!
00114 
00116     PositionVector intersectionPoints2D(const Line& line) const;
00117 
00120     std::vector<SUMOReal> intersectsAtLengths2D(const PositionVector& other) const; // !!!
00121 
00124     std::vector<SUMOReal> intersectsAtLengths2D(const Line& line) const; // !!!
00125 
00127     Position intersectsAtPoint(const PositionVector& v1) const; // !!!
00128 
00130     void clear();
00131 
00132     void closePolygon();
00133 
00136     const Position& operator[](int index) const;
00137     Position& operator[](int index);
00138 
00140     size_t size() const;
00141 
00143     Position positionAtLengthPosition(SUMOReal pos) const;
00144 
00146     Position positionAtLengthPosition2D(SUMOReal pos) const;
00147 
00149     SUMOReal rotationDegreeAtLengthPosition(SUMOReal pos) const;
00150 
00152     static Position positionAtLengthPosition(const Position& p1,
00153             const Position& p2, SUMOReal pos);
00154 
00156     static Position positionAtLengthPosition2D(const Position& p1,
00157             const Position& p2, SUMOReal pos);
00158 
00160     Boundary getBoxBoundary() const;
00161 
00164     Position getPolygonCenter() const;
00165 
00167     Position getCentroid() const;
00168 
00170     void scaleSize(SUMOReal factor);
00171 
00172     Position getLineCenter() const;
00173 
00174     Position pop_back();
00175     Position pop_front();
00176 
00178     SUMOReal length() const;
00179 
00180 
00182     SUMOReal area() const;
00183 
00185     bool partialWithin(const AbstractPoly& poly, SUMOReal offset = 0) const;
00186 
00188     const Position& getBegin() const;
00189 
00191     const Position& getEnd() const;
00192 
00194     std::pair<PositionVector, PositionVector> splitAt(SUMOReal where) const;
00195 
00197     friend std::ostream& operator<<(std::ostream& os,
00198                                     const PositionVector& geom);
00199 
00200     bool crosses(const Position& p1, const Position& p2) const;
00201 
00202     void add(SUMOReal xoff, SUMOReal yoff, SUMOReal zoff);
00203 
00204     void reshiftRotate(SUMOReal xoff, SUMOReal yoff, SUMOReal rot);
00205 
00206     PositionVector convexHull() const;
00207 
00208     int appendWithCrossingPoint(const PositionVector& v);
00209 
00210     ContType::const_iterator begin() const {
00211         return myCont.begin();
00212     }
00213 
00214     ContType::const_iterator end() const {
00215         return myCont.end();
00216     }
00217 
00218     PositionVector getSubpart(SUMOReal begin, SUMOReal end) const;
00219 
00220     PositionVector getSubpart2D(SUMOReal begin, SUMOReal end) const;
00221 
00222     void sortAsPolyCWByAngle();
00223 
00224     void sortByIncreasingXY();
00225 
00226     void extrapolate(SUMOReal val);
00227 
00228     PositionVector reverse() const;
00229 
00230     void move2side(SUMOReal amount);
00231 
00232     Line lineAt(size_t pos) const;
00233 
00234     Line getBegLine() const;
00235 
00236     Line getEndLine() const;
00237 
00238 
00239     void insertAt(int index, const Position& p);
00240 
00241     // brief inserts p between the two closest positions
00242     void insertAtClosest(const Position& p);
00243 
00245     bool operator==(const PositionVector& v2) const;
00246 
00247     class as_poly_cw_sorter {
00248     public:
00250         as_poly_cw_sorter() {};
00251 
00252     public:
00254         int operator()(const Position& p1, const Position& p2) const;
00255 
00256     };
00257 
00258     class increasing_x_y_sorter {
00259     public:
00261         explicit increasing_x_y_sorter();
00262 
00263     public:
00265         int operator()(const Position& p1, const Position& p2) const;
00266 
00267     };
00268 
00269     // !!!
00270     SUMOReal isLeft(const Position& P0, const Position& P1, const Position& P2) const;
00271 
00272     void set(size_t pos, const Position& p);
00273 
00274     void pruneFromBeginAt(const Position& p);
00275     void pruneFromEndAt(const Position& p);
00276 
00277     SUMOReal beginEndAngle() const;
00278 
00279     void eraseAt(int i);
00280 
00281     SUMOReal nearest_position_on_line_to_point2D(const Position& p, bool perpendicular = true) const;
00282 
00283     /* @brief index of the closest position to p
00284      * @note: may only be called for a non-empty vector */
00285     int indexOfClosest(const Position& p) const;
00286 
00287     // distances of all my points to s and all of s points to myself
00288     std::vector<SUMOReal> distances(const PositionVector& s) const;
00289 
00290     SUMOReal distance(const Position& p) const;
00291 
00292     void push_back_noDoublePos(const Position& p);
00293     void push_front_noDoublePos(const Position& p);
00294 
00295     void replaceAt(size_t index, const Position& by);
00296 
00297     bool isClosed() const;
00298 
00299     void removeDoublePoints();
00300 
00301     void removeColinearPoints();
00302 
00303 private:
00304 
00306     ContType myCont;
00307 
00308 };
00309 
00310 
00311 #endif
00312 
00313 /****************************************************************************/
00314 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines