Commit 0b763829 authored by Laurent Belcour's avatar Laurent Belcour

Adding the script file to compute the retro data fitting

Plus unitary testing for retro and fresnel stuff
parent ad0523a8
......@@ -287,6 +287,9 @@ bool spherical_gaussian_function::load(std::istream& in)
{
in >> token >> _a;
}
std::cout << "<<DEBUG>> Spherical gaussians plugin, found p= " << parameters() << std::endl;
return true;
}
......
import math
from vec3 import *
def fresnel(dotVH, R):
return R + (1.0-R)*math.pow(1.0 - dotVH, 5.0)
#end
def blinn(dotHN, N):
return math.pow(dotHN, N)
#end
f = open('unitary-fresnel.data', 'w+')
# Generate the header of the file in the ALTA format
f.write("#DIM 3 1\n")
f.write("#PARAM_IN ISOTROPIC_TV_TL_DPHI\n")
f.write("#PARAM_OUT INV_STERADIAN\n")
N = vec3(0.0, 0.0, 1.0)
theta_i = -(0.5*math.pi - 0.1)
phi_i = 0.0
V = vec3()
V.set_spherical(1.0, theta_i, phi_i)
n = 50
# Blinn lobe parameter
N0 = 10
# Fresnel Parameter
R0 = 0.5
for i in range(0,n):
for j in range(0,n):
theta_o = 0.5 * math.pi * float(i) / float(n)
phi_o = 2.0 * math.pi * float(j) / float(n)
L = vec3()
L.set_spherical(1.0, theta_o, phi_o)
H = V+L;
H.normalize()
val = blinn(H*N, N0) * fresnel(V*H, R0)
f.write(str(theta_i) + '\t' + str(theta_o) + '\t' + str(phi_o-phi_i) + '\t' + str(val) + '\n')
#end
#end
import math
from vec3 import *
f = open('unitary-retro.data', 'w+')
# Generate the header of the file in the ALTA format
f.write("#DIM 3 1\n")
f.write("#PARAM_IN ISOTROPIC_TV_TL_DPHI\n")
f.write("#PARAM_OUT INV_STERADIAN\n")
def blinn(cost, sigma):
return math.pow(cost, sigma);
#endif
def fresnel(u, R):
return R + (1.0-R)*math.pow(1-u, 5)
#end
n = 100
# Blinn lobe parameter
N0 = 10
# Fresnel Parameter
R0 = 0.5
# Normal vector
N = vec3(0.0, 0.0, 1.0)
# View vector
theta_i = -(0.5*math.pi - 0.05)
phi_i = 0.0
V = vec3()
V.set_spherical(1.0, theta_i, phi_i)
# Reflection vector
R = 2*(V*N)*N - V
for i in range(0,n):
for j in range(0,n):
theta_o = 0.5 * math.pi * float(i) / float(n)
phi_o = 2.0 * math.pi * float(j) / float(n)
L = vec3()
L.set_spherical(1.0, theta_o, phi_o)
H = V+L
H.normalize()
B = R+L
B.normalize()
val = blinn(B*N, N0) * fresnel(R*B, R0)
f.write(str(theta_i) + '\t' + str(theta_o) + '\t' + str(phi_o-phi_i) + '\t' + str(val) + '\n')
#end
#end
import math
import random
f = open('rational_test_3d.input', 'w+')
# Generate the header of the file in the ALTA format
f.write("#DIM 3 1\n")
f.write("#PARAM_IN UNKNOWN\n")
f.write("#PARAM_OUT INV_STERADIAN\n")
nx = 10
ny = 10
nz = 10
for i in range(0,nx):
for j in range(0,ny):
for k in range(0,nz):
x = i * (1.0/nx)
y = j * (1.0/ny)
z = k * (1.0/nz)
val = x*x + math.sin(2*3.14*y*z) ;
f.write(str(x) + '\t' + str(y) + '\t' + str(z) + '\t' + str(val) + '\n');
#end
#end
#end
'''
Simple class for 3D vectors.
Requires: Python 2.5 and numpy 1.0.4
(c) Ilan Schnell, 2008
'''
import numpy
import math
_TINY = 1e-15
def _xyzto012(c):
if c in 'xyz':
return ord(c) - ord('x')
else:
raise AttributeError("vec3 instance has no attribute '%s'" % c)
def _args2tuple(funcname, args):
narg = len(args)
if narg == 0:
data = 3*(0,)
elif narg == 1:
data = args[0]
if len(data) != 3:
raise TypeError('vec3.%s() takes sequence with 3 elements '
'(%d given),\n\t when 1 argument is given' %
(funcname, len(data)))
elif narg == 3:
data = args
else:
raise TypeError('vec3.%s() takes 0, 1 or 3 arguments (%d given)' %
(funcname, narg))
assert len(data) == 3
try:
return tuple(map(float, data))
except (TypeError, ValueError):
raise TypeError("vec3.%s() can't convert elements to float" % funcname)
class vec3(numpy.ndarray):
def __new__(cls, *args):
if len(args) == 1:
if isinstance(args[0], vec3):
return args[0].copy()
if isinstance(args[0], numpy.matrix):
return vec3(args[0].flatten().tolist()[0])
data = _args2tuple('__new__', args)
arr = numpy.array(data, dtype=numpy.float, copy=True)
return numpy.ndarray.__new__(cls, shape=(3,), buffer=arr)
def __repr__(self):
return 'vec3' + repr(tuple(self))
def __mul__(self, other):
return numpy.dot(self, other)
def __abs__(self):
return math.sqrt(self * self)
def __pow__(self, x):
return (self * self) if x == 2 else pow(abs(self), x)
def __eq__(self, other):
return abs(self-other) < _TINY
def __ne__(self, other):
return not self == other
def __getattr__(self, name):
return self[_xyzto012(name)]
def __setattr__(self, name, val):
self[_xyzto012(name)] = val
def get_spherical(self):
r = abs(self)
if r < _TINY:
theta = phi = 0.0
else:
x, y, z = self
theta = math.acos(z/r)
phi = math.atan2(y, x)
return r, theta, phi
def set_spherical(self, *args):
r, theta, phi = _args2tuple('set_spherical', args)
self[0] = r * math.sin(theta) * math.cos(phi);
self[1] = r * math.sin(theta) * math.sin(phi);
self[2] = r * math.cos(theta);
def get_cylindrical(self):
x, y, z = self
rho = math.sqrt(x*x + y*y)
phi = math.atan2(y, x)
return rho, phi, z
def set_cylindrical(self, *args):
rho, phi, z = _args2tuple('set_cylindrical', args)
self[0] = rho * math.cos(phi);
self[1] = rho * math.sin(phi);
self[2] = z
def normalize(self):
norm = abs(self)
self[0] /= norm
self[1] /= norm
self[2] /= norm
def cross(a, b):
return vec3(numpy.cross(a, b))
if __name__ == '__main__':
import doctest, os
fname = 'doc.txt'
if os.access(fname, os.R_OK):
doctest.testfile(fname)
os.system('rm /tmp/data.*')
<?xml version="1.0"?>
<alta>
<!-- This script file compute the fitting of the retro-reflecting materials present in
the ALTA library. This script file should be executed in the sources directory of
repository as all directories are relative.
It is also necessary to create a results/3d/retro directory to store the resulting
fits and exports to BRDF-explorer and matlab.
-->
<configuration>
<parameter name="lib-dir" value="./build" />
</configuration>
<!-- Fit the data to a BRDF model -->
<action name="data2brdf">
<!-- Input and output arguments of the action -->
<input name="../papers/retro/mesures/original/3M_jaune/3d/633nm/Fichiers\ definitifs/3M_jaune_isotropic_brdfcc_rescaled_alta.dat" />
<output name="./results/3d/retro/3M_jaune_blinn.brdf" />
<!-- Define the function to use -->
<function name="nonlinear_function_diffuse" />
<function name="nonlinear_function_blinn" />
<function name="nonlinear_function_retroblinn" />
<!-- Define the ftting procedure to use -->
<plugin type="fitter" name="nonlinear_fitter_ceres" />
</action>
<!-- Export the fit -->
<action name="brdf2gnuplot">
<!-- Input and output arguments of the action -->
<input name="./results/3d/retro/3M_jaune_blinn.brdf" />
<output name="./results/3d/retro/3M_jaune_blinn.dat" />
<parameter name="data" value="../papers/retro/mesures/original/3M_jaune/3d/633nm/Fichiers\ definitifs/3M_jaune_isotropic_brdfcc_rescaled_alta.dat" />
</action>
<!-- Fit the data to a BRDF model -->
<action name="data2brdf">
<!-- Input and output arguments of the action -->
<input name="../papers/retro/mesures/original/3M_jaune/3d/633nm/Fichiers\ definitifs/3M_jaune_isotropic_brdfcc_rescaled_alta.dat" />
<output name="./results/3d/retro/3M_jaune_sg.brdf" />
<!-- Define the function to use -->
<function name="nonlinear_function_diffuse" />
<function name="nonlinear_function_spherical_gaussian" />
<function name="nonlinear_function_spherical_gaussian">
<parameter name="sg-type" value="back" />
</function>
<!-- Define the ftting procedure to use -->
<plugin type="fitter" name="nonlinear_fitter_ceres" />
</action>
<!-- Export the fit -->
<action name="brdf2gnuplot">
<!-- Input and output arguments of the action -->
<input name="./results/3d/retro/3M_jaune_sg.brdf" />
<output name="./results/3d/retro/3M_jaune_sg.dat" />
<parameter name="data" value="../papers/retro/mesures/original/3M_jaune/3d/633nm/Fichiers\ definitifs/3M_jaune_isotropic_brdfcc_rescaled_alta.dat" />
</action>
</alta>
<?xml version="1.0"?>
<alta>
<!-- This script file compute the fitting of the retro-reflecting materials present in
the ALTA library. This script file should be executed in the sources directory of
repository as all directories are relative.
It is also necessary to create a results/3d/retro directory to store the resulting
fits and exports to BRDF-explorer and matlab.
-->
<configuration>
<parameter name="lib-dir" value="./build" />
</configuration>
<!-- Fit the data to a BRDF model -->
<action name="data2brdf">
<!-- Input and output arguments of the action -->
<input name="../papers/retro/mesures/original/Bande_fluo_grise/3d/633nm/Fichiers\ definitifs/Bande_grise_isotropic_brdfcc_rescaled_alta.dat" />
<output name="./results/3d/retro/bande_fluo_blinn.brdf" />
<!-- Define the function to use -->
<function name="nonlinear_function_diffuse" />
<function name="nonlinear_function_blinn" />
<function name="nonlinear_function_retroblinn" />
<!-- Define the ftting procedure to use -->
<plugin type="fitter" name="nonlinear_fitter_ceres" />
</action>
<!-- Export the fit -->
<action name="brdf2gnuplot">
<!-- Input and output arguments of the action -->
<input name="./results/3d/retro/bande_fluo_blinn.brdf" />
<output name="./results/3d/retro/bande_fluo_blinn.dat" />
<parameter name="data" value="../papers/retro/mesures/original/Bande_fluo_grise/3d/633nm/Fichiers\ definitifs/Bande_grise_isotropic_brdfcc_rescaled_alta.dat" />
</action>
<!-- Fit the data to a BRDF model -->
<action name="data2brdf">
<!-- Input and output arguments of the action -->
<input name="../papers/retro/mesures/original/Bande_fluo_grise/3d/633nm/Fichiers\ definitifs/Bande_grise_isotropic_brdfcc_rescaled_alta.dat" />
<output name="./results/3d/retro/bande_fluo_sg.brdf" />
<!-- Define the function to use -->
<function name="nonlinear_function_diffuse" />
<function name="nonlinear_function_spherical_gaussian" />
<function name="nonlinear_function_spherical_gaussian">
<parameter name="sg-type" value="back" />
</function>
<!-- Define the ftting procedure to use -->
<plugin type="fitter" name="nonlinear_fitter_ceres" />
</action>
<!-- Export the fit -->
<action name="brdf2gnuplot">
<!-- Input and output arguments of the action -->
<input name="./results/3d/retro/bande_fluo_sg.brdf" />
<output name="./results/3d/retro/bande_fluo_sg.dat" />
<parameter name="data" value="../papers/retro/mesures/original/Bande_fluo_grise/3d/633nm/Fichiers\ definitifs/Bande_grise_isotropic_brdfcc_rescaled_alta.dat" />
</action>
</alta>
<?xml version="1.0"?>
<alta>
<!-- This script file compute the fitting of the retro-reflecting materials present in
the ALTA library. This script file should be executed in the sources directory of
repository as all directories are relative.
It is also necessary to create a results/3d/retro directory to store the resulting
fits and exports to BRDF-explorer and matlab.
-->
<configuration>
<parameter name="lib-dir" value="./build" />
</configuration>
<!-- Fit the data to a BRDF model -->
<action name="data2brdf">
<!-- Input and output arguments of the action -->
<input name="../papers/retro/mesures/original/Bande_orange/3d/633nm/Fichiers_definitifs/Bande_orange_isotropic_brdfcc_rescaled_alta.dat" />
<output name="./results/3d/retro/bande_orange_blinn.brdf" />
<!-- Define the function to use -->
<function name="nonlinear_function_diffuse" />
<function name="nonlinear_function_blinn" />
<function name="nonlinear_function_retroblinn" />
<!-- Define the ftting procedure to use -->
<plugin type="fitter" name="nonlinear_fitter_ceres" />
</action>
<!-- Export the fit -->
<action name="brdf2gnuplot">
<!-- Input and output arguments of the action -->
<input name="./results/3d/retro/bande_orange_blinn.brdf" />
<output name="./results/3d/retro/bande_orange_blinn.dat" />
<parameter name="data" value="../papers/retro/mesures/original/Bande_orange/3d/633nm/Fichiers_definitifs/Bande_orange_isotropic_brdfcc_rescaled_alta.dat" />
</action>
<!-- Fit the data to a BRDF model -->
<action name="data2brdf">
<!-- Input and output arguments of the action -->
<input name="../papers/retro/mesures/original/Bande_orange/3d/633nm/Fichiers_definitifs/Bande_orange_isotropic_brdfcc_rescaled_alta.dat" />
<output name="./results/3d/retro/bande_orange_sg.brdf" />
<!-- Define the function to use -->
<function name="nonlinear_function_diffuse" />
<function name="nonlinear_function_spherical_gaussian" />
<function name="nonlinear_function_spherical_gaussian">
<parameter name="sg-type" value="back" />
</function>
<!-- Define the ftting procedure to use -->
<plugin type="fitter" name="nonlinear_fitter_ceres" />
</action>
<!-- Export the fit -->
<action name="brdf2gnuplot">
<!-- Input and output arguments of the action -->
<input name="./results/3d/retro/bande_orange_sg.brdf" />
<output name="./results/3d/retro/bande_orange_sg.dat" />
<parameter name="data" value="../papers/retro/mesures/original/Bande_orange/3d/633nm/Fichiers_definitifs/Bande_orange_isotropic_brdfcc_rescaled_alta.dat" />
</action>
</alta>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment