Optimize range clearing with equivalent early pixel rejection
This commit is contained in:
@@ -10,7 +10,6 @@ import itertools
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
VIEW_FIELDS = ("view_models", "view_sizes", "view_axes", "view_parameters", "view_ranges")
|
||||
|
||||
|
||||
@@ -60,7 +59,35 @@ class RangeImages:
|
||||
self.models, self.sizes, self.origins, self.axes, self.parameters, strict=True):
|
||||
image = self.ranges[offset:offset+w*h].reshape(h, w)
|
||||
offset += w*h
|
||||
local = (corners-origin) @ axes
|
||||
# Clearing requires EVERY corner and EVERY pixel in its footprint.
|
||||
# A single corner/pixel that fails is therefore a sufficient veto.
|
||||
# Most retained returns are still occluded: reject those cheaply
|
||||
# before projecting the other seven corners. Survivors still take
|
||||
# the complete original test below; this grants no new free space.
|
||||
first = (corners[:, :1, :]-origin) @ axes
|
||||
first_distance = np.linalg.norm(first, axis=2)[:, 0]
|
||||
if model == 0:
|
||||
first_u = (np.degrees(np.arctan2(first[..., 1], first[..., 0]))-p[0])/p[1]
|
||||
first_u = (first_u + (first_u-first_u+w/2) % w-w/2)[:, 0]
|
||||
first_v = ((np.degrees(np.arctan2(first[..., 2],
|
||||
np.linalg.norm(first[..., :2], axis=2)))-p[2])/p[3])[:, 0]
|
||||
eligible = np.ones(len(points), dtype=bool)
|
||||
else:
|
||||
front = first[:, 0, 0]
|
||||
eligible = front > 1e-6
|
||||
denominator = np.maximum(front, 1e-6)
|
||||
first_u = p[2]-p[0]*first[:, 0, 1]/denominator-0.5
|
||||
first_v = p[3]-p[1]*first[:, 0, 2]/denominator-0.5
|
||||
eligible &= (np.floor(first_u) >= 0) & (np.ceil(first_u) < w)
|
||||
eligible &= ((first_distance > margin_m) & (np.floor(first_v) >= 0)
|
||||
& (np.ceil(first_v) < h) & ~result)
|
||||
candidates = np.flatnonzero(eligible)
|
||||
measured = image[np.floor(first_v[candidates]).astype(int),
|
||||
np.floor(first_u[candidates]).astype(int) % w]
|
||||
candidates = candidates[measured > first_distance[candidates]+margin_m]
|
||||
if not len(candidates):
|
||||
continue
|
||||
local = (corners[candidates]-origin) @ axes
|
||||
distance = np.linalg.norm(local, axis=2)
|
||||
if model == 0:
|
||||
u = (np.degrees(np.arctan2(local[..., 1], local[..., 0]))-p[0])/p[1]
|
||||
@@ -68,7 +95,7 @@ class RangeImages:
|
||||
u = u[:, :1] + (u-u[:, :1]+w/2) % w-w/2
|
||||
v = (np.degrees(np.arctan2(local[..., 2],
|
||||
np.linalg.norm(local[..., :2], axis=2)))-p[2])/p[3]
|
||||
visible = np.ones(len(points), dtype=bool)
|
||||
visible = np.ones(len(candidates), dtype=bool)
|
||||
else:
|
||||
front = local[..., 0]
|
||||
visible = (front > 1e-6).all(axis=1)
|
||||
@@ -82,7 +109,7 @@ class RangeImages:
|
||||
visible &= (low_u >= 0) & (high_u < w)
|
||||
# A near-sensor voxel spanning a large portion of the image stays
|
||||
# unknown. Bound work, without subsampling its clearing footprint.
|
||||
visible &= (high_u-low_u <= 8) & (high_v-low_v <= 8) & ~result
|
||||
visible &= (high_u-low_u <= 8) & (high_v-low_v <= 8)
|
||||
indices = np.flatnonzero(visible)
|
||||
if not len(indices):
|
||||
continue
|
||||
@@ -96,5 +123,5 @@ class RangeImages:
|
||||
rows = np.flatnonzero(inside)
|
||||
measured = image[lv[rows]+dv, (lu[rows]+du) % w]
|
||||
free[rows] &= measured > required[rows]
|
||||
result[indices[free]] = True
|
||||
result[candidates[indices[free]]] = True
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user