16-889 Assignment 1: Rendering Basics with PyTorch3D

initial information

1.cd into starter folder

import render_mesh
import dolly_zoom
import render_shapes
import camera_transforms
import render_generic
import extra_credit

import matplotlib.pyplot as plt

cow_path = "../data/cow.obj"
image_size = 256

1. Practicing with Cameras

1.1. 360-degree Renders (5 points)

cow_360_gif_path = "../images/cow_360.gif"
render_mesh.render_cow(cow_path=cow_path, image_size=image_size, output_path=cow_360_gif_path)

360 GIF

1.2 Re-creating the Dolly Zoom (10 points)

num_frames = 10
duration = 3
dolly_gif_path = "../images/dolly.gif"
dolly_zoom.dolly_zoom(
    image_size=image_size,
    num_frames=num_frames,
    duration=duration,
    output_file=dolly_gif_path,
)

Dolly Zoom

2. Practicing with Meshes

2.1 Constructing a Tetrahedron (5 points)

tetragedron_gif_path = "../images/tetrahedron.gif"
render_shapes.render_tetrahedon(output_file=tetragedron_gif_path, image_size=image_size)

tetrahedron

2.2 Constructing a Cube (5 points)

cube_gif_path = "../images/cube.gif"
render_shapes.render_cube(output_file=cube_gif_path, image_size=image_size)

cube

3. Re-texturing a mesh (10 points)

cow_color_gif_path = "../images/cow_color.gif"
render_shapes.render_cow_color(output_file=cow_color_gif_path, image_size=image_size)

color cow

In this case, color1 = [1, 0.5, 0] is saffron and color2 = [0, 0.5, 0] is green.

4. Camera Transformations (20 points)

cow_obj_path = "../data/cow.obj"
cow_transform_img_path = "../images/transform_cow.jpg"

transform 1 - rotate around z axis

R_relative = [[0, 1, 0], [-1, 0, 0], [0, 0, 1]]
T_relative = [0, 0, 0]

output_path = cow_transform_img_path[:-4] + "_Trans_1" + cow_transform_img_path[-4:]
plt.imsave(output_path,
           camera_transforms.render_textured_cow(cow_path=cow_obj_path,
                                                 image_size=image_size,
                                                 R_relative=R_relative,
                                                 T_relative=T_relative))

transform 1

transform 2 - move back - z axis

R_relative = [[0, 1, 0], [-1, 0, 0], [0, 0, 1]]
T_relative = [0, 0, 0]

output_path = cow_transform_img_path[:-4] + "_Trans_2" + cow_transform_img_path[-4:]
plt.imsave(output_path,
           camera_transforms.render_textured_cow(cow_path=cow_obj_path,
                                                 image_size=image_size,
                                                 R_relative=R_relative,
                                                 T_relative=T_relative))

transform 2

transform 3 - slight translation along x and y

R_relative = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
T_relative = [0.5, -0.5, 0]
output_path = cow_transform_img_path[:-4] + "_Trans_3" + cow_transform_img_path[-4:]
plt.imsave(output_path,
           camera_transforms.render_textured_cow(cow_path=cow_obj_path,
                                                 image_size=image_size,
                                                 R_relative=R_relative,
                                                 T_relative=T_relative))

transform 3

transform 4 - rotate around y axis and shift along x and z axis

R_relative = [[0, 0, 1], [0, 1, 0], [-1, 0, 0]]
T_relative = [-3, 0, 3]
output_path = cow_transform_img_path[:-4] + "_Trans_4" + cow_transform_img_path[-4:]
plt.imsave(output_path,
           camera_transforms.render_textured_cow(cow_path=cow_obj_path,
                                                 image_size=image_size,
                                                 R_relative=R_relative,
                                                 T_relative=T_relative))

transform 4

5. Rendering Generic 3D Representations

5.1 Rendering Point Clouds from RGB-D Images (10 points)

# transform 1 - rotate around z axis
R_relative = [[0, 1, 0], [-1, 0, 0], [0, 0, 1]]
T_relative = [0, 0, 0]
#
output_path = cow_transform_img_path[:-4] + "_Trans_1" + cow_transform_img_path[-4:]
plt.imsave(output_path,
           camera_transforms.render_textured_cow(cow_path=cow_obj_path,
                                                 image_size=image_size,
                                                 R_relative=R_relative,
                                                 T_relative=T_relative))

# # transform 2 - move back - z axis
R_relative = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
T_relative = [0, 0, 2]

output_path = cow_transform_img_path[:-4] + "_Trans_2" + cow_transform_img_path[-4:]
plt.imsave(output_path,
           camera_transforms.render_textured_cow(cow_path=cow_obj_path,
                                                 image_size=image_size,
                                                 R_relative=R_relative,
                                                 T_relative=T_relative))

# transform 3 - slight translation along x and y
R_relative = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
T_relative = [0.5, -0.5, 0]
output_path = cow_transform_img_path[:-4] + "_Trans_3" + cow_transform_img_path[-4:]
plt.imsave(output_path,
           camera_transforms.render_textured_cow(cow_path=cow_obj_path,
                                                 image_size=image_size,
                                                 R_relative=R_relative,
                                                 T_relative=T_relative))

# transform 4 - rotate around y axis and shift
R_relative = [[0, 0, 1], [0, 1, 0], [-1, 0, 0]]
T_relative = [-3, 0, 3]
output_path = cow_transform_img_path[:-4] + "_Trans_4" + cow_transform_img_path[-4:]
plt.imsave(output_path,
           camera_transforms.render_textured_cow(cow_path=cow_obj_path,
                                                 image_size=image_size,
                                                 R_relative=R_relative,
                                                 T_relative=T_relative))

left, right and union

plant left plant right plant union

5.2 Parametric Functions (10 points)

output_torus_file = '../images/torus_param.gif'
num_samples = 200
render_generic.render_torus(image_size=image_size, num_samples=num_samples, device=None, output_file=output_torus_file)

torus parametric

In your writeup, include a 360-degree gif of your torus point cloud, and make sure the hole is visible. You may choose to texture your point cloud however you wish.

5.3 Implicit Surfaces (15 points)

output_torus_file = '../images/torus_impl.gif'
voxel_size = 64
render_generic.render_torus_mesh(image_size=image_size, voxel_size=voxel_size,
                                 device=None, output_file=output_torus_file)

torus implicit

In your writeup, include a 360-degree gif of your torus mesh, and make sure the hole is visible. In addition, discuss some of the tradeoffs between rendering as a mesh vs a point cloud. Things to consider might include rendering speed, rendering quality, ease of use, memory usage, etc.

6. Do Something Fun (10 points)

out_fun_file = "../images/cow_rainbow.gif"
render_shapes.render_cow_rainbow(cow_path=cow_obj_path,
                                 image_size=256,
                                 device=None,
                                 output_file=out_fun_file)

cow fun

Here I did a texture based on rainbow colors.

(Extra Credit) 7. Sampling Points on Meshes (10 points)

num_samples = 1000
out_cow_pts_path = "../images/cow_pts.gif"
extra_credit.render_cow_ptc(out_path=out_cow_pts_path, image_size=image_size, num_samples=num_samples)

10, 100, 1000, 10000

cow 10 cow 10 cow 10 cow 10 360 GIF

For this part, write a function that takes a triangle mesh and the number of samples and outputs a point cloud. Then, using the cow mesh, randomly sample 10, 100, 1000, and 10000 points. Render each pointcloud and the original cow mesh side-by-side, and include the gif in your writeup.*