From a4f9c0dbedd276288e62d168753ac83bbce0c21a Mon Sep 17 00:00:00 2001 From: gobbo_a Date: Tue, 5 Sep 2017 10:25:17 +0200 Subject: [PATCH] Startup --- devices/CurrentCamera.properties | 6 +- plugins/ScreenPanel.form | 13 +- plugins/ScreenPanel.java | 664 ++++++++--------- ...creenPanelNew.form => ScreenPanelOld.form} | 13 +- ...creenPanelNew.java => ScreenPanelOld.java} | 671 ++++++++++-------- 5 files changed, 683 insertions(+), 684 deletions(-) rename plugins/{ScreenPanelNew.form => ScreenPanelOld.form} (99%) rename plugins/{ScreenPanelNew.java => ScreenPanelOld.java} (86%) diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index 182663e..0e9f81d 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,4 +1,4 @@ -#Mon Sep 04 15:36:49 CEST 2017 +#Tue Sep 05 10:19:32 CEST 2017 colormap=Flame colormapAutomatic=true colormapMax=450.0 @@ -21,8 +21,8 @@ rotation=0.0 rotationCrop=false scale=1.0 serverURL=localhost\:10000 -spatialCalOffsetX=-50.075987841945285 -spatialCalOffsetY=-50.10141987829615 +spatialCalOffsetX=-50.03909304143862 +spatialCalOffsetY=-50.048875855327466 spatialCalScaleX=-1.0 spatialCalScaleY=-1.0 spatialCalUnits=mm diff --git a/plugins/ScreenPanel.form b/plugins/ScreenPanel.form index 21f7673..3974d55 100644 --- a/plugins/ScreenPanel.form +++ b/plugins/ScreenPanel.form @@ -248,6 +248,9 @@ + + + @@ -656,7 +659,7 @@ - + @@ -668,7 +671,7 @@ - + @@ -677,16 +680,16 @@ - + - + - + diff --git a/plugins/ScreenPanel.java b/plugins/ScreenPanel.java index f75e519..4581ec1 100644 --- a/plugins/ScreenPanel.java +++ b/plugins/ScreenPanel.java @@ -12,7 +12,7 @@ import ch.psi.utils.State; import ch.psi.utils.Chrono; import ch.psi.utils.swing.SwingUtils; import ch.psi.utils.swing.TextEditor; -import ch.psi.pshell.bs.Camtool; +import ch.psi.pshell.bs.PipelineServer; import ch.psi.pshell.bs.StreamValue; import ch.psi.pshell.device.DescStatsDouble; import ch.psi.pshell.device.Device; @@ -44,14 +44,12 @@ import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener; import ch.psi.utils.Arr; import ch.psi.utils.ArrayProperties; import ch.psi.utils.Convert; -import ch.psi.utils.TcpClient; import ch.psi.utils.swing.Editor.EditorDialog; import ch.psi.utils.swing.MainFrame; import ch.psi.utils.swing.StandardDialog; import ch.psi.utils.swing.StandardDialog.StandardDialogListener; import ch.psi.utils.swing.SwingUtils.OptionResult; import ch.psi.utils.swing.SwingUtils.OptionType; -import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; @@ -67,7 +65,6 @@ import java.awt.image.BufferedImage; import java.io.FileInputStream; import java.lang.reflect.Array; import java.lang.reflect.Field; -import java.net.ServerSocket; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -83,7 +80,6 @@ import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JMenuItem; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; @@ -104,10 +100,10 @@ import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; public class ScreenPanel extends Panel { final String CAMERA_DEVICE_NAME = "CurrentCamera"; - boolean useCamtoolStats = true; - + boolean useServerStats = true; String userOverlaysConfigFile; ColormapSource camera; + PipelineServer server; String cameraName; String cameraConfigJson; int polling = 1000; @@ -122,51 +118,50 @@ public class ScreenPanel extends Panel { Overlay[] profileOv; Overlay errorOverlay; boolean requestCameraListUpdate; - Integer localServerPort; - Process privateServer; - String serverUrl; boolean goodRegion; + String serverUrl; + String instanceName; - Double getCamtoolDouble(String name) { - return (Double) Convert.toDouble(((Camtool) camera).getValue(name)); + Double getServerDouble(String name) { + return (Double) Convert.toDouble(server.getValue(name)); } - double[] getCamtoolDoubleArray(String name) { - return (double[]) Convert.toDouble(((Camtool) camera).getValue(name)); + double[] getServerDoubleArray(String name) { + return (double[]) Convert.toDouble(server.getValue(name)); } - Double getCamtoolDouble(String name, StreamValue cache) { + Double getServerDouble(String name, StreamValue cache) { return (Double) Convert.toDouble(cache.__getitem__(name)); } - double[] getCamtoolDoubleArray(String name, StreamValue cache) { + double[] getServerDoubleArray(String name, StreamValue cache) { return (double[]) Convert.toDouble(cache.__getitem__(name)); } class ImageData { ImageData(){ - if (camera instanceof Camtool) { - StreamValue cache = ((Camtool) camera).getStream().take(); + if (server!= null) { + StreamValue cache = server.getStream().take(); String prefix = goodRegion ? "gr_" : ""; - x_fit_mean = getCamtoolDouble(prefix + "x_fit_mean", cache); - y_fit_mean = getCamtoolDouble(prefix + "y_fit_mean", cache); - x_fit_standard_deviation = getCamtoolDouble(prefix + "x_fit_standard_deviation", cache); - y_fit_standard_deviation = getCamtoolDouble(prefix + "y_fit_standard_deviation", cache); - x_fit_gauss_function = getCamtoolDoubleArray(prefix +"x_fit_gauss_function", cache); - y_fit_gauss_function = getCamtoolDoubleArray(prefix +"y_fit_gauss_function", cache); - x_profile = getCamtoolDoubleArray("x_profile", cache); - y_profile = getCamtoolDoubleArray("y_profile", cache); - x_center_of_mass = getCamtoolDouble("x_center_of_mass", cache); - y_center_of_mass = getCamtoolDouble("y_center_of_mass", cache); - x_rms = getCamtoolDouble("x_rms", cache); - y_rms = getCamtoolDouble("y_rms", cache); + x_fit_mean = getServerDouble(prefix + "x_fit_mean", cache); + y_fit_mean = getServerDouble(prefix + "y_fit_mean", cache); + x_fit_standard_deviation = getServerDouble(prefix + "x_fit_standard_deviation", cache); + y_fit_standard_deviation = getServerDouble(prefix + "y_fit_standard_deviation", cache); + x_fit_gauss_function = getServerDoubleArray(prefix +"x_fit_gauss_function", cache); + y_fit_gauss_function = getServerDoubleArray(prefix +"y_fit_gauss_function", cache); + x_profile = getServerDoubleArray("x_profile", cache); + y_profile = getServerDoubleArray("y_profile", cache); + x_center_of_mass = getServerDouble("x_center_of_mass", cache); + y_center_of_mass = getServerDouble("y_center_of_mass", cache); + x_rms = getServerDouble("x_rms", cache); + y_rms = getServerDouble("y_rms", cache); if (goodRegion){ double[] gX2 = new double[x_profile.length]; Arrays.fill(gX2, Double.NaN); try{ - double x = getCamtoolDoubleArray("gr_x_axis", cache)[0]; + double x = getServerDoubleArray("gr_x_axis", cache)[0]; System.arraycopy(x_fit_gauss_function, 0, gX2, (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageX(x): x), x_fit_gauss_function.length); } catch (Exception ex){ } @@ -174,7 +169,7 @@ public class ScreenPanel extends Panel { double[] gY2 = new double[y_profile.length]; Arrays.fill(gY2, Double.NaN); try{ - double y = getCamtoolDoubleArray("gr_y_axis", cache)[0]; + double y = getServerDoubleArray("gr_y_axis", cache)[0]; System.arraycopy(y_fit_gauss_function, 0, gY2, (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageY(y): y), y_fit_gauss_function.length); } catch (Exception ex){ } @@ -207,7 +202,7 @@ public class ScreenPanel extends Panel { final ArrayList imageBuffer = new ArrayList(); Frame currentFrame; - int imageBufferLenght = 0; + int imageBufferLenght = 1; Text imageBufferOverlay; public ScreenPanel() { @@ -219,7 +214,7 @@ public class ScreenPanel extends Panel { //spinnerMin.setVisible(false); labelMin.setVisible(false); //spinnerMax.setVisible(false); labelMax.setVisible(false); renderer.setPersistenceFile(Paths.get(getContext().getSetup().getContextPath(), "Renderer_Cameras.bin")); - setPersistedComponents(new Component[]{buttonCamtool, buttonDirect}); + setPersistedComponents(new Component[]{buttonServer, buttonDirect}); comboCameras.setEnabled(false); SwingUtils.setEnumCombo(comboColormap, Colormap.class); if (App.hasArgument("poll")) { @@ -253,26 +248,12 @@ public class ScreenPanel extends Panel { } } - if (App.hasArgument("priv_srv")) { - try { - try(ServerSocket s = new ServerSocket(0)){ - localServerPort = s.getLocalPort(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (App.hasArgument("srv_port")) { - localServerPort = Integer.valueOf(App.getArgumentValue("srv_port")); - } - if (App.hasArgument("srv_url")) { serverUrl = App.getArgumentValue("srv_url"); } if (App.hasArgument("calc")) { - useCamtoolStats = false; + useServerStats = false; } renderer.setProfileNormalized(true); @@ -288,10 +269,10 @@ public class ScreenPanel extends Panel { } }); - JMenuItem menuShowImageData = new JMenuItem("Show Image Data"); - menuShowImageData.addActionListener((ActionEvent e) -> { + JMenuItem menuShowStreamData = new JMenuItem("Show Stream Data"); + menuShowStreamData.addActionListener((ActionEvent e) -> { try { - showImageData(); + showStreamData(); } catch (Exception ex) { showException(ex); } @@ -310,7 +291,7 @@ public class ScreenPanel extends Panel { JMenuItem menuSetROI = new JMenuItem("Set ROI..."); menuSetROI.addActionListener((ActionEvent e) -> { renderer.abortSelection(); - if (camera instanceof Camtool) { + if (server != null) { final Overlays.Rect selection = new Overlays.Rect(renderer.getPenMovingOverlay()); renderer.addListener(new RendererListener() { @Override @@ -318,11 +299,11 @@ public class ScreenPanel extends Panel { try { renderer.setShowReticle(false); Rectangle roi = overlay.isFixed() ? renderer.toImageCoord(overlay.getBounds()) : overlay.getBounds(); - if (((Camtool) camera).isRoiEnabled()) { - int[] cur = ((Camtool) camera).getRoi(); - ((Camtool) camera).setRoi(new int[]{roi.x + cur[0], roi.y + cur[1], roi.width, roi.height}); + if (server.isRoiEnabled()) { + int[] cur = server.getRoi(); + server.setRoi(new int[]{roi.x + cur[0], roi.y + cur[1], roi.width, roi.height}); } else { - ((Camtool) camera).setRoi(new int[]{roi.x, roi.y, roi.width, roi.height}); + server.setRoi(new int[]{roi.x, roi.y, roi.width, roi.height}); } } catch (Exception ex) { } finally { @@ -343,17 +324,17 @@ public class ScreenPanel extends Panel { JMenuItem menuResetROI = new JMenuItem("Reset ROI"); menuResetROI.addActionListener((ActionEvent e) -> { renderer.abortSelection(); - if (camera instanceof Camtool) { + if (server != null) { try { renderer.setShowReticle(false); - ((Camtool) camera).resetRoi(); + server.resetRoi(); } catch (IOException ex) { showException(ex); } } }); - renderer.getPopupMenu().add(menuShowImageData); + renderer.getPopupMenu().add(menuShowStreamData); renderer.getPopupMenu().add(menuCalibrate); renderer.getPopupMenu().add(menuSaveStack); renderer.getPopupMenu().addSeparator(); @@ -362,10 +343,10 @@ public class ScreenPanel extends Panel { renderer.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - menuResetROI.setEnabled(camera instanceof Camtool); - menuSetROI.setEnabled(camera instanceof Camtool); - menuShowImageData.setVisible(camera instanceof Camtool); - menuCalibrate.setVisible(camera instanceof Camtool); + menuResetROI.setEnabled(server != null); + menuSetROI.setEnabled(server != null); + menuShowStreamData.setVisible(server != null); + menuCalibrate.setVisible(server != null); menuCalibrate.setEnabled((calibrationDialolg==null) || (!calibrationDialolg.isShowing()) ); } @@ -405,43 +386,9 @@ public class ScreenPanel extends Panel { super.onStart(); if (App.hasArgument("ct")) { boolean direct = App.getArgumentValue("ct").equals("0") || App.getArgumentValue("ct").equalsIgnoreCase("false"); - buttonCamtool.setSelected(!direct); + buttonServer.setSelected(!direct); buttonDirect.setSelected(direct); - } - if (App.hasArgument("priv_srv")) { - try { - System.out.println("Starting camtool server on port: " + localServerPort); - //Was creating sub-processes which cannot be destroyed. - //String cmd = "cam_server"; - //cmd = "source /opt/gfa/python\n" + cmd; - //privateServer = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd}); - String cmd = "/opt/gfa/python-3.5/2.4.1/bin/python /opt/gfa/python-3.5/latest/bin/cam_server"; - String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null); - cmd = cmd + " -p " + localServerPort + " -b " + configFolder; - privateServer = Runtime.getRuntime().exec(cmd); - //System.out.println("pid = " + Sys.getPid(privateServer)); - long start = System.currentTimeMillis(); - while (true){ - try (TcpClient c = new TcpClient("localhost", localServerPort)){ - try{ - c.connect(); - System.out.println("Connected to camtool server on port: " + localServerPort); - break; - } catch (Exception ex){ - } - } - Thread.sleep(10); - if ((System.currentTimeMillis() - start) > 5000){ - errorOverlay = new Text(renderer.getPenErrorText(), "Error connecting to server at port " + localServerPort , new Font("Verdana", Font.PLAIN, 12), new Point(20, 20)); - renderer.addOverlay(errorOverlay); - break; - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - + } } @@ -452,17 +399,7 @@ public class ScreenPanel extends Panel { if (camera != null) { camera.close(); camera = null; - } - if (privateServer!=null){ - System.out.println("Closing camtool server"); - //int pid = Sys.getPid(privateServer); - privateServer.destroyForcibly(); - //if (pid>0){ - // System.out.println("Killing pid = " + pid); - // Runtime.getRuntime().exec("kill " + pid); - // - //} - privateServer = null; + server = null; } } catch (Exception ex) { ex.printStackTrace(); @@ -491,7 +428,7 @@ public class ScreenPanel extends Panel { ); } else { - usingCamtool = buttonCamtool.isSelected(); + usingServer = buttonServer.isSelected(); updateCameraList(); comboCameras.setEnabled(true); setComboCameraSelection(-1); @@ -510,37 +447,39 @@ public class ScreenPanel extends Panel { startTimer(1000); } - DefaultComboBoxModel getCameraListFromFolder() throws Exception { - ArrayList cameras = (ArrayList) getContext().getClassByName("SfCamera").getMethod("getCameras", new Class[]{}).invoke(null); + DefaultComboBoxModel getCameraList(boolean fromServer) throws Exception { DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String cam:cameras) { - model.addElement(cam); - } - return model; - } - - DefaultComboBoxModel getCameraListFromCamtool() throws IOException, InterruptedException { - DefaultComboBoxModel model = new DefaultComboBoxModel(); - Camtool camtool = newCamtool(); - try { - camtool.initialize(); - List cameras = camtool.getCameras(); - Collections.sort(cameras); - for (String camera : cameras) { - model.addElement(camera); + if (fromServer){ + PipelineServer server = newServer(); + try { + server.initialize(); + List cameras = server.getCameras(); + Collections.sort(cameras); + for (String camera : cameras) { + model.addElement(camera); + } + } finally { + server.close(); + } + + } else { + ArrayList cameras = (ArrayList) getContext().getClassByName("SfCamera").getMethod("getCameras", new Class[]{}).invoke(null); + for (String cam:cameras) { + model.addElement(cam); } - //model.addElement(Camtool.SIMULATION); - } finally { - camtool.close(); } return model; } - Camtool newCamtool(){ - if (serverUrl!=null){ - return new Camtool(CAMERA_DEVICE_NAME, serverUrl); - } - return (localServerPort != null) ? new Camtool(CAMERA_DEVICE_NAME, "localhost:"+localServerPort) : new Camtool(CAMERA_DEVICE_NAME); + PipelineServer newServer() throws IOException{ + if (serverUrl!=null){ + System.out.println("Connecting to server: " + serverUrl); + server = new PipelineServer(CAMERA_DEVICE_NAME, serverUrl); + } else { + System.out.println("Connecting to server"); + server = new PipelineServer(CAMERA_DEVICE_NAME); + } + return server; } boolean updatingCameraSelection; @@ -554,12 +493,12 @@ public class ScreenPanel extends Panel { } } - boolean usingCamtool; + boolean usingServer; void updateCameraList() { try { String selected = (String) comboCameras.getSelectedItem(); - DefaultComboBoxModel model = usingCamtool ? getCameraListFromCamtool() : getCameraListFromFolder(); + DefaultComboBoxModel model = getCameraList(usingServer); if (App.hasArgument("cam")) { String cam = App.getArgumentValue("cam"); if (model.getIndexOf(cam) < 0) { @@ -615,8 +554,8 @@ public class ScreenPanel extends Panel { Thread devicesInitTask; - void setCamera(String cameraName) throws IOException, InterruptedException { - System.out.println("Setting camera: " + cameraName + " [" + (buttonCamtool.isSelected() ? "camtool" : "direct") + "]"); + void setCamera(String cameraName) throws IOException, InterruptedException { + System.out.println("Initializing"); parseUserOverlays(); errorOverlay = null; @@ -631,13 +570,15 @@ public class ScreenPanel extends Panel { calibrationDialolg = null; } - boolean was_camtool = false; + boolean was_server = false; if (camera != null) { //camera.removeAllListeners(); - was_camtool = camera instanceof Camtool; + was_server = (server != null); camera.close(); camera = null; + server = null; } + instanceName = null; renderer.setDevice(null); renderer.setShowReticle(false); @@ -675,6 +616,8 @@ public class ScreenPanel extends Panel { return; } + System.out.println("Setting camera: " + cameraName + " [" + (buttonServer.isSelected() ? "server" : "direct") + "]"); + synchronized (imageBuffer) { currentFrame = null; imageBuffer.clear(); @@ -686,8 +629,8 @@ public class ScreenPanel extends Panel { Path configFile = Paths.get(configFolder, cameraName + ".json"); cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null; - if (buttonCamtool.isSelected()) { - camera = newCamtool(); + if (buttonServer.isSelected()) { + camera = newServer(); camera.getConfig().flipHorizontally = false; camera.getConfig().flipVertically = false; camera.getConfig().rotation = 0.0; @@ -702,27 +645,22 @@ public class ScreenPanel extends Panel { camera.initialize(); camera.assertInitialized(); System.out.println("Camera initialization OK"); - if (camera instanceof Camtool) { - //Managing no background exception. Can be done in a better way? -// if (changed) { - ((Camtool) camera).startPipeline(cameraName, null); - updateCamtoolControls(); -// } else { -// ((Camtool) camera).startPipeline(cameraName, null, checkBackground.isSelected(), null, null, null); -// } - // HashMap gr = null; - // if (goodRegion){ - // gr = new HashMap<>(); - // gr.put("threshold", spinnerGrThreshold.getValue()); - // gr.put("gfscale", spinnerGrScale.getValue()); - // } - // ((Camtool) camera).startPipeline(cameraName, null, checkBackground.isSelected(), null, checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null, gr); - //} - + if (server != null) { + //server.start(cameraName, false); + String pipelineName = cameraName+"_sp"; + instanceName = cameraName+"_sp1"; + if (!server.getPipelines().contains(pipelineName)){ + System.out.println("Creating pipeline: " + pipelineName); + HashMap config = new HashMap<>(); + config.put("camera_name", cameraName); + //server.createFromConfig(config, pipelineName); + server.savePipelineConfig(pipelineName, config); + } + server.start(pipelineName, instanceName); + + updateServerControls(); checkThreshold.setEnabled(true); - checkGoodRegion.setEnabled(true); - - ((Camtool) camera).startReceiver(); + checkGoodRegion.setEnabled(true); } else { checkThreshold.setSelected(false); checkGoodRegion.setSelected(false); @@ -764,7 +702,7 @@ public class ScreenPanel extends Panel { if (data != null) { synchronized (imageBuffer) { currentFrame =new Frame(data); - if (imageBufferLenght > 1) { + if (imageBufferLenght >= 1) { imageBuffer.add(currentFrame); if (imageBuffer.size() > imageBufferLenght) { imageBuffer.remove(0); @@ -780,7 +718,7 @@ public class ScreenPanel extends Panel { @Override public void onError(Object o, Exception ex) { - ex.printStackTrace(); + //System.err.println(ex); } }); @@ -788,7 +726,7 @@ public class ScreenPanel extends Panel { ex.printStackTrace(); showException(ex); renderer.clearOverlays(); - updateCamtoolControls(); + updateServerControls(); if (renderer.getDevice() == null) { //renderer.setZoom(1.0); //renderer.setMode(RendererMode.Zoom); @@ -944,21 +882,21 @@ public class ScreenPanel extends Panel { updatingColormap = false; } - boolean updatingCamtoolControls; + boolean updatingServerControls; - void updateCamtoolControls() { - if ((camera != null) && (camera instanceof Camtool)) { - updatingCamtoolControls = true; + void updateServerControls() { + if (server != null) { + updatingServerControls = true; try { - checkBackground.setSelected(((Camtool) camera).getBackgroundSubtraction()); - Double threshold = ((Camtool) camera).getThreshold(); + checkBackground.setSelected(server.getBackgroundSubtraction()); + Double threshold = (server.getThreshold()); checkThreshold.setSelected(threshold != null); spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = ((Camtool) camera).getGoodRegion(); + Map gr = (server.getGoodRegion()); checkGoodRegion.setSelected(gr != null); if (gr != null){ - spinnerGrThreshold.setValue(gr.get("threshold")); - spinnerGrScale.setValue(gr.get("gfscale")); + spinnerGrThreshold.setValue(((Number)gr.get("threshold")).doubleValue()); + spinnerGrScale.setValue(((Number)gr.get("gfscale")).doubleValue()); } } catch (Exception ex) { } @@ -966,13 +904,13 @@ public class ScreenPanel extends Panel { spinnerThreshold.setVisible(checkThreshold.isSelected()); spinnerGrThreshold.setVisible(goodRegion); labelGrThreshold.setVisible(spinnerGrThreshold.isVisible()); spinnerGrScale.setVisible(goodRegion); labelGrScale.setVisible(spinnerGrScale.isVisible()); - updatingCamtoolControls = false; + updatingServerControls = false; } } boolean isCameraStopped() { - if ((camera != null) && (camera instanceof Camtool)) { - if (!((Camtool) camera).isPipelineStarted()) { + if (server != null) { + if (!server.isStarted()) { return true; } } @@ -1015,7 +953,7 @@ public class ScreenPanel extends Panel { buttonMarker.setSelected(false); } if (!renderer.isPaused() && (dataTableDialog!=null) && (dataTableDialog.isShowing())){ - updateImageData(); + updateStreamData(); } updateZoom(); updateColormap(); @@ -1038,7 +976,7 @@ public class ScreenPanel extends Panel { return currentFrame; } - Frame getFrame(Data data){ + Frame getFrame(Data data){ synchronized (imageBuffer) { for (Frame f : imageBuffer) { if (f.data == data) { @@ -1062,7 +1000,7 @@ public class ScreenPanel extends Panel { //Double xCom=null, yCom=null; if (data != null) { int profileSize = renderer.getProfileSize(); - if ((useCamtoolStats) && (camera instanceof Camtool)) { + if ((useServerStats) && (server != null)) { try { ImageData id = getFrame(data); @@ -1141,94 +1079,94 @@ public class ScreenPanel extends Panel { if (rangePlot <= 0) { return null; } - try { - double[] sum = data.integrateVertically(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] x_egu = renderer.getCalibration().getAxisX(sum.length); - double[] comRms = getComRms(sum, x_egu); - xCom = comRms[0]; - xRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - if (showFit){ - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - xNorm = gaussian[0]; - xMean = gaussian[1]; - xSigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize)); - } - vgaussian = new Overlays.Polyline(penFit, x, y); + if (renderer.getCalibration() != null) { + try { + double[] sum = data.integrateVertically(true); + double[] saux = new double[sum.length]; + int[] p = new int[sum.length]; + double[] x_egu = renderer.getCalibration().getAxisX(sum.length); + double[] comRms = getComRms(sum, x_egu); + xCom = comRms[0]; + xRms = comRms[1]; + int[] x = Arr.indexesInt(sum.length); + DescriptiveStatistics stats = new DescriptiveStatistics(sum); + double min = stats.getMin(); + for (int i = 0; i < sum.length; i++) { + saux[i] = sum[i] - min; + } + if (showFit){ + double[] gaussian = fitGaussian(saux, x); + if (gaussian != null) { + if ((gaussian[2] < sum.length * 0.45) + && (gaussian[2] > 2) + && (gaussian[0] > min * 0.03)) { + xNorm = gaussian[0]; + xMean = gaussian[1]; + xSigma = gaussian[2]; + double[] fit = getFitFunction(gaussian, x); + int[] y = new int[x.length]; + for (int i = 0; i < x.length; i++) { + y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize)); + } + vgaussian = new Overlays.Polyline(penFit, x, y); + } } } - } - if (showProfile){ - for (int i = 0; i < x.length; i++) { - p[i] = (int) (height - 1 - (((sum[i] / height- minPlot) / rangePlot) * profileSize)); + if (showProfile){ + for (int i = 0; i < x.length; i++) { + p[i] = (int) (height - 1 - (((sum[i] / height- minPlot) / rangePlot) * profileSize)); + } + vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); } - vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - - try { - double[] sum = data.integrateHorizontally(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] y_egu = renderer.getCalibration().getAxisY(sum.length); - double[] comRms = getComRms(sum, y_egu); - yCom = comRms[0]; - yRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; + } catch (Exception ex) { + ex.printStackTrace(); } - if (showFit){ - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - //Only aknowledge beam fully inside the image and peak over 3% of min - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - yNorm = gaussian[0]; - yMean = gaussian[1]; - ySigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize); - } - hgaussian = new Overlays.Polyline(penFit, y, x); - } + try { + double[] sum = data.integrateHorizontally(true); + double[] saux = new double[sum.length]; + int[] p = new int[sum.length]; + double[] y_egu = renderer.getCalibration().getAxisY(sum.length); + double[] comRms = getComRms(sum, y_egu); + yCom = comRms[0]; + yRms = comRms[1]; + int[] x = Arr.indexesInt(sum.length); + DescriptiveStatistics stats = new DescriptiveStatistics(sum); + double min = stats.getMin(); + for (int i = 0; i < sum.length; i++) { + saux[i] = sum[i] - min; } - } - if (showProfile){ - for (int i = 0; i < x.length; i++) { - p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize); - } - hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - if (renderer.getCalibration() != null) { + if (showFit){ + double[] gaussian = fitGaussian(saux, x); + if (gaussian != null) { + //Only aknowledge beam fully inside the image and peak over 3% of min + if ((gaussian[2] < sum.length * 0.45) + && (gaussian[2] > 2) + && (gaussian[0] > min * 0.03)) { + yNorm = gaussian[0]; + yMean = gaussian[1]; + ySigma = gaussian[2]; + double[] fit = getFitFunction(gaussian, x); + + int[] y = new int[x.length]; + for (int i = 0; i < x.length; i++) { + y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize); + } + hgaussian = new Overlays.Polyline(penFit, y, x); + } + } + } + if (showProfile){ + for (int i = 0; i < x.length; i++) { + p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize); + } + hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x); + } + + } catch (Exception ex) { + ex.printStackTrace(); + } if (xSigma != null) { xSigma *= renderer.getCalibration().getScaleX(); } @@ -1277,7 +1215,7 @@ public class ScreenPanel extends Panel { if (goodRegion){ try{ - double[] x = getCamtoolDoubleArray("gr_x_axis"); double[] y = getCamtoolDoubleArray("gr_y_axis"); + double[] x = getServerDoubleArray("gr_x_axis"); double[] y = getServerDoubleArray("gr_y_axis"); double x1 = x[0]; double x2 = x[x.length-1]; double y1 = y[0]; double y2 = y[y.length-1]; Overlays.Rect goodRegionOv = new Overlays.Rect(new Pen(penFit.getColor(), 0, Pen.LineStyle.dotted)); goodRegionOv.setCalibration(renderer.getCalibration()); @@ -1376,7 +1314,7 @@ public class ScreenPanel extends Panel { Overlay[] getUserOverlays(Data data) { ArrayList ret = new ArrayList<>(); - if (camera instanceof Camtool) { + if (server != null) { for (UserOverlay uo : userOverlayConfig) { try { Overlay ov = uo.obj; @@ -1384,8 +1322,8 @@ public class ScreenPanel extends Panel { ov.setCalibration(renderer.getCalibration()); boolean valid = false; if (ov instanceof Overlays.Polyline) { - double[] x = (uo.channels[0].equals("null")) ? null : getCamtoolDoubleArray(uo.channels[0]); - double[] y = (uo.channels[1].equals("null")) ? null : getCamtoolDoubleArray(uo.channels[1]); + double[] x = (uo.channels[0].equals("null")) ? null : getServerDoubleArray(uo.channels[0]); + double[] y = (uo.channels[1].equals("null")) ? null : getServerDoubleArray(uo.channels[1]); if ((x != null) || (y !=null)) { if (x == null) { x = (renderer.getCalibration() == null) ? Arr.indexesDouble(y.length) : renderer.getCalibration().getAxisX(y.length); @@ -1397,12 +1335,12 @@ public class ScreenPanel extends Panel { valid = true; } } else { - Double x = getCamtoolDouble(uo.channels[0]); Double y = getCamtoolDouble(uo.channels[1]); + Double x = getServerDouble(uo.channels[0]); Double y = getServerDouble(uo.channels[1]); if ((x != null) && (y !=null)) { PointDouble position = new PointDouble(x,y); ov.setAbsolutePosition(position); if (!(ov instanceof Overlays.Crosshairs)) { - Double x2 = getCamtoolDouble(uo.channels[2]); Double y2 = getCamtoolDouble(uo.channels[3]); + Double x2 = getServerDouble(uo.channels[2]); Double y2 = getServerDouble(uo.channels[3]); if ((x != null) && (y !=null)) { DimensionDouble size = new DimensionDouble(x2 - position.x, y2 - position.y); ov.setAbsoluteSize(size); @@ -1417,7 +1355,7 @@ public class ScreenPanel extends Panel { ret.add(ov); } } catch (Exception ex) { - ex.printStackTrace(); + //ex.printStackTrace(); } } } @@ -1592,9 +1530,9 @@ public class ScreenPanel extends Panel { getContext().getDataManager().setAttribute("/", "Calibration", cal == null ? new double[]{1,1,0,0} : new double[]{cal.getScaleX(), cal.getScaleY(), cal.getOffsetX(), cal.getOffsetY()}); getContext().getDataManager().setAttribute(path, "Timestamp", Chrono.getTimeStr(frame.data.getTimestamp(), "HH:mm:ss.SSS")); - if (camera instanceof Camtool){ + if (server != null){ try{ - getContext().getDataManager().setAttribute("/", "ROI", ((Camtool) camera).getRoi()); + getContext().getDataManager().setAttribute("/", "ROI", server.getRoi()); } catch (Exception ex){ getContext().getDataManager().setAttribute("/", "ROI", new int[]{0,0,-1,-1}); } @@ -1605,7 +1543,7 @@ public class ScreenPanel extends Panel { } } for (String name : new String[]{"x_axis", "y_axis", "gr_x_axis", "gr_y_axis"}){ - double[] val = getCamtoolDoubleArray(name); + double[] val = getServerDoubleArray(name); getContext().getDataManager().setAttribute("/", "GoodRegion", goodRegion); if (val!=null){ getContext().getDataManager().setAttribute("/", name, val); @@ -1661,7 +1599,7 @@ public class ScreenPanel extends Panel { if (SwingUtils.showOption(getTopLevel(), "Success", panel, OptionType.OkCancel) == OptionResult.Yes){ StringBuilder message = new StringBuilder(); message.append("Camera: ").append(cameraName).append(" ("). - append((camera instanceof Camtool) ? "camtool" : "direct").append(")").append("\n"); + append((server!=null) ? "server" : "direct").append(")").append("\n"); message.append("Screen: ").append(String.valueOf(valueScreen.getLabel().getText())).append("\n"); message.append("Filter: ").append(String.valueOf(valueFilter.getLabel().getText())).append("\n"); message.append("Data file: ").append(getContext().getExecutionPars().getPath()).append("\n"); @@ -1699,9 +1637,10 @@ public class ScreenPanel extends Panel { StandardDialog calibrationDialolg; void calibrate() throws Exception{ - if (camera instanceof Camtool){ - calibrationDialolg = (StandardDialog) getContext().getClassByName("CameraConfigDialog").getConstructors()[0].newInstance(new Object[]{getTopLevel(), camera, renderer}); - SwingUtils.centerComponent(this, calibrationDialolg); + if (server != null){ + server.resetRoi(); + calibrationDialolg = (StandardDialog) getContext().getClassByName("CameraCalibrationDialog").getConstructors()[0].newInstance(new Object[]{getTopLevel(), server.getCurrentCamera(), renderer}); + SwingUtils.centerComponent(getTopLevel(), calibrationDialolg); calibrationDialolg.setVisible(true); calibrationDialolg.setListener(new StandardDialogListener() { @Override @@ -1710,7 +1649,7 @@ public class ScreenPanel extends Panel { @Override public void onWindowClosed(StandardDialog dlg, boolean accepted) { if (accepted){ - comboCamerasActionPerformed(null); + //comboCamerasActionPerformed(null); } } }); @@ -1719,9 +1658,9 @@ public class ScreenPanel extends Panel { StandardDialog dataTableDialog; DefaultTableModel dataTableModel; - void showImageData(){ + void showStreamData(){ dataTableModel = null; - if (camera instanceof Camtool){ + if (server!=null){ if ((dataTableDialog!=null) && (dataTableDialog.isShowing())){ SwingUtils.centerComponent(getTopLevel(), dataTableDialog); @@ -1738,10 +1677,11 @@ public class ScreenPanel extends Panel { return false; } }; - updateImageData(); - StreamValue val = ((Camtool)camera).getStream().take(); + updateStreamData(); + StreamValue val = server.getStream().take(); JTable dataTable = new JTable(dataTableModel); dataTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); + dataTable.setCellSelectionEnabled(true); dataTable.getTableHeader().setReorderingAllowed(false); dataTable.getTableHeader().setResizingAllowed(true); dataTableDialog = new StandardDialog(getTopLevel(), "Image Data", false); @@ -1762,19 +1702,31 @@ public class ScreenPanel extends Panel { } } - void updateImageData(){ - if ((dataTableModel!=null)&&(camera instanceof Camtool)){ - List ids = new ArrayList(((Camtool)camera).getValue().getIdentifiers()); - if (ids.size() != dataTableModel.getRowCount()){ - dataTableModel.setNumRows(0); + void updateStreamData(){ + if ((dataTableModel!=null)&&(server != null)){ + StreamValue value = server.getValue(); + + List ids = (value==null) ? new ArrayList<>(): new ArrayList(value.getIdentifiers()); + if (ids.size()+2 != dataTableModel.getRowCount()){ + dataTableModel.setNumRows(0); + try { + dataTableModel.addRow(new Object[]{"Locator", server.getUrl() + "/" + ((value==null) ? instanceName : server.getCurrentInstance())}); + } catch (Exception ex) { + dataTableModel.addRow(new Object[]{"Locator", ex.getMessage()}); + } + try { + dataTableModel.addRow(new Object[]{"Stream", server.getStreamAddress()}); + } catch (Exception ex) { + dataTableModel.addRow(new Object[]{"Stream", ex.getMessage()}); + } Collections.sort(ids); for (String id : ids){ dataTableModel.addRow(new Object[]{id, ""}); } } - for (int i = 0 ; i< dataTableModel.getRowCount(); i++){ + for (int i = 2 ; i< dataTableModel.getRowCount(); i++){ String id = String.valueOf(dataTableModel.getValueAt(i, 0)); - Object obj = ((Camtool)camera).getValue(id); + Object obj = server.getValue(id); if (obj!=null){ if (obj.getClass().isArray()){ obj = obj.getClass().getComponentType().getSimpleName() + "[" + Array.getLength(obj) + "]"; @@ -1839,7 +1791,7 @@ public class ScreenPanel extends Panel { labelMax = new javax.swing.JLabel(); btFixColormapRange = new javax.swing.JButton(); jPanel5 = new javax.swing.JPanel(); - buttonCamtool = new javax.swing.JRadioButton(); + buttonServer = new javax.swing.JRadioButton(); buttonDirect = new javax.swing.JRadioButton(); panelScreen = new javax.swing.JPanel(); valueScreen = new ch.psi.pshell.swing.DeviceValuePanel(); @@ -1960,6 +1912,7 @@ public class ScreenPanel extends Panel { jLabel2.setText("State:"); + comboCameras.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N comboCameras.setMaximumRowCount(30); comboCameras.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -2275,12 +2228,12 @@ public class ScreenPanel extends Panel { jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Source")); - buttonGroup4.add(buttonCamtool); - buttonCamtool.setSelected(true); - buttonCamtool.setText("Camtool"); - buttonCamtool.addActionListener(new java.awt.event.ActionListener() { + buttonGroup4.add(buttonServer); + buttonServer.setSelected(true); + buttonServer.setText("Server"); + buttonServer.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonCamtoolActionPerformed(evt); + buttonServerActionPerformed(evt); } }); @@ -2298,7 +2251,7 @@ public class ScreenPanel extends Panel { jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup() .addContainerGap() - .addComponent(buttonCamtool) + .addComponent(buttonServer) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonDirect) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) @@ -2308,7 +2261,7 @@ public class ScreenPanel extends Panel { .addGroup(jPanel5Layout.createSequentialGroup() .addGap(4, 4, 4) .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonCamtool) + .addComponent(buttonServer) .addComponent(buttonDirect)) .addContainerGap()) ); @@ -2540,7 +2493,7 @@ public class ScreenPanel extends Panel { throw new Exception("Invalid state"); } comboCameras.setEnabled(false); - buttonCamtool.setEnabled(false); + buttonServer.setEnabled(false); buttonDirect.setEnabled(false); final String cameraName = (String) comboCameras.getSelectedItem(); new Thread(new Runnable() { @@ -2561,7 +2514,7 @@ public class ScreenPanel extends Panel { } finally { updateStop(); comboCameras.setEnabled(true); - buttonCamtool.setEnabled(true); + buttonServer.setEnabled(true); buttonDirect.setEnabled(true); } } @@ -2582,7 +2535,7 @@ public class ScreenPanel extends Panel { EditorDialog dlg = editor.getDialog(getTopLevel(), false); dlg.setSize(480, 640); dlg.setVisible(true); - SwingUtils.centerComponent(this, dlg); + SwingUtils.centerComponent(getTopLevel(), dlg); } } catch (Exception ex) { showException(ex); @@ -2610,14 +2563,14 @@ public class ScreenPanel extends Panel { imageBuffer.clear(); renderer.resume(); } - pauseSelection.setVisible(buttonPause.isSelected() && (imageBuffer.size() > 0)); + pauseSelection.setVisible(buttonPause.isSelected() && (imageBuffer.size() > 1)); if (pauseSelection.isVisible()) { renderer.addOverlay(imageBufferOverlay); pauseSelection.setMaxValue(imageBuffer.size()); pauseSelection.setValue(imageBuffer.size());; } } - updateImageData(); + updateStreamData(); } } catch (Exception ex) { ex.printStackTrace(); @@ -2669,36 +2622,19 @@ public class ScreenPanel extends Panel { if (camera != null) { if (SwingUtils.showOption(getTopLevel(), "Background", "Do you want to capture background now?", OptionType.YesNo) == OptionResult.Yes) { boolean laserOn = getLaserState(); - if (camera instanceof Camtool){ - boolean rendering = (!camera.isClosed()); - if (rendering) { - camera.close(); - } - if (laserOn) { - setLaserState(false); - } - try { - System.out.println("Grabbing background for: " + cameraName); - ((Camtool) camera).grabBackground(cameraName, 5); - } finally { - if (laserOn) { - setLaserState(true); - } - if (rendering) { - comboCamerasActionPerformed(null); - } - updateStop(); - } - } else { - if (laserOn) { - setLaserState(false); - } - try { + if (laserOn) { + setLaserState(false); + } + try { + System.out.println("Grabbing background for: " + cameraName); + if (server!=null){ + server.captureBackground(cameraName, 5); + } else { camera.captureBackground(5, 0); - } finally { - if (laserOn) { - setLaserState(true); - } + } + } finally { + if (laserOn) { + setLaserState(true); } } SwingUtils.showMessage(getTopLevel(), "Success", "Success capturing background", 5000); @@ -2789,17 +2725,17 @@ public class ScreenPanel extends Panel { centralizeRenderer(); }//GEN-LAST:event_buttonZoom05ActionPerformed - private void buttonCamtoolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCamtoolActionPerformed - if (!usingCamtool) { - usingCamtool = true; + private void buttonServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonServerActionPerformed + if (!usingServer) { + usingServer = true; requestCameraListUpdate = true; } comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonCamtoolActionPerformed + }//GEN-LAST:event_buttonServerActionPerformed private void buttonDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectActionPerformed - if (usingCamtool) { - usingCamtool = false; + if (usingServer) { + usingServer = false; requestCameraListUpdate = true; } comboCamerasActionPerformed(null); @@ -2876,32 +2812,31 @@ public class ScreenPanel extends Panel { }//GEN-LAST:event_buttonZoom2ActionPerformed private void spinnerThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerThresholdonChange - if (!updatingCamtoolControls) { + if (!updatingServerControls) { try { - if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { - ((Camtool) camera).setThreshold((Double) spinnerThreshold.getValue()); + if ((server!=null) && (server.isStarted())) { + server.setThreshold((Double) spinnerThreshold.getValue()); } } catch (Exception ex) { showException(ex); - updateCamtoolControls(); + updateServerControls(); } } }//GEN-LAST:event_spinnerThresholdonChange private void checkBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBackgroundActionPerformed - if (camera instanceof Camtool){ - if (!updatingCamtoolControls) { + if (server!=null){ + if (!updatingServerControls) { try { - if (((Camtool) camera).isPipelineStarted()) { - ((Camtool) camera).setBackgroundSubtraction(checkBackground.isSelected()); + if (server.isStarted()) { + server.setBackgroundSubtraction(checkBackground.isSelected()); } } catch (Exception ex) { showException(ex); - updateCamtoolControls(); - //There is a bug in camtool: it will flag bg extraction as on: - updatingCamtoolControls = true; + updateServerControls(); + updatingServerControls = true; checkBackground.setSelected(false); - updatingCamtoolControls = false; + updatingServerControls = false; } } @@ -2911,15 +2846,15 @@ public class ScreenPanel extends Panel { }//GEN-LAST:event_checkBackgroundActionPerformed private void checkThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkThresholdActionPerformed - if (!updatingCamtoolControls) { + if (!updatingServerControls) { try { - if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { + if ((server!=null) && (server.isStarted())) { spinnerThreshold.setVisible(checkThreshold.isSelected()); - ((Camtool) camera).setThreshold(checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null); + server.setThreshold(checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null); } } catch (Exception ex) { showException(ex); - updateCamtoolControls(); + updateServerControls(); } } }//GEN-LAST:event_checkThresholdActionPerformed @@ -2957,34 +2892,35 @@ public class ScreenPanel extends Panel { }//GEN-LAST:event_buttonProfileActionPerformed private void checkGoodRegionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkGoodRegionActionPerformed - if (!updatingCamtoolControls) { + if (!updatingServerControls) { try { - if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { + if ((server!=null) && (server.isStarted())) { spinnerGrScale.setVisible(checkGoodRegion.isSelected()); labelGrScale.setVisible(spinnerGrScale.isVisible()); spinnerGrThreshold.setVisible(checkGoodRegion.isSelected()); labelGrThreshold.setVisible(spinnerGrThreshold.isVisible()); if (checkGoodRegion.isSelected()){ - ((Camtool) camera).setGoodRegion( (Double)spinnerGrThreshold.getValue(), (Double)spinnerGrScale.getValue() ); + server.setGoodRegion( ((Number)spinnerGrThreshold.getValue()).doubleValue(), ((Number)spinnerGrScale.getValue()).doubleValue() ); } else { - ((Camtool) camera).setGoodRegion(null); + server.setGoodRegion(null); } goodRegion = checkGoodRegion.isSelected(); } } catch (Exception ex) { showException(ex); - updateCamtoolControls(); + ex.printStackTrace(); + updateServerControls(); } } }//GEN-LAST:event_checkGoodRegionActionPerformed private void spinnerGrThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerGrThresholdonChange - if (!updatingCamtoolControls) { + if (!updatingServerControls) { try { - if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { - ((Camtool) camera).setGoodRegion( (Double)spinnerGrThreshold.getValue(), (Double)spinnerGrScale.getValue() ); + if ((server != null) && (server.isStarted())) { + server.setGoodRegion( (Double)spinnerGrThreshold.getValue(), (Double)spinnerGrScale.getValue() ); } } catch (Exception ex) { showException(ex); - updateCamtoolControls(); + updateServerControls(); } } }//GEN-LAST:event_spinnerGrThresholdonChange @@ -3008,7 +2944,6 @@ public class ScreenPanel extends Panel { private javax.swing.JButton btFixColormapRange; private javax.swing.JButton buttonArgs; private javax.swing.JRadioButton buttonAutomatic; - private javax.swing.JRadioButton buttonCamtool; private javax.swing.JButton buttonConfig; private javax.swing.JRadioButton buttonDirect; private javax.swing.JToggleButton buttonFit; @@ -3024,6 +2959,7 @@ public class ScreenPanel extends Panel { private javax.swing.JToggleButton buttonProfile; private javax.swing.JToggleButton buttonReticle; private javax.swing.JToggleButton buttonSave; + private javax.swing.JRadioButton buttonServer; private javax.swing.JButton buttonStop; private javax.swing.JRadioButton buttonZoom025; private javax.swing.JRadioButton buttonZoom05; diff --git a/plugins/ScreenPanelNew.form b/plugins/ScreenPanelOld.form similarity index 99% rename from plugins/ScreenPanelNew.form rename to plugins/ScreenPanelOld.form index 3974d55..21f7673 100644 --- a/plugins/ScreenPanelNew.form +++ b/plugins/ScreenPanelOld.form @@ -248,9 +248,6 @@ - - - @@ -659,7 +656,7 @@ - + @@ -671,7 +668,7 @@ - + @@ -680,16 +677,16 @@ - + - + - + diff --git a/plugins/ScreenPanelNew.java b/plugins/ScreenPanelOld.java similarity index 86% rename from plugins/ScreenPanelNew.java rename to plugins/ScreenPanelOld.java index 59a9c71..ac33de4 100644 --- a/plugins/ScreenPanelNew.java +++ b/plugins/ScreenPanelOld.java @@ -12,7 +12,7 @@ import ch.psi.utils.State; import ch.psi.utils.Chrono; import ch.psi.utils.swing.SwingUtils; import ch.psi.utils.swing.TextEditor; -import ch.psi.pshell.bs.PipelineServer; +import ch.psi.pshell.bs.Camtool; import ch.psi.pshell.bs.StreamValue; import ch.psi.pshell.device.DescStatsDouble; import ch.psi.pshell.device.Device; @@ -44,6 +44,7 @@ import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener; import ch.psi.utils.Arr; import ch.psi.utils.ArrayProperties; import ch.psi.utils.Convert; +import ch.psi.utils.TcpClient; import ch.psi.utils.swing.Editor.EditorDialog; import ch.psi.utils.swing.MainFrame; import ch.psi.utils.swing.StandardDialog; @@ -65,6 +66,7 @@ import java.awt.image.BufferedImage; import java.io.FileInputStream; import java.lang.reflect.Array; import java.lang.reflect.Field; +import java.net.ServerSocket; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -80,6 +82,7 @@ import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JMenuItem; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; @@ -97,13 +100,13 @@ import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; /** * */ -public class ScreenPanelNew extends Panel { +public class ScreenPanelOld extends Panel { final String CAMERA_DEVICE_NAME = "CurrentCamera"; - boolean useServerStats = true; + boolean useCamtoolStats = true; + String userOverlaysConfigFile; ColormapSource camera; - PipelineServer server; String cameraName; String cameraConfigJson; int polling = 1000; @@ -118,50 +121,51 @@ public class ScreenPanelNew extends Panel { Overlay[] profileOv; Overlay errorOverlay; boolean requestCameraListUpdate; - boolean goodRegion; + Integer localServerPort; + Process privateServer; String serverUrl; - String instanceName; + boolean goodRegion; - Double getServerDouble(String name) { - return (Double) Convert.toDouble(server.getValue(name)); + Double getCamtoolDouble(String name) { + return (Double) Convert.toDouble(((Camtool) camera).getValue(name)); } - double[] getServerDoubleArray(String name) { - return (double[]) Convert.toDouble(server.getValue(name)); + double[] getCamtoolDoubleArray(String name) { + return (double[]) Convert.toDouble(((Camtool) camera).getValue(name)); } - Double getServerDouble(String name, StreamValue cache) { + Double getCamtoolDouble(String name, StreamValue cache) { return (Double) Convert.toDouble(cache.__getitem__(name)); } - double[] getServerDoubleArray(String name, StreamValue cache) { + double[] getCamtoolDoubleArray(String name, StreamValue cache) { return (double[]) Convert.toDouble(cache.__getitem__(name)); } class ImageData { ImageData(){ - if (server!= null) { - StreamValue cache = server.getStream().take(); + if (camera instanceof Camtool) { + StreamValue cache = ((Camtool) camera).getStream().take(); String prefix = goodRegion ? "gr_" : ""; - x_fit_mean = getServerDouble(prefix + "x_fit_mean", cache); - y_fit_mean = getServerDouble(prefix + "y_fit_mean", cache); - x_fit_standard_deviation = getServerDouble(prefix + "x_fit_standard_deviation", cache); - y_fit_standard_deviation = getServerDouble(prefix + "y_fit_standard_deviation", cache); - x_fit_gauss_function = getServerDoubleArray(prefix +"x_fit_gauss_function", cache); - y_fit_gauss_function = getServerDoubleArray(prefix +"y_fit_gauss_function", cache); - x_profile = getServerDoubleArray("x_profile", cache); - y_profile = getServerDoubleArray("y_profile", cache); - x_center_of_mass = getServerDouble("x_center_of_mass", cache); - y_center_of_mass = getServerDouble("y_center_of_mass", cache); - x_rms = getServerDouble("x_rms", cache); - y_rms = getServerDouble("y_rms", cache); + x_fit_mean = getCamtoolDouble(prefix + "x_fit_mean", cache); + y_fit_mean = getCamtoolDouble(prefix + "y_fit_mean", cache); + x_fit_standard_deviation = getCamtoolDouble(prefix + "x_fit_standard_deviation", cache); + y_fit_standard_deviation = getCamtoolDouble(prefix + "y_fit_standard_deviation", cache); + x_fit_gauss_function = getCamtoolDoubleArray(prefix +"x_fit_gauss_function", cache); + y_fit_gauss_function = getCamtoolDoubleArray(prefix +"y_fit_gauss_function", cache); + x_profile = getCamtoolDoubleArray("x_profile", cache); + y_profile = getCamtoolDoubleArray("y_profile", cache); + x_center_of_mass = getCamtoolDouble("x_center_of_mass", cache); + y_center_of_mass = getCamtoolDouble("y_center_of_mass", cache); + x_rms = getCamtoolDouble("x_rms", cache); + y_rms = getCamtoolDouble("y_rms", cache); if (goodRegion){ double[] gX2 = new double[x_profile.length]; Arrays.fill(gX2, Double.NaN); try{ - double x = getServerDoubleArray("gr_x_axis", cache)[0]; + double x = getCamtoolDoubleArray("gr_x_axis", cache)[0]; System.arraycopy(x_fit_gauss_function, 0, gX2, (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageX(x): x), x_fit_gauss_function.length); } catch (Exception ex){ } @@ -169,7 +173,7 @@ public class ScreenPanelNew extends Panel { double[] gY2 = new double[y_profile.length]; Arrays.fill(gY2, Double.NaN); try{ - double y = getServerDoubleArray("gr_y_axis", cache)[0]; + double y = getCamtoolDoubleArray("gr_y_axis", cache)[0]; System.arraycopy(y_fit_gauss_function, 0, gY2, (int) ((renderer.getCalibration() != null) ? renderer.getCalibration().convertToImageY(y): y), y_fit_gauss_function.length); } catch (Exception ex){ } @@ -202,10 +206,10 @@ public class ScreenPanelNew extends Panel { final ArrayList imageBuffer = new ArrayList(); Frame currentFrame; - int imageBufferLenght = 1; + int imageBufferLenght = 0; Text imageBufferOverlay; - public ScreenPanelNew() { + public ScreenPanelOld() { initComponents(); spinnerThreshold.setVisible(false); btFixColormapRange.setVisible(false); @@ -214,7 +218,7 @@ public class ScreenPanelNew extends Panel { //spinnerMin.setVisible(false); labelMin.setVisible(false); //spinnerMax.setVisible(false); labelMax.setVisible(false); renderer.setPersistenceFile(Paths.get(getContext().getSetup().getContextPath(), "Renderer_Cameras.bin")); - setPersistedComponents(new Component[]{buttonServer, buttonDirect}); + setPersistedComponents(new Component[]{buttonCamtool, buttonDirect}); comboCameras.setEnabled(false); SwingUtils.setEnumCombo(comboColormap, Colormap.class); if (App.hasArgument("poll")) { @@ -248,12 +252,26 @@ public class ScreenPanelNew extends Panel { } } + if (App.hasArgument("priv_srv")) { + try { + try(ServerSocket s = new ServerSocket(0)){ + localServerPort = s.getLocalPort(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + if (App.hasArgument("srv_port")) { + localServerPort = Integer.valueOf(App.getArgumentValue("srv_port")); + } + if (App.hasArgument("srv_url")) { serverUrl = App.getArgumentValue("srv_url"); } if (App.hasArgument("calc")) { - useServerStats = false; + useCamtoolStats = false; } renderer.setProfileNormalized(true); @@ -269,10 +287,10 @@ public class ScreenPanelNew extends Panel { } }); - JMenuItem menuShowStreamData = new JMenuItem("Show Stream Data"); - menuShowStreamData.addActionListener((ActionEvent e) -> { + JMenuItem menuShowImageData = new JMenuItem("Show Image Data"); + menuShowImageData.addActionListener((ActionEvent e) -> { try { - showStreamData(); + showImageData(); } catch (Exception ex) { showException(ex); } @@ -291,7 +309,7 @@ public class ScreenPanelNew extends Panel { JMenuItem menuSetROI = new JMenuItem("Set ROI..."); menuSetROI.addActionListener((ActionEvent e) -> { renderer.abortSelection(); - if (server != null) { + if (camera instanceof Camtool) { final Overlays.Rect selection = new Overlays.Rect(renderer.getPenMovingOverlay()); renderer.addListener(new RendererListener() { @Override @@ -299,11 +317,11 @@ public class ScreenPanelNew extends Panel { try { renderer.setShowReticle(false); Rectangle roi = overlay.isFixed() ? renderer.toImageCoord(overlay.getBounds()) : overlay.getBounds(); - if (server.isRoiEnabled()) { - int[] cur = server.getRoi(); - server.setRoi(new int[]{roi.x + cur[0], roi.y + cur[1], roi.width, roi.height}); + if (((Camtool) camera).isRoiEnabled()) { + int[] cur = ((Camtool) camera).getRoi(); + ((Camtool) camera).setRoi(new int[]{roi.x + cur[0], roi.y + cur[1], roi.width, roi.height}); } else { - server.setRoi(new int[]{roi.x, roi.y, roi.width, roi.height}); + ((Camtool) camera).setRoi(new int[]{roi.x, roi.y, roi.width, roi.height}); } } catch (Exception ex) { } finally { @@ -324,17 +342,17 @@ public class ScreenPanelNew extends Panel { JMenuItem menuResetROI = new JMenuItem("Reset ROI"); menuResetROI.addActionListener((ActionEvent e) -> { renderer.abortSelection(); - if (server != null) { + if (camera instanceof Camtool) { try { renderer.setShowReticle(false); - server.resetRoi(); + ((Camtool) camera).resetRoi(); } catch (IOException ex) { showException(ex); } } }); - renderer.getPopupMenu().add(menuShowStreamData); + renderer.getPopupMenu().add(menuShowImageData); renderer.getPopupMenu().add(menuCalibrate); renderer.getPopupMenu().add(menuSaveStack); renderer.getPopupMenu().addSeparator(); @@ -343,10 +361,10 @@ public class ScreenPanelNew extends Panel { renderer.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - menuResetROI.setEnabled(server != null); - menuSetROI.setEnabled(server != null); - menuShowStreamData.setVisible(server != null); - menuCalibrate.setVisible(server != null); + menuResetROI.setEnabled(camera instanceof Camtool); + menuSetROI.setEnabled(camera instanceof Camtool); + menuShowImageData.setVisible(camera instanceof Camtool); + menuCalibrate.setVisible(camera instanceof Camtool); menuCalibrate.setEnabled((calibrationDialolg==null) || (!calibrationDialolg.isShowing()) ); } @@ -386,9 +404,43 @@ public class ScreenPanelNew extends Panel { super.onStart(); if (App.hasArgument("ct")) { boolean direct = App.getArgumentValue("ct").equals("0") || App.getArgumentValue("ct").equalsIgnoreCase("false"); - buttonServer.setSelected(!direct); + buttonCamtool.setSelected(!direct); buttonDirect.setSelected(direct); - } + } + if (App.hasArgument("priv_srv")) { + try { + System.out.println("Starting camtool server on port: " + localServerPort); + //Was creating sub-processes which cannot be destroyed. + //String cmd = "cam_server"; + //cmd = "source /opt/gfa/python\n" + cmd; + //privateServer = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd}); + String cmd = "/opt/gfa/python-3.5/2.4.1/bin/python /opt/gfa/python-3.5/latest/bin/cam_server"; + String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null); + cmd = cmd + " -p " + localServerPort + " -b " + configFolder; + privateServer = Runtime.getRuntime().exec(cmd); + //System.out.println("pid = " + Sys.getPid(privateServer)); + long start = System.currentTimeMillis(); + while (true){ + try (TcpClient c = new TcpClient("localhost", localServerPort)){ + try{ + c.connect(); + System.out.println("Connected to camtool server on port: " + localServerPort); + break; + } catch (Exception ex){ + } + } + Thread.sleep(10); + if ((System.currentTimeMillis() - start) > 5000){ + errorOverlay = new Text(renderer.getPenErrorText(), "Error connecting to server at port " + localServerPort , new Font("Verdana", Font.PLAIN, 12), new Point(20, 20)); + renderer.addOverlay(errorOverlay); + break; + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } @@ -399,7 +451,17 @@ public class ScreenPanelNew extends Panel { if (camera != null) { camera.close(); camera = null; - server = null; + } + if (privateServer!=null){ + System.out.println("Closing camtool server"); + //int pid = Sys.getPid(privateServer); + privateServer.destroyForcibly(); + //if (pid>0){ + // System.out.println("Killing pid = " + pid); + // Runtime.getRuntime().exec("kill " + pid); + // + //} + privateServer = null; } } catch (Exception ex) { ex.printStackTrace(); @@ -428,7 +490,7 @@ public class ScreenPanelNew extends Panel { ); } else { - usingServer = buttonServer.isSelected(); + usingCamtool = buttonCamtool.isSelected(); updateCameraList(); comboCameras.setEnabled(true); setComboCameraSelection(-1); @@ -447,39 +509,37 @@ public class ScreenPanelNew extends Panel { startTimer(1000); } - DefaultComboBoxModel getCameraList(boolean fromServer) throws Exception { + DefaultComboBoxModel getCameraListFromFolder() throws Exception { + ArrayList cameras = (ArrayList) getContext().getClassByName("SfCamera").getMethod("getCameras", new Class[]{}).invoke(null); DefaultComboBoxModel model = new DefaultComboBoxModel(); - if (fromServer){ - PipelineServer server = newServer(); - try { - server.initialize(); - List cameras = server.getCameras(); - Collections.sort(cameras); - for (String camera : cameras) { - model.addElement(camera); - } - } finally { - server.close(); - } - - } else { - ArrayList cameras = (ArrayList) getContext().getClassByName("SfCamera").getMethod("getCameras", new Class[]{}).invoke(null); - for (String cam:cameras) { - model.addElement(cam); + for (String cam:cameras) { + model.addElement(cam); + } + return model; + } + + DefaultComboBoxModel getCameraListFromCamtool() throws IOException, InterruptedException { + DefaultComboBoxModel model = new DefaultComboBoxModel(); + Camtool camtool = newCamtool(); + try { + camtool.initialize(); + List cameras = camtool.getCameras(); + Collections.sort(cameras); + for (String camera : cameras) { + model.addElement(camera); } + //model.addElement(Camtool.SIMULATION); + } finally { + camtool.close(); } return model; } - PipelineServer newServer() throws IOException{ - if (serverUrl!=null){ - System.out.println("Connecting to server: " + serverUrl); - server = new PipelineServer(CAMERA_DEVICE_NAME, serverUrl); - } else { - System.out.println("Connecting to server"); - server = new PipelineServer(CAMERA_DEVICE_NAME); - } - return server; + Camtool newCamtool(){ + if (serverUrl!=null){ + return new Camtool(CAMERA_DEVICE_NAME, serverUrl); + } + return (localServerPort != null) ? new Camtool(CAMERA_DEVICE_NAME, "localhost:"+localServerPort) : new Camtool(CAMERA_DEVICE_NAME); } boolean updatingCameraSelection; @@ -493,12 +553,12 @@ public class ScreenPanelNew extends Panel { } } - boolean usingServer; + boolean usingCamtool; void updateCameraList() { try { String selected = (String) comboCameras.getSelectedItem(); - DefaultComboBoxModel model = getCameraList(usingServer); + DefaultComboBoxModel model = usingCamtool ? getCameraListFromCamtool() : getCameraListFromFolder(); if (App.hasArgument("cam")) { String cam = App.getArgumentValue("cam"); if (model.getIndexOf(cam) < 0) { @@ -554,8 +614,8 @@ public class ScreenPanelNew extends Panel { Thread devicesInitTask; - void setCamera(String cameraName) throws IOException, InterruptedException { - System.out.println("Initializing"); + void setCamera(String cameraName) throws IOException, InterruptedException { + System.out.println("Setting camera: " + cameraName + " [" + (buttonCamtool.isSelected() ? "camtool" : "direct") + "]"); parseUserOverlays(); errorOverlay = null; @@ -570,15 +630,13 @@ public class ScreenPanelNew extends Panel { calibrationDialolg = null; } - boolean was_server = false; + boolean was_camtool = false; if (camera != null) { //camera.removeAllListeners(); - was_server = (server != null); + was_camtool = camera instanceof Camtool; camera.close(); camera = null; - server = null; } - instanceName = null; renderer.setDevice(null); renderer.setShowReticle(false); @@ -616,8 +674,6 @@ public class ScreenPanelNew extends Panel { return; } - System.out.println("Setting camera: " + cameraName + " [" + (buttonServer.isSelected() ? "server" : "direct") + "]"); - synchronized (imageBuffer) { currentFrame = null; imageBuffer.clear(); @@ -629,8 +685,8 @@ public class ScreenPanelNew extends Panel { Path configFile = Paths.get(configFolder, cameraName + ".json"); cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null; - if (buttonServer.isSelected()) { - camera = newServer(); + if (buttonCamtool.isSelected()) { + camera = newCamtool(); camera.getConfig().flipHorizontally = false; camera.getConfig().flipVertically = false; camera.getConfig().rotation = 0.0; @@ -645,22 +701,27 @@ public class ScreenPanelNew extends Panel { camera.initialize(); camera.assertInitialized(); System.out.println("Camera initialization OK"); - if (server != null) { - //server.start(cameraName, false); - String pipelineName = cameraName+"_sp"; - instanceName = cameraName+"_sp1"; - if (!server.getPipelines().contains(pipelineName)){ - System.out.println("Creating pipeline: " + pipelineName); - HashMap config = new HashMap<>(); - config.put("camera_name", cameraName); - //server.createFromConfig(config, pipelineName); - server.savePipelineConfig(pipelineName, config); - } - server.start(pipelineName, instanceName); - - updateServerControls(); + if (camera instanceof Camtool) { + //Managing no background exception. Can be done in a better way? +// if (changed) { + ((Camtool) camera).startPipeline(cameraName, null); + updateCamtoolControls(); +// } else { +// ((Camtool) camera).startPipeline(cameraName, null, checkBackground.isSelected(), null, null, null); +// } + // HashMap gr = null; + // if (goodRegion){ + // gr = new HashMap<>(); + // gr.put("threshold", spinnerGrThreshold.getValue()); + // gr.put("gfscale", spinnerGrScale.getValue()); + // } + // ((Camtool) camera).startPipeline(cameraName, null, checkBackground.isSelected(), null, checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null, gr); + //} + checkThreshold.setEnabled(true); - checkGoodRegion.setEnabled(true); + checkGoodRegion.setEnabled(true); + + ((Camtool) camera).startReceiver(); } else { checkThreshold.setSelected(false); checkGoodRegion.setSelected(false); @@ -702,7 +763,7 @@ public class ScreenPanelNew extends Panel { if (data != null) { synchronized (imageBuffer) { currentFrame =new Frame(data); - if (imageBufferLenght >= 1) { + if (imageBufferLenght > 1) { imageBuffer.add(currentFrame); if (imageBuffer.size() > imageBufferLenght) { imageBuffer.remove(0); @@ -718,7 +779,7 @@ public class ScreenPanelNew extends Panel { @Override public void onError(Object o, Exception ex) { - //System.err.println(ex); + ex.printStackTrace(); } }); @@ -726,7 +787,7 @@ public class ScreenPanelNew extends Panel { ex.printStackTrace(); showException(ex); renderer.clearOverlays(); - updateServerControls(); + updateCamtoolControls(); if (renderer.getDevice() == null) { //renderer.setZoom(1.0); //renderer.setMode(RendererMode.Zoom); @@ -882,21 +943,21 @@ public class ScreenPanelNew extends Panel { updatingColormap = false; } - boolean updatingServerControls; + boolean updatingCamtoolControls; - void updateServerControls() { - if (server != null) { - updatingServerControls = true; + void updateCamtoolControls() { + if ((camera != null) && (camera instanceof Camtool)) { + updatingCamtoolControls = true; try { - checkBackground.setSelected(server.getBackgroundSubtraction()); - Double threshold = (server.getThreshold()); + checkBackground.setSelected(((Camtool) camera).getBackgroundSubtraction()); + Double threshold = ((Camtool) camera).getThreshold(); checkThreshold.setSelected(threshold != null); spinnerThreshold.setValue((threshold == null) ? 0 : threshold); - Map gr = (server.getGoodRegion()); + Map gr = ((Camtool) camera).getGoodRegion(); checkGoodRegion.setSelected(gr != null); if (gr != null){ - spinnerGrThreshold.setValue(((Number)gr.get("threshold")).doubleValue()); - spinnerGrScale.setValue(((Number)gr.get("gfscale")).doubleValue()); + spinnerGrThreshold.setValue(gr.get("threshold")); + spinnerGrScale.setValue(gr.get("gfscale")); } } catch (Exception ex) { } @@ -904,13 +965,13 @@ public class ScreenPanelNew extends Panel { spinnerThreshold.setVisible(checkThreshold.isSelected()); spinnerGrThreshold.setVisible(goodRegion); labelGrThreshold.setVisible(spinnerGrThreshold.isVisible()); spinnerGrScale.setVisible(goodRegion); labelGrScale.setVisible(spinnerGrScale.isVisible()); - updatingServerControls = false; + updatingCamtoolControls = false; } } boolean isCameraStopped() { - if (server != null) { - if (!server.isStarted()) { + if ((camera != null) && (camera instanceof Camtool)) { + if (!((Camtool) camera).isPipelineStarted()) { return true; } } @@ -937,9 +998,9 @@ public class ScreenPanelNew extends Panel { try { ((Source) getDevice("image")).initialize(); } catch (IOException ex) { - Logger.getLogger(ScreenPanelNew.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(ScreenPanelOld.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { - Logger.getLogger(ScreenPanelNew.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(ScreenPanelOld.class.getName()).log(Level.SEVERE, null, ex); } } if (renderer.isPaused() != buttonPause.isSelected()) { @@ -953,7 +1014,7 @@ public class ScreenPanelNew extends Panel { buttonMarker.setSelected(false); } if (!renderer.isPaused() && (dataTableDialog!=null) && (dataTableDialog.isShowing())){ - updateStreamData(); + updateImageData(); } updateZoom(); updateColormap(); @@ -976,7 +1037,7 @@ public class ScreenPanelNew extends Panel { return currentFrame; } - Frame getFrame(Data data){ + Frame getFrame(Data data){ synchronized (imageBuffer) { for (Frame f : imageBuffer) { if (f.data == data) { @@ -1000,7 +1061,7 @@ public class ScreenPanelNew extends Panel { //Double xCom=null, yCom=null; if (data != null) { int profileSize = renderer.getProfileSize(); - if ((useServerStats) && (server != null)) { + if ((useCamtoolStats) && (camera instanceof Camtool)) { try { ImageData id = getFrame(data); @@ -1079,94 +1140,94 @@ public class ScreenPanelNew extends Panel { if (rangePlot <= 0) { return null; } - if (renderer.getCalibration() != null) { - try { - double[] sum = data.integrateVertically(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] x_egu = renderer.getCalibration().getAxisX(sum.length); - double[] comRms = getComRms(sum, x_egu); - xCom = comRms[0]; - xRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; + try { + double[] sum = data.integrateVertically(true); + double[] saux = new double[sum.length]; + int[] p = new int[sum.length]; + double[] x_egu = renderer.getCalibration().getAxisX(sum.length); + double[] comRms = getComRms(sum, x_egu); + xCom = comRms[0]; + xRms = comRms[1]; + int[] x = Arr.indexesInt(sum.length); + DescriptiveStatistics stats = new DescriptiveStatistics(sum); + double min = stats.getMin(); + for (int i = 0; i < sum.length; i++) { + saux[i] = sum[i] - min; + } + if (showFit){ + double[] gaussian = fitGaussian(saux, x); + if (gaussian != null) { + if ((gaussian[2] < sum.length * 0.45) + && (gaussian[2] > 2) + && (gaussian[0] > min * 0.03)) { + xNorm = gaussian[0]; + xMean = gaussian[1]; + xSigma = gaussian[2]; + double[] fit = getFitFunction(gaussian, x); + int[] y = new int[x.length]; + for (int i = 0; i < x.length; i++) { + y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize)); + } + vgaussian = new Overlays.Polyline(penFit, x, y); + } } - if (showFit){ - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - xNorm = gaussian[0]; - xMean = gaussian[1]; - xSigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize)); - } - vgaussian = new Overlays.Polyline(penFit, x, y); + } + if (showProfile){ + for (int i = 0; i < x.length; i++) { + p[i] = (int) (height - 1 - (((sum[i] / height- minPlot) / rangePlot) * profileSize)); + } + vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + + try { + double[] sum = data.integrateHorizontally(true); + double[] saux = new double[sum.length]; + int[] p = new int[sum.length]; + double[] y_egu = renderer.getCalibration().getAxisY(sum.length); + double[] comRms = getComRms(sum, y_egu); + yCom = comRms[0]; + yRms = comRms[1]; + int[] x = Arr.indexesInt(sum.length); + DescriptiveStatistics stats = new DescriptiveStatistics(sum); + double min = stats.getMin(); + for (int i = 0; i < sum.length; i++) { + saux[i] = sum[i] - min; + } + + if (showFit){ + double[] gaussian = fitGaussian(saux, x); + if (gaussian != null) { + //Only aknowledge beam fully inside the image and peak over 3% of min + if ((gaussian[2] < sum.length * 0.45) + && (gaussian[2] > 2) + && (gaussian[0] > min * 0.03)) { + yNorm = gaussian[0]; + yMean = gaussian[1]; + ySigma = gaussian[2]; + double[] fit = getFitFunction(gaussian, x); + + int[] y = new int[x.length]; + for (int i = 0; i < x.length; i++) { + y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize); } - } + hgaussian = new Overlays.Polyline(penFit, y, x); + } } - if (showProfile){ - for (int i = 0; i < x.length; i++) { - p[i] = (int) (height - 1 - (((sum[i] / height- minPlot) / rangePlot) * profileSize)); - } - vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); + } + if (showProfile){ + for (int i = 0; i < x.length; i++) { + p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize); } - } catch (Exception ex) { - ex.printStackTrace(); + hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x); } - try { - double[] sum = data.integrateHorizontally(true); - double[] saux = new double[sum.length]; - int[] p = new int[sum.length]; - double[] y_egu = renderer.getCalibration().getAxisY(sum.length); - double[] comRms = getComRms(sum, y_egu); - yCom = comRms[0]; - yRms = comRms[1]; - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i = 0; i < sum.length; i++) { - saux[i] = sum[i] - min; - } - - if (showFit){ - double[] gaussian = fitGaussian(saux, x); - if (gaussian != null) { - //Only aknowledge beam fully inside the image and peak over 3% of min - if ((gaussian[2] < sum.length * 0.45) - && (gaussian[2] > 2) - && (gaussian[0] > min * 0.03)) { - yNorm = gaussian[0]; - yMean = gaussian[1]; - ySigma = gaussian[2]; - double[] fit = getFitFunction(gaussian, x); - - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize); - } - hgaussian = new Overlays.Polyline(penFit, y, x); - } - } - } - if (showProfile){ - for (int i = 0; i < x.length; i++) { - p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize); - } - hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } + } catch (Exception ex) { + ex.printStackTrace(); + } + if (renderer.getCalibration() != null) { if (xSigma != null) { xSigma *= renderer.getCalibration().getScaleX(); } @@ -1215,7 +1276,7 @@ public class ScreenPanelNew extends Panel { if (goodRegion){ try{ - double[] x = getServerDoubleArray("gr_x_axis"); double[] y = getServerDoubleArray("gr_y_axis"); + double[] x = getCamtoolDoubleArray("gr_x_axis"); double[] y = getCamtoolDoubleArray("gr_y_axis"); double x1 = x[0]; double x2 = x[x.length-1]; double y1 = y[0]; double y2 = y[y.length-1]; Overlays.Rect goodRegionOv = new Overlays.Rect(new Pen(penFit.getColor(), 0, Pen.LineStyle.dotted)); goodRegionOv.setCalibration(renderer.getCalibration()); @@ -1314,7 +1375,7 @@ public class ScreenPanelNew extends Panel { Overlay[] getUserOverlays(Data data) { ArrayList ret = new ArrayList<>(); - if (server != null) { + if (camera instanceof Camtool) { for (UserOverlay uo : userOverlayConfig) { try { Overlay ov = uo.obj; @@ -1322,8 +1383,8 @@ public class ScreenPanelNew extends Panel { ov.setCalibration(renderer.getCalibration()); boolean valid = false; if (ov instanceof Overlays.Polyline) { - double[] x = (uo.channels[0].equals("null")) ? null : getServerDoubleArray(uo.channels[0]); - double[] y = (uo.channels[1].equals("null")) ? null : getServerDoubleArray(uo.channels[1]); + double[] x = (uo.channels[0].equals("null")) ? null : getCamtoolDoubleArray(uo.channels[0]); + double[] y = (uo.channels[1].equals("null")) ? null : getCamtoolDoubleArray(uo.channels[1]); if ((x != null) || (y !=null)) { if (x == null) { x = (renderer.getCalibration() == null) ? Arr.indexesDouble(y.length) : renderer.getCalibration().getAxisX(y.length); @@ -1335,12 +1396,12 @@ public class ScreenPanelNew extends Panel { valid = true; } } else { - Double x = getServerDouble(uo.channels[0]); Double y = getServerDouble(uo.channels[1]); + Double x = getCamtoolDouble(uo.channels[0]); Double y = getCamtoolDouble(uo.channels[1]); if ((x != null) && (y !=null)) { PointDouble position = new PointDouble(x,y); ov.setAbsolutePosition(position); if (!(ov instanceof Overlays.Crosshairs)) { - Double x2 = getServerDouble(uo.channels[2]); Double y2 = getServerDouble(uo.channels[3]); + Double x2 = getCamtoolDouble(uo.channels[2]); Double y2 = getCamtoolDouble(uo.channels[3]); if ((x != null) && (y !=null)) { DimensionDouble size = new DimensionDouble(x2 - position.x, y2 - position.y); ov.setAbsoluteSize(size); @@ -1355,7 +1416,7 @@ public class ScreenPanelNew extends Panel { ret.add(ov); } } catch (Exception ex) { - //ex.printStackTrace(); + ex.printStackTrace(); } } } @@ -1530,9 +1591,9 @@ public class ScreenPanelNew extends Panel { getContext().getDataManager().setAttribute("/", "Calibration", cal == null ? new double[]{1,1,0,0} : new double[]{cal.getScaleX(), cal.getScaleY(), cal.getOffsetX(), cal.getOffsetY()}); getContext().getDataManager().setAttribute(path, "Timestamp", Chrono.getTimeStr(frame.data.getTimestamp(), "HH:mm:ss.SSS")); - if (server != null){ + if (camera instanceof Camtool){ try{ - getContext().getDataManager().setAttribute("/", "ROI", server.getRoi()); + getContext().getDataManager().setAttribute("/", "ROI", ((Camtool) camera).getRoi()); } catch (Exception ex){ getContext().getDataManager().setAttribute("/", "ROI", new int[]{0,0,-1,-1}); } @@ -1543,7 +1604,7 @@ public class ScreenPanelNew extends Panel { } } for (String name : new String[]{"x_axis", "y_axis", "gr_x_axis", "gr_y_axis"}){ - double[] val = getServerDoubleArray(name); + double[] val = getCamtoolDoubleArray(name); getContext().getDataManager().setAttribute("/", "GoodRegion", goodRegion); if (val!=null){ getContext().getDataManager().setAttribute("/", name, val); @@ -1599,7 +1660,7 @@ public class ScreenPanelNew extends Panel { if (SwingUtils.showOption(getTopLevel(), "Success", panel, OptionType.OkCancel) == OptionResult.Yes){ StringBuilder message = new StringBuilder(); message.append("Camera: ").append(cameraName).append(" ("). - append((server!=null) ? "server" : "direct").append(")").append("\n"); + append((camera instanceof Camtool) ? "camtool" : "direct").append(")").append("\n"); message.append("Screen: ").append(String.valueOf(valueScreen.getLabel().getText())).append("\n"); message.append("Filter: ").append(String.valueOf(valueFilter.getLabel().getText())).append("\n"); message.append("Data file: ").append(getContext().getExecutionPars().getPath()).append("\n"); @@ -1637,10 +1698,9 @@ public class ScreenPanelNew extends Panel { StandardDialog calibrationDialolg; void calibrate() throws Exception{ - if (server != null){ - server.resetRoi(); - calibrationDialolg = (StandardDialog) getContext().getClassByName("CameraCalibrationDialog").getConstructors()[0].newInstance(new Object[]{getTopLevel(), server.getCurrentCamera(), renderer}); - SwingUtils.centerComponent(getTopLevel(), calibrationDialolg); + if (camera instanceof Camtool){ + calibrationDialolg = (StandardDialog) getContext().getClassByName("CameraConfigDialog").getConstructors()[0].newInstance(new Object[]{getTopLevel(), camera, renderer}); + SwingUtils.centerComponent(this, calibrationDialolg); calibrationDialolg.setVisible(true); calibrationDialolg.setListener(new StandardDialogListener() { @Override @@ -1649,7 +1709,7 @@ public class ScreenPanelNew extends Panel { @Override public void onWindowClosed(StandardDialog dlg, boolean accepted) { if (accepted){ - //comboCamerasActionPerformed(null); + comboCamerasActionPerformed(null); } } }); @@ -1658,9 +1718,9 @@ public class ScreenPanelNew extends Panel { StandardDialog dataTableDialog; DefaultTableModel dataTableModel; - void showStreamData(){ + void showImageData(){ dataTableModel = null; - if (server!=null){ + if (camera instanceof Camtool){ if ((dataTableDialog!=null) && (dataTableDialog.isShowing())){ SwingUtils.centerComponent(getTopLevel(), dataTableDialog); @@ -1677,11 +1737,10 @@ public class ScreenPanelNew extends Panel { return false; } }; - updateStreamData(); - StreamValue val = server.getStream().take(); + updateImageData(); + StreamValue val = ((Camtool)camera).getStream().take(); JTable dataTable = new JTable(dataTableModel); dataTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); - dataTable.setCellSelectionEnabled(true); dataTable.getTableHeader().setReorderingAllowed(false); dataTable.getTableHeader().setResizingAllowed(true); dataTableDialog = new StandardDialog(getTopLevel(), "Image Data", false); @@ -1702,31 +1761,19 @@ public class ScreenPanelNew extends Panel { } } - void updateStreamData(){ - if ((dataTableModel!=null)&&(server != null)){ - StreamValue value = server.getValue(); - - List ids = (value==null) ? new ArrayList<>(): new ArrayList(value.getIdentifiers()); - if (ids.size()+2 != dataTableModel.getRowCount()){ - dataTableModel.setNumRows(0); - try { - dataTableModel.addRow(new Object[]{"Locator", server.getUrl() + "/" + ((value==null) ? instanceName : server.getCurrentInstance())}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Locator", ex.getMessage()}); - } - try { - dataTableModel.addRow(new Object[]{"Stream", server.getStreamAddress()}); - } catch (Exception ex) { - dataTableModel.addRow(new Object[]{"Stream", ex.getMessage()}); - } + void updateImageData(){ + if ((dataTableModel!=null)&&(camera instanceof Camtool)){ + List ids = new ArrayList(((Camtool)camera).getValue().getIdentifiers()); + if (ids.size() != dataTableModel.getRowCount()){ + dataTableModel.setNumRows(0); Collections.sort(ids); for (String id : ids){ dataTableModel.addRow(new Object[]{id, ""}); } } - for (int i = 2 ; i< dataTableModel.getRowCount(); i++){ + for (int i = 0 ; i< dataTableModel.getRowCount(); i++){ String id = String.valueOf(dataTableModel.getValueAt(i, 0)); - Object obj = server.getValue(id); + Object obj = ((Camtool)camera).getValue(id); if (obj!=null){ if (obj.getClass().isArray()){ obj = obj.getClass().getComponentType().getSimpleName() + "[" + Array.getLength(obj) + "]"; @@ -1791,7 +1838,7 @@ public class ScreenPanelNew extends Panel { labelMax = new javax.swing.JLabel(); btFixColormapRange = new javax.swing.JButton(); jPanel5 = new javax.swing.JPanel(); - buttonServer = new javax.swing.JRadioButton(); + buttonCamtool = new javax.swing.JRadioButton(); buttonDirect = new javax.swing.JRadioButton(); panelScreen = new javax.swing.JPanel(); valueScreen = new ch.psi.pshell.swing.DeviceValuePanel(); @@ -1912,7 +1959,6 @@ public class ScreenPanelNew extends Panel { jLabel2.setText("State:"); - comboCameras.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N comboCameras.setMaximumRowCount(30); comboCameras.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -2228,12 +2274,12 @@ public class ScreenPanelNew extends Panel { jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Source")); - buttonGroup4.add(buttonServer); - buttonServer.setSelected(true); - buttonServer.setText("Server"); - buttonServer.addActionListener(new java.awt.event.ActionListener() { + buttonGroup4.add(buttonCamtool); + buttonCamtool.setSelected(true); + buttonCamtool.setText("Camtool"); + buttonCamtool.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonServerActionPerformed(evt); + buttonCamtoolActionPerformed(evt); } }); @@ -2251,7 +2297,7 @@ public class ScreenPanelNew extends Panel { jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup() .addContainerGap() - .addComponent(buttonServer) + .addComponent(buttonCamtool) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonDirect) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) @@ -2261,7 +2307,7 @@ public class ScreenPanelNew extends Panel { .addGroup(jPanel5Layout.createSequentialGroup() .addGap(4, 4, 4) .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonServer) + .addComponent(buttonCamtool) .addComponent(buttonDirect)) .addContainerGap()) ); @@ -2493,7 +2539,7 @@ public class ScreenPanelNew extends Panel { throw new Exception("Invalid state"); } comboCameras.setEnabled(false); - buttonServer.setEnabled(false); + buttonCamtool.setEnabled(false); buttonDirect.setEnabled(false); final String cameraName = (String) comboCameras.getSelectedItem(); new Thread(new Runnable() { @@ -2514,7 +2560,7 @@ public class ScreenPanelNew extends Panel { } finally { updateStop(); comboCameras.setEnabled(true); - buttonServer.setEnabled(true); + buttonCamtool.setEnabled(true); buttonDirect.setEnabled(true); } } @@ -2535,7 +2581,7 @@ public class ScreenPanelNew extends Panel { EditorDialog dlg = editor.getDialog(getTopLevel(), false); dlg.setSize(480, 640); dlg.setVisible(true); - SwingUtils.centerComponent(getTopLevel(), dlg); + SwingUtils.centerComponent(this, dlg); } } catch (Exception ex) { showException(ex); @@ -2563,14 +2609,14 @@ public class ScreenPanelNew extends Panel { imageBuffer.clear(); renderer.resume(); } - pauseSelection.setVisible(buttonPause.isSelected() && (imageBuffer.size() > 1)); + pauseSelection.setVisible(buttonPause.isSelected() && (imageBuffer.size() > 0)); if (pauseSelection.isVisible()) { renderer.addOverlay(imageBufferOverlay); pauseSelection.setMaxValue(imageBuffer.size()); pauseSelection.setValue(imageBuffer.size());; } } - updateStreamData(); + updateImageData(); } } catch (Exception ex) { ex.printStackTrace(); @@ -2622,19 +2668,36 @@ public class ScreenPanelNew extends Panel { if (camera != null) { if (SwingUtils.showOption(getTopLevel(), "Background", "Do you want to capture background now?", OptionType.YesNo) == OptionResult.Yes) { boolean laserOn = getLaserState(); - if (laserOn) { - setLaserState(false); - } - try { - System.out.println("Grabbing background for: " + cameraName); - if (server!=null){ - server.captureBackground(cameraName, 5); - } else { - camera.captureBackground(5, 0); + if (camera instanceof Camtool){ + boolean rendering = (!camera.isClosed()); + if (rendering) { + camera.close(); } - } finally { if (laserOn) { - setLaserState(true); + setLaserState(false); + } + try { + System.out.println("Grabbing background for: " + cameraName); + ((Camtool) camera).grabBackground(cameraName, 5); + } finally { + if (laserOn) { + setLaserState(true); + } + if (rendering) { + comboCamerasActionPerformed(null); + } + updateStop(); + } + } else { + if (laserOn) { + setLaserState(false); + } + try { + camera.captureBackground(5, 0); + } finally { + if (laserOn) { + setLaserState(true); + } } } SwingUtils.showMessage(getTopLevel(), "Success", "Success capturing background", 5000); @@ -2725,17 +2788,17 @@ public class ScreenPanelNew extends Panel { centralizeRenderer(); }//GEN-LAST:event_buttonZoom05ActionPerformed - private void buttonServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonServerActionPerformed - if (!usingServer) { - usingServer = true; + private void buttonCamtoolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCamtoolActionPerformed + if (!usingCamtool) { + usingCamtool = true; requestCameraListUpdate = true; } comboCamerasActionPerformed(null); - }//GEN-LAST:event_buttonServerActionPerformed + }//GEN-LAST:event_buttonCamtoolActionPerformed private void buttonDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectActionPerformed - if (usingServer) { - usingServer = false; + if (usingCamtool) { + usingCamtool = false; requestCameraListUpdate = true; } comboCamerasActionPerformed(null); @@ -2812,31 +2875,32 @@ public class ScreenPanelNew extends Panel { }//GEN-LAST:event_buttonZoom2ActionPerformed private void spinnerThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerThresholdonChange - if (!updatingServerControls) { + if (!updatingCamtoolControls) { try { - if ((server!=null) && (server.isStarted())) { - server.setThreshold((Double) spinnerThreshold.getValue()); + if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { + ((Camtool) camera).setThreshold((Double) spinnerThreshold.getValue()); } } catch (Exception ex) { showException(ex); - updateServerControls(); + updateCamtoolControls(); } } }//GEN-LAST:event_spinnerThresholdonChange private void checkBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBackgroundActionPerformed - if (server!=null){ - if (!updatingServerControls) { + if (camera instanceof Camtool){ + if (!updatingCamtoolControls) { try { - if (server.isStarted()) { - server.setBackgroundSubtraction(checkBackground.isSelected()); + if (((Camtool) camera).isPipelineStarted()) { + ((Camtool) camera).setBackgroundSubtraction(checkBackground.isSelected()); } } catch (Exception ex) { showException(ex); - updateServerControls(); - updatingServerControls = true; + updateCamtoolControls(); + //There is a bug in camtool: it will flag bg extraction as on: + updatingCamtoolControls = true; checkBackground.setSelected(false); - updatingServerControls = false; + updatingCamtoolControls = false; } } @@ -2846,15 +2910,15 @@ public class ScreenPanelNew extends Panel { }//GEN-LAST:event_checkBackgroundActionPerformed private void checkThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkThresholdActionPerformed - if (!updatingServerControls) { + if (!updatingCamtoolControls) { try { - if ((server!=null) && (server.isStarted())) { + if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { spinnerThreshold.setVisible(checkThreshold.isSelected()); - server.setThreshold(checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null); + ((Camtool) camera).setThreshold(checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null); } } catch (Exception ex) { showException(ex); - updateServerControls(); + updateCamtoolControls(); } } }//GEN-LAST:event_checkThresholdActionPerformed @@ -2892,35 +2956,34 @@ public class ScreenPanelNew extends Panel { }//GEN-LAST:event_buttonProfileActionPerformed private void checkGoodRegionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkGoodRegionActionPerformed - if (!updatingServerControls) { + if (!updatingCamtoolControls) { try { - if ((server!=null) && (server.isStarted())) { + if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { spinnerGrScale.setVisible(checkGoodRegion.isSelected()); labelGrScale.setVisible(spinnerGrScale.isVisible()); spinnerGrThreshold.setVisible(checkGoodRegion.isSelected()); labelGrThreshold.setVisible(spinnerGrThreshold.isVisible()); if (checkGoodRegion.isSelected()){ - server.setGoodRegion( ((Number)spinnerGrThreshold.getValue()).doubleValue(), ((Number)spinnerGrScale.getValue()).doubleValue() ); + ((Camtool) camera).setGoodRegion( (Double)spinnerGrThreshold.getValue(), (Double)spinnerGrScale.getValue() ); } else { - server.setGoodRegion(null); + ((Camtool) camera).setGoodRegion(null); } goodRegion = checkGoodRegion.isSelected(); } } catch (Exception ex) { showException(ex); - ex.printStackTrace(); - updateServerControls(); + updateCamtoolControls(); } } }//GEN-LAST:event_checkGoodRegionActionPerformed private void spinnerGrThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerGrThresholdonChange - if (!updatingServerControls) { + if (!updatingCamtoolControls) { try { - if ((server != null) && (server.isStarted())) { - server.setGoodRegion( (Double)spinnerGrThreshold.getValue(), (Double)spinnerGrScale.getValue() ); + if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) { + ((Camtool) camera).setGoodRegion( (Double)spinnerGrThreshold.getValue(), (Double)spinnerGrScale.getValue() ); } } catch (Exception ex) { showException(ex); - updateServerControls(); + updateCamtoolControls(); } } }//GEN-LAST:event_spinnerGrThresholdonChange @@ -2944,6 +3007,7 @@ public class ScreenPanelNew extends Panel { private javax.swing.JButton btFixColormapRange; private javax.swing.JButton buttonArgs; private javax.swing.JRadioButton buttonAutomatic; + private javax.swing.JRadioButton buttonCamtool; private javax.swing.JButton buttonConfig; private javax.swing.JRadioButton buttonDirect; private javax.swing.JToggleButton buttonFit; @@ -2959,7 +3023,6 @@ public class ScreenPanelNew extends Panel { private javax.swing.JToggleButton buttonProfile; private javax.swing.JToggleButton buttonReticle; private javax.swing.JToggleButton buttonSave; - private javax.swing.JRadioButton buttonServer; private javax.swing.JButton buttonStop; private javax.swing.JRadioButton buttonZoom025; private javax.swing.JRadioButton buttonZoom05;