Mercurial Hosting > traffic-intelligence
changeset 663:65a867942eee
modified concatenate to take into account features if available
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 19 May 2015 16:58:26 +0200 |
parents | 72174e66aba5 |
children | 455f9b93819c |
files | python/moving.py |
diffstat | 1 files changed, 25 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/python/moving.py Mon May 18 17:17:06 2015 +0200 +++ b/python/moving.py Tue May 19 16:58:26 2015 +0200 @@ -1010,30 +1010,34 @@ # positions positions = Trajectory() for t in newTimeInterval: + nTotal = 0. p = Point(0.,0.) - n = 0. - if obj1.existsAtInstant(t): - p += obj1.getPositionAtInstant(t) - n += 1. - if obj2.existsAtInstant(t): - p += obj2.getPositionAtInstant(t) - n += 1. - assert n>0, 'there should be at least one point for each instant' - positions.addPosition(p.divide(n)) + for obj in [obj1, obj2]: + if obj.existsAtInstant(t): + if obj.hasFeatures(): + n = len([f for f in obj.getFeatures() if f.existsAtInstant(t)]) + else: + n = 1. + p += obj.getPositionAtInstant(t).multiply(n) + nTotal += n + assert nTotal>0, 'there should be at least one point for each instant' + positions.addPosition(p.divide(nTotal)) # velocities: if any if hasattr(obj1, 'velocities') and hasattr(obj2, 'velocities'): velocities = Trajectory() for t in newTimeInterval: + nTotal = 0. p = Point(0.,0.) - n = 0. - if obj1.existsAtInstant(t): - p += obj1.getVelocityAtInstant(t) - n += 1. - if obj2.existsAtInstant(t): - p += obj2.getVelocityAtInstant(t) - n += 1. + for obj in [obj1, obj2]: + if obj.existsAtInstant(t): + if obj.hasFeatures(): + n = len([f for f in obj.getFeatures() if f.existsAtInstant(t)]) + else: + n = 1. + p += obj.getVelocityAtInstant(t).multiply(n) + nTotal += n assert n>0, 'there should be at least one point for each instant' - velocities.addPosition(p.divide(n)) + velocities.addPosition(p.divide(nTotal)) else: velocities = None # TODO object envelop (polygon) @@ -1041,7 +1045,10 @@ if obj1.getUserType() != obj2.getUserType(): print('The two moving objects have different user types: obj1 {} obj2 {}'.format(userTypeNames[obj1.getUserType()], userTypeNames[obj2.getUserType()])) - return MovingObject(newNum, newTimeInterval, positions, velocities, userType = obj1.getUserType()) + newObject = MovingObject(newNum, newTimeInterval, positions, velocities, userType = obj1.getUserType()) + if obj1.hasFeatures() and obj2.hasFeatures(): + newObject.features = obj1.getFeatures()+obj2.getFeatures() + return newObject def getObjectInTimeInterval(self, inter): '''Returns a new object extracted from self,