Commit 2b8ae048 authored by Andrey Filippov's avatar Andrey Filippov

Before updating IMS interpolation

parent 726f4add
......@@ -103,7 +103,12 @@ public class EyesisCorrectionParameters {
public String sourceSequencesList= "";
public boolean useSourceList= false;
public String sourceImsDirectory= ""; // source IMS log files
// public String sourceImsDirectory= ""; // source IMS log files
public String imsRootDirectory= ""; // source IMS log files
public String imsDataSubdirectory= "data"; // source IMS log files relative to imsRootDirectory
public String imsPrintSubdirectory= "print"; // directory to print DiD-s in human-readable format
public String imsSuffix= "-ims.corr-xml"; // model subdirectory to store IMS data
public String egomotionSuffix= "-egomotion.csv"; // Egomotion table
public String sourcePrefix= "";
public String sourceSuffix= ".tiff"; //".jp4"
......@@ -205,6 +210,7 @@ public class EyesisCorrectionParameters {
public String x3dModelVersion="v01";
public String jp4SubDir="jp4"; // FIXME:
public String linkedModels=""; // linked models with reference scenes
public String x3dDirectory="";
......@@ -279,7 +285,12 @@ public class EyesisCorrectionParameters {
cp.sourceSequencesList= this.sourceSequencesList;
cp.useSourceList= this.useSourceList;
cp.sourceImsDirectory= this.sourceImsDirectory;
/// cp.sourceImsDirectory= this.sourceImsDirectory;
cp.imsRootDirectory = this.imsRootDirectory;
cp.imsDataSubdirectory = this.imsDataSubdirectory;
cp.imsPrintSubdirectory = this.imsPrintSubdirectory;
cp.imsSuffix = this.imsSuffix;
cp.egomotionSuffix = this.egomotionSuffix;
cp.tile_processor_gpu = this.tile_processor_gpu;
cp.use_set_dirs = this.use_set_dirs;
......@@ -473,7 +484,12 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"sourceSequencesList",this.sourceSequencesList);
properties.setProperty(prefix+"useSourceList",this.useSourceList+"");
properties.setProperty(prefix+"sourceImsDirectory",this.sourceImsDirectory);
/// properties.setProperty(prefix+"sourceImsDirectory",this.sourceImsDirectory);
properties.setProperty(prefix+"imsRootDirectory", this.imsRootDirectory);
properties.setProperty(prefix+"imsDataSubdirectory", this.imsDataSubdirectory);
properties.setProperty(prefix+"imsPrintSubdirectory",this.imsPrintSubdirectory);
properties.setProperty(prefix+"imsSuffix", this.imsSuffix);
properties.setProperty(prefix+"egomotionSuffix", this.egomotionSuffix);
properties.setProperty(prefix+"tile_processor_gpu",this.tile_processor_gpu);
......@@ -664,7 +680,13 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"sourceDirectory")!= null) this.sourceDirectory=properties.getProperty(prefix+"sourceDirectory");
if (properties.getProperty(prefix+"sourceSequencesList")!= null) this.sourceSequencesList=properties.getProperty(prefix+"sourceSequencesList");
if (properties.getProperty(prefix+"useSourceList")!=null) this.useSourceList=Boolean.parseBoolean(properties.getProperty(prefix+"useSourceList")); // save 32-bit tiff also if the end result is 8 or 16 bit
if (properties.getProperty(prefix+"sourceImsDirectory")!= null) this.sourceImsDirectory=properties.getProperty(prefix+"sourceImsDirectory");
/// if (properties.getProperty(prefix+"sourceImsDirectory")!= null) this.sourceImsDirectory=properties.getProperty(prefix+"sourceImsDirectory");
if (properties.getProperty(prefix+"imsRootDirectory")!= null) this.imsRootDirectory =properties.getProperty(prefix+"imsRootDirectory");
if (properties.getProperty(prefix+"imsDataSubdirectory")!= null) this.imsDataSubdirectory =properties.getProperty(prefix+"imsDataSubdirectory");
if (properties.getProperty(prefix+"imsPrintSubdirectory")!= null) this.imsPrintSubdirectory=properties.getProperty(prefix+"imsPrintSubdirectory");
if (properties.getProperty(prefix+"imsSuffix")!= null) this.imsSuffix=properties.getProperty(prefix+"imsSuffix");
if (properties.getProperty(prefix+"egomotionSuffix")!=null) this.egomotionSuffix=properties.getProperty(prefix+"egomotionSuffix");
if (properties.getProperty(prefix+"tile_processor_gpu")!= null) this.tile_processor_gpu=properties.getProperty(prefix+"tile_processor_gpu");
if (properties.getProperty(prefix+"firstSubCamera")!= null) this.firstSubCamera=Integer.parseInt(properties.getProperty(prefix+"firstSubCamera"));
if (properties.getProperty(prefix+"firstSubCameraConfig")!= null) this.firstSubCameraConfig=Integer.parseInt(properties.getProperty(prefix+"firstSubCameraConfig"));
......@@ -871,9 +893,16 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Select source directory", false);
gd.addCheckbox ("Use individual subdirectory for image set", this.use_set_dirs);
gd.addStringField ("Source IMS logs directory", this.sourceImsDirectory, 80); // 10?
gd.addCheckbox ("Select IMS logs directory", false); // 10?
/// gd.addStringField ("Source IMS logs directory", this.sourceImsDirectory, 80); // 10?
/// gd.addCheckbox ("Select IMS logs directory", false); // 10?
gd.addStringField ("IMS root directory", this.imsRootDirectory, 80); // 10?
gd.addCheckbox ("Select IMS root directory", false); // 10?
gd.addStringField ("IMS source logs subdirectory", this.imsDataSubdirectory, 80); // 10?
gd.addStringField ("IMS print human-readable subdirectory", this.imsPrintSubdirectory, 80);
gd.addStringField ("IMS data suffix", this.imsSuffix, 80);
gd.addStringField ("Egomotion table filename suffix", this.egomotionSuffix, 80);
gd.addStringField ("Source sequences list file", this.sourceSequencesList, 80);
gd.addCheckbox ("Select source sequences file", false);
gd.addCheckbox ("Use source list to iterate multiple sequences", this.useSourceList);
......@@ -1017,12 +1046,16 @@ public class EyesisCorrectionParameters {
this.sourceDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectSourceDirectory(false, false);
this.use_set_dirs = gd.getNextBoolean();
this.sourceImsDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectSourceImsDirectory(false, false); // 3
/// this.sourceImsDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectSourceImsDirectory(false, false); // 3
this.imsRootDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectImsRootDirectory(false, false); // 3
this.imsDataSubdirectory= gd.getNextString();
this.imsPrintSubdirectory= gd.getNextString();
this.imsSuffix= gd.getNextString();
this.egomotionSuffix= gd.getNextString();
this.sourceSequencesList= gd.getNextString(); if (gd.getNextBoolean()) selectSourceSequencesList(false, false);
this.useSourceList = gd.getNextBoolean();
this.sensorDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectSensorDirectory(false, false);
this.sharpKernelDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectSharpKernelDirectory(false, false);
this.smoothKernelDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectSmoothKernelDirectory(false, true);
......@@ -1097,8 +1130,14 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Select source directory", false); // 3
gd.addCheckbox ("Use individual subdirectory for each image set (timestamp as name)", this.use_set_dirs); //10
gd.addStringField ("Source IMS logs directory", this.sourceImsDirectory, 80); // 10?
gd.addCheckbox ("Select IMS logs directory", false); // 10?
/// gd.addStringField ("Source IMS logs directory", this.sourceImsDirectory, 80); // 10?
/// gd.addCheckbox ("Select IMS logs directory", false); // 10?
gd.addStringField ("IMS root directory", this.imsRootDirectory, 80); // 10?
gd.addCheckbox ("Select IMS root directory", false); // 10?
gd.addStringField ("IMS source logs subdirectory", this.imsDataSubdirectory, 80); // 10?
gd.addStringField ("IMS print human-readable subdirectory", this.imsPrintSubdirectory, 80); // 10?
gd.addStringField ("IMS data suffix", this.imsSuffix, 80);
gd.addStringField ("Egomotion table filename suffix", this.egomotionSuffix, 80);
gd.addStringField ("Source sequences list file", this.sourceSequencesList, 80); // 10x
gd.addCheckbox ("Select source sequences file", false); // 10y
......@@ -1275,7 +1314,12 @@ public class EyesisCorrectionParameters {
this.sourceDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectSourceDirectory(false, false); // 3
this.use_set_dirs = gd.getNextBoolean();
this.sourceImsDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectSourceImsDirectory(false, false); // 3
// this.sourceImsDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectImsRootDirectory(false, false); // 3
this.imsRootDirectory= gd.getNextString(); if (gd.getNextBoolean()) selectImsRootDirectory(false, false); // 3
this.imsDataSubdirectory= gd.getNextString();
this.imsPrintSubdirectory= gd.getNextString();
this.imsSuffix= gd.getNextString();
this.egomotionSuffix= gd.getNextString();
this.sourceSequencesList= gd.getNextString(); if (gd.getNextBoolean()) selectSourceSequencesList(false, false); // 10x,10y
this.useSourceList = gd.getNextBoolean(); // 10z
......@@ -2221,18 +2265,41 @@ public class EyesisCorrectionParameters {
return dir;
}
public String selectSourceImsDirectory(boolean smart, boolean newAllowed) { // normally newAllowed=false
public String selectImsRootDirectory(boolean smart, boolean newAllowed) { // normally newAllowed=false
String dir= CalibrationFileManagement.selectDirectory(
smart,
newAllowed, // save
"Source (acquired from the camera) IMS logs directory", // title
"Select source IMS directory", // button
"IMS root directory", // title
"Select IMS root directory", // button
null, // filter
this.sourceImsDirectory); // this.sourceDirectory);
if (dir!=null) this.sourceImsDirectory=dir;
this.imsRootDirectory); // this.sourceDirectory);
if (dir!=null) {
while (dir.endsWith(Prefs.getFileSeparator())) {
dir=dir.substring(0, dir.length()-1);
}
this.imsRootDirectory=dir;
}
return dir;
}
public String getImsSourceDirectory() {
while (this.imsDataSubdirectory.startsWith(Prefs.getFileSeparator())) {
this.imsDataSubdirectory=this.imsDataSubdirectory.substring(1);
}
while (this.imsDataSubdirectory.endsWith(Prefs.getFileSeparator())) {
this.imsDataSubdirectory=this.imsDataSubdirectory.substring(0, this.imsDataSubdirectory.length()-1);
}
return this.imsRootDirectory + Prefs.getFileSeparator() + this.imsDataSubdirectory;
}
public String getImsPrintDirectory() {
while (this.imsPrintSubdirectory.startsWith(Prefs.getFileSeparator())) {
this.imsPrintSubdirectory=this.imsPrintSubdirectory.substring(1);
}
while (this.imsPrintSubdirectory.endsWith(Prefs.getFileSeparator())) {
this.imsPrintSubdirectory=this.imsPrintSubdirectory.substring(0, this.imsPrintSubdirectory.length()-1);
}
return this.imsRootDirectory + Prefs.getFileSeparator() + this.imsPrintSubdirectory;
}
public String selectSourceSequencesList(boolean smart, boolean newAllowed) { // normally newAllowed=false
......@@ -2407,9 +2474,9 @@ public class EyesisCorrectionParameters {
null, // filter
name); //this.x3dDirectory + Prefs.getFileSeparator()+name); //this.sourceDirectory);
}
}
while (dir.endsWith(Prefs.getFileSeparator())) {
dir = dir.substring(0, dir.length()-1);
while (dir.endsWith(Prefs.getFileSeparator())) {
dir = dir.substring(0, dir.length()-1);
}
}
return dir;
}
......
......@@ -411,6 +411,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
public static EyesisCorrections EYESIS_CORRECTIONS = null;
public static EyesisCorrections EYESIS_CORRECTIONS_AUX = null;
public static EyesisCorrectionParameters.EquirectangularParameters EQUIRECTANGULAR_PARAMETERS = new EyesisCorrectionParameters.EquirectangularParameters();
public static EventLogger EVENT_LOGGER = null;
public static int CONVOLVE_FFT_SIZE = 128; // FFT size for sliding convolution with kernel
public static int THREADS_MAX = 100; // testing multi-threading, limit maximal number of threads
......@@ -5523,19 +5524,22 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
DEBUG_LEVEL = MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
CLT_PARAMETERS.batch_run = true;
/*
Imx5 imx5 = new Imx5();
byte [] imx5_rslt = imx5.test_imx();
System.out.println("imx5_rslt.length="+imx5_rslt.length);
*/
// EventLogger eventLogger = new EventLogger ("/home/elphel/lwir16-proc/ims/ims_selected/");
String imx_logs = CORRECTION_PARAMETERS.sourceImsDirectory;
if ((imx_logs != null) && !imx_logs.equals("")) {
EventLogger eventLogger = new EventLogger (imx_logs);
String imx_logs = CORRECTION_PARAMETERS.getImsSourceDirectory(); // sourceImsDirectory;
if (EVENT_LOGGER == null) {
if ((imx_logs != null) && !imx_logs.equals("")) {
EVENT_LOGGER = new EventLogger (imx_logs);
} else {
System.out.println("sourceImsDirectory is not set. Use Setup CLT Batch parameters to define it.");
}
}
if (EVENT_LOGGER != null) {
EVENT_LOGGER.printPimu(CORRECTION_PARAMETERS.getImsPrintDirectory()+Prefs.getFileSeparator()+"did_pimu");
EVENT_LOGGER.printGps(CORRECTION_PARAMETERS.getImsPrintDirectory()+Prefs.getFileSeparator()+"did_gps", 7);
EVENT_LOGGER.printDidIns1(CORRECTION_PARAMETERS.getImsPrintDirectory()+Prefs.getFileSeparator()+"did_ins1");
EVENT_LOGGER.printDidIns2(CORRECTION_PARAMETERS.getImsPrintDirectory()+Prefs.getFileSeparator()+"did_ins2");
} else {
System.out.println("sourceImsDirectory is not set. Use Setup CLT Batch parameters to define it.");
System.out.println("EVENT_LOGGEER is null.");
}
return;
//JTabbedTest
// End of buttons code
......
......@@ -2,6 +2,9 @@ package com.elphel.imagej.ims;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Properties;
import com.elphel.imagej.tileprocessor.IntersceneMatchParameters;
/** (DID_GPS1_POS, DID_GPS1_UBX_POS, DID_GPS2_POS) GPS position data */
public class Did_gps_pos {
......@@ -94,10 +97,14 @@ public class Did_gps_pos {
}
public Did_gps_pos() {}
public Did_gps_pos(String prefix, Properties properties) {
getProperties(prefix, properties);
}
public Did_gps_pos interpolate(double frac, Did_gps_pos next_did) {
Did_gps_pos new_did = new Did_gps_pos();
double time_ms_this = timeOfWeekMs + Did_strobe_in_time.WEEK_MS * week;
double time_ms_next = timeOfWeekMs + Did_strobe_in_time.WEEK_MS * week;
double time_ms_next = next_did.timeOfWeekMs + Did_strobe_in_time.WEEK_MS * next_did.week;
long time_ms = (long) Did_ins.interpolateDouble(frac, time_ms_this, time_ms_next);
new_did.week = (int) Math.floor(time_ms / Did_strobe_in_time.WEEK_MS);
new_did.timeOfWeekMs = (int) (time_ms - new_did.week * Did_strobe_in_time.WEEK_MS);
......@@ -160,5 +167,46 @@ public class Did_gps_pos {
s += String.format("reserved: %d", ((int) reserved) & 0xff);
return s;
}
public void getProperties(String prefix, Properties properties) {
if (properties.getProperty(prefix+"week")!=null) this.week= Integer.parseInt(properties.getProperty(prefix+"week"));
if (properties.getProperty(prefix+"timeOfWeekMs")!=null) this.timeOfWeekMs= Integer.parseInt(properties.getProperty(prefix+"week"));
if (properties.getProperty(prefix+"status")!=null) this.status= Integer.parseInt(properties.getProperty(prefix+"status"));
if (properties.getProperty(prefix+"ecef")!=null) this.ecef= IntersceneMatchParameters.StringToDoubles(properties.getProperty(prefix+"ecef"),3);
if (properties.getProperty(prefix+"lla")!=null) this.lla= IntersceneMatchParameters.StringToDoubles(properties.getProperty(prefix+"lla"),3);
if (properties.getProperty(prefix+"hMSL")!=null) this.hMSL= Float.parseFloat(properties.getProperty(prefix+"hMSL"));
if (properties.getProperty(prefix+"hAcc")!=null) this.hAcc= Float.parseFloat(properties.getProperty(prefix+"hAcc"));
if (properties.getProperty(prefix+"vAcc")!=null) this.vAcc= Float.parseFloat(properties.getProperty(prefix+"vAcc"));
if (properties.getProperty(prefix+"pDop")!=null) this.pDop= Float.parseFloat(properties.getProperty(prefix+"pDop"));
if (properties.getProperty(prefix+"cnoMean")!=null) this.cnoMean= Float.parseFloat(properties.getProperty(prefix+"cnoMean"));
if (properties.getProperty(prefix+"towOffset")!=null) this.towOffset= Double.parseDouble(properties.getProperty(prefix+"towOffset"));
if (properties.getProperty(prefix+"leapS")!=null) this.leapS= Byte.parseByte(properties.getProperty(prefix+"leapS"));
if (properties.getProperty(prefix+"satsUsed")!=null) this.satsUsed= Byte.parseByte(properties.getProperty(prefix+"satsUsed"));
if (properties.getProperty(prefix+"cnoMeanSigma")!=null) this.cnoMeanSigma= Byte.parseByte(properties.getProperty(prefix+"cnoMeanSigma"));
if (properties.getProperty(prefix+"reserved")!=null) this.reserved= Byte.parseByte(properties.getProperty(prefix+"reserved"));
}
public Properties setProperties(String prefix, Properties properties){ // save // USED in lwir
if (properties == null) {
properties = new Properties();
}
properties.setProperty(prefix+"week", this.week+"");
properties.setProperty(prefix+"timeOfWeekMs", this.timeOfWeekMs+"");
properties.setProperty(prefix+"status", this.status+"");
properties.setProperty(prefix+"ecef", IntersceneMatchParameters.doublesToString(this.ecef));
properties.setProperty(prefix+"lla", IntersceneMatchParameters.doublesToString(this.lla));
properties.setProperty(prefix+"hMSL", this.hMSL+"");
properties.setProperty(prefix+"hAcc", this.hAcc+"");
properties.setProperty(prefix+"vAcc", this.vAcc+"");
properties.setProperty(prefix+"pDop", this.pDop+"");
properties.setProperty(prefix+"cnoMean", this.cnoMean+"");
properties.setProperty(prefix+"towOffset", this.towOffset+"");
properties.setProperty(prefix+"leapS", this.leapS+"");
properties.setProperty(prefix+"satsUsed", this.satsUsed+"");
properties.setProperty(prefix+"cnoMeanSigma", this.cnoMeanSigma+"");
properties.setProperty(prefix+"reserved", this.reserved+"");
return properties;
}
}
\ No newline at end of file
package com.elphel.imagej.ims;
import java.util.Properties;
import com.elphel.imagej.tileprocessor.IntersceneMatchParameters;
public abstract class Did_ins <T extends Did_ins <T>>{
final static int WEEK_SECONDS = 7 * 24 * 3600;
/** GPS number of weeks since January 6th, 1980 */
......@@ -42,4 +46,23 @@ public abstract class Did_ins <T extends Did_ins <T>>{
new_did.lla[i] = interpolateDouble(frac, lla[i], next_did.lla[i]) ;
}
}
public void getProperties(String prefix, Properties properties) {
if (properties.getProperty(prefix+"week")!=null) this.week= Integer.parseInt(properties.getProperty(prefix+"week"));
if (properties.getProperty(prefix+"timeOfWeek")!=null) this.timeOfWeek= Double.parseDouble(properties.getProperty(prefix+"timeOfWeek"));
if (properties.getProperty(prefix+"insStatus")!=null) this.insStatus= Integer.parseInt(properties.getProperty(prefix+"insStatus"));
if (properties.getProperty(prefix+"hdwStatus")!=null) this.hdwStatus= Integer.parseInt(properties.getProperty(prefix+"hdwStatus"));
if (properties.getProperty(prefix+"lla")!=null) this.lla= IntersceneMatchParameters.StringToDoubles(properties.getProperty(prefix+"lla"),3);
}
public Properties setProperties(String prefix, Properties properties){ // save // USED in lwir
if (properties == null) {
properties = new Properties();
}
properties.setProperty(prefix+"week", this.week+"");
properties.setProperty(prefix+"timeOfWeek", this.timeOfWeek+"");
properties.setProperty(prefix+"insStatus", this.insStatus+"");
properties.setProperty(prefix+"hdwStatus", this.hdwStatus+"");
properties.setProperty(prefix+"lla", IntersceneMatchParameters.doublesToString(this.lla));
return properties;
}
}
\ No newline at end of file
......@@ -3,6 +3,9 @@ package com.elphel.imagej.ims;
//import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Properties;
import com.elphel.imagej.tileprocessor.IntersceneMatchParameters;
//public class Did_ins_1 implements Serializable {
// static final long serialVersionUID = 4;
......@@ -36,6 +39,10 @@ public class Did_ins_1 extends Did_ins <Did_ins_1>{
ned[0]= bb.getFloat(); ned[1] = bb.getFloat(); ned[2]= bb.getFloat();
}
public Did_ins_1() {}
public Did_ins_1(String prefix, Properties properties) {
getProperties(prefix, properties);
}
public Did_ins_1 interpolate(double frac, Did_ins_1 next_did) {
Did_ins_1 new_did = new Did_ins_1();
......@@ -75,6 +82,19 @@ public class Did_ins_1 extends Did_ins <Did_ins_1>{
s += String.format("ned: %f, %f, %f", ned[0], ned[1], ned[2]);
return s;
}
public void getProperties(String prefix, Properties properties) {
super.getProperties(prefix, properties);
if (properties.getProperty(prefix+"theta")!=null) this.theta= IntersceneMatchParameters.StringToFloats(properties.getProperty(prefix+"theta"),3);
if (properties.getProperty(prefix+"uvw")!=null) this.uvw= IntersceneMatchParameters.StringToFloats(properties.getProperty(prefix+"uvw"),3);
if (properties.getProperty(prefix+"ned")!=null) this.ned= IntersceneMatchParameters.StringToFloats(properties.getProperty(prefix+"ned"),3);
}
public Properties setProperties(String prefix, Properties properties){ // save // USED in lwir
properties = super.setProperties(prefix, properties);
properties.setProperty(prefix+"theta", IntersceneMatchParameters.floatsToString(this.theta));
properties.setProperty(prefix+"uvw", IntersceneMatchParameters.floatsToString(this.uvw));
properties.setProperty(prefix+"ned", IntersceneMatchParameters.floatsToString(this.ned));
return properties;
}
}
\ No newline at end of file
package com.elphel.imagej.ims;
//import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Properties;
import com.elphel.imagej.tileprocessor.IntersceneMatchParameters;
//public class Did_ins_1 implements Serializable {
// static final long serialVersionUID = 4;
public class Did_ins_2 extends Did_ins <Did_ins_2>{
/** GPS number of weeks since January 6th, 1980 */
// public int week; // uint32_t
/** GPS time of week (since Sunday morning) in seconds */
// public double timeOfWeek;
/** INS status flags (eInsStatusFlags). Copy of DID_SYS_PARAMS.insStatus */
// public int insStatus; //uint32_t
/** Hardware status flags (eHdwStatusFlags). Copy of DID_SYS_PARAMS.hdwStatus */
// public int hdwStatus; // uint32_t
/** Euler angles: roll, pitch, yaw in radians with respect to NED */
public float [] qn2b = new float[4];
/** Velocity U, V, W in meters per second. Convert to NED velocity using "vectorBodyToReference( uvw, theta, vel_ned )". */
public float [] uvw = new float [3];
/** WGS84 latitude, longitude, height above ellipsoid (degrees,degrees,meters) */
// public double [] lla = new double [3];
public Did_ins_2 (ByteBuffer bb) {
bb.order(ByteOrder.LITTLE_ENDIAN);
week= bb.getInt();
timeOfWeek=bb.getDouble();
insStatus= bb.getInt();
hdwStatus= bb.getInt();
qn2b[0]= bb.getFloat(); qn2b[1] = bb.getFloat(); qn2b[2]= bb.getFloat(); qn2b[3]= bb.getFloat();
uvw[0]= bb.getFloat(); uvw[1] = bb.getFloat(); uvw[2]= bb.getFloat();
lla[0]= bb.getDouble(); lla[1] = bb.getDouble(); lla[2]= bb.getDouble();
}
public Did_ins_2() {}
public Did_ins_2(String prefix, Properties properties) {
getProperties(prefix, properties);
}
public Did_ins_2 interpolate(double frac, Did_ins_2 next_did) {
Did_ins_2 new_did = new Did_ins_2();
interpolateBase(frac, next_did, new_did);
for (int i = 0; i < qn2b.length; i++) {
new_did.qn2b[i] = interpolateFloat(frac, qn2b[i], next_did.qn2b[i]) ;
}
for (int i = 0; i < uvw.length; i++) {
new_did.uvw[i] = interpolateFloat(frac, uvw[i], next_did.uvw[i]) ;
}
return new_did;
}
public int pack(ByteBuffer bb) {
int p_start = bb.position();
bb.putInt(week);
bb.putDouble(timeOfWeek);
bb.putInt(insStatus);
bb.putInt(hdwStatus);
bb.putFloat(qn2b[0]); bb.putFloat(qn2b[1]); bb.putFloat(qn2b[2]); bb.putFloat(qn2b[3]);
bb.putFloat(uvw[0]); bb.putFloat(uvw[1]); bb.putFloat(uvw[2]);
bb.putDouble(lla[0]); bb.putDouble(lla[1]); bb.putDouble(lla[2]);
int p_end = bb.position();
return p_end - p_start;
}
public String toString() {
String s = "DID_INS_2\n";
s += String.format("week: %d\n", week);
s += String.format("timeOfWeek: %f\n", timeOfWeek);
s += String.format("insStatus: 0x%x\n", insStatus);
s += String.format("hdwStatus: 0x%x\n", hdwStatus);
s += String.format("qn2b: %f, %f, %f, %f\n", qn2b[0], qn2b[1], qn2b[2], qn2b[3]);
s += String.format("uvw: %f, %f, %f\n", uvw[0], uvw[1], uvw[2]);
s += String.format("lla: %f, %f, %f\n", lla[0], lla[1], lla[2]);
return s;
}
public void getProperties(String prefix, Properties properties) {
super.getProperties(prefix, properties);
if (properties.getProperty(prefix+"qn2b")!=null) this.qn2b= IntersceneMatchParameters.StringToFloats(properties.getProperty(prefix+"qn2b"),4);
if (properties.getProperty(prefix+"uvw")!=null) this.uvw= IntersceneMatchParameters.StringToFloats(properties.getProperty(prefix+"uvw"),3);
}
public Properties setProperties(String prefix, Properties properties){ // save // USED in lwir
properties = super.setProperties(prefix, properties);
properties.setProperty(prefix+"qn2b", IntersceneMatchParameters.floatsToString(this.qn2b));
properties.setProperty(prefix+"uvw", IntersceneMatchParameters.floatsToString(this.uvw));
return properties;
}
}
\ No newline at end of file
......@@ -2,6 +2,9 @@ package com.elphel.imagej.ims;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Properties;
import com.elphel.imagej.tileprocessor.IntersceneMatchParameters;
public class Did_pimu {
/** Time since boot up in seconds. Convert to GPS time of week by adding gps.towOffset */
......@@ -25,6 +28,10 @@ public class Did_pimu {
}
public Did_pimu() {}
public Did_pimu(String prefix, Properties properties) {
getProperties(prefix, properties);
}
public Did_pimu interpolate(double frac, Did_pimu next_did) {
Did_pimu new_did = new Did_pimu();
new_did.time = Did_ins.interpolateDouble(frac, time, next_did.time);
......@@ -58,5 +65,25 @@ public class Did_pimu {
s += String.format("vel: %f, %f, %f", vel[0], vel[1], vel[2]);
return s;
}
public void getProperties(String prefix, Properties properties) {
if (properties.getProperty(prefix+"time")!=null) this.time= Double.parseDouble(properties.getProperty(prefix+"time"));
if (properties.getProperty(prefix+"dt")!=null) this.dt= Float.parseFloat(properties.getProperty(prefix+"dt"));
if (properties.getProperty(prefix+"status")!=null) this.status= Integer.parseInt(properties.getProperty(prefix+"status"));
if (properties.getProperty(prefix+"theta")!=null) this.theta= IntersceneMatchParameters.StringToFloats(properties.getProperty(prefix+"theta"),3);
if (properties.getProperty(prefix+"vel")!=null) this.vel= IntersceneMatchParameters.StringToFloats(properties.getProperty(prefix+"vel"),3);
}
public Properties setProperties(String prefix, Properties properties){ // save // USED in lwir
if (properties == null) {
properties = new Properties();
}
properties.setProperty(prefix+"time", this.time+"");
properties.setProperty(prefix+"dt", this.dt+"");
properties.setProperty(prefix+"status", this.status+"");
properties.setProperty(prefix+"theta", IntersceneMatchParameters.floatsToString(this.theta));
properties.setProperty(prefix+"vel", IntersceneMatchParameters.floatsToString(this.vel));
return properties;
}
}
\ No newline at end of file
......@@ -17,7 +17,7 @@ typedef struct PACKED
} strobe_in_time_t;
*/
public class Did_strobe_in_time {
public final static int WEEK_MS = 7 * 24 * 3600 * 1000; // milliseconds in a week
public final static long WEEK_MS = 7 * 24 * 3600 * 1000; // milliseconds in a week
public int week;
/** GPS time of week (since Sunday morning) in milliseconds */
......
......@@ -35,10 +35,10 @@ public class EventLogger {
}
Arrays.sort(logger_files); // increasing start time stamps
testInterpolateDidIns1();
testInterpolateDidIns1();
testInterpolateDidIns1();
// testInterpolateDidIns1();
// testInterpolateDidIns1();
// testInterpolateDidIns1();
/*
// String out_did_gps_path = "/home/elphel/lwir16-proc/office_04/did_gps";
String out_did_gps_path = dir+"../did_gps/did_gps";
out_did_gps_path = Paths.get(out_did_gps_path).normalize().toString();
......@@ -56,8 +56,9 @@ public class EventLogger {
e.printStackTrace();
}
}
*/
// String out_did1_path = "/media/elphel/SSD3-4GB/lwir16-proc/berdich/ims/test_out/did_ins1";
/*
String out_did1_path = dir+"../did_ins1/did_ins1";
out_did1_path = Paths.get(out_did1_path).normalize().toString();
Path op_did1 = Paths.get(out_did1_path);
......@@ -73,9 +74,82 @@ public class EventLogger {
e.printStackTrace();
}
}
*/
System.out.println("Processed "+logger_files.length+" event log files");
}
public void printGps(
String out_did_gps_path,
int gps_mask) { // 7: // +1 - DID_GPS1_POS, +2 - DID_GPS2_POS, +4 - DID_GPS1_UBX_POS
out_did_gps_path = Paths.get(out_did_gps_path).normalize().toString();
Path op_did_gps = Paths.get(out_did_gps_path);
op_did_gps=op_did_gps.normalize();
(new File(op_did_gps.getParent().toString())).mkdirs();
for (int nf = 0; nf < logger_files.length; nf++) {
String out_path= out_did_gps_path+"-"+String.format("%03d", nf)+".out";
System.out.println("Printing all DID_GPS data in "+logger_files[nf].abs_path+" to "+out_path);
try {
logger_files[nf].listGPS(out_path, gps_mask, false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void printDidIns1(String out_did1_path) {
out_did1_path = Paths.get(out_did1_path).normalize().toString();
Path op_did1 = Paths.get(out_did1_path);
op_did1=op_did1.normalize();
(new File(op_did1.getParent().toString())).mkdirs();
for (int nf = 0; nf < logger_files.length; nf++) {
String out_path= out_did1_path+"-"+String.format("%03d", nf)+".out";
System.out.println("Printing all DID_INS_1 data in "+logger_files[nf].abs_path+" to "+out_path);
try {
logger_files[nf].listDidIns1(out_path,false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void printDidIns2(String out_did2_path) {
out_did2_path = Paths.get(out_did2_path).normalize().toString();
Path op_did2 = Paths.get(out_did2_path);
op_did2=op_did2.normalize();
(new File(op_did2.getParent().toString())).mkdirs();
for (int nf = 0; nf < logger_files.length; nf++) {
String out_path= out_did2_path+"-"+String.format("%03d", nf)+".out";
System.out.println("Printing all DID_INS_2 data in "+logger_files[nf].abs_path+" to "+out_path);
try {
logger_files[nf].listDidIns2(out_path,false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void printPimu(String out_pimu_path) {
out_pimu_path = Paths.get(out_pimu_path).normalize().toString();
Path op_pimu = Paths.get(out_pimu_path);
op_pimu=op_pimu.normalize();
(new File(op_pimu.getParent().toString())).mkdirs();
for (int nf = 0; nf < logger_files.length; nf++) {
String out_path= out_pimu_path+"-"+String.format("%03d", nf)+".out";
System.out.println("Printing all DID_INS_1 data in "+logger_files[nf].abs_path+" to "+out_path);
try {
logger_files[nf].listPimu(out_path,false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void testInterpolateDidIns1() {
boolean exit_now = false;
double ts_master = 1694576078.939126;
......@@ -96,7 +170,7 @@ public class EventLogger {
//Did_ins_1
Did_ins_1 interpolateDidIns1(
public Did_ins_1 interpolateDidIns1(
double ts_master,
int debug_level) throws IOException {
byte [][] payload = new byte[2][];
......@@ -118,6 +192,77 @@ public class EventLogger {
frac, // double frac,
did_above); // Did_ins_1 next_did))
}
//Did_ins_2
public Did_ins_2 interpolateDidIns2(
double ts_master,
int debug_level) throws IOException {
byte [][] payload = new byte[2][];
int did = Imx5.DID_INS_2;
double frac = getDidAtTS(
ts_master, // double ts_master,
did, // int did, // DID value (4 for DID_INS_1, 3 for DID_PIMU)
payload, // byte [][] payload,
debug_level); // int debug_level)
if (Double.isNaN(frac)) {
if (debug_level > -1){
System.out.println("interpolateDidIns1(): Failed to extract DID_INS_2 data");
}
return null;
}
Did_ins_2 did_below = new Did_ins_2(ByteBuffer.wrap(payload[0]));
Did_ins_2 did_above = new Did_ins_2(ByteBuffer.wrap(payload[1]));
return did_below.interpolate(
frac, // double frac,
did_above); // Did_ins_1 next_did))
}
public Did_gps_pos interpolateDidGpsPos(
double ts_master,
int did, // Imx5.DID_GPS1_POS, Imx5.DID_GPS2_POS, Imx5.DID_GPS1_UBX_POS
int debug_level) throws IOException {
byte [][] payload = new byte[2][];
double frac = getDidAtTS(
ts_master, // double ts_master,
did, // int did, // DID value (4 for DID_INS_1, 3 for DID_PIMU)
payload, // byte [][] payload,
debug_level); // int debug_level)
if (Double.isNaN(frac)) {
if (debug_level > -1){
System.out.println("interpolateDidIns1(): Failed to extract DID_GPS_POS data");
}
return null;
}
Did_gps_pos did_below = new Did_gps_pos(ByteBuffer.wrap(payload[0]));
Did_gps_pos did_above = new Did_gps_pos(ByteBuffer.wrap(payload[1]));
return did_below.interpolate(
frac, // double frac,
did_above); // Did_gps_pos next_did))
}
public Did_pimu interpolateDidPimu(
double ts_master,
int debug_level) throws IOException {
byte [][] payload = new byte[2][];
int did = Imx5.DID_PIMU;
double frac = getDidAtTS(
ts_master, // double ts_master,
did, // int did, // DID value (4 for DID_INS_1, 3 for DID_PIMU)
payload, // byte [][] payload,
debug_level); // int debug_level)
if (Double.isNaN(frac)) {
if (debug_level > -1){
System.out.println("interpolateDidIns1(): Failed to extract DID_PIMU data");
}
return null;
}
Did_pimu did_below = new Did_pimu(ByteBuffer.wrap(payload[0]));
Did_pimu did_above = new Did_pimu(ByteBuffer.wrap(payload[1]));
return did_below.interpolate(
frac, // double frac,
did_above); // Did_ins_1 next_did))
}
public double getDidAtTS(
double ts_master,
......
......@@ -403,7 +403,7 @@ public class EventLoggerFileInfo implements Comparable<EventLoggerFileInfo> {
}
}
public void listDid1(String path, boolean keep) throws IOException {
public void listDidIns1(String path, boolean keep) throws IOException {
double max_offset = 1000; // m
open();
float [] start_ned = null;
......@@ -430,7 +430,7 @@ public class EventLoggerFileInfo implements Comparable<EventLoggerFileInfo> {
int type = (EventLoggerFileInfo.REC_TYPE_GPS << 4) | EventLoggerFileInfo.REC_SUBTYPE_IMX5; // 0x18 - first subpacket
for (int nrec = 0; nrec < num_recs; nrec++) {
if (nrec == dbg_nrec) {
System.out.println("listDid1(): nrec="+nrec);
System.out.println("listDidIns1(): nrec="+nrec);
}
int [] full_type = getFullType(bb, nrec);
if ((full_type != null) && (full_type[0] == type) && (full_type[1] == Imx5.DID_INS_1)) {
......@@ -487,6 +487,75 @@ public class EventLoggerFileInfo implements Comparable<EventLoggerFileInfo> {
}
}
public void listDidIns2(String path, boolean keep) throws IOException {
open();
FileWriter writer = null;
if (path != null) {
writer = new FileWriter (path);
}
String header = "record "+
" master TS "+
" local TS "+
"timeOfWeek " +
" insStat "+
" hdwStat "+
" qn2b "+
" uvw "+
" lla \n";
if (writer != null) {
writer.write(header);
} else {
System.out.print(header);
}
int dbg_nrec = -5000;
int type = (EventLoggerFileInfo.REC_TYPE_GPS << 4) | EventLoggerFileInfo.REC_SUBTYPE_IMX5; // 0x18 - first subpacket
for (int nrec = 0; nrec < num_recs; nrec++) {
if (nrec == dbg_nrec) {
System.out.println("listDidIns1(): nrec="+nrec);
}
int [] full_type = getFullType(bb, nrec);
if ((full_type != null) && (full_type[0] == type) && (full_type[1] == Imx5.DID_INS_2)) {
byte [] payload = getDidPayload(
null, // next_fileinfo, // may be null if payload does not extend beyond single record
nrec);
if (payload == null) {
System.out.println("EventLoggerFileInfo(): payload == null, nrec="+nrec);
break;
}
ByteBuffer bb_payload = ByteBuffer.wrap(payload);
bb_payload.order(ByteOrder.LITTLE_ENDIAN);
Did_ins_2 did_ins_2 = new Did_ins_2(bb_payload);
if ((did_ins_2.uvw[0] == 0) && (did_ins_2.uvw[1] == 0) && (did_ins_2.uvw[2] == 0)) {
continue;
}
String line =String.format(
"%6d %17.6f %17.6f %10.3f %08x %08x [%8.4f, %8.4f, %8.4f, %8.4f] "+
"[%8.3f, %8.3f, %8.3f] [%12.7f, %12.7f, %12.7f]\n",
nrec,
getMasterTS(nrec),
getLocalTS(nrec),
did_ins_2.timeOfWeek,
did_ins_2.insStatus,
did_ins_2.hdwStatus,
did_ins_2.qn2b[0], did_ins_2.qn2b[1], did_ins_2.qn2b[2], did_ins_2.qn2b[3], // Quaternion body rotation with respect to NED: W, X, Y, Z
did_ins_2.uvw[0], did_ins_2.uvw[1], did_ins_2.uvw[2], // Velocity U, V, W in meters per second. Convert to NED velocity using "vectorBodyToReference( uvw, theta, vel_ned )".
did_ins_2.lla[0], did_ins_2.lla[1], did_ins_2.lla[2] // WGS84 latitude, longitude, height above ellipsoid (degrees,degrees,meters)
);
if (writer != null) {
writer.write(line);
} else {
System.out.print(line);
}
}
}
if (writer != null) {
writer.close();
}
if (!keep) {
close();
}
}
public void listGPS (String path, int gps_mask, boolean keep) throws IOException {
// +1 - DID_GPS1_POS, +2 - DID_GPS2_POS, +4 - DID_GPS1_UBX_POS
// double max_offset = 1000; // m
......@@ -594,6 +663,76 @@ public class EventLoggerFileInfo implements Comparable<EventLoggerFileInfo> {
}
public void listPimu(String path, boolean keep) throws IOException {
open();
FileWriter writer = null;
if (path != null) {
writer = new FileWriter (path);
}
String header = "record "+
" master TS "+
" local TS "+
" time since boot " +
" dt "+
" status "+
" omega (rad/s) "+
" a (m/s^2) "+"\n";
if (writer != null) {
writer.write(header);
} else {
System.out.print(header);
}
int dbg_nrec = -5000;
int type = (EventLoggerFileInfo.REC_TYPE_GPS << 4) | EventLoggerFileInfo.REC_SUBTYPE_IMX5; // 0x18 - first subpacket
for (int nrec = 0; nrec < num_recs; nrec++) {
if (nrec == dbg_nrec) {
System.out.println("listPimu(): nrec="+nrec);
}
int [] full_type = getFullType(bb, nrec);
if ((full_type != null) && (full_type[0] == type) && (full_type[1] == Imx5.DID_PIMU)) {
byte [] payload = getDidPayload(
null, // next_fileinfo, // may be null if payload does not extend beyond single record
nrec);
if (payload == null) {
System.out.println("EventLoggerFileInfo(): payload == null, nrec="+nrec);
break;
}
ByteBuffer bb_payload = ByteBuffer.wrap(payload);
bb_payload.order(ByteOrder.LITTLE_ENDIAN);
Did_pimu did_pimu = new Did_pimu(bb_payload);
if ((did_pimu.vel[0] == 0) && (did_pimu.vel[1] == 0) && (did_pimu.vel[2] == 0)) {
continue; // skip no-movement
}
String line =String.format(
"%6d %17.6f %17.6f %17.6f %8.6f %08x [%9.5f, %9.5f, %9.5f] "+
"[%9.4f, %9.4f, %9.4f]\n",
nrec,
getMasterTS(nrec),
getLocalTS(nrec),
did_pimu.time,
did_pimu.dt,
did_pimu.status,
did_pimu.theta[0]/did_pimu.dt, did_pimu.theta[1]/did_pimu.dt, did_pimu.theta[2]/did_pimu.dt, // Euler angles: roll, pitch, yaw in radians with respect to NED
did_pimu.vel[0]/did_pimu.dt, did_pimu.vel[1]/did_pimu.dt, did_pimu.vel[2]/did_pimu.dt // Velocity U, V, W in meters per second. Convert to NED velocity using "vectorBodyToReference( uvw, theta, vel_ned )".
);
if (writer != null) {
writer.write(line);
} else {
System.out.print(line);
}
}
}
if (writer != null) {
writer.close();
}
if (!keep) {
close();
}
}
byte [] getDidPayload(
EventLoggerFileInfo next_fileinfo, // may be null if payload does not extend beyond single record
int nrec) throws IOException {
......
package com.elphel.imagej.ims;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
//import java.io.ByteArrayOutputStream;
//import java.io.IOException;
//import java.io.ObjectOutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
import org.apache.commons.math3.geometry.euclidean.threed.RotationConvention;
import org.apache.commons.math3.geometry.euclidean.threed.RotationOrder;
public class Imx5 {
// defines adapted from Inertial Sense data_sets.h
public static int DID_NULL = 0 ; /** NULL (INVALID) */
public static int DID_DEV_INFO = 1 ; /** (dev_info_t) Device information */
......@@ -119,6 +125,7 @@ public class Imx5 {
/** Count of data ids (including null data id 0) - MUST BE MULTPLE OF 4 and larger than last DID number! */
public static int DID_COUNT = 120; // Used in SDK
public static int DID_COUNT_UINS = 100; // Used in uINS
public static double EARTH_RADIUS = 6356752.0; // meters
/** Maximum number of data ids */
public static int DID_MAX_COUNT = 256;
......@@ -150,44 +157,80 @@ public class Imx5 {
Did_ins_1 did_ins_1_2 = new Did_ins_1(bb);
System.out.println("did_ins_1_2 = "+did_ins_1_2);
return bb.array();
/*
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = null;
try {
out = new ObjectOutputStream(bos);
out.writeObject(yourObject);
out.flush();
byte[] yourBytes = bos.toByteArray();
...
} finally {
try {
bos.close();
} catch (IOException ex) {
// ignore close exception
}
}
Create an object from a byte array:
ByteArrayInputStream bis = new ByteArrayInputStream(yourBytes);
ObjectInput in = null;
try {
in = new ObjectInputStream(bis);
Object o = in.readObject();
...
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException ex) {
// ignore close exception
}
}
}
// static final RotationConvention ROT_CONV = RotationConvention.FRAME_TRANSFORM;
// RotationConvention.VECTOR_OPERATOR
//RotationOrder.YXZ, ROT_CONV
public static double [] applyQuternionTo(double[]quat, double[] vector, boolean inverse) {
Rotation ims_rot = new Rotation(quat[0],quat[1],quat[2],quat[3],true);
double [] rslt = new double[3];
if (inverse) {
ims_rot.applyInverseTo(vector, rslt);
*/
} else {
ims_rot.applyTo(vector, rslt);
}
return rslt;
}
public static double [] imsToCamRotations(double [] ims_theta, int ord, boolean rev_order, boolean rev_matrix ) {
RotationConvention rc = RotationConvention.FRAME_TRANSFORM;
// RotationOrder ro = zyx ? RotationOrder.ZYX : RotationOrder.XYZ; // XYZ; // ZYX;
RotationOrder ro = RotationOrder.XYZ;
switch (ord) {
case 0: ro = RotationOrder.XYZ; break;
case 1: ro = RotationOrder.XZY; break;
case 2: ro = RotationOrder.YXZ; break;
case 3: ro = RotationOrder.YZX; break;
case 4: ro = RotationOrder.ZXY; break;
case 5: ro = RotationOrder.ZYX; break;
}
RotationOrder ro1 = ro; // ? RotationOrder.ZYX : RotationOrder.XYZ; //.XYZ;
Rotation cam_to_ims0 = new Rotation(new double [][] {{0,0,1},{-1,0,0},{0,-1,0}}, 1E-8);
// Rotation cam_to_ims1 = new Rotation(ro, rc, -Math.PI/2, 0, -Math.PI/2);
Rotation cam_to_ims = rev_matrix? (new Rotation(ro, rc, -Math.PI/2, 0, -Math.PI/2)):(new Rotation(ro, rc, Math.PI/2, 0, Math.PI/2));
double [] angles1 = cam_to_ims.getAngles(ro1, rc);
Rotation ims_rot = new Rotation(ro, rc, ims_theta[0], ims_theta[1], ims_theta[2]);
//Rotation r1= new Rotation(RotationOrder.YXZ, RC, ro.aux_azimuth, ro.aux_tilt, ro.aux_roll)
Rotation comb_rot = rev_order?ims_rot.applyTo(cam_to_ims): cam_to_ims.applyTo(ims_rot);
double [] angles = comb_rot.getAngles(ro1, rc);
return angles;
}
public static double [] imsQToCamRotations(double [] ims_qn2b, int ord, boolean rev_order, boolean rev_matrix ) {
RotationConvention rc = RotationConvention.FRAME_TRANSFORM;
// RotationOrder ro = zyx ? RotationOrder.ZYX : RotationOrder.XYZ; // XYZ; // ZYX;
RotationOrder ro = RotationOrder.XYZ;
switch (ord) {
case 0: ro = RotationOrder.XYZ; break;
case 1: ro = RotationOrder.XZY; break;
case 2: ro = RotationOrder.YXZ; break;
case 3: ro = RotationOrder.YZX; break;
case 4: ro = RotationOrder.ZXY; break;
case 5: ro = RotationOrder.ZYX; break;
}
RotationOrder ro1 = ro; // ? RotationOrder.ZYX : RotationOrder.XYZ; //.XYZ;
Rotation cam_to_ims0 = new Rotation(new double [][] {{0,0,1},{-1,0,0},{0,-1,0}}, 1E-8);
// Rotation cam_to_ims1 = new Rotation(ro, rc, -Math.PI/2, 0, -Math.PI/2);
Rotation cam_to_ims = rev_matrix? (new Rotation(ro, rc, -Math.PI/2, 0, -Math.PI/2)):(new Rotation(ro, rc, Math.PI/2, 0, Math.PI/2));
double [] angles1 = cam_to_ims.getAngles(ro1, rc);
// Rotation ims_rot = new Rotation(ro, rc, ims_theta[0], ims_theta[1], ims_theta[2]);
// public Rotation(double q0, double q1, double q2, double q3, boolean needsNormalization) {
Rotation ims_rot = new Rotation(ims_qn2b[0],ims_qn2b[1],ims_qn2b[2],ims_qn2b[3],true);
//Rotation r1= new Rotation(RotationOrder.YXZ, RC, ro.aux_azimuth, ro.aux_tilt, ro.aux_roll)
Rotation comb_rot = rev_order?ims_rot.applyTo(cam_to_ims): cam_to_ims.applyTo(ims_rot);
double [] angles = comb_rot.getAngles(ro1, rc);
return angles;
}
public static double [] nedFromLla (double [] lla, double [] lla_ref) {
double [] ned = new double[] {
EARTH_RADIUS* Math.cos(lla[0] * Math.PI / 180)*(lla[1] - lla_ref[1]) * Math.PI / 180.0,
EARTH_RADIUS* (lla[0]-lla_ref[0]) * Math.PI / 180,
-(lla[2] - lla_ref[2])
};
return ned;
}
}
......@@ -34,12 +34,18 @@ public class IntersceneMatchParameters {
public static String [] MODES3D = {"RAW", "INF", "FG", "BG"}; // RAW:-1
public static String [] MODES_AVI = {"RAW", "JPEG", "PNG"};
// Maybe add parameters to make sure there is enough data? Enough in each zone? Enough spread?
public boolean ims_use = true; // use IMS data
public boolean ims_rebuild = false; // recalculate INS data (after lag change)
public double ims_offset = 0.0; // IMS data lead relative to images (seconds)
public double gmt_plus = 3.0; // (hrs) filename timestamp is this lower than in IMU log
public boolean force_ref_dsi = false; // true;
public boolean force_orientations = false;
public boolean run_ly = false; // will return just after LY adjustments, skipping all output generation
public int min_num_orient = 2; // make from parameters, should be >= 1
public int min_num_interscene = 2; // make from parameters, should be >= 1
public boolean generate_egomotion = true; // generate egomotion table (image-based and ims)
public boolean generate_mapped = true; // generate any of the sequences - Tiff, video, mono or stereo
public boolean reuse_video = false; // dry-run video generation, just reassemble video fragments (active if !generate_mapped)
public boolean save_mapped_color = false; // may be not needed when using AVI
......@@ -398,6 +404,15 @@ public class IntersceneMatchParameters {
// gd.addTab ("Inter-Match", "Parameters for full-resolution (no decimation/macrotiles) scene matching");
gd.addTab ("Scene Series", "Processing series of scenes and multi-series sets");
gd.addMessage ("Build series options");
gd.addCheckbox ("Use IMS data", this.ims_use,
"Use INS data for egomotion.");
gd.addCheckbox ("Recalculate IMS", this.ims_rebuild,
"Recalculate scene INS data.");
gd.addNumericField("IMS offset", this.ims_offset, 5,8,"s",
"Positive if the IMS data has lower lag than images.");
gd.addNumericField("GMT plus", this.gmt_plus, 5,8,"hrs",
"Timestamp filename is lower by this hours than in the IMU log.");
gd.addCheckbox ("Force reference scene DSI calculation", this.force_ref_dsi,
"Calculate reference scene DSI even if the file exists.");
gd.addCheckbox ("Force egomotion calculation", this.force_orientations,
......@@ -410,6 +425,8 @@ public class IntersceneMatchParameters {
"Minimal required number of re-calculations of the interscene-accumulated DSI.");
gd.addMessage ("Generate/show scene sequences");
gd.addCheckbox ("Generate egomotion table", this.generate_egomotion,
"Generate table with image-based and IMS egomotion data.");
gd.addCheckbox ("Generate mapped scene sequence", this.generate_mapped,
"Generate scene sequence mapped to the reference scene.");
gd.addCheckbox ("Reuse existing video fragments, disable other options",this.reuse_video,
......@@ -1051,11 +1068,16 @@ public class IntersceneMatchParameters {
}
public void dialogAnswers(GenericJTabbedDialog gd) {
this.ims_use = gd.getNextBoolean();
this.ims_rebuild = gd.getNextBoolean();
this.ims_offset = gd.getNextNumber();
this.gmt_plus = gd.getNextNumber();
this.force_ref_dsi = gd.getNextBoolean();
this.force_orientations = gd.getNextBoolean();
this.run_ly = gd.getNextBoolean();
this.min_num_orient = (int) gd.getNextNumber(); if (min_num_orient < 1) min_num_orient = 1;
this.min_num_interscene = (int) gd.getNextNumber(); if (min_num_interscene < 1) min_num_interscene = 1;
this.generate_egomotion = gd.getNextBoolean();
this.generate_mapped = gd.getNextBoolean();
this.reuse_video = gd.getNextBoolean();
this.save_mapped_color = gd.getNextBoolean(); // as tiff
......@@ -1394,6 +1416,11 @@ public class IntersceneMatchParameters {
}
public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"ims_use", this.ims_use + ""); // boolean
properties.setProperty(prefix+"ims_rebuild", this.ims_rebuild + ""); // boolean
properties.setProperty(prefix+"ims_offset", this.ims_offset+""); // double
properties.setProperty(prefix+"gmt_plus", this.gmt_plus+""); // double
properties.setProperty(prefix+"force_ref_dsi", this.force_ref_dsi + ""); // boolean
properties.setProperty(prefix+"force_orientations", this.force_orientations + ""); // boolean
properties.setProperty(prefix+"run_ly", this.run_ly + ""); // boolean
......@@ -1401,6 +1428,7 @@ public class IntersceneMatchParameters {
// properties.setProperty(prefix+"force_interscene", this.force_interscene + ""); // boolean
properties.setProperty(prefix+"min_num_orient", this.min_num_orient+""); // int
properties.setProperty(prefix+"min_num_interscene", this.min_num_interscene+""); // int
properties.setProperty(prefix+"generate_egomotion", this.generate_egomotion+""); // boolean
properties.setProperty(prefix+"generate_mapped", this.generate_mapped+""); // boolean
properties.setProperty(prefix+"reuse_video", this.reuse_video+""); // boolean
properties.setProperty(prefix+"save_mapped_color", this.save_mapped_color+""); // boolean
......@@ -1699,11 +1727,17 @@ public class IntersceneMatchParameters {
}
public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"ims_use")!=null) this.ims_use=Boolean.parseBoolean(properties.getProperty(prefix+"ims_use"));
if (properties.getProperty(prefix+"ims_rebuild")!=null) this.ims_rebuild=Boolean.parseBoolean(properties.getProperty(prefix+"ims_rebuild"));
if (properties.getProperty(prefix+"ims_offset")!=null) this.ims_offset=Double.parseDouble(properties.getProperty(prefix+"ims_offset"));
if (properties.getProperty(prefix+"gmt_plus")!=null) this.gmt_plus=Double.parseDouble(properties.getProperty(prefix+"gmt_plus"));
if (properties.getProperty(prefix+"force_ref_dsi")!=null) this.force_ref_dsi=Boolean.parseBoolean(properties.getProperty(prefix+"force_ref_dsi"));
if (properties.getProperty(prefix+"force_orientations")!=null) this.force_orientations=Boolean.parseBoolean(properties.getProperty(prefix+"force_orientations"));
if (properties.getProperty(prefix+"run_ly")!=null) this.run_ly=Boolean.parseBoolean(properties.getProperty(prefix+"run_ly"));
if (properties.getProperty(prefix+"min_num_orient")!=null) this.min_num_orient=Integer.parseInt(properties.getProperty(prefix+"min_num_orient"));
if (properties.getProperty(prefix+"min_num_interscene")!=null) this.min_num_interscene=Integer.parseInt(properties.getProperty(prefix+"min_num_interscene"));
if (properties.getProperty(prefix+"generate_egomotion")!=null) this.generate_egomotion=Boolean.parseBoolean(properties.getProperty(prefix+"generate_egomotion"));
if (properties.getProperty(prefix+"generate_mapped")!=null) this.generate_mapped=Boolean.parseBoolean(properties.getProperty(prefix+"generate_mapped"));
if (properties.getProperty(prefix+"reuse_video")!=null) this.reuse_video=Boolean.parseBoolean(properties.getProperty(prefix+"reuse_video"));
......@@ -2029,11 +2063,17 @@ public class IntersceneMatchParameters {
@Override
public IntersceneMatchParameters clone() throws CloneNotSupportedException {
IntersceneMatchParameters imp = new IntersceneMatchParameters();
imp.force_ref_dsi = this.force_ref_dsi;
imp.ims_use = this.ims_use;
imp.ims_rebuild = this.ims_rebuild;
imp.ims_offset = this.ims_offset;
imp.gmt_plus = this.gmt_plus;
imp.force_ref_dsi = this.force_ref_dsi;
imp.force_orientations = this.force_orientations;
imp.run_ly = this.run_ly;
imp.min_num_orient = this.min_num_orient;
imp.min_num_interscene = this.min_num_interscene;
imp.generate_egomotion = this.generate_egomotion;
imp.generate_mapped = this.generate_mapped;
imp.reuse_video = this.reuse_video;
imp.save_mapped_color = this.save_mapped_color;
......@@ -2465,6 +2505,50 @@ public class IntersceneMatchParameters {
return data;
}
public static float [] StringToFloats(String s, int len) {
StringTokenizer st = new StringTokenizer(s, " \t\n\r\f,");
if (st.countTokens() == 0) {
return null;
}
if (len <= 0) {
len = st.countTokens();
}
float [] data = new float [len];
int i = 0;
while (st.hasMoreTokens() && (i < len)) {
double d = 0;
try {
d = Double.parseDouble(st.nextToken());
} catch(NumberFormatException e){
d = 0;
}
data[i++] = (float) d;
}
return data;
}
public static String floatsToString(float [] data) {
return floatsToString(data, null);
}
public static String floatsToString(float [] data, String fmt) {
// if ((fmt == null) || (fmt.trim().length()==0)) {
// fmt = "%.0f";
// }
String s = "";
for (int i = 0; i < data.length; i++) {
if (fmt==null) {
s += data[i]; // unformatted
} else {
s+=String.format(fmt,data[i]);
}
if (i < (data.length - 1)) {
s+= ", ";
}
}
return s;
}
}
......@@ -48,14 +48,22 @@ import org.apache.commons.math3.complex.Quaternion;
import java.util.concurrent.ThreadLocalRandom;
import com.elphel.imagej.calibration.CalibrationFileManagement;
import com.elphel.imagej.cameras.CLTParameters;
import com.elphel.imagej.cameras.ColorProcParameters;
import com.elphel.imagej.cameras.EyesisCorrectionParameters;
import com.elphel.imagej.common.DoubleGaussianBlur;
import com.elphel.imagej.common.ShowDoubleFloatArrays;
import com.elphel.imagej.correction.CorrectionColorProc;
import com.elphel.imagej.correction.Eyesis_Correction;
import com.elphel.imagej.gpu.GpuQuad;
import com.elphel.imagej.gpu.TpTask;
import com.elphel.imagej.ims.Did_gps_pos;
import com.elphel.imagej.ims.Did_ins_1;
import com.elphel.imagej.ims.Did_ins_2;
import com.elphel.imagej.ims.Did_pimu;
import com.elphel.imagej.ims.EventLogger;
import com.elphel.imagej.ims.Imx5;
import com.elphel.imagej.jp4.JP46_Reader_camera;
import Jama.Matrix;
......@@ -67,6 +75,7 @@ import ij.io.FileSaver;
import ij.process.FloatProcessor;
import ij.process.ImageConverter;
import ij.process.ImageProcessor;
import ij.text.TextWindow;
import ij.plugin.filter.AVI_Writer;
import ij.plugin.filter.GaussianBlur;
......@@ -4905,6 +4914,14 @@ public class OpticalFlow {
final boolean updateStatus,
final int debugLevel) throws Exception
{
/*
if (clt_parameters.imp.ims_use && (Eyesis_Correction.EVENT_LOGGER == null)) {
System.out.println("Preparing IMS data as it is needed but does not exist");
String imx_logs = Eyesis_Correction.CORRECTION_PARAMETERS.getImsSourceDirectory(); // sourceImsDirectory;
Eyesis_Correction.EVENT_LOGGER = new EventLogger (imx_logs);
}
EventLogger eventLogger = Eyesis_Correction.EVENT_LOGGER;
*/
int earliest_scene = 0; // increase on failure
boolean build_ref_dsi = clt_parameters.imp.force_ref_dsi;
......@@ -4943,6 +4960,9 @@ public class OpticalFlow {
save_mapped_mono_color[0] || gen_avi_mono_color[0] || show_mono_color[0],
save_mapped_mono_color[1] || gen_avi_mono_color[1] || show_mono_color[1]} ;
// skip completely if no color or mono, tiff or video
boolean generate_egomotion = clt_parameters.imp.generate_egomotion; // generate egomotion table (image-based and ims)
boolean generate_mapped = clt_parameters.imp.generate_mapped &&
(gen_seq_mono_color[0] || gen_seq_mono_color[1]); // generate sequences - Tiff and/or video
boolean export3d = clt_parameters.imp.export3d; // true;
......@@ -5368,6 +5388,34 @@ public class OpticalFlow {
}
}
if (generate_egomotion) {
boolean ego_show = !clt_parameters.batch_run; //true;
String ego_path = quadCLTs[ref_index].getX3dDirectory()+Prefs.getFileSeparator()+
quadCLTs[ref_index].getImageName()+
quadCLTs[ref_index].correctionsParameters.egomotionSuffix;
String ego_comment = null;
generateEgomotionTable(
clt_parameters, // CLTParameters clt_parameters,
quadCLTs, // QuadCLT [] quadCLTs,
ref_index,// ref_indx,
earliest_scene, // int earliest_scene,
ego_path, // String path,
ego_comment); // String comment);
if (debugLevel> -3) {
System.out.println("Egomotion table saved to "+ego_path);
}
if (ego_show) {
generateEgomotionTable(
clt_parameters, // CLTParameters clt_parameters,
quadCLTs, // QuadCLT [] quadCLTs,
ref_index,// ref_indx,
earliest_scene, // int earliest_scene,
ego_path, // String path,
ego_comment); // String comment);
}
}
if (test_ers) { // only debug feature
test_ers0 = quadCLTs.length -1; // make it always == reference !
testERS(
......@@ -6187,6 +6235,308 @@ public class OpticalFlow {
return quadCLTs[ref_index].getX3dTopDirectory();
}
public static void generateEgomotionTable(
CLTParameters clt_parameters,
QuadCLT [] quadCLTs,
int ref_index,
int earliest_scene,
String path,
String comment) {
boolean use_euler = true;
boolean use_qn2b = true;
String header_img="#\ttimestamp\tx(m)\ty(m)\tz(m)\ta(rad)\ttilt(rad)\troll(rad)"+
"\tVx(m/s)\tVy(m/s)\tVz(m/s)\tVa(rad/s)\tVt(rad/s)\tVr(rad/s)";
String header_ins1="\ttow\ttheta0\ttheta1\ttheta2\tu(m/s)\tv(m/s)\tw(m/s)"+
"\tlat\tlong\talt\tned0\tned1\tned2";
String header_ins2="\ttow\tqn2b0\tqn2b1\tqn2b2\tqn2b3\tu(m/s)\tv(m/s)\tw(m/s)\tlat\tlong\talt";
String header_ins2_extra="\tned_N\tned_E\tned_D\timu_X\timu_Y\timu_Z"+
"\tu_dir\tv_dir\tw_dir\tu_inv\tv_inv\tw_inv";
String header_pimu="\to0\to1\to2\ta0\ta1\ta2";
String header_cam000= "\ttheta0-000\ttheta1-000\ttheta2-000";
String header_cam001= "\ttheta0-001\ttheta1-001\ttheta2-001";
String header_cam010= "\ttheta0-010\ttheta1-010\ttheta2-010";
String header_cam011= "\ttheta0-011\ttheta1-011\ttheta2-011";
String header_cam100= "\ttheta0-100\ttheta1-100\ttheta2-100";
String header_cam101= "\ttheta0-101\ttheta1-101\ttheta2-101";
String header_cam110= "\ttheta0-110\ttheta1-110\ttheta2-110";
String header_cam111= "\ttheta0-111\ttheta1-111\ttheta2-111";
String header_cam200= "\ttheta0-200\ttheta1-200\ttheta2-200";
String header_cam201= "\ttheta0-201\ttheta1-201\ttheta2-201";
String header_cam210= "\ttheta0-210\ttheta1-210\ttheta2-210";
String header_cam211= "\ttheta0-211\ttheta1-211\ttheta2-211";
String header_cam300= "\ttheta0-300\ttheta1-300\ttheta2-300";
String header_cam301= "\ttheta0-301\ttheta1-301\ttheta2-301";
String header_cam310= "\ttheta0-310\ttheta1-310\ttheta2-310";
String header_cam311= "\ttheta0-311\ttheta1-311\ttheta2-311";
String header_cam400= "\ttheta0-400\ttheta1-400\ttheta2-400";
String header_cam401= "\ttheta0-401\ttheta1-401\ttheta2-401";
String header_cam410= "\ttheta0-410\ttheta1-410\ttheta2-410";
String header_cam411= "\ttheta0-411\ttheta1-411\ttheta2-411";
String header_cam500= "\ttheta0-500\ttheta1-500\ttheta2-500";
String header_cam501= "\ttheta0-501\ttheta1-501\ttheta2-501";
String header_cam510= "\ttheta0-510\ttheta1-510\ttheta2-510";
String header_cam511= "\ttheta0-511\ttheta1-511\ttheta2-511";
String header_qn2b000= "\tqn2b0-000\tqn2b1-000\tqn2b2-000";
String header_qn2b001= "\tqn2b0-001\tqn2b1-001\tqn2b2-001";
String header_qn2b010= "\tqn2b0-010\tqn2b1-010\tqn2b2-010";
String header_qn2b011= "\tqn2b0-011\tqn2b1-011\tqn2b2-011";
String header_qn2b100= "\tqn2b0-100\tqn2b1-100\tqn2b2-100";
String header_qn2b101= "\tqn2b0-101\tqn2b1-101\tqn2b2-101";
String header_qn2b110= "\tqn2b0-110\tqn2b1-110\tqn2b2-110";
String header_qn2b111= "\tqn2b0-111\tqn2b1-111\tqn2b2-111";
String header_qn2b200= "\tqn2b0-200\tqn2b1-200\tqn2b2-200";
String header_qn2b201= "\tqn2b0-201\tqn2b1-201\tqn2b2-201";
String header_qn2b210= "\tqn2b0-210\tqn2b1-210\tqn2b2-210";
String header_qn2b211= "\tqn2b0-211\tqn2b1-211\tqn2b2-211";
String header_qn2b300= "\tqn2b0-300\tqn2b1-300\tqn2b2-300";
String header_qn2b301= "\tqn2b0-301\tqn2b1-301\tqn2b2-301";
String header_qn2b310= "\tqn2b0-310\tqn2b1-310\tqn2b2-310";
String header_qn2b311= "\tqn2b0-311\tqn2b1-311\tqn2b2-311";
String header_qn2b400= "\tqn2b0-400\tqn2b1-400\tqn2b2-400";
String header_qn2b401= "\tqn2b0-401\tqn2b1-401\tqn2b2-401";
String header_qn2b410= "\tqn2b0-410\tqn2b1-410\tqn2b2-410";
String header_qn2b411= "\tqn2b0-411\tqn2b1-411\tqn2b2-411";
String header_qn2b500= "\tqn2b0-500\tqn2b1-500\tqn2b2-500";
String header_qn2b501= "\tqn2b0-501\tqn2b1-501\tqn2b2-501";
String header_qn2b510= "\tqn2b0-510\tqn2b1-510\tqn2b2-510";
String header_qn2b511= "\tqn2b0-511\tqn2b1-511\tqn2b2-511";
String header = header_img+header_ins1+header_ins2+header_ins2_extra+header_pimu;
if (use_qn2b) {
header+=
header_qn2b000 + header_qn2b001 + header_qn2b010 + header_qn2b011 +
header_qn2b100 + header_qn2b101 + header_qn2b110 + header_qn2b111 +
header_qn2b200 + header_qn2b201 + header_qn2b210 + header_qn2b211 +
header_qn2b300 + header_qn2b301 + header_qn2b310 + header_qn2b311 +
header_qn2b400 + header_qn2b401 + header_qn2b410 + header_qn2b411 +
header_qn2b500 + header_qn2b501 + header_qn2b510 + header_qn2b511;
}
if (use_euler) {
header+=
header_cam000 + header_cam001 + header_cam010 + header_cam011 +
header_cam100 + header_cam101 + header_cam110 + header_cam111 +
header_cam200 + header_cam201 + header_cam210 + header_cam211 +
header_cam300 + header_cam301 + header_cam310 + header_cam311 +
header_cam400 + header_cam401 + header_cam410 + header_cam411 +
header_cam500 + header_cam501 + header_cam510 + header_cam511;
}
StringBuffer sb = new StringBuffer();
QuadCLT ref_scene = quadCLTs[ref_index];
ErsCorrection ers_reference = ref_scene.getErsCorrection();
double [][][] scenes_xyzatr = new double [quadCLTs.length][][];
for (int nscene = earliest_scene; nscene < quadCLTs.length; nscene++) {
QuadCLT scene = quadCLTs[nscene];
if (nscene == ref_index) {
scenes_xyzatr[nscene] = new double[2][3];
} else {
String ts = scene.getImageName();
scenes_xyzatr[nscene] = new double [][] {ers_reference.getSceneXYZ(ts),ers_reference.getSceneATR(ts)};
}
}
double [][][] dxyzatr_dt = getVelocitiesFromScenes(
quadCLTs, // QuadCLT [] scenes, // ordered by increasing timestamps
ref_index,
earliest_scene, // int start_scene,
quadCLTs.length-1, // int end1_scene,
scenes_xyzatr, // double [][][] scenes_xyzatr,
clt_parameters.ofp.lpf_series); // half_run_range); // double half_run_range
Did_ins_2 d2_ref = quadCLTs[ref_index].did_ins_2;
for (int nscene = earliest_scene; nscene < quadCLTs.length; nscene++) {
QuadCLT scene = quadCLTs[nscene];
if (scene == null) {
for (int i = 0; i < 26; i++) {
sb.append("\t---");
}
sb.append("\n");
continue;
}
double timestamp = scene.getTimeStamp();
Did_ins_1 d1 = scene.did_ins_1;
Did_ins_2 d2 = scene.did_ins_2;
Did_pimu d3 = scene.did_pimu;
sb.append(nscene+"\t"+timestamp);
// TODO: try saved, not calculated velocities!
sb.append("\t"+scenes_xyzatr[nscene][0][0]+"\t"+scenes_xyzatr[nscene][0][1]+"\t"+scenes_xyzatr[nscene][0][2]);
sb.append("\t"+scenes_xyzatr[nscene][1][0]+"\t"+scenes_xyzatr[nscene][1][1]+"\t"+scenes_xyzatr[nscene][1][2]);
sb.append("\t"+dxyzatr_dt[nscene][0][0]+"\t"+dxyzatr_dt[nscene][0][1]+"\t"+dxyzatr_dt[nscene][0][2]);
sb.append("\t"+dxyzatr_dt[nscene][1][0]+"\t"+dxyzatr_dt[nscene][1][1]+"\t"+dxyzatr_dt[nscene][1][2]);
// String header_ins1="\ttow\ttheta0\ttheta1\ttheta2\tu(m/s)\tv(m/s)\tw(m/s)"+
// "\tlong\tlat\talt\tned0\tned1\tned2";
sb.append("\t"+d1.timeOfWeek);
sb.append("\t"+d1.theta[0]+"\t"+d1.theta[1]+"\t"+d1.theta[2]);
sb.append("\t"+d1.uvw[0]+ "\t"+d1.uvw[1]+ "\t"+d1.uvw[2]);
sb.append("\t"+d1.lla[0]+ "\t"+d1.lla[1]+ "\t"+d1.lla[2]);
sb.append("\t"+d1.ned[0]+ "\t"+d1.ned[1]+ "\t"+d1.ned[2]);
// String header_ins2="\ttow\tqn2b0\tqn2b1\tqn2b2\tqn2b3\tu(m/s)\tv(m/s)\tw(m/s)\tlong\tlat\talt";
sb.append("\t"+d2.timeOfWeek);
sb.append("\t"+d2.qn2b[0]+"\t"+d2.qn2b[1]+"\t"+d2.qn2b[2]+"\t"+d2.qn2b[3]);
sb.append("\t"+d2.uvw[0]+ "\t"+d2.uvw[1]+ "\t"+d2.uvw[2]);
sb.append("\t"+d2.lla[0]+ "\t"+d2.lla[1]+ "\t"+d2.lla[2]);
double [] double_theta = new double [] {d1.theta[0], d1.theta[1], d1.theta[2]};
//imsToCamRotations(double [] ims_theta, boolean rev_order, boolean rev_matrix )
double [] double_qn2b = new double [] {d2.qn2b[0],d2.qn2b[1],d2.qn2b[2],d2.qn2b[3]};
double [] double_uvw = new double[] {d2.uvw[0],d2.uvw[1],d2.uvw[2]};
double [] uvw_dir = Imx5.applyQuternionTo(double_qn2b, double_uvw, false);
double [] uvw_inv = Imx5.applyQuternionTo(double_qn2b, double_uvw, true);
//Converting from local uvw to NED: (qn2b).applyInverseTo(uvw,ned) results in [vNorth, vEast, vUp]
double [] ned = Imx5.nedFromLla (d2.lla, d2_ref.lla);
double [] ims_xyz = Imx5.applyQuternionTo(double_qn2b, ned, false);
sb.append("\t"+ned[0]+ "\t"+ned[1]+ "\t"+ned[2]); // global axes
sb.append("\t"+ims_xyz[0]+ "\t"+ims_xyz[1]+ "\t"+ims_xyz[2]); // imu axes
sb.append("\t"+uvw_dir[0]+ "\t"+uvw_dir[1]+ "\t"+uvw_dir[2]); // wrong
sb.append("\t"+uvw_inv[0]+ "\t"+uvw_inv[1]+ "\t"+uvw_inv[2]); // correct
// String header_pimu="\to0\to1\to2\ta0\ta1\ta2";
sb.append("\t"+(d3.theta[0]/d3.dt)+"\t"+(d3.theta[1]/d3.dt)+"\t"+(d3.theta[2]/d3.dt));
sb.append("\t"+(d3.vel[0]/d3.dt)+"\t"+(d3.vel[1]/d3.dt)+"\t"+(d3.vel[2]/d3.dt));
// String header_cam= "\ttheta0\ttheta1\ttheta2\troll\tpitch\tyaw";
if (use_qn2b) {
double [] cam_qn2b_000 = Imx5.imsQToCamRotations(double_qn2b, 0, false, false);
double [] cam_qn2b_001 = Imx5.imsQToCamRotations(double_qn2b, 0, false, true);
double [] cam_qn2b_010 = Imx5.imsQToCamRotations(double_qn2b, 0, true, false);
double [] cam_qn2b_011 = Imx5.imsQToCamRotations(double_qn2b, 0, true, true);
double [] cam_qn2b_100 = Imx5.imsQToCamRotations(double_qn2b, 1, false, false);
double [] cam_qn2b_101 = Imx5.imsQToCamRotations(double_qn2b, 1, false, true);
double [] cam_qn2b_110 = Imx5.imsQToCamRotations(double_qn2b, 1, true, false);
double [] cam_qn2b_111 = Imx5.imsQToCamRotations(double_qn2b, 1, true, true);
double [] cam_qn2b_200 = Imx5.imsQToCamRotations(double_qn2b, 2, false, false);
double [] cam_qn2b_201 = Imx5.imsQToCamRotations(double_qn2b, 2, false, true);
double [] cam_qn2b_210 = Imx5.imsQToCamRotations(double_qn2b, 2, true, false);
double [] cam_qn2b_211 = Imx5.imsQToCamRotations(double_qn2b, 2, true, true);
double [] cam_qn2b_300 = Imx5.imsQToCamRotations(double_qn2b, 3, false, false);
double [] cam_qn2b_301 = Imx5.imsQToCamRotations(double_qn2b, 3, false, true);
double [] cam_qn2b_310 = Imx5.imsQToCamRotations(double_qn2b, 3, true, false);
double [] cam_qn2b_311 = Imx5.imsQToCamRotations(double_qn2b, 3, true, true);
double [] cam_qn2b_400 = Imx5.imsQToCamRotations(double_qn2b, 4, false, false);
double [] cam_qn2b_401 = Imx5.imsQToCamRotations(double_qn2b, 4, false, true);
double [] cam_qn2b_410 = Imx5.imsQToCamRotations(double_qn2b, 4, true, false);
double [] cam_qn2b_411 = Imx5.imsQToCamRotations(double_qn2b, 4, true, true);
double [] cam_qn2b_500 = Imx5.imsQToCamRotations(double_qn2b, 5, false, false);
double [] cam_qn2b_501 = Imx5.imsQToCamRotations(double_qn2b, 5, false, true);
double [] cam_qn2b_510 = Imx5.imsQToCamRotations(double_qn2b, 5, true, false);
double [] cam_qn2b_511 = Imx5.imsQToCamRotations(double_qn2b, 5, true, true);
sb.append("\t"+cam_qn2b_000[0]+"\t"+cam_qn2b_000[1]+"\t"+cam_qn2b_000[2]);
sb.append("\t"+cam_qn2b_001[0]+"\t"+cam_qn2b_001[1]+"\t"+cam_qn2b_001[2]);
sb.append("\t"+cam_qn2b_010[0]+"\t"+cam_qn2b_010[1]+"\t"+cam_qn2b_010[2]);
sb.append("\t"+cam_qn2b_011[0]+"\t"+cam_qn2b_011[1]+"\t"+cam_qn2b_011[2]);
sb.append("\t"+cam_qn2b_100[0]+"\t"+cam_qn2b_100[1]+"\t"+cam_qn2b_100[2]);
sb.append("\t"+cam_qn2b_101[0]+"\t"+cam_qn2b_101[1]+"\t"+cam_qn2b_101[2]);
sb.append("\t"+cam_qn2b_110[0]+"\t"+cam_qn2b_110[1]+"\t"+cam_qn2b_110[2]);
sb.append("\t"+cam_qn2b_111[0]+"\t"+cam_qn2b_111[1]+"\t"+cam_qn2b_111[2]);
sb.append("\t"+cam_qn2b_200[0]+"\t"+cam_qn2b_200[1]+"\t"+cam_qn2b_200[2]);
sb.append("\t"+cam_qn2b_201[0]+"\t"+cam_qn2b_201[1]+"\t"+cam_qn2b_201[2]);
sb.append("\t"+cam_qn2b_210[0]+"\t"+cam_qn2b_210[1]+"\t"+cam_qn2b_210[2]);
sb.append("\t"+cam_qn2b_211[0]+"\t"+cam_qn2b_211[1]+"\t"+cam_qn2b_211[2]);
sb.append("\t"+cam_qn2b_300[0]+"\t"+cam_qn2b_300[1]+"\t"+cam_qn2b_300[2]);
sb.append("\t"+cam_qn2b_301[0]+"\t"+cam_qn2b_301[1]+"\t"+cam_qn2b_301[2]);
sb.append("\t"+cam_qn2b_310[0]+"\t"+cam_qn2b_310[1]+"\t"+cam_qn2b_310[2]);
sb.append("\t"+cam_qn2b_311[0]+"\t"+cam_qn2b_311[1]+"\t"+cam_qn2b_311[2]);
sb.append("\t"+cam_qn2b_400[0]+"\t"+cam_qn2b_400[1]+"\t"+cam_qn2b_400[2]);
sb.append("\t"+cam_qn2b_401[0]+"\t"+cam_qn2b_401[1]+"\t"+cam_qn2b_401[2]);
sb.append("\t"+cam_qn2b_410[0]+"\t"+cam_qn2b_410[1]+"\t"+cam_qn2b_410[2]);
sb.append("\t"+cam_qn2b_411[0]+"\t"+cam_qn2b_411[1]+"\t"+cam_qn2b_411[2]);
sb.append("\t"+cam_qn2b_500[0]+"\t"+cam_qn2b_500[1]+"\t"+cam_qn2b_500[2]);
sb.append("\t"+cam_qn2b_501[0]+"\t"+cam_qn2b_501[1]+"\t"+cam_qn2b_501[2]);
sb.append("\t"+cam_qn2b_510[0]+"\t"+cam_qn2b_510[1]+"\t"+cam_qn2b_510[2]);
sb.append("\t"+cam_qn2b_511[0]+"\t"+cam_qn2b_511[1]+"\t"+cam_qn2b_511[2]);
}
if (use_euler) {
double [] cam_theta_000 = Imx5.imsToCamRotations(double_theta, 0, false, false);
double [] cam_theta_001 = Imx5.imsToCamRotations(double_theta, 0, false, true);
double [] cam_theta_010 = Imx5.imsToCamRotations(double_theta, 0, true, false);
double [] cam_theta_011 = Imx5.imsToCamRotations(double_theta, 0, true, true);
double [] cam_theta_100 = Imx5.imsToCamRotations(double_theta, 1, false, false);
double [] cam_theta_101 = Imx5.imsToCamRotations(double_theta, 1, false, true);
double [] cam_theta_110 = Imx5.imsToCamRotations(double_theta, 1, true, false);
double [] cam_theta_111 = Imx5.imsToCamRotations(double_theta, 1, true, true);
double [] cam_theta_200 = Imx5.imsToCamRotations(double_theta, 2, false, false);
double [] cam_theta_201 = Imx5.imsToCamRotations(double_theta, 2, false, true);
double [] cam_theta_210 = Imx5.imsToCamRotations(double_theta, 2, true, false);
double [] cam_theta_211 = Imx5.imsToCamRotations(double_theta, 2, true, true);
double [] cam_theta_300 = Imx5.imsToCamRotations(double_theta, 3, false, false);
double [] cam_theta_301 = Imx5.imsToCamRotations(double_theta, 3, false, true);
double [] cam_theta_310 = Imx5.imsToCamRotations(double_theta, 3, true, false);
double [] cam_theta_311 = Imx5.imsToCamRotations(double_theta, 3, true, true);
double [] cam_theta_400 = Imx5.imsToCamRotations(double_theta, 4, false, false);
double [] cam_theta_401 = Imx5.imsToCamRotations(double_theta, 4, false, true);
double [] cam_theta_410 = Imx5.imsToCamRotations(double_theta, 4, true, false);
double [] cam_theta_411 = Imx5.imsToCamRotations(double_theta, 4, true, true);
double [] cam_theta_500 = Imx5.imsToCamRotations(double_theta, 5, false, false);
double [] cam_theta_501 = Imx5.imsToCamRotations(double_theta, 5, false, true);
double [] cam_theta_510 = Imx5.imsToCamRotations(double_theta, 5, true, false);
double [] cam_theta_511 = Imx5.imsToCamRotations(double_theta, 5, true, true);
sb.append("\t"+cam_theta_000[0]+"\t"+cam_theta_000[1]+"\t"+cam_theta_000[2]);
sb.append("\t"+cam_theta_001[0]+"\t"+cam_theta_001[1]+"\t"+cam_theta_001[2]);
sb.append("\t"+cam_theta_010[0]+"\t"+cam_theta_010[1]+"\t"+cam_theta_010[2]);
sb.append("\t"+cam_theta_011[0]+"\t"+cam_theta_011[1]+"\t"+cam_theta_011[2]);
sb.append("\t"+cam_theta_100[0]+"\t"+cam_theta_100[1]+"\t"+cam_theta_100[2]);
sb.append("\t"+cam_theta_101[0]+"\t"+cam_theta_101[1]+"\t"+cam_theta_101[2]);
sb.append("\t"+cam_theta_110[0]+"\t"+cam_theta_110[1]+"\t"+cam_theta_110[2]);
sb.append("\t"+cam_theta_111[0]+"\t"+cam_theta_111[1]+"\t"+cam_theta_111[2]);
sb.append("\t"+cam_theta_200[0]+"\t"+cam_theta_200[1]+"\t"+cam_theta_200[2]);
sb.append("\t"+cam_theta_201[0]+"\t"+cam_theta_201[1]+"\t"+cam_theta_201[2]);
sb.append("\t"+cam_theta_210[0]+"\t"+cam_theta_210[1]+"\t"+cam_theta_210[2]);
sb.append("\t"+cam_theta_211[0]+"\t"+cam_theta_211[1]+"\t"+cam_theta_211[2]);
sb.append("\t"+cam_theta_300[0]+"\t"+cam_theta_300[1]+"\t"+cam_theta_300[2]);
sb.append("\t"+cam_theta_301[0]+"\t"+cam_theta_301[1]+"\t"+cam_theta_301[2]);
sb.append("\t"+cam_theta_310[0]+"\t"+cam_theta_310[1]+"\t"+cam_theta_310[2]);
sb.append("\t"+cam_theta_311[0]+"\t"+cam_theta_311[1]+"\t"+cam_theta_311[2]);
sb.append("\t"+cam_theta_400[0]+"\t"+cam_theta_400[1]+"\t"+cam_theta_400[2]);
sb.append("\t"+cam_theta_401[0]+"\t"+cam_theta_401[1]+"\t"+cam_theta_401[2]);
sb.append("\t"+cam_theta_410[0]+"\t"+cam_theta_410[1]+"\t"+cam_theta_410[2]);
sb.append("\t"+cam_theta_411[0]+"\t"+cam_theta_411[1]+"\t"+cam_theta_411[2]);
sb.append("\t"+cam_theta_500[0]+"\t"+cam_theta_500[1]+"\t"+cam_theta_500[2]);
sb.append("\t"+cam_theta_501[0]+"\t"+cam_theta_501[1]+"\t"+cam_theta_501[2]);
sb.append("\t"+cam_theta_510[0]+"\t"+cam_theta_510[1]+"\t"+cam_theta_510[2]);
sb.append("\t"+cam_theta_511[0]+"\t"+cam_theta_511[1]+"\t"+cam_theta_511[2]);
}
/*
sb.append("\t"+
cam_theta[0]*180/Math.PI+"\t"+
cam_theta[1]*180/Math.PI+"\t"+
cam_theta[2]*180/Math.PI);
*/
sb.append("\n");
}
if (path!=null) {
String footer=(comment != null) ? ("Comment: "+comment): "";
CalibrationFileManagement.saveStringToFile (
path,
header+"\n"+sb.toString()+"\n"+footer);
}else{
new TextWindow("Sharpness History", header, sb.toString(), 1000,900);
}
}
public void adjustLYSeries(
QuadCLT quadCLT_main, // update extrinsics here too
QuadCLT [] quadCLTs,
......
......@@ -37,7 +37,7 @@ import java.nio.channels.Channels;
import java.nio.channels.WritableByteChannel;
import java.util.Arrays;
import java.util.Properties;
import java.util.Random;
//import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.DoubleAccumulator;
......@@ -52,13 +52,13 @@ import com.elphel.imagej.correction.EyesisCorrections;
import com.elphel.imagej.gpu.GPUTileProcessor;
import com.elphel.imagej.gpu.GpuQuad;
import com.elphel.imagej.gpu.TpTask;
import com.elphel.imagej.tileprocessor.QuadCLTCPU.SetChannels;
//import com.elphel.imagej.tileprocessor.QuadCLTCPU.SetChannels;
import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.Prefs;
import ij.io.FileSaver;
//import ij.Prefs;
//import ij.io.FileSaver;
public class QuadCLT extends QuadCLTCPU {
int dbg_lev = 1;
private GpuQuad gpuQuad = null; // use updateQuadCLT() to update after switching to a different
......
......@@ -63,8 +63,15 @@ import com.elphel.imagej.common.PolynomialApproximation;
import com.elphel.imagej.common.ShowDoubleFloatArrays;
import com.elphel.imagej.correction.CorrectionColorProc;
import com.elphel.imagej.correction.EyesisCorrections;
import com.elphel.imagej.correction.Eyesis_Correction;
import com.elphel.imagej.gpu.GpuQuad;
import com.elphel.imagej.gpu.TpTask;
import com.elphel.imagej.ims.Did_gps_pos;
import com.elphel.imagej.ims.Did_ins_1;
import com.elphel.imagej.ims.Did_ins_2;
import com.elphel.imagej.ims.Did_pimu;
import com.elphel.imagej.ims.EventLogger;
import com.elphel.imagej.ims.Imx5;
import com.elphel.imagej.readers.ImagejJp4Tiff;
import com.elphel.imagej.x3d.export.TriMesh;
import com.elphel.imagej.x3d.export.WavefrontExport;
......@@ -168,6 +175,18 @@ public class QuadCLTCPU {
public int num_orient = 0;
//number of times scenes are accumulated: 0 - none, 1 - after first orientation, 2 - after second orientation
public int num_accum = 0;
// IMS data
public double ims_offs = Double.NaN; // IMS offset for which data was saved (positive - IMS lag is lower than images)
public double gmt_plus = Double.NaN;
public Did_ins_1 did_ins_1 = null;
public Did_ins_2 did_ins_2 = null;
public Did_pimu did_pimu = null;
public Did_gps_pos did_gps1_pos = null;
public Did_gps_pos did_gps2_pos = null;
public Did_gps_pos did_gps1_ubx_pos = null;
public String ims_last_path = null;
// TODO: Use dsi[] instead
// @Deprecated
// public boolean[] blue_sky = null;
......@@ -602,18 +621,25 @@ public class QuadCLTCPU {
return quadCLT;
}
public double getTimeStamp() {
String sts = image_name.replace("_", ".");
Matcher m = Pattern.compile("\\d").matcher(sts);
public static double getTimeStamp(String ts) {
String sts = ts.replace("_", ".");
// Matcher m = Pattern.compile("\\d").matcher(sts);
Matcher m = Pattern.compile("\\d{5,10}\\.\\d{6}").matcher(sts);
//
if(m.find()) {
sts = sts.substring(m.start());
sts = sts.substring(m.start(), m.end());
}
return Double.parseDouble(sts);
}
public double getTimeStamp() {
return getTimeStamp(image_name);
}
public String getImageName() {
return image_name;
}
public void setImageName(String name) {
image_name = name;
}
public String getX3dTopDirectory() { // replace direct calculations
String x3d_path = correctionsParameters.selectX3dDirectory( // for x3d and obj
......@@ -1821,7 +1847,9 @@ public class QuadCLTCPU {
}
properties = loadProperties(
path, // String path,
properties); // Properties properties)
properties, // Properties properties)
false); // boolean silent)
// if (properties == null) {
// properties = new Properties();
// }
......@@ -2112,6 +2140,15 @@ public class QuadCLTCPU {
threadsMax,
1); // debugLevel); // final int debug_level)
}
// optionally restore/generate IMS data
if (clt_parameters.imp.ims_use) {
restoreIms(
clt_parameters.imp.ims_offset, // double ims_offset,
clt_parameters.imp.gmt_plus, // double gmt_plus,
null, // String ims_path,
true, // boolean create,
debugLevelInner); // int debugLevel);
}
return this; // can only be QuadCLT instance
}
......@@ -2172,15 +2209,264 @@ public class QuadCLTCPU {
threadsMax,
1); // debugLevel); // final int debug_level)
}
// optionally restore/generate IMS data
if (clt_parameters.imp.ims_use) {
restoreIms(
clt_parameters.imp.ims_offset, // double ims_offset,
clt_parameters.imp.gmt_plus, // double gmt_plus,
null, // String ims_path,
true, // boolean create,
debugLevelInner); // int debugLevel);
}
return this; // can only be QuadCLT instance
}
/**
* Generate if needed and save several interpolated IMS DID-s
* @param ims_offset difference between the IMS snapshot time and images.
* Positive if IMS has lower latency
* @param gmt_plus hours from GMT to add to filename timestamp to get IMU log timestamp
* @param ims_path full file path or null (will be generated)
* @param debugLevel debug level
* @return true on success, false on failure
*/
public boolean saveIms(
double ims_offset,
double gmt_plus,
String ims_path,
int debugLevel) {
double this_ts;
if (ims_path == null) {
String model_dir = correctionsParameters.selectX3dDirectory(
image_name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
null,
true, // smart,
true); //newAllowed, // save
if (model_dir == null) {
return false;
}
ims_path = model_dir + Prefs.getFileSeparator()+image_name+correctionsParameters.imsSuffix; // String path,
this_ts= getTimeStamp();
} else {
this_ts=getTimeStamp(ims_path.substring(ims_path.lastIndexOf(Prefs.getFileSeparator())+1));
}
if ((getImageName()==null) || (getTimeStamp() != this_ts) || (ims_offset != this.ims_offs) || (gmt_plus != this.gmt_plus)){
// invalidate
this.ims_offs = ims_offset;
this.gmt_plus = gmt_plus;
did_ins_1 = null;
did_ins_2 = null;
did_pimu = null;
did_gps1_pos = null;
did_gps2_pos = null;
did_gps1_ubx_pos = null;
}
if (Eyesis_Correction.EVENT_LOGGER == null) {
System.out.println("Preparing IMS data as it is needed but does not exist");
String imx_logs = correctionsParameters.getImsSourceDirectory(); // sourceImsDirectory;
Eyesis_Correction.EVENT_LOGGER = new EventLogger (imx_logs);
}
EventLogger eventLogger = Eyesis_Correction.EVENT_LOGGER;
double ims_timestamp = this_ts + this.ims_offs + 3600 * gmt_plus;
if (did_ins_1 == null) {
try {did_ins_1=eventLogger.interpolateDidIns1(ims_timestamp, 0);}
catch (IOException e) {e.printStackTrace();}
}
if (did_ins_2 == null) {
try {did_ins_2=eventLogger.interpolateDidIns2(ims_timestamp, 0);}
catch (IOException e) {e.printStackTrace();}
}
if (did_pimu == null) {
try {did_pimu=eventLogger.interpolateDidPimu(ims_timestamp, 0);}
catch (IOException e) {e.printStackTrace();}
}
if (did_gps1_pos == null) {
try {did_gps1_pos=eventLogger.interpolateDidGpsPos(ims_timestamp, Imx5.DID_GPS1_POS, 0);}
catch (IOException e) {e.printStackTrace();}
}
if (did_gps2_pos == null) {
try {did_gps2_pos=eventLogger.interpolateDidGpsPos(ims_timestamp, Imx5.DID_GPS2_POS, 0);}
catch (IOException e) {e.printStackTrace();}
}
if (did_gps1_ubx_pos == null) {
try {did_gps1_ubx_pos=eventLogger.interpolateDidGpsPos(ims_timestamp, Imx5.DID_GPS1_UBX_POS, 0);}
catch (IOException e) {e.printStackTrace();}
}
Properties ims_properties = new Properties();
ims_properties.setProperty("ims_offs", this.ims_offs+"");
ims_properties.setProperty("gmt_plus", this.gmt_plus+"");
if (did_ins_1 != null) did_ins_1.setProperties("did_ins_1-", ims_properties);
if (did_ins_2 != null) did_ins_2.setProperties("did_ins_2-", ims_properties);
if (did_pimu != null) did_pimu.setProperties("did_pimu-", ims_properties);
if (did_gps1_pos != null) did_gps1_pos.setProperties("did_gps1_pos-", ims_properties);
if (did_gps2_pos != null) did_gps2_pos.setProperties("did_gps2_pos-", ims_properties);
if (did_gps1_ubx_pos != null) did_gps1_ubx_pos.setProperties("did_gps1_ubx_pos-", ims_properties);
//Properties setProperties(String prefix, Properties properties)
// ims_path
OutputStream os;
try {
os = new FileOutputStream(ims_path);
} catch (FileNotFoundException e1) {
// missing config directory
File dir = (new File(ims_path)).getParentFile();
if (!dir.exists()){
dir.mkdirs();
try {
os = new FileOutputStream(ims_path);
} catch (FileNotFoundException e2) {
IJ.showMessage("Error","Failed to create directory "+dir.getName()+" to save configuration file: "+ims_path);
return false;
}
} else {
IJ.showMessage("Error","Failed to open configuration file: "+ims_path);
return false;
}
}
try {
ims_properties.storeToXML(os,
"last updated " + new java.util.Date(), "UTF8");
} catch (IOException e) {
IJ.showMessage("Error","Failed to write XML configuration file: "+ims_path);
return false;
}
try {
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ims_last_path = ims_path;
if (debugLevel> -3) {
System.out.println("IMS parameters are saved to "+ims_path);
}
return true;
}
/**
* Restore IMS data, regenerate and save if it does not exist or was generated for
* different ims_offset
* @param ims_offset difference between the IMS snapshot time and images.
* Positive if IMS has lower latency
* @param gmt_plus hours from GMT to add to filename timestamp to get IMU log timestamp
* @param ims_path full file path or null (will be generated)
* @param create generate if does not exist
* @param debugLevel debug level
* @return true on success, false on failure
*/
public boolean restoreIms(
double ims_offset,
double gmt_plus,
String ims_path,
boolean create,
int debugLevel) {
if (ims_path == null) {
String model_dir = correctionsParameters.selectX3dDirectory(
image_name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
null,
true, // smart,
false); //newAllowed, // save
if (model_dir == null) {
return false;
}
ims_path = model_dir + Prefs.getFileSeparator()+image_name+correctionsParameters.imsSuffix; // String path,
}
if (ims_path.equals(this.ims_last_path) && (ims_offset == this.ims_offs) && (gmt_plus == this.gmt_plus)) {
return true;
}
Properties ims_properties = loadProperties(
ims_path, // String path,
null, // Properties properties)
true); // boolean silent)
// temporary to recalculate if no did_ins_2:
{
Did_ins_2 did_ins_2 = new Did_ins_2("did_ins_2-", ims_properties);
if ((did_ins_2.lla == null) || ((did_ins_2.lla[0]==0) && (did_ins_2.lla[1]==0))) {
ims_properties = null;
System.out.println("restoreIms(): no did_ins_2 - invalidating and recalculating config");
}
}
if (ims_properties == null) {
if (create) {
saveIms(ims_offset, gmt_plus, ims_path, debugLevel);
ims_properties = loadProperties(
ims_path, // String path,
null, // Properties properties)
true); // boolean silent)
}
if (ims_properties == null) {
if (debugLevel> -3) {
System.out.println("Failed to read IMS properties file: "+ims_path);
}
return false;
}
}
this.ims_offs = Double.NaN;
this.gmt_plus = Double.NaN;
if (ims_properties.getProperty("ims_offs")!=null) this.ims_offs=Double.parseDouble(ims_properties.getProperty("ims_offs"));
if (ims_properties.getProperty("gmt_plus")!=null) this.gmt_plus=Double.parseDouble(ims_properties.getProperty("gmt_plus"));
if ((this.ims_offs != ims_offset) || (this.gmt_plus != gmt_plus)) {
if (debugLevel> -3) {
System.out.println("IMS offset differs, recalculating "+ims_path);
}
saveIms(ims_offset, gmt_plus, ims_path, debugLevel);
}
did_ins_1 = new Did_ins_1("did_ins_1-", ims_properties);
did_ins_2 = new Did_ins_2("did_ins_2-", ims_properties);
did_pimu = new Did_pimu("did_pimu-", ims_properties);
did_gps1_pos = new Did_gps_pos("did_gps1_pos-", ims_properties);
did_gps2_pos = new Did_gps_pos("did_gps2_pos-", ims_properties);
did_gps1_ubx_pos = new Did_gps_pos("did_gps1_ubx_pos-", ims_properties);
ims_last_path = ims_path;
if (debugLevel> -3) {
System.out.println("IMS parameters are restored from "+ims_path);
}
return true;
}
/**
* Read ims_offset from the saved IMS data. Return Double.NaN if file does not exist
* @param ims_path full file path or null (will be generated)
* @param debugLevel debug level
* @return difference between the IMS snapshot time and images or NaN if file does not exist.
* Positive if IMS has lower latency
*/
public double [] readImsOffset(
String ims_path,
int debugLevel) {
if (ims_path == null) {
String model_dir = correctionsParameters.selectX3dDirectory(
image_name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
null,
true, // smart,
false); //newAllowed, // save
if (model_dir == null) {
return null;
}
ims_path = model_dir + Prefs.getFileSeparator()+image_name+correctionsParameters.imsSuffix; // String path,
}
Properties ims_properties = loadProperties(
ims_path, // String path,
null, // Properties properties)
true); // boolean silent)
if (ims_properties == null) {
System.out.println("Failed to read IMS properties file: "+ims_path);
// IJ.showMessage("Error","Failed to read IMS properties file: "+ims_path);
return null;
}
double [] rslt = {Double.NaN,Double.NaN};
if (ims_properties.getProperty("ims_offs")!=null) rslt[0] = Double.parseDouble(ims_properties.getProperty("ims_offs"));
if (ims_properties.getProperty("gmt_plus")!=null) rslt[1] = Double.parseDouble(ims_properties.getProperty("gmt_plus"));
return rslt;
}
// generate and save noise file (each Bayer component amplitude same as the corresponding image average,
// apply gaussian blur with sigma (before Bayer scaling)
// apply Gaussian blur with sigma (before Bayer scaling)
// If file with the same sigma already exists in the model directory - just use it, multiply by noise_sigma_level[0] and add to the non-zero Bayer
......@@ -2862,7 +3148,8 @@ public class QuadCLTCPU {
public static Properties loadProperties(
String path,
Properties properties){
Properties properties,
boolean silent){
if (properties == null) {
properties = new Properties();
}
......@@ -2870,14 +3157,18 @@ public class QuadCLTCPU {
try {
is = new FileInputStream(path);
} catch (FileNotFoundException e) {
IJ.showMessage("Error","Failed to open configuration file: "+path);
if (!silent) {
IJ.showMessage("Error","Failed to open configuration file: "+path);
}
return null;
}
try {
properties.loadFromXML(is);
} catch (IOException e) {
IJ.showMessage("Error","Failed to read XML configuration file: "+path);
if (!silent) {
IJ.showMessage("Error","Failed to read XML configuration file: "+path);
}
return null;
}
try {
......
......@@ -2982,7 +2982,7 @@ if (debugLevel > -100) return true; // temporarily !
* @param quadCLT_aux secondary RGB or LWIR QuadCLT instance
* @param clt_parameters CLT parameters
* @param skip_existing do not copy if destination files exist
* @param search_KML search fpr geo data and extract it to KML file if found
* @param search_KML search for geo data and extract it to KML file if found
* @param debugLevel debug level
*/
public static void copyJP4src(
......@@ -3012,6 +3012,7 @@ if (debugLevel > -100) return true; // temporarily !
set_name = set_channels[00].set_name;
}
QuadCLT.SetChannels [] set_channels_main = quadCLT_main.setChannels(set_name,debugLevel); // only for specified image timestamp
QuadCLT.SetChannels [] set_channels_aux = (quadCLT_aux !=null) ? quadCLT_aux.setChannels(set_name,debugLevel) : null;
......@@ -3036,20 +3037,39 @@ if (debugLevel > -100) return true; // temporarily !
true, // smart,
true); //newAllowed, // save
File dir = (new File(jp4_copy_path)); // .getParentFile();
boolean already_copied = false;
if (!dir.exists()){
dir.mkdirs();
System.out.println("Created "+dir);
} else if (skip_existing) {
if (dir.list().length > 0) {
System.out.println("Skipping existing directory "+dir);
return;
already_copied = true;
}
}
if (clt_parameters.imp.ims_use) {
String ims_path = dir.getParent() + Prefs.getFileSeparator()+set_name+quadCLT_main.correctionsParameters.imsSuffix;
double [] saved_offset = quadCLT_main.readImsOffset(
ims_path, // String ims_path,
debugLevel); // int debugLevel)
if ((saved_offset == null) || (saved_offset[0] != clt_parameters.imp.ims_offset) || (saved_offset[1] != clt_parameters.imp.gmt_plus)) {
quadCLT_main.saveIms(
clt_parameters.imp.ims_offset,
clt_parameters.imp.gmt_plus, // double gmt_plus,
ims_path,
debugLevel);
}
}
if (search_KML && (set_channels_main !=null)) { // TODO: make it look in both MAIN and AUX. Look in only the same scene?
quadCLT_main.writeKml(
set_name,
debugLevel ); // also generated with x3d model
}
if (already_copied) {
System.out.println("Skipping existing directory "+dir);
return;
}
for (String fname:path_list) {
if (fname.contains(set_name)) { // only files containing set name // TODO:improve
File file = new File(fname);
......
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