Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 327:42f2b46ec210
added class for trajectories in curvilinear coordinates
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 12 Jun 2013 17:28:34 -0400 |
parents | 82a8fba99bec |
children | a70c205ebdd9 |
comparison
equal
deleted
inserted
replaced
326:f7872d15a6cc | 327:42f2b46ec210 |
---|---|
337 '''Class for trajectories: temporal sequence of positions | 337 '''Class for trajectories: temporal sequence of positions |
338 | 338 |
339 The class is iterable''' | 339 The class is iterable''' |
340 | 340 |
341 def __init__(self, positions=None): | 341 def __init__(self, positions=None): |
342 if positions != None: | 342 if positions: |
343 self.positions = positions | 343 self.positions = positions |
344 else: | 344 else: |
345 self.positions = [[],[]] | 345 self.positions = [[],[]] |
346 | 346 |
347 @staticmethod | 347 @staticmethod |
354 t = Trajectory() | 354 t = Trajectory() |
355 for p in points: | 355 for p in points: |
356 t.addPosition(p) | 356 t.addPosition(p) |
357 return t | 357 return t |
358 | 358 |
359 def __len__(self): | |
360 return len(self.positions[0]) | |
361 | |
362 def length(self): | |
363 return self.__len__() | |
364 | |
359 def __str__(self): | 365 def __str__(self): |
360 return ' '.join([self.__getitem__(i).__str__() for i in xrange(self.length())]) | 366 return ' '.join([self.__getitem__(i).__str__() for i in xrange(self.length())]) |
361 | 367 |
362 def __repr__(self): | 368 def __repr__(self): |
363 return str(self) | 369 return str(self) |
374 raise StopIteration | 380 raise StopIteration |
375 else: | 381 else: |
376 self.iterInstantNum += 1 | 382 self.iterInstantNum += 1 |
377 return self[self.iterInstantNum-1] | 383 return self[self.iterInstantNum-1] |
378 | 384 |
379 def length(self): | 385 def setPositionXY(self, i, x, y): |
380 return len(self.positions[0]) | 386 if i < self.__len__(): |
381 | 387 self.positions[0][i] = x |
382 def __len__(self): | 388 self.positions[1][i] = y |
383 return self.length() | 389 |
390 def setPosition(self, i, p): | |
391 self.setPositionXY(i, p.x, p.y) | |
384 | 392 |
385 def addPositionXY(self, x, y): | 393 def addPositionXY(self, x, y): |
386 self.positions[0].append(x) | 394 self.positions[0].append(x) |
387 self.positions[1].append(y) | 395 self.positions[1].append(y) |
388 | 396 |
513 return utils.LCSS(t1, t2, threshold, Point.distanceNorm2) | 521 return utils.LCSS(t1, t2, threshold, Point.distanceNorm2) |
514 | 522 |
515 @staticmethod | 523 @staticmethod |
516 def normMaxLCSS(t1, t2, threshold): | 524 def normMaxLCSS(t1, t2, threshold): |
517 return utils.LCSS(t1, t2, threshold, lambda p1, p2: (p1-p2).normMax()) | 525 return utils.LCSS(t1, t2, threshold, lambda p1, p2: (p1-p2).normMax()) |
526 | |
527 class CurvilinearTrajectory(Trajectory): | |
528 '''Sub class of trajectory for trajectories with curvilinear coordinates and lane assignements | |
529 longitudinal coordinate is stored as first coordinate (exterior name S) | |
530 lateral coordiante is stored as second coordinate''' | |
531 | |
532 def __init__(self, S = [], Y = [], lanes = []): | |
533 self.positions = [S,Y] | |
534 self.lanes = lanes | |
535 | |
536 def __getitem__(self,i): | |
537 return [self.positions[0][i], self.positions[1][i], self.lanes[i]] | |
538 | |
539 def getSCoordinates(self): | |
540 return self.getXCoordinates() | |
541 | |
542 def getLanes(self): | |
543 return self.lanes | |
544 | |
545 def addPosition(self, s, y, lane): | |
546 self.addPositionXY(s,y) | |
547 self.lanes.append(lane) | |
548 | |
549 def setPosition(self, i, s, y, lane): | |
550 self.setPositionXY(i, s, y) | |
551 if i < self.__len__(): | |
552 self.lanes[i] = lane | |
518 | 553 |
519 ################## | 554 ################## |
520 # Moving Objects | 555 # Moving Objects |
521 ################## | 556 ################## |
522 | 557 |