changeset 601:e1f3b789c632

add a definition of interaction and collision course intervals
author Mohamed Gomaa
date Thu, 02 May 2013 11:35:45 -0400
parents 414b2e7cd873
children 480c8edf177e
files python/events.py
diffstat 1 files changed, 49 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/python/events.py	Thu Apr 18 17:12:53 2013 -0400
+++ b/python/events.py	Thu May 02 11:35:45 2013 -0400
@@ -47,10 +47,13 @@
         collisionCourseAngles = {}
         distances = {}#[0]*int(self.timeInterval.length())
         speedDifferentials = {}
+        velocityAngle= {}
         for instant in self.timeInterval:
             deltap = self.movingObject1.getPositionAtInstant(instant)-self.movingObject2.getPositionAtInstant(instant)
             deltav = self.movingObject2.getVelocityAtInstant(instant)-self.movingObject1.getVelocityAtInstant(instant)
             collisionCourseDotProducts[instant] = moving.Point.dot(deltap, deltav)
+            velocityDotProduct= moving.Point.dot(self.movingObject1.getVelocityAtInstant(instant),self.movingObject2.getVelocityAtInstant(instant))
+            velocityAngle[instant]= np.arccos(velocityDotProduct/ (self.movingObject1.getVelocityAtInstant(instant).norm2() * self.movingObject2.getVelocityAtInstant(instant).norm2()))
             distances[instant] = deltap.norm2()
             speedDifferentials[instant] = deltav.norm2()
             if collisionCourseDotProducts[instant] > 0:
@@ -60,6 +63,7 @@
         self.addIndicator(indicators.SeverityIndicator('Collision Course Dot Product', collisionCourseDotProducts))
         self.addIndicator(indicators.SeverityIndicator('Distance', distances))
         self.addIndicator(indicators.SeverityIndicator('Speed Differential', speedDifferentials))
+        self.addIndicator(indicators.SeverityIndicator('Velocity Angle', velocityAngle))
         self.addIndicator(indicators.SeverityIndicator('Collision Course Angle', collisionCourseAngles))
 
         # todo test for interaction instants and interval, compute indicators
@@ -82,6 +86,51 @@
         else:
             print('Features not associated with objects')
 
+    def defineInteractionInterval(self):
+        ''' interaction defined as the first and last time that the collion course is positive'''
+        keys=sorted(self.getIndicator('Collision Course Angle').values.keys())
+        if keys!=[]:
+            self.interactionInterval= moving.TimeInterval(keys[0],keys[-1])
+        else:
+            print('no interaction')
+            self.interactionInterval=None
+			
+    def defineCollisionPointInterval(self):
+        ''' collision point defined as the first and last time that the collion point exist'''
+        values= self.getIndicator('TTC').values
+        keys=sorted(values.keys())
+		#keysReverse=sorted(values.keys(),reverse=True)		
+        keysWithoutinf= [key for key in keys if values[key]!=np.inf]
+        if keysWithoutinf!=[]:
+            self.collisionPointInterval= moving.TimeInterval(min(keysWithoutinf),max(keysWithoutinf))
+        else:
+            print('no collision points')
+            self.collisionPointInterval=None	
+			
+    def removeIndicatorExtraValues(self,indicatorName):
+        ''' refine the indicators value wrt interaction definition'''
+        self.defineInteractionInterval()
+        refinedIndicator = {}
+        if self.interactionInterval!= None:
+            for i in xrange(self.interactionInterval.first,self.interactionInterval.last+1):
+                if self.getIndicator(indicatorName).values.get(i)== None:
+                    refinedIndicator[i]= None
+                else:
+                    refinedIndicator[i]= self.getIndicator(indicatorName).values[i]
+        self.addIndicator(indicators.SeverityIndicator(str(indicatorName)+' New', refinedIndicator))
+
+    def removeIndicatorExtraValuesCP(self,indicatorName):
+        ''' refine the indicators value wrt interaction definition'''
+        self.defineCollisionPointInterval()
+        refinedIndicator = {}
+        if self.collisionPointInterval!= None:
+            for i in xrange(self.collisionPointInterval.first,self.collisionPointInterval.last+1):
+                if self.getIndicator(indicatorName).values.get(i)== None:
+                    refinedIndicator[i]= None
+                else:
+                    refinedIndicator[i]= self.getIndicator(indicatorName).values[i]
+        self.addIndicator(indicators.SeverityIndicator(str(indicatorName)+'2', refinedIndicator))
+		
     def addVideoFilename(self,videoFilename):
         self.videoFilename= videoFilename