root / trunk / code / projects / traffic_navigation / intersectData.c @ 1933
History | View | Annotate | Download (2.47 KB)
1 |
#include "intersectData.h" |
---|---|
2 |
#include "lineDrive.h" |
3 |
|
4 |
/*
|
5 |
* This function serves to make the code for the intersection database
|
6 |
* as reuseable as possible. This part initializes the data and is the
|
7 |
* only one that needs to be rewritten for each map.
|
8 |
*
|
9 |
*/
|
10 |
|
11 |
void initializeData(){
|
12 |
//insert all intersections that are in the map.
|
13 |
//THIS DATA FOR THE DEMO MAP
|
14 |
insertNode(0, INTERSECTION_NODE, DOUBLE_C, TMIDDLE);
|
15 |
insertNode(1, ROAD_NODE, ROAD, ROAD_SINGLE);
|
16 |
insertNode(2, INTERSECTION_NODE, DOUBLE_C, TMIDDLE);
|
17 |
insertNode(4,ROAD_NODE,ROAD,HIGHWAY);
|
18 |
insertNode(5,INTERSECTION_NODE,DOUBLE_C,TMIDDLE);
|
19 |
insertNode(8,ROAD_NODE,ROAD,ROAD_SINGLE);
|
20 |
insertNode(10,ROAD_NODE,ROAD,ROAD_SINGLE);
|
21 |
insertNode(16,INTERSECTION_NODE,DOUBLE_C, TMIDDLE);
|
22 |
return;
|
23 |
} |
24 |
|
25 |
/*
|
26 |
* This function serves to make the code for the intersection database
|
27 |
* as reuseable as possible. This part creates the implementation of the
|
28 |
* database that can be copied over for all projects.
|
29 |
*
|
30 |
*/
|
31 |
|
32 |
|
33 |
// Does nothing if your indmax is out of bounds.
|
34 |
void insertNode(int key, int featureid, int node_type, int node_info){ |
35 |
// if (key < sizeof(IntersectData)/sizeof(int))
|
36 |
if(key < NUM_FEATURES)
|
37 |
NodeData[key] = (featureid<<12) + (node_type<<2) + node_info; |
38 |
return;
|
39 |
} |
40 |
|
41 |
void insertIntersection(int key, int node_type, int intersection_position){ |
42 |
if(key < NUM_FEATURES)
|
43 |
NodeData[key] = (INTERSECTION_NODE<<12) + (node_type<<2) |
44 |
+ intersection_position; |
45 |
return;
|
46 |
} |
47 |
|
48 |
void insertRoad(int key, int node_type, int road_type){ |
49 |
if(key < NUM_FEATURES)
|
50 |
NodeData[key] = (ROAD_NODE<<12) + (node_type<<2) + road_type; |
51 |
return;
|
52 |
} |
53 |
|
54 |
// Functions to get data from the Database:
|
55 |
//@TODO:Add some checks to make sure the key is less than NUM_FEATURES
|
56 |
// also: figure out what to do when this happens.
|
57 |
// Add checks to see if we call getIntersect...() on intersections
|
58 |
// and getRoad...() on roads.
|
59 |
|
60 |
int getFeatureId(int key) |
61 |
{ |
62 |
if(key < NUM_FEATURES)
|
63 |
return (NodeData[key]>>12)&15; |
64 |
else return -1; |
65 |
} |
66 |
|
67 |
int getIntersectType(int key){ |
68 |
if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE)
|
69 |
return (NodeData[key]>>2)&3; |
70 |
else return -1; |
71 |
} |
72 |
|
73 |
int getIntersectPos(int key){ |
74 |
if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE)
|
75 |
return (NodeData[key])&3; |
76 |
else return -1; |
77 |
} |
78 |
|
79 |
int getRoadType(int key){ |
80 |
if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE)
|
81 |
return (NodeData[key]>>2)&3; |
82 |
else return -1; |
83 |
} |
84 |
|
85 |
int getRoadInfo(int key){ |
86 |
if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE)
|
87 |
return (NodeData[key])&3; |
88 |
else return -1; |
89 |
} |
90 |
|