changeset 1011:4f0312bee393

moving.py
author Wendlasida
date Fri, 01 Jun 2018 10:43:23 -0400
parents c90c4682c67e
children 01db14e947e4
files python/moving.py
diffstat 1 files changed, 23 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/python/moving.py	Fri May 25 15:14:27 2018 -0400
+++ b/python/moving.py	Fri Jun 01 10:43:23 2018 -0400
@@ -10,6 +10,7 @@
 from scipy.stats import scoreatpercentile
 from scipy.spatial.distance import cdist
 from scipy.signal import savgol_filter
+import copy
 
 try:
     from shapely.geometry import Polygon, Point as shapelyPoint
@@ -1141,6 +1142,16 @@
     def generate(num, p, v, timeInterval):
         positions, velocities = Trajectory.generate(p, v, int(timeInterval.length())) 
         return MovingObject(num = num, timeInterval = timeInterval, positions = positions, velocities = velocities)
+        
+
+
+
+    @staticmethod
+    def generateWithFeatures(num, features, userType):
+    	newObjectTMP = MovingObject.concatenateWith(features[0],features[1:],num)
+	newObject = MovingObject(newObjectTMP.getNum() if num is None else num, newObjectTMP.getTimeInterval(), newObjectTMP.positions, newObjectTMP.velocities, userType = userType)
+	newObject.features = [copy.deepcopy(f) for f in features]
+	return newObject
 
     @staticmethod
     def concatenateWith(obj1, ObjectList=[], num = None): #Concatenate with a list of MovingObjects
@@ -1157,7 +1168,7 @@
     		newObject = MovingObject.concatenateWith(newObject,ObjectList)
     	return newObject
 
-    @staticmethod
+    '''@staticmethod
     def addFeatures(obj1, FeatureList=[], num = None): #Add features to an object
     	if len(FeatureList)==0: #We return a clone
     		newObject = MovingObject(obj1.getNum() if num is None else num, obj1.getTimeInterval(), obj1.positions, obj1.velocities, userType = obj1.getUserType()) 
@@ -1169,15 +1180,18 @@
 		if obj1.hasFeatures() and newObjectTMP.hasFeatures():
 			newObject.features = obj1.features + newObjectTMP.features
 		
-	return newObject
+	return newObject'''
 	
 
     @staticmethod
     def delFeatures(obj1, FeatureList=[], num = None):
     	if obj1.features is not None:
     		if len(FeatureList)>0:
-    			tmp = [ i for i in obj1.features and i not in FeatureList]
-    			if len(obj1.features)!=len(tmp):
+    			tmp = [ i for i in (obj1.features if obj1.features is not None else []) if i not in FeatureList]
+    			if len(tmp)==0:
+    				newObject = MovingObject(obj1.getNum() if num is None else num, obj1.getTimeInterval(), obj1.positions, obj1.velocities, userType = obj1.getUserType())
+    				newObject.features = [MovingObject(obj1.getNum() if num is None else num, newInterval, obj1.positions, obj1.velocities, userType = obj1.getUserType())]
+    			elif len(obj1.features if obj1.features is not None else [])!=len(tmp):
     				newInterval = TimeInterval(min([i.getFirstInstant() for i in tmp]), max([i.getLastInstant() for i in tmp]))
 		    		positions = Trajectory()
 		    		for t in newInterval:
@@ -1197,7 +1211,7 @@
 						positions.addPosition(p.divide(nTotal))
 				if hasattr(obj1, 'velocities'):
 					velocities = Trajectory()
-					for t in newTimeInterval:
+					for t in newInterval:
 						nTotal = 0.
 						p = Point(0.,0.)
 						for obj in tmp:
@@ -1217,6 +1231,10 @@
 				
 				newObject = MovingObject(obj1.getNum() if num is None else num, newInterval, positions, velocities, userType = obj1.getUserType())
 				newObject.features = tmp+[MovingObject(obj1.getNum() if num is None else num, newInterval, positions, velocities, userType = obj1.getUserType())]
+			else:
+				newObject = MovingObject(obj1.getNum() if num is None else num, obj1.getTimeInterval(), obj1.positions, obj1.velocities, userType = obj1.getUserType()) 
+		    		if obj1.features is not None:
+		    			newObject.features = list(obj1.features)
     	else:
     		newObject = MovingObject(obj1.getNum() if num is None else num, obj1.getTimeInterval(), obj1.positions, obj1.velocities, userType = obj1.getUserType())
     	return newObject
@@ -1224,7 +1242,6 @@
 
     def updatePosition(self):
     	if self.features is not None:
-    		print 'On update ici'
 	    	positions = Trajectory()
 	    	for t in self.getTimeInterval():
 	    		nTotal = 0.