comparison python/event.py @ 291:9f81218e497a

class VehPairs subsumes createInteractions(objects); legacy code remains
author Paul@BEAST-III
date Tue, 05 Feb 2013 15:45:33 -0500
parents dbe7e53334d7
children 8b2c8a4015f1
comparison
equal deleted inserted replaced
290:df58d361f19e 291:9f81218e497a
2 '''Libraries for events 2 '''Libraries for events
3 Interactions, pedestrian crossing...''' 3 Interactions, pedestrian crossing...'''
4 4
5 #import utils; 5 #import utils;
6 import moving 6 import moving
7 import prediction
7 8
8 __metaclass__ = type 9 __metaclass__ = type
10
11 ## Subsumes createInteractions(objects) with a VehPair Object
12 class VehPairs():
13 def __init__(self,objects):
14 '''
15 Create all pairs of two co-existing road users
16 TODO: add test to compute categories?
17 '''
18 #print(' -------------') #Disabled for traffic-intelligence trunk
19 #print(' Generating vehicle pairs...') #Disabled for traffic-intelligence trunk
20
21 self.pairs = []
22 num = 0
23 for i in xrange(len(objects)):
24 for j in xrange(i):
25 commonTimeInterval = objects[i].commonTimeInterval(objects[j])
26 if not commonTimeInterval.empty():
27 self.pairs.append(event.Interaction(num, commonTimeInterval, objects[i].num, objects[j].num, objects[i], objects[j]))
28 num += 1
29
30 def calculateIndicators(self,predParam,frameRate=15,collisionDistanceThreshold=1.8,timeHorizonMultiplier=5):
31 #print(' -------------') #Disabled for traffic-intelligence trunk
32 #print(' Calculating time-to-collision...') #Disabled for traffic-intelligence trunk
33
34 timeHorizon = frameRate*timeHorizonMultiplier # prediction time Horizon = 1.5 s (reaction time) (5 second)
35
36 for params in [predParam]:
37
38 #prog = Tools.ProgressBar(0, len(self.pairs), 77) #Disabled for traffic-intelligence trunk (PVA Tools dependancy)
39 for j in xrange(len(self.pairs)):
40 #prog.updateAmount(j) #Disabled for traffic-intelligence trunk (PVA Tools dependancy)
41
42 collisionPoints, crossingZones = prediction.computeCrossingsCollisions(self.pairs[j].movingObject1, self.pairs[j].movingObject2, predParam, collisionDistanceThreshold, timeHorizon)
43
44 # Ignore empty collision points
45 empty = 1
46 for i in collisionPoints:
47 if(collisionPoints[i] != []):
48 empty = 0
49 if(empty == 1):
50 self.pairs[j].hasCP = 0
51 else:
52 self.pairs[j].hasCP = 1
53 self.pairs[j].CP = collisionPoints
54
55 # Ignore empty crossing zones
56 empty = 1
57 for i in crossingZones:
58 if(crossingZones[i] != []):
59 empty = 0
60 if(empty == 1):
61 self.pairs[j].hasCZ = 0
62 else:
63 self.pairs[j].hasCZ = 1
64 self.pairs[j].CZ = crossingZones
65 return
66
67 def getPairsWCP(self):
68 lists = []
69 for j in self.pairs:
70 if(j.hasCP):
71 lists.append(j.num)
72 return lists
73
74 def getPairsWCZ(self):
75 lists = []
76 for j in self.pairs:
77 if(j.hasCZ):
78 lists.append(j.num)
79 return lists
80
81 def getCPlist(self):
82 lists = []
83 for j in self.pairs:
84 if(j.hasCP):
85 for k in j.CP:
86 if(j.CP[k] != []):
87 lists.append(j.CP[k])
88 return lists
89
90 def getCZlist(self):
91 lists = []
92 for j in self.pairs:
93 if(j.hasCZ):
94 for k in j.CZ:
95 if(j.CZ[k] != []):
96 lists.append(j.CZ[k])
97 return lists
9 98
10 class Interaction(moving.STObject): 99 class Interaction(moving.STObject):
11 '''Class for an interaction between two road users 100 '''Class for an interaction between two road users
12 or a road user and an obstacle 101 or a road user and an obstacle
13 102
48 collisionCourseCosine[instant] = collisionCourseDotProduct[i]/(distances[i]*deltav.norm2()) 137 collisionCourseCosine[instant] = collisionCourseDotProduct[i]/(distances[i]*deltav.norm2())
49 self.indicators = [moving.SeverityIndicator('Collision Course Dot Product', collisionCourseDotProduct, self.timeInterval), 138 self.indicators = [moving.SeverityIndicator('Collision Course Dot Product', collisionCourseDotProduct, self.timeInterval),
50 moving.SeverityIndicator('Distances', distances, self.timeInterval), 139 moving.SeverityIndicator('Distances', distances, self.timeInterval),
51 moving.SeverityIndicator('Collision Course Cosine', collisionCourseCosine)] 140 moving.SeverityIndicator('Collision Course Cosine', collisionCourseCosine)]
52 141
142
143 ######====>BEGIN LEGACY CODE
53 def createInteractions(objects): 144 def createInteractions(objects):
54 '''Create all interactions of two co-existing road users 145 '''Create all interactions of two co-existing road users
55 146
56 todo add test to compute categories?''' 147 todo add test to compute categories?'''
57 interactions = [] 148 interactions = []
61 commonTimeInterval = objects[i].commonTimeInterval(objects[j]) 152 commonTimeInterval = objects[i].commonTimeInterval(objects[j])
62 if not commonTimeInterval.empty(): 153 if not commonTimeInterval.empty():
63 interactions.append(Interaction(num, commonTimeInterval, objects[i].num, objects[j].num, objects[i], objects[j])) 154 interactions.append(Interaction(num, commonTimeInterval, objects[i].num, objects[j].num, objects[i], objects[j]))
64 num += 1 155 num += 1
65 return interactions 156 return interactions
157 #<====END LEGACY CODE#####
158
159
66 160
67 class Crossing(moving.STObject): 161 class Crossing(moving.STObject):
68 '''Class for the event of a street crossing 162 '''Class for the event of a street crossing
69 163
70 TODO: detecter passage sur la chaussee 164 TODO: detecter passage sur la chaussee