Mercurial Hosting > traffic-intelligence
changeset 995:349cd5e73f79
work in progress
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 21 May 2018 22:56:58 -0400 |
parents | 8118c6b77d7c |
children | add667153087 |
files | python/moving.py |
diffstat | 1 files changed, 32 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/python/moving.py Sun May 20 10:56:24 2018 -0400 +++ b/python/moving.py Mon May 21 22:56:58 2018 -0400 @@ -1133,12 +1133,17 @@ # compute bounding polygon from trajectory @staticmethod + def aggregateTrajectory(features, aggFunc = np.mean): + 'Computes the aggregate trajectory from list of MovingObject features' + return None + + @staticmethod def generate(num, p, v, timeInterval): positions, velocities = Trajectory.generate(p, v, int(timeInterval.length())) return MovingObject(num = num, timeInterval = timeInterval, positions = positions, velocities = velocities) @staticmethod - def concatenate(obj1, obj2, num = None): + def concatenate(obj1, obj2, num = None, computePositions = False): '''Concatenates two objects supposed to overlap temporally ''' if num is None: newNum = obj1.getNum() @@ -1172,23 +1177,8 @@ else: newTimeInterval = TimeInterval.union(obj1.getTimeInterval(), obj2.getTimeInterval()) # positions - positions = Trajectory() - for t in newTimeInterval: - nTotal = 0. - p = Point(0.,0.) - 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).__mul__(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() + if computePositions: # TODO it would probably be better to recompute from all features, if features are available, in other method + positions = Trajectory() for t in newTimeInterval: nTotal = 0. p = Point(0.,0.) @@ -1198,11 +1188,30 @@ n = len([f for f in obj.getFeatures() if f.existsAtInstant(t)]) else: n = 1. - p += obj.getVelocityAtInstant(t).__mul__(n) + p += obj.getPositionAtInstant(t).__mul__(n) nTotal += n - assert n>0, 'there should be at least one point for each instant' - velocities.addPosition(p.divide(nTotal)) + assert nTotal>0, 'there should be at least one point for each instant' + positions.addPosition(p.divide(nTotal)) + # velocities: if any + if obj1.getVelocities() is not None and obj2.getVelocities() is not None: + velocities = Trajectory() + for t in newTimeInterval: + nTotal = 0. + p = Point(0.,0.) + 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).__mul__(n) + nTotal += n + assert n>0, 'there should be at least one point for each instant' + velocities.addPosition(p.divide(nTotal)) + else: + velocities = None else: + positions = None velocities = None # TODO object envelop (polygon) # user type @@ -1210,6 +1219,8 @@ print('The two moving objects have different user types: obj1 {} obj2 {}'.format(userTypeNames[obj1.getUserType()], userTypeNames[obj2.getUserType()])) newObject = MovingObject(newNum, newTimeInterval, positions, velocities, userType = obj1.getUserType()) + if hasattr(obj1, 'featureNumbers') and hasattr(obj2, 'featureNumbers'): + newObject.featureNumbers = obj1.featureNumbers+obj2.featureNumbers if obj1.hasFeatures() and obj2.hasFeatures(): newObject.features = obj1.getFeatures()+obj2.getFeatures() return newObject