comparison python/moving.py @ 211:ada6e8fbe4c6

2 Changes : 1) Modified storage.py to read prototype and matching trajectory indexes from db 2) Modified moving.py to give draw function **kwargs option (to matplotlib.plot)
author Francois Belisle <belisle.francois@gmail.com>
date Wed, 06 Jun 2012 13:24:04 -0400
parents e2f31813ade6
children 5cde6da74605
comparison
equal deleted inserted replaced
210:e841ba9981e2 211:ada6e8fbe4c6
101 self.boundingPolygon = boundingPolygon 101 self.boundingPolygon = boundingPolygon
102 102
103 def empty(self): 103 def empty(self):
104 return self.timeInterval.empty() or not self.boudingPolygon 104 return self.timeInterval.empty() or not self.boudingPolygon
105 105
106 def getId(self):
107 return self.num
108
106 def getFirstInstant(self): 109 def getFirstInstant(self):
107 return self.timeInterval.first 110 return self.timeInterval.first
108 111
109 def getLastInstant(self): 112 def getLastInstant(self):
110 return self.timeInterval.last 113 return self.timeInterval.last
136 return Point(self.x-other.x, self.y-other.y) 139 return Point(self.x-other.x, self.y-other.y)
137 140
138 def multiply(self, alpha): 141 def multiply(self, alpha):
139 return Point(self.x*alpha, self.y*alpha) 142 return Point(self.x*alpha, self.y*alpha)
140 143
141 def draw(self, options = 'o'): 144 def draw(self, options = 'o', **kwargs):
142 from matplotlib.pylab import plot 145 from matplotlib.pylab import plot
143 plot([self.x], [self.y], options) 146 plot([self.x], [self.y], options, **kwargs)
144 147
145 def norm2Squared(self): 148 def norm2Squared(self):
146 '''2-norm distance (Euclidean distance)''' 149 '''2-norm distance (Euclidean distance)'''
147 return self.x*self.x+self.y*self.y 150 return self.x*self.x+self.y*self.y
148 151
217 return FlowVector(self.position+other.position, self.velocity+other.velocity) 220 return FlowVector(self.position+other.position, self.velocity+other.velocity)
218 221
219 def multiply(self, alpha): 222 def multiply(self, alpha):
220 return FlowVector(self.position.multiply(alpha), self.velocity.multiply(alpha)) 223 return FlowVector(self.position.multiply(alpha), self.velocity.multiply(alpha))
221 224
222 def draw(self, options = ''): 225 def draw(self, options = '', **kwargs):
223 from matplotlib.pylab import plot 226 from matplotlib.pylab import plot
224 plot([self.position.x, self.position.x+self.velocity.x], [self.position.y, self.position.y+self.velocity.y], options) 227 plot([self.position.x, self.position.x+self.velocity.x], [self.position.y, self.position.y+self.velocity.y], options, **kwargs)
225 self.position.draw(options+'x') 228 self.position.draw(options+'x', **kwargs)
226 229
227 @staticmethod 230 @staticmethod
228 def similar(f1, f2, maxDistance2, maxDeltavelocity2): 231 def similar(f1, f2, maxDistance2, maxDeltavelocity2):
229 return (f1.position-f2.position).norm2Squared()<maxDistance2 and (f1.velocity-f2.velocity).norm2Squared()<maxDeltavelocity2 232 return (f1.position-f2.position).norm2Squared()<maxDistance2 and (f1.velocity-f2.velocity).norm2Squared()<maxDeltavelocity2
230 233
299 302
300 def addPosition(self, p): 303 def addPosition(self, p):
301 self.addPositionXY(p.x, p.y) 304 self.addPositionXY(p.x, p.y)
302 305
303 @staticmethod 306 @staticmethod
304 def _draw(positions, options = '', withOrigin = False, lastCoordinate = None): 307 def _draw(positions, options = '', withOrigin = False, lastCoordinate = None, **kwargs):
305 from matplotlib.pylab import plot 308 from matplotlib.pylab import plot
306 if lastCoordinate == None: 309 if lastCoordinate == None:
307 plot(positions[0], positions[1], options) 310 plot(positions[0], positions[1], options, **kwargs)
308 elif 0 <= lastCoordinate <= len(positions[0]): 311 elif 0 <= lastCoordinate <= len(positions[0]):
309 plot(positions[0][:lastCoordinate], positions[1][:lastCoordinate], options) 312 plot(positions[0][:lastCoordinate], positions[1][:lastCoordinate], options, **kwargs)
310 if withOrigin: 313 if withOrigin:
311 plot([positions[0][0]], [positions[1][0]], 'ro') 314 plot([positions[0][0]], [positions[1][0]], 'ro', **kwargs)
312 315
313 def project(self, homography): 316 def project(self, homography):
314 from numpy.core.multiarray import array 317 from numpy.core.multiarray import array
315 projected = cvutils.projectArray(homography, array(self.positions)) 318 projected = cvutils.projectArray(homography, array(self.positions))
316 return Trajectory(projected) 319 return Trajectory(projected)
317 320
318 def draw(self, options = '', withOrigin = False): 321 def draw(self, options = '', withOrigin = False, **kwargs):
319 Trajectory._draw(self.positions, options, withOrigin) 322 Trajectory._draw(self.positions, options, withOrigin,**kwargs)
320 323
321 def drawAt(self, lastCoordinate, options = '', withOrigin = False): 324 def drawAt(self, lastCoordinate, options = '', withOrigin = False, **kwargs):
322 Trajectory._draw(self.positions, options, withOrigin, lastCoordinate) 325 Trajectory._draw(self.positions, options, withOrigin, lastCoordinate, **kwargs)
323 326
324 def drawOnWorldImage(self, nPixelsPerUnitDistance, imageHeight, options = '', withOrigin = False): 327 def drawOnWorldImage(self, nPixelsPerUnitDistance, imageHeight, options = '', withOrigin = False, **kwargs):
325 from matplotlib.pylab import plot 328 from matplotlib.pylab import plot
326 imgPositions = [[x*nPixelsPerUnitDistance for x in self.positions[0]], 329 imgPositions = [[x*nPixelsPerUnitDistance for x in self.positions[0]],
327 [-x*nPixelsPerUnitDistance+imageHeight for x in self.positions[1]]] 330 [-x*nPixelsPerUnitDistance+imageHeight for x in self.positions[1]]]
328 Trajectory._draw(imgPositions, options, withOrigin) 331 Trajectory._draw(imgPositions, options, withOrigin, **kwargs)
329 332
330 def getXCoordinates(self): 333 def getXCoordinates(self):
331 return self.positions[0] 334 return self.positions[0]
332 335
333 def getYCoordinates(self): 336 def getYCoordinates(self):
487 return self.positions.getXCoordinates() 490 return self.positions.getXCoordinates()
488 491
489 def getYCoordinates(self): 492 def getYCoordinates(self):
490 return self.positions.getYCoordinates() 493 return self.positions.getYCoordinates()
491 494
492 def draw(self, options = '', withOrigin = False): 495 def draw(self, options = '', withOrigin = False, **kwargs):
493 self.positions.draw(options, withOrigin) 496 self.positions.draw(options, withOrigin, **kwargs)
494 497
495 def drawWorldOnImage(self, nPixelsPerUnitDistance, imageHeight, options = '', withOrigin = False): 498 def drawWorldOnImage(self, nPixelsPerUnitDistance, imageHeight, options = '', withOrigin = False):
496 self.positions.drawWorldOnImage(nPixelsPerUnitDistance, imageHeight, options, withOrigin) 499 self.positions.drawWorldOnImage(nPixelsPerUnitDistance, imageHeight, options, withOrigin)
497 500
498 def getInstantsCrossingLane(self, p1, p2): 501 def getInstantsCrossingLane(self, p1, p2):