Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
from tensorflow_graphics.geometry.transformation import rotation_matrix_3d
from tensorflow_graphics.util import export_api
from tensorflow_graphics.util import shape
from tensorflow_graphics.util import type_alias


def blend(points,
skinning_weights,
bone_rotations,
bone_translations,
name="linear_blend_skinning_blend"):
def blend(points: type_alias.TensorLike,
skinning_weights: type_alias.TensorLike,
bone_rotations: type_alias.TensorLike,
bone_translations: type_alias.TensorLike,
name: str = "linear_blend_skinning_blend") -> tf.Tensor:
"""Transforms the points using Linear Blend Skinning.

Note:
Expand Down
5 changes: 4 additions & 1 deletion tensorflow_graphics/geometry/transformation/look_at.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
from tensorflow_graphics.math import vector
from tensorflow_graphics.util import export_api
from tensorflow_graphics.util import shape
from tensorflow_graphics.util import type_alias


def right_handed(camera_position, look_at, up_vector, name="right_handed"):
def right_handed(camera_position: type_alias.TensorLike,
look_at, up_vector: type_alias.TensorLike,
name: str = "right_handed") -> tf.Tensor:
"""Builds a right handed look at view matrix.

Note:
Expand Down
70 changes: 51 additions & 19 deletions tensorflow_graphics/geometry/transformation/quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from __future__ import division
from __future__ import print_function

from typing import List

from six.moves import range
import tensorflow as tf

Expand All @@ -39,9 +41,12 @@
from tensorflow_graphics.util import export_api
from tensorflow_graphics.util import safe_ops
from tensorflow_graphics.util import shape
from tensorflow_graphics.util import type_alias


def _build_quaternion_from_sines_and_cosines(sin_half_angles, cos_half_angles):
def _build_quaternion_from_sines_and_cosines(
sin_half_angles: type_alias.TensorLike,
cos_half_angles: type_alias.TensorLike) -> tf.Tensor:
"""Builds a quaternion from sines and cosines of half Euler angles.

Note:
Expand All @@ -66,9 +71,10 @@ def _build_quaternion_from_sines_and_cosines(sin_half_angles, cos_half_angles):
return tf.stack((x, y, z, w), axis=-1)


def between_two_vectors_3d(vector1,
vector2,
name="quaternion_between_two_vectors_3d"):
def between_two_vectors_3d(vector1: type_alias.TensorLike,
vector2: type_alias.TensorLike,
name: str = "quaternion_between_two_vectors_3d"
) -> tf.Tensor:
"""Computes quaternion over the shortest arc between two vectors.

