Commit 7f9773fb authored by Andrey Filippov's avatar Andrey Filippov

done refactoring, starting debugging

parent 0a4fdfe3
package com.elphel.imagej.orthomosaic;
public class Affine2Import {
public static final String AFFINE2_TAG = "AFFINE2";
public static final int AFFINE2_LEN = 10;
public String name1;
public String name2;
public double overlap;
public double [][] affine;
public static boolean matches(String [] tokens) {
return ((tokens.length == AFFINE2_LEN) && AFFINE2_TAG.equals(tokens[0]));
}
public Affine2Import(
String [] tokens) {
if (!matches(tokens)) {
throw new IllegalArgumentException ("Not Affine2Import tokens");
}
int indx = 1;
name1 = tokens[indx++];
name2 = tokens[indx++];
overlap = Double.parseDouble(tokens[indx++]);
affine = new double [2][3];
for (int i = 0; i < affine.length; i++) {
for (int j = 0; j < affine[i].length; j++) {
affine[i][j] = Double.parseDouble(tokens[indx++]);
}
}
}
}
package com.elphel.imagej.orthomosaic;
public class AffineImport {
public static final String AFFINE_TAG = "AFFINE";
public static final int AFFINE_LEN = 8;
public String name;
public double [][] affine;
public static boolean matches(String [] tokens) {
return ((tokens.length == AFFINE_LEN) && AFFINE_TAG.equals(tokens[0]));
}
public AffineImport(
String [] tokens) {
if (!matches(tokens)) {
throw new IllegalArgumentException ("Not AffineImport tokens");
}
int indx = 1;
name = tokens[indx++];
affine = new double [2][3];
for (int i = 0; i < affine.length; i++) {
for (int j = 0; j < affine[i].length; j++) {
affine[i][j] = Double.parseDouble(tokens[indx++]);
}
}
}
// String[] tokens
}
...@@ -238,6 +238,10 @@ public class FloatImageData implements Serializable { ...@@ -238,6 +238,10 @@ public class FloatImageData implements Serializable {
return extra_zoom[0]; return extra_zoom[0];
} }
public double needZoomIn() {
return needZoomIn(pix_meters);
}
public int getZoomLevel() { public int getZoomLevel() {
return zoom_lev; return zoom_lev;
} }
......
...@@ -106,54 +106,57 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -106,54 +106,57 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
public static final String ALT_SUFFIX = "-ALT"; public static final String ALT_SUFFIX = "-ALT";
public transient String name; // timestamp public String path; // full path to the model directory (including /vXX?)
public transient double ts; // public double [] lla; // lat/long/alt
public transient String path; // full path to the model directory (including /vXX?) // public LocalDateTime dt;
public double [] lla; // lat/long/alt
public LocalDateTime dt;
// affine convert (input) rectified coordinates (meters) relative to vert_meters to source image // affine convert (input) rectified coordinates (meters) relative to vert_meters to source image
// coordinates relative to vert_meters // coordinates relative to vert_meters
public double [][] affine = new double[][] {{1,0,0},{0,1,0}}; // relative to vert_meters[], positive Y is down (as in images) public double [][] affine = new double[][] {{1,0,0},{0,1,0}}; // relative to vert_meters[], positive Y is down (as in images)
public transient double [][] ers_affine = new double[][] {{1,0},{0,1}}; // orientation only for remaining ERS, positive Y is down (as in images) public double [][] ers_affine = new double[][] {{1,0},{0,1}}; // orientation only for remaining ERS, positive Y is down (as in images)
public transient FloatImageData orig_image; public FloatImageData orig_image;
public transient FloatImageData alt_image; public FloatImageData alt_image;
public int orig_zoom_level; // public int orig_zoom_level;
public boolean orig_zoom_valid; // public boolean orig_zoom_valid;
public double need_extra_zoom; // public double need_extra_zoom;
public double averageRawPixel = Double.NaN; // measure of scene temperature public double averageRawPixel = Double.NaN; // measure of scene temperature
transient HashMap <Integer, FloatImageData> images;
HashMap <String, PairwiseOrthoMatch> pairwise_matches; HashMap <String, PairwiseOrthoMatch> pairwise_matches;
public transient SensorTemperatureData[] temp_data; public SensorTemperatureData[] temp_data;
public transient double agl = Double.NaN; public double agl = Double.NaN;
public transient int num_scenes = -1;; // number of scenes that made up this image public int num_scenes = -1;; // number of scenes that made up this image
public transient double sfm_gain = Double.NaN; // maximal SfM gain of this map public double sfm_gain = Double.NaN; // maximal SfM gain of this map
public transient double [] equalize = {1,0}; // rectified value = equalize[0]*source_value+equalize[1] public double [] equalize = {1,0}; // rectified value = equalize[0]*source_value+equalize[1]
public transient double [] qorient = null; // quternion representing orientation+scale of the scene public double [] qorient = null; // quternion representing orientation+scale of the scene
// really transient
transient HashMap <Integer, FloatImageData> images;
public transient String name; // timestamp
public transient double ts;
private void writeObject(ObjectOutputStream oos) throws IOException { private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject(); oos.defaultWriteObject();
oos.writeObject(path); // oos.writeObject(path);
oos.writeObject(temp_data); // temporary, while transient // oos.writeObject(temp_data); // temporary, while transient
oos.writeObject(agl); // oos.writeObject(agl);
oos.writeObject(num_scenes); // oos.writeObject(num_scenes);
oos.writeObject(sfm_gain); // oos.writeObject(sfm_gain);
oos.writeObject(equalize); // oos.writeObject(equalize);
oos.writeObject(qorient); // oos.writeObject(qorient);
} }
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject(); ois.defaultReadObject();
path = (String) ois.readObject(); // path = (String) ois.readObject();
name = getNameFromPath(path); name = getNameFromPath(path);
ts= Double.parseDouble(name.replace("_", ".")); ts= Double.parseDouble(name.replace("_", "."));
temp_data = (SensorTemperatureData[]) ois.readObject(); // temp_data = (SensorTemperatureData[]) ois.readObject();
agl = (double) ois.readObject(); // agl = (double) ois.readObject();
num_scenes = (int) ois.readObject(); // num_scenes = (int) ois.readObject();
sfm_gain = (double) ois.readObject(); // sfm_gain = (double) ois.readObject();
equalize = (double []) ois.readObject(); // equalize = (double []) ois.readObject();
if (OrthoMapsCollection.CURRENT_VERSION >= OrthoMapsCollection.VERSION_POST_ORIENT) { // if (OrthoMapsCollection.CURRENT_VERSION >= OrthoMapsCollection.VERSION_POST_ORIENT) {
qorient = (double[]) ois.readObject(); // qorient = (double[]) ois.readObject();
} // }
images = new HashMap <Integer, FloatImageData>(); // field images was not saved images = new HashMap <Integer, FloatImageData>(); // field images was not saved
// averageImagePixel = Double.NaN; // average image pixel value (to combine with raw) // averageImagePixel = Double.NaN; // average image pixel value (to combine with raw)
...@@ -229,7 +232,16 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -229,7 +232,16 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
if (with_undefined || match.isDefined()) return match; if (with_undefined || match.isDefined()) return match;
return null; return null;
} }
public static boolean isAffineNonTrivial(double [][] affine) {
if (affine == null) {
return false;
}
return ( affine[0][0] != 1.0) || (affine[0][1] != 0.0) || (affine[0][2] != 0.0) ||
(affine[1][0] != 0.0) || (affine[1][1] != 1.0) || (affine[1][2] != 0.0);
}
public boolean isAffineNonTrivial() {
return isAffineNonTrivial(this.affine);
}
public PairwiseOrthoMatch getMatch(String name) { public PairwiseOrthoMatch getMatch(String name) {
...@@ -252,7 +264,8 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -252,7 +264,8 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
} }
public int getOriginalZoomLevel() { public int getOriginalZoomLevel() {
return orig_zoom_level; return getImage().getZoomLevel(); // image, not altitude!
// return orig_zoom_level;
} }
// Generate ALT image path from the GEO // Generate ALT image path from the GEO
public static String getAltPath(String path) { public static String getAltPath(String path) {
...@@ -494,7 +507,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -494,7 +507,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
// initialize and read Exif for the images // initialize and read Exif for the images
orig_image = new FloatImageData(path); orig_image = new FloatImageData(path);
dt = orig_image.getDT(); // dt = orig_image.getDT();
/* /*
Properties imp_prop = null; Properties imp_prop = null;
...@@ -551,7 +564,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -551,7 +564,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
return false; return false;
} }
orig_image = new FloatImageData(path); orig_image = new FloatImageData(path);
dt = orig_image.getDT(); // dt = orig_image.getDT();
} }
if (alt_image != null) { if (alt_image != null) {
String alt_path = getAltPath(path); String alt_path = getAltPath(path);
...@@ -577,7 +590,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -577,7 +590,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
return null; return null;
} }
orig_image = new FloatImageData(path); orig_image = new FloatImageData(path);
dt = orig_image.getDT(); // dt = orig_image.getDT();
} }
return orig_image; return orig_image;
} }
...@@ -654,7 +667,8 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -654,7 +667,8 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
return ts; return ts;
} }
public LocalDateTime getLocalDateTime() { public LocalDateTime getLocalDateTime() {
return dt; return getImage().getDT();
// return dt;
} }
public String getName() { public String getName() {
...@@ -974,11 +988,11 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -974,11 +988,11 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
return false; return false;
} }
if (!orig_image.isZoomValid()) { if (!orig_image.isZoomValid()) {
System.out.println("Original zoom level is invalid, need_extra_zoom = "+need_extra_zoom); System.out.println("Original zoom level is invalid, need_extra_zoom = "+orig_image.needZoomIn());
return false; return false;
} }
if (zoom_level > orig_image.getZoomLevel()) { if (zoom_level > orig_image.getZoomLevel()) {
System.out.println("Requested zoom level is too high ("+zoom_level+" > "+orig_zoom_level+")"); System.out.println("Requested zoom level is too high ("+zoom_level+" > "+orig_image.getZoomLevel()+")");
return false; return false;
} }
if (images.get(zoom_level) != null) { if (images.get(zoom_level) != null) {
...@@ -1085,7 +1099,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -1085,7 +1099,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
final float [] felev = src_elev.readFData(); final float [] felev = src_elev.readFData();
final double [] elev = new double [tilesX*tilesY]; final double [] elev = new double [tilesX*tilesY];
Arrays.fill(elev, Double.NaN); Arrays.fill(elev, Double.NaN);
final int diff_zoom_lev = zoom_level-orig_zoom_level; final int diff_zoom_lev = zoom_level-getAlt().getZoomLevel(); // orig_zoom_level;
final double scale = 1.0/getScale (diff_zoom_lev); // int zoom_lev); final double scale = 1.0/getScale (diff_zoom_lev); // int zoom_lev);
final Thread[] threads = ImageDtt.newThreadArray(); final Thread[] threads = ImageDtt.newThreadArray();
......
...@@ -32,20 +32,61 @@ import Jama.Matrix; ...@@ -32,20 +32,61 @@ import Jama.Matrix;
public class PairwiseOrthoMatch implements Serializable { public class PairwiseOrthoMatch implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static boolean READ_NO_ALT = false; // to read old format w/o alt data ( not final!) // public static boolean READ_NO_ALT = false; // to read old format w/o alt data ( not final!)
private double [][] affine = new double[2][3]; private double [][] affine = new double[2][3];
public transient double [][] jtj = new double [6][6];
public int zoom_lev; public int zoom_lev;
public double rms = Double.NaN; public double rms = Double.NaN;
public transient double overlap = 0.0; public double overlap = 0.0;
public transient double [] alt_data = null; public double [] alt_data = null;
public transient double [] equalize1to0 = {1,0}; // value1 = equalize2to1[0]*value2+equalize2to1[1] public double [] equalize1to0 = {1,0}; // value1 = equalize2to1[0]*value2+equalize2to1[1]
public transient double [] quat = null; // relative orientation of the second scene (ERS affine removed). Will be eventually saved public double [] quat = null; // relative orientation of the second scene (ERS affine removed). Will be eventually saved
public transient double [][] qaffine = null; // affine relative to rotated scenes public double [][] qaffine = null; // affine relative to rotated scenes
// real transient
public transient double [][] jtj = new double [6][6];
// below - not saved/restored // below - not saved/restored
public transient boolean ok = false; // not saved/restored public transient boolean ok = false; // not saved/restored
public transient int [] nxy = null; // not saved, just to communicate for logging public transient int [] nxy = null; // not saved, just to communicate for logging
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
for (int i = 0; i < jtj.length; i++) {
for (int j = i; j < jtj[i].length; j++) {
oos.writeObject(jtj[i][j]);
}
}
// oos.writeObject(overlap);
// oos.writeObject(equalize1to0);
// oos.writeObject(alt_data);
// oos.writeObject(quat);
// oos.writeObject(qaffine);
}
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject();
jtj = new double [6][6]; // readObject does not use constructor!
for (int i = 0; i < jtj.length; i++) {
for (int j = i; j < jtj[i].length; j++) {
jtj[i][j] = (Double) ois.readObject();
if (j > i) {
jtj[j][i] = jtj[i][j];
}
}
}
// overlap = (Double) ois.readObject();
// equalize1to0 = new double[] {1,0};
// equalize1to0 = (double[]) ois.readObject();
// if (!READ_NO_ALT) {
// alt_data = (double[]) ois.readObject();
// }
// if (OrthoMapsCollection.CURRENT_VERSION >= OrthoMapsCollection.VERSION_POST_ORIENT) {
quat= (double[]) ois.readObject();
qaffine = (double[][]) ois.readObject();
// }
}
public double [] getQuaternion() { public double [] getQuaternion() {
return quat; return quat;
} }
...@@ -95,6 +136,11 @@ public class PairwiseOrthoMatch implements Serializable { ...@@ -95,6 +136,11 @@ public class PairwiseOrthoMatch implements Serializable {
public boolean isDefined() { public boolean isDefined() {
return affine != null; return affine != null;
} }
public boolean isAffineNonTrivial() {
return OrthoMap.isAffineNonTrivial(this.affine);
}
public double [] getEqualize2to1() { public double [] getEqualize2to1() {
return equalize1to0; return equalize1to0;
} }
...@@ -298,42 +344,5 @@ public class PairwiseOrthoMatch implements Serializable { ...@@ -298,42 +344,5 @@ public class PairwiseOrthoMatch implements Serializable {
this.affine= affine; this.affine= affine;
} }
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
for (int i = 0; i < jtj.length; i++) {
for (int j = i; j < jtj[i].length; j++) {
oos.writeObject(jtj[i][j]);
}
}
oos.writeObject(overlap);
oos.writeObject(equalize1to0);
oos.writeObject(alt_data);
oos.writeObject(quat);
oos.writeObject(qaffine);
}
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject();
jtj = new double [6][6]; // readObject does not use constructor!
for (int i = 0; i < jtj.length; i++) {
for (int j = i; j < jtj[i].length; j++) {
jtj[i][j] = (Double) ois.readObject();
if (j > i) {
jtj[j][i] = jtj[i][j];
}
}
}
overlap = (Double) ois.readObject();
// equalize1to0 = new double[] {1,0};
equalize1to0 = (double[]) ois.readObject();
if (!READ_NO_ALT) {
alt_data = (double[]) ois.readObject();
}
if (OrthoMapsCollection.CURRENT_VERSION >= OrthoMapsCollection.VERSION_POST_ORIENT) {
quat= (double[]) ois.readObject();
qaffine = (double[][]) ois.readObject();
}
}
//private void readObjectNoData() throws ObjectStreamException; // used to modify default values //private void readObjectNoData() throws ObjectStreamException; // used to modify default values
} }
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