comparison python/objectsmoothing.py @ 998:933670761a57

updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sun, 27 May 2018 23:22:48 -0400
parents 15e244d2a1b5
children
comparison
equal deleted inserted replaced
997:4f3387a242a1 998:933670761a57
48 def buildFeature(obj, featureID, num = 1): 48 def buildFeature(obj, featureID, num = 1):
49 featureList= getFeatures(obj, featureID) 49 featureList= getFeatures(obj, featureID)
50 tmp={} 50 tmp={}
51 delta={} 51 delta={}
52 for i in featureList: 52 for i in featureList:
53 for t in xrange(i[1],i[2]+1): 53 for t in range(i[1],i[2]+1):
54 tmp[t]=[i[0],i[3]] 54 tmp[t]=[i[0],i[3]]
55 newTraj = moving.Trajectory() 55 newTraj = moving.Trajectory()
56 56
57 for instant in obj.getTimeInterval(): 57 for instant in obj.getTimeInterval():
58 newTraj.addPosition(tmp[instant][0].getPositionAtInstant(instant)+tmp[instant][1]) 58 newTraj.addPosition(tmp[instant][0].getPositionAtInstant(instant)+tmp[instant][1])
150 bearing[i]=bearingOut[t] 150 bearing[i]=bearingOut[t]
151 151
152 #solve a smoothing problem in case of big drop in computing bearing (0,360) 152 #solve a smoothing problem in case of big drop in computing bearing (0,360)
153 for t,i in enumerate(sorted(bearing.keys())): 153 for t,i in enumerate(sorted(bearing.keys())):
154 if i!= max(bearing.keys()) and abs(bearingInput[t] - bearingInput[t+1])>=340: 154 if i!= max(bearing.keys()) and abs(bearingInput[t] - bearingInput[t+1])>=340:
155 for x in xrange(max(i-halfWidth,min(bearing.keys())),min(i+halfWidth,max(bearing.keys()))+1): 155 for x in range(max(i-halfWidth,min(bearing.keys())),min(i+halfWidth,max(bearing.keys()))+1):
156 bearing[x]=bearingInput[t-i+x] 156 bearing[x]=bearingInput[t-i+x]
157 157
158 translated = moving.Trajectory() 158 translated = moving.Trajectory()
159 for t in feature.getTimeInterval(): 159 for t in feature.getTimeInterval():
160 p1= feature.getPositionAtInstant(t) 160 p1= feature.getPositionAtInstant(t)
164 164
165 #modify first and last un-smoothed positions (half width) 165 #modify first and last un-smoothed positions (half width)
166 if smoothing: 166 if smoothing:
167 d1= translated[halfWidth]- feature.positions[halfWidth] 167 d1= translated[halfWidth]- feature.positions[halfWidth]
168 d2= translated[-halfWidth-1]- feature.positions[-halfWidth-1] 168 d2= translated[-halfWidth-1]- feature.positions[-halfWidth-1]
169 for i in xrange(halfWidth): 169 for i in range(halfWidth):
170 p1= feature.getPositionAt(i)+d1 170 p1= feature.getPositionAt(i)+d1
171 p2= feature.getPositionAt(-i-1)+d2 171 p2= feature.getPositionAt(-i-1)+d2
172 translated.setPosition(i,p1) 172 translated.setPosition(i,p1)
173 translated.setPosition(-i-1,p2) 173 translated.setPosition(-i-1,p2)
174 174