| 1 | /** |
| 2 | * Polyline - store geographic line-segments */ |
| 3 | |
| 4 | // Written by James Turner, started 2013. |
| 5 | // |
| 6 | // Copyright (C) 2013 James Turner <[email protected]> |
| 7 | // |
| 8 | // This program is free software; you can redistribute it and/or |
| 9 | // modify it under the terms of the GNU General Public License as |
| 10 | // published by the Free Software Foundation; either version 2 of the |
| 11 | // License, or (at your option) any later version. |
| 12 | // |
| 13 | // This program is distributed in the hope that it will be useful, but |
| 14 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | // General Public License for more details. |
| 17 | // |
| 18 | // You should have received a copy of the GNU General Public License |
| 19 | // along with this program; if not, write to the Free Software |
| 20 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 21 | |
| 22 | #ifndef FG_POLY_LINE_HXX |
| 23 | #define FG_POLY_LINE_HXX |
| 24 | |
| 25 | #include <vector> |
| 26 | |
| 27 | #include <simgear/sg_inlines.h> |
| 28 | #include <simgear/structure/SGSharedPtr.hxx> |
| 29 | #include <simgear/math/SGMath.hxx> |
| 30 | #include <simgear/math/SGBox.hxx> |
| 31 | #include <simgear/math/SGGeometryFwd.hxx> |
| 32 | |
| 33 | namespace flightgear |
| 34 | { |
| 35 | |
| 36 | typedef std::vector<SGGeod> SGGeodVec; |
| 37 | |
| 38 | class PolyLine; |
| 39 | |
| 40 | typedef SGSharedPtr<PolyLine> PolyLineRef; |
| 41 | typedef std::vector<PolyLineRef> PolyLineList; |
| 42 | |
| 43 | /** |
| 44 | * @class Store geographical linear data, with a type code. |
| 45 | * |
| 46 | * This is a basic in-memory model of GIS line data, without support for |
| 47 | * many features; especially there is no support for per-node attributes. |
| 48 | * |
| 49 | * PolyLines are added to the spatial index and can be queried by passing |
| 50 | * a search centre and cutoff distance. |
| 51 | */ |
| 52 | class PolyLine : public SGReferenced |
| 53 | { |
| 54 | public: |
| 55 | virtual ~PolyLine(); |
| 56 | |
| 57 | enum Type |
| 58 | { |
| 59 | INVALID = 0, |
| 60 | COASTLINE, |
| 61 | NATIONAL_BOUNDARY, /// aka a border |
| 62 | REGIONAL_BOUNDARY, /// state / province / country / department |
| 63 | RIVER, |
| 64 | LAKE, |
| 65 | URBAN, |
| 66 | // airspace types in the future |
| 67 | LAST_TYPE |
| 68 | }; |
| 69 | |
| 70 | Type type() const |
| 71 | { return m_type; } |
| 72 | |
| 73 | /** |
| 74 | * number of points in this line - at least two. |
| 75 | */ |
| 76 | unsigned int numPoints() const; |
| 77 | |
| 78 | SGGeod point(unsigned int aIndex) const; |
| 79 | |
| 80 | const SGGeodVec& points() const |
| 81 | { return m_data; } |
| 82 | |
| 83 | /** |
| 84 | * create poly line objects from raw input points and a type. |
| 85 | * input points will be subdivided so the bounding area of each |
| 86 | * polyline stays within some threshold. |
| 87 | * |
| 88 | */ |
| 89 | static PolyLineList createChunked(Type aTy, const SGGeodVec& aRawPoints); |
| 90 | |
| 91 | static PolyLineRef create(Type aTy, const SGGeodVec& aRawPoints); |
| 92 | |
| 93 | static void bulkAddToSpatialIndex(PolyLineList::const_iterator begin, |
| 94 | PolyLineList::const_iterator end); |
| 95 | |
| 96 | /** |
| 97 | * retrieve all the lines within a range of a search point. |
| 98 | * lines are returned if any point is near the search location. |
| 99 | */ |
| 100 | static PolyLineList linesNearPos(const SGGeod& aPos, double aRangeNm, Type aTy); |
| 101 | |
| 102 | class TypeFilter |
| 103 | { |
| 104 | public: |
| 105 | virtual bool pass(Type aTy) const = 0; |
| 106 | }; |
| 107 | |
| 108 | static PolyLineList linesNearPos(const SGGeod& aPos, double aRangeNm, const TypeFilter& aFilter); |
| 109 | |
| 110 | SGBoxd cartesianBox() const; |
| 111 | |
| 112 | void addToSpatialIndex() const; |
| 113 | |
| 114 | private: |
| 115 | |
| 116 | PolyLine(Type aTy, const SGGeodVec& aPoints); |
| 117 | |
| 118 | Type m_type; |
| 119 | SGGeodVec m_data; |
| 120 | |
| 121 | }; |
| 122 | |
| 123 | |
| 124 | |
| 125 | } // of namespace flightgear |
| 126 | |
| 127 | #endif |