Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
RoadMap.h
1 //
2 // RoadMap.h
3 //
4 // Copyright (c) 2001-2009 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef ROADMAPH
9 #define ROADMAPH
10 
11 #include "DLG.h"
12 
13 #define RMFVERSION_STRING "RMFFile2.0"
14 #define RMFVERSION_CURRENT 2.0
15 #define RMFVERSION_SUPPORTED 1.7 // oldest supported version
16 
17 enum SurfaceType {
18  SURFT_NONE, // 0
19  SURFT_GRAVEL, // 1
20  SURFT_TRAIL, // 2
21  SURFT_2TRACK, // 3
22  SURFT_DIRT, // 4
23  SURFT_PAVED, // 5
24  SURFT_RAILROAD, // 6
25  SURFT_STONE // 7
26 };
27 
28 //
29 // This enum describes how a single link meets a node.
30 //
31 enum IntersectionType {
32  IT_NONE, // uncontrolled
33  IT_LIGHT, // a traffic light
34  IT_STOPSIGN, // a stop sign
35 };
36 
37 enum LightStatus {
38  LT_INVALID,
39  LT_RED,
40  LT_YELLOW,
41  LT_GREEN
42 };
43 
44 // link flags
45 #define RF_SIDEWALK 0x0800
46 #define RF_PARKING 0x0400
47 #define RF_MARGIN 0x0200
48 #define RF_FORWARD 0x0080 // true if traffic flows from node 0 to 1
49 #define RF_REVERSE 0x0040 // true if traffic flows from node 1 to 0
50 // the following are for temporary, runtime use
51 #define RF_HIT 0x0001
52 
53 // Typical, default values for widths, in meters
54 #define SIDEWALK_WIDTH 1.5f
55 #define CURB_HEIGHT 0.15f
56 #define MARGIN_WIDTH 1.6f
57 #define LANE_WIDTH 3.3f
58 #define PARKING_WIDTH LANE_WIDTH
59 
60 // Nodes and Links refer to each other, so use forward declarations
61 class TNode;
62 class TLink;
63 
64 // Store the connectivity information for each place a link meets a node.
66 {
67  TLink *pLink;
68 
69  // True if the link starts at this node, false if it ends
70  bool bStart;
71 
72  // intersection types of the link at this node.
73  IntersectionType eIntersection;
74 
75  // light of the link at this node.
76  LightStatus eLight;
77 
78  // angle of each link, not initialized till SortLinksByAngle is called
79  float fLinkAngle;
80 };
81 
85 class TNode
86 {
87 public:
88  TNode();
89  virtual ~TNode();
90 
91  // comparison
92  bool operator==(TNode &ref);
93 
94  //copies internal variables from another node.
95  void Copy(TNode* node);
96 
97  TLink *GetLink(int n);
98  int AddLink(TLink *pR, bool bStart); // attaches a link to the node
99  void DetachLink(TLink *pR, bool bStart); // detaches the link from the node
100  void DetermineLinkAngles(); // resulting angles > 0
101  float GetLinkAngle(int iLinkNum);
102  void SortLinksByAngle(); // sorts the internal links by angle.
103  DPoint2 GetAdjacentLinkPoint2d(int iLinkNum); //returns the 2nd point on the link from the node.
104 
105  int GetLinkNum(TLink *link, bool bStart);
106  LinkConnect &GetLinkConnect(int iLinkNum) { return m_connect[iLinkNum]; }
107 
108  //sets intersection type for node. returns false if link is invalid
109  bool SetIntersectType(int linkNum, IntersectionType type); //linkNum is internal index within the node
110  IntersectionType GetIntersectType(int linkNum); //returns the intersection type of given link index (not ID)
111  LightStatus GetLightStatus(int linkNum); //returns the light status of given link index (not ID)
112  bool SetLightStatus(int linkNum, LightStatus light); //sets the light status of given link index (not ID)
113 
114  bool HasLights();
115  bool IsControlled(); // true if any stopsigns or stoplights
116 
117  //adjust the light relationship of the links at the node (if the intersection is has a signal light.)
118  void AdjustForLights();
119 
120  DPoint2 m_p; // utm coordinates of center
121  int m_iLinks; // number of links meeting here
122 
123  TNode *m_pNext;
124 
125  // only used while reading from DLG/RMF/OSM
126  int FindLink(int linkID); // returns internal number of link with given ID. -1 if not found.
127  int m_id;
128 
129 protected:
130  // Information about the links that connect to or from this node.
131  std::vector<LinkConnect> m_connect;
132 
133 private:
134  // Don't let unsuspecting users stumble into assuming that object
135  // copy semantics will work. Declare them private and never
136  // define them,
137  TNode( const TNode & );
138  TNode &operator=( const TNode & );
139 };
140 
141 
145 class TLink : public DLine2
146 {
147 public:
148  TLink();
149  TLink(TLink &ref);
150  virtual ~TLink();
151 
152  // comparison
153  bool operator==(TLink &ref);
154 
155  void SetNode(int n, TNode *pNode) { m_pNode[n] = pNode; }
156  TNode *GetNode(int n) { return m_pNode[n]; }
157 
158  // closest distance from point to the link
159  double GetLinearCoordinates(const DPoint2 &p, double &a, double &b,
160  DPoint2 &closest, int &linkpoint, float &fractional, bool bAllowEnds = true);
161  double DistanceToPoint(const DPoint2 &point, bool bAllowEnds = true);
162 
163  // is the link a loop?
164  bool IsLoop() { return (m_pNode[0] == m_pNode[1]); }
165 
166  // accessors for flag properties
167  virtual void SetFlag(int flag, bool value);
168  int GetFlag(int flag);
169 
170  // Return length of link centerline.
171  float Length();
172  float EstimateWidth(bool bIncludeSidewalk = true);
173 
174  float m_fWidth; // link width in meters
175  unsigned short m_iLanes; // number of lanes
176  SurfaceType m_Surface;
177  short m_iHwy; // highway number: -1 for normal links
178  TLink *m_pNext; // the next Link, if links are maintained in link list form
179  short m_iFlags; // a flag to be used to holding any addition info.
180  int m_id; // only used during file reading
181  float m_fSidewalkWidth;
182  float m_fCurbHeight;
183  float m_fMarginWidth;
184  float m_fLaneWidth;
185  float m_fParkingWidth;
186 
187 protected:
188  TNode *m_pNode[2]; // "from" and "to" nodes
189  float m_fHeight[2];
190 };
191 
192 typedef TLink *LinkPtr;
193 typedef TNode *TNodePtr;
194 
205 {
206 public:
207  vtRoadMap();
208  virtual ~vtRoadMap();
209 
210  void DeleteElements();
211  DRECT GetMapExtent(); // get the geographical extent of the road map
212  void ComputeExtents();
213 
214  int NumLinks() const; // returns number of links in the road map
215  int NumNodes() const; // returns number of nodes in the road map
216 
217  TLink *GetFirstLink() { return m_pFirstLink; }
218  TNode *GetFirstNode() { return m_pFirstNode; }
219 
220  virtual TNode *NewNode() { return new TNode; }
221  virtual TLink *NewLink() { return new TLink; }
222 
223  void AddNode(TNode *pNode)
224  {
225  pNode->m_pNext = m_pFirstNode;
226  m_pFirstNode = pNode;
227  }
228  void AddLink(TLink *pLink)
229  {
230  pLink->m_pNext = m_pFirstLink;
231  m_pFirstLink = pLink;
232  }
233 
234  TNode *FindNodeByID(int id);
235  TNode *FindNodeAtPoint(const DPoint2 &point, double epsilon);
236 
237  // cleaning function: remove unused nodes, return the number removed
238  int RemoveUnusedNodes();
239 
240  // Other clean up functions
241  void RemoveNode(TNode *pNode);
242  void RemoveLink(TLink *pLink);
243 
244  bool ReadRMF(const char *filename, bool bHwy, bool bPaved, bool bDirt);
245  bool WriteRMF(const char *filename);
246 
247  vtProjection &GetProjection() { return m_proj; }
248 
249 protected:
250  DRECT m_extents; // the extent of the roads in the RoadMap
251  bool m_bValidExtents; // true when extents are computed
252 
253  TLink *m_pFirstLink;
254  TNode *m_pFirstNode;
255 
256  vtProjection m_proj;
257 };
258 
259 #endif // ROADMAPH
260