FlightGear next
awynet.hxx
Go to the documentation of this file.
1// airwaynet.hxx - A number of classes to handle taxiway
2// assignments by the AI code
3//
4// Written by Durk Talsma. Based upon the ground netword code, started June 2005.
5//
6// Copyright (C) 2004 Durk Talsma.
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 St, Fifth Floor, Boston, MA 02110-1301, USA.
21//
22// $Id$
23
24#ifndef _AIRWAYNETWORK_HXX_
25#define _AIRWAYNETWORK_HXX_
26
27#include <string>
28#include <istream>
29#include <set>
30#include <map>
31#include <vector>
32
33#include <simgear/io/iostreams/sgstream.hxx>
34
35
36//#include "parking.hxx"
37
38class FGAirway; // forward reference
39class SGPath;
40class SGGeod;
41
42typedef std::vector<FGAirway> FGAirwayVector;
43typedef std::vector<FGAirway *> FGAirwayPointerVector;
44typedef std::vector<FGAirway>::iterator FGAirwayVectorIterator;
45typedef std::vector<FGAirway*>::iterator FGAirwayPointerVectorIterator;
46
47/**************************************************************************************
48 * class FGNode
49 *************************************************************************************/
50class FGNode
51{
52private:
53 std::string ident;
54 SGGeod geod;
55 SGVec3d cart; // cached cartesian position
56 int index;
57 FGAirwayPointerVector next; // a vector to all the segments leaving from this node
58
59public:
60 FGNode();
61 FGNode(const SGGeod& aPos, int idx, std::string id);
62
63 void setIndex(int idx) { index = idx;};
64 void addAirway(FGAirway *segment) { next.push_back(segment); };
65
66 const SGGeod& getPosition() {return geod;}
67 const SGVec3d& getCart() { return cart; }
68 int getIndex() { return index; };
69 std::string getIdent() { return ident; };
70 FGNode *getAddress() { return this;};
71 FGAirwayPointerVectorIterator getBeginRoute() { return next.begin(); };
73
74 bool matches(std::string ident, const SGGeod& aPos);
75};
76
77typedef std::vector<FGNode *> FGNodeVector;
78typedef std::vector<FGNode *>::iterator FGNodeVectorIterator;
79
80
81typedef std::map < std::string, FGNode *> node_map;
82typedef node_map::iterator node_map_iterator;
83typedef node_map::const_iterator const_node_map_iterator;
84
85
86/***************************************************************************************
87 * class FGAirway
88 **************************************************************************************/
90{
91private:
92 std::string startNode;
93 std::string endNode;
94 double length;
95 FGNode *start;
96 FGNode *end;
97 int index;
98 int type; // 1=low altitude; 2=high altitude airway
99 int base; // base altitude
100 int top; // top altitude
101 std::string name;
102
103public:
104 FGAirway();
106
107 void setIndex (int val) { index = val; };
108 void setStartNodeRef (std::string val) { startNode = val; };
109 void setEndNodeRef (std::string val) { endNode = val; };
110
111 void setStart(node_map *nodes);
112 void setEnd (node_map *nodes);
113 void setType (int tp) { type = tp;};
114 void setBase (int val) { base = val;};
115 void setTop (int val) { top = val;};
116 void setName (std::string val) { name = val;};
117
118 void setTrackDistance();
119
120 FGNode * getEnd() { return end;};
121 double getLength() { if (length == 0) setTrackDistance(); return length; };
122 int getIndex() { return index; };
123 std::string getName() { return name; };
124
125
126};
127
128
129typedef std::vector<int> intVec;
130typedef std::vector<int>::iterator intVecIterator;
131typedef std::vector<int>::const_iterator constIntVecIterator;
132
134{
135private:
136 intVec nodes;
137 double distance;
138 intVecIterator currNode;
139
140public:
141 FGAirRoute() { distance = 0; currNode = nodes.begin(); };
142 FGAirRoute(intVec nds, double dist) { nodes = nds; distance = dist; currNode = nodes.begin();};
143 bool operator< (const FGAirRoute &other) const {return distance < other.distance; };
144 bool empty () { return nodes.begin() == nodes.end(); };
145 bool next(int *val);
146
147 void first() { currNode = nodes.begin(); };
148 void add(const FGAirRoute &other);
149 void add(int node) {nodes.push_back(node);};
150
151 friend std::istream& operator >> (std::istream& in, FGAirRoute& r);
152};
153
154inline std::istream& operator >> ( std::istream& in, FGAirRoute& r )
155{
156 int node;
157 in >> node;
158 r.nodes.push_back(node);
159 //getline( in, n.name );
160 return in;
161}
162
163typedef std::vector<FGAirRoute> AirRouteVector;
164typedef std::vector<FGAirRoute>::iterator AirRouteVectorIterator;
165
166/**************************************************************************************
167 * class FGAirwayNetwork
168 *************************************************************************************/
170{
171private:
172 bool hasNetwork;
173 node_map nodesMap;
174 FGNodeVector nodes;
175 FGAirwayVector segments;
176 //intVec route;
177 intVec traceStack;
178 AirRouteVector routes;
179
180 bool foundRoute;
181 double totalDistance, maxDistance;
182
183public:
186
187 //void addNode (const FGNode& node);
188 //void addNodes (FGParkingVec *parkings);
189 void addAirway(const FGAirway& seg);
190
191 void init();
192 bool exists() { return hasNetwork; };
193 int findNearestNode(const SGGeod& aPos);
194 FGNode *findNode(int idx);
195 FGAirRoute findShortestRoute(int start, int end);
196 void trace(FGNode *, int, int, double dist);
197
198 void load(const SGPath& path);
199};
200
201#endif
std::vector< FGNode * > FGNodeVector
Definition awynet.hxx:77
std::vector< int > intVec
Definition awynet.hxx:129
std::istream & operator>>(std::istream &in, FGAirRoute &r)
Definition awynet.hxx:154
std::vector< FGAirway * > FGAirwayPointerVector
Definition awynet.hxx:43
node_map::const_iterator const_node_map_iterator
Definition awynet.hxx:83
std::vector< FGNode * >::iterator FGNodeVectorIterator
Definition awynet.hxx:78
std::vector< int >::iterator intVecIterator
Definition awynet.hxx:130
std::vector< FGAirRoute >::iterator AirRouteVectorIterator
Definition awynet.hxx:164
std::vector< FGAirway >::iterator FGAirwayVectorIterator
Definition awynet.hxx:44
node_map::iterator node_map_iterator
Definition awynet.hxx:82
std::vector< FGAirway > FGAirwayVector
Definition awynet.hxx:42
std::vector< FGAirRoute > AirRouteVector
Definition awynet.hxx:163
std::vector< int >::const_iterator constIntVecIterator
Definition awynet.hxx:131
std::map< std::string, FGNode * > node_map
Definition awynet.hxx:81
std::vector< FGAirway * >::iterator FGAirwayPointerVectorIterator
Definition awynet.hxx:45
FGAirRoute(intVec nds, double dist)
Definition awynet.hxx:142
friend std::istream & operator>>(std::istream &in, FGAirRoute &r)
Definition awynet.hxx:154
void add(const FGAirRoute &other)
Definition awynet.cxx:129
bool next(int *val)
Definition awynet.cxx:112
bool empty()
Definition awynet.hxx:144
void add(int node)
Definition awynet.hxx:149
void first()
Definition awynet.hxx:147
bool operator<(const FGAirRoute &other) const
Definition awynet.hxx:143
void addAirway(const FGAirway &seg)
Definition awynet.cxx:155
FGAirRoute findShortestRoute(int start, int end)
Definition awynet.cxx:352
void load(const SGPath &path)
Definition awynet.cxx:200
FGNode * findNode(int idx)
Definition awynet.cxx:340
void trace(FGNode *, int, int, double dist)
Definition awynet.cxx:384
int findNearestNode(const SGGeod &aPos)
Definition awynet.cxx:317
void setTop(int val)
Definition awynet.hxx:115
FGAirway(FGNode *, FGNode *, int)
double getLength()
Definition awynet.hxx:121
void setBase(int val)
Definition awynet.hxx:114
void setType(int tp)
Definition awynet.hxx:113
void setStartNodeRef(std::string val)
Definition awynet.hxx:108
void setEndNodeRef(std::string val)
Definition awynet.hxx:109
void setTrackDistance()
Definition awynet.cxx:102
void setIndex(int val)
Definition awynet.hxx:107
int getIndex()
Definition awynet.hxx:122
FGAirway()
Definition awynet.cxx:72
FGNode * getEnd()
Definition awynet.hxx:120
void setName(std::string val)
Definition awynet.hxx:116
void setStart(node_map *nodes)
Definition awynet.cxx:77
void setEnd(node_map *nodes)
Definition awynet.cxx:89
std::string getName()
Definition awynet.hxx:123
int getIndex()
Definition awynet.hxx:68
FGAirwayPointerVectorIterator getEndRoute()
Definition awynet.hxx:72
bool matches(std::string ident, const SGGeod &aPos)
Definition awynet.cxx:59
void addAirway(FGAirway *segment)
Definition awynet.hxx:64
FGAirwayPointerVectorIterator getBeginRoute()
Definition awynet.hxx:71
void setIndex(int idx)
Definition awynet.hxx:63
const SGVec3d & getCart()
Definition awynet.hxx:67
std::string getIdent()
Definition awynet.hxx:69
FGNode * getAddress()
Definition awynet.hxx:70
const SGGeod & getPosition()
Definition awynet.hxx:66
FGNode()
Definition awynet.cxx:47
std::vector< int > intVec
std::vector< int >::iterator intVecIterator