Commit 36dcabff authored by Andrey Filippov's avatar Andrey Filippov

modifying for non-quad (sym <->vect and derivatives still remain)

parent 0895e5a9
......@@ -7,6 +7,7 @@ import java.nio.ByteOrder;
import java.nio.channels.Channels;
import java.nio.channels.WritableByteChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Properties;
import com.elphel.imagej.common.GenericJTabbedDialog;
......@@ -52,9 +53,7 @@ public class GeometryCorrection {
// use static CorrVector.getCorrNames(numSensors)
// or non-static corrVector.getCorrNames();
public String [] getCorrNames() {
return CorrVector.getCorrNames(numSensors);
}
/*
static final String [] CORR_NAMES = { // need to be fixed too!
"tilt0","tilt1","tilt2",
"azimuth0","azimuth1","azimuth2",
......@@ -62,7 +61,7 @@ public class GeometryCorrection {
"zoom0","zoom1","zoom2",
"omega_tilt", "omega_azimuth", "omega_roll",
"velocity_x", "velocity_y", "velocity_z"};
*/
public int debugLevel = 0;
public double line_time = 36.38E-6; // 26.5E-6; // duration of sensor scan line (for ERS) Wrong, 36.38us (change and re-run ERS
public int pixelCorrectionWidth=2592; // virtual camera center is at (pixelCorrectionWidth/2, pixelCorrectionHeight/2)
......@@ -141,6 +140,49 @@ public class GeometryCorrection {
public int [] woi_tops = null; // used to calculate scanline timing
public int [] camera_heights = null; // actual acquired lines (from woi_tops)
public String [] getCorrNames() {
return CorrVector.getCorrNames(numSensors);
}
// Removing dependence on CORR_NAMES in QuadCLTCPU
public void setPropertiesExtrinsic(String prefix, Properties properties) {
String [] corr_names = getCorrNames(); // variable number of cameras
for (int i = 0; i < corr_names.length; i++){
String name = prefix+"extrinsic_corr_"+corr_names[i];
properties.setProperty(name, getCorrVector().toArray()[i]+"");
}
}
public static void setPropertiesExtrinsic(String prefix, Properties properties, double [] extrinsic_corr) {
int num_cams = CorrVector.getCamerasFromEV(extrinsic_corr.length);
String [] corr_names = CorrVector.getCorrNames(num_cams); // variable number of cameras
for (int i = 0; i < corr_names.length; i++){
String name = prefix+"extrinsic_corr_"+corr_names[i];
if (!Double.isNaN( extrinsic_corr[i])) {
properties.setProperty(name, extrinsic_corr[i]+"");
}
}
}
public static double [] getPropertiesExtrinsic(String prefix, Properties properties) {
// determine number of cameras from maximal tilt?
int num_chn = 4;
for (; true; num_chn++) {
String name = prefix+"extrinsic_corr_"+CorrVector.CORR_TILT+(num_chn - 1); // maximal tilt index = N-2 (tilt2 for quad)
if (properties.getProperty(name) == null) {
break;
}
}
String [] corr_names = CorrVector.getCorrNames(num_chn);
double [] extrinsic_vect = new double [corr_names.length];
Arrays.fill(extrinsic_vect, Double.NaN);
for (int i = 0; i < extrinsic_vect.length; i++) {
String name = prefix+"extrinsic_corr_"+corr_names[i];
if (properties.getProperty(name)!=null) {
extrinsic_vect[i] = Double.parseDouble(properties.getProperty(name));
}
}
return extrinsic_vect;
}
public float [] toFloatArray() { // for GPU comparison
return new float[] {
......
......@@ -110,7 +110,7 @@ public class QuadCLTCPU {
public EyesisCorrectionParameters.CorrectionParameters correctionsParameters=null;
double [][][][][][] clt_kernels = null; // can be used to determine monochrome too?
public GeometryCorrection geometryCorrection = null;
double [] extrinsic_vect = new double [GeometryCorrection.CORR_NAMES.length]; // extrinsic corrections (needed from properties, before geometryCorrection
double[] extrinsic_vect; // = new double [GeometryCorrection.CORR_NAMES.length]; // extrinsic corrections (needed from properties, before geometryCorrection
public int extra_items = 8; // number of extra items saved with kernels (center offset (partial, full, derivatives)
public ImagePlus eyesisKernelImage = null;
public long startTime; // start of batch processing
......@@ -666,10 +666,13 @@ public class QuadCLTCPU {
if (gc == null) { // if it was not yet created
gc = new GeometryCorrection(this.extrinsic_vect); // not used in lwir
}
gc.setPropertiesExtrinsic(prefix, properties);
/*
for (int i = 0; i < GeometryCorrection.CORR_NAMES.length; i++){
String name = prefix+"extrinsic_corr_"+GeometryCorrection.CORR_NAMES[i];
properties.setProperty(name, gc.getCorrVector().toArray()[i]+"");
}
*/
if (is_aux && (gc.rigOffset != null)) {
gc.rigOffset.setProperties(prefix,properties);
}
......@@ -697,10 +700,16 @@ public class QuadCLTCPU {
}
}
}
/*
GeometryCorrection gc = geometryCorrection;
if (gc == null) { // if it was not yet created
gc = new GeometryCorrection(this.extrinsic_vect);
}
*/
double [] other_extrinsic_vect = GeometryCorrection.getPropertiesExtrinsic(other_prefix, other_properties);
int num_cams = CorrVector.getCamerasFromEV(other_extrinsic_vect.length);
GeometryCorrection.setPropertiesExtrinsic(this_prefix, properties, other_extrinsic_vect);
/*
for (int i = 0; i < GeometryCorrection.CORR_NAMES.length; i++){
String other_name = other_prefix+"extrinsic_corr_"+GeometryCorrection.CORR_NAMES[i];
if (other_properties.getProperty(other_name)!=null) {
......@@ -713,6 +722,7 @@ public class QuadCLTCPU {
properties.setProperty(this_name, gc.getCorrVector().toArray()[i]+"");
// System.out.println("copyPropertiesFrom():"+i+": setProperty("+this_name+","+gc.getCorrVector().toArray()[i]+"");
}
*/
// System.out.println("Done copyPropertiesFrom");
}
......@@ -751,6 +761,21 @@ public class QuadCLTCPU {
}
}
// always set extrinsic_corr
double [] new_extrinsic_vect = GeometryCorrection.getPropertiesExtrinsic(prefix, properties);
int num_cams = CorrVector.getCamerasFromEV(new_extrinsic_vect.length);
for (int i = 0; i < new_extrinsic_vect.length; i++) {
if (!Double.isNaN(new_extrinsic_vect[i])) {
if (this.extrinsic_vect == null) { // not used in lwir
// only create non-null array if there are saved values
this.extrinsic_vect = new_extrinsic_vect.clone();
}
this.extrinsic_vect[i] = new_extrinsic_vect[i];
if (geometryCorrection != null){ // not used in lwir
geometryCorrection.setCorrVector(i,this.extrinsic_vect[i]); // should be same mumber of cameras
}
}
}
/*
for (int i = 0; i < GeometryCorrection.CORR_NAMES.length; i++){
String name = prefix+"extrinsic_corr_"+GeometryCorrection.CORR_NAMES[i];
if (properties.getProperty(name)!=null) {
......@@ -759,20 +784,12 @@ public class QuadCLTCPU {
this.extrinsic_vect = new double [GeometryCorrection.CORR_NAMES.length];
}
this.extrinsic_vect[i] = Double.parseDouble(properties.getProperty(name));
// System.out.println("getProperties():"+i+": getProperty("+name+") -> "+properties.getProperty(name)+"");
if (geometryCorrection != null){ // not used in lwir
// if (geometryCorrection.getCorrVector().toArray() == null) {
// geometryCorrection.resetCorrVector(); // make it array of zeros
// }
// geometryCorrection.getCorrVector().toArray()[i] = this.extrinsic_vect[i];
geometryCorrection.setCorrVector(i,this.extrinsic_vect[i]);
}
}
}
// if (is_aux && (geometryCorrection != null)) {
// geometryCorrection.setRigOffsetFromProperies(prefix, properties);
// }
*/
if (geometryCorrection == null) {
double [] extrinsic_vect_saved = this.extrinsic_vect.clone();
......@@ -846,11 +863,11 @@ public class QuadCLTCPU {
// TODO: Verify correction sign!
double f_avg = geometryCorrection.getCorrVector().setZoomsFromF(
sensors[0].focalLength,
sensors[1].focalLength,
sensors[2].focalLength,
sensors[3].focalLength);
double [] f_lengths = new double [sensors.length];
for (int i = 0; i < f_lengths.length; i++) {
f_lengths[i] = sensors[i].focalLength;
}
double f_avg = geometryCorrection.getCorrVector().setZoomsFromF(f_lengths);
// following parameters are used for scaling extrinsic corrections
geometryCorrection.focalLength = f_avg;
......@@ -875,28 +892,13 @@ public class QuadCLTCPU {
sensors[0].pixelCorrectionHeight,
sensors[0].pixelSize);
// set other/individual sensor parameters
/*
for (int i = 1; i < numSensors; i++){
if ( (sensors[0].theta != sensors[i].theta) || // elevation
(sensors[0].heading != sensors[i].heading)){
System.out.println("initGeometryCorrection(): All sensors have to have the same elevation and heading, but channels 0 and "+i+" mismatch");
return false;
}
}
*/
double theta_avg = geometryCorrection.getCorrVector().setTiltsFromThetas(
sensors[0].theta,
sensors[1].theta,
sensors[2].theta,
sensors[3].theta);
double heading_avg = geometryCorrection.getCorrVector().setAzimuthsFromHeadings(
sensors[0].heading,
sensors[1].heading,
sensors[2].heading,
sensors[3].heading);
double [] thetas = new double [sensors.length];
for (int i = 0; i < thetas.length; i++) thetas[i] = sensors[i].theta;
double theta_avg = geometryCorrection.getCorrVector().setTiltsFromThetas(thetas);
double [] headings = new double [sensors.length];
for (int i = 0; i < headings.length; i++) headings[i] = sensors[i].heading;
double heading_avg = geometryCorrection.getCorrVector().setAzimuthsFromHeadings(headings);
double [] forward = new double[numSensors];
double [] right = new double[numSensors];
double [] height = new double[numSensors];
......
package com.elphel.imagej.tileprocessor;
import java.util.ArrayList;
import java.util.HashMap;
/**
**
......@@ -62,10 +63,47 @@ public class SymmVector {
private int num_rz_defined; // number of defined rz_indices
private boolean [] used_rz_indices;// already used rz_vectors
private double [] cumul_rz_influences; // will not work? - all candidates correlate the same
public int debug_level = -1;
// caching results of vectors generation for used camera configuration not to re-generate each time
// CorrVector is constructed
public static HashMap <Integer,SymmVectorsSet> vectors_cache = new HashMap <Integer,SymmVectorsSet>();
public static SymmVectorsSet getSymmVectorsSet (int num_cameras) {
SymmVectorsSet rvs = vectors_cache.get(num_cameras);
if (rvs == null) {
rvs = newVectors (num_cameras);
vectors_cache.put(num_cameras, rvs);
}
return rvs;
}
public int debug_level = -1;
public static double [][] getSymmXY(int num_cameras){
SymmVectorsSet rvs = vectors_cache.get(num_cameras);
if (rvs == null) {
rvs = newVectors (num_cameras);
vectors_cache.put(num_cameras, rvs);
}
return rvs.xy;
}
public static SymmVectorsSet newVectors (int num_cameras) {
boolean full_type1 = false;
boolean full_type2 = false;
int debug_level = -1;
SymmVectorsSet rvs = new SymmVectorsSet();
SymmVector sv = new SymmVector(
num_cameras,
full_type1,
full_type2,
debug_level);
rvs.xy = sv.exportXY();
rvs.rt = sv.exportRT();
rvs.dir_rt = sv.exportDirRT();
rvs.rots = sv.exportRZ(false); // include common roll
rvs.zooms = sv.exportRZ(true); // no common zoom
return rvs;
}
public SymmVector (
int num_cameras,
......@@ -343,6 +381,18 @@ public class SymmVector {
return rslt;
}
/**
* Export directions (0 - radial to center, 1 - tangential CW, 2 - radial out , 3 tangential CW
* @return
*/
public int [][] exportDirRT(){
int [][] rslt = new int[sym_indices.length][];
for (int n = 0; n < sym_indices.length; n++){
rslt[n]= proto_all[sym_indices[n]];
}
return rslt;
}
/**
*
* @param zoom_mode
......@@ -1064,3 +1114,12 @@ public class SymmVector {
*/
}
class SymmVectorsSet {
// int num_sensors;
double [][] xy;
double [][] rt;
int [][] dir_rt;
double [][] rots;
double [][] zooms;
}
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