diff --git a/config/jcae.properties b/config/jcae.properties index f22753b..76f5958 100755 --- a/config/jcae.properties +++ b/config/jcae.properties @@ -1,8 +1,11 @@ -#Tue Aug 23 14:26:30 CEST 2016 +#Mon Sep 05 16:40:34 CEST 2016 ch.psi.jcae.ContextFactory.addressList=172.26.0.255 172.26.2.255 172.26.8.255 172.26.16.255 172.26.24.255 172.26.32.255 172.26.40.255 172.26.120.255 ch.psi.jcae.ContextFactory.maxArrayBytes=20000000 -ch.psi.jcae.ChannelFactory.retries=2 +ch.psi.jcae.ChannelFactory.retries=1 ch.psi.jcae.ChannelFactory.timeout=500 ch.psi.jcae.impl.DefaultChannelService.retries=4 ch.psi.jcae.impl.DefaultChannelService.timeout=1000 ch.psi.jcae.ContextFactory.serverPort= +ch.psi.jcae.ContextFactory.autoAddressList=true +ch.psi.jcae.ContextFactory.useShellVariables=false +ch.psi.jcae.ContextFactory.addLocalBroadcastInterfaces=false diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index e2a6603..9a1854b 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,13 +1,13 @@ -#Mon Sep 05 11:20:34 CEST 2016 +#Mon Sep 05 17:37:11 CEST 2016 colormap=Temperature colormapAutomatic=true colormapMax=2475.851 colormapMin=2189.861 -flipHorizontally=false -flipVertically=false +flipHorizontally=true +flipVertically=true grayscale=false -imageHeight=840 -imageWidth=627 +imageHeight=1628 +imageWidth=1280 invert=false rescaleFactor=1.0 rescaleOffset=0.0 @@ -18,9 +18,9 @@ roiY=0 rotation=0.0 rotationCrop=true scale=1.0 -spatialCalOffsetX=-100.0 -spatialCalOffsetY=-100.0 -spatialCalScaleX=NaN -spatialCalScaleY=NaN +spatialCalOffsetX=-1251.0 +spatialCalOffsetY=-1504.0 +spatialCalScaleX=0.008333333333333333 +spatialCalScaleY=0.004081632653061225 spatialCalUnits=mm transpose=false diff --git a/plugins/Cameras.java b/plugins/Cameras.java index b0396e1..d1383b1 100644 --- a/plugins/Cameras.java +++ b/plugins/Cameras.java @@ -35,6 +35,7 @@ import ch.psi.pshell.imaging.Utils; import ch.psi.pshell.scripting.InterpreterResult; import ch.psi.pshell.scripting.ScriptManager; import ch.psi.utils.Arr; +import ch.psi.utils.ArrayProperties; import ch.psi.utils.Convert; import ch.psi.utils.swing.Editor.EditorDialog; import java.awt.Color; @@ -47,11 +48,15 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.IntStream; import javax.script.ScriptException; import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE; - +import org.apache.commons.math3.analysis.function.Gaussian; +import org.apache.commons.math3.fitting.GaussianCurveFitter; +import org.apache.commons.math3.fitting.WeightedObservedPoint; /** * */ @@ -62,6 +67,9 @@ public class Cameras extends Panel { renderer.setPersistenceFile(Paths.get(getController().getSetup().getContextPath(), "Renderer_Cameras.bin")); setPersistedComponents(new Component[]{checkCamtool}); comboCameras.setEnabled(false); + if (App.hasArgument("ct")) { + checkCamtool.setSelected(! App.getArgumentValue("ct").equals("0")); + } } final String configFolder = "/afs/psi.ch/intranet/SF/Applications/config/camtool"; @@ -97,7 +105,7 @@ public class Cameras extends Panel { ex.printStackTrace(); } } - startTimer(1000); + startTimer(2000); } @Override @@ -238,7 +246,7 @@ public class Cameras extends Panel { } camera.getConfig().save(); - camera.setPolling(-1000); + camera.setPolling(-2000); camera.setMonitored(false); renderer.setDevice(camera); renderer.setShowReticle(true); @@ -286,44 +294,100 @@ public class Cameras extends Panel { Profile profile = renderer.getProfile(); if ((profile != Profile.None) && (img != null)) { img = Utils.grayscale(img); - if (profile.hasVertical()) { - int[] sum = Utils.integrateVertically(img); - int[] x = Arr.indexesInt(img.getWidth()); - int[] y = new int[img.getWidth()]; + if (profile.hasVertical()) { try { - ScriptManager sm = Controller.getInstance().getScriptManager(); - sm.setVar("y", Convert.toDouble(sum)); - sm.setVar("x", Convert.toDouble(x)); - InterpreterResult r = sm.eval("r = fit(y, x)"); - if (r.exception != null){ - r.exception .printStackTrace(); - return null; - } else { - Object ret = sm.getVar("r"); - System.out.println(ret); + int[] sum = Utils.integrateVertically(img); + int[] x = Arr.indexesInt(sum.length); + double[] gaussian = fitGaussian(sum, x); + if (gaussian!=null){ + System.out.println("Norm: " + gaussian[0] + " Mean: " + gaussian[1] + " Sigma: " + gaussian[2]); + + double[] fit = getFitFunction(gaussian, x); + int[] y = new int[x.length]; + for (int i = 0; i < x.length; i++) { + y[i] = (int) (img.getHeight() - 1 - (((double) fit[i]) / 255 / factor)/2); + } + vpoly = new Overlays.Polyline(fitPen, x, y); } + } catch (Exception ex) { + ex.printStackTrace(); } - - for (int i = 0; i < img.getWidth(); i++) { - y[i] = (int) (img.getHeight() - 1 - (((double) sum[i]) / 255 / factor)/2); - } - vpoly = new Overlays.Polyline(fitPen, Arr.indexesInt(img.getWidth()), y); } if (profile.hasHorizontal()) { - int[] integration = Utils.integrateHorizontally(img); - int[] x = new int[img.getHeight()]; - int[] y = Arr.indexesInt(img.getHeight()); - - for (int i = 0; i < img.getHeight(); i++) { - x[i] = (int) (((double) integration[i]) / 255 / factor)/2; - } - hpoly = new Overlays.Polyline(fitPen, x, y); + try { + int[] sum = Utils.integrateHorizontally(img); + int[] x = Arr.indexesInt(sum.length); + double[] gaussian = fitGaussian(sum, x); + if (gaussian!=null){ + double[] fit = getFitFunction(gaussian, x); + + int[] y = new int[x.length]; + for (int i = 0; i < x.length; i++) { + y[i] = (int) (((double) fit[i]) / 255 / factor)/2; + } + hpoly = new Overlays.Polyline(fitPen, y, x); + } + + } catch (Exception ex) { + ex.printStackTrace(); + } } return new Overlay[]{hpoly, vpoly}; } return null; } + +double[] fitGaussianScript(int[] y, int[] x){ + ScriptManager sm = Controller.getInstance().getScriptManager(); + ArrayProperties pY = ArrayProperties.get(y); + sm.setVar("y", y); + sm.setVar("x", x); + //InterpreterResult r = sm.eval("r = fit(y, x)"); + System.out.println("-> " + pY.maxIndex); + InterpreterResult r = sm.eval("r = fit_gaussians(y, x, [" + pY.maxIndex+ ",])"); + if (r.exception != null){ + r.exception .printStackTrace(); + } else { + List ret = (List) sm.getVar("r"); + System.out.println(ret.size()); + if ((ret!=null) && (ret.size()==1)&& (ret.get(0) instanceof List) && (((List)(ret.get(0))).size()==3)){ + double norm = (Double) ((List)ret.get(0)).get(0); + double mean = (Double) ((List)ret.get(0)).get(1); + double sigma = (Double) ((List)ret.get(0)).get(2); + System.out.println("! " + norm + " " + mean + " " + sigma) ; + return new double[]{norm, mean, sigma}; + } + } + return null; + } + +double[]fitGaussian(int[] y, int[] x){ + try{ + ScriptManager sm = Controller.getInstance().getScriptManager(); + ArrayProperties pY = ArrayProperties.get(y); + GaussianCurveFitter fitter = GaussianCurveFitter.create().withStartPoint(new double[]{(pY.max-pY.min)/2,x[pY.maxIndex],1.0}).withMaxIterations(1000); + ArrayListvalues = new ArrayList<>(); + for (int i=0; i< y.length; i++){ + values.add(new WeightedObservedPoint(1.0, x[i], y[i])); + } + return fitter.fit(values); + } catch (Exception ex){ + return null; + } + + } + + + + double[] getFitFunction(double[] pars, int[] x){ + double[] fit = new double[x.length]; + Gaussian g = new Gaussian(pars[0], pars[1], pars[2]); + for (int i=0; i< x.length; i++){ + fit[i] = g.value(x[i]); + } + return fit; + } ///////// public class Camtool extends ArraySource {