Mercurial Hosting > traffic-intelligence
comparison trafficintelligence/moving.py @ 1134:4b2a55d570c1
resolve issue for short features when merging objects manually
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 05 Mar 2020 16:20:29 -0500 |
parents | c4d9c270f999 |
children | 342701cdac30 |
comparison
equal
deleted
inserted
replaced
1133:c4d9c270f999 | 1134:4b2a55d570c1 |
---|---|
1297 | 1297 |
1298 def updatePositions(self): | 1298 def updatePositions(self): |
1299 inter, self.positions, self.velocities = MovingObject.aggregateTrajectories(self.features, self.getTimeInterval()) | 1299 inter, self.positions, self.velocities = MovingObject.aggregateTrajectories(self.features, self.getTimeInterval()) |
1300 | 1300 |
1301 @staticmethod | 1301 @staticmethod |
1302 def concatenate(obj1, obj2, num = None, newFeatureNum = None, computePositions = False): | 1302 def concatenate(obj1, obj2, num = None, newFeatureNum = None, minFeatureLength = 5): |
1303 '''Concatenates two objects, whether overlapping temporally or not | 1303 '''Concatenates two objects, whether overlapping temporally or not |
1304 | 1304 |
1305 Positions will be recomputed only if computePositions is True | 1305 Positions will be recomputed features are merged |
1306 Otherwise, only featureNumbers and/or features will be merged''' | 1306 Otherwise, only featureNumbers and/or features will be merged |
1307 minFeatureLength enforces a minimum length to avoid small features | |
1308 (and smaller velocities that are not saved)''' | |
1307 if num is None: | 1309 if num is None: |
1308 newNum = obj1.getNum() | 1310 newNum = obj1.getNum() |
1309 else: | 1311 else: |
1310 newNum = num | 1312 newNum = num |
1311 commonTimeInterval = obj1.commonTimeInterval(obj2) | 1313 commonTimeInterval = obj1.commonTimeInterval(obj2) |
1329 velocities.addPosition(v) | 1331 velocities.addPosition(v) |
1330 featurePositions.addPosition(p) | 1332 featurePositions.addPosition(p) |
1331 featureVelocities.addPosition(v) | 1333 featureVelocities.addPosition(v) |
1332 p=p+v | 1334 p=p+v |
1333 for t in secondObject.getTimeInterval(): | 1335 for t in secondObject.getTimeInterval(): |
1334 positions.addPosition(secondObject.getPositionAtInstant(t)) | 1336 p = secondObject.getPositionAtInstant(t) |
1335 velocities.addPosition(secondObject.getVelocityAtInstant(t)) | 1337 v = secondObject.getVelocityAtInstant(t) |
1338 positions.addPosition(p) | |
1339 velocities.addPosition(v) | |
1340 if featurePositions.length() < minFeatureLength: | |
1341 featurePositions.addPosition(p) | |
1342 featureVelocities.addPosition(v) | |
1336 newObject = MovingObject(newNum, TimeInterval(firstObject.getFirstInstant(), secondObject.getLastInstant()), positions, velocities, nObjects = 1) | 1343 newObject = MovingObject(newNum, TimeInterval(firstObject.getFirstInstant(), secondObject.getLastInstant()), positions, velocities, nObjects = 1) |
1337 if hasattr(obj1, 'featureNumbers') and hasattr(obj2, 'featureNumbers'): | 1344 if hasattr(obj1, 'featureNumbers') and hasattr(obj2, 'featureNumbers'): |
1338 if newFeatureNum is not None: | 1345 if newFeatureNum is not None: |
1339 newObject.featureNumbers = obj1.featureNumbers+obj2.featureNumbers+[newFeatureNum] | 1346 newObject.featureNumbers = obj1.featureNumbers+obj2.featureNumbers+[newFeatureNum] |
1340 else: | 1347 else: |
1341 print('Issue, new created feature has no num id') | 1348 print('Issue, new created feature has no num id') |
1342 if obj1.hasFeatures() and obj2.hasFeatures(): | 1349 if obj1.hasFeatures() and obj2.hasFeatures(): |
1343 newObject.features = obj1.getFeatures()+obj2.getFeatures()+[MovingObject(newFeatureNum, TimeInterval(emptyInterval.first+1, emptyInterval.last-1), featurePositions, featureVelocities)] | 1350 newObject.features = obj1.getFeatures()+obj2.getFeatures()+[MovingObject(newFeatureNum, TimeInterval(emptyInterval.first+1, emptyInterval.first+featurePositions.length()), featurePositions, featureVelocities)] |
1344 newObject.updatePositions() | 1351 newObject.updatePositions() |
1345 else: # time intervals overlap | 1352 else: # time intervals overlap |
1346 newTimeInterval = TimeInterval.union(obj1.getTimeInterval(), obj2.getTimeInterval()) | 1353 newTimeInterval = TimeInterval.union(obj1.getTimeInterval(), obj2.getTimeInterval()) |
1347 newObject = MovingObject(newNum, newTimeInterval, nObjects = 1) # hypothesis is that it's the same object being reunited | 1354 newObject = MovingObject(newNum, newTimeInterval, nObjects = 1) # hypothesis is that it's the same object being reunited |
1348 if hasattr(obj1, 'featureNumbers') and hasattr(obj2, 'featureNumbers'): | 1355 if hasattr(obj1, 'featureNumbers') and hasattr(obj2, 'featureNumbers'): |