Mise à jour terminée. Pour connaître les apports de la version 13.8.4 par rapport à notre ancienne version vous pouvez lire les "Release Notes" suivantes :
https://about.gitlab.com/releases/2021/02/11/security-release-gitlab-13-8-4-released/
https://about.gitlab.com/releases/2021/02/05/gitlab-13-8-3-released/

params.cpp 8.15 KB
Newer Older
1 2
#include "params.h"

3 4 5 6 7 8 9 10 11 12
struct param_info
{
	param_info(std::string n, int d, std::string i) : 
		name(n), dimension(d), info(i) { };

	std::string name;
	int dimension;
	std::string info;
};

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
#ifdef WIN32
std::map<params::input, const param_info> create_map()
{
	std::map<params::input, const param_info> _map;
	/* 1D Params */
	_map.insert(std::make_pair<params::input, const param_info>(params::COS_TH, param_info("COS_TH", 1, "Cosine of the Half angle")));
	
	/* 2D Params */
	_map.insert(std::make_pair<params::input, const param_info>(params::RUSIN_TH_TD, param_info("RUSIN_TH_TD", 2, "Radialy symmetric Half angle parametrization")));
	
	/* 3D Params */
	_map.insert(std::make_pair<params::input, const param_info>(params::RUSIN_TH_TD_PD, param_info("RUSIN_TH_TD_PD", 3, "Isotropic Half angle parametrization")));
	_map.insert(std::make_pair<params::input, const param_info>(params::ISOTROPIC_TV_TL_DPHI, param_info("ISOTROPIC_TV_TL_DPHI", 3, "Isotropic Light/View angle parametrization")));
	
	/* 4D Params */
	_map.insert(std::make_pair<params::input, const param_info>(params::RUSIN_TH_PH_TD_PD, param_info("RUSIN_TH_PH_TD_PD", 4, "Complete Half angle parametrization")));
	_map.insert(std::make_pair<params::input, const param_info>(params::SPHERICAL_TL_PL_TV_PV, param_info("SPHERICAL_TL_PL_TV_PV", 4, "Complete classical parametrization")));

	/* 6D Param */
	_map.insert(std::make_pair<params::input, const param_info>(params::CARTESIAN, param_info("CARTESIAN", 6, "Complete vector parametrization")));

	return _map;
}
static const std::map<params::input, const param_info> input_map = create_map();
#else

