Mercurial Hosting > traffic-intelligence
diff trafficintelligence/moving.py @ 1041:fc7c0f38e8a6
added nObjects to MovingObject, with loading/saving
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 04 Jul 2018 16:06:23 -0400 |
parents | 6a6c37eb3a74 |
children | 75a6ad604cc5 |
line wrap: on
line diff
--- a/trafficintelligence/moving.py Wed Jul 04 15:37:04 2018 -0400 +++ b/trafficintelligence/moving.py Wed Jul 04 16:06:23 2018 -0400 @@ -1141,12 +1141,13 @@ and a usertype (e.g. road user) coded as a number (see userTypeNames) ''' - def __init__(self, num = None, timeInterval = None, positions = None, velocities = None, geometry = None, userType = userType2Num['unknown']): + def __init__(self, num = None, timeInterval = None, positions = None, velocities = None, geometry = None, userType = userType2Num['unknown'], nObjects = None): super(MovingObject, self).__init__(num, timeInterval) self.positions = positions self.velocities = velocities self.geometry = geometry self.userType = userType + self.setNObjects(nObjects) # a feature has None for nObjects self.features = None # compute bounding polygon from trajectory @@ -1213,7 +1214,7 @@ for t in secondObject.getTimeInterval(): positions.addPosition(secondObject.getPositionAtInstant(t)) velocities.addPosition(secondObject.getVelocityAtInstant(t)) - newObject = MovingObject(newNum, TimeInterval(firstObject.getFirstInstant(), secondObject.getLastInstant()), positions, velocities) + newObject = MovingObject(newNum, TimeInterval(firstObject.getFirstInstant(), secondObject.getLastInstant()), positions, velocities, nObjects = 1) if hasattr(obj1, 'featureNumbers') and hasattr(obj2, 'featureNumbers'): if newFeatureNum is not None: newObject.featureNumbers = obj1.featureNumbers+obj2.featureNumbers+[newFeatureNum] @@ -1223,7 +1224,7 @@ newObject.features = obj1.getFeatures()+obj2.getFeatures()+[MovingObject(newFeatureNum, TimeInterval(emptyInterval.first+1, emptyInterval.last-1), featurePositions, featureVelocities)] else: # time intervals overlap newTimeInterval = TimeInterval.union(obj1.getTimeInterval(), obj2.getTimeInterval()) - newObject = MovingObject(newNum, newTimeInterval) + newObject = MovingObject(newNum, newTimeInterval, nObjects = 1) # hypothesis is that it's the same object being reunited if hasattr(obj1, 'featureNumbers') and hasattr(obj2, 'featureNumbers'): newObject.featureNumbers = obj1.featureNumbers+obj2.featureNumbers if obj1.hasFeatures() and obj2.hasFeatures(): @@ -1243,7 +1244,7 @@ intersection = TimeInterval.intersection(inter, self.getTimeInterval()) if not intersection.empty(): trajectoryInterval = TimeInterval(intersection.first-self.getFirstInstant(), intersection.last-self.getFirstInstant()) - obj = MovingObject(self.num, intersection, self.positions.getTrajectoryInInterval(trajectoryInterval), self.geometry, self.userType) + obj = MovingObject(self.num, intersection, self.positions.getTrajectoryInInterval(trajectoryInterval), self.geometry, self.userType, self.nObjects) if self.velocities is not None: obj.velocities = self.velocities.getTrajectoryInInterval(trajectoryInterval) return obj @@ -1330,6 +1331,15 @@ def setUserType(self, userType): self.userType = userType + def getNObjects(self): + return self.nObjects + + def setNObjects(self, nObjects): + if nObjects is None or nObjects >= 1: + self.nObjects = nObjects + else: + print('Number of objects represented by object {} must be greater or equal to 1 ({})'.format(self.getNum(), nObjects)) + def setFeatures(self, features, featuresOrdered = False): '''Sets the features in the features field based on featureNumbers if not all features are loaded from 0, one needs to renumber in a dict'''