27 #include <hugin_config.h>
36 using std::ostringstream;
39 #define distanceparam (*((double*)params))
40 #define shift (*((double*)params))
41 #define var0 ((double*)params)[0]
42 #define var1 ((double*)params)[1]
43 #define var2 ((double*)params)[2]
44 #define var3 ((double*)params)[3]
45 #define var4 ((double*)params)[4]
46 #define var5 ((double*)params)[5]
47 #define mp ((struct MakeParams*)params)
51 #define DISCARD "{ discardA = 0.0; discardB = 1.0; }"
61 oss <<
" // rotate_erect(" <<
var0 <<
", " <<
var1 <<
")" << endl
63 <<
" " << ((
var1 == 0.0) ?
"//" :
"") <<
"src.s += " << var1 <<
";" << endl
64 <<
" float w = (abs(src.s) > " <<
var0 <<
") ? 1.0 : 0.0;" << endl
65 <<
" float n = (src.s < 0.0) ? 0.5 : -0.5;" << endl
66 <<
" src.s += w * " << (-2.0 *
var0) <<
" * ceil(src.s / " << (2.0 *
var0) <<
" + n);" << endl
71 static void resize_glsl(ostringstream& oss,
const void* params) {
72 oss <<
" // resize(" <<
var0 <<
", " <<
var1 <<
")" << endl
73 <<
" src *= vec2(" <<
var0 <<
", " <<
var1 <<
");" << endl
77 static void vert_glsl(ostringstream& oss,
const void* params) {
78 oss <<
" // vert(" <<
shift <<
")" << endl
79 <<
" src.t += " <<
shift <<
";" << endl
83 static void horiz_glsl(ostringstream& oss,
const void* params) {
84 oss <<
" // horiz(" <<
shift <<
")" << endl
85 <<
" src.s += " <<
shift <<
";" << endl
89 static void shear_glsl(ostringstream& oss,
const void* params) {
90 oss <<
" // shear(" <<
var0 <<
", " <<
var1 <<
")" << endl
91 <<
" src += (src.ts * vec2(" <<
var0 <<
", " <<
var1 <<
"));" << endl
109 oss <<
" // erect_sphere_tp(" <<
distanceparam <<
")" << endl
111 <<
" float r = length(src);" << endl
114 <<
" if (theta != 0.0) { s = sin(theta) / r; }" << endl
115 <<
" float v1 = s * src.s;" << endl
116 <<
" float v0 = cos(theta);" << endl
117 <<
" src.s = " <<
distanceparam <<
" * atan2_safe(v1, v0);" << endl
118 <<
" src.t = " <<
distanceparam <<
" * atan_safe(s * src.t / length(vec2(v0, v1)));" << endl
124 oss <<
" // sphere_tp_erect(" <<
distanceparam <<
")" << endl
127 <<
" float theta = -src.t / " <<
distanceparam <<
" + " << (
M_PI/2) <<
";" << endl
128 <<
" if (theta < 0.0) {" << endl
129 <<
" theta = -theta;" << endl
130 <<
" phi += " <<
M_PI <<
";" << endl
132 <<
" if (theta > " <<
M_PI <<
") {" << endl
133 <<
" theta = " <<
M_PI <<
" - (theta - " <<
M_PI <<
");" << endl
134 <<
" phi += " <<
M_PI <<
";" << endl
136 <<
" float s = sin(theta);" << endl
137 <<
" vec2 v = vec2(s * sin(phi), cos(theta));" << endl
138 <<
" float r = length(v);" << endl
139 <<
" theta = " <<
distanceparam <<
" * atan2_safe(r, s * cos(phi));" << endl
140 <<
" src = v * (theta / r);" << endl
146 oss <<
" // vertical(" <<
var0 <<
", " <<
var1 <<
", " <<
var2 <<
", " <<
var3 <<
", " <<
var4 <<
")" << endl
148 <<
" float r = abs(src.t / " <<
var4 <<
");" << endl
149 <<
" float scale = ((" <<
var3 <<
" * r + " <<
var2 <<
") * r + " <<
var1 <<
") * r + " <<
var0 <<
";" << endl
150 <<
" src.t *= scale;" << endl
156 oss <<
" // deregister(" <<
var1 <<
", " <<
var2 <<
", " <<
var3 <<
", " <<
var4 <<
")" << endl
158 <<
" float r = abs(src.t / " <<
var4 <<
");" << endl
159 <<
" float scale = (" <<
var3 <<
" * r + " <<
var2 <<
") * r + " <<
var1 <<
";" << endl
160 <<
" src.s += abs(src.t) * scale;" << endl
166 oss <<
" // radial(" <<
var0 <<
", " <<
var1 <<
", " <<
var2 <<
", " <<
var3 <<
", " <<
var4 <<
", " <<
var5 <<
")" << endl
168 <<
" float r = length(src) / " <<
var4 <<
";" << endl
169 <<
" float scale = 1000.0; " << endl
170 <<
" if (r < " <<
var5 <<
") {" << endl
171 <<
" scale = ((" <<
var3 <<
" * r + " <<
var2 <<
") * r + " <<
var1 <<
") * r + " <<
var0 <<
";" << endl
173 <<
" src *= scale;" << endl
181 <<
" float r = length(src);" << endl
184 <<
" if (theta != 0.0) s = sin(theta) / r;" << endl
185 <<
" vec2 v = vec2(cos(theta), s * src.s);" << endl
186 <<
" src.s = " <<
distanceparam <<
" * atan2_safe(v.t, v.s);" << endl
187 <<
" src.t = " <<
distanceparam <<
" * s * src.t / length(v);" << endl
195 <<
" float r = length(src);" << endl
197 <<
" float rho = 0.0;" << endl
198 <<
" if (theta >= " << (
M_PI / 2.0) <<
") rho = 1.6e16;" << endl
199 <<
" else if (theta == 0.0) rho = 1.0;" << endl
200 <<
" else rho = tan(theta) / theta;" << endl
201 <<
" src *= rho;" << endl
207 double d = *((
double*) ((
void**)params)[1]);
208 double (*m)[3] = (double(*)[3]) ((
void**)params)[0];
209 oss <<
" // persp_sphere(" << d <<
")" << endl
211 <<
" mat3 m = mat3(" << m[0][0] <<
", " << m[1][0] <<
", " << m[2][0] <<
"," << endl
212 <<
" " << m[0][1] <<
", " << m[1][1] <<
", " << m[2][1] <<
"," << endl
213 <<
" " << m[0][2] <<
", " << m[1][2] <<
", " << m[2][2] <<
");" << endl
214 <<
" float r = length(src);" << endl
215 <<
" float theta = r / " << d <<
";" << endl
216 <<
" float s = 0.0;" << endl
217 <<
" if (r != 0.0) s = sin(theta) / r;" << endl
218 <<
" vec3 v = vec3(s * src.s, s * src.t, cos(theta));" << endl
219 <<
" vec3 u = v * m;" << endl
220 <<
" r = length(u.st);" << endl
221 <<
" theta = 0.0;" << endl
222 <<
" if (r != 0.0) theta = " << d <<
" * atan2_safe(r, u.p) / r;" << endl
223 <<
" src = theta * u.st;" << endl
235 oss <<
" // erect_millercylindrical(" <<
distanceparam <<
")" << endl
247 oss <<
" // erect_transmercator(" <<
distanceparam <<
")" << endl
250 <<
" if (abs(src.t) > " <<
M_PI <<
") " <<
DISCARD << endl
251 <<
" float x = src.s;" << endl
252 <<
" src.s = " <<
distanceparam <<
" * atan2_safe(sinh(src.s), cos(src.t));" << endl
253 <<
" src.t = " <<
distanceparam <<
" * asin(sin(src.t) / cosh(x));" << endl
259 oss <<
" // erect_sinusoidal(" <<
distanceparam <<
")" << endl
266 oss <<
" // erect_lambertazimuthal(" <<
distanceparam <<
")" << endl
269 <<
" if (any(greaterThan(abs(src), vec2(" <<
M_PI <<
", " <<
M_PI <<
")))) " <<
DISCARD << endl
270 <<
" float ro = length(src);" << endl
271 <<
" if (abs(ro) <= 1.0e-10) src = vec2(0.0, 0.0);" << endl
273 <<
" float c = 2.0 * asin(ro / 2.0);" << endl
274 <<
" src.t = " <<
distanceparam <<
" * asin((src.t * sin(c)) / ro);" << endl
275 <<
" if (abs(ro * cos(c)) <= 1.0e-10) src.s = 0.0;" << endl
276 <<
" else src.s = " <<
distanceparam <<
" * atan2_safe(src.s * sin(c), (ro * cos(c)));" << endl
286 <<
" float z2 = 1.0 - src.s * src.s / 16.0 - src.t * src.t / 4.0;" << endl
287 <<
" if (z2 < 0.0 ) " <<
DISCARD << endl
288 <<
" float z = sqrt(z2);" << endl
289 <<
" src.s = 2.0 * atan2_safe( z * src.s, 2.0*(2.0*z2-1.0));" << endl
290 <<
" src.t = asin (src.t * z);" << endl
291 <<
" if(any(greaterThan(abs(src), vec2(" <<
M_PI <<
"," << HALF_PI <<
"))))" <<
DISCARD << endl
300 <<
" if(src.t < 0.0) {" << endl
302 <<
" } else {" << endl
310 oss <<
" // erect_stereographic(" <<
distanceparam <<
")" << endl
313 <<
" float rh = length(src);" << endl
314 <<
" float c = 2.0 * atan_safe(rh / 2.0);" << endl
315 <<
" float sin_c = sin(c);" << endl
316 <<
" float cos_c = cos(c);" << endl
317 <<
" if (abs(rh) <= 1.0e-10) " <<
DISCARD << endl
318 <<
" src.t = asin((src.t * sin_c) / rh) * " <<
distanceparam <<
";" << endl
319 <<
" if (abs(cos_c) < 1.0e-10 && abs(src.s) < 1.0e-10) " <<
DISCARD << endl
320 <<
" float y = src.s * sin_c;" << endl
321 <<
" float x = cos_c * rh;" << endl
322 <<
" src.s = atan2_safe(y, x) * " <<
distanceparam <<
";" << endl
328 oss <<
" // stereographic_erect(" <<
distanceparam <<
")" << endl
331 <<
" vec2 cos_lon_lat=cos(src);" << endl
332 <<
" float g=cos_lon_lat.s * cos_lon_lat.t;" << endl
333 <<
" src = " <<
distanceparam <<
" * 2.0 / (1.0 + g) * vec2(cos_lon_lat.t * sin(src.s), sin(src.t));" << endl
339 oss <<
" // erect_albersequalareaconic(...)" << endl
344 int result = erect_albersequalareaconic(0.0, 0.0, &junk0, &junk1, const_cast<void*>(params));
346 oss <<
" // albersEqualAreaConic_ParamCheck failed" << endl;
349 const double n =
mp->pn->precomputedValue[3];
350 const double C =
mp->pn->precomputedValue[4];
351 const double rho0 =
mp->pn->precomputedValue[5];
352 const double yoffset =
mp->pn->precomputedValue[6];
353 const double n2 =
mp->pn->precomputedValue[7];
354 const double twiceN =
mp->pn->precomputedValue[9];
356 oss <<
" src /= " <<
mp->distance <<
";" << endl
357 <<
" src.t += " << yoffset <<
";" << endl
358 <<
" float rho2 = (src.s * src.s + (" << rho0 <<
" - src.t) * (" << rho0 <<
" - src.t));" << endl
359 <<
" float theta = atan2_safe(" << ((n < 0) ?
"-" :
"") <<
"src.s, " << ((n < 0) ?
"-1.0 * " :
"") <<
"(" << rho0 <<
" - src.t));" << endl
360 <<
" float phi = asin((" << C <<
" - rho2 * " << n2 <<
") / " << twiceN <<
");" << endl
361 <<
" float lambda = theta / " << n <<
";" << endl
362 <<
" if (abs(lambda) > " <<
M_PI <<
") " <<
DISCARD << endl
363 <<
" src.s = " <<
mp->distance <<
" * lambda;" << endl
364 <<
" src.t = " <<
mp->distance <<
" * phi;" << endl
371 oss <<
" // lambertazimuthal_erect(" <<
distanceparam <<
")" << endl
374 <<
" float a=cos(src.t) * cos(src.s) + 1.0;" << endl
375 <<
" if (abs(a) <= 1e-10) " <<
DISCARD << endl
376 <<
" src = " <<
distanceparam <<
" * sqrt (2.0/a) * vec2 ( cos(src.t) * sin(src.s), sin(src.t));" << endl
382 oss <<
" // sphere_tp_equisolid(" <<
distanceparam <<
")" << endl
384 <<
" float phi = atan2_safe(src.t, src.s);" << endl
385 <<
" src = " <<
distanceparam <<
" * 2.0 * asin( length(src) / (2.0 * " <<
distanceparam <<
")) * vec2 (cos(phi), sin(phi));" << endl
391 oss <<
" // sphere_tp_orthographic(" <<
distanceparam <<
")" << endl
393 <<
" float rho=length(src);" << endl
395 <<
" float phi = atan2_safe(src.t, src.s);" << endl
402 oss <<
" // orthographic_sphere_tp(" <<
distanceparam <<
")" << endl
404 <<
" float theta = length(src) / " <<
distanceparam <<
";" << endl
405 <<
" float phi = atan2_safe(src.t, src.s);" << endl
406 <<
" if ( abs(theta) > " << HALF_PI <<
") " <<
DISCARD << endl
408 <<
" src = " <<
distanceparam <<
" * sin( theta ) * vec2 (cos(phi), sin(phi));" << endl
414 oss <<
" // sphere_tp_thoby(" <<
distanceparam <<
")" << endl
416 <<
" float rho = length(src) / " <<
distanceparam <<
";" << endl
417 <<
" if (abs(rho) > " << THOBY_K1_PARM <<
") " <<
DISCARD << endl
418 <<
" float phi = atan2_safe(src.t, src.s);" << endl
419 <<
" src = " <<
distanceparam <<
" * asin(rho/" << THOBY_K1_PARM <<
") / " << THOBY_K2_PARM <<
" * vec2 (cos(phi), sin(phi));" << endl
425 oss <<
" // thoby_sphere_tp(" <<
distanceparam <<
")" << endl
427 <<
" float theta = length(src) / " <<
distanceparam <<
";" << endl
428 <<
" float phi = atan2_safe(src.t, src.s);" << endl
429 <<
" src = " <<
distanceparam <<
" * " << THOBY_K1_PARM <<
" * sin(theta * " << THOBY_K2_PARM <<
") * vec2 (cos(phi), sin(phi));" << endl
435 oss <<
" // plane_transfer_to_camera" << endl
436 <<
" // distance : " <<
mp->distance << endl
437 <<
" // x : " <<
mp->trans[0] << endl
438 <<
" // y : " <<
mp->trans[1] << endl
439 <<
" // z : " <<
mp->trans[2] << endl
440 <<
" // plane yaw : " <<
mp->trans[3] << endl
441 <<
" // plane pitch: " <<
mp->trans[4] << endl
443 <<
" float phi = src.s / " <<
mp->distance <<
";" << endl
444 <<
" float theta = " << HALF_PI <<
" - src.t / " <<
mp->distance <<
";" << endl
445 <<
" vec3 p = vec3(sin(theta)*sin(phi), cos(theta), sin(theta)*-cos(phi));" << endl
446 <<
" vec3 plane_coeff=vec3(" << sin(HALF_PI+
mp->trans[4])*sin(
mp->trans[3]) <<
", " << cos(HALF_PI+
mp->trans[4]) <<
", " << sin(HALF_PI+
mp->trans[4])*-cos(
mp->trans[3]) <<
");" << endl
447 <<
" float den = -dot(plane_coeff, p);" << endl
448 <<
" if ( abs(den) < 1E-15 ) " <<
DISCARD << endl
449 <<
" float u = length(plane_coeff);" << endl
450 <<
" u = -u * u / den;" << endl
451 <<
" if ( u < 0.0 ) " <<
DISCARD << endl
452 <<
" p *= u;" << endl
453 <<
" p -= vec3(" <<
mp->trans[0] <<
"," <<
mp->trans[1] <<
"," <<
mp->trans[2] <<
");" << endl
454 <<
" src = " <<
mp->distance <<
" * vec2( atan2_safe(p.s, -p.p), asin(p.t/length(p)));" << endl
459 namespace HuginBase {
namespace PTools {
463 oss <<
" vec2 src = gl_TexCoord[0].st;" << endl
467 bool foundUnsupportedFunction =
false;
471 while ( (stack->func) != NULL ) {
476 else if (stack->func == shear)
shear_glsl(oss, stack->param);
481 else if (stack->func == vertical)
vertical_glsl(oss, stack->param);
482 else if (stack->func == deregister)
deregister_glsl(oss, stack->param);
496 else if (stack->func == erect_arch)
erect_arch_glsl(oss, stack->param);
506 oss <<
" // Unknown function " << (
const void*)stack->func << endl << endl;
507 foundUnsupportedFunction =
true;
513 oss <<
" src += vec2(" << (
m_destTX-0.5) <<
", " << (
m_destTY-0.5) <<
");" << endl
516 return !foundUnsupportedFunction;
529 for (
int i = 0; i < 2; ++i) {
530 if ((stack->func) == NULL)
break;
531 if ( (stack->func)(xd, yd, &x_dest, &y_dest, stack->param) ) {
void stereographic_erect(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
convert from erect to stereographic
void sphere_tp_erect(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void radial(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void erect_rect(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void erect_sinusoidal(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
convert from sinusoidal to erect
void erect_stereographic(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
convert from stereographic to erect
void rotate_erect(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void erect_sphere_tp(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void vert(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void pano_sphere_tp(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void resize(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void persp_sphere(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void erect_pano(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void rect_sphere_tp(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void erect_mercator(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
convert from mercator to erect
void horiz(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void erect_transmercator(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
convert from erect to transverse mercator