Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/moving.py @ 1282:106365257da9
reorganization of moving.py and adding documentation tests
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 09 Jul 2024 17:44:51 -0400 |
| parents | 8915747a4fc8 |
| children | 77a310e29233 |
comparison
equal
deleted
inserted
replaced
| 1281:8915747a4fc8 | 1282:106365257da9 |
|---|---|
| 1573 if not intersection.empty(): | 1573 if not intersection.empty(): |
| 1574 trajectoryInterval = TimeInterval(intersection.first-self.getFirstInstant(), intersection.last-self.getFirstInstant()) | 1574 trajectoryInterval = TimeInterval(intersection.first-self.getFirstInstant(), intersection.last-self.getFirstInstant()) |
| 1575 obj = MovingObject(self.num, intersection, self.positions.subTrajectoryInInterval(trajectoryInterval), self.geometry, self.userType, self.nObjects) | 1575 obj = MovingObject(self.num, intersection, self.positions.subTrajectoryInInterval(trajectoryInterval), self.geometry, self.userType, self.nObjects) |
| 1576 if self.velocities is not None: | 1576 if self.velocities is not None: |
| 1577 obj.velocities = self.velocities.subTrajectoryInInterval(trajectoryInterval) | 1577 obj.velocities = self.velocities.subTrajectoryInInterval(trajectoryInterval) |
| 1578 if hasattr(self, 'curvilinearPositions'): | |
| 1579 obj.curvilinearPositions = self.curvilinearPositions.subTrajectoryInInterval(trajectoryInterval) | |
| 1580 | |
| 1578 return obj | 1581 return obj |
| 1579 else: | 1582 else: |
| 1580 print('The object does not exist at {}'.format(inter)) | 1583 print('The object does not exist at {}'.format(inter)) |
| 1581 return None | 1584 return None |
| 1582 | 1585 |
| 1870 self.positions.reset(meanPosition.x, meanPosition.y) | 1873 self.positions.reset(meanPosition.x, meanPosition.y) |
| 1871 self.velocities.reset(0,0) | 1874 self.velocities.reset(0,0) |
| 1872 if self.hasFeatures(): | 1875 if self.hasFeatures(): |
| 1873 for f in self.getFeatures(): | 1876 for f in self.getFeatures(): |
| 1874 f.setStationary() | 1877 f.setStationary() |
| 1875 | 1878 |
| 1879 # Plotting functions | |
| 1876 def plot(self, options = '', withOrigin = False, timeStep = 1, withFeatures = False, withOutline = False, withIds = False, **kwargs): | 1880 def plot(self, options = '', withOrigin = False, timeStep = 1, withFeatures = False, withOutline = False, withIds = False, **kwargs): |
| 1877 if withIds: | 1881 if withIds: |
| 1878 objNum = self.getNum() | 1882 objNum = self.getNum() |
| 1879 else: | 1883 else: |
| 1880 objNum = None | 1884 objNum = None |
| 2090 def motDistanceAtInstant(self, obj, instant): | 2094 def motDistanceAtInstant(self, obj, instant): |
| 2091 '''Returns distance for computing CLEAR MOT metrics | 2095 '''Returns distance for computing CLEAR MOT metrics |
| 2092 (returns an actual value, otherwise munkres does not terminate)''' | 2096 (returns an actual value, otherwise munkres does not terminate)''' |
| 2093 return Point.distanceNorm2(self.getPositionAtInstant(instant), obj.getPositionAtInstant(instant)) | 2097 return Point.distanceNorm2(self.getPositionAtInstant(instant), obj.getPositionAtInstant(instant)) |
| 2094 | 2098 |
| 2099 @staticmethod | |
| 2100 def collisionCourseDotProduct(movingObject1, movingObject2, instant): | |
| 2101 'A positive result indicates that the road users are getting closer' | |
| 2102 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) | |
| 2103 deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant) | |
| 2104 return Point.dot(deltap, deltav) | |
| 2105 | |
| 2106 @staticmethod | |
| 2107 def collisionCourseCosine(movingObject1, movingObject2, instant): | |
| 2108 'A positive result indicates that the road users are getting closer' | |
| 2109 return Point.cosine(movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant), #deltap | |
| 2110 movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant)) #deltav | |
| 2111 | |
| 2095 ### | 2112 ### |
| 2096 # User Type Classification | 2113 # User Type Classification |
| 2097 ### | 2114 ### |
| 2098 def classifyUserTypeSpeedMotorized(self, threshold, aggregationFunc = median, nInstantsIgnoredAtEnds = 0): | 2115 def classifyUserTypeSpeedMotorized(self, threshold, aggregationFunc = median, nInstantsIgnoredAtEnds = 0): |
| 2099 '''Classifies slow and fast road users | 2116 '''Classifies slow and fast road users |
| 2233 for userTypename in areas: | 2250 for userTypename in areas: |
| 2234 if areas[userTypename][p.x, p.y] != 0: | 2251 if areas[userTypename][p.x, p.y] != 0: |
| 2235 possibleUserTypes[userType2Enum[userTypename]] += 1 | 2252 possibleUserTypes[userType2Enum[userTypename]] += 1 |
| 2236 # what to do: threshold for most common type? self.setUserType() | 2253 # what to do: threshold for most common type? self.setUserType() |
| 2237 return possibleUserTypes | 2254 return possibleUserTypes |
| 2238 | |
| 2239 @staticmethod | |
| 2240 def collisionCourseDotProduct(movingObject1, movingObject2, instant): | |
| 2241 'A positive result indicates that the road users are getting closer' | |
| 2242 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) | |
| 2243 deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant) | |
| 2244 return Point.dot(deltap, deltav) | |
| 2245 | |
| 2246 @staticmethod | |
| 2247 def collisionCourseCosine(movingObject1, movingObject2, instant): | |
| 2248 'A positive result indicates that the road users are getting closer' | |
| 2249 return Point.cosine(movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant), #deltap | |
| 2250 movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant)) #deltav | |
| 2251 | 2255 |
| 2252 | 2256 |
| 2253 class Prototype(object): | 2257 class Prototype(object): |
| 2254 'Class for a prototype' | 2258 'Class for a prototype' |
| 2255 | 2259 |
