Attention une mise à jour du serveur va être effectuée le vendredi 16 avril entre 12h et 12h30. Cette mise à jour va générer une interruption du service de quelques minutes.

params.cpp 5.56 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
// Assing the input params map
14
static const std::map<params::input, const param_info> input_map = {
15
	/* 1D Params */
16
	{params::COS_TH,                {"COS_TH",                1, "Cosine of the Half angle"}},
17 18

	/* 2D Params */
19
	{params::RUSIN_TH_TD,           {"RUSIN_TH_TD",           2, "Radialy symmetric Half angle parametrization"}},
20 21

	/* 3D Params */
22
	{params::RUSIN_TH_TD_PD,        {"RUSIN_TH_TD_PD",        3, "Isotropic Half angle parametrization"}},
23 24 25
	{params::ISOTROPIC_TV_TL_DPHI,  {"ISOTROPIC_TV_TL_DPHI",  3, "Isotropic Light/View angle parametrization"}},
	
	/* 4D Params */
26 27
	{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"}},
28 29

	/* 6D Params */
30
	{params::CARTESIAN,             {"CARTESIAN",             6, "Complete vector parametrization"}}
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 176
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:
			half_to_cartesian(invec[0], 0.0, invec[1], 0.0, outvec);
			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);
			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:
			throw("Transformation not implemented, params::to_cartesian");
			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];
			outvec[1] = half[0]*outvec[0] + half[1]*outvec[1] + half[2]*outvec[2];
			break;
		case params::RUSIN_TH_TD:
			outvec[0] = acos(half[2]);
			outvec[2] = acos(half[0]*outvec[0] + half[1]*outvec[1] + half[2]*outvec[2]);
			break;

			// 3D Parametrization
		case params::RUSIN_TH_PH_TD:
			outvec[0] = acos(half[2]);
			outvec[1] = atan2(half[0], half[1]);
			outvec[2] = acos(half[0]*outvec[0] + half[1]*outvec[1] + half[2]*outvec[2]);
			break;
		case params::ISOTROPIC_TV_TL_DPHI:
			outvec[0] = acos(invec[2]);
			outvec[1] = 0.0;
			outvec[2] = acos(invec[5]);
			outvec[3] = atan2(invec[1], invec[0]) - atan2(invec[4], invec[3]);
			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_normal(diff, -outvec[1]);
			rotate_binormal(diff, -outvec[0]);

			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]);
			outvec[1] = atan2(invec[0], invec[1]);
			outvec[2] = acos(invec[5]);
			outvec[3] = atan2(invec[3], invec[4]);
			break;

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

		default:
			assert(false);
			break;
	}
}
177 178 179 180 181 182 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 208 209 210 211 212 213 214 215 216 217 218 219 220
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;
		}
	}

	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;
	}

	return std::string();
}

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;
	}
}