Mercurial Hosting > traffic-intelligence
diff 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 |
line wrap: on
line diff
--- a/python/moving.py Thu May 23 17:57:11 2013 +0200 +++ b/python/moving.py Wed Jun 12 17:28:34 2013 -0400 @@ -339,7 +339,7 @@ The class is iterable''' def __init__(self, positions=None): - if positions != None: + if positions: self.positions = positions else: self.positions = [[],[]] @@ -356,6 +356,12 @@ t.addPosition(p) return t + def __len__(self): + return len(self.positions[0]) + + def length(self): + return self.__len__() + def __str__(self): return ' '.join([self.__getitem__(i).__str__() for i in xrange(self.length())]) @@ -376,11 +382,13 @@ self.iterInstantNum += 1 return self[self.iterInstantNum-1] - def length(self): - return len(self.positions[0]) + def setPositionXY(self, i, x, y): + if i < self.__len__(): + self.positions[0][i] = x + self.positions[1][i] = y - def __len__(self): - return self.length() + def setPosition(self, i, p): + self.setPositionXY(i, p.x, p.y) def addPositionXY(self, x, y): self.positions[0].append(x) @@ -516,6 +524,33 @@ def normMaxLCSS(t1, t2, threshold): return utils.LCSS(t1, t2, threshold, lambda p1, p2: (p1-p2).normMax()) +class CurvilinearTrajectory(Trajectory): + '''Sub class of trajectory for trajectories with curvilinear coordinates and lane assignements + longitudinal coordinate is stored as first coordinate (exterior name S) + lateral coordiante is stored as second coordinate''' + + def __init__(self, S = [], Y = [], lanes = []): + self.positions = [S,Y] + self.lanes = lanes + + def __getitem__(self,i): + return [self.positions[0][i], self.positions[1][i], self.lanes[i]] + + def getSCoordinates(self): + return self.getXCoordinates() + + def getLanes(self): + return self.lanes + + def addPosition(self, s, y, lane): + self.addPositionXY(s,y) + self.lanes.append(lane) + + def setPosition(self, i, s, y, lane): + self.setPositionXY(i, s, y) + if i < self.__len__(): + self.lanes[i] = lane + ################## # Moving Objects ##################