]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/PolyLine.hxx
Trying to bullet-proof the traffic code.
[flightgear.git] / src / Navaids / PolyLine.hxx
1 /**
2  * Polyline - store geographic line-segments */
3
4 // Written by James Turner, started 2013.
5 //
6 // Copyright (C) 2013 James Turner <zakalawe@mac.com>
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
42 typedef std::vector<PolyLineRef> PolyLineList;
43     
44 /**
45  * @class Store geographical linear data, with a type code.
46  *
47  * This is a basic in-memory model of GIS line data, without support for
48  * many features; especially there is no support for per-node attributes.
49  *
50  * PolyLines are added to the spatial index and can be queried by passing
51  * a search centre and cutoff distance.
52  */
53 class PolyLine : public SGReferenced
54 {
55 public:
56     virtual ~PolyLine();
57     
58     enum Type
59     {
60         INVALID = 0,
61         COASTLINE,
62         NATIONAL_BOUNDARY, /// aka a border
63         REGIONAL_BOUNDARY, /// state / province / country / department
64         RIVER,
65         LAKE,
66         URBAN,
67         // airspace types in the future
68         LAST_TYPE
69     };
70     
71     Type type() const
72     { return m_type; }
73     
74     /**
75      * number of points in this line - at least two.
76      */
77     unsigned int numPoints() const;
78     
79     SGGeod point(unsigned int aIndex) const;
80     
81     const SGGeodVec& points() const
82     { return m_data; }
83     
84     /**
85      * create poly line objects from raw input points and a type.
86      * input points will be subdivided so the bounding area of each
87      * polyline stays within some threshold.
88      *
89      */
90     static PolyLineList createChunked(Type aTy, const SGGeodVec& aRawPoints);
91     
92     static PolyLineRef create(Type aTy, const SGGeodVec& aRawPoints);
93
94     static void bulkAddToSpatialIndex(const PolyLineList& lines);
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