Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/moving.py @ 1079:845d694af7b8
reversed minor bug
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 20 Jul 2018 16:36:42 -0400 |
| parents | 3939ae415be0 |
| children | 346b41cbc81a |
comparison
equal
deleted
inserted
replaced
| 1078:8cc3feb1c1c5 | 1079:845d694af7b8 |
|---|---|
| 1159 self.setNObjects(nObjects) # a feature has None for nObjects | 1159 self.setNObjects(nObjects) # a feature has None for nObjects |
| 1160 self.features = None | 1160 self.features = None |
| 1161 # compute bounding polygon from trajectory | 1161 # compute bounding polygon from trajectory |
| 1162 | 1162 |
| 1163 @staticmethod | 1163 @staticmethod |
| 1164 def cropedTimeInterval(obj, value, after = True): | 1164 def croppedTimeInterval(obj, value, after = True): |
| 1165 newTimeInterval = TimeInterval(obj.getFirstInstant(), min(value, obj.getLastInstant())) if after else TimeInterval(max(obj.getFirstInstant(), value), obj.getLastInstant()) | 1165 newTimeInterval = TimeInterval(obj.getFirstInstant(), min(value, obj.getLastInstant())) if after else TimeInterval(max(obj.getFirstInstant(), value), obj.getLastInstant()) |
| 1166 if obj.positions is not None : | 1166 if obj.positions is not None : |
| 1167 newPositions = obj.positions[slice(newTimeInterval.first, newTimeInterval.last+1)] | 1167 newPositions = obj.positions[slice(newTimeInterval.first, newTimeInterval.last+1)] |
| 1168 else: | 1168 else: |
| 1169 newPositions = None | 1169 newPositions = None |
| 1170 if obj.velocities is not None : | 1170 if obj.velocities is not None : |
| 1171 newVelocities = obj.velocities[slice(newTimeInterval.first, newTimeInterval.last+1)] | 1171 newVelocities = obj.velocities[slice(newTimeInterval.first, newTimeInterval.last+1)] |
| 1172 else: | 1172 else: |
| 1173 newVelocities = None | 1173 newVelocities = None |
| 1174 if obj.features is not None : | 1174 if obj.hasFeatures(): |
| 1175 newFeatures = [f.cropedTimeInterval(value, after) for f in obj.features] | 1175 newFeatures = [f.croppedTimeInterval(value, after) for f in obj.features] |
| 1176 else: | 1176 else: |
| 1177 newFeatures = None | 1177 newFeatures = None |
| 1178 res = MovingObject(obj.getNum(), newTimeInterval, newPositions, newVelocities, obj.geometry, obj.userType, obj.nObjects) | 1178 res = MovingObject(obj.getNum(), newTimeInterval, newPositions, newVelocities, obj.geometry, obj.userType, obj.nObjects) |
| 1179 res.features = newFeatures | 1179 res.features = newFeatures |
| 1180 res.featureNumbers = obj.featureNumbers | 1180 res.featureNumbers = obj.featureNumbers |
| 1181 if hasattr(obj, 'projectedPositions'): | 1181 #if hasattr(obj, 'projectedPositions'): |
| 1182 res.projectedPositions = obj.projectedPositions[slice(newTimeInterval.first, newTimeInterval.last+1)] | 1182 # res.projectedPositions = obj.projectedPositions[slice(newTimeInterval.first, newTimeInterval.last+1)] |
| 1183 return res | 1183 return res |
| 1184 | 1184 |
| 1185 | 1185 |
| 1186 @staticmethod | 1186 @staticmethod |
| 1187 def aggregateTrajectories(features, interval = None, aggFunc = mean): | 1187 def aggregateTrajectories(features, interval = None, aggFunc = mean): |
| 1222 else: | 1222 else: |
| 1223 newNum = num | 1223 newNum = num |
| 1224 commonTimeInterval = obj1.commonTimeInterval(obj2) | 1224 commonTimeInterval = obj1.commonTimeInterval(obj2) |
| 1225 if commonTimeInterval.empty(): | 1225 if commonTimeInterval.empty(): |
| 1226 #print('The two objects\' time intervals do not overlap: obj1 {} and obj2 {}'.format(obj1.getTimeInterval(), obj2.getTimeInterval())) | 1226 #print('The two objects\' time intervals do not overlap: obj1 {} and obj2 {}'.format(obj1.getTimeInterval(), obj2.getTimeInterval())) |
| 1227 emptyInterval = TimeInterval(min(obj1.getLastInstant(),obj2.getLastInstant()), max(obj1.getFirstInstant(),obj2.getFirstInstant())+1) | 1227 emptyInterval = TimeInterval(min(obj1.getLastInstant(),obj2.getLastInstant()), max(obj1.getFirstInstant(),obj2.getFirstInstant())) |
| 1228 if obj1.existsAtInstant(emptyInterval.last): | 1228 if obj1.existsAtInstant(emptyInterval.last): |
| 1229 firstObject = obj2 | 1229 firstObject = obj2 |
| 1230 secondObject = obj1 | 1230 secondObject = obj1 |
| 1231 else: | 1231 else: |
| 1232 firstObject = obj1 | 1232 firstObject = obj1 |
| 1235 positions = copy.deepcopy(firstObject.getPositions()) | 1235 positions = copy.deepcopy(firstObject.getPositions()) |
| 1236 velocities = copy.deepcopy(firstObject.getPositions()) | 1236 velocities = copy.deepcopy(firstObject.getPositions()) |
| 1237 featurePositions = Trajectory() | 1237 featurePositions = Trajectory() |
| 1238 featureVelocities = Trajectory() | 1238 featureVelocities = Trajectory() |
| 1239 p = firstObject.getPositionAtInstant(emptyInterval.first)+v | 1239 p = firstObject.getPositionAtInstant(emptyInterval.first)+v |
| 1240 for t in range(emptyInterval.first+1, emptyInterval.last+1): | 1240 for t in range(emptyInterval.first+1, emptyInterval.last): |
| 1241 positions.addPosition(p) | 1241 positions.addPosition(p) |
| 1242 velocities.addPosition(v) | 1242 velocities.addPosition(v) |
| 1243 featurePositions.addPosition(p) | 1243 featurePositions.addPosition(p) |
| 1244 featureVelocities.addPosition(v) | 1244 featureVelocities.addPosition(v) |
| 1245 p=p+v | 1245 p=p+v |