39
// Assing the input params map
40
static const std::map<params::input, const param_info> input_map = {
41
	/* 1D Params */
42
	{params::COS_TH,                {"COS_TH",                1, "Cosine of the Half angle"}},
43 44

	/* 2D Params */
45
	{params::RUSIN_TH_TD,           {"RUSIN_TH_TD",           2, "Radialy symmetric Half angle parametrization"}},
46 47

	/* 3D Params */
48
	{params::RUSIN_TH_TD_PD,        {"RUSIN_TH_TD_PD",        3, "Isotropic Half angle parametrization"}},
49 50 51
	{params::ISOTROPIC_TV_TL_DPHI,  {"ISOTROPIC_TV_TL_DPHI",  3, "Isotropic Light/View angle parametrization"}},
	
	/* 4D Params */
52 53
	{params::RUSIN_TH_PH_TD_PD,     {"RUSIN_TH_PH_TD_PD",     4, "Complete Half angle parametrization"}},
	{params::SPHERICAL_TL_PL_TV_PV, {"SPHERICAL_TL_PL_TV_PV", 4, "Complete classical parametrization"}},
54 55

	/* 6D Params */
56
	{params::CARTESIAN,             {"CARTESIAN",             6, "Complete vector parametrization"}}
57
};
58
#endif
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
void params::to_cartesian(const double* invec, params::input intype,
		double* outvec)
{
	switch(intype)
	{
		// 1D Parametrizations
		case params::COS_TH:
#ifndef USE_HALF
			half_to_cartesian(acos(invec[0]), 0.0, 0.0, 0.0, outvec);
#else
			outvec[0] = sqrt(1.0 - invec[0]*invec[0]);
			outvec[1] = 0;
			outvec[2] = invec[0];							
			outvec[3] = sqrt(1.0 - invec[0]*invec[0]);
			outvec[4] = 0;
			outvec[5] = invec[0];							
#endif
			break;

			// 2D Parametrizations
		case params::COS_TH_TD:
			half_to_cartesian(acos(invec[0]), 0.0, acos(invec[1]), 0.0, outvec);
			break;

		case params::RUSIN_TH_TD:
85
            half_to_cartesian(invec[0], 0.0, invec[1], 0.0, outvec);
86 87 88 89 90 91 92 93
			break;

			// 3D Parametrization
		case params::RUSIN_TH_PH_TD:
			half_to_cartesian(invec[0], invec[1], invec[2], 0.0, outvec);
			break;
		case params::RUSIN_TH_TD_PD:
			half_to_cartesian(invec[0], 0.0, invec[1], invec[2], outvec);
Laurent Belcour's avatar
Laurent Belcour committed
94 95 96
#ifdef DEBUG
			std::cout << outvec[2] << std::endl;
#endif
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
			break;
		case params::ISOTROPIC_TV_TL_DPHI:
			classical_to_cartesian(invec[0], 0.0, invec[1], invec[2], outvec);
			break;

			// 4D Parametrization
		case params::RUSIN_TH_PH_TD_PD:
			half_to_cartesian(invec[0], invec[1], invec[2], invec[3], outvec);
			break;

		case params::SPHERICAL_TL_PL_TV_PV:
			outvec[0] = cos(invec[1])*sin(invec[0]);
			outvec[1] = sin(invec[1])*sin(invec[0]);
			outvec[2] = cos(invec[0]);
			outvec[3] = cos(invec[3])*sin(invec[2]);
			outvec[4] = sin(invec[3])*sin(invec[2]);
			outvec[5] = cos(invec[2]);
			break;

			// 6D Parametrization
		case params::CARTESIAN:
			memcpy(outvec, invec, 6*sizeof(double));
			break;

		default:
122 123
			std::cerr << "<<ERROR>> Transformation not implemented, " << get_name(intype) << " " << __FILE__ << ":" << __LINE__ << std::endl;
			throw;
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
			break;
	}

}

