def visibility(cam, footprints, targets):
"""
This function tests is the target points (x,y only) are "visable" (i.e.
within the photo footprints) and calculates the "r" angle for the refraction
correction\n
Vars:\n
\t cam = Pandas dataframe (n x ~6, fields: x,y,z,yaw,pitch,roll)\n
\t footprints = Pandas dataframe (n x 1) of Matplotlib Path objects\n
\t targets = Pandas dataframe (n x ~3, fields: x,y,sfm_z...)\n
RETURNS: r_filt = numpy array (n_points x n_cams) of filtered "r" angles.\n
Points that are not visable to a camera will have a NaN "r" angle.
"""
# Setup boolean array for visability
vis = np.zeros((targets.shape[0],cam.shape[0]))
# for each path objec in footprints, check is the points in targets are
# within the path polygon. path.contains_points returns boolean.
# the results are accumulated in the vis array.
for idx in range(footprints.shape[0]):
path = footprints.fov[idx]
vis[:,idx] = path.contains_points(np.array([targets.x.values, targets.y.values]).T)
# calculate the coord. deltas between the cameras and the target
dx = np.atleast_2d(cam.x.values) - np.atleast_2d(targets.x.values).T
dy = np.atleast_2d(cam.y.values) - np.atleast_2d(targets.y.values).T
dz = np.atleast_2d(cam.z.values) - np.atleast_2d(targets.sfm_z).T
# calc xy distance (d)
d = np.sqrt((dx)**2+(dy)**2)
# calc inclination angle (r) from targets to cams
r = np.rad2deg(np.arctan(d/dz))
r_filt = r * vis
r_filt[r_filt == 0] = np.nan
return r_filt
评论列表
文章目录