Commit 59172c80 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

added strategy comments, strategy list

parent 5aad0ee7
Loading
Loading
Loading
Loading
+8 −13
Original line number Diff line number Diff line
@@ -718,6 +718,7 @@ public static MatchSimulatedPattern.DistortionParameters DISTORTION =new MatchSi
		addButton("Edit Strategy",panelFitDistortions,color_configure);
		addButton("Save Strategy",panelFitDistortions,color_bundle);
		addButton("Restore Strategy",panelFitDistortions,color_restore);
		addButton("List Strategy",panelFitDistortions,color_report);
		addButton("Run LMA",panelFitDistortions,color_bundle);
		addButton("Bad Nodes",panelFitDistortions,color_bundle);
		addButton("Debug deriv",panelFitDistortions,color_debug);
@@ -2311,18 +2312,8 @@ if (MORE_BUTTONS) {
/* ======================================================================== */
		if (label.equals("List Eyesis4pi") || label.equals("List X-cam")) {
			DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
			System.out.println("DISTORTION_CALIBRATION_DATA="+((DISTORTION_CALIBRATION_DATA==null)?"null":" NOT null"));
			System.out.println("+++++++++++ EYESIS_CAMERA_PARAMETERS.numStations="+EYESIS_CAMERA_PARAMETERS.numStations+
					" +EYESIS_CAMERA_PARAMETERS.goniometerHorizontal.length="+EYESIS_CAMERA_PARAMETERS.goniometerHorizontal.length);
			if (DISTORTION_CALIBRATION_DATA!=null) {
			if (DEBUG_LEVEL>1) System.out.println("+++++++++++ DISTORTION_CALIBRATION_DATA.eyesisCameraParameters.numStations="+DISTORTION_CALIBRATION_DATA.eyesisCameraParameters.numStations+
					" +DISTORTION_CALIBRATION_DATA.eyesisCameraParameters.goniometerHorizontal.length="+DISTORTION_CALIBRATION_DATA.eyesisCameraParameters.goniometerHorizontal.length);
			}
			DistortionCalibrationData dcd=(DISTORTION_CALIBRATION_DATA!=null)?DISTORTION_CALIBRATION_DATA:
				new DistortionCalibrationData(EYESIS_CAMERA_PARAMETERS);
			if (DEBUG_LEVEL>1) System.out.println("+++++++++++ dcd.eyesisCameraParameters.numStations="+dcd.eyesisCameraParameters.numStations+
					" +dcd.eyesisCameraParameters.goniometerHorizontal.length="+dcd.eyesisCameraParameters.goniometerHorizontal.length);
			dcd.listCameraParameters(label.equals("List X-cam"));
			return;
		}
@@ -2486,8 +2477,7 @@ if (MORE_BUTTONS) {
			return;
		}
/* ======================================================================== */
		if       (label.equals("Edit Strategy")) {
		if       (label.equals("Edit Strategy") || label.equals("List Strategy")) {
			DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
			if (LENS_DISTORTIONS==null) {
				if (LENS_DISTORTION_PARAMETERS==null){
@@ -2506,7 +2496,11 @@ if (MORE_BUTTONS) {
				LENS_DISTORTIONS.fittingStrategy=new FittingStrategy(DISTORTION_CALIBRATION_DATA);
			}
			LENS_DISTORTIONS.fittingStrategy.debugLevel=DEBUG_LEVEL;
			if (label.equals("Edit Strategy")) {
				LENS_DISTORTIONS.fittingStrategy.selectStrategy(LENS_DISTORTIONS.seriesNumber);
			} else {
				LENS_DISTORTIONS.fittingStrategy.listStrategies();
			}
			return;
		}
/* ======================================================================== */
@@ -2558,6 +2552,7 @@ if (MORE_BUTTONS) {
			return;
		}
/* ======================================================================== */
		if       (label.equals("Run LMA")) {
			DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
+284 −128
Original line number Diff line number Diff line
@@ -21,10 +21,6 @@
 ** -----------------------------------------------------------------------------**
 **
 */
import ij.IJ;
import ij.gui.GenericDialog;
import ij.text.TextWindow;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
@@ -40,6 +36,10 @@ import java.util.Set;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;

import ij.IJ;
import ij.gui.GenericDialog;
import ij.text.TextWindow;



    /**
@@ -149,7 +149,7 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
    	public double [] weightVariance=    null; // weight for LMA over variance of parameters from average
    	public double [] varianceErrorsSquared=  null; // weighted squared errors

    	
    	public String [] strategyComment = null;

    	public FittingStrategy(
    	    	DistortionCalibrationData distortionCalibrationData// per-image parameters
@@ -243,6 +243,7 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
			this.parameterGroups=new int[nSer][len][];
			this.lambdas=new double  [nSer];
			this.stepDone=new double [nSer];
			this.strategyComment=new String[nSer];
        	for (int i=0;i<nSer;i++){ // iterate through series
//this.stopAfterThis
// read selected images (no check here that it matches to the    distortionCalibrationData!
@@ -299,6 +300,12 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
    			} else {
    				this.zGroups[i]=null;
    			}

    			if (hConfig.getString(sSeries+".strategyComment")!=null) {
    				this.strategyComment[i]=hConfig.getString(sSeries+".strategyComment");
    			}


        	}
//        	if (hConfig.getString("variances")!=null){
//            if (!hConfig.configurationAt("variances").isEmpty()){
@@ -410,6 +417,7 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
        		hConfig.addProperty(sSeries+".lambdas",lambdas[i]);
        		hConfig.addProperty(sSeries+".stepDone",stepDone[i]);
        		hConfig.addProperty(sSeries+".stopAfterThis",this.stopAfterThis[i]);
        		hConfig.addProperty(sSeries+".strategyComment",this.strategyComment[i]);
        	}
        	hConfig.addProperty("variances","");
       		this.distortionCalibrationData.eyesisCameraParameters.setCostsPropertiesXML("variances.",hConfig);
@@ -448,6 +456,7 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
    				this.stopAfterThis[numSeries]=this.stopAfterThis[sourceSeries];
    				this.varianceModes[numSeries]=this.varianceModes[sourceSeries];
    				this.zGroups[numSeries]=(this.zGroups[sourceSeries]!=null)?this.zGroups[sourceSeries].clone():null;
    				this.strategyComment[numSeries] = this.strategyComment[sourceSeries]+" (copy)";
    				return true;
    		} else {
    			return false;
@@ -461,7 +470,7 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
         * @param num - series to verify
         * @return true if series is valid
         */
    	public boolean isSeriesValid(int num){
    	public boolean isSeriesValidVerbose(int num){
    		if ((num<0) || (num>=this.selectedImages.length)) return false;
    		boolean someImagesSelected=false;
    		for (int i=0;i<this.selectedImages[num].length;i++) if (this.selectedImages[num][i]){
@@ -483,6 +492,27 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
    		}
    		return true;
    	}

    	public boolean isSeriesValid(int num){
    		if ((num<0) || (num>=this.selectedImages.length)) return false;
    		boolean someImagesSelected=false;
    		for (int i=0;i<this.selectedImages[num].length;i++) if (this.selectedImages[num][i]){
    			someImagesSelected=true;
    			break;
    		}
    		if (!someImagesSelected) {
    			return false;
    		}
    		boolean someParametersSelected=false;
    		for (int i=0;i<this.parameterMode[num].length;i++) if (this.parameterMode[num][i]>0){
    			someParametersSelected=true;
    			break;
    		}
    		if (!someParametersSelected) {
    			return false;
    		}
    		return true;
    	}
    	/**
    	 * Determins if LMA should stop after this series (either flag is set or next is invalid)
    	 * @param num number of series to test
@@ -1221,6 +1251,7 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
    		int [] oldMasterImages=null;
        	double [] oldStepDone=null;
        	boolean [] oldStopAfterThis=null;
        	String [] oldStrategyComment=null;
            int oldNumSeries=(this.selectedImages==null)?0:this.selectedImages.length;
            int oldLength=0;
    		if (this.selectedImages!=null){
@@ -1229,6 +1260,7 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
    			oldParameterMode=new int[oldNumSeries][];
    			oldParameterGroups=new int[oldNumSeries][][];
    			oldZGroups=new int[oldNumSeries][];
        		oldStrategyComment = new String [oldNumSeries];
    			for (int i=0;i<oldNumSeries;i++){
    				oldSelectedImages[i]=this.selectedImages[i].clone();
        			oldParameterMode[i]= this.parameterMode[i].clone(); // out of bound - 2
@@ -1237,6 +1269,7 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
        				oldParameterGroups[i][j]=(parameterGroups[i][j]==null)?null:parameterGroups[i][j].clone();
        			if (this.zGroups[i]!=null) oldZGroups[i]=this.zGroups[i].clone();
        			else this.zGroups[i]=oldZGroups[i];
        			oldStrategyComment[i]=this.strategyComment[i];
    			}
    			oldVarianceModes=(this.varianceModes==null)?null:this.varianceModes.clone();
    			oldLambdas=this.lambdas.clone();
@@ -1256,6 +1289,7 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
        		this.stopAfterThis[i]=oldStopAfterThis[i];
    			this.varianceModes[i]=oldVarianceModes[i];
    			this.zGroups[i]=(oldZGroups[i]!=null)?oldZGroups[i].clone():null;
    			this.strategyComment[i] = oldStrategyComment[i];
    		}
    	}

@@ -1332,6 +1366,7 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
        		this.parameterGroups=null;
        		this.varianceModes=null;
        		this.zGroups=null;
        		this.strategyComment=null;
                return;
    		}
    		this.stopAfterThis=new boolean[numSeries];
@@ -1357,6 +1392,7 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
    		this.parameterGroups=new int[numSeries][totalNumPars][];
    		this.parameterEnable= new boolean [totalNumPars];
    		this.zGroups=new int[numSeries][];
    		this.strategyComment = new String [numSeries];
    		for (int i=0;i<this.selectedImages.length;i++){
    			invalidateSelectedImages(i);
    			for (int j=0;j<this.selectedImages[i].length;j++){
@@ -1371,6 +1407,7 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
    			this.masterImages[i]=0; // first image, supposingly the earliest timestamp
    			this.varianceModes[i]=varianceModeDisabled;
        		this.zGroups[i]=null;
        		this.strategyComment[i] = "";
    		}

    		initParameterList();
@@ -1869,6 +1906,122 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
			this.selectedImages[numSeries]=selection;
			return more?0:1;
    	}
       	/**
   	 *
   	 * @param numSeries Number of series to edit
   	 * @param useImages Select images for this series
   	 * @param fromToImages - limit number of checkboxes, otherwise window does not show the bottom ones
   	 * @param useParameters Select parameters for this series
   	 * @param askNextSeries Ask for next series number
   	 * @param zeroAndOther use 2 channels 0 and "other", propagate settings for channel 1 to all the rest
   	 * @return -2 - cancel, -1, done, otherwise - number of step to edit
   	public int selectStrategyStep(
   			int numSeries,
   			boolean useImages,
				int [] fromToImages,
   			boolean allImages,
   			boolean useParameters,
   			boolean askLambdas,
   			boolean askNextSeries,
   			boolean zeroAndOther
   			){
			GenericDialog gd = new GenericDialog("Fitting Strategy Step Configuration, step "+numSeries+
					                             " number of enabled images="+this.distortionCalibrationData.getNumEnabled());
			gd.addStringField  ("Comment",   this.strategyComment[numSeries],80);

   	 */

    	public void listStrategies() {
    		if (this.selectedImages == null) {
    			String msg="No strategies defined";
    			IJ.showMessage("Error",msg);
    			return;
    		}
    		int fromSer = 0;
    		int toSer = this.selectedImages.length;
			boolean zeroAndOther=    true;
    		GenericDialog gd = new GenericDialog("List Fitting Strategies");
    		gd.addNumericField("First number of series to list", fromSer, 0);
    		gd.addNumericField("Last number of series to list", toSer - 1, 0);
    		gd.addCheckbox    ("Use only channel 0 and \"all other channels\"",zeroAndOther);
    		gd.showDialog();
    		if (gd.wasCanceled()) return;
    		fromSer=          (int) gd.getNextNumber();
    		toSer=            (int) gd.getNextNumber();
    		zeroAndOther=           gd.getNextBoolean();
    		listStrategies(fromSer, toSer, zeroAndOther);
    	}

    	public void listStrategies(
        		int     fromSer,
        		int     toSer,
       			boolean zeroAndOther
    			) {
    		if (this.selectedImages == null) {
    			String msg="No strategies defined";
    			IJ.showMessage("Error",msg);
    			return;
    		}
    		int [] choice_offsets = new int [this.parameterEnable.length];
    		//
    	    String header="Strategy Number\t";
    	    StringBuffer sb = new StringBuffer();
    		for (int i=fromSer;i<toSer;i++)  if (isSeriesValid(i)) header+="\t"+i;
			sb.append("Comment\t");
			for (int i=fromSer;i<toSer;i++) if (isSeriesValid(i)) sb.append("\t"+this.strategyComment[i]);sb.append("\n");
			sb.append("Number of selected images\t");
			for (int i=fromSer;i<toSer;i++) if (isSeriesValid(i)) {
				int ns = 0;
				for (int j=0; j<this.selectedImages[i].length;j++) if (this.selectedImages[i][j]) ns++;
				sb.append("\t"+ns);
			}
			sb.append("\n");
			// parameters
			for (int ipar =0; ipar<this.parameterEnable.length;ipar++) if (this.parameterEnable[ipar] &&
					(!zeroAndOther || (this.parameterList[ipar][0] <= 1) || (this.parameterList[ipar][0] ==24))){ // in "zeroAndOther" mode do not show other subcameras
				int parIndex=this.parameterList[ipar][1];
				int subCam=this.parameterList[ipar][0];
				boolean isSub=this.distortionCalibrationData.isSubcameraParameter(parIndex);
				String sChn=(zeroAndOther && (subCam>=1)&& (subCam<24))?"-head-other":
					((zeroAndOther && (subCam>=24))?"-bottom":("-"+subCam));
				boolean noWeak=!this.distortionCalibrationData.eyesisCameraParameters.isExtrinsic(parIndex);
				boolean isTilt=this.distortionCalibrationData.eyesisCameraParameters.isTilt(parIndex);
				// for non-subcamera or subcam 0 - no extra choices. For "zeroAndOther" - only "0". For other subCam - all less than this
				int subMaxNum = (this.distortionCalibrationData.isSubcameraParameter(parIndex) && (subCam > 0)) ? (zeroAndOther? 0 : (subCam-1)):-1;
				String [] commonChoices = (isTilt?this.definedModesTiltEq:(noWeak?this.definedModesNoWeak:this.definedModes));
				String [] theseChoices;
				String thisChoice = "";
				choice_offsets[ipar] = 0;

				sb.append(this.distortionCalibrationData.getParameterName(parIndex)+"\t"+(isSub?(" sub"+sChn):"com "));
				for (int numSeries=fromSer;numSeries<toSer;numSeries++) if (isSeriesValid(numSeries)) {
					if (subMaxNum < 0){
//						theseChoices = commonChoices;
						thisChoice = this.definedModesAll[this.parameterMode[numSeries][ipar]];
					} else { // only can happen if (!isTilt) && (noWeak)
						choice_offsets[ipar] = commonChoices.length;
						theseChoices = new String [commonChoices.length + subMaxNum + 1];
						for (int ch = 0; ch < commonChoices.length; ch++) theseChoices[ch] = commonChoices[ch];
						for (int ch = 0; ch <= subMaxNum; ch++)  theseChoices[ch + commonChoices.length] = "same as "+ch;
						// choice index for "same as ..." starts with  this.definedModesAll.length, but in the listbox index is lower
						int indx = this.parameterMode[numSeries][ipar];
						if (indx >= this.definedModesAll.length) {
							indx -= (this.definedModesAll.length - choice_offsets[ipar]);
						}
						thisChoice = theseChoices[indx];
//						System.out.println("selectStrategyStep(): this.parameterMode["+numSeries+"]["+ipar+"]=" + this.parameterMode[numSeries][ipar]+" indx = "+indx);
					}
					if (thisChoice.equals("fixed")) thisChoice = "-";
					sb.append("\t"+thisChoice);
				}
				sb.append("\n");

			}


		    new TextWindow("Strategies_List", header, sb.toString(), 800,1000);
			System.out.println("** Do not save as .csv - it will replace tabs with commas! ***");
    	}


    	/**
@@ -1917,7 +2070,9 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
    			if (sourceSeries>=0)  copySeries(sourceSeries, numSeries);
    		}

			GenericDialog gd = new GenericDialog("Fitting Strategy Step Configuration, step "+numSeries+" number of enabled images="+this.distortionCalibrationData.getNumEnabled());
			GenericDialog gd = new GenericDialog("Fitting Strategy Step Configuration, step "+numSeries+
					                             " number of enabled images="+this.distortionCalibrationData.getNumEnabled());
			gd.addStringField  ("Comment",   this.strategyComment[numSeries],80);
			gd.addCheckbox("Advanced image selection (disregard other fields)", showAdvancedImageSelection);
			gd.addCheckbox("Copy all from the series below, ignore all other fields", false);
			gd.addNumericField("Source series to copy from", (numSeries>0)?(numSeries-1):(numSeries+1), 0, 3, "");
@@ -2082,6 +2237,7 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
			WindowTools.addScrollBars(gd);
			gd.showDialog();
			if (gd.wasCanceled()) return -2;
			this.strategyComment[numSeries]= gd.getNextString();
			showAdvancedImageSelection=gd.getNextBoolean();
			if (showAdvancedImageSelection){
				int rslt=0;