main.cpp 6.05 KB
Newer Older
1 2 3 4
#include <iostream>
#include <fstream>
#include <cmath>

Laurent Belcour's avatar
Laurent Belcour committed
5
#include <core/args.h>
6
#include <core/params.h>
7
#include <nonlinear_fresnel_schlick/function.h>
Laurent Belcour's avatar
Laurent Belcour committed
8 9

int main(int argc, char** argv)
10 11
{
	std::ofstream f("input.gnuplot") ;
Laurent Belcour's avatar
Laurent Belcour committed
12 13
	arguments args(argc, argv);	

14
	std::cout.precision(10);
15

16
	int nbx = 10000;
Laurent Belcour's avatar
Laurent Belcour committed
17 18 19 20 21 22
	int nby = 100;
	int nbz = 100;
	if(args.is_defined("nbx"))
		nbx = args.get_int("nbx", 100) ;
	if(args.is_defined("nby"))
		nby = args.get_int("nby", 100) ;
23

Laurent Belcour's avatar
Laurent Belcour committed
24
	const int k = args.get_int("f", 1) ;
25 26
	int K = 1;
	if(k == K++)
27
	{
28
		f << "#DIM 1 1" << std::endl ;
29 30
		f << "#PARAM_IN UNKNOWN" << std::endl;
		//f << "#VS 2" << std::endl;
Laurent Belcour's avatar
Laurent Belcour committed
31
		for(int i=0; i<nbx; ++i)
32
		{
33 34 35 36
			const float x  = 10.0 * i / (float)nbx ;
			const float xp = (x - 9);
			const float y  = 1000.0f * exp(- x*x) * x*x + 00.1 * exp(-100.0 * xp*xp)  *x*x*x + 0.1 ;
			//const float y = (1.0) / (1.0E-10 + x);
37

38
			f << x << "\t" << y << /*"\t" << y*0.9f << "\t" << y*1.1f <<*/ std::endl ;
39 40
		}
	}
41
	else if(k == K++)
42 43 44 45 46 47 48 49 50 51 52
	{
		f << "#DIM 1 1" << std::endl ;
		f << "#PARAM_IN UNKNOWN" << std::endl;
		for(int i=0; i<nbx; ++i)
		{
			const float x = i / (float)nbx ;
			const float y = (1.0 + 7.0*x - 10.5*x*x) / (1.0 + 7.0 * x) ;

			f << x << "\t" << y << "\t" << 0.1f << std::endl ;
		}
	}
53
	else if(k == K++)
54 55
	{
		f << "#DIM 2 1" << std::endl ;
Laurent Belcour's avatar
Laurent Belcour committed
56 57 58 59 60
		for(int i=0; i<nbx; ++i)
			for(int j=0; j<nby; ++j)
			{
				const float x = i / (float)nbx ;				
				const float y = j / (float)nby ; 
61 62 63
				const float z = 10 * x + 1.0;

				f << x << "\t" << y << "\t" << z << "\t" << z-0.1f << "\t" << z << std::endl ;
Laurent Belcour's avatar
Laurent Belcour committed
64 65
			}
	}
66
	else if(k == K++)
Laurent Belcour's avatar
Laurent Belcour committed
67 68
	{
		f << "#DIM 2 1" << std::endl ;
69
		f << "#PARAM_IN UNKNOWN" << std::endl;
Laurent Belcour's avatar
Laurent Belcour committed
70 71
		for(int i=0; i<nbx; ++i)
			for(int j=0; j<nby; ++j)
72
			{
Laurent Belcour's avatar
Laurent Belcour committed
73 74
				const float x = i / (float)nbx ;
				const float y = j / (float)nby ; 
75 76
				const float z = x*y / (1.0E-3 + x*x*x) + 10.;

77

78
				f << x << "\t" << y << "\t" << z << std::endl ;
79
			}
80
	}
81
	else if(k == K++)
82
	{
83
		f << "#DIM 1 1" << std::endl ;
84 85 86
		f << "#PARAM_IN COS_TH" << std::endl;
		for(int i=0; i<nbx; ++i)
		{
87 88 89 90 91 92 93 94 95 96 97
			const double   x = i / (float)nbx ;
			//				const float d[3] = {0.1, 0.0, 0.5};
			const float d[3] = {0.0, 0.0, 0.0};
			const float z1 = d[0] + 0.2 * std::pow(x, 1.5) ;
			//				const float z2 = d[1] - 0.1 * std::pow(x, 4.0) ;
			//				const float z3 = d[2] + 0.7 * std::pow(x, 1.0) ;

			f << x << "\t" << z1 ;
			//				f << "\t" << z2 ;
			//				f << "\t" << z3 ;
			f << std::endl ;
Laurent Belcour's avatar
Laurent Belcour committed
98 99
		}
	}
100
	else if(k == K++)
Laurent Belcour's avatar
Laurent Belcour committed
101 102 103 104 105
	{
		f << "#DIM 1 1" << std::endl ;
		f << "#PARAM_IN COS_TH" << std::endl;
		for(int i=0; i<nbx; ++i)
		{
106 107 108 109 110 111
			const double x = i / (float)nbx ;
			const double z = 0.1 + 0.5 * std::pow(x, 1.5) ;

			f << x << "\t" << z << std::endl ;
		}
	}
112 113 114 115 116 117 118 119 120 121 122 123 124 125
	else if(k == K++)
	{
		f << "#DIM 1 3" << std::endl ;
		f << "#PARAM_IN COS_TH" << std::endl;
		for(int i=0; i<nbx; ++i)
		{
			const double x = i / (float)nbx ;
			const double z1 = 0.1 + 0.5 * std::pow(x, 1.5) ;
			const double z2 = 1.0 + 0.4 * std::pow(x, 1000.0) ;
			const double z3 = 0.5 + 0.3265 * std::pow(x, 0.1) ;

			f << x << "\t" << z1 << "\t" << z2 << "\t" << z3 << std::endl ;
		}
	}
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
	// Multidimensional data
	else if(k == K++)
	{
		f << "#DIM 1 3" << std::endl ;
		f << "#PARAM_IN UNKNOWN" << std::endl;
		for(int i=0; i<nbx; ++i)
		{
			const double x = i / (float)nbx ;
			const double z1 = 0.1 + x -0.2 * x*x ;
			const double z2 = 0.1 - 0.001* x*x;
			const double z3 = 0.1 + 0.5 * std::pow(x, 1.5) ;

			f << x << "\t" << z1 << "\t" << z2 << "\t" << z3 << std::endl ;
		}
	}
141 142
	// Lafortune fitting
	// Single lobe (0.86, 0.77, 18.6)
143
	else if(k == K++)
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 176
	{
		f << "#DIM 2 1" << std::endl ;
		f << "#PARAM_IN RUSIN_TH_TD" << std::endl;
		for(int i=0; i<nbx; ++i)
		{
			for(int j=0; j<nby; ++j)
			{
				double in_r[2], in_c[6];
				in_r[0] = M_PI * 0.5 * i / (float)nbx ;
				in_r[1] = M_PI * 0.5 * j / (float)nby ;

				params::convert(in_r, params::RUSIN_TH_TD, params::CARTESIAN, in_c);

				const double Cx =0.86;
				const double Cz =0.77;
				const double n = 18.6;

				const double cos = Cx * (in_c[0]*in_c[3] + in_c[1]*in_c[4]) + Cz*in_c[2]*in_c[5];
				
				if(cos > 0.0)
				{
					const double z = std::pow(cos, n) ;
					f << in_r[0] << "\t" << in_r[1] << "\t" << z << std::endl ;
				}
				else
				{
					f << in_r[0] << "\t" << in_r[1] << "\t" << 0.0 << std::endl ;
				}
			}
		}
	}
	// Lafortune fitting
	// Triple lobe (0.86, 0.77, 18.6), (-0.41, 0.018, 2.58), (-1.03, 0.7, 63.8)
177
	else if(k == K++)
178
	{
179 180 181 182
		const double Cx[3] = {0.86, -0.410, -1.03};
		const double Cz[3] = {0.77,  0.018,  0.70};
		const double n[3]  = {18.6,  2.580,  63.8};

183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
		f << "#DIM 2 1" << std::endl ;
		f << "#PARAM_IN RUSIN_TH_TD" << std::endl;
		for(int i=0; i<=90; ++i)
		{
			for(int j=0; j<=90; ++j)
			{
				double in_r[2], in_c[6];
				in_r[0] = M_PI * 0.5 * i / (double)90 ;
				in_r[1] = M_PI * 0.5 * j / (double)90 ;

				params::convert(in_r, params::RUSIN_TH_TD, params::CARTESIAN, in_c);

				double z = 0.0;
				for(int k=0; k<3; ++k)
				{
					const double cos = Cx[k] * (in_c[0]*in_c[3] + in_c[1]*in_c[4]) + Cz[k]*in_c[2]*in_c[5];

					if(cos > 0.0)
					{
						z += std::pow(cos, n[k]) ;

					}
				}
				f << in_r[0] << "\t" << in_r[1] << "\t" << z << std::endl ;
			}
208 209
		}
	}
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
	// Lafortune fitting
	// Simple lobe but multiple channels
	// [(0.86, 0.77, 18.6), (-0.41, 0.018, 2.58), (-1.03, 0.7, 63.8)]
	else if(k == K++)
	{
		const double Cx[3] = {0.86, -0.410, -1.03};
		const double Cz[3] = {0.77,  0.018,  0.70};
		const double n[3]  = {18.6,  2.580,  63.8};

		f << "#DIM 2 3" << std::endl ;
		f << "#PARAM_IN RUSIN_TH_TD" << std::endl;
		for(int i=0; i<=90; ++i)
		{
			for(int j=0; j<=90; ++j)
			{
				double in_r[2], in_c[6];
				in_r[0] = M_PI * 0.5 * i / (double)90 ;
				in_r[1] = M_PI * 0.5 * j / (double)90 ;

				params::convert(in_r, params::RUSIN_TH_TD, params::CARTESIAN, in_c);

				double z[3] = {0.0, 0.0, 0.0};
				for(int k=0; k<3; ++k)
				{
					const double cos = Cx[k] * (in_c[0]*in_c[3] + in_c[1]*in_c[4]) + Cz[k]*in_c[2]*in_c[5];

					if(cos > 0.0)
					{
						z[k] += std::pow(cos, n[k]) ;

					}
				}
				f << in_r[0] << "\t" << in_r[1] << "\t" << z[0] << "\t " << z[1] << "\t" << z[2] << std::endl ;
			}
		}
	}
246 247 248

	return 0 ;
}