@@ -10,6 +10,7 @@ from sensor_msgs.msg import NavSatFix
10
10
import numpy as np
11
11
from matplotlib .transforms import blended_transform_factory
12
12
13
+ import smopy
13
14
14
15
# color palette definition (V2 from https://matplotlib.org/users/dflt_style_changes.html#colors-color-cycles-and-color-maps)
15
16
C = ['#1f77b4' , '#ff7f0e' , '#2ca02c' , '#d62728' ,
@@ -60,6 +61,7 @@ class Debugging_2D_matplot():
60
61
rospy .Subscriber ('position' , NavSatFix , self .update_position )
61
62
self .position = [1 ,1 ]
62
63
64
+ self .window = [0 ,0 ,0 ,0 ]
63
65
self .init_plot ()
64
66
self .update_plot ()
65
67
@@ -204,6 +206,37 @@ class Debugging_2D_matplot():
204
206
miny = - dist * scale_dy
205
207
maxy = + dist * scale_dy
206
208
self .ax .axis ([minx , maxx , miny , maxy ])
209
+
210
+ if self .window == [minx , maxx , miny , maxy ]:
211
+ return
212
+
213
+ self .window = [minx , maxx , miny , maxy ]
214
+
215
+
216
+ SO_corner = self .nav .utm_to_latlon (self .origin [0 ] + minx , self .origin [1 ] + miny )
217
+ NE_corner = self .nav .utm_to_latlon (self .origin [0 ] + maxx , self .origin [1 ] + maxy )
218
+
219
+ image_map = smopy .Map ((float (SO_corner .lat ),
220
+ float (SO_corner .lon ),
221
+ float (NE_corner .lat ),
222
+ float (NE_corner .lon )), )
223
+
224
+ mapminx , mapminy = image_map .to_pixels ((float (SO_corner .lat ),
225
+ float (SO_corner .lon )), )
226
+
227
+ mapmaxx , mapmaxy = image_map .to_pixels ((float (NE_corner .lat ),
228
+ float (NE_corner .lon )), )
229
+
230
+ mapminx = int (mapminx )
231
+ mapminy = int (mapminy )
232
+ mapmaxx = int (mapmaxx )
233
+ mapmaxy = int (mapmaxy )
234
+ image = image_map .to_numpy ()[mapmaxy :mapminy , mapminx :mapmaxx , :]
235
+
236
+ self .ax .imshow (image , extent = (minx , maxx , miny , maxy ))
237
+
238
+
239
+
207
240
208
241
209
242
def update_plot (self ):
0 commit comments