00001
00002
00003
00004
00005
00006
00007
00008 #ifndef ROADMAPH
00009 #define ROADMAPH
00010
00011 #include "DLG.h"
00012
00013 #define RMFVERSION_STRING "RMFFile1.8"
00014 #define RMFVERSION_CURRENT 1.8f
00015 #define RMFVERSION_SUPPORTED 1.7f // oldest supported version
00016
00017 #define SWITCH 0
00018
00019 enum SurfaceType {
00020 ST_NONE,
00021 ST_GRAVEL,
00022 ST_TRAIL,
00023 ST_2TRACK,
00024 ST_DIRT,
00025 ST_PAVED,
00026 ST_RAILROAD
00027 };
00028
00029
00030 enum IntersectionType {
00031 IT_NONE,
00032 IT_LIGHT,
00033 IT_STOPSIGN,
00034 };
00035
00036 enum LightStatus {
00037 LT_INVALID,
00038 LT_RED,
00039 LT_YELLOW,
00040 LT_GREEN
00041 };
00042
00043
00044 #define RF_SIDEWALK 0x8000000
00045 #define RF_PARKING 0x4000000
00046 #define RF_MARGIN 0x2000000
00047 #define RF_FORWARD 0x0800000 // true if traffic flows from node 0 to 1
00048 #define RF_REVERSE 0x0400000 // true if traffic flows from node 1 to 0
00049
00050 #define RF_HIT 0x0000001
00051
00052
00053
00054
00055 #if SWITCH
00056
00057
00058 class LaneIO {
00059 public:
00060 LaneIO();
00061 ~LaneIO();
00062 void AddChoice(class Road *road, int lane);
00063 int GetRoadNum(class Road *road);
00064
00065 int m_iChoices;
00066
00067 class Road **m_pRoads;
00068
00069 int *m_iLane;
00070 };
00071
00072 class RoadIO {
00073 public:
00074 RoadIO(int lanes);
00075 ~RoadIO();
00076 int m_iLanes;
00077 LaneIO **m_pLaneIO;
00078 };
00079
00080 class Switch
00081 {
00082 public:
00083 Switch(int r, class Road **roads);
00084 ~Switch();
00085
00086 Road** RoadChoices(Road *curRoad, int curLane);
00087
00088 int LaneChoice(Road *curRoad, int curLane, Road* destRoad);
00089 int LaneChoice(Road *curRoad, int curLane, int destRoad);
00090
00091 int m_iRoads;
00092
00093 class Road **m_pRoads;
00094
00095 RoadIO **m_pRoadIO;
00096 };
00097 #endif //SWITCH
00098
00099
00100
00101
00102 class Node
00103 {
00104 public:
00105 Node();
00106 ~Node();
00107
00108
00109 bool operator==(Node &ref);
00110
00111
00112 void Copy(Node* node);
00113
00114 class Road *GetRoad(int n);
00115 int FindRoad(int roadID);
00116 void AddRoad(class Road *pR);
00117 void DetachRoad(class Road *pR);
00118 double DistanceToPoint(DPoint2 target);
00119 void DetermineRoadAngles();
00120 void SortRoadsByAngle();
00121 DPoint2 find_adjacent_roadpoint2d(Road *pR);
00122
00123
00124 bool SetIntersectType(Road *road, IntersectionType type);
00125 bool SetIntersectType(int roadNum, IntersectionType type);
00126 IntersectionType GetIntersectType(Road *road);
00127 IntersectionType GetIntersectType(int roadNum);
00128 LightStatus GetLightStatus(Road *road);
00129 LightStatus GetLightStatus(int roadNum);
00130 bool SetLightStatus(Road *road, LightStatus light);
00131 bool SetLightStatus(int roadNum, LightStatus light);
00132
00133 bool HasLights();
00134 bool IsControlled();
00135
00136
00137 void AdjustForLights();
00138
00139 #if SWITCH
00140 void SetupSwitch();
00141
00142 void DetermineOptions(int i, int *in,
00143 int &right, int &straight, int &left, int &uturn);
00144 Switch *m_pSwitch;
00145 #endif //SWITCH
00146
00147 DPoint2 m_p;
00148 int m_iRoads;
00149 int m_id;
00150
00151
00152 float *m_fRoadAngle;
00153
00154 Node *m_pNext;
00155 protected:
00156 IntersectionType *m_IntersectTypes;
00157 LightStatus *m_Lights;
00158 class Road **m_r;
00159 };
00160
00161
00162
00163
00164
00165 class Road : public DLine2
00166 {
00167 public:
00168 Road();
00169 Road(Road &ref);
00170 ~Road();
00171
00172
00173 bool operator==(Road &ref);
00174
00175 void SetNode(int n, Node *pNode) { m_pNode[n] = pNode; }
00176 Node *GetNode(int n) { return m_pNode[n]; }
00177
00178 double DistanceToPoint(DPoint2 target);
00179
00180 bool IsLoop() { return (m_pNode[0] == m_pNode[1]); }
00181
00182 void SetFlag(int flag, bool value);
00183 bool GetFlag(int flag);
00184
00185 float GetHeightAt(int i);
00186 float GetHeightAt(Node *node);
00187 void SetHeightAt(int i, float height);
00188 void SetHeightAt(Node *node, float height);
00189 float Length();
00190
00191 float m_fWidth;
00192 int m_iLanes;
00193 SurfaceType m_Surface;
00194
00195 int m_iHwy;
00196
00197 Road *m_pNext;
00198
00199 int m_id;
00200
00201 unsigned int m_iFlags;
00202
00203 protected:
00204 Node *m_pNode[2];
00205
00206 float m_fHeight[2];
00207 };
00208
00209 typedef Road *RoadPtr;
00210 typedef Node *NodePtr;
00211
00212 #define intSize 4
00213 #define floatSize 4
00214 #define doubleSize 8
00215
00216 class vtRoadMap
00217 {
00218 public:
00219 vtRoadMap();
00220 ~vtRoadMap();
00221
00222 Node *FindNodeByID(int id);
00223 void DeleteElements();
00224 DRECT GetMapExtent();
00225 void ComputeExtents();
00226
00227 int NumRoads() const;
00228 int NumNodes() const;
00229
00230 Road *GetFirstRoad() { return m_pFirstRoad; }
00231 Node *GetFirstNode() { return m_pFirstNode; }
00232
00233 void AddNode(Node *pNode)
00234 {
00235 pNode->m_pNext = m_pFirstNode;
00236 m_pFirstNode = pNode;
00237 }
00238 void AddRoad(Road *pRoad)
00239 {
00240 pRoad->m_pNext = m_pFirstRoad;
00241 m_pFirstRoad = pRoad;
00242 }
00243
00244
00245 int RemoveUnusedNodes();
00246
00247 vtProjection &GetProjection() { return m_proj; }
00248
00249 protected:
00250 DRECT m_extents;
00251 bool m_bValidExtents;
00252
00253 Road *m_pFirstRoad;
00254 Node *m_pFirstNode;
00255
00256 vtProjection m_proj;
00257 };
00258
00259 #endif