Skip to content

Commit

Permalink
Moved to rendering/rasterizer. Adds a minimum depth argument (i.e. fu…
Browse files Browse the repository at this point in the history
…nction signatures have changed), fixes differentiability and speed issues, adds graph mode and AutoGraph compatibility.

PiperOrigin-RevId: 257096238
  • Loading branch information
cem-keskin authored and Copybara-Service committed Jul 16, 2019
1 parent 22a8e19 commit 368bbfa
Show file tree
Hide file tree
Showing 11 changed files with 808 additions and 966 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _rotation_2d_x(angle):
Returns:
The 2d rotation matrix.
"""
angle = np.asscalar(angle)
angle = angle.item()
return np.array(((np.cos(angle), -np.sin(angle)),
(np.sin(angle), np.cos(angle)))) # pyformat: disable

Expand Down Expand Up @@ -91,7 +91,7 @@ def _rotation_3d_x(angle):
Returns:
The 3d rotation matrix.
"""
angle = np.asscalar(angle)
angle = angle.item()
return np.array(((1., 0., 0.),
(0., np.cos(angle), -np.sin(angle)),
(0., np.sin(angle), np.cos(angle)))) # pyformat: disable
Expand All @@ -106,7 +106,7 @@ def _rotation_3d_y(angle):
Returns:
The 3d rotation matrix.
"""
angle = np.asscalar(angle)
angle = angle.item()
return np.array(((np.cos(angle), 0., np.sin(angle)),
(0., 1., 0.),
(-np.sin(angle), 0., np.cos(angle)))) # pyformat: disable
Expand All @@ -121,7 +121,7 @@ def _rotation_3d_z(angle):
Returns:
The 3d rotation matrix.
"""
angle = np.asscalar(angle)
angle = angle.item()
return np.array(((np.cos(angle), -np.sin(angle), 0.),
(np.sin(angle), np.cos(angle), 0.),
(0., 0., 1.))) # pyformat: disable
Expand Down
36 changes: 35 additions & 1 deletion tensorflow_graphics/rendering/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# Rendering utils for tf-graphics.

# google internal package dependency 8)
# google internal package dependency 5

licenses(["notice"]) # Apache 2.0

Expand All @@ -29,8 +30,41 @@ py_library(
visibility = ["//visibility:public"],
deps = [
"//tensorflow_graphics/rendering/camera",
"//tensorflow_graphics/rendering/differentiable_renderer",
"//tensorflow_graphics/rendering/reflectance",
"//tensorflow_graphics/util:export_api",
],
)

py_library(
name = "rasterizer",
srcs = ["rasterizer.py"],
srcs_version = "PY2AND3",
# google internal rule 1
deps = [
# google internal package dependency 1,
"//tensorflow_graphics/rendering/camera:orthographic",
"//tensorflow_graphics/util:safe_ops",
"//tensorflow_graphics/util:shape",
],
)

py_test(
name = "rasterizer_test",
srcs = ["tests/rasterizer_test.py"],
srcs_version = "PY2AND3",
# google internal rule 1
# google internal rule 2
# google internal rule 3
# google internal rule 4
# google internal rule 5
# google internal rule 6
deps = [
":rasterizer",
# google internal package dependency 3
# google internal package dependency 2
# google internal package dependency 6
# google internal package dependency 1,
"//tensorflow_graphics/notebooks/resources:tfg_simplified_logo",
"//tensorflow_graphics/util:test_case",
],
)
1 change: 0 additions & 1 deletion tensorflow_graphics/rendering/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from __future__ import print_function

from tensorflow_graphics.rendering import camera
from tensorflow_graphics.rendering import differentiable_renderer
from tensorflow_graphics.rendering import reflectance
from tensorflow_graphics.util import export_api as _export_api

Expand Down
10 changes: 4 additions & 6 deletions tensorflow_graphics/rendering/camera/orthographic.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def project(point_3d, name=None):
shape.check_static(
tensor=point_3d, tensor_name="point_3d", has_dim_equals=(-1, 3))

return point_3d[..., :2]
point_xy, _ = tf.compat.v1.split(point_3d, (2, 1), axis=-1)
return point_xy


def ray(point_2d, name=None):
Expand Down Expand Up @@ -99,12 +100,9 @@ def ray(point_2d, name=None):
shape.check_static(
tensor=point_2d, tensor_name="point_2d", has_dim_equals=(-1, 2))

zeros = tf.zeros_like(point_2d)
ones = tf.ones_like(point_2d[..., :1])
zeros = tf.zeros_like(point_2d)
# The multiplication of point_2d by zeros is necessary for getting
# gradients.
return tf.concat((point_2d * zeros, ones), axis=-1)
# point_2d is multiplied by zero to ensure it has defined gradients.
return tf.concat((point_2d * 0.0, ones), axis=-1)


def unproject(point_2d, depth, name=None):
Expand Down
64 changes: 0 additions & 64 deletions tensorflow_graphics/rendering/differentiable_renderer/BUILD

This file was deleted.

23 changes: 0 additions & 23 deletions tensorflow_graphics/rendering/differentiable_renderer/__init__.py

This file was deleted.

0 comments on commit 368bbfa

Please sign in to comment.