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]
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]
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]
[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]
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]
[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]
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]
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]