C++ examples

This example executes the examples written with C++ API.

[1]:
import os
import sys
import subprocess as sp
import numpy as np
import imageio
%matplotlib inline
import matplotlib.pyplot as plt
import lmfunctest as ft
[2]:
outdir = './output'
width = 1920
height = 1080
[3]:
def run_example(ex, params):
    print('Executing example [name=%s]' % ex)
    sys.stdout.flush()
    # Execute the example executable
    # We convert backslashes as path separator in Windows environment
    # to slashes because subprocess might pass unescaped backslash.
    sp.call([
        os.path.join(ft.env.bin_path, ex)
    ] + [str(v).replace('\\', '/') for v in params])

def visualize(out):
    img = imageio.imread(out)
    f = plt.figure(figsize=(15,15))
    ax = f.add_subplot(111)
    ax.imshow(np.clip(np.power(img,1/2.2),0,1), origin='lower')
    plt.show()

blank.cpp

Corresponding Python example: Rendering blank image

[4]:
out = os.path.join(outdir, 'blank.pfm')
run_example('blank', [out, width, height])
visualize(out)
Executing example [name=blank]
../_images/executed_functest_example_cpp_6_1.png

quad.cpp

Corresponding Python example: Rendering quad

[5]:
out = os.path.join(outdir, 'quad.pfm')
run_example('quad', [out, width, height])
visualize(out)
Executing example [name=quad]
../_images/executed_functest_example_cpp_9_1.png

raycast.cpp

Corresponding Python example: Raycasting a scene with OBJ models

[6]:
out = os.path.join(outdir, 'raycast.pfm')
run_example('raycast', [
    os.path.join(ft.env.scene_path, 'fireplace_room/fireplace_room.obj'),
    out,
    width, height,
    5.101118, 1.083746, -2.756308,
    4.167568, 1.078925, -2.397892,
    43.001194
])
visualize(out)
Executing example [name=raycast]
../_images/executed_functest_example_cpp_12_1.png
[7]:
out = os.path.join(outdir, 'pt2.pfm')
run_example('raycast', [
    os.path.join(ft.env.scene_path, 'cornell_box/CornellBox-Sphere.obj'),
    out,
    width, height,
    0, 1, 5,
    0, 1, 0,
    30
])
visualize(out)
Executing example [name=raycast]
../_images/executed_functest_example_cpp_13_1.png

pt.cpp

Corresponding Python example: Rendering with path tracing

[8]:
out = os.path.join(outdir, 'pt.pfm')
run_example('pt', [
    os.path.join(ft.env.scene_path, 'fireplace_room/fireplace_room.obj'),
    out,
    10, 20,
    width, height,
    5.101118, 1.083746, -2.756308,
    4.167568, 1.078925, -2.397892,
    43.001194
])
visualize(out)
Executing example [name=pt]
../_images/executed_functest_example_cpp_16_1.png
[9]:
out = os.path.join(outdir, 'pt2.pfm')
run_example('pt', [
    os.path.join(ft.env.scene_path, 'cornell_box/CornellBox-Sphere.obj'),
    out,
    10, 20,
    width, height,
    0, 1, 5,
    0, 1, 0,
    30
])
visualize(out)
Executing example [name=pt]
../_images/executed_functest_example_cpp_17_1.png

custom_material.cpp

Corresponding Python example: Rendering with custom material

[10]:
out = os.path.join(outdir, 'custom_material.pfm')
run_example('custom_material', [
    os.path.join(ft.env.scene_path, 'fireplace_room/fireplace_room.obj'),
    out,
    width, height,
    5.101118, 1.083746, -2.756308,
    4.167568, 1.078925, -2.397892,
    43.001194
])
visualize(out)
Executing example [name=custom_material]
../_images/executed_functest_example_cpp_20_1.png

custom_renderer.cpp

Corresponding Python example: Rendering with custom renderer

[11]:
out = os.path.join(outdir, 'custom_renderer.pfm')
run_example('custom_renderer', [
    os.path.join(ft.env.scene_path, 'fireplace_room/fireplace_room.obj'),
    out,
    10,
    width, height,
    5.101118, 1.083746, -2.756308,
    4.167568, 1.078925, -2.397892,
    43.001194
])
visualize(out)
Executing example [name=custom_renderer]
../_images/executed_functest_example_cpp_23_1.png