-
Notifications
You must be signed in to change notification settings - Fork 0
/
reflecteur.py
68 lines (52 loc) · 2.09 KB
/
reflecteur.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
from __future__ import print_function
import sys
import argparse
import time
sys.path.append('../PyMongeAmpere-build/')
sys.path.append('../PyMongeAmpere-build/lib')
sys.path.append('./lib')
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import MongeAmpere as ma
from preprocessing import *
import geometry as geo
import rayTracing as ray
import misc
import export
debut = time.clock()
#### Parameters initialization ####
parser = argparse.ArgumentParser()
param = init_parameters(parser)
display_parameters(param)
# Target base
target_plane_base = [param['e_eta'],param['e_xi'],param['n_plan']]
##### Source and target processing #####
mu, P, nu = input_preprocessing(param)
#misc.plot_density(mu)
source_box = [np.min(mu.vertices[:,0]), np.max(mu.vertices[:,0]), np.min(mu.vertices[:,1]), np.max(mu.vertices[:,1])]
target_plane_box = [np.min(P[:,0]), np.max(P[:,0]), np.min(P[:,1]), np.max(P[:,1])]
p,q = geo.planar_to_gradient(P[:,0],P[:,1],target_plane_base)
Y = np.vstack([p,q]).T
print('Number of diracs: ', len(nu))
t = time.clock() - debut
print ("Inputs processing:", t, "s")
##### Optimal Transport problem resolution #####
psi0 = ma.optimal_transport_presolve_2(Y, mu.vertices, Y_w=nu, X_w=mu.values)
psi = ma.optimal_transport_2(mu, Y, nu, w0=psi0, verbose=True)
t = time.clock() - t
print ("OT resolution:", t, "s")
Z,T_Z,u_Z = misc.eval_legendre_fenchel(mu, Y, psi)
interpol = misc.make_cubic_interpolator(Z, T_Z, u_Z, grad=Y)
##### Export of the scaled reflector in .off and .ioff files #####
points = np.array([Z[:,0],Z[:,1],u_Z]).T
##export.export_improved_off('square_cameraman1e2.ioff', points, grad, T_Z)
export.export_off('square_monge_1e3.off', points, T_Z)
#export.export_off('square_monge_1e3_horiz.off', points, T_Z, rot=True, param=param)
##### Ray tracing #####
M = ray.ray_tracer(mu, target_plane_box, interpol, target_plane_base, niter=3)
print ("Ray tracing:", time.clock() - t, "s")
plt.imshow(M, interpolation='nearest',
vmin=0, vmax=255, cmap=plt.get_cmap('gray'))
print ("Execution time:", time.clock() - debut, "s (CPU time)")
plt.show()