def lat_long_to_cube_uv(S, T):
# Convert to Cartesian.
x = tf.cos(T) * tf.sin(S)
y = tf.sin(T)
z = tf.cos(T) * tf.cos(S)
argmax = tf.argmax(tf.abs([x, y, z]), axis = 0)
max = tf.reduce_max(tf.abs([x, y, z]), axis = 0)
# Check which face the ray lies on.
front_check = tf.logical_and(
tf.equal(argmax, 2),
tf.greater_equal(z, 0.0)
)
back_check = tf.logical_and(
tf.equal(argmax, 2),
tf.less(z, 0.0)
)
left_check = tf.logical_and(
tf.equal(argmax, 0),
tf.less(x, 0.0)
)
right_check = tf.logical_and(
tf.equal(argmax, 0),
tf.greater_equal(x, 0.0)
)
up_check = tf.logical_and(
tf.equal(argmax, 1),
tf.less(y, 0.0)
)
down_check = tf.logical_and(
tf.equal(argmax, 1),
tf.greater_equal(y, 0.0)
)
# Normalize coordinates.
x = x / max
y = y / max
z = z / max
# Calculate UV coordinates.
u = tf.where(front_check, 0.5 + x / 2.0, tf.zeros_like(x))
u = tf.where(back_check, 1.0 + (0.5 - x / 2.0), u)
u = tf.where(left_check, 2.0 + (0.5 + z / 2.0), u)
u = tf.where(right_check, 3.0 + (0.5 - z / 2.0), u)
u = tf.where(up_check, 4.0 + (0.5 + x / 2.0), u)
u = tf.where(down_check, 5.0 + (0.5 + x / 2.0), u)
u = u / 6.0
v = tf.where(front_check, (1.0 + y) / 2.0, tf.zeros_like(y))
v = tf.where(back_check, (1.0 + y) / 2.0, v)
v = tf.where(left_check, (1.0 + y) / 2.0, v)
v = tf.where(right_check, (1.0 + y) / 2.0, v)
v = tf.where(up_check, (1.0 + z) / 2.0, v)
v = tf.where(down_check, (1.0 - z) / 2.0, v)
return u, v
评论列表
文章目录