Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/moving.py @ 1109:6e8ab471ebd4
minor adjustment to Lionel s needs
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 16 Apr 2019 11:58:23 -0400 |
| parents | 799ef82caa1a |
| children | 6bbcd9433732 |
comparison
equal
deleted
inserted
replaced
| 1108:77ce1cb3c868 | 1109:6e8ab471ebd4 |
|---|---|
| 261 e2 = e1.orthogonal(clockwise) | 261 e2 = e1.orthogonal(clockwise) |
| 262 return Point(Point.dot(self, e1), Point.dot(self, e2)) | 262 return Point(Point.dot(self, e1), Point.dot(self, e2)) |
| 263 | 263 |
| 264 def rotate(self, theta): | 264 def rotate(self, theta): |
| 265 return Point(self.x*cos(theta)-self.y*sin(theta), self.x*sin(theta)+self.y*cos(theta)) | 265 return Point(self.x*cos(theta)-self.y*sin(theta), self.x*sin(theta)+self.y*cos(theta)) |
| 266 | 266 |
| 267 def plot(self, options = 'o', **kwargs): | 267 def plot(self, options = 'o', **kwargs): |
| 268 plot([self.x], [self.y], options, **kwargs) | 268 plot([self.x], [self.y], options, **kwargs) |
| 269 | 269 |
| 270 @staticmethod | 270 @staticmethod |
| 271 def plotSegment(p1, p2, options = 'o', **kwargs): | 271 def plotSegment(p1, p2, options = 'o', **kwargs): |
| 355 def distanceNorm2(p1, p2): | 355 def distanceNorm2(p1, p2): |
| 356 return (p1-p2).norm2() | 356 return (p1-p2).norm2() |
| 357 | 357 |
| 358 @staticmethod | 358 @staticmethod |
| 359 def plotAll(points, options = '', **kwargs): | 359 def plotAll(points, options = '', **kwargs): |
| 360 plot([p.x for p in points],[p.y for p in points], options, **kwargs) | 360 plot([p.x for p in points], [p.y for p in points], options, **kwargs) |
| 361 | 361 |
| 362 def similarOrientation(self, refDirection, cosineThreshold): | 362 def similarOrientation(self, refDirection, cosineThreshold): |
| 363 'Indicates whether the cosine of the vector and refDirection is smaller than cosineThreshold' | 363 'Indicates whether the cosine of the vector and refDirection is smaller than cosineThreshold' |
| 364 return Point.cosine(self, refDirection) >= cosineThreshold | 364 return Point.cosine(self, refDirection) >= cosineThreshold |
| 365 | 365 |
| 418 frontLeft = Point(xmax, ymin) | 418 frontLeft = Point(xmax, ymin) |
| 419 frontRight = Point(xmax, ymax) | 419 frontRight = Point(xmax, ymax) |
| 420 rearLeft = Point(xmin, ymin) | 420 rearLeft = Point(xmin, ymin) |
| 421 rearRight = Point(xmin, ymax) | 421 rearRight = Point(xmin, ymax) |
| 422 return [Point(Point.dot(e1, p), Point.dot(e2, p)) for p in [frontLeft, frontRight, rearRight, rearLeft]] | 422 return [Point(Point.dot(e1, p), Point.dot(e2, p)) for p in [frontLeft, frontRight, rearRight, rearLeft]] |
| 423 | 423 |
| 424 if shapelyAvailable: | 424 if shapelyAvailable: |
| 425 def pointsInPolygon(points, polygon): | 425 def pointsInPolygon(points, polygon): |
| 426 '''Optimized tests of a series of points within (Shapely) polygon (not prepared)''' | 426 '''Optimized tests of a series of points within (Shapely) polygon (not prepared)''' |
| 427 if type(polygon) == PreparedGeometry: | 427 if type(polygon) == PreparedGeometry: |
| 428 prepared_polygon = polygon | 428 prepared_polygon = polygon |
| 530 i += 1 | 530 i += 1 |
| 531 if i < len(alignment): | 531 if i < len(alignment): |
| 532 d = s - alignment.getCumulativeDistance(i-1) # distance on subsegment | 532 d = s - alignment.getCumulativeDistance(i-1) # distance on subsegment |
| 533 #Get difference vector and then snap | 533 #Get difference vector and then snap |
| 534 dv = alignment[i] - alignment[i-1] | 534 dv = alignment[i] - alignment[i-1] |
| 535 #magnitude = dv.norm2() | |
| 536 normalizedV = dv.normalize() | 535 normalizedV = dv.normalize() |
| 537 #snapped = alignment[i-1] + normalizedV*d # snapped point coordinate along alignment | 536 #snapped = alignment[i-1] + normalizedV*d # snapped point coordinate along alignment |
| 538 # add offset finally | 537 # add offset finally |
| 539 orthoNormalizedV = normalizedV.orthogonal() | 538 orthoNormalizedV = normalizedV.orthogonal() |
| 540 return alignment[i-1] + normalizedV*d + orthoNormalizedV*y | 539 return alignment[i-1] + normalizedV*d + orthoNormalizedV*y |
| 966 ratio = 0 | 965 ratio = 0 |
| 967 indices.append(i+ratio) | 966 indices.append(i+ratio) |
| 968 intersections.append(p) | 967 intersections.append(p) |
| 969 return indices, intersections | 968 return indices, intersections |
| 970 | 969 |
| 971 def getTrajectoryInInterval(self, inter): | 970 def subTrajectoryInInterval(self, inter): |
| 972 'Returns all position between index inter.first and index.last (included)' | 971 'Returns all position between index inter.first and index.last (included)' |
| 973 if inter.first >=0 and inter.last<= self.length(): | 972 if inter.first >=0 and inter.last<= self.length(): |
| 974 return Trajectory([self.positions[0][inter.first:inter.last+1], | 973 return Trajectory([self.positions[0][inter.first:inter.last+1], |
| 975 self.positions[1][inter.first:inter.last+1]]) | 974 self.positions[1][inter.first:inter.last+1]]) |
| 976 else: | 975 else: |
| 1145 def getYCoordAt(self, i): | 1144 def getYCoordAt(self, i): |
| 1146 return self.positions[1][i] | 1145 return self.positions[1][i] |
| 1147 | 1146 |
| 1148 def getLaneAt(self, i): | 1147 def getLaneAt(self, i): |
| 1149 return self.lanes[i] | 1148 return self.lanes[i] |
| 1149 | |
| 1150 def subTrajectoryInInterval(self, inter): | |
| 1151 'Returns all curvilinear positions between index inter.first and index.last (included)' | |
| 1152 if inter.first >=0 and inter.last<= self.length(): | |
| 1153 return CurvilinearTrajectory(self.positions[0][inter.first:inter.last+1], | |
| 1154 self.positions[1][inter.first:inter.last+1], | |
| 1155 self.lanes[inter.first:inter.last+1]) | |
| 1156 else: | |
| 1157 return None | |
| 1150 | 1158 |
| 1151 def addPositionSYL(self, s, y, lane = None): | 1159 def addPositionSYL(self, s, y, lane = None): |
| 1152 self.addPositionXY(s,y) | 1160 self.addPositionXY(s,y) |
| 1153 self.lanes.append(lane) | 1161 self.lanes.append(lane) |
| 1154 | 1162 |
| 1723 if not hasattr(self, 'prototypeSimilarities'): | 1731 if not hasattr(self, 'prototypeSimilarities'): |
| 1724 self.prototypeSimilarities = [] | 1732 self.prototypeSimilarities = [] |
| 1725 for proto in prototypes: | 1733 for proto in prototypes: |
| 1726 lcss.similarities(proto.getMovingObject().getPositions().asArray().T, self.getPositions().asArray().T) | 1734 lcss.similarities(proto.getMovingObject().getPositions().asArray().T, self.getPositions().asArray().T) |
| 1727 similarities = lcss.similarityTable[-1, :-1].astype(float) | 1735 similarities = lcss.similarityTable[-1, :-1].astype(float) |
| 1728 self.prototypeSimilarities.append(similarities/minimum(arange(1.,len(similarities)+1), proto.getMovingObject().length()*ones(len(similarities)))) | 1736 self.prototypeSimilarities.append(similarities/minimum(arange(1., len(similarities)+1), proto.getMovingObject().length()*ones(len(similarities)))) |
| 1729 | 1737 |
| 1730 @staticmethod | 1738 @staticmethod |
| 1731 def computePET(obj1, obj2, collisionDistanceThreshold): | 1739 def computePET(obj1, obj2, collisionDistanceThreshold): |
| 1732 '''Post-encroachment time based on distance threshold | 1740 '''Post-encroachment time based on distance threshold |
| 1733 | 1741 |
| 1793 positions = [f.getPositionAtInstant(instant) for f in self.getFeatures() if f.existsAtInstant(instant)] | 1801 positions = [f.getPositionAtInstant(instant) for f in self.getFeatures() if f.existsAtInstant(instant)] |
| 1794 return Point.boundingRectangle(positions, self.getVelocityAtInstant(instant)) | 1802 return Point.boundingRectangle(positions, self.getVelocityAtInstant(instant)) |
| 1795 else: | 1803 else: |
| 1796 print('Object {} has no features'.format(self.getNum())) | 1804 print('Object {} has no features'.format(self.getNum())) |
| 1797 return None | 1805 return None |
| 1798 | 1806 |
| 1799 ### | 1807 ### |
| 1800 # User Type Classification | 1808 # User Type Classification |
| 1801 ### | 1809 ### |
| 1802 def classifyUserTypeSpeedMotorized(self, threshold, aggregationFunc = median, nInstantsIgnoredAtEnds = 0): | 1810 def classifyUserTypeSpeedMotorized(self, threshold, aggregationFunc = median, nInstantsIgnoredAtEnds = 0): |
| 1803 '''Classifies slow and fast road users | 1811 '''Classifies slow and fast road users |
