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