Commit 0abd52b8 authored by Andrey Filippov's avatar Andrey Filippov

fixing quaternions-affines

parent d9f79276
...@@ -56,6 +56,13 @@ public class OrthoAltitudeMatch { ...@@ -56,6 +56,13 @@ public class OrthoAltitudeMatch {
String orthoMapsCollection_path, String orthoMapsCollection_path,
int debugLevel) { int debugLevel) {
boolean y_down_ccw = true; boolean y_down_ccw = true;
boolean invert_q2a = true;
boolean test_quat = true;
if (test_quat) {
QuatUtils.testQuatAff();
}
int [] indices = orthoMapsCollection.getScenesFromPairs( // may be shorter, each element - absolute scene number used in pairs int [] indices = orthoMapsCollection.getScenesFromPairs( // may be shorter, each element - absolute scene number used in pairs
available_pairs, // pairs_defined_abs,// int [][] pairs, available_pairs, // pairs_defined_abs,// int [][] pairs,
null); // int [] indices_in) // preselected indices or null null); // int [] indices_in) // preselected indices or null
...@@ -197,7 +204,7 @@ public class OrthoAltitudeMatch { ...@@ -197,7 +204,7 @@ public class OrthoAltitudeMatch {
} }
double [] alt_data = {alt_data5[0]/pix_size_meters, alt_data5[1]/pix_size_meters,alt_data5[2]}; double [] alt_data = {alt_data5[0]/pix_size_meters, alt_data5[1]/pix_size_meters,alt_data5[2]};
boolean test_quat = true;
if (test_quat) { if (test_quat) {
System.out.println(">>>>>>>>>>>>>>>>> npair="+npair+": "+ipair[0]+" -> "+ipair[1]); System.out.println(">>>>>>>>>>>>>>>>> npair="+npair+": "+ipair[0]+" -> "+ipair[1]);
boolean use_degrees = true; boolean use_degrees = true;
...@@ -331,6 +338,7 @@ public class OrthoAltitudeMatch { ...@@ -331,6 +338,7 @@ public class OrthoAltitudeMatch {
{A1a.get(1,0),A1a.get(1,1)}}; {A1a.get(1,0),A1a.get(1,1)}};
double [][][] affines = new double [][][] {ortho_maps[ipair[0]].getAffine(),ortho_maps[ipair[1]].getAffine(), affine1a}; double [][][] affines = new double [][][] {ortho_maps[ipair[0]].getAffine(),ortho_maps[ipair[1]].getAffine(), affine1a};
boolean make__pure_tilt = false; boolean make__pure_tilt = false;
/*
double [][] aff1_stretch = QuatUtils.quatToAffine( double [][] aff1_stretch = QuatUtils.quatToAffine(
quats01[0], // double [] quat, quats01[0], // double [] quat,
true, // boolean stretch, true, // boolean stretch,
...@@ -351,6 +359,25 @@ public class OrthoAltitudeMatch { ...@@ -351,6 +359,25 @@ public class OrthoAltitudeMatch {
true, // boolean stretch, true, // boolean stretch,
make__pure_tilt, // boolean make__pure_tilt) make__pure_tilt, // boolean make__pure_tilt)
y_down_ccw); // boolean y_down_ccw); y_down_ccw); // boolean y_down_ccw);
*/
double [][] aff1_stretch = QuatUtils.quatToAffine( // use old for stretch
quats01[0], // double [] quat,
true, // boolean stretch,
make__pure_tilt, // boolean make__pure_tilt)
y_down_ccw); // boolean y_down_ccw);
double [][] aff1_shrink = QuatUtils.quatToAffine(
quats01[0], // double [] quat,
invert_q2a, // boolean stretch,
y_down_ccw); // boolean y_down_ccw);
double [][] aff2_shrink = QuatUtils.quatToAffine(
quats01[2], // double [] quat,
invert_q2a, // boolean stretch,
y_down_ccw); // boolean y_down_ccw);
double [][] aff2_stretch = QuatUtils.quatToAffine( // use old for stretch
quats01[2], // double [] quat,
true, // boolean stretch,
make__pure_tilt, // boolean make__pure_tilt)
y_down_ccw); // boolean y_down_ccw);
double [][] qaffd_pm = QuatUtils.affineToQuatScaled(affine_pair,true, y_down_ccw); double [][] qaffd_pm = QuatUtils.affineToQuatScaled(affine_pair,true, y_down_ccw);
System.out.println("qaffd_pm[0]= "+QuatUtils.toString(qaffd_pm[0],use_degrees)); System.out.println("qaffd_pm[0]= "+QuatUtils.toString(qaffd_pm[0],use_degrees));
...@@ -390,8 +417,10 @@ public class OrthoAltitudeMatch { ...@@ -390,8 +417,10 @@ public class OrthoAltitudeMatch {
double [][][][] raffines_pm = new double [affines.length][2][][]; double [][][][] raffines_pm = new double [affines.length][2][][];
SingularValueDecomposition[][] rsvd_pm = new SingularValueDecomposition [affines.length][2]; SingularValueDecomposition[][] rsvd_pm = new SingularValueDecomposition [affines.length][2];
for (int i = 0; i < raffines_pm.length;i++) { for (int i = 0; i < raffines_pm.length;i++) {
raffines_pm[i][0] = QuatUtils.quatToAffine(QuatUtils.affineToQuatScaled(affines[i], false, y_down_ccw)[0],false,true,true); // raffines_pm[i][0] = QuatUtils.quatToAffine(QuatUtils.affineToQuatScaled(affines[i], false, y_down_ccw)[0],false,true,true);
raffines_pm[i][1] = QuatUtils.quatToAffine(QuatUtils.affineToQuatScaled(affines[i], false, y_down_ccw)[1],false,false,true); // raffines_pm[i][1] = QuatUtils.quatToAffine(QuatUtils.affineToQuatScaled(affines[i], false, y_down_ccw)[1],false,false,true);
raffines_pm[i][0] = QuatUtils.quatToAffine(QuatUtils.affineToQuatScaled(affines[i], false, y_down_ccw)[0],invert_q2a,true);
raffines_pm[i][1] = QuatUtils.quatToAffine(QuatUtils.affineToQuatScaled(affines[i], false, y_down_ccw)[1],invert_q2a,true);
rsvd_pm[i][0] = SingularValueDecomposition.singularValueDecomposeScaleTiltGamma(raffines_pm[i][0], y_down_ccw); rsvd_pm[i][0] = SingularValueDecomposition.singularValueDecomposeScaleTiltGamma(raffines_pm[i][0], y_down_ccw);
rsvd_pm[i][1] = SingularValueDecomposition.singularValueDecomposeScaleTiltGamma(raffines_pm[i][1], y_down_ccw); rsvd_pm[i][1] = SingularValueDecomposition.singularValueDecomposeScaleTiltGamma(raffines_pm[i][1], y_down_ccw);
System.out.println("raffines["+i+"][0]= [["+raffines_pm[i][0][0][0]+ ","+raffines_pm[i][0][0][1]+"],"); System.out.println("raffines["+i+"][0]= [["+raffines_pm[i][0][0][0]+ ","+raffines_pm[i][0][0][1]+"],");
...@@ -444,17 +473,18 @@ public class OrthoAltitudeMatch { ...@@ -444,17 +473,18 @@ public class OrthoAltitudeMatch {
double [] svariants= new double [qvariants.length]; double [] svariants= new double [qvariants.length];
double [][][] taffines = new double [qvariants.length][][]; double [][][] taffines = new double [qvariants.length][][];
SingularValueDecomposition[] svd_avars = new SingularValueDecomposition[qvariants.length]; SingularValueDecomposition[] svd_avars = new SingularValueDecomposition[qvariants.length];
/// double [] svariants1= new double [qvariants1.length];
for (int i = 0; i < svariants.length; i++) svariants[i] = QuatUtils.normalizeInPlace(qvariants[i]); for (int i = 0; i < svariants.length; i++) svariants[i] = QuatUtils.normalizeInPlace(qvariants[i]);
/// for (int i = 0; i < svariants1.length; i++) svariants1[i] = QuatUtils.normalizeInPlace(qvariants1[i]);
for (int i = 0; i < svariants.length; i++) { for (int i = 0; i < svariants.length; i++) {
System.out.println(" qvariant["+i+"] = ["+qvariants[i][0]+ ","+qvariants[i][1]+ ","+qvariants[i][2]+ ","+qvariants[i][3]+ "] scale="+svariants[i]); System.out.println(" qvariant["+i+"] = ["+qvariants[i][0]+ ","+qvariants[i][1]+ ","+qvariants[i][2]+ ","+qvariants[i][3]+ "] scale="+svariants[i]);
/// System.out.println("qvariant1["+i+"] = ["+qvariants1[i][0]+ ","+qvariants1[i][1]+ ","+qvariants1[i][2]+ ","+qvariants1[i][3]+ "] scale="+svariants1[i]); /// taffines[i] = QuatUtils.quatToAffine(
/// qvariants[i], // double [] quat,
/// false, // boolean stretch,
/// false, // make__pure_tilt, // boolean make__pure_tilt)
/// y_down_ccw); // boolean y_down_ccw);
taffines[i] = QuatUtils.quatToAffine( taffines[i] = QuatUtils.quatToAffine(
qvariants[i], // double [] quat, qvariants[i], // double [] quat,
false, // boolean stretch, invert_q2a, // boolean invert,
false, // make__pure_tilt, // boolean make__pure_tilt)
y_down_ccw); // boolean y_down_ccw); y_down_ccw); // boolean y_down_ccw);
svd_avars[i] = SingularValueDecomposition.singularValueDecomposeScaleTiltGamma(taffines[i], y_down_ccw); svd_avars[i] = SingularValueDecomposition.singularValueDecomposeScaleTiltGamma(taffines[i], y_down_ccw);
} }
...@@ -473,8 +503,8 @@ public class OrthoAltitudeMatch { ...@@ -473,8 +503,8 @@ public class OrthoAltitudeMatch {
} }
double [][] aff_combo = QuatUtils.matMult(aff2_shrink,aff1_stretch); // invdert order? double [][] aff_combo = QuatUtils.matMult(aff2_shrink,aff1_stretch); // invert order?
double [][] aff_combo1= QuatUtils.matMult(aff1_stretch,aff2_shrink); // invdert order? double [][] aff_combo1= QuatUtils.matMult(aff1_stretch,aff2_shrink); // invert order?
SingularValueDecomposition svd_affine_pair = SingularValueDecomposition.singularValueDecomposeScaleTiltGamma(affine_pair, y_down_ccw); // boolean y_down_ccw) SingularValueDecomposition svd_affine_pair = SingularValueDecomposition.singularValueDecomposeScaleTiltGamma(affine_pair, y_down_ccw); // boolean y_down_ccw)
SingularValueDecomposition[] svd_affines = { SingularValueDecomposition[] svd_affines = {
SingularValueDecomposition.singularValueDecomposeScaleTiltGamma(affines[0], y_down_ccw), SingularValueDecomposition.singularValueDecomposeScaleTiltGamma(affines[0], y_down_ccw),
......
...@@ -90,6 +90,21 @@ public class SingularValueDecomposition { ...@@ -90,6 +90,21 @@ public class SingularValueDecomposition {
svd.ratio = svd.w2/svd.w1; svd.ratio = svd.w2/svd.w1;
return svd; return svd;
} }
public static double [] getMinMaxEigenValues(double [][] A) {
double a00=A[0][0],a01=A[0][1],a10=A[1][0],a11=A[1][1];
double b00=(a00+a11)/2; // , b11 = b00;
double c00=(a00-a11)/2; //, c11 =-c00;
double b01=(a01-a10)/2; //, b10 =-b01;
double c01=(a01+a10)/2; //, c10 = c01;
double w1_p_w2_2= Math.sqrt(b00*b00+b01*b01);
double w1_m_w2_2= Math.sqrt(c00*c00+c01*c01);
double w1 = w1_p_w2_2 + w1_m_w2_2;
double w2 = w1_p_w2_2 - w1_m_w2_2;
return (w1 < w2) ? (new double[] {w1,w2}) : (new double[] {w2,w1});
}
/** /**
* Use singular value decomposition and then split scaling {{w1,0},{0,w1}} * Use singular value decomposition and then split scaling {{w1,0},{0,w1}}
* into overall scaling caused by zoom != 1.0 because of altitude error * into overall scaling caused by zoom != 1.0 because of altitude error
...@@ -153,7 +168,7 @@ public class SingularValueDecomposition { ...@@ -153,7 +168,7 @@ public class SingularValueDecomposition {
while (beta >= Math.PI/2) { while (beta >= Math.PI/2) {
beta -= Math.PI; beta -= Math.PI;
} }
while (beta < Math.PI/2) { while (beta < -Math.PI/2) {
beta += Math.PI; beta += Math.PI;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment