@@ -287,14 +287,18 @@ def generate_cut_outs(scan, standard_depth=4.0, window_size=48, threshold_distan
287287 return cut_outs
288288
289289
290- def generate_cut_outs_raw (scan , window_size = 48 , border = 29.99 ):
290+ def generate_cut_outs_raw (scan , window_size = 48 , threshold_distance = np . inf , center = False , border = 29.99 ):
291291 '''
292292 Generate window cut outs that all have a fixed number of rays independent of depth.
293293 This means objects close to the scanner will cover more rays and those far away fewer.
294294 All cut outs will contain the raw values from the input scan.
295295
296296 - `scan` an iterable of radii within a laser scan.
297297 - `window_size` the window of laser rays that will be extracted everywhere.
298+ - `threshold_distance` the distance in meters from the center point that will be used to clamp the laser radii.
299+ Since we're talking about laser-radii, this means the cutout is a donut-shaped hull, as opposed to a rectangular hull.
300+ This can be `np.inf` to skip the clamping altogether.
301+ - `center` whether to center the cutout around the current laser point's depth (True), or keep depth values raw (False).
298302 - `border` the radius value to fill the half of the outermost windows with.
299303 '''
300304 s_np = np .fromiter (iter (scan ), dtype = np .float32 )
@@ -306,11 +310,26 @@ def generate_cut_outs_raw(scan, window_size=48, border=29.99):
306310 end = start + window_size
307311 s_np_extended = np .append (s_np , border )
308312
313+ # While we don't really need to special-case, it should save precious computation.
314+ if threshold_distance != np .inf :
315+ near = s_np - threshold_distance
316+ far = s_np + threshold_distance
317+
309318 for i in range (N ):
310319 # Get the window.
311320 sample_points = np .arange (start [i ], end [i ])
312321 sample_points [sample_points < 0 ] = - 1
313322 sample_points [sample_points >= N ] = - 1
314- cut_outs [i ,:] = s_np_extended [sample_points ]
323+ window = s_np_extended [sample_points ]
324+
325+ # Threshold the near and far values, then
326+ if threshold_distance != np .inf :
327+ window = np .clip (window , near [i ], far [i ])
328+
329+ # shift everything to be centered around the middle point.
330+ if center :
331+ window -= s_np [i ]
332+
333+ cut_outs [i ,:] = window
315334
316335 return cut_outs
0 commit comments