diff python/moving.py @ 231:249d65ff6c35

merged modifications for windows
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 02 Jul 2012 23:49:39 -0400
parents c31722fcc9de
children e0988a8ace0c
line wrap: on
line diff
--- a/python/moving.py	Fri Jun 29 16:15:13 2012 -0400
+++ b/python/moving.py	Mon Jul 02 23:49:39 2012 -0400
@@ -103,6 +103,9 @@
     def empty(self):
         return self.timeInterval.empty() or not self.boudingPolygon
 
+    def getId(self):
+        return self.num
+
     def getFirstInstant(self):
         return self.timeInterval.first
 
@@ -138,9 +141,9 @@
     def multiply(self, alpha):
         return Point(self.x*alpha, self.y*alpha)
 
-    def draw(self, options = 'o'):
+    def draw(self, options = 'o', **kwargs):
         from matplotlib.pylab import plot
-        plot([self.x], [self.y], options)
+        plot([self.x], [self.y], options, **kwargs)
 
     def norm2Squared(self):
         '''2-norm distance (Euclidean distance)'''
@@ -156,6 +159,9 @@
     def astuple(self):
         return (self.x, self.y)
 
+    def asint(self):
+        return Point(int(self.x), int(self.y))
+
     def project(self, homography):
         from numpy.core.multiarray import array
         projected = cvutils.projectArray(homography, array([[self.x], [self.y]]))
@@ -219,10 +225,10 @@
     def multiply(self, alpha):
         return FlowVector(self.position.multiply(alpha), self.velocity.multiply(alpha))
 
-    def draw(self, options = ''):
+    def draw(self, options = '', **kwargs):
         from matplotlib.pylab import plot
-        plot([self.position.x, self.position.x+self.velocity.x], [self.position.y, self.position.y+self.velocity.y], options)
-        self.position.draw(options+'x')
+        plot([self.position.x, self.position.x+self.velocity.x], [self.position.y, self.position.y+self.velocity.y], options, **kwargs)
+        self.position.draw(options+'x', **kwargs)
     
     @staticmethod
     def similar(f1, f2, maxDistance2, maxDeltavelocity2):
@@ -301,31 +307,31 @@
         self.addPositionXY(p.x, p.y)
 
     @staticmethod
-    def _draw(positions, options = '', withOrigin = False, lastCoordinate = None):
+    def _draw(positions, options = '', withOrigin = False, lastCoordinate = None, **kwargs):
         from matplotlib.pylab import plot
         if lastCoordinate == None:
-            plot(positions[0], positions[1], options)
+            plot(positions[0], positions[1], options, **kwargs)
         elif 0 <= lastCoordinate <= len(positions[0]):
-            plot(positions[0][:lastCoordinate], positions[1][:lastCoordinate], options)
+            plot(positions[0][:lastCoordinate], positions[1][:lastCoordinate], options, **kwargs)
         if withOrigin:
-            plot([positions[0][0]], [positions[1][0]], 'ro')
+            plot([positions[0][0]], [positions[1][0]], 'ro', **kwargs)
 
     def project(self, homography):
         from numpy.core.multiarray import array
         projected = cvutils.projectArray(homography, array(self.positions))
         return Trajectory(projected)
 
-    def draw(self, options = '', withOrigin = False):
-        Trajectory._draw(self.positions, options, withOrigin)
+    def draw(self, options = '', withOrigin = False, **kwargs):
+        Trajectory._draw(self.positions, options, withOrigin,**kwargs)
 
-    def drawAt(self, lastCoordinate, options = '', withOrigin = False):
-        Trajectory._draw(self.positions, options, withOrigin, lastCoordinate)
+    def drawAt(self, lastCoordinate, options = '', withOrigin = False, **kwargs):
+        Trajectory._draw(self.positions, options, withOrigin, lastCoordinate, **kwargs)
 
-    def drawOnWorldImage(self, nPixelsPerUnitDistance, imageHeight, options = '', withOrigin = False):
+    def drawOnWorldImage(self, nPixelsPerUnitDistance, imageHeight, options = '', withOrigin = False, **kwargs):
         from matplotlib.pylab import plot
         imgPositions = [[x*nPixelsPerUnitDistance for x in self.positions[0]],
                         [-x*nPixelsPerUnitDistance+imageHeight for x in self.positions[1]]]
-        Trajectory._draw(imgPositions, options, withOrigin)
+        Trajectory._draw(imgPositions, options, withOrigin, **kwargs)
 
     def getXCoordinates(self):
         return self.positions[0]
@@ -489,11 +495,11 @@
     def getYCoordinates(self):
         return self.positions.getYCoordinates()
     
-    def draw(self, options = '', withOrigin = False):
-        self.positions.draw(options, withOrigin)
+    def draw(self, options = '', withOrigin = False, **kwargs):
+        self.positions.draw(options, withOrigin, **kwargs)
 
-    def drawWorldOnImage(self, nPixelsPerUnitDistance, imageHeight, options = '', withOrigin = False):
-        self.positions.drawWorldOnImage(nPixelsPerUnitDistance, imageHeight, options, withOrigin)
+    def drawOnWorldImage(self, nPixelsPerUnitDistance, imageHeight, options = '', withOrigin = False, **kwargs):
+        self.positions.drawOnWorldImage(nPixelsPerUnitDistance, imageHeight, options, withOrigin, **kwargs)
 
     def getInstantsCrossingLane(self, p1, p2):
         '''Returns the instant(s)
@@ -622,6 +628,9 @@
         else:
             return None
 
+# functions to aggregate discretized maps of indicators
+# TODO add values in the cells between the positions (similar to discretizing vector graphics to bitmap)
+
 def indicatorMap(indicatorValues, trajectory, squareSize):
     '''Returns a dictionary 
     with keys for the indices of the cells (squares)