Result quaternion describes shortest geodesic rotation from
Expand Down Expand Up @@ -129,7 +135,8 @@ def between_two_vectors_3d(vector1,
return tf.nn.l2_normalize(rot, axis=-1)


def conjugate(quaternion, name="quaternion_conjugate"):
def conjugate(quaternion: type_alias.TensorLike,
name: str = "quaternion_conjugate") -> tf.Tensor:
"""Computes the conjugate of a quaternion.

Note:
Expand Down Expand Up @@ -157,7 +164,10 @@ def conjugate(quaternion, name="quaternion_conjugate"):
return tf.concat((-xyz, w), axis=-1)


def from_axis_angle(axis, angle, name="quaternion_from_axis_angle"):
def from_axis_angle(axis: type_alias.TensorLike,
angle: type_alias.TensorLike,
name: str = "quaternion_from_axis_angle"
) -> tf.Tensor:
"""Converts an axis-angle representation to a quaternion.

Note:
Expand Down Expand Up @@ -194,7 +204,9 @@ def from_axis_angle(axis, angle, name="quaternion_from_axis_angle"):
return tf.concat((xyz, w), axis=-1)


def from_euler(angles, name="quaternion_from_euler"):
def from_euler(angles: type_alias.TensorLike,
name: str = "quaternion_from_euler"
) -> tf.Tensor:
"""Converts an Euler angle representation to a quaternion.

Note:
Expand Down Expand Up @@ -230,8 +242,9 @@ def from_euler(angles, name="quaternion_from_euler"):
cos_half_angles)


def from_euler_with_small_angles_approximation(angles,
name="quaternion_from_euler"):
def from_euler_with_small_angles_approximation(
angles: type_alias.TensorLike,
name: str = "quaternion_from_euler") -> tf.Tensor:
r"""Converts small Euler angles to quaternions.

Under the small angle assumption, $$\sin(x)$$ and $$\cos(x)$$ can be
Expand Down Expand Up @@ -274,8 +287,9 @@ def from_euler_with_small_angles_approximation(angles,
return tf.nn.l2_normalize(quaternion, axis=-1)


def from_rotation_matrix(rotation_matrix,
name="quaternion_from_rotation_matrix"):
def from_rotation_matrix(rotation_matrix: type_alias.TensorLike,
name: str = "quaternion_from_rotation_matrix"
) -> tf.Tensor:
"""Converts a rotation matrix representation to a quaternion.

Warning:
Expand Down Expand Up @@ -361,7 +375,9 @@ def cond_idx(cond):
return quat


def inverse(quaternion, name="quaternion_inverse"):
def inverse(quaternion: type_alias.TensorLike,
name: str = "quaternion_inverse"
) -> tf.Tensor:
"""Computes the inverse of a quaternion.

Note:
Expand Down Expand Up @@ -391,7 +407,10 @@ def inverse(quaternion, name="quaternion_inverse"):
return safe_ops.safe_unsigned_div(conjugate(quaternion), squared_norm)


def is_normalized(quaternion, atol=1e-3, name="quaternion_is_normalized"):
def is_normalized(quaternion: type_alias.TensorLike,
atol: type_alias.Float = 1e-3,
name: str = "quaternion_is_normalized"
) -> tf.Tensor:
"""Determines if quaternion is normalized quaternion or not.

Note:
Expand Down Expand Up @@ -422,7 +441,10 @@ def is_normalized(quaternion, atol=1e-3, name="quaternion_is_normalized"):
tf.zeros_like(norms, dtype=bool))


def normalize(quaternion, eps=1e-12, name="quaternion_normalize"):
def normalize(quaternion: type_alias.TensorLike,
eps: type_alias.Float = 1e-12,
name: str = "quaternion_normalize"
) -> tf.Tensor:
"""Normalizes a quaternion.

Note:
Expand Down Expand Up @@ -450,7 +472,10 @@ def normalize(quaternion, eps=1e-12, name="quaternion_normalize"):
return tf.math.l2_normalize(quaternion, axis=-1, epsilon=eps)


def multiply(quaternion1, quaternion2, name="quaternion_multiply"):
def multiply(quaternion1: type_alias.TensorLike,
quaternion2: type_alias.TensorLike,
name: str = "quaternion_multiply"
) -> tf.Tensor:
"""Multiplies two quaternions.

Note:
Expand Down Expand Up @@ -487,8 +512,9 @@ def multiply(quaternion1, quaternion2, name="quaternion_multiply"):
return tf.stack((x, y, z, w), axis=-1)


def normalized_random_uniform(quaternion_shape,
name="quaternion_normalized_random_uniform"):
def normalized_random_uniform(quaternion_shape: List[int],
name: str = "quaternion_normalized_random_uniform"
) -> tf.Tensor:
"""Random normalized quaternion following a uniform distribution law on SO(3).

Args:
Expand Down Expand Up @@ -545,7 +571,10 @@ def _initializer(shape, dtype=tf.float32, partition_info=None):
# pylint: enable=redefined-outer-name


def rotate(point, quaternion, name="quaternion_rotate"):
def rotate(point: type_alias.TensorLike,
quaternion: type_alias.TensorLike,
name: str = "quaternion_rotate"
) -> tf.Tensor:
"""Rotates a point using a quaternion.

Note:
Expand Down Expand Up @@ -586,7 +615,10 @@ def rotate(point, quaternion, name="quaternion_rotate"):
return xyz


def relative_angle(quaternion1, quaternion2, name="quaternion_relative_angle"):
def relative_angle(quaternion1: type_alias.TensorLike,
quaternion2: type_alias.TensorLike,
name: str = "quaternion_relative_angle"
) -> tf.Tensor:
r"""Computes the unsigned relative rotation angle between 2 unit quaternions.

Given two normalized quanternions $$\mathbf{q}_1$$ and $$\mathbf{q}_2$$, the
Expand Down
20 changes: 14 additions & 6 deletions tensorflow_graphics/geometry/transformation/rotation_matrix_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
from tensorflow_graphics.geometry.transformation import rotation_matrix_common
from tensorflow_graphics.util import export_api
from tensorflow_graphics.util import shape
from tensorflow_graphics.util import type_alias


def from_euler(angle, name="rotation_matrix_2d_from_euler_angle"):
def from_euler(angle: type_alias.TensorLike,
name: str = "rotation_matrix_2d_from_euler_angle") -> tf.Tensor:
r"""Converts an angle to a 2d rotation matrix.

Converts an angle $$\theta$$ to a 2d rotation matrix following the equation
Expand Down Expand Up @@ -89,8 +91,9 @@ def from_euler(angle, name="rotation_matrix_2d_from_euler_angle"):


def from_euler_with_small_angles_approximation(
angles,
name="rotation_matrix_2d_from_euler_with_small_angles_approximation"):
angles: type_alias.TensorLike,
name: str = "rotation_matrix_2d_from_euler_with_small_angles_approximation"
) -> tf.Tensor:
r"""Converts an angle to a 2d rotation matrix under the small angle assumption.

Under the small angle assumption, $$\sin(x)$$ and $$\cos(x)$$ can be
Expand Down Expand Up @@ -142,7 +145,8 @@ def from_euler_with_small_angles_approximation(
return tf.reshape(matrix, shape=output_shape)


def inverse(matrix, name="rotation_matrix_2d_inverse"):
def inverse(matrix: type_alias.TensorLike,
name: str = "rotation_matrix_2d_inverse") -> tf.Tensor:
"""Computes the inverse of a 2D rotation matrix.

Note:
Expand Down Expand Up @@ -174,7 +178,9 @@ def inverse(matrix, name="rotation_matrix_2d_inverse"):
return tf.transpose(a=matrix, perm=perm)


def is_valid(matrix, atol=1e-3, name="rotation_matrix_2d_is_valid"):
def is_valid(matrix: type_alias.TensorLike,
atol: type_alias.Float = 1e-3,
name: str = "rotation_matrix_2d_is_valid") -> tf.Tensor:
r"""Determines if a matrix is a valid rotation matrix.

Determines if a matrix $$\mathbf{R}$$ is a valid rotation matrix by checking
Expand Down Expand Up @@ -205,7 +211,9 @@ def is_valid(matrix, atol=1e-3, name="rotation_matrix_2d_is_valid"):
return rotation_matrix_common.is_valid(matrix, atol)


def rotate(point, matrix, name="rotation_matrix_2d_rotate"):
def rotate(point: type_alias.TensorLike,
matrix: type_alias.TensorLike,
name: str = "rotation_matrix_2d_rotate") -> tf.Tensor:
"""Rotates a 2d point using a 2d rotation matrix.

Note:
Expand Down
38 changes: 27 additions & 11 deletions tensorflow_graphics/geometry/transformation/rotation_matrix_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
from tensorflow_graphics.util import export_api
from tensorflow_graphics.util import shape
from tensorflow_graphics.util import tfg_flags
from tensorflow_graphics.util import type_alias

FLAGS = flags.FLAGS


def _build_matrix_from_sines_and_cosines(sin_angles, cos_angles):
def _build_matrix_from_sines_and_cosines(
sin_angles: type_alias.TensorLike,
cos_angles: type_alias.TensorLike) -> tf.Tensor:
"""Builds a rotation matrix from sines and cosines of Euler angles.

Note:
Expand Down Expand Up @@ -71,9 +74,10 @@ def _build_matrix_from_sines_and_cosines(sin_angles, cos_angles):
return tf.reshape(matrix, shape=output_shape)


def assert_rotation_matrix_normalized(matrix,
eps=1e-3,
name="assert_rotation_matrix_normalized"):
def assert_rotation_matrix_normalized(
matrix: type_alias.TensorLike,
eps: type_alias.Float = 1e-3,
name: str = "assert_rotation_matrix_normalized") -> tf.Tensor:
"""Checks whether a matrix is a rotation matrix.

Note:
Expand Down Expand Up @@ -113,7 +117,10 @@ def assert_rotation_matrix_normalized(matrix,
return tf.identity(matrix)


def from_axis_angle(axis, angle, name="rotation_matrix_3d_from_axis_angle"):
def from_axis_angle(
axis: type_alias.TensorLike,
angle: type_alias.TensorLike,
name: str = "rotation_matrix_3d_from_axis_angle") -> tf.Tensor:
"""Convert an axis-angle representation to a rotation matrix.

Note:
Expand Down Expand Up @@ -174,7 +181,8 @@ def from_axis_angle(axis, angle, name="rotation_matrix_3d_from_axis_angle"):
return tf.reshape(matrix, shape=output_shape)


def from_euler(angles, name="rotation_matrix_3d_from_euler"):
def from_euler(angles: type_alias.TensorLike,
name: str = "rotation_matrix_3d_from_euler") -> tf.Tensor:
r"""Convert an Euler angle representation to a rotation matrix.

The resulting matrix is $$\mathbf{R} = \mathbf{R}_z\mathbf{R}_y\mathbf{R}_x$$.
Expand Down Expand Up @@ -208,7 +216,8 @@ def from_euler(angles, name="rotation_matrix_3d_from_euler"):


def from_euler_with_small_angles_approximation(
angles, name="rotation_matrix_3d_from_euler_with_small_angles"):
angles: type_alias.TensorLike,
name: str = "rotation_matrix_3d_from_euler_with_small_angles") -> tf.Tensor:
r"""Convert an Euler angle representation to a rotation matrix.

The resulting matrix is $$\mathbf{R} = \mathbf{R}_z\mathbf{R}_y\mathbf{R}_x$$.
Expand Down Expand Up @@ -246,7 +255,9 @@ def from_euler_with_small_angles_approximation(
return _build_matrix_from_sines_and_cosines(sin_angles, cos_angles)


def from_quaternion(quaternion, name="rotation_matrix_3d_from_quaternion"):
def from_quaternion(
quaternion: type_alias.TensorLike,
name: str = "rotation_matrix_3d_from_quaternion") -> tf.Tensor:
"""Convert a quaternion to a rotation matrix.

Note:
Expand Down Expand Up @@ -293,7 +304,8 @@ def from_quaternion(quaternion, name="rotation_matrix_3d_from_quaternion"):
return tf.reshape(matrix, shape=output_shape)


def inverse(matrix, name="rotation_matrix_3d_inverse"):
def inverse(matrix: type_alias.TensorLike,
name: str = "rotation_matrix_3d_inverse") -> tf.Tensor:
"""Computes the inverse of a 3D rotation matrix.

Note:
Expand Down Expand Up @@ -326,7 +338,9 @@ def inverse(matrix, name="rotation_matrix_3d_inverse"):
return tf.transpose(a=matrix, perm=perm)


def is_valid(matrix, atol=1e-3, name="rotation_matrix_3d_is_valid"):
def is_valid(matrix: type_alias.TensorLike,
atol: type_alias.Float = 1e-3,
name: str = "rotation_matrix_3d_is_valid") -> tf.Tensor:
"""Determines if a matrix is a valid rotation matrix.

Note:
Expand Down Expand Up @@ -354,7 +368,9 @@ def is_valid(matrix, atol=1e-3, name="rotation_matrix_3d_is_valid"):
return rotation_matrix_common.is_valid(matrix, atol)


def rotate(point, matrix, name="rotation_matrix_3d_rotate"):
def rotate(point: type_alias.TensorLike,
matrix: type_alias.TensorLike,
name: str = "rotation_matrix_3d_rotate") -> tf.Tensor:
"""Rotate a point using a rotation matrix 3d.

Note:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@

from tensorflow_graphics.util import export_api
from tensorflow_graphics.util import shape
from tensorflow_graphics.util import type_alias


def is_valid(matrix, atol=1e-3, name="rotation_matrix_common_is_valid"):
def is_valid(matrix: type_alias.TensorLike,
atol: type_alias.Float = 1e-3,
name: str = "rotation_matrix_common_is_valid") -> tf.Tensor:
r"""Determines if a matrix in K-dimensions is a valid rotation matrix.

Determines if a matrix $$\mathbf{R}$$ is a valid rotation matrix by checking
Expand Down
Loading