Commit cb61d659 authored by Andrey Filippov's avatar Andrey Filippov

Putting all together, adding generation of thumbnails, KML, etc.

parent 9c02927a
...@@ -226,16 +226,19 @@ public class BiQuadParameters { ...@@ -226,16 +226,19 @@ public class BiQuadParameters {
public boolean ml_generate = false; // Generate ML data automatically when running ground truth
public boolean ml_poles = true; // Generate ML data from the DSI that includes extracted poles
public boolean ml_copyJP4 = true; // Copy source jp4 files when running "Ground truth" command
public int ml_hwidth = 2; // Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5) public int ml_hwidth = 4; // Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5)
public double ml_disparity_sweep = 2.0; // Disparity sweep around ground truth, each side public double ml_disparity_sweep = 1.0; // Disparity sweep around ground truth, each side
public int ml_sweep_steps = 5; // Number of disparity sweep steps public int ml_sweep_steps = 21; // Number of disparity sweep steps
public boolean ml_keep_aux = true; // include auxiliary camera data in the ML output public boolean ml_keep_aux = false; // true; // include auxiliary camera data in the ML output
public boolean ml_keep_inter = true; // include inter-camera correlation data in the ML output public boolean ml_keep_inter = false; // true; // include inter-camera correlation data in the ML output
public boolean ml_keep_hor_vert = true; // include combined horizontal and vertical pairs data in the ML output public boolean ml_keep_hor_vert = true; // include combined horizontal and vertical pairs data in the ML output
public boolean ml_keep_tbrl = true; // include individual top, bottom, right, left pairs public boolean ml_keep_tbrl = false; // true; // include individual top, bottom, right, left pairs
public boolean ml_keep_debug= true; // include debug layer(s) data in the ML output public boolean ml_keep_debug= false; // true; // include debug layer(s) data in the ML output
public boolean ml_8bit= true; // output in 8-bit format (default - 32-bit TIFF public boolean ml_8bit= true; // output in 8-bit format (default - 32-bit TIFF
public double ml_limit_extrim = 0.00001; // ignore lowest and highest values when converting to 8 bpp public double ml_limit_extrim = 0.00001; // ignore lowest and highest values when converting to 8 bpp
public boolean ml_show_ml = true; // show each generated MLoutput file public boolean ml_show_ml = true; // show each generated MLoutput file
...@@ -311,7 +314,7 @@ public class BiQuadParameters { ...@@ -311,7 +314,7 @@ public class BiQuadParameters {
gd.addNumericField("Minimal RMS improvement after short cycle to exit", this.rig_adjust_short_threshold, 3,6,"", gd.addNumericField("Minimal RMS improvement after short cycle to exit", this.rig_adjust_short_threshold, 3,6,"",
"Short cycle iteration finish after relative RMS improvement is less than this of maximal number of steps is exceeded"); "Short cycle iteration finish after relative RMS improvement is less than this of maximal number of steps is exceeded");
gd.addCheckbox ("Adjust orientation (azimuth, tilt, roll) of the auxiliary camera", this.rig_adjust_orientation,"3 angles, most basic adjustment"); gd.addCheckbox ("Adjust orientation (azimuth, tilt, roll) of the auxiliary camera", this.rig_adjust_orientation,"3 angles, most basic adjustment");
gd.addCheckbox ("Adjust orientation relative zoom of the auxiliary camera", this.rig_adjust_zoom,"Not likely to change, may be frozen"); gd.addCheckbox ("Adjust relative zoom of the auxiliary camera", this.rig_adjust_zoom,"Not likely to change, may be frozen");
gd.addCheckbox ("Adjust position of the aux camera in the main camera pricipal plane", this.rig_adjust_angle,"0 - exactly to the right, positive - higher than main"); gd.addCheckbox ("Adjust position of the aux camera in the main camera pricipal plane", this.rig_adjust_angle,"0 - exactly to the right, positive - higher than main");
gd.addCheckbox ("Adjust aux camera distance from the main", this.rig_adjust_distance,"Normally not practical, rely on direct measurement"); gd.addCheckbox ("Adjust aux camera distance from the main", this.rig_adjust_distance,"Normally not practical, rely on direct measurement");
gd.addCheckbox ("Adjust aux camera distance from the main principal plane", this.rig_adjust_forward,"Not implemented, assumed zero"); gd.addCheckbox ("Adjust aux camera distance from the main principal plane", this.rig_adjust_forward,"Not implemented, assumed zero");
...@@ -600,6 +603,13 @@ public class BiQuadParameters { ...@@ -600,6 +603,13 @@ public class BiQuadParameters {
gd.addTab("ML","Parameters related to the ML files generation for the dual-quad camera rig"); gd.addTab("ML","Parameters related to the ML files generation for the dual-quad camera rig");
gd.addCheckbox ("Generate ML data automatically", this.ml_generate,
"Generate ML data automatically when running ground truth (may run separately from a command button)");
gd.addCheckbox ("Generate ML data from the DSI that includes extracted poles", this.ml_poles,
"If unchecked - use DSI w/o poles data");
gd.addCheckbox ("Copy JP4 source images when generating ML data", this.ml_copyJP4,
"Possible to run by a command button");
gd.addNumericField("Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5)", this.ml_hwidth, 0,3,"", gd.addNumericField("Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5)", this.ml_hwidth, 0,3,"",
"Amount of data to export to the ML system"); "Amount of data to export to the ML system");
gd.addNumericField("Disparity sweep around ground truth, each side", this.ml_disparity_sweep, 3,6,"", gd.addNumericField("Disparity sweep around ground truth, each side", this.ml_disparity_sweep, 3,6,"",
...@@ -802,6 +812,10 @@ public class BiQuadParameters { ...@@ -802,6 +812,10 @@ public class BiQuadParameters {
this.rf_min_disp= gd.getNextNumber(); this.rf_min_disp= gd.getNextNumber();
this.rf_remove_unselected= gd.getNextBoolean(); this.rf_remove_unselected= gd.getNextBoolean();
this.ml_generate= gd.getNextBoolean();
this.ml_poles= gd.getNextBoolean();
this.ml_copyJP4= gd.getNextBoolean();
this.ml_hwidth= (int) gd.getNextNumber(); this.ml_hwidth= (int) gd.getNextNumber();
this.ml_disparity_sweep= gd.getNextNumber(); this.ml_disparity_sweep= gd.getNextNumber();
this.ml_sweep_steps= (int) gd.getNextNumber(); this.ml_sweep_steps= (int) gd.getNextNumber();
...@@ -995,6 +1009,9 @@ public class BiQuadParameters { ...@@ -995,6 +1009,9 @@ public class BiQuadParameters {
properties.setProperty(prefix+"rf_min_disp", this.rf_min_disp+""); properties.setProperty(prefix+"rf_min_disp", this.rf_min_disp+"");
properties.setProperty(prefix+"rf_remove_unselected", this.rf_remove_unselected+""); properties.setProperty(prefix+"rf_remove_unselected", this.rf_remove_unselected+"");
properties.setProperty(prefix+"ml_generate", this.ml_generate+"");
properties.setProperty(prefix+"ml_poles", this.ml_poles+"");
properties.setProperty(prefix+"ml_copyJP4", this.ml_copyJP4+"");
properties.setProperty(prefix+"ml_hwidth", this.ml_hwidth+""); properties.setProperty(prefix+"ml_hwidth", this.ml_hwidth+"");
properties.setProperty(prefix+"ml_disparity_sweep", this.ml_disparity_sweep+""); properties.setProperty(prefix+"ml_disparity_sweep", this.ml_disparity_sweep+"");
properties.setProperty(prefix+"ml_sweep_steps", this.ml_sweep_steps+""); properties.setProperty(prefix+"ml_sweep_steps", this.ml_sweep_steps+"");
...@@ -1185,6 +1202,9 @@ public class BiQuadParameters { ...@@ -1185,6 +1202,9 @@ public class BiQuadParameters {
if (properties.getProperty(prefix+"rf_min_disp")!=null) this.rf_min_disp=Double.parseDouble(properties.getProperty(prefix+"rf_min_disp")); if (properties.getProperty(prefix+"rf_min_disp")!=null) this.rf_min_disp=Double.parseDouble(properties.getProperty(prefix+"rf_min_disp"));
if (properties.getProperty(prefix+"rf_remove_unselected")!=null) this.rf_remove_unselected=Boolean.parseBoolean(properties.getProperty(prefix+"rf_remove_unselected")); if (properties.getProperty(prefix+"rf_remove_unselected")!=null) this.rf_remove_unselected=Boolean.parseBoolean(properties.getProperty(prefix+"rf_remove_unselected"));
if (properties.getProperty(prefix+"ml_generate")!=null) this.ml_generate=Boolean.parseBoolean(properties.getProperty(prefix+"ml_generate"));
if (properties.getProperty(prefix+"ml_poles")!=null) this.ml_poles=Boolean.parseBoolean(properties.getProperty(prefix+"ml_poles"));
if (properties.getProperty(prefix+"ml_copyJP4")!=null) this.ml_copyJP4=Boolean.parseBoolean(properties.getProperty(prefix+"ml_copyJP4"));
if (properties.getProperty(prefix+"ml_hwidth")!=null) this.ml_hwidth=Integer.parseInt(properties.getProperty(prefix+"ml_hwidth")); if (properties.getProperty(prefix+"ml_hwidth")!=null) this.ml_hwidth=Integer.parseInt(properties.getProperty(prefix+"ml_hwidth"));
if (properties.getProperty(prefix+"ml_disparity_sweep")!=null) this.ml_disparity_sweep=Double.parseDouble(properties.getProperty(prefix+"ml_disparity_sweep")); if (properties.getProperty(prefix+"ml_disparity_sweep")!=null) this.ml_disparity_sweep=Double.parseDouble(properties.getProperty(prefix+"ml_disparity_sweep"));
if (properties.getProperty(prefix+"ml_sweep_steps")!=null) this.ml_sweep_steps=Integer.parseInt(properties.getProperty(prefix+"ml_sweep_steps")); if (properties.getProperty(prefix+"ml_sweep_steps")!=null) this.ml_sweep_steps=Integer.parseInt(properties.getProperty(prefix+"ml_sweep_steps"));
...@@ -1376,6 +1396,9 @@ public class BiQuadParameters { ...@@ -1376,6 +1396,9 @@ public class BiQuadParameters {
bqp.rf_min_disp= this.rf_min_disp; bqp.rf_min_disp= this.rf_min_disp;
bqp.rf_remove_unselected= this.rf_remove_unselected; bqp.rf_remove_unselected= this.rf_remove_unselected;
bqp.ml_generate= this.ml_generate;
bqp.ml_poles= this.ml_poles;
bqp.ml_copyJP4= this.ml_copyJP4;
bqp.ml_hwidth= this.ml_hwidth; bqp.ml_hwidth= this.ml_hwidth;
bqp.ml_disparity_sweep= this.ml_disparity_sweep; bqp.ml_disparity_sweep= this.ml_disparity_sweep;
bqp.ml_sweep_steps= this.ml_sweep_steps; bqp.ml_sweep_steps= this.ml_sweep_steps;
......
...@@ -871,10 +871,10 @@ public class BiScan { ...@@ -871,10 +871,10 @@ public class BiScan {
System.out.println("suggestNewScan(): nTile="+nTile+" w="+w); System.out.println("suggestNewScan(): nTile="+nTile+" w="+w);
System.out.println("suggestNewScan(): nTile="+nTile+" w="+w); System.out.println("suggestNewScan(): nTile="+nTile+" w="+w);
} }
if (nTile == 66945) { // if (nTile == 66945) {
System.out.println("suggestNewScan(): nTile="+nTile+" w="+w); // System.out.println("suggestNewScan(): nTile="+nTile+" w="+w);
System.out.println("suggestNewScan(): nTile="+nTile+" w="+w); // System.out.println("suggestNewScan(): nTile="+nTile+" w="+w);
} // }
} }
} }
......
...@@ -2443,7 +2443,7 @@ public class EyesisCorrections { ...@@ -2443,7 +2443,7 @@ public class EyesisCorrections {
} }
} }
if (hasAlphaHighByte){ if (hasAlphaHighByte && (jpegQuality <= 0)){
if (png){ if (png){
if (debugLevel > 0) System.out.println("Saving RGBA result to "+path+".png"); if (debugLevel > 0) System.out.println("Saving RGBA result to "+path+".png");
(new EyesisTiff()).savePNG_ARGB32( (new EyesisTiff()).savePNG_ARGB32(
......
...@@ -552,7 +552,7 @@ private Panel panel1, ...@@ -552,7 +552,7 @@ private Panel panel1,
addButton("CLT infinity corr", panelClt2, color_conf_process); addButton("CLT infinity corr", panelClt2, color_conf_process);
addButton("CLT ext infinity corr", panelClt2, color_conf_process); addButton("CLT ext infinity corr", panelClt2, color_conf_process);
addButton("CLT reset 3D", panelClt2, color_stop); addButton("CLT reset 3D", panelClt2, color_stop);
addButton("CLT Extrinsics", panelClt2, color_process); addButton("MAIN extrinsics", panelClt2, color_process);
addButton("CLT Poly corr", panelClt2, color_process); addButton("CLT Poly corr", panelClt2, color_process);
addButton("CLT 3D", panelClt2, color_process); addButton("CLT 3D", panelClt2, color_process);
addButton("CLT planes", panelClt2, color_conf_process); addButton("CLT planes", panelClt2, color_conf_process);
...@@ -583,19 +583,21 @@ private Panel panel1, ...@@ -583,19 +583,21 @@ private Panel panel1,
// addButton("CLT 2*4 images", panelClt4, color_conf_process); // addButton("CLT 2*4 images", panelClt4, color_conf_process);
// addButton("CLT 2*4 images - 2", panelClt4, color_conf_process); // addButton("CLT 2*4 images - 2", panelClt4, color_conf_process);
// addButton("CLT 2*4 images - 3", panelClt4, color_conf_process); // addButton("CLT 2*4 images - 3", panelClt4, color_conf_process);
addButton("SHOW extrinsics", panelClt4, color_configure);
addButton("MAIN extrinsics", panelClt4, color_process);
addButton("RIG extrinsics", panelClt4, color_conf_process);
addButton("AUX extrinsics", panelClt4, color_process);
addButton("Rig8 images", panelClt4, color_conf_process); addButton("Rig8 images", panelClt4, color_conf_process);
addButton("Rig infinity calibration", panelClt4, color_conf_process);
addButton("AUX Extrinsics", panelClt4, color_process); // addButton("Rig enhance", panelClt4, color_conf_process);
addButton("AUX show fine", panelClt4, color_configure);
// addButton("Rig enhance", panelClt4, color_conf_process);
// /"Reset GT" // /"Reset GT"
addButton("Reset GT", panelClt4, color_stop); addButton("Reset GT", panelClt4, color_stop);
addButton("Ground truth 0", panelClt4, color_configure); // addButton("Ground truth 0", panelClt4, color_configure);
addButton("Ground truth", panelClt4, color_conf_process); addButton("Ground truth", panelClt4, color_conf_process);
addButton("Show biscan", panelClt4, color_configure); addButton("Show biscan", panelClt4, color_configure);
addButton("Poles GT", panelClt4, color_process); addButton("Poles GT", panelClt4, color_process);
addButton("ML export", panelClt4, color_conf_process); addButton("ML export", panelClt4, color_conf_process);
addButton("Rig planes", panelClt4, color_conf_process); addButton("JP4 copy", panelClt4, color_conf_process);
add(panelClt4); add(panelClt4);
...@@ -4253,9 +4255,9 @@ private Panel panel1, ...@@ -4253,9 +4255,9 @@ private Panel panel1,
/// ============================================ /// ============================================
} else if (label.equals("CLT 3D") || label.equals("CLT Extrinsics") || label.equals("CLT Poly corr")) { } else if (label.equals("CLT 3D") || label.equals("MAIN extrinsics") || label.equals("CLT Poly corr")) {
boolean adjust_extrinsics = label.equals("CLT Extrinsics") || label.equals("CLT Poly corr"); boolean adjust_extrinsics = label.equals("MAIN extrinsics") || label.equals("CLT Poly corr");
boolean adjust_poly = label.equals("CLT Poly corr"); boolean adjust_poly = label.equals("CLT Poly corr");
DEBUG_LEVEL=MASTER_DEBUG_LEVEL; DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL); EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
...@@ -4333,8 +4335,8 @@ private Panel panel1, ...@@ -4333,8 +4335,8 @@ private Panel panel1,
} }
*/ */
return; return;
} else if (label.equals("AUX Extrinsics") || label.equals("AUX Poly corr")) { } else if (label.equals("AUX extrinsics") || label.equals("AUX Poly corr")) {
boolean adjust_extrinsics = label.equals("AUX Extrinsics") || label.equals("AUX Poly corr"); boolean adjust_extrinsics = label.equals("AUX extrinsics") || label.equals("AUX Poly corr");
boolean adjust_poly = label.equals("AUX Poly corr"); boolean adjust_poly = label.equals("AUX Poly corr");
DEBUG_LEVEL=MASTER_DEBUG_LEVEL; DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL); EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
...@@ -4567,13 +4569,13 @@ private Panel panel1, ...@@ -4567,13 +4569,13 @@ private Panel panel1,
getPairImages2(true); getPairImages2(true);
return; return;
/* ======================================================================== */ /* ======================================================================== */
} else if (label.equals("Rig infinity calibration")) { } else if (label.equals("RIG extrinsics")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL; DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL); EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
infinityRig(); infinityRig();
return; return;
/* ======================================================================== */ /* ======================================================================== */
} else if (label.equals("AUX show fine")) { } else if (label.equals("SHOW extrinsics")) {
if (QUAD_CLT == null){ if (QUAD_CLT == null){
QUAD_CLT = new QuadCLT ( QUAD_CLT = new QuadCLT (
QuadCLT.PREFIX, QuadCLT.PREFIX,
...@@ -4599,6 +4601,8 @@ private Panel panel1, ...@@ -4599,6 +4601,8 @@ private Panel panel1,
} }
} }
QUAD_CLT_AUX.showExtrinsicCorr("aux");// show_fine_corr("aux"); QUAD_CLT_AUX.showExtrinsicCorr("aux");// show_fine_corr("aux");
QUAD_CLT_AUX.geometryCorrection.showRig();// show_fine_corr("aux");
QuadCLT dbg_QUAD_CLT = QUAD_CLT; QuadCLT dbg_QUAD_CLT = QUAD_CLT;
QuadCLT dbg_QUAD_CLT_AUX = QUAD_CLT_AUX; QuadCLT dbg_QUAD_CLT_AUX = QUAD_CLT_AUX;
...@@ -4649,6 +4653,12 @@ private Panel panel1, ...@@ -4649,6 +4653,12 @@ private Panel panel1,
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL); EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
exportMLData(); exportMLData();
return; return;
/* ======================================================================== */
} else if (label.equals("JP4 copy")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
copyJP4src();
return;
/* ======================================================================== */ /* ======================================================================== */
} else if (label.equals("CLT rig edit")) { } else if (label.equals("CLT rig edit")) {
...@@ -5163,7 +5173,7 @@ private Panel panel1, ...@@ -5163,7 +5173,7 @@ private Panel panel1,
return true; return true;
} }
// boolean adjust_extrinsics = label.equals("CLT Extrinsics") || label.equals("CLT Poly corr"); // boolean adjust_extrinsics = label.equals("MAIN extrinsics") || label.equals("CLT Poly corr");
// boolean adjust_poly = label.equals("CLT Poly corr"); // boolean adjust_poly = label.equals("CLT Poly corr");
public boolean clt3d( public boolean clt3d(
boolean adjust_extrinsics, boolean adjust_extrinsics,
...@@ -5285,8 +5295,8 @@ private Panel panel1, ...@@ -5285,8 +5295,8 @@ private Panel panel1,
public boolean exportMLData() { public boolean exportMLData() {
long startTime=System.nanoTime(); long startTime=System.nanoTime();
if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) { if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.rig_pre_poles_ds == null)) {
String msg = "DSI data is not available. Please run \"CLT 3D\" first"; String msg = "DSI data is not available. Please run \"Ground truth\" first";
IJ.showMessage("Error",msg); IJ.showMessage("Error",msg);
System.out.println(msg); System.out.println(msg);
return false; return false;
...@@ -5325,6 +5335,94 @@ private Panel panel1, ...@@ -5325,6 +5335,94 @@ private Panel panel1,
return true; return true;
} }
public boolean copyJP4src() {
if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) {
if (QUAD_CLT == null){
QUAD_CLT = new QuadCLT (
QuadCLT.PREFIX,
PROPERTIES,
EYESIS_CORRECTIONS,
CORRECTION_PARAMETERS);
if (DEBUG_LEVEL > 0){
System.out.println("Created new QuadCLT instance, will need to read CLT kernels");
}
}
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return false;
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL);
int numChannels=EYESIS_CORRECTIONS.getNumChannels();
CHANNEL_GAINS_PARAMETERS.modifyNumChannels(numChannels);
if (!QUAD_CLT.CLTKernelsAvailable()){
if (DEBUG_LEVEL > 0){
System.out.println("Reading CLT kernels");
}
QUAD_CLT.readCLTKernels(
CLT_PARAMETERS,
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
if (DEBUG_LEVEL > 1){
QUAD_CLT.showCLTKernels(
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
}
}
if (!QUAD_CLT.geometryCorrectionAvailable()){
if (DEBUG_LEVEL > 0){
System.out.println("Calculating geometryCorrection");
}
if (!QUAD_CLT.initGeometryCorrection(DEBUG_LEVEL+2)){
return false;
}
}
/*
boolean OK = clt3d(
false, // boolean adjust_extrinsics,
false); // boolean adjust_poly);
if (! OK) {
String msg = "DSI data is not available and \"CLT 3D\" failed";
IJ.showMessage("Error",msg);
System.out.println(msg);
return false;
}
*/
}
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return false;
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Copying JP4 source files ++++++++++++++");
}
try {
TWO_QUAD_CLT.copyJP4src( // actually there is no sense to process multiple image sets. Combine with other processing?
QUAD_CLT, // QuadCLT quadCLT_main,
QUAD_CLT_AUX, // QuadCLT quadCLT_aux,
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBUG_LEVEL);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //final int debugLevel);
if (configPath!=null) {
saveTimestampedProperties( // save config again
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
}
return true;
}
public boolean infinityRig() { public boolean infinityRig() {
if (!prepareRigImages()) return false; if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath(); String configPath=getSaveCongigPath();
......
...@@ -890,6 +890,19 @@ public class GeometryCorrection { ...@@ -890,6 +890,19 @@ public class GeometryCorrection {
recalcRXY(); recalcRXY();
return true; return true;
} }
public void showRigOffsets()
{
System.out.println("=== Inter-camera adjustments ===");
System.out.println(" Baseline "+ this.baseline +"mm");
System.out.println(" Angle to the aux camera from the main "+ (180.0/Math.PI*this.aux_angle)+"°");
System.out.println("Auxilliary camera forward from the plane of the main one (not used) "+ this.aux_z +"mm");
System.out.println(" Auxilliary camera azimuth (positive - to the right) "+ (par_scales[AUX_AZIMUTH_INDEX] * this.aux_azimuth) + "pix");
System.out.println(" Auxilliary camera tilt (positive - looking up) "+ (par_scales[AUX_TILT_INDEX] * this.aux_tilt)+"pix");
System.out.println(" Auxilliary camera roll (positive - clockwise) "+ (par_scales[AUX_ROLL_INDEX] * this.aux_roll)+"pix");
System.out.println(" Relative zoom - difference from 1.0 in parts parts per 1/1000 "+ (par_scales[AUX_ZOOM_INDEX] * this.aux_zoom) +"pix");
}
} }
public boolean editRig() { public boolean editRig() {
...@@ -899,6 +912,10 @@ public class GeometryCorrection { ...@@ -899,6 +912,10 @@ public class GeometryCorrection {
return this.rigOffset.editOffsetsPixels(); return this.rigOffset.editOffsetsPixels();
} }
public void showRig() {
this.rigOffset.showRigOffsets();
}
public boolean setRigOffsetFromProperies(String parent_prefix,Properties properties) { public boolean setRigOffsetFromProperies(String parent_prefix,Properties properties) {
RigOffset rigOffset = new RigOffset(); RigOffset rigOffset = new RigOffset();
boolean gotit = rigOffset.getProperties(parent_prefix, properties); boolean gotit = rigOffset.getProperties(parent_prefix, properties);
......
...@@ -310,6 +310,7 @@ public class JP46_Reader_camera extends PlugInFrame implements ActionListener { ...@@ -310,6 +310,7 @@ public class JP46_Reader_camera extends PlugInFrame implements ActionListener {
boolean showDemux=showImage && demux; boolean showDemux=showImage && demux;
if (demux) showImage=false; if (demux) showImage=false;
double [] xtraExif=new double[1]; // ExposureTime double [] xtraExif=new double[1]; // ExposureTime
double [] lla = null;
try { try {
imp = openJpegOrGif(directory, fileName); imp = openJpegOrGif(directory, fileName);
if (imp == null) { if (imp == null) {
...@@ -320,6 +321,12 @@ public class JP46_Reader_camera extends PlugInFrame implements ActionListener { ...@@ -320,6 +321,12 @@ public class JP46_Reader_camera extends PlugInFrame implements ActionListener {
if (ElphelMakerNote==null) ElphelMakerNote = readElphelMakerNote(directory, fileName, 14,xtraExif); /* after or 8.0.8.32 */ if (ElphelMakerNote==null) ElphelMakerNote = readElphelMakerNote(directory, fileName, 14,xtraExif); /* after or 8.0.8.32 */
if (ElphelMakerNote==null) ElphelMakerNote = readElphelMakerNote(directory, fileName, 12,xtraExif); /* after or 8.0.7.3 */ if (ElphelMakerNote==null) ElphelMakerNote = readElphelMakerNote(directory, fileName, 12,xtraExif); /* after or 8.0.7.3 */
if (ElphelMakerNote==null) ElphelMakerNote = readElphelMakerNote(directory, fileName, 8 ,xtraExif); /* before 8.0.7.3 */ if (ElphelMakerNote==null) ElphelMakerNote = readElphelMakerNote(directory, fileName, 8 ,xtraExif); /* before 8.0.7.3 */
lla = readGpsLLA(directory, fileName);
if (lla != null) {
imp.setProperty("LATITUDE", String.format("%f",lla[0]));
imp.setProperty("LONGITUDE", String.format("%f",lla[1]));
imp.setProperty("ALTITUDE", String.format("%f",lla[2]));
}
} }
} catch (IOException e) { } catch (IOException e) {
IJ.showStatus(""); IJ.showStatus("");
...@@ -850,6 +857,78 @@ public class JP46_Reader_camera extends PlugInFrame implements ActionListener { ...@@ -850,6 +857,78 @@ public class JP46_Reader_camera extends PlugInFrame implements ActionListener {
return note; return note;
} }
double [] readGpsLLA(String directory, String fileName) throws IOException
{
RandomAccessFile in = new RandomAccessFile(directory + fileName, "r");
byte[] head = new byte[4096]; /* just read the beginning of the file */
in.readFully(head);
in.close(); // was no close()! -? "too many open files"
if ((head[this.ExifOffset]!=0x4d) || (head[this.ExifOffset+1]!=0x4d)) {
IJ.showMessage("JP46 Reader", "Exif Header not found in " + directory + fileName);
return null;
}
// skip to gps header
byte [] sig = {0x2, 0x2, 0x0, 0x0};
int i = this.ExifOffset + 2;
boolean match=false;
for (i = this.ExifOffset + 2; i < (head.length - sig.length); i++ ) {
match=true;
for (int j=0;j<sig.length;j++)if (head[i+j]!=sig[j]){
match=false;
break;
}
if (match) break;
}
i += sig.length;
if (i >= (head.length-4)) {
/* IJ.showMessage("JP46 Reader", "MakerNote tag not found in "+directory + fileName+ ", finished at offset="+i); // re-enable with DEBUG_LEVEL*/
return null;
}
// System.out.println(String.format("offset=0x%04x", i));
double [] lla = new double[3];
boolean [] lla_sign = new boolean[3];
for (int ntag = 0; ntag < 10; ntag++) {
// read 2 big endian bytesof tag, and 2 - type
int tag = ((head[i+0] << 8) & 0xff00) + ((head[i+1] << 0) & 0x00ff);
int typ = ((head[i+2] << 8) & 0xff00) + ((head[i+3] << 0) & 0x00ff);
int len = ((head[i+4] <<24) & 0xff000000) + ((head[i+5] <<16) & 0x00ff0000) + ((head[i+ 6] << 8) & 0x0000ff00) + ((head[i+ 7] << 0) & 0x000000ff);
int val = ((head[i+8] <<24) & 0xff000000) + ((head[i+9] <<16) & 0x00ff0000) + ((head[i+10] << 8) & 0x0000ff00) + ((head[i+11] << 0) & 0x000000ff);
// System.out.println(String.format("ntag=%2d tag = 0x%04x type = 0x%04x len = 0x%08x value = 0x%08x", ntag, tag, typ, len, val));
i+=12;
switch (tag) {
case 1: lla_sign[0] = ((val >> 24) & 0xff) == 0x53; break; // S GPSLatitudeRef
case 2: int [] lat_arr = readExifBE(head, this.ExifOffset + val , 2 * len); //GPSLatitude
lla[0] = 1.0*lat_arr[0]/lat_arr[1] + (1.0/60)* lat_arr[2]/lat_arr[3] + (1.0/3600)* lat_arr[4]/lat_arr[5];
break;
case 3: lla_sign[1] = ((val >> 24) & 0xff) == 0x57; break; // W GPSLongitudeRef
case 4: int [] long_arr = readExifBE(head, this.ExifOffset + val , 2 * len); // GPSLongitude
lla[1] = 1.0*long_arr[0]/long_arr[1] + (1.0/60)* long_arr[2]/long_arr[3] + (1.0/3600)* long_arr[4]/long_arr[5];
break;
case 5: lla_sign[2] = ((val >> 24) & 0xff) != 0x0; break; // GPSAltitudeRef
case 6: int [] alt_arr = readExifBE(head, this.ExifOffset + val , 2 * len); // GPSLongitude
lla[2] = 1.0*alt_arr[0]/alt_arr[1];
break;
}
}
for (int j = 0; j < lla.length; j++) {
if (lla_sign[j]) lla[j] *= -1;
}
// System.out.println("Lat = "+lla[0]+" Long = "+lla[1]+ " alt = "+lla[2]+"m");
return lla;
}
int [] readExifBE(byte [] head, int offset, int len) {
int [] data = new int [len];
for (int i = 0; i < len; i++) {
int offs = offset + 4*i;
data[i] = ((head[offs + 0] << 24) & 0xff000000) +
((head[offs + 1] << 16) & 0x00ff0000) +
((head[offs + 2] << 8) & 0x0000ff00) +
((head[offs + 3] << 0) & 0x000000ff);
}
return data;
}
long[] readElphelMakerNoteURL(String url, int len, double [] xtraExif) throws IOException { long[] readElphelMakerNoteURL(String url, int len, double [] xtraExif) throws IOException {
URL camURL = null; URL camURL = null;
URLConnection urlConn = null; URLConnection urlConn = null;
......
...@@ -1261,7 +1261,8 @@ public class MeasuredLayers { ...@@ -1261,7 +1261,8 @@ public class MeasuredLayers {
} }
if (iworst < 0){ if (iworst < 0){
if (debugLevel > 0) { if (debugLevel > 0) {
System.out.println("**** this may be BUG in getDisparityStrengthML() can not find the worst sample - all tiles fit perfectly ****"); System.out.println("**** this may be BUG in getDisparityStrengthML() can not find the worst sample - all tiles fit perfectly ****, num_in_sample="+
num_in_sample+", stX="+stX+", stY="+stY);
} }
// this can happen if some samples are the same and all the pixels fit exactly - use all of them // this can happen if some samples are the same and all the pixels fit exactly - use all of them
break; break;
...@@ -1354,7 +1355,8 @@ public class MeasuredLayers { ...@@ -1354,7 +1355,8 @@ public class MeasuredLayers {
//remove_far_only //remove_far_only
} }
if (iworst < 0){ if (iworst < 0){
System.out.println("**** this is a BUG2 in getDisparityStrengthML() ****"); // all smpl_d are NaNs System.out.println("**** this may be BUG2 in getDisparityStrengthML() can not find the worst sample - all tiles fit perfectly ****, num_in_sample="+
num_in_sample+", stX="+stX+", stY="+stY);
break; break;
} }
// remove worst sample // remove worst sample
...@@ -1378,7 +1380,7 @@ public class MeasuredLayers { ...@@ -1378,7 +1380,7 @@ public class MeasuredLayers {
} }
} else { } else {
num_in_sample = 0; num_in_sample = 0;
System.out.println("**** this is a BUG in getDisparityStrengthML(), shoud not happen ? ****"); System.out.println("**** this is a BUG in getDisparityStrengthML(), should not happen ? ****");
} }
} }
} }
...@@ -1453,6 +1455,12 @@ public class MeasuredLayers { ...@@ -1453,6 +1455,12 @@ public class MeasuredLayers {
} }
ds[0][indx] = sd; ds[0][indx] = sd;
ds[1][indx] = sw * lapWeight[dy][dx] /sum_wnd; // average weights, multiply by window //** TODO: change ds[1][indx] = sw * lapWeight[dy][dx] /sum_wnd; // average weights, multiply by window //** TODO: change
if ((ds[0][indx] ==0.0) && (ds[0][indx] ==0.0)) {
System.out.println("**** this may be BUG5 in getDisparityStrengthML() ****, num_in_sample="+
num_in_sample+", stX="+stX+", stY="+stY+" ds[0]["+indx+"]="+ds[0][indx]+", ds[1]["+indx+"]="+ds[1][indx]);
ds[1][indx] = 0.0;
}
} }
} else { } else {
num_in_sample = 0; num_in_sample = 0;
......
This diff is collapsed.
...@@ -24,10 +24,19 @@ ...@@ -24,10 +24,19 @@
//import java.awt.Polygon; //import java.awt.Polygon;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import ij.CompositeImage; import ij.CompositeImage;
...@@ -67,6 +76,7 @@ public class QuadCLT { ...@@ -67,6 +76,7 @@ public class QuadCLT {
TileProcessor tp = null; TileProcessor tp = null;
String image_name = null; String image_name = null;
double [] gps_lla = null;
double [][][] image_data = null; double [][][] image_data = null;
boolean [][] saturation_imp = null; // (near) saturated pixels or null boolean [][] saturation_imp = null; // (near) saturated pixels or null
boolean is_aux = false; boolean is_aux = false;
...@@ -4730,7 +4740,7 @@ public class QuadCLT { ...@@ -4730,7 +4740,7 @@ public class QuadCLT {
public boolean editRig() public boolean editRig()
{ {
if (!is_aux) { if (!is_aux) {
System.out.println("Rig offsets can only be edited for the auxiliary camera, not for the amin one"); System.out.println("Rig offsets can only be edited for the auxiliary camera, not for the main one");
return false; return false;
} }
// GeometryCorrection gc = this.geometryCorrection; // GeometryCorrection gc = this.geometryCorrection;
...@@ -7700,13 +7710,16 @@ public class QuadCLT { ...@@ -7700,13 +7710,16 @@ public class QuadCLT {
System.out.println("Wavefront object file saved to "+wfOutput.obj_path); System.out.println("Wavefront object file saved to "+wfOutput.obj_path);
System.out.println("Wavefront material file saved to "+wfOutput.mtl_path); System.out.println("Wavefront material file saved to "+wfOutput.mtl_path);
} }
// Save KML and ratings files if they do not exist (so not to overwrite edited ones), make them world-writable
writeKml (debugLevel);
writeRatingFile (debugLevel);
Runtime.getRuntime().gc(); Runtime.getRuntime().gc();
System.out.println("output3d(): generating 3d output files finished at "+ System.out.println("output3d(): generating 3d output files finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startStepTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")"); IJ.d2s(0.000000001*(System.nanoTime()-this.startStepTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
return true; return true;
// return imp_bgnd; // relative (to x3d directory) path - (String) imp_bgnd.getProperty("name");
} }
...@@ -9079,5 +9092,160 @@ public class QuadCLT { ...@@ -9079,5 +9092,160 @@ public class QuadCLT {
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")"); IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
} }
public void setGpsLla(
String source_file)
{
ImagePlus imp=(new JP46_Reader_camera(false)).open(
"", // path,
source_file,
"", //arg - not used in JP46 reader
true, // un-apply camera color gains
null, // new window
false); // do not show
if (imp.getProperty("LATITUDE") != null){
gps_lla = new double[3];
for (int i = 0; i < 3; i++) {
gps_lla[i] = Double.NaN;
}
if (imp.getProperty("LATITUDE") != null) gps_lla[0] =Double.parseDouble((String) imp.getProperty("LATITUDE"));
if (imp.getProperty("LONGITUDE") != null) gps_lla[1] =Double.parseDouble((String) imp.getProperty("LONGITUDE"));
if (imp.getProperty("ALTITUDE") != null) gps_lla[2] =Double.parseDouble((String) imp.getProperty("ALTITUDE"));
}
}
public boolean writeKml(
int debugLevel )
{
String [] sourceFiles_main=correctionsParameters.getSourcePaths();
// String [] sourceFiles_aux=quadCLT_main.correctionsParameters.getSourcePaths();
setGpsLla(sourceFiles_main[0]);
String set_name = image_name;
if (set_name == null ) {
QuadCLT.SetChannels [] set_channels=setChannels(debugLevel);
set_name = set_channels[0].set_name;
}
if (gps_lla != null) {
String kml_copy_dir= correctionsParameters.selectX3dDirectory(
set_name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
null,
true, // smart,
true); //newAllowed, // save
double ts = Double.parseDouble(set_name.replace('_', '.'));
(new X3dOutput()).generateKML(
kml_copy_dir+ Prefs.getFileSeparator()+set_name+".kml", // String path,
false, // boolean overwrite,
"", // String icon_path, //<href>x3d/1487451413_967079.x3d</href> ?
ts, // double timestamp,
gps_lla); // double [] lla)
} else {
if (debugLevel > -2) {
System.out.println("GPS data not available, skipping KML file generation (TODO: maybe make some default LLA?)");
}
}
return true;
}
public boolean createThumbNailImage(
ImagePlus imp,
String dir,
String name,
int debugLevel)
{
String thumb_path = dir + Prefs.getFileSeparator() + name+".jpeg";
if (new File(thumb_path).exists()) {
System.out.println("file "+thumb_path+" exists, skipping thumbnail generation");
return false;
}
int image_width = imp.getWidth();
int image_height = imp.getHeight();
double scale_h = 1.0 * correctionsParameters.thumb_width/image_width;
double scale_v = 1.0 * correctionsParameters.thumb_height/image_height;
// double scale = Math.min(scale_h, scale_v) /correctionsParameters.thumb_size;
double scale = scale_h / correctionsParameters.thumb_size;
// ImageProcessor ip = imp.getChannelProcessor();
ImageProcessor ip = imp.getProcessor().duplicate();
ip.setInterpolationMethod(ImageProcessor.BICUBIC);
// ip.setInterpolationMethod(ImageProcessor.BILINEAR);
ip.blurGaussian(2.0);
ip.scale(scale, scale);
// Rectangle rs = new Rectangle(
// (int)Math.round(0.5*image_width*(1.0-scale)),
// (int)Math.round(0.5*image_height*(1.0-scale)),
// (int)Math.round(image_width*scale),
// (int)Math.round(image_height*scale));
// int scaled_width = rs.width; // ip.getWidth();
// int scaled_height = rs.height; // ip.getHeight();
// int lm = (int) Math.round ((scaled_width-correctionsParameters.thumb_width)* correctionsParameters.thumb_h_center);
// int tm = (int) Math.round ((scaled_height-correctionsParameters.thumb_height)* correctionsParameters.thumb_v_center);
int lm = (int) Math.round (((image_width*scale)-correctionsParameters.thumb_width)* correctionsParameters.thumb_h_center + (0.5*image_width*(1.0-scale)));
int tm = (int) Math.round (((image_height*scale)-correctionsParameters.thumb_height)* correctionsParameters.thumb_v_center + (0.5*image_height*(1.0-scale)));
Rectangle r = new Rectangle(lm,tm,correctionsParameters.thumb_width,correctionsParameters.thumb_height);
ip.setRoi(r);
ImageProcessor ip2 = ip.crop();
ImagePlus ip_thumb = new ImagePlus(name,ip2);
eyesisCorrections.saveAndShow(
ip_thumb,
dir,
false,
false,
correctionsParameters.JPEG_quality, // jpegQuality); // jpegQuality){// <0 - keep current, 0 - force Tiff, >0 use for JPEG
(debugLevel > -2) ? debugLevel : 1); // int debugLevel (print what it saves)
return true;
}
public boolean writeRatingFile(
int debugLevel
)
{
String set_name = image_name;
if (set_name == null ) {
QuadCLT.SetChannels [] set_channels = setChannels(debugLevel);
set_name = set_channels[0].set_name;
}
String model_dir= correctionsParameters.selectX3dDirectory(
set_name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
null,
true, // smart,
true); //newAllowed, // save
String fname = model_dir+ Prefs.getFileSeparator()+"rating.txt";
File rating_file = new File(fname);
if (rating_file.exists()) {
if (debugLevel > -2){
System.out.println("file "+rating_file.getPath()+" exists, skipping overwrite");
}
return false;
}
List<String> lines = Arrays.asList(correctionsParameters.default_rating+"");
Path path = Paths.get(fname);
try {
Files.write(path,lines, Charset.forName("UTF-8"));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return false;
}
try {
Path fpath = Paths.get(rating_file.getCanonicalPath());
Set<PosixFilePermission> perms = Files.getPosixFilePermissions(fpath);
perms.add(PosixFilePermission.OTHERS_WRITE);
Files.setPosixFilePermissions(fpath, perms);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
} }
...@@ -1926,6 +1926,10 @@ public class TilePlanes { ...@@ -1926,6 +1926,10 @@ public class TilePlanes {
for (int indx = 0; indx < disp_str[nl][0].length; indx++){ for (int indx = 0; indx < disp_str[nl][0].length; indx++){
if (tile_sel[nl][indx]) { if (tile_sel[nl][indx]) {
double w = disp_str[nl][1][indx]; double w = disp_str[nl][1][indx];
if ((w > 0.0) && !(disp_str[nl][0][indx] > 0.0)) {
System.out.println("BUG!!!: getPlaneFromMeas(): disp_str[nl][0]["+indx+"]="+disp_str[nl][0][indx]+", disp_str[nl][1]["+indx+"]="+disp_str[nl][1][indx]);
continue;
}
if (w > 0.0){ if (w > 0.0){
tiles_xyzw[nl][indx] = new double [4]; tiles_xyzw[nl][indx] = new double [4];
double d = disp_str[nl][0][indx]; double d = disp_str[nl][0][indx];
...@@ -2020,6 +2024,7 @@ public class TilePlanes { ...@@ -2020,6 +2024,7 @@ public class TilePlanes {
acovar [2][2] += w * z * z; acovar [2][2] += w * z * z;
if (Double.isNaN(acovar [0][0])) { if (Double.isNaN(acovar [0][0])) {
System.out.println("--*--BUG! acovar[0][0] is NaN"); System.out.println("--*--BUG! acovar[0][0] is NaN");
return null;
} }
} }
} }
......
This diff is collapsed.
...@@ -21,9 +21,15 @@ ...@@ -21,9 +21,15 @@
** -----------------------------------------------------------------------------** ** -----------------------------------------------------------------------------**
** **
*/ */
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Set;
import java.io.File;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
...@@ -34,7 +40,6 @@ import javax.xml.transform.TransformerFactory; ...@@ -34,7 +40,6 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Attr;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
...@@ -52,6 +57,8 @@ public class X3dOutput { ...@@ -52,6 +57,8 @@ public class X3dOutput {
Element el_TopGroup; Element el_TopGroup;
public int max_line_length = 0; // 100; // 0 - no limit public int max_line_length = 0; // 100; // 0 - no limit
public X3dOutput() {}
public X3dOutput( public X3dOutput(
EyesisCorrectionParameters.CLTParameters clt_parameters, EyesisCorrectionParameters.CLTParameters clt_parameters,
EyesisCorrectionParameters.CorrectionParameters correctionsParameters, EyesisCorrectionParameters.CorrectionParameters correctionsParameters,
...@@ -207,7 +214,7 @@ public class X3dOutput { ...@@ -207,7 +214,7 @@ public class X3dOutput {
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(source, result); transformer.transform(source, result);
System.out.println("x3d file saved to "+path); System.out.println("x3d file is saved to "+path);
} catch (TransformerException tfe) { } catch (TransformerException tfe) {
tfe.printStackTrace(); tfe.printStackTrace();
...@@ -223,4 +230,156 @@ public class X3dOutput { ...@@ -223,4 +230,156 @@ public class X3dOutput {
double [][] bbox = {{0, 0, -depth/2},{width,height,depth}}; double [][] bbox = {{0, 0, -depth/2},{width,height,depth}};
return bbox; return bbox;
} }
public void generateKML(
String path,
boolean overwrite,
String icon_path, //<href>x3d/1487451413_967079.x3d</href> ?
double timestamp,
double [] lla)
{
if (!overwrite) {
if (new File(path).exists()) {
System.out.println("KML file "+path+" exists, skipping KML generation");
return;
}
}
Document kmlDoc;
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
kmlDoc = docBuilder.newDocument();
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
return;
}
// root elements
Element el_kml = kmlDoc.createElement("kml");
el_kml.setAttribute("xmlns","http://earth.google.com/kml/2.2");
kmlDoc.appendChild(el_kml);
Element el_Document = addElement(kmlDoc, el_kml,"Document");
Element el_PhotoOverlay = addElement(kmlDoc, el_Document, "PhotoOverlay"); // kmlDoc.createElement("PhotoOverlay");
addTextElement(kmlDoc, el_PhotoOverlay, "name", "test");
addTextElement(kmlDoc, el_PhotoOverlay, "description", "this kml description");
addTextElement(kmlDoc, el_PhotoOverlay, "visibility", "1");
addTextElement(kmlDoc, el_PhotoOverlay, "shape", "rectangle");
Element el_TimeStamp = addElement(kmlDoc, el_PhotoOverlay, "TimeStamp");
addTextElement(kmlDoc, el_TimeStamp, "when", String.format("%f",timestamp));
Element el_Camera = addElement(kmlDoc, el_PhotoOverlay, "Camera");
addTextElement(kmlDoc, el_Camera, "latitude", String.format("%f",lla[0]));
addTextElement(kmlDoc, el_Camera, "longitude", String.format("%f",lla[1]));
addTextElement(kmlDoc, el_Camera, "altitude", String.format("%f",lla[2]));
addTextElement(kmlDoc, el_Camera, "heading", String.format("%f",0.0));
addTextElement(kmlDoc, el_Camera, "tilt", String.format("%f",90.0));
addTextElement(kmlDoc, el_Camera, "roll", String.format("%f",0.0));
if (icon_path != null) {
Element el_Icon = addElement(kmlDoc, el_PhotoOverlay, "Icon");
addTextElement(kmlDoc, el_Icon, "href", icon_path);
}
Element el_ExtendedData = addElement(kmlDoc, el_PhotoOverlay, "ExtendedData");
Element el_OriginalData = addElement(kmlDoc, el_ExtendedData, "OriginalData");
addTextElement(kmlDoc, el_OriginalData, "latitude", String.format("%f",lla[0]));
addTextElement(kmlDoc, el_OriginalData, "longitude", String.format("%f",lla[1]));
addTextElement(kmlDoc, el_OriginalData, "altitude", String.format("%f",lla[2]));
addTextElement(kmlDoc, el_OriginalData, "heading", String.format("%f",0.0));
addTextElement(kmlDoc, el_OriginalData, "tilt", String.format("%f",90.0));
addTextElement(kmlDoc, el_OriginalData, "roll", String.format("%f",0.0));
try {
// write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(kmlDoc);
StreamResult result = new StreamResult(new File(path));
// Output to console for testing
// StreamResult result = new StreamResult(System.out);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(source, result);
System.out.println("kml file is saved to "+path);
} catch (TransformerException tfe) {
tfe.printStackTrace();
}
try {
Path fpath = Paths.get((new File(path)).getCanonicalPath());
Set<PosixFilePermission> perms = Files.getPosixFilePermissions(fpath);
perms.add(PosixFilePermission.OTHERS_WRITE);
Files.setPosixFilePermissions(fpath, perms);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Element addTextElement(Document doc, Element parent, String name, String text)
{
Element child = doc.createElement(name);
child.setTextContent(text);
parent.appendChild(child);
return child;
}
Element addElement(Document doc, Element parent, String name)
{
Element child = doc.createElement(name);
parent.appendChild(child);
return child;
}
} }
/*
* <?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<PhotoOverlay>
<name>test</name>
<visibility>1</visibility>
<shape>rectangle</shape>
<TimeStamp>
<when>1487451413.967079</when>
</TimeStamp>
<Camera>
<longitude>-111.93292339</longitude>
<latitude>40.72350154</latitude>
<altitude>1305.1</altitude>
<heading>68.8186</heading>
<tilt>90</tilt>
<roll>0</roll>
</Camera>
<Icon>
<href>x3d/1487451413_967079.x3d</href>
</Icon>
<ExtendedData>
<OriginalData>
<longitude>-111.9328843</longitude>
<latitude>40.7233861</latitude>
<altitude>1305.1</altitude>
<heading>65</heading>
<tilt>90</tilt>
<roll>0</roll>
</OriginalData>
</ExtendedData>
<description></description></PhotoOverlay>
</Document>
</kml>
<?xml version="1.0" encoding="UTF-8"?>
<x3d profile="Interchange" version="3.3">
<Scene>
<Group bboxCenter="0.000 0.000 -1419.899 " bboxSize="3704.001 2766.569 2839.798 " class="GroupTop" id="GroupTop"/>
*/
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