Main Page   Class Hierarchy   Compound List   File List   Compound Members  

RoadMap.h

00001 //
00002 // RoadMap.h
00003 //
00004 // Copyright (c) 2001 Virtual Terrain Project
00005 // Free for all uses, see license.txt for details.
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 //WARNING!!!! Do NOT change the order of the items in the enumeration.
00030 enum IntersectionType {
00031     IT_NONE,    // uncontrolled
00032     IT_LIGHT,   // controlled intersection with at least one traffic light
00033     IT_STOPSIGN,  // controlled intersection with at least one stop sign
00034 };
00035 
00036 enum LightStatus { 
00037     LT_INVALID,
00038     LT_RED, 
00039     LT_YELLOW, 
00040     LT_GREEN
00041 };
00042 
00043 // road flags
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 // the following are for temporary, runtime use
00050 #define RF_HIT      0x0000001
00051 
00052 
00053 //incomplete code for a node switch that tells which lanes connect to other
00054 //lanes on other roads.
00055 #if SWITCH
00056 // Info in a node that directs traffic flow.  
00057 // Tells which lanes can turn into which lanes.
00058 class LaneIO {
00059 public:
00060     LaneIO();
00061     ~LaneIO();
00062     void AddChoice(class Road *road, int lane);
00063     int GetRoadNum(class Road *road);
00064     //number of choices to choose from reaching end of this lane
00065     int m_iChoices;
00066     //possible roads
00067     class Road **m_pRoads;
00068     //corresponding lane to road choice
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     //return possible road choices given current road and lane.
00086     Road** RoadChoices(Road *curRoad, int curLane);
00087     //return possible lane to follow given destination road and current road and lane
00088     int LaneChoice(Road *curRoad, int curLane, Road* destRoad);
00089     int LaneChoice(Road *curRoad, int curLane, int destRoad);
00090 
00091     int m_iRoads;
00092     //roads
00093     class Road **m_pRoads;  //points to node's roads
00094     //structure to hold lanes associated with the road
00095     RoadIO **m_pRoadIO;
00096 };
00097 #endif //SWITCH
00098 
00099 //
00100 // A place where 2 or more roads meet
00101 //
00102 class Node
00103 {
00104 public:
00105     Node();
00106     ~Node();
00107 
00108     // comparison
00109     bool operator==(Node &ref);
00110 
00111     //copies internal variables from given node.
00112     void Copy(Node* node);
00113 
00114     class Road *GetRoad(int n);
00115     int FindRoad(int roadID);           //returns internal number of road with given ID.  -1 if not found.
00116     void AddRoad(class Road *pR);       //adds a road to the node
00117     void DetachRoad(class Road *pR);    //detaches the road from the node.
00118     double DistanceToPoint(DPoint2 target);  //distance from a point to the node
00119     void DetermineRoadAngles();         //resulting angles > 0
00120     void SortRoadsByAngle();            //sorts the internal roads by angle.
00121     DPoint2 find_adjacent_roadpoint2d(Road *pR);  //returns the 2nd point on the road from the node.
00122 
00123     //sets intersection type for node.  returns false if road not found
00124     bool SetIntersectType(Road *road, IntersectionType type);
00125     bool SetIntersectType(int roadNum, IntersectionType type);  //roadNum is internal index within the node
00126     IntersectionType GetIntersectType(Road *road);  //returns the intersection type of given road
00127     IntersectionType GetIntersectType(int roadNum); //returns the intersection type of given road index (not ID)
00128     LightStatus GetLightStatus(Road *road);         //returns the light status of given road
00129     LightStatus GetLightStatus(int roadNum);        //returns the light status of given road index (not ID)
00130     bool SetLightStatus(Road *road, LightStatus light); //sets the light status of given road
00131     bool SetLightStatus(int roadNum, LightStatus light); //sets the light status of given road index (not ID)
00132 
00133     bool HasLights();
00134     bool IsControlled();    // true if any stopsigns or stoplights
00135 
00136     //adjust the light relationship of the roads at the node (if the intersection is has a signal light.)
00137     void AdjustForLights();
00138 
00139 #if SWITCH
00140     void SetupSwitch();
00141     //i is index to current road
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;    // utm coordinates of center
00148     int m_iRoads;   // number of roads meeting here
00149     int m_id;       // only used for reading from DLG/RMF
00150 
00151     // angle of each road, not initialized till SortRoadsByAngle is called
00152     float *m_fRoadAngle;
00153 
00154     Node *m_pNext;
00155 protected:
00156     IntersectionType *m_IntersectTypes; //intersection types of the roads at this node.
00157     LightStatus *m_Lights;  //lights of the roads at this node.
00158     class Road **m_r;  //array of roads that intersect this node.
00159 };
00160 
00161 
00162 //
00163 // a series of points, connecting one node to another
00164 //
00165 class Road : public DLine2
00166 {
00167 public:
00168     Road();
00169     Road(Road &ref);
00170     ~Road();
00171 
00172     // comparison
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     // closet distance from target to the road
00178     double DistanceToPoint(DPoint2 target);
00179     // is the road a loop?
00180     bool IsLoop() { return (m_pNode[0] == m_pNode[1]); }
00181 
00182     void SetFlag(int flag, bool value); //value true, perform bitwise OR with flag.  otherwise, bitwise AND
00183     bool GetFlag(int flag);
00184 
00185     float GetHeightAt(int i);   //height at node (0 or 1).
00186     float GetHeightAt(Node *node);  //height at node
00187     void SetHeightAt(int i, float height);  //set the height at a node (0 or 1)
00188     void SetHeightAt(Node *node, float height); //set the height at a node
00189     float Length(); //returns length of road.
00190 
00191     float m_fWidth;     // road width in meters
00192     int m_iLanes;       // number of lanes
00193     SurfaceType m_Surface;
00194 
00195     int m_iHwy;         // highway number: -1 for normal roads
00196 
00197     Road *m_pNext;      // the next Road, if roads are maintained in list form
00198 
00199     int m_id;           // only used for reading from DLG
00200 
00201     unsigned int m_iFlags;  // a flag to be used to holding any addition info.
00202 
00203 protected:
00204     Node *m_pNode[2];   // "from" and "to" nodes
00205 //  IntersectionType m_iBehavior[2];
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();       // get the geographical extent of the road map
00225     void ComputeExtents();
00226 
00227     int     NumRoads() const;   // returns number of roads in the road map
00228     int     NumNodes() const;   // returns number of nodes in the road map
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     // cleaning function: remove unused nodes, return the number removed
00245     int RemoveUnusedNodes();
00246 
00247     vtProjection &GetProjection() { return m_proj; }
00248 
00249 protected:
00250     DRECT   m_extents;          // the extent of the roads in the RoadMap
00251     bool    m_bValidExtents;    // true when extents are computed
00252 
00253     Road    *m_pFirstRoad;
00254     Node    *m_pFirstNode;
00255 
00256     vtProjection    m_proj;
00257 };
00258 
00259 #endif

Generated at Fri Aug 17 14:40:42 2001 for vtdata library by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000