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
}
......@@ -43,6 +43,7 @@ import ij.gui.PointRoi;
import ij.process.FloatPolygon;
public class ComboMatch {
public static final String [] SUFFIXES_BL_BC= {"","-BL","-BC"};
public static GPUTileProcessor GPU_TILE_PROCESSOR = null;
public static GpuQuad GPU_QUAD_AFFINE = null;
public static ImagePlus imp_src1 = null;
......@@ -174,9 +175,6 @@ public class ComboMatch {
boolean display_pairs = false;
boolean create_map = false;
boolean create_equalize = false;
boolean use_saved_collection = false; // true; // false;
boolean save_collection = false; // true;
boolean process_correlation = true; // use false to save new version of data
......@@ -191,23 +189,24 @@ public class ComboMatch {
boolean restore_temp = true;
double frac_remove = clt_parameters.imp.pmtch_frac_remove; // 0.15;
double metric_error = clt_parameters.imp.pmtch_metric_err; // 0.05; // 0.02;// 2 cm
boolean update_files = false;
boolean update_lla = false; // re-read file metadata
boolean update_kernel_patterns = false;
boolean update_bl_bc = false;
boolean export_affine = false; // export per-scene affines
boolean export_affine2 = false; // export per-pair affines
boolean import_export = false;
// boolean update_files = false;
// boolean update_lla = false; // re-read file metadata
// boolean update_kernel_patterns = false;
// boolean update_bl_bc = false;
// boolean export_affine = false; // export per-scene affines
// boolean export_affine2 = false; // export per-pair affines
boolean fix_duplicates = false;
String [] suffixes_bl_bc= {"","-BL","-BC"};
boolean log_append = clt_parameters.imp.pwise_log_append;
String log_path = clt_parameters.imp.pwise_log_path;
String omtch_img_set = clt_parameters.imp.omtch_img_set;
// boolean READ_NO_ALT = false; // to read older format data file where pairs do not have alt_data[]
int suffix_bc_bl_indx = 2;
// int suffix_bc_bl_indx = 2;
if (!use_marked_image) {
process_correlation=false; // use already adjusted by default
}
......@@ -217,12 +216,10 @@ public class ComboMatch {
}
GenericJTabbedDialog gd = new GenericJTabbedDialog("Set image pair",1200,900);
// gd.addChoice ("Files list/data path (w/o extension):", FILES_LISTS_PATHS, FILES_LISTS_PATHS[default_list_choice]);
gd.addChoice ("Files list/data path (w/o extension):", FILES_LISTS_PATHS, omtch_img_set);
gd.addCheckbox ("Use saved maps collection ", use_saved_collection, " (if available). If false - use files list.");
gd.addCheckbox ("Save maps collection", save_collection, "Save maps collection to be able to restore.");
gd.addCheckbox ("Process correlations", process_correlation, "false to skip to just regenerate new save file.");
// int num_tries_fit = 10;
gd.addNumericField("Num tries fit", num_tries_fit, 0,4,"", "Try matching images this number of times");
gd.addCheckbox ("Update match if calculated", update_match, "Will update correlation match for a pair if found.");
......@@ -254,28 +251,29 @@ public class ComboMatch {
if (use_marked_image ) {
gd.addCheckbox ("Use marked image data", true, "Use markes from the selected image");
}
gd.addCheckbox ("Update scene files", update_files, "Re-read files as specified in .list file, possibly changing versions");
gd.addCheckbox ("Update files metadata", update_lla, "Re-read files metadata (if it was modified)");
gd.addCheckbox ("Update kernels/patterns", update_kernel_patterns, "Re-read kernels and patterns from *.list file");
gd.addCheckbox ("Import/Export operations", import_export, "Import/export and update operations");
// gd.addCheckbox ("Update scene files", update_files, "Re-read files as specified in .list file, possibly changing versions");
// gd.addCheckbox ("Update files metadata", update_lla, "Re-read files metadata (if it was modified)");
// gd.addCheckbox ("Update kernels/patterns", update_kernel_patterns, "Re-read kernels and patterns from *.list file");
gd.addCheckbox ("Remove duplicate scenes", fix_duplicates, "Remove scenes with the same timestamp");
gd.addCheckbox ("Update BC/BL suffix", update_bl_bc,
"Change source filenames to use -BC for bicubic, -BL - for bilinear, or empty - for old bilinear files");
gd.addChoice("BL/BC suffix:",
suffixes_bl_bc,
suffixes_bl_bc[suffix_bc_bl_indx],
"Select interpolation mode of the source files: old bilinear (empty), bilinear (-BL), or bicubic (-BC)", 0);
// gd.addCheckbox ("Update BC/BL suffix", update_bl_bc,
// "Change source filenames to use -BC for bicubic, -BL - for bilinear, or empty - for old bilinear files");
// gd.addChoice("BL/BC suffix:",
// SUFFIXES_BL_BC,
// SUFFIXES_BL_BC[suffix_bc_bl_indx],
// "Select interpolation mode of the source files: old bilinear (empty), bilinear (-BL), or bicubic (-BC)", 0);
gd.addCheckbox ("Export scene affines", export_affine, "Export per-scene affines in text format for migration.");
gd.addCheckbox ("Export pairs affines", export_affine2, "Export per-pair affines in text format for migration.");
// gd.addCheckbox ("Export scene affines", export_affine, "Export per-scene affines in text format for migration.");
// gd.addCheckbox ("Export pairs affines", export_affine2, "Export per-pair affines in text format for migration.");
gd.addCheckbox ("Write log file", log_append, "Enable writing log file with matching results.");
gd.addStringField ("Log file full path", log_path, 150, "Path of the log file to be appended.");
// gd.addCheckbox ("Read no-alt data (old)", READ_NO_ALT, "Read older format data file where pairs do not have alt_data[].");
// gd.addCheckbox ("Read no-alt data (old)", READ_NO_ALT, "Read older format data file where pairs do not have alt_data[].");
// update_kernel_patterns
// update_kernel_patterns
gd.showDialog();
if (gd.wasCanceled()) return false;
......@@ -285,6 +283,7 @@ public class ComboMatch {
String orthoMapsCollection_path =omtch_img_set+".data";
String affines_path = omtch_img_set+".affines"; // for export per-scene affines
String affines2_path = omtch_img_set+".affines2"; // for export per-pair affines
use_saved_collection = gd.getNextBoolean();
save_collection = gd.getNextBoolean();
String orthoMapsCollection_savepath = save_collection?orthoMapsCollection_path:null;
......@@ -317,15 +316,16 @@ public class ComboMatch {
if (use_marked_image ) { // will only be used if found and asked
use_marked_image= gd.getNextBoolean();
}
update_files= gd.getNextBoolean();
update_lla= gd.getNextBoolean();
update_kernel_patterns= gd.getNextBoolean();
import_export = gd.getNextBoolean();
// update_files= gd.getNextBoolean();
// update_lla= gd.getNextBoolean();
// update_kernel_patterns= gd.getNextBoolean();
fix_duplicates= gd.getNextBoolean();
update_bl_bc= gd.getNextBoolean();
suffix_bc_bl_indx = gd.getNextChoiceIndex();
// update_bl_bc= gd.getNextBoolean();
// suffix_bc_bl_indx = gd.getNextChoiceIndex();
export_affine = gd.getNextBoolean();
export_affine2 = gd.getNextBoolean();
// export_affine = gd.getNextBoolean();
// export_affine2 = gd.getNextBoolean();
log_append = gd.getNextBoolean();
......@@ -343,13 +343,13 @@ public class ComboMatch {
}
//files_list_path
if (!use_files_list) {
if (update_kernel_patterns) {
maps_collection.updateKernels(files_list_path);
maps_collection.updatePatterns(files_list_path);
}
if (update_files) {
maps_collection.updateFiles(files_list_path);
}
// if (update_kernel_patterns) {
// maps_collection.updateKernels(files_list_path);
// maps_collection.updatePatterns(files_list_path);
// }
// if (update_files) {
// maps_collection.updateFiles(files_list_path);
// }
}
} else {
use_files_list = true;
......@@ -360,6 +360,15 @@ public class ComboMatch {
maps_collection.updateSfmGain();
}
if (import_export) {
return updateImportExport(
omtch_img_set, // String files_base
maps_collection); // OrthoMapsCollection maps_collection
}
/*
if (export_affine) {
StringBuffer sb = new StringBuffer();
for (OrthoMap omap : maps_collection.ortho_maps) {
......@@ -415,22 +424,23 @@ public class ComboMatch {
if (export_affine || export_affine2) {
return true; // do not save
}
*/
if (fix_duplicates) {
removeDuplicateScenes (maps_collection);
}
/*
if (update_bl_bc) {
boolean OK = updateBlBcFileNames(
suffixes_bl_bc[suffix_bc_bl_indx], // String suffix,
SUFFIXES_BL_BC[suffix_bc_bl_indx], // String suffix,
"-FLAT",// String before,
maps_collection); // OrthoMapsCollection maps_collection)
if (!OK) {
System.out.println("Failed to update filenames for different interpolation mode");
}
}
*/
String [] names = maps_collection.getNames(); // null
......@@ -608,7 +618,7 @@ public class ComboMatch {
}
}
maps_collection.reverseRender(
maps_collection.reverseRender( // assuming image, not alt
object_list, // ArrayList<ObjectLocation> objects,
zool_lev_objects, // int zoom_level){
indices); // int [] indices){ // null or selected image indices
......@@ -843,12 +853,12 @@ public class ComboMatch {
//getTemperature()
// get all temperatures
maps_collection.getAllTemperatures();
if (update_lla) {
System.out.println("Updating map files metadata");
maps_collection.updateLLa();
maps_collection.updateNumberScenes();
maps_collection.updateSfmGain();
}
// if (update_lla) {
// System.out.println("Updating map files metadata");
// maps_collection.updateLLA();
// maps_collection.updateNumberScenes();
// maps_collection.updateSfmGain();
// }
// which pair to compare
// String [] gpu_spair = {names[gpu_ipair[0]],names[gpu_ipair[1]]};
......@@ -2652,5 +2662,210 @@ adjusted affines[1] for a pair: 1694564291_293695/1694564778_589341
}
}
public static boolean updateImportExport(
String files_base,
OrthoMapsCollection maps_collection) {
if (maps_collection == null) {
throw new IllegalArgumentException ("maps_collection is not initialized!");
}
int suffix_bc_bl_indx = 2;
boolean update_files = false;
boolean update_lla = false; // re-read file metadata
boolean update_kernel_patterns = false;
boolean update_bl_bc = false;
boolean export_affine = false; // export per-scene affines
boolean export_affine2 = false; // export per-pair affines
boolean overwrite_affine = false;
boolean import_affine = false; // export per-scene affines
boolean import_affine2 = false; // export per-pair affines
String files_list_path = files_base+".list";
// String orthoMapsCollection_path =omtch_img_set+".data";
String affines_path = files_base+".affines"; // for export per-scene affines
String affines2_path = files_base+".affines2"; // for export per-pair affines
GenericJTabbedDialog gd = new GenericJTabbedDialog("Select Update, Import or Export operations",1200,900);
gd.addStringField ("List file full path", files_list_path, 150, "Path to read/update directories and GEO files.");
gd.addStringField ("Scene affines full path", affines_path, 150, "Path to import/export scenes affines.");
gd.addStringField ("Pairwise affines full path", affines2_path, 150, "Path to import/export scenes pairs affines.");
gd.addCheckbox ("Update scene files", update_files, "Re-read files as specified in .list file, possibly changing versions");
gd.addCheckbox ("Update files metadata", update_lla, "Re-read files metadata (if it was modified)");
gd.addCheckbox ("Update kernels/patterns", update_kernel_patterns, "Re-read kernels and patterns from *.list file");
gd.addCheckbox ("Export scene affines", export_affine, "Export per-scene affines in text format for migration.");
gd.addCheckbox ("Export pairs affines", export_affine2, "Export per-pair affines in text format for migration.");
gd.addCheckbox ("Overwrite affines on import",overwrite_affine, "Overwrite existing non-trivial affines on import.");
gd.addCheckbox ("Import scene affines", import_affine, "Export per-scene affines in text format for migration.");
gd.addCheckbox ("Import pairs affines", import_affine2, "Export per-pair affines in text format for migration.");
gd.addCheckbox ("Update BC/BL suffix", update_bl_bc,
"Change source filenames to use -BC for bicubic, -BL - for bilinear, or empty - for old bilinear files");
gd.addChoice("BL/BC suffix:",
SUFFIXES_BL_BC,
SUFFIXES_BL_BC[suffix_bc_bl_indx],
"Select interpolation mode of the source files: old bilinear (empty), bilinear (-BL), or bicubic (-BC)", 0);
gd.showDialog();
if (gd.wasCanceled()) return false;
files_list_path = gd.getNextString();
affines_path = gd.getNextString();
affines2_path = gd.getNextString();
update_files= gd.getNextBoolean();
update_lla= gd.getNextBoolean();
update_kernel_patterns= gd.getNextBoolean();
export_affine = gd.getNextBoolean();
export_affine2 = gd.getNextBoolean();
overwrite_affine = gd.getNextBoolean();
import_affine = gd.getNextBoolean();
import_affine2 = gd.getNextBoolean();
update_bl_bc= gd.getNextBoolean();
suffix_bc_bl_indx = gd.getNextChoiceIndex();
if (update_files) {
maps_collection.updateFiles(files_list_path);
maps_collection.updateNumberScenes(); // number of scenes in each sequence
}
if (update_lla) {
System.out.println("Updating map files metadata");
maps_collection.updateLLA();
maps_collection.updateNumberScenes();
maps_collection.updateSfmGain();
}
if (update_kernel_patterns) {
maps_collection.updateKernels(files_list_path);
maps_collection.updatePatterns(files_list_path);
}
if (export_affine) {
StringBuffer sb = new StringBuffer();
for (OrthoMap omap : maps_collection.ortho_maps) {
String name = omap.getName();
double [][] affine = omap.getAffine();
if (affine != null) {
sb.append(String.format("AFFINE %s %11.8f %11.8f %11.8f %11.8f %11.8f %11.8f\n",
name, affine[0][0], affine[0][1], affine[0][2], affine[1][0], affine[1][1], affine[1][2]));
}
}
CalibrationFileManagement.saveStringToFile (
affines_path, //String path,
sb.toString(), // data,
false); // boolean append)
}
if (export_affine2) {
StringBuffer sb = new StringBuffer();
ArrayList<Point> pairs_list = new ArrayList<Point>();
for (OrthoMap map : maps_collection.ortho_maps) {
for (String other_name: map.pairwise_matches.keySet()) {
pairs_list.add(new Point(
maps_collection.getIndex(map.getName()),
maps_collection.getIndex(other_name)));
}
}
Collections.sort(pairs_list, new Comparator<Point>() {
@Override
public int compare(Point lhs, Point rhs) {
return (rhs.x > lhs.x) ? -1 : (rhs.x < lhs.x) ? 1 :
((rhs.y > lhs.y) ? -1 : (rhs.y < lhs.y) ? 1 : 0); // increasing
}
});
for (Point pair: pairs_list) {
PairwiseOrthoMatch pom = maps_collection.ortho_maps[pair.x].getMatch(
maps_collection.ortho_maps[pair.y].getName(), false); // undef_only || nan_rms);
if ((pom !=null) && pom.isDefined()) {
double overlap = pom.overlap;
double [][] affine = pom.getAffine();
sb.append(String.format("AFFINE2 %s %s %11.8f %11.8f %11.8f %11.8f %11.8f %11.8f %11.8f\n",
maps_collection.ortho_maps[pair.x].getName(),
maps_collection.ortho_maps[pair.y].getName(),
overlap,
affine[0][0], affine[0][1], affine[0][2], affine[1][0], affine[1][1], affine[1][2]));
}
}
CalibrationFileManagement.saveStringToFile (
affines2_path, //String path,
sb.toString(), // data,
false); // boolean append)
}
if (import_affine) {
ArrayList<AffineImport> affine_import = new ArrayList<AffineImport>();
OrthoMapsCollection.getPathsAndScenesFromSourceList(
affines_path,
null, // scenes0,
null, // ArrayList<AltitudeMismatchKernel> kernels,
null, // ArrayList<GroundObjectPattern> patterns);
null, // ArrayList<ModelRegex> model_regexes,
null, // String [] regex_use) {
affine_import, // ArrayList<AffineImport> affine_import,
null); // ArrayList<Affine2Import> affine2_import) {
int num_updated_affines = 0;
for (AffineImport affineImport: affine_import) {
OrthoMap map = maps_collection.getMap(affineImport.name);
if (map != null) {
if (overwrite_affine || !map.isAffineNonTrivial()) {
map.setAffine(affineImport.affine);
num_updated_affines++;
}
}
}
maps_collection.updateNumberScenes();
System.out.println("Updated "+num_updated_affines+" affines of "+affine_import.size()+" specified. There are "+
maps_collection.ortho_maps.length+" maps in the system.");
}
if (import_affine2) {
ArrayList<Affine2Import> affine2_import = new ArrayList<Affine2Import>();
OrthoMapsCollection.getPathsAndScenesFromSourceList(
affines_path,
null, // scenes0,
null, // ArrayList<AltitudeMismatchKernel> kernels,
null, // ArrayList<GroundObjectPattern> patterns);
null, // ArrayList<ModelRegex> model_regexes,
null, // String [] regex_use) {
null, // ArrayList<AffineImport> affine_import,
affine2_import); // ArrayList<Affine2Import> affine2_import) {
int num_updated_affines = 0;
for (Affine2Import affine2Import: affine2_import) {
OrthoMap map = maps_collection.getMap(affine2Import.name1);
if (map != null) {
PairwiseOrthoMatch pom = map.getMatch(affine2Import.name2,true);
if (pom != null) {
if (overwrite_affine || !pom.isAffineNonTrivial()) {
pom.setOverlap(affine2Import.overlap);
pom.setAffine(affine2Import.affine); // does not clone - OK
}
} else {
OrthoMap map2 = maps_collection.getMap(affine2Import.name2);
int zoom_lev = Math.min(map.getOriginalZoomLevel(), map2.getOriginalZoomLevel());
pom= new PairwiseOrthoMatch(
affine2Import.affine, // double [][] affine,
null, // double [][] jtj,
Double.NaN, // double rms,
zoom_lev, // int zoom_lev,
affine2Import.overlap); // double overlap)
}
}
}
}
if (update_bl_bc) {
boolean OK = updateBlBcFileNames(
SUFFIXES_BL_BC[suffix_bc_bl_indx], // String suffix,
"-FLAT",// String before,
maps_collection); // OrthoMapsCollection maps_collection)
if (!OK) {
System.out.println("Failed to update filenames for different interpolation mode");
}
}
return true;
}
}
......@@ -238,6 +238,10 @@ public class FloatImageData implements Serializable {
return extra_zoom[0];
}
public double needZoomIn() {
return needZoomIn(pix_meters);
}
public int getZoomLevel() {
return zoom_lev;
}
......
......@@ -106,54 +106,57 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
public static final String ALT_SUFFIX = "-ALT";
public transient String name; // timestamp
public transient double ts;
public transient String path; // full path to the model directory (including /vXX?)
public double [] lla; // lat/long/alt
public LocalDateTime dt;
public String path; // full path to the model directory (including /vXX?)
// public double [] lla; // lat/long/alt
// public LocalDateTime dt;
// affine convert (input) rectified coordinates (meters) relative to vert_meters to source image
// 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 transient 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 transient FloatImageData alt_image;
public int orig_zoom_level;
public boolean orig_zoom_valid;
public double need_extra_zoom;
public double [][] ers_affine = new double[][] {{1,0},{0,1}}; // orientation only for remaining ERS, positive Y is down (as in images)
public FloatImageData orig_image;
public FloatImageData alt_image;
// public int orig_zoom_level;
// public boolean orig_zoom_valid;
// public double need_extra_zoom;
public double averageRawPixel = Double.NaN; // measure of scene temperature
transient HashMap <Integer, FloatImageData> images;
HashMap <String, PairwiseOrthoMatch> pairwise_matches;
public transient SensorTemperatureData[] temp_data;
public transient double agl = Double.NaN;
public transient 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 transient 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 SensorTemperatureData[] temp_data;
public double agl = Double.NaN;
public int num_scenes = -1;; // number of scenes that made up this image
public double sfm_gain = Double.NaN; // maximal SfM gain of this map
public double [] equalize = {1,0}; // rectified value = equalize[0]*source_value+equalize[1]
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 {
oos.defaultWriteObject();
oos.writeObject(path);
oos.writeObject(temp_data); // temporary, while transient
oos.writeObject(agl);
oos.writeObject(num_scenes);
oos.writeObject(sfm_gain);
oos.writeObject(equalize);
oos.writeObject(qorient);
// oos.writeObject(path);
// oos.writeObject(temp_data); // temporary, while transient
// oos.writeObject(agl);
// oos.writeObject(num_scenes);
// oos.writeObject(sfm_gain);
// oos.writeObject(equalize);
// oos.writeObject(qorient);
}
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject();
path = (String) ois.readObject();
// path = (String) ois.readObject();
name = getNameFromPath(path);
ts= Double.parseDouble(name.replace("_", "."));
temp_data = (SensorTemperatureData[]) ois.readObject();
agl = (double) ois.readObject();
num_scenes = (int) ois.readObject();
sfm_gain = (double) ois.readObject();
equalize = (double []) ois.readObject();
if (OrthoMapsCollection.CURRENT_VERSION >= OrthoMapsCollection.VERSION_POST_ORIENT) {
qorient = (double[]) ois.readObject();
}
// temp_data = (SensorTemperatureData[]) ois.readObject();
// agl = (double) ois.readObject();
// num_scenes = (int) ois.readObject();
// sfm_gain = (double) ois.readObject();
// equalize = (double []) ois.readObject();
// if (OrthoMapsCollection.CURRENT_VERSION >= OrthoMapsCollection.VERSION_POST_ORIENT) {
// qorient = (double[]) ois.readObject();
// }
images = new HashMap <Integer, FloatImageData>(); // field images was not saved
// averageImagePixel = Double.NaN; // average image pixel value (to combine with raw)
......@@ -229,7 +232,16 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
if (with_undefined || match.isDefined()) return match;
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) {
......@@ -252,7 +264,8 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
}
public int getOriginalZoomLevel() {
return orig_zoom_level;
return getImage().getZoomLevel(); // image, not altitude!
// return orig_zoom_level;
}
// Generate ALT image path from the GEO
public static String getAltPath(String path) {
......@@ -494,7 +507,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
// initialize and read Exif for the images
orig_image = new FloatImageData(path);
dt = orig_image.getDT();
// dt = orig_image.getDT();
/*
Properties imp_prop = null;
......@@ -551,7 +564,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
return false;
}
orig_image = new FloatImageData(path);
dt = orig_image.getDT();
// dt = orig_image.getDT();
}
if (alt_image != null) {
String alt_path = getAltPath(path);
......@@ -577,7 +590,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
return null;
}
orig_image = new FloatImageData(path);
dt = orig_image.getDT();
// dt = orig_image.getDT();
}
return orig_image;
}
......@@ -654,7 +667,8 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
return ts;
}
public LocalDateTime getLocalDateTime() {
return dt;
return getImage().getDT();
// return dt;
}
public String getName() {
......@@ -974,11 +988,11 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
return false;
}
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;
}
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;
}
if (images.get(zoom_level) != null) {
......@@ -1085,7 +1099,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
final float [] felev = src_elev.readFData();
final double [] elev = new double [tilesX*tilesY];
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 Thread[] threads = ImageDtt.newThreadArray();
......
......@@ -84,33 +84,35 @@ public class OrthoMapsCollection implements Serializable{
"kernelsDirectory", "patternsDirectory"};
public static final String [] NAME_FH = {"full","half"};
public static final String [] NAME_MO = {"main","other"};
public OrthoMap [] ortho_maps;
private HashMap<String,ModelRegex> model_regexes;
private String current_model_regex="";
private ArrayList<AltitudeMismatchKernel> kernels;
private ArrayList<GroundObjectPattern> patterns;
// real transient:
public transient long version = -1;
OrthoMap [] ortho_maps;
// remove some transients
transient HashMap<Double,Integer> map_index;
transient HashMap<String,Integer> map_index_string;
transient ArrayList<AltitudeMismatchKernel> kernels;
transient ArrayList<GroundObjectPattern> patterns;
transient HashMap<String,ModelRegex> model_regexes;
transient String current_model_regex="";
private transient HashMap<Double,Integer> map_index;
private transient HashMap<String,Integer> map_index_string;
private void writeObject(ObjectOutputStream oos) throws IOException { // ?
oos.defaultWriteObject();
oos.writeObject(AltitudeMismatchKernel.getKernelsDirectory());
oos.writeObject(kernels);
// oos.writeObject(kernels);
oos.writeObject(GroundObjectPattern.getPatternsDirectory());
oos.writeObject(patterns);
// oos.writeObject(patterns);
// oos.writeObject(path);
// ortho_maps is not transient
}
@SuppressWarnings("unchecked")
// @SuppressWarnings("unchecked")
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject();
AltitudeMismatchKernel.setKernelsDirectory((String) ois.readObject());
kernels = (ArrayList<AltitudeMismatchKernel>) ois.readObject();
// kernels = (ArrayList<AltitudeMismatchKernel>) ois.readObject();
GroundObjectPattern.setPatternsDirectory((String) ois.readObject());
patterns = (ArrayList<GroundObjectPattern>) ois.readObject();
// patterns = (ArrayList<GroundObjectPattern>) ois.readObject();
reindex(); // will recreate map_index, map_index_string
// lla is not transient
......@@ -131,7 +133,10 @@ public class OrthoMapsCollection implements Serializable{
kernels, // ArrayList<AltitudeMismatchKernel> kernels,
patterns, // ArrayList<GroundObjectPattern> patterns);
model_regexes, // ArrayList<ModelRegex> model_regexes,
regex_use_p); // String [] regex_use) {
regex_use_p, // String [] regex_use) {
null, // ArrayList<AffineImport> affine_import,
null); // ArrayList<Affine2Import> affine2_import) {
current_model_regex = regex_use_p[0];
paths = ModelRegex.removeDuplicatesSort(paths);
String [] orig_paths = paths.clone();
......@@ -169,7 +174,7 @@ public class OrthoMapsCollection implements Serializable{
if (indx >= 0) {
OrthoMap omap = orthoMapsCollection.ortho_maps[indx];
omap.orig_image = new FloatImageData(path); // always replace (nothing to preserve
omap.dt = omap.orig_image.getDT(); // just in case?
/// omap.dt = omap.orig_image.getDT(); // just in case?
// see if alt image is already initialized
if (omap.alt_image != null) {
FloatImageData alt_image = OrthoMap.getAlt(path);
......@@ -201,6 +206,7 @@ public class OrthoMapsCollection implements Serializable{
Arrays.sort(ortho_maps); // mixed old+new, previous scene numbers will no longer be valui
orthoMapsCollection.ortho_maps = ortho_maps;
orthoMapsCollection.reindex();
} else {
System.out.println("No new scenes added");
}
......@@ -218,6 +224,11 @@ public class OrthoMapsCollection implements Serializable{
}
}
public OrthoMap getMap(String name) {
int indx = getIndex(name);
if (indx < 0) return null;
return ortho_maps[indx];
}
public static double [][] unityAffine() {
return new double [][] {{1,0,0},{0,1,0}};
......@@ -243,7 +254,9 @@ public class OrthoMapsCollection implements Serializable{
kernels, // ArrayList<AltitudeMismatchKernel> kernels,
null, // ArrayList<GroundObjectPattern> patterns);
null, // ArrayList<ModelRegex> model_regexes,
null); // String [] regex_use) {
null, // String [] regex_use) {
null, // ArrayList<AffineImport> affine_import,
null); // ArrayList<Affine2Import> affine2_import) {
} else {
System.out.println("updateKernels(): path should end with \".list\"");
}
......@@ -259,7 +272,9 @@ public class OrthoMapsCollection implements Serializable{
null, // ArrayList<AltitudeMismatchKernel> kernels,
patterns, // ArrayList<GroundObjectPattern> patterns);
null, // ArrayList<ModelRegex> model_regexes,
null); // String [] regex_use) {
null, // String [] regex_use) {
null, // ArrayList<AffineImport> affine_import,
null); // ArrayList<Affine2Import> affine2_import) {
} else {
System.out.println("updatePatterns(): path should end with \".list\"");
......@@ -297,6 +312,7 @@ public class OrthoMapsCollection implements Serializable{
map_index.put(ortho_maps[i].getTimeStamp(), i);
map_index_string.put(ortho_maps[i].name,i);
}
// updateNumberScenes();
return ortho_maps.length;
}
......@@ -319,7 +335,7 @@ public class OrthoMapsCollection implements Serializable{
}
}
public void updateLLa() { // make automatic by saving/testing file modification stamp?
public void updateLLA() { // make automatic by saving/testing file modification stamp?
for (int n = 0; n < ortho_maps.length; n++) {
if (n == 530) {
System.out.println("updateLLa(): n="+n);
......@@ -362,7 +378,9 @@ public class OrthoMapsCollection implements Serializable{
ArrayList<AltitudeMismatchKernel> kernels,
ArrayList<GroundObjectPattern> patterns,
HashMap<String,ModelRegex> model_regexes,
String [] regex_use) {
String [] regex_use,
ArrayList<AffineImport> affine_import,
ArrayList<Affine2Import> affine2_import) {
List<String> lines;
List<String> rel_files = new ArrayList<String>();
Path seq_path = Paths.get(files_list);
......@@ -404,7 +422,6 @@ public class OrthoMapsCollection implements Serializable{
tokens[3],
LocalDateTime.parse(tokens[4])));
}
} else if ((tokens.length > 0) && (tokens[0].toUpperCase().equals("REGEX"))) {
if ((model_regexes != null) && (tokens.length > 4)) {
model_regexes.put(tokens[1],new ModelRegex(
......@@ -417,6 +434,15 @@ public class OrthoMapsCollection implements Serializable{
if ((regex_use != null) && (tokens.length > 1)) {
regex_use[0] = tokens[1];
}
} else if ((tokens.length > 0) && AffineImport.matches(tokens)) {
if (affine_import != null) {
affine_import.add(new AffineImport(tokens));
}
} else if ((tokens.length > 0) && Affine2Import.matches(tokens)) {
if (affine2_import != null) {
affine2_import.add(new Affine2Import(tokens));
}
} else if ((tokens.length == 1) && (tokens[0].length() > 0)) {
rel_files.add(tokens[0]);
}
......@@ -639,7 +665,7 @@ public class OrthoMapsCollection implements Serializable{
for (ObjectLocation ol: objects) {
int nmap =getIndex(ol.getName());
final double scale = 1.0/OrthoMap.getPixelSizeMeters(zoom_level);
final double src_scale = 1.0/OrthoMap.getPixelSizeMeters(ortho_maps[nmap].orig_zoom_level); // pix per meter
final double src_scale = 1.0/OrthoMap.getPixelSizeMeters(ortho_maps[nmap].getImage().getZoomLevel()); // pix per meter
double [][] mbounds = ortho_maps[nmap].getBoundsMeters(true); // keep original bounds
double [] enu_offset = ortho_maps[reference_index].enuOffsetTo(ortho_maps[nmap]);
double [] scaled_out_center = { // xy center to apply affine to
......@@ -921,7 +947,9 @@ public class OrthoMapsCollection implements Serializable{
final double [][] affine = (affines !=null) ? affines[indx]: ortho_maps[nmap].affine; // only here use provided
Arrays.fill(fpixels[findx], Float.NaN);
final double scale = 1.0/OrthoMap.getPixelSizeMeters(zoom_level);
final double src_scale = 1.0/OrthoMap.getPixelSizeMeters(ortho_maps[nmap].orig_zoom_level); // pix per meter
// final int orig_zoom_level = getOriginalZoomLevel()
final int orig_zoom_level = use_alt? ortho_maps[nmap].getAlt().getZoomLevel(): ortho_maps[nmap].getImage().getZoomLevel();
final double src_scale = 1.0/OrthoMap.getPixelSizeMeters(orig_zoom_level); // pix per meter
// double [][] mbounds = ortho_maps[nmap].getBoundsMeters(true); // keep original bounds
double [][] mbounds = ortho_maps[nmap].getBoundsMeters(true,affine); // keep original bounds
double [] enu_offset = ortho_maps[indices[0]].enuOffsetTo(ortho_maps[nmap]);
......@@ -1082,7 +1110,9 @@ public class OrthoMapsCollection implements Serializable{
final double [] equalize = ignore_equalize ? null:((equalize_in != null) ? equalize_in[indx] : ortho_maps[nmap].equalize);
Arrays.fill(dpixels[findx], Float.NaN);
final double scale = 1.0/OrthoMap.getPixelSizeMeters(zoom_level);
final double src_scale = 1.0/OrthoMap.getPixelSizeMeters(ortho_maps[nmap].orig_zoom_level); // pix per meter
final int orig_zoom_level = use_alt? ortho_maps[nmap].getAlt().getZoomLevel(): ortho_maps[nmap].getImage().getZoomLevel();
final double src_scale = 1.0/OrthoMap.getPixelSizeMeters(orig_zoom_level); // pix per meter
// final double src_scale = 1.0/OrthoMap.getPixelSizeMeters(ortho_maps[nmap].orig_zoom_level); // pix per meter
// metric bounds of the rectified image relative to its origin
/// double [][] mbounds = ortho_maps[nmap].getBoundsMeters(true); // keep original bounds
double [][] mbounds = ortho_maps[nmap].getBoundsMeters(true,affine); // keep original bounds
......@@ -1195,10 +1225,14 @@ public class OrthoMapsCollection implements Serializable{
public int getIndex(String sindx) {
return map_index_string.get(sindx);
Integer indx = map_index_string.get(sindx);
if (indx == null) {
return -1;
}
return indx;
}
/*
public float [][] getPaddedPairGPU(
String [] spair,
int zoom_lev){
......@@ -1221,6 +1255,7 @@ public class OrthoMapsCollection implements Serializable{
}
return gpu_pair_img;
}
*/
public PairwiseOrthoMatch SpiralMatch (
......@@ -2375,36 +2410,11 @@ public class OrthoMapsCollection implements Serializable{
// try reading current_version, if fails - restart without it (for older formats)
FileInputStream fileInputStream = new FileInputStream(path);
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
int current_version = -1;
OrthoMapsCollection orthoMapsCollection = null;
PairwiseOrthoMatch.READ_NO_ALT = true; // reading old version
Object obj = objectInputStream.readObject(); // reads OrthoMapsCollection
/* // do not handle that intermediate version
try {
obj = objectInputStream.readObject(); // reads OrthoMapsCollection
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
fileInputStream.reset();
System.out.println("readOrthoMapsCollection(): error reading stream, using current_version="+current_version);
PairwiseOrthoMatch.READ_NO_ALT = false; // reading new version
obj = objectInputStream.readObject(); // reads OrthoMapsCollection
}
*/
PairwiseOrthoMatch.READ_NO_ALT = false; // reading new version
if (obj instanceof OrthoMapsCollection) {
orthoMapsCollection = (OrthoMapsCollection) obj;
System.out.println("readOrthoMapsCollection(): got old version, using current_version="+current_version);
} else {
current_version = (int) obj;
int current_version = (int) objectInputStream.readObject(); // reads OrthoMapsCollection
OrthoMapsCollection.CURRENT_VERSION = current_version; // trying here 08.29.2024 - before orthoMapsCollection exists
System.out.println("readOrthoMapsCollection(): got current_version="+current_version);
PairwiseOrthoMatch.READ_NO_ALT = false; // reading new version
orthoMapsCollection = (OrthoMapsCollection) objectInputStream.readObject();
}
OrthoMapsCollection orthoMapsCollection = (OrthoMapsCollection) objectInputStream.readObject();
objectInputStream.close();
/// orthoMapsCollection.current_version = current_version;
System.out.println("readOrthoMapsCollection(): got orthoMapsCollection, current_version="+current_version);
return orthoMapsCollection;
}
......@@ -2412,10 +2422,7 @@ public class OrthoMapsCollection implements Serializable{
public void writeOrthoMapsCollection (String path) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(path);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
/// current_version = LATEST_VERSION;
objectOutputStream.writeObject(LATEST_VERSION); // current_version);
objectOutputStream.writeObject(this);
objectOutputStream.flush();
objectOutputStream.close();
......
......@@ -32,20 +32,61 @@ import Jama.Matrix;
public class PairwiseOrthoMatch implements Serializable {
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];
public transient double [][] jtj = new double [6][6];
public int zoom_lev;
public double rms = Double.NaN;
public transient double overlap = 0.0;
public transient double [] alt_data = null;
public transient 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 transient double [][] qaffine = null; // affine relative to rotated scenes
public double overlap = 0.0;
public double [] alt_data = null;
public double [] equalize1to0 = {1,0}; // value1 = equalize2to1[0]*value2+equalize2to1[1]
public double [] quat = null; // relative orientation of the second scene (ERS affine removed). Will be eventually saved
public double [][] qaffine = null; // affine relative to rotated scenes
// real transient
public transient double [][] jtj = new double [6][6];
// below - not saved/restored
public transient boolean ok = false; // not saved/restored
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() {
return quat;
}
......@@ -95,6 +136,11 @@ public class PairwiseOrthoMatch implements Serializable {
public boolean isDefined() {
return affine != null;
}
public boolean isAffineNonTrivial() {
return OrthoMap.isAffineNonTrivial(this.affine);
}
public double [] getEqualize2to1() {
return equalize1to0;
}
......@@ -298,42 +344,5 @@ public class PairwiseOrthoMatch implements Serializable {
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
}
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