Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / traffic_navigation / intersectData.c @ 1934

History | View | Annotate | Download (2.47 KB)

1 1887 pdeo
#include "intersectData.h"
2 1912 pdeo
#include "lineDrive.h"
3 1887 pdeo
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 1904 jdcooper
        //THIS DATA FOR THE DEMO MAP
14 1912 pdeo
        insertNode(0, INTERSECTION_NODE, DOUBLE_C, TMIDDLE);
15 1933 bwasserm
        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 1887 pdeo
        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 1912 pdeo
// Does nothing if your indmax is out of bounds.
34 1908 pdeo
void insertNode(int key, int featureid, int node_type, int node_info){
35 1903 jdcooper
//        if (key < sizeof(IntersectData)/sizeof(int))
36 1904 jdcooper
        if(key < NUM_FEATURES)
37 1912 pdeo
          NodeData[key] = (featureid<<12) + (node_type<<2) + node_info;
38 1887 pdeo
        return;
39
}
40
41 1912 pdeo
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 1887 pdeo
// Functions to get data from the Database:
55 1904 jdcooper
//@TODO:Add some checks to make sure the key is less than NUM_FEATURES
56 1903 jdcooper
//        also: figure out what to do when this happens.
57 1908 pdeo
//        Add checks to see if we call getIntersect...() on intersections
58
//        and getRoad...() on roads.
59 1887 pdeo
60 1912 pdeo
int getFeatureId(int key)
61
{
62
        if(key < NUM_FEATURES)
63
          return (NodeData[key]>>12)&15;
64
        else return -1;
65 1887 pdeo
}
66
67 1912 pdeo
int getIntersectType(int key){
68
        if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE)
69
          return (NodeData[key]>>2)&3;
70
        else return -1;
71 1908 pdeo
}
72 1906 jdcooper
73 1908 pdeo
int getIntersectPos(int key){
74 1912 pdeo
        if(key < NUM_FEATURES && getFeatureId(key) == INTERSECTION_NODE)
75
          return (NodeData[key])&3;
76
        else return -1;
77 1906 jdcooper
}
78 1912 pdeo
79 1908 pdeo
int getRoadType(int key){
80 1912 pdeo
        if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE)
81
          return (NodeData[key]>>2)&3;
82
        else return -1;
83 1908 pdeo
}
84 1912 pdeo
85 1908 pdeo
int getRoadInfo(int key){
86 1912 pdeo
        if(key < NUM_FEATURES && getFeatureId(key) == ROAD_NODE)
87
          return (NodeData[key])&3;
88
        else return -1;
89 1908 pdeo
}