56 fD.
func = function_name;
68 fD.
func = function_name;
85 *x_src = x_dest + params.
var1;
86 while( *x_src < -params.
var0 )
87 *x_src += 2 * params.
var0;
88 while( *x_src > params.
var0 )
89 *x_src -= 2 * params.
var0;
98 double rs, rd, f, scale;
101 rd = (sqrt( x_dest*x_dest + y_dest*y_dest )) / params.
var4;
104 f = (((params.
var3 * rs + params.
var2) * rs + params.
var1) * rs + params.
var0) * rs;
108 rs = rs - (f - rd) / ((( 4 * params.
var3 * rs + 3 * params.
var2) * rs +
109 2 * params.
var1) * rs + params.
var0);
111 f = (((params.
var3 * rs + params.
var2) * rs +
112 params.
var1) * rs + params.
var0) * rs;
118 *x_src = x_dest * scale ;
119 *y_src = y_dest * scale ;
150 void resize(
double x_dest,
double y_dest,
double* x_src,
double* y_src,
const _FuncParams & params)
153 *x_src = x_dest * params.
var0;
154 *y_src = y_dest * params.
var1;
168 void horiz(
double x_dest,
double y_dest,
double* x_src,
double* y_src,
const _FuncParams & params)
171 *x_src = x_dest + params.
shift;
176 void vert(
double x_dest,
double y_dest,
double* x_src,
double* y_src,
const _FuncParams & params)
180 *y_src = y_dest + params.
shift;
184 void radial(
double x_dest,
double y_dest,
double* x_src,
double* y_src,
const _FuncParams & params)
189 r = (sqrt( x_dest*x_dest + y_dest*y_dest )) / params.
var4;
190 if( r < params.
var5 )
192 scale = ((params.
var3 * r + params.
var2) * r + params.
var1) * r + params.
var0;
197 *x_src = x_dest * scale ;
198 *y_src = y_dest * scale ;
243 r = sqrt( x_dest * x_dest + y_dest * y_dest );
248 s = sin( theta ) / r;
256 r = sqrt( v2.
x*v2.
x + v2.
y*v2.
y );
260 theta = params.
distance * atan2( r, v2.
z ) / r;
261 *x_src = theta * v2.
x;
262 *y_src = theta * v2.
y;
271 v.
x = x_dest + params.
var2;
272 v.
y = y_dest + params.
var3;
275 *x_src = v.
x * params.
var1 / v.
z;
276 *y_src = v.
y * params.
var1 / v.
z;
304 theta = - y_dest / params.
distance +
PI / 2.0;
312 theta =
PI - (theta -
PI);
316 *x_src = params.
distance * tan(phi);
317 *y_src = params.
distance / (tan( theta ) * cos(phi));
369 double phi, theta, r,s;
380 theta =
PI - (theta -
PI);
384 v[0] = s * sin( phi );
386 r = sqrt( v[1]*v[1] + v[0]*v[0]);
387 theta = params.
distance * atan2( r , s * cos( phi ) );
389 *x_src = theta * v[0] / r;
390 *y_src = theta * v[1] / r;
411 r = sqrt( x_dest*x_dest + y_dest*y_dest );
414 if( theta >=
PI /2.0 )
416 else if( theta == 0.0 )
419 rho = tan( theta ) / theta;
420 *x_src = rho * x_dest ;
421 *y_src = rho * y_dest ;
429 r = sqrt(x_dest*x_dest + y_dest*y_dest) / params.
distance;
433 theta = atan( r ) / r;
434 *x_src = theta * x_dest ;
435 *y_src = theta * y_dest ;
442 double r, s, Phi, theta;
445 r = sqrt( s*s + y_dest*y_dest );
448 *y_src = theta * y_dest ;
457 r = sqrt( x_dest * x_dest + y_dest * y_dest );
465 *x_src = params.
distance * atan2( v[1], v[0] );
466 *y_src = params.
distance * s * y_dest / sqrt( v[0]*v[0] + v[1]*v[1] );
496 r = sqrt( x_dest * x_dest + y_dest * y_dest );
506 *x_src = params.
distance * atan2( v[1], v[0] );
507 *y_src = params.
distance * atan( s * y_dest /sqrt( v[0]*v[0] + v[1]*v[1] ) );
533 double B = cos(y_dest)*sin(x_dest);
535 *y_src = params.
distance * atan(tan(y_dest)/cos(x_dest));
544 *x_src = params.
distance * atan(sinh(x_dest)/cos(y_dest));
545 *y_src = params.
distance * asin(sin(y_dest)/cosh(x_dest));
563 *x_src = x_dest/cos(y_dest/params.
distance);
570 double lon = x_dest / params.
distance;
571 double lat = y_dest / params.
distance;
574 double k=2.0/(1+cos(lat)*cos(lon));
575 *x_src = params.
distance * k*cos(lat)*sin(lon);
576 *y_src = params.
distance * k*sin(lat);
585 double p=sqrt(x_dest*x_dest + y_dest*y_dest) / params.
distance;
586 double c= 2.0*atan(p/2.0);
803 static void cubeZero_copy(
double *a,
int *n,
double *root );
812 double p = ((-1.0/3.0) * (a[2]/a[3]) * (a[2]/a[3]) + a[1]/a[3]) / 3.0;
813 double q = ((2.0/27.0) * (a[2]/a[3]) * (a[2]/a[3]) * (a[2]/a[3]) - (1.0/3.0) * (a[2]/a[3]) * (a[1]/a[3]) + a[0]/a[3]) / 2.0;
815 if( q*q + p*p*p >= 0.0 ){
819 double phi = acos( -q / sqrt(-p*p*p) );
821 root[0] = 2.0 * sqrt(-p) * cos(phi/3.0) - a[2] / (3.0 * a[3]);
822 root[1] = -2.0 * sqrt(-p) * cos(phi/3.0 +
PI/3.0) - a[2] / (3.0 * a[3]);
823 root[2] = -2.0 * sqrt(-p) * cos(phi/3.0 -
PI/3.0) - a[2] / (3.0 * a[3]);
833 *n = 1; root[0] = 0.0;
838 *n = 1; root[0] = - a[0] / a[1];
841 if( 4.0 * a[2] * a[0] > a[1] * a[1] ){
845 root[0] = (- a[1] + sqrt( a[1] * a[1] - 4.0 * a[2] * a[0] )) / (2.0 * a[2]);
846 root[1] = (- a[1] - sqrt( a[1] * a[1] - 4.0 * a[2] * a[0] )) / (2.0 * a[2]);
856 return pow(x, 1.0/3.0);
858 return -
pow(-x, 1.0/3.0);
863 double root[3], sroot = 1000.0;
869 if(root[i] > 0.0 && root[i] < sroot)
887 if( coeff[k] != 0.0 )
889 a[k] = (k+1) * coeff[k];
901 r = (sqrt( x_dest*x_dest + y_dest*y_dest )) / params.
var4;
902 if( r < params.
var5 )
904 scale = ((params.
var3 * r + params.
var2) * r + params.
var1) * r + params.
var0;
909 *x_src = x_dest * scale + params.
var6;
910 *y_src = y_dest * scale + params.
var7;
928 return ( (mz * mx) * my );
930 return ( (mx * mz) * my );
944 vigra::Rect2D inside;
945 vigra::Rect2D insideTemp;
946 vigra::Rect2D boundingBox;
951 inside &= insideTemp;
954 inside &= insideTemp;
956 double width2 = src.getSize().x/2.0;
957 double height2 = src.getSize().y/2.0;
958 double sx =
std::max(width2/(width2-inside.left()), width2/(inside.right()-width2));
959 double sy =
std::max(height2/(height2-inside.top()), height2/(inside.bottom()-height2));
981 p = (double)(width) / (double)(height);
983 p = (double)(height) / (double)(width);
988 r_test[0] = sqrt(1 + p * p);
999 r = (-b + sqrt(b * b - 3 * a * c)) / (3 * a);
1000 if (r >= 1 && r <= r_test[0])
1002 r_test[test_points] = r;
1003 test_points = test_points + 1;
1005 r = (-b - sqrt(b * b - 3 * a * c)) / (3 * a);
1006 if (r >= 1 && r <= r_test[0])
1008 r_test[test_points] = r;
1009 test_points = test_points + 1;
1017 if (a == 0.0 && b != 0.0)
1020 if (r >= 1 && r <= r_test[0])
1022 r_test[test_points] = r;
1023 test_points = test_points + 1;
1029 double scalefactor = 0.1;
1030 for (i = 0; i <= test_points - 1; i++)
1033 double scale = d + r * (c + r * (b + r * a));
1034 if ( scalefactor < scale)
1035 scalefactor = scale;
1061 for (
int i=0; i < 4; i++) {
1062 mprad[3-i] = radDist[i];
1064 mprad[4] = ( sz.x < sz.y ? sz.x: sz.y) / 2.0;
1069 if ( mprad[0] != 1.0 || mprad[1] != 0.0 || mprad[2] != 0.0 || mprad[3] != 0.0) {
1071 centerShift.
x, centerShift.
y);
1084 m_srcTX = src.getSize().x/2.0;
1085 m_srcTY = src.getSize().y/2.0;
1089 if (src.getRadialDistortionCenterShift().x != 0.0) {
1094 if (src.getRadialDistortionCenterShift().y != 0.0) {
1098 if (src.
getCorrectTCA() && (channel == 0 || channel == 2)) {
1099 for (
int i=0; i < 4; i++) {
1102 mprad[3-i] = src.getRadialDistortionRed()[i];
1105 mprad[3-i] = src.getRadialDistortionBlue()[i];
1108 mprad[4] = ( src.getSize().x < src.getSize().y ? src.getSize().x: src.getSize().y) / 2.0;
1113 if ( mprad[0] != 1.0 || mprad[1] != 0.0 || mprad[2] != 0.0 || mprad[3] != 0.0) {
1119 for (
int i=0; i < 4; i++) {
1120 mprad[3-i] = src.getRadialDistortion()[i];
1122 mprad[4] = ( src.getSize().x < src.getSize().y ? src.getSize().x: src.getSize().y) / 2.0;
1127 if ( mprad[0] != 1.0 || mprad[1] != 0.0 || mprad[2] != 0.0 || mprad[3] != 0.0) {
1142 m_srcTX = src.getSize().x/2.0;
1143 m_srcTY = src.getSize().y/2.0;
1148 for (
int i=0; i < 4; i++) {
1149 mprad[3-i] = src.getRadialDistortion()[i];
1151 mprad[4] = ( src.getSize().x < src.getSize().y ? src.getSize().x: src.getSize().y) / 2.0;
1156 if ( mprad[0] != 1.0 || mprad[1] != 0.0 || mprad[2] != 0.0 || mprad[3] != 0.0) {
1159 <<
"g: " << mprad[0] <<
" " << mprad[1] <<
" " << mprad[2]
1160 <<
" " << mprad[3] <<
" " << mprad[4] <<
" " << mprad[5]);
1163 if (src.
getCorrectTCA() && (channel == 0 || channel == 2)) {
1164 for (
int i=0; i < 4; i++) {
1167 mprad[3-i] = src.getRadialDistortionRed()[i];
1170 mprad[3-i] = src.getRadialDistortionBlue()[i];
1173 mprad[4] = ( src.getSize().x < src.getSize().y ? src.getSize().x: src.getSize().y) / 2.0;
1178 if ( mprad[0] != 1.0 || mprad[1] != 0.0 || mprad[2] != 0.0 || mprad[3] != 0.0) {
1180 DEBUG_DEBUG(
"Init Radial (channel " << channel <<
"): "
1181 <<
"g: " << mprad[0] <<
" " << mprad[1] <<
" " << mprad[2]
1182 <<
" " << mprad[3] <<
" " << mprad[4] <<
" " << mprad[5]);
1187 if (src.getRadialDistortionCenterShift().y != 0.0) {
1190 if (src.getRadialDistortionCenterShift().x != 0.0) {
1200 const vigra::Diff2D &destSize,
1207 double mpdistance, mpscale[2], mprot[2], mprad[6];
1209 double mphorizontal, mpvertical;
1211 double imhfov = image.getHFOV();
1212 vigra::Size2D srcSize = image.getSize();
1213 double imwidth = srcSize.x;
1214 double imheight= srcSize.y;
1215 double imyaw = image.getYaw();
1216 double impitch = image.getPitch();
1217 double imroll = image.getRoll();
1218 double ima = image.getRadialDistortion()[0];
1219 double imb = image.getRadialDistortion()[1];
1220 double imc = image.getRadialDistortion()[2];
1221 double imd = image.getRadialDistortionCenterShift().x;
1222 double ime = image.getRadialDistortionCenterShift().y;
1223 double img = image.getShear().x;
1224 double imt = image.getShear().y;
1225 double pnhfov = destHFOV;
1226 double pnwidth = destSize.x;
1246 mpdistance = pnwidth / (2.0 * tan(b/2.0));
1249 mpscale[0] = (pnhfov / imhfov) * (a /(2.0 * tan(a/2.0))) * (imwidth/pnwidth) * 2.0 * tan(b/2.0) / b;
1254 mpscale[0] = (pnhfov / imhfov) * (imwidth/pnwidth) * 2.0 * tan(b/2.0) / b;
1259 mpdistance = pnwidth / b;
1262 mpscale[0] = (pnhfov / imhfov) * (a /(2.0 * tan(a/2.0)))*( imwidth / pnwidth );
1266 mpscale[0] = (pnhfov / imhfov) * ( imwidth / pnwidth );
1269 mpscale[1] = mpscale[0];
1272 mprot[0] = mpdistance *
PI;
1273 mprot[1] = -imyaw * mpdistance * PI / 180.0;
1279 mprad[0] = 1.0 - (ima+imb+imc);
1280 mprad[4] = ( imwidth < imheight ? imwidth : imheight) / 2.0;
1335 DEBUG_FATAL(
"Fatal error: Unknown projection " << destProj);
1371 if ( mprad[1] != 0.0 || mprad[2] != 0.0 || mprad[3] != 0.0) {
1376 if (mpvertical != 0.0) {
1379 if (mphorizontal != 0.0) {
1411 const vigra::Diff2D &destSize,
1417 double mpdistance, mpscale[2], mprot[2], mprad[6];
1419 double mphorizontal, mpvertical;
1421 double imhfov = image.getHFOV();
1422 vigra::Size2D srcSize = image.getSize();
1423 double imwidth = srcSize.x;
1424 double imheight= srcSize.y;
1425 double imyaw = image.getYaw();
1426 double impitch = image.getPitch();
1427 double imroll = image.getRoll();
1428 double ima = image.getRadialDistortion()[0];
1429 double imb = image.getRadialDistortion()[1];
1430 double imc = image.getRadialDistortion()[2];
1431 double imd = image.getRadialDistortionCenterShift().x;
1432 double ime = image.getRadialDistortionCenterShift().y;
1435 double pnhfov = destHFOV;
1436 double pnwidth = destSize.x;
1456 mpdistance = pnwidth / (2.0 * tan(b/2.0));
1459 mpscale[0] = ( pnhfov/imhfov ) * (a /(2.0 * tan(a/2.0))) * ( imwidth/pnwidth ) * 2.0 * tan(b/2.0) / b;
1463 mpscale[0] = ( pnhfov/imhfov ) * ( imwidth/pnwidth ) * 2.0 * tan(b/2.0) / b;
1468 mpdistance = pnwidth / b;
1471 mpscale[0] = ( pnhfov/imhfov ) * (a /(2.0 * tan(a/2.0))) * ( imwidth/pnwidth );
1475 mpscale[0] = ( pnhfov/imhfov ) * ( imwidth/pnwidth );
1481 mpscale[0] = 1.0 / mpscale[0];
1482 mpscale[1] = mpscale[0];
1485 mphorizontal = - imd;
1492 mprad[0] = 1.0 - (ima+imb+imc);
1493 mprad[4] = ( imwidth < imheight ? imwidth : imheight) / 2.0;
1512 mprot[0] = mpdistance *
PI;
1513 mprot[1] = imyaw * mpdistance * PI / 180.0;
1526 if (mphorizontal != 0.0) {
1529 if (mpvertical != 0.0) {
1534 if ( mprad[1] != 0.0 || mprad[2] != 0.0 || mprad[3] != 0.0) {
1600 DEBUG_FATAL(
"Fatal error: Unknown projection " << destProj);
1625 vigra::Diff2D srcSize)
1628 if (srcSize.x == 0 && srcSize.y == 0)
1630 srcSize = img.getSize();
1641 vigra::Diff2D srcSize)
1644 if (srcSize.x == 0 && srcSize.y == 0)
1646 srcSize = img.getSize();
1657 const vigra::Diff2D &destSize,
1662 src_image.
setSize(vigra::Size2D(srcSize.x, srcSize.y));
1664 for (VariableMap::const_iterator i = srcVars.begin(); i != srcVars.end(); ++i)
1666 src_image.
setVar((*i).first, (*i).second.getValue());
1668 Init(src_image, destSize, destProj, destHFOV);
1676 const vigra::Diff2D & destSize,
1682 src_image.
setSize(vigra::Size2D(srcSize.x, srcSize.y));
1684 for (VariableMap::const_iterator i = srcVars.begin(); i != srcVars.end(); ++i)
1686 src_image.
setVar((*i).first, (*i).second.getValue());
1688 InitInv(src_image, destSize, destProj, destHFOV);
1695 double xd = src.
x, yd = src.
y;
1696 std::vector<fDescription>::const_iterator tI;
1702 (tI->func)( xd, yd, &dest.
x, &dest.
y, tI->param );
PanoramaOptions::ProjectionFormat getProjection() const
void stereographic_erect(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
convert from erect to stereographic
void persp_rect(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void sphere_tp_erect(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void sinusoidal_erect(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
convert from erect to sinusoidal
void sphere_tp_pano(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void traceImageOutline(vigra::Size2D sz, TRANSFORM &transf, vigra::Rect2D &inside, vigra::Rect2D &boundingBox)
Internal function to estimate the image scaling required to avoid black stripes at the image borders...
void radial(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void transmercator_erect(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
convert from erect to transverse mercator
unsigned int getHeight() const
get panorama height
general : Matrix3 is a class for handling 3x3 Matrix manipulation.
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
Vector3 TransformVector(const Vector3 &V) const
transforms a vector
void(* trfn)(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
Transformation function type.
#define PI
Header file for Khan's deghosting algorithm Copyright (C) 2009 Lukáš Jirkovský l...
void SetRotationX(double a)
set the matrice to rotation around X
Parameters for transformation calls Can be just one double, two double, 4 double, a matrix...
void erect_stereographic(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
convert from stereographic to erect
Matrix3 SetMatrix(double a, double b, double c, int cl)
static double CalcCorrectionRadius_copy(double *coeff)
void rotate_erect(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
static void radial_shift(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
static void squareZero_copy(double *a, int *n, double *root)
void setVar(const std::string &name, double val)
Function descriptor to be executed by exec_function.
bool getCorrectTCA() const
void erect_sphere_tp(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
float pow(float a, double b)
void pano_erect(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void SetRotationZ(double a)
virtual const SrcPanoImage & getImage(std::size_t nr) const =0
get a panorama image, counting starts with 0
void rect_erect(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 sphere_tp_rect(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void mercator_erect(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
convert from erect to mercator
std::map< std::string, Variable > VariableMap
void pano_sphere_tp(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
void SetRotationY(double a)
vigra::RGBValue< T, RIDX, GIDX, BIDX > log(vigra::RGBValue< T, RIDX, GIDX, BIDX > const &v)
component-wise logarithm
unsigned int getWidth() const
void transpano_erect(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
static double cubeRoot_copy(double x)
void setSize(vigra::Size2D val)
Set the image size in pixels.
double estRadialScaleCrop(const std::vector< double > &coeff, int width, int height)
Calculate effective scaling factor.
double estScaleFactorForFullFrame(const SrcPanoImage &src)
Calculate effective scaling factor for a given source image.
void erect_transpano(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)
general : Vector3 is a class for handling 3D Vectors manipulation.
ProjectionFormat
Projection of final panorama.
void erect_pano(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
double x
x,y,z coordinates, 0 at the initialisation
All variables of a source image.
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
static void cubeZero_copy(double *a, int *n, double *root)
static double smallestRoot_copy(double *p)
void inv_radial(double x_dest, double y_dest, double *x_src, double *y_src, const _FuncParams ¶ms)
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