void params::from_cartesian(const double* invec, params::input outtype,
		double* outvec)
{
	// Compute the half vector
	double half[3] ;
	half[0] = invec[0] + invec[3];
	half[1] = invec[1] + invec[4];
	half[2] = invec[2] + invec[5];
	double half_norm = sqrt(half[0]*half[0] + half[1]*half[1] + half[2]*half[2]);
	half[0] /= half_norm;
	half[1] /= half_norm;
	half[2] /= half_norm;

	// Difference vector 
	double diff[3];

	switch(outtype)
	{
		// 1D Parametrizations
		case params::COS_TH:
			outvec[0] = half[2];
			break;

			// 2D Parametrizations
		case params::COS_TH_TD:
			outvec[0] = half[2];
155
			outvec[1] = half[0]*invec[0] + half[1]*invec[1] + half[2]*invec[2];
156 157 158
			break;
		case params::RUSIN_TH_TD:
			outvec[0] = acos(half[2]);
159
			outvec[2] = acos(half[0]*invec[0] + half[1]*invec[1] + half[2]*invec[2]);
160 161 162 163 164
			break;

			// 3D Parametrization
		case params::RUSIN_TH_PH_TD:
			outvec[0] = acos(half[2]);
165
            outvec[1] = atan2(half[1], half[0]);
166
			outvec[2] = acos(half[0]*invec[0] + half[1]*invec[1] + half[2]*invec[2]);
167
			break;
168 169 170 171 172 173 174 175
        case params::RUSIN_TH_TD_PD:
            outvec[0] = acos(half[2]);

            // Compute the diff vector
            diff[0] = invec[0];
            diff[1] = invec[1];
            diff[2] = invec[2];

176 177 178 179 180 181 182 183 184
            rotate_normal(diff, -atan2(half[1], half[0]));
#ifdef DEBUG
				std::cout << "diff* = [ " << diff[0] << ", " << diff[1] << ", " << diff[2] << "]" << std::endl;
#endif
            rotate_binormal(diff, -outvec[0]);
#ifdef DEBUG
				std::cout << "half  = [ " << half[0] << ", " << half[1] << ", " << half[2] << "]" << std::endl;
				std::cout << "diff  = [ " << diff[0] << ", " << diff[1] << ", " << diff[2] << "]" << std::endl;
#endif
185
            outvec[1] = acos(diff[2]);
186
            outvec[2] = atan2(diff[1], diff[0]);
187
            break;
188 189
		case params::ISOTROPIC_TV_TL_DPHI:
			outvec[0] = acos(invec[2]);
190 191
			outvec[1] = acos(invec[5]);
			outvec[2] = atan2(invec[1], invec[0]) - atan2(invec[4], invec[3]);
192 193 194 195 196 197 198 199 200 201 202 203
			break;

			// 4D Parametrization
		case params::RUSIN_TH_PH_TD_PD:
			outvec[0] = acos(half[2]);
			outvec[1] = atan2(half[0], half[1]);

			// Compute the diff vector
			diff[0] = invec[0];
			diff[1] = invec[1];
			diff[2] = invec[2];
			rotate_binormal(diff, -outvec[0]);
204
            rotate_normal(diff, -outvec[1]);
205 206 207 208 209 210 211

			outvec[2] = acos(diff[2]);
			outvec[3] = atan2(diff[0], diff[1]);
			break;

		case params::SPHERICAL_TL_PL_TV_PV:
			outvec[0] = acos(invec[2]);
212
			outvec[1] = atan2(invec[1], invec[0]);
213
			outvec[2] = acos(invec[5]);
214
			outvec[3] = atan2(invec[4], invec[3]);
Laurent Belcour's avatar
Laurent Belcour committed
215 216 217
#ifdef DEBUG
			std::cout << invec[2] << " - acos -> " << outvec[0] << std::endl;
#endif
218 219 220 221 222 223 224 225
			break;

			// 6D Parametrization
		case params::CARTESIAN:
			memcpy(outvec, invec, 6*sizeof(double));
			break;

		default:
226
			std::cerr << "<<ERROR>> Transformation not implemented, " << get_name(outtype) << " " << __FILE__ << ":" << __LINE__ << std::endl;
227 228 229 230
			assert(false);
			break;
	}
}
231 232 233 234 235 236 237 238 239 240
params::input params::parse_input(const std::string& txt)
{
	for(std::map<params::input, const param_info>::const_iterator it=input_map.begin(); it != input_map.end(); ++it)
	{
		if(txt.compare(it->second.name) == 0)
		{
			return it->first;
		}
	}

241
	std::cout << "<<INFO>> the input parametrization is UNKNOWN_INPUT" << std::endl;
242 243 244 245 246 247 248 249 250 251 252
	return params::UNKNOWN_INPUT;
}
		  
std::string params::get_name(const params::input param)
{
	std::map<params::input, const param_info>::const_iterator it = input_map.find(param);
	if(it != input_map.end())
	{
		return it->second.name;
	}

253
	return std::string("UNKNOWN_INPUT");
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
}

int  params::dimension(params::input t)
{
	std::map<params::input, const param_info>::const_iterator it = input_map.find(t);
	if(it != input_map.end())
	{
		return it->second.dimension;
	}
	else
	{
		return -1;
	}
}

void params::print_input_params()
{
	for(std::map<params::input, const param_info>::const_iterator it=input_map.begin(); it != input_map.end(); ++it)
	{
		std::cout << it->second.name << std::endl;
	}
}