-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiment1.py
175 lines (133 loc) · 6.55 KB
/
experiment1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import os
import random
import subprocess
from termcolor import cprint
import util as u
#EXPERIMENT 1: roterende objecten in een cornell box (zie paper)
sphere_train_amount = 70 #70
sphere_val_amount = 30 #30
sphere_test_amount = 0
cylinder_train_amount = 70
cylinder_val_amount = 30
cylinder_test_amount = 0
cube_train_amount = 70
cube_val_amount = 30
cube_test_amount = 0
bunny_train_amount = 70
bunny_val_amount = 30
bunny_test_amount = 0
dragon_train_amount = 70
dragon_val_amount = 30
dragon_test_amount = 0
buddha_train_amount = 0
buddha_val_amount = 0
buddha_test_amount = 20
total_amount = (sphere_train_amount + sphere_val_amount + sphere_test_amount + cylinder_train_amount + cylinder_val_amount
+ cylinder_test_amount + cube_train_amount + cube_val_amount + cube_test_amount + bunny_train_amount + bunny_val_amount
+ bunny_test_amount + dragon_train_amount + dragon_val_amount + dragon_test_amount + buddha_train_amount
+ buddha_val_amount + buddha_test_amount) * 5
amount_done = 0
def experiment1():
train_counter = 0
test_counter = 0
val_counter = 0
# CYLINDER
at = """NamedMaterial "Item"
Translate 0 1 0
Rotate {} 1 0 0
Rotate {} 0 1 0
Rotate {} 0 0 1
Shape "cylinder" "float radius" 0.5 "float zmin" -0.5 "float zmax" 0.5 """
train_counter = generate_data("train", at, train_counter, cylinder_train_amount)
test_counter = generate_data("test", at, test_counter, cylinder_test_amount)
val_counter = generate_data("val", at, val_counter, cylinder_val_amount)
# SPHERE
at = """NamedMaterial "Item"
Translate 0 1 0
Rotate {} 1 0 0
Rotate {} 0 1 0
Rotate {} 0 0 1
Shape "sphere" "float radius" 0.5 """
train_counter = generate_data("train", at, train_counter, sphere_train_amount)
test_counter = generate_data("test", at, test_counter, sphere_test_amount)
val_counter = generate_data("val", at, val_counter, sphere_val_amount)
# CUBE
at = """NamedMaterial "Item"
Translate 0 1 0
Rotate {} 1 0 0
Rotate {} 0 1 0
Rotate {} 0 0 1
Translate 0 -0.5 0
Scale 0.3 0.3 0.3
Shape "plymesh" "string filename" "\\meshes\\\\cube.ply" """
train_counter = generate_data("train", at, train_counter, cube_train_amount)
test_counter = generate_data("test", at, test_counter, cube_test_amount)
val_counter = generate_data("val", at, val_counter, cube_val_amount)
#BUNNY
at = """NamedMaterial "Item"
Translate 0 1 0
Rotate {} 1 0 0
Rotate {} 0 1 0
Rotate {} 0 0 1
Translate 0 -0.5 0
Scale 0.75 0.75 0.75
Shape "plymesh" "string filename" "\\meshes\\\\bunny.ply" """
train_counter = generate_data("train", at, train_counter, bunny_train_amount)
test_counter = generate_data("test", at, test_counter, bunny_test_amount)
val_counter = generate_data("val", at, val_counter, bunny_val_amount)
# DRAGON
at = """NamedMaterial "Item"
Translate 0 1 0
Rotate {} 1 0 0
Rotate {} 0 1 0
Rotate {} 0 0 1
Translate 0 -0.5 0
Scale 0.75 0.75 0.75
Shape "plymesh" "string filename" "\\meshes\\\\dragon.ply" """
train_counter = generate_data("train", at, train_counter, dragon_train_amount)
test_counter = generate_data("test", at, test_counter, dragon_test_amount)
val_counter = generate_data("val", at, val_counter, dragon_val_amount)
# BUDDHA
at = """NamedMaterial "Item"
Translate 0 1 0
Rotate {} 1 0 0
Rotate {} 0 1 0
Rotate {} 0 0 1
Translate 0 -0.5 0
Scale 0.75 0.75 0.75
Shape "plymesh" "string filename" "\\meshes\\\\buddha.ply" """
train_counter = generate_data("train", at, train_counter, buddha_train_amount)
test_counter = generate_data("test", at, test_counter, buddha_test_amount)
val_counter = generate_data("val", at, val_counter, buddha_val_amount)
def generate_data(dataset, at_template, name, amount):
counter = 0
while counter < amount:
x_rotation = random.random() * 360
y_rotation = random.random() * 360
z_rotation = random.random() * 360
at = at_template.format(x_rotation, y_rotation, z_rotation)
albedo_scene_file_content = u.makePBRT(u.albedoIntegrator(), u.sobolSampler(64), u.triangleFilter(), u.imageFilm("render.png"), u.perspectiveCamera(), u.cornellBoxWorld(at))
normal_scene_file_content = u.makePBRT(u.normalIntegrator(), u.sobolSampler(64), u.triangleFilter(), u.imageFilm("render.pfm"), u.perspectiveCamera(), u.cornellBoxWorld(at))
direct_scene_file_content = u.makePBRT(u.directIlluminationIntegrator(), u.sobolSampler(64), u.triangleFilter(), u.imageFilm("render.png"), u.perspectiveCamera(), u.cornellBoxWorld(at))
depth_scene_file_content = u.makePBRT(u.depthIntegrator(), u.sobolSampler(64), u.triangleFilter(), u.imageFilm("render.pfm"), u.perspectiveCamera(), u.cornellBoxWorld(at))
gt_scene_file_content = u.makePBRT(u.pathTracingIntegrator(), u.sobolSampler(512), u.triangleFilter(), u.imageFilm("render.png"), u.perspectiveCamera(), u.cornellBoxWorld(at))
render_and_save_scene(albedo_scene_file_content, "dataset\\rot_cor\\{}\\albedo\\{}.png".format(dataset, name))
render_and_save_scene(normal_scene_file_content, "dataset\\rot_cor\\{}\\normal\\{}.pfm".format(dataset, name))
render_and_save_scene(direct_scene_file_content, "dataset\\rot_cor\\{}\\direct\\{}.png".format(dataset, name))
render_and_save_scene(depth_scene_file_content, "dataset\\rot_cor\\{}\\depth\\{}.pfm".format(dataset, name))
render_and_save_scene(gt_scene_file_content, "dataset\\rot_cor\\{}\\gt\\{}.png".format(dataset, name))
counter += 1
name += 1
return name
def render_and_save_scene(scene_file_content, path):
scene_file = open("scene.pbrt", "w")
scene_file.write(scene_file_content)
scene_file.close()
print(os.path.abspath("scene.pbrt"))
subprocess.run(['pbrt', "scene.pbrt"])
global amount_done
amount_done = amount_done + 1
cprint("{}/{} renders completed".format(amount_done, total_amount), 'green')
u.put_render_in_location(path)
os.remove("scene.pbrt")
experiment1()