Search in sources :

Example 1 with IJDataList

use of org.vcell.imagej.helper.VCellHelper.IJDataList in project vcell by virtualcell.

the class NikitaTest method run.

@Override
public void run() {
    try {
        // Find the port that a separately running VCell client is listening on
        System.out.println("vcell service port=" + vcellHelper.findVCellApiServerPort());
    } catch (Exception e) {
        uiService.showDialog("Activate VCell client ImageJ service\nTools->'Start Fiji (ImageJ) service'\n" + e.getMessage(), "Couldn't contact VCell client", MessageType.ERROR_MESSAGE);
        return;
    }
    String theCacheKey = null;
    VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.valueOf(modelType), vCellUser, vCellModel, application, simulation, null, null);
    try {
        ArrayList<VCellModelSearchResults> vcmsr = vcellHelper.getSearchedModelSimCacheKey(false, vcms, null);
        if (vcmsr.size() == 0) {
            throw new Exception("No Results for search found");
        }
        theCacheKey = vcmsr.get(0).getCacheKey();
        System.out.println("theCacheKey=" + theCacheKey);
    } catch (Exception e) {
        uiService.showDialog(modelType + ", " + vCellUser + ", " + vCellModel + ", " + application + ", " + simulation + ", null, null\n" + e.getMessage(), "Search failed", MessageType.ERROR_MESSAGE);
        return;
    }
    IJDataList timePointData = null;
    // there is 1 timePoint
    int[] timePointIndexes = new int[1];
    int theTimePointIndex = 0;
    timePointIndexes[theTimePointIndex] = timePoint;
    try {
        timePointData = vcellHelper.getTimePointData(theCacheKey, variable, VARTYPE_POSTPROC.NotPostProcess, timePointIndexes, 0);
    } catch (Exception e) {
        uiService.showDialog(modelType + ", " + vCellUser + ", " + vCellModel + ", " + application + ", " + simulation + ", " + variable + ", " + timePoint + "\n" + e.getMessage(), "Get Data failed", MessageType.ERROR_MESSAGE);
        return;
    }
    double[] theTimePointData = timePointData.ijData[theTimePointIndex].getDoubleData();
    Range xAxisRange = null;
    int[] dataIndexes = new int[endIndex - startIndex + 1];
    // This is just for JFreeChart
    double[] dataIndexesDouble = new double[dataIndexes.length];
    for (int i = startIndex; i <= endIndex; i++) {
        dataIndexes[i - startIndex] = i;
        dataIndexesDouble[i - startIndex] = i;
        xAxisRange = Range.expandToInclude(xAxisRange, dataIndexesDouble[i - startIndex]);
    }
    Range yAxisRange = null;
    double[] chartTheseDataPoints = new double[dataIndexes.length];
    for (int i = 0; i < dataIndexes.length; i++) {
        chartTheseDataPoints[i] = theTimePointData[dataIndexes[i]];
        yAxisRange = Range.expandToInclude(yAxisRange, chartTheseDataPoints[i]);
    // ijTimeSeriesJobResults.data[0/*index of "r"*/][i+1/*data, skip 0 because it holds copy of times*/][0/*0 always because we had only 1 timePoint=22.0*/]
    }
    try {
        // LINE plot of data at 1 timePoint along defined indexes
        // Create JFreechart x,y axis arrays for plotting x=data indexes, y=dataPoint values
        double[][] data = new double[][] { dataIndexesDouble, chartTheseDataPoints };
        String title = "LINE Plot at time=" + timePoint;
        String xAxisLabel = "distance";
        String yAxisLabel = "val";
        DefaultXYDataset xyDataset = new DefaultXYDataset();
        xyDataset.addSeries("data1", data);
        JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, xyDataset, PlotOrientation.VERTICAL, false, false, false);
        // Y
        chart.getXYPlot().getDomainAxis().setRange(xAxisRange);
        // X
        chart.getXYPlot().getRangeAxis().setRange(yAxisRange);
        ChartPanel chartPanel = new ChartPanel(chart);
        JFrame frame = new JFrame("Chart");
        // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(chartPanel);
        // Display the window.
        frame.pack();
        frame.setVisible(true);
    } catch (Exception e) {
        uiService.showDialog("LINE PlotGet Data failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
    IJTimeSeriesJobResults timeSeries = null;
    try {
        IJVarInfos simulationInfo = vcellHelper.getSimulationInfo(theCacheKey);
        double[] times = simulationInfo.getTimes();
        timeSeries = vcellHelper.getTimeSeries(new String[] { variable }, new int[] { dataIndexes[0] }, times[0], 1, times[times.length - 1], false, false, 0, Integer.parseInt(theCacheKey));
    } catch (Exception e) {
        uiService.showDialog("TIME Plot Get Data failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
    try {
        // TIME plot of data at 1 timePoint along defined indexes
        // Create JFreechart x,y axis arrays for plotting x=data indexes, y=dataPoint values
        double[][] data = new double[][] { timeSeries.data[0][0], timeSeries.data[0][1] };
        String title = "TIME Plot at dataIndex=" + dataIndexes[0];
        String xAxisLabel = "time";
        String yAxisLabel = "val";
        DefaultXYDataset xyDataset = new DefaultXYDataset();
        xyDataset.addSeries("data1", data);
        JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, xyDataset, PlotOrientation.VERTICAL, false, false, false);
        // chart.getXYPlot().getDomainAxis().setRange(yAxisRange);//Y
        // chart.getXYPlot().getRangeAxis().setRange(xAxisRange);//X
        ChartPanel chartPanel = new ChartPanel(chart);
        JFrame frame = new JFrame("Chart");
        // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(chartPanel);
        // Display the window.
        frame.pack();
        frame.setVisible(true);
    } catch (Exception e) {
        uiService.showDialog("TIME Plot show chart failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) IJVarInfos(org.vcell.imagej.helper.VCellHelper.IJVarInfos) DefaultXYDataset(org.jfree.data.xy.DefaultXYDataset) VCellModelSearchResults(org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults) Range(org.jfree.data.Range) VCellHelper(org.vcell.imagej.helper.VCellHelper) JFreeChart(org.jfree.chart.JFreeChart) JFrame(javax.swing.JFrame) IJDataList(org.vcell.imagej.helper.VCellHelper.IJDataList) IJTimeSeriesJobResults(org.vcell.imagej.helper.VCellHelper.IJTimeSeriesJobResults)

Example 2 with IJDataList

use of org.vcell.imagej.helper.VCellHelper.IJDataList in project vcell by virtualcell.

the class VCellPlugin_Minimal method run.

// private Hashtable<String,Thread> threadHash = new Hashtable<String,Thread>();
// private void startJProgressThread0(String lastName,String newName) {
// if(lastName != null && threadHash.get(lastName) != null) {
// threadHash.get(lastName).interrupt();
// while(threadHash.get(lastName) != null) {
// try {
// Thread.sleep(50);
// } catch (InterruptedException e) {
// e.printStackTrace();
// break;
// }
// }
// }
// if(newName == null) {
// return;
// }
// final Thread progressThread = new Thread(new Runnable(){
// @Override
// public void run() {
// final int[] progress = new int[] {1};
// while(progressDialog.isVisible()) {
// if(Thread.currentThread().isInterrupted()) {
// break;
// }
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// jProgressBar.setValue(progress[0]);
// }});
// progress[0]++;
// try {
// Thread.sleep(500);
// } catch (InterruptedException e) {
// break;
// }
// }
// threadHash.remove(Thread.currentThread().getName());
// }});
// threadHash.put(newName, progressThread);
// progressThread.setName(newName);
// progressThread.setDaemon(true);//So not block JVM exit
// progressThread.start();
// }
// public void showAndZoom(String displayName,Object thingToDisplay,double zoomFactor) throws Exception{
// final ImageDisplayService ids = getContext().getService(ImageDisplayService.class);
// final DisplayService ds = getContext().getService(DisplayService.class);
// new Thread(new Runnable() {
// 
// @Override
// public void run() {
// // TODO Auto-generated method stub
// uiService.show(displayName,thingToDisplay);
// //Find display and set zoom, resize window
// List<ImageDisplay> knownImageDisplays = ids.getImageDisplays();
// boolean bvisible = false;
// while (!bvisible) {
// for (ImageDisplay imageDisplay : knownImageDisplays) {
// if (imageDisplay.getName().equals(displayName)) {
// if (imageDisplay.isVisible(imageDisplay.getActiveView())) {
// bvisible = true;
// break;
// }
// }
// }
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// //		    	int vw = ij.imageDisplay().getActiveImageDisplay().getCanvas().getViewportWidth();
// //		    	int vh = ij.imageDisplay().getActiveImageDisplay().getCanvas().getViewportHeight();
// //		    	System.out.println(" -----byname="+ij.display().getDisplay(displayName));
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// try {
// ids.getActiveImageDisplay().getCanvas().setZoom(zoomFactor);
// if(ds.getDisplay(displayName) != null && uiService.getDisplayViewer(ds.getDisplay(displayName)) instanceof JFrame) {
// double vw = ids.getActiveImageDisplay().dimension(ids.getActiveImageDisplay().dimensionIndex(Axes.X))*zoomFactor;
// double vh = ids.getActiveImageDisplay().dimension(ids.getActiveImageDisplay().dimensionIndex(Axes.Y))*zoomFactor;
// ((JFrame)uiService.getDisplayViewer(ds.getDisplay(displayName)).getWindow()).setSize(new Dimension((int)vw+50, (int)vh+150));
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// 
// //		    	ij.ui().getDisplayViewer(ij.display().getDisplay(displayName)).getPanel().redoLayout();
// //		    	List<Display<?>> displays = ij.display().getDisplays();
// //		    	for (Display<?> display : displays) {
// //					System.out.println(display+" -----byname="+ij.display().getDisplay(displayName));
// //				}
// 
// }
// }).start();
// 
// }
@Override
public void run() {
    try {
        if (vcellSelection != null && vcellSelection.exception != null) {
            if (!vcellSelection.exception.getMessage().equals(MyPreProcessor.CANCELLED)) {
                uiService.showDialog("Model search failed\n" + vcellSelection.exception.getClass().getName() + "\n" + vcellSelection.exception.getMessage(), MessageType.ERROR_MESSAGE);
            }
            return;
        }
        if (vcellSelection == null || vcellSelection.theCacheKey == null) {
            return;
        }
        // Create ImageJ datasets and display separate hyperstack for each variable
        for (int varIndex = 0; varIndex < vcellSelection.varName.length; varIndex++) {
            int[] time = vcellSelection.timePointIndexes;
            displayProgressBar(true, "loading Image...", "VCell Model Loader", (varIndex + 1) * 100 / vcellSelection.varName.length, uiService);
            final IJDataList tpd = vcellHelper.getTimePointData(vcellSelection.theCacheKey, vcellSelection.varName[varIndex], VCellHelper.VARTYPE_POSTPROC.NotPostProcess, time, 0);
            BasicStackDimensions bsd = tpd.ijData[0].stackInfo;
            double[] data = new double[bsd.getTotalSize() * tpd.ijData.length];
            double min = Double.MAX_VALUE;
            double max = Double.MIN_VALUE;
            ArrayImg<DoubleType, DoubleArray> testimg = ArrayImgs.doubles(data, bsd.xsize, bsd.ysize, bsd.zsize, tpd.ijData.length);
            for (int i = 0; i < tpd.ijData.length; i++) {
                System.arraycopy(tpd.ijData[i].getDoubleData(), 0, data, i * bsd.getTotalSize(), bsd.getTotalSize());
                // calc minmax only for pixel values that are in domain of this variable
                for (int j = 0; j < tpd.ijData[i].getDoubleData().length; j++) {
                    if (tpd.ijData[i].getDoubleData()[j] != tpd.ijData[i].notInDomainValue) {
                        min = Math.min(min, tpd.ijData[i].getDoubleData()[j]);
                        max = Math.max(max, tpd.ijData[i].getDoubleData()[j]);
                    }
                }
            }
            ImgPlus<DoubleType> imgPlus = new ImgPlus<DoubleType>(testimg);
            imgPlus.setChannelMinimum(0, min);
            imgPlus.setChannelMaximum(0, max);
            imgPlus.setAxis(new DefaultLinearAxis(Axes.Z), 2);
            imgPlus.setAxis(new DefaultLinearAxis(Axes.TIME), 3);
            uiService.show(vcellSelection.varName[varIndex], imgPlus);
            DefaultImageDisplay createDisplayQuietly = (DefaultImageDisplay) displayService.getDisplay(vcellSelection.varName[varIndex]);
            while (displayService.getActiveDisplay() == null) {
                Thread.sleep(100);
            }
            WindowManager.getActiveWindow().setSize(400, 400);
            IJ.run("Scale to Fit", "");
            // refresh the sliders
            WindowManager.getActiveWindow().setSize(400, 400);
            // final ZoomService zoomService = getContext().getService(ZoomService.class);
            // zoomService.zoomSet(createDisplayQuietly, 300, 0, 0);
            // eventService.publish(new PanZoomEvent(createDisplayQuietly.getCanvas()));
            // IJ.run("Set... ", "zoom=300 x="+(bsd.xsize/2)+" y="+(bsd.ysize/2));
            // IJ.run("Set... ", "zoom=300");
            // IJ.run("In");
            // IJ.run("In");
            // IJ.run("In");
            // RunService runService = getContext().getService(RunService.class);
            // runService.run("In", (Map)null);
            // final Iterator<PluginInfo<Op>> iterator = opService.getPlugins().iterator();
            // while(iterator.hasNext()) {
            // System.out.println(iterator.next());
            // }
            // opService.run("In", "");
            // final ZoomService zoomService = getContext().getService(ZoomService.class);
            // zoomService.zoomSet(createDisplayQuietly, 300, 0, 0);
            // createDisplayQuietly.update();
            // final Display<?> createDisplayQuietly = getContext().getService(DisplayService.class).createDisplayQuietly(testimg);
            final DefaultDatasetView defaultDatasetView = (DefaultDatasetView) ((DefaultImageDisplay) createDisplayQuietly).getActiveView();
            // defaultDatasetView.getData().setAxis(createDisplayQuietly.axis(2), 2);
            // defaultDatasetView.getData().setAxis(createDisplayQuietly.axis(3), 3);
            // defaultDatasetView.update();
            System.out.println(min + " " + max);
        // displayService.setActiveDisplay(createDisplayQuietly);
        // IJ.setMinAndMax(min, max);
        // defaultDatasetView.getData().setChannelMinimum(0, min);
        // defaultDatasetView.getData().setChannelMaximum(0, max);
        // defaultDatasetView.setChannelRanges(min,max);
        // IJ.getImage().updateAndDraw();
        // while(displayService.getActiveDisplay() == null) {
        // Thread.sleep(100);
        // }
        // IJ.setMinAndMax(min, max);
        // WindowManager.getCurrentImage().setDisplayRange(min, max)
        // WindowManager.getCurrentImage().setDisplayRange(min,max);
        // ImageStack.create(varIndex, varIndex, varIndex, varIndex)
        // ImagePlus ip = new ImagePlus();
        // uiService.showUI();
        // EventService es = null;
        // getContext().getService(EventService.class).publish(new DisplayUpdatedEvent(createDisplayQuietly,DisplayUpdatedEvent.DisplayUpdateLevel.UPDATE));
        // uiService.get
        // uiService.show(createDisplayQuietly);
        // getContext().getService(DisplayService.class).
        // showAndZoom(vcellSelection.varName[varIndex],createDisplayQuietly, 3);
        }
    } catch (Exception e) {
        displayProgressBar(false, "Error", "VCell Model Loader", 100, uiService);
        uiService.showDialog("theCacheKey,var,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0\n" + e.getMessage(), "getTimePoint(...) failed", MessageType.ERROR_MESSAGE);
    } finally {
        displayProgressBar(false, "displaying Image...", "VCell Model Loader", 100, uiService);
    }
}
Also used : ImgPlus(net.imagej.ImgPlus) DefaultLinearAxis(net.imagej.axis.DefaultLinearAxis) DoubleType(net.imglib2.type.numeric.real.DoubleType) IJDataList(org.vcell.imagej.helper.VCellHelper.IJDataList) BasicStackDimensions(org.vcell.imagej.helper.VCellHelper.BasicStackDimensions) DefaultImageDisplay(net.imagej.display.DefaultImageDisplay) DoubleArray(net.imglib2.img.basictypeaccess.array.DoubleArray) DefaultDatasetView(net.imagej.display.DefaultDatasetView)

Example 3 with IJDataList

use of org.vcell.imagej.helper.VCellHelper.IJDataList in project vcell by virtualcell.

the class VCellPlugin method run.

// private Hashtable<String,Thread> threadHash = new Hashtable<String,Thread>();
// private void startJProgressThread0(String lastName,String newName) {
// if(lastName != null && threadHash.get(lastName) != null) {
// threadHash.get(lastName).interrupt();
// while(threadHash.get(lastName) != null) {
// try {
// Thread.sleep(50);
// } catch (InterruptedException e) {
// e.printStackTrace();
// break;
// }
// }
// }
// if(newName == null) {
// return;
// }
// final Thread progressThread = new Thread(new Runnable(){
// @Override
// public void run() {
// final int[] progress = new int[] {1};
// while(progressDialog.isVisible()) {
// if(Thread.currentThread().isInterrupted()) {
// break;
// }
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// jProgressBar.setValue(progress[0]);
// }});
// progress[0]++;
// try {
// Thread.sleep(500);
// } catch (InterruptedException e) {
// break;
// }
// }
// threadHash.remove(Thread.currentThread().getName());
// }});
// threadHash.put(newName, progressThread);
// progressThread.setName(newName);
// progressThread.setDaemon(true);//So not block JVM exit
// progressThread.start();
// }
// public void showAndZoom(String displayName,Object thingToDisplay,double zoomFactor) throws Exception{
// final ImageDisplayService ids = getContext().getService(ImageDisplayService.class);
// final DisplayService ds = getContext().getService(DisplayService.class);
// new Thread(new Runnable() {
// 
// @Override
// public void run() {
// // TODO Auto-generated method stub
// uiService.show(displayName,thingToDisplay);
// //Find display and set zoom, resize window
// List<ImageDisplay> knownImageDisplays = ids.getImageDisplays();
// boolean bvisible = false;
// while (!bvisible) {
// for (ImageDisplay imageDisplay : knownImageDisplays) {
// if (imageDisplay.getName().equals(displayName)) {
// if (imageDisplay.isVisible(imageDisplay.getActiveView())) {
// bvisible = true;
// break;
// }
// }
// }
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// //		    	int vw = ij.imageDisplay().getActiveImageDisplay().getCanvas().getViewportWidth();
// //		    	int vh = ij.imageDisplay().getActiveImageDisplay().getCanvas().getViewportHeight();
// //		    	System.out.println(" -----byname="+ij.display().getDisplay(displayName));
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// try {
// ids.getActiveImageDisplay().getCanvas().setZoom(zoomFactor);
// if(ds.getDisplay(displayName) != null && uiService.getDisplayViewer(ds.getDisplay(displayName)) instanceof JFrame) {
// double vw = ids.getActiveImageDisplay().dimension(ids.getActiveImageDisplay().dimensionIndex(Axes.X))*zoomFactor;
// double vh = ids.getActiveImageDisplay().dimension(ids.getActiveImageDisplay().dimensionIndex(Axes.Y))*zoomFactor;
// ((JFrame)uiService.getDisplayViewer(ds.getDisplay(displayName)).getWindow()).setSize(new Dimension((int)vw+50, (int)vh+150));
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// 
// //		    	ij.ui().getDisplayViewer(ij.display().getDisplay(displayName)).getPanel().redoLayout();
// //		    	List<Display<?>> displays = ij.display().getDisplays();
// //		    	for (Display<?> display : displays) {
// //					System.out.println(display+" -----byname="+ij.display().getDisplay(displayName));
// //				}
// 
// }
// }).start();
// 
// }
@Override
public void run() {
    try {
        if (vcellSelection != null && vcellSelection.exception != null) {
            if (!vcellSelection.exception.getMessage().equals(MyPreProcessor.CANCELLED)) {
                uiService.showDialog("Model search failed\n" + vcellSelection.exception.getClass().getName() + "\n" + vcellSelection.exception.getMessage(), MessageType.ERROR_MESSAGE);
            }
            return;
        }
        if (vcellSelection == null || vcellSelection.theCacheKey == null) {
            return;
        }
        // Create ImageJ datasets and display separate hyperstack for each variable
        for (int varIndex = 0; varIndex < vcellSelection.varName.length; varIndex++) {
            int[] time = vcellSelection.timePointIndexes;
            displayProgressBar(true, "loading Image...", "VCell Model Loader", (varIndex + 1) * 100 / vcellSelection.varName.length, uiService);
            final IJDataList tpd = vcellHelper.getTimePointData(vcellSelection.theCacheKey, vcellSelection.varName[varIndex], VCellHelper.VARTYPE_POSTPROC.NotPostProcess, time, 0);
            BasicStackDimensions bsd = tpd.ijData[0].stackInfo;
            double[] data = new double[bsd.getTotalSize() * tpd.ijData.length];
            double min = Double.MAX_VALUE;
            double max = Double.MIN_VALUE;
            ArrayImg<DoubleType, DoubleArray> testimg = ArrayImgs.doubles(data, bsd.xsize, bsd.ysize, bsd.zsize, tpd.ijData.length);
            for (int i = 0; i < tpd.ijData.length; i++) {
                System.arraycopy(tpd.ijData[i].getDoubleData(), 0, data, i * bsd.getTotalSize(), bsd.getTotalSize());
                // calc minmax only for pixel values that are in domain of this variable
                for (int j = 0; j < tpd.ijData[i].getDoubleData().length; j++) {
                    if (tpd.ijData[i].getDoubleData()[j] != tpd.ijData[i].notInDomainValue) {
                        min = Math.min(min, tpd.ijData[i].getDoubleData()[j]);
                        max = Math.max(max, tpd.ijData[i].getDoubleData()[j]);
                    }
                }
            }
            ImgPlus<DoubleType> imgPlus = new ImgPlus<DoubleType>(testimg);
            imgPlus.setChannelMinimum(0, min);
            imgPlus.setChannelMaximum(0, max);
            imgPlus.setAxis(new DefaultLinearAxis(Axes.Z), 2);
            imgPlus.setAxis(new DefaultLinearAxis(Axes.TIME), 3);
            uiService.show(vcellSelection.varName[varIndex], imgPlus);
            DefaultImageDisplay createDisplayQuietly = (DefaultImageDisplay) displayService.getDisplay(vcellSelection.varName[varIndex]);
            while (displayService.getActiveDisplay() == null) {
                Thread.sleep(100);
            }
            WindowManager.getActiveWindow().setSize(400, 400);
            IJ.run("Scale to Fit", "");
            // refresh the sliders
            WindowManager.getActiveWindow().setSize(400, 400);
            // final ZoomService zoomService = getContext().getService(ZoomService.class);
            // zoomService.zoomSet(createDisplayQuietly, 300, 0, 0);
            // eventService.publish(new PanZoomEvent(createDisplayQuietly.getCanvas()));
            // IJ.run("Set... ", "zoom=300 x="+(bsd.xsize/2)+" y="+(bsd.ysize/2));
            // IJ.run("Set... ", "zoom=300");
            // IJ.run("In");
            // IJ.run("In");
            // IJ.run("In");
            // RunService runService = getContext().getService(RunService.class);
            // runService.run("In", (Map)null);
            // final Iterator<PluginInfo<Op>> iterator = opService.getPlugins().iterator();
            // while(iterator.hasNext()) {
            // System.out.println(iterator.next());
            // }
            // opService.run("In", "");
            // final ZoomService zoomService = getContext().getService(ZoomService.class);
            // zoomService.zoomSet(createDisplayQuietly, 300, 0, 0);
            // createDisplayQuietly.update();
            // final Display<?> createDisplayQuietly = getContext().getService(DisplayService.class).createDisplayQuietly(testimg);
            final DefaultDatasetView defaultDatasetView = (DefaultDatasetView) ((DefaultImageDisplay) createDisplayQuietly).getActiveView();
            // defaultDatasetView.getData().setAxis(createDisplayQuietly.axis(2), 2);
            // defaultDatasetView.getData().setAxis(createDisplayQuietly.axis(3), 3);
            // defaultDatasetView.update();
            System.out.println(min + " " + max);
        // displayService.setActiveDisplay(createDisplayQuietly);
        // IJ.setMinAndMax(min, max);
        // defaultDatasetView.getData().setChannelMinimum(0, min);
        // defaultDatasetView.getData().setChannelMaximum(0, max);
        // defaultDatasetView.setChannelRanges(min,max);
        // IJ.getImage().updateAndDraw();
        // while(displayService.getActiveDisplay() == null) {
        // Thread.sleep(100);
        // }
        // IJ.setMinAndMax(min, max);
        // WindowManager.getCurrentImage().setDisplayRange(min, max)
        // WindowManager.getCurrentImage().setDisplayRange(min,max);
        // ImageStack.create(varIndex, varIndex, varIndex, varIndex)
        // ImagePlus ip = new ImagePlus();
        // uiService.showUI();
        // EventService es = null;
        // getContext().getService(EventService.class).publish(new DisplayUpdatedEvent(createDisplayQuietly,DisplayUpdatedEvent.DisplayUpdateLevel.UPDATE));
        // uiService.get
        // uiService.show(createDisplayQuietly);
        // getContext().getService(DisplayService.class).
        // showAndZoom(vcellSelection.varName[varIndex],createDisplayQuietly, 3);
        }
    } catch (Exception e) {
        displayProgressBar(false, "Error", "VCell Model Loader", 100, uiService);
        uiService.showDialog("theCacheKey,var,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0\n" + e.getMessage(), "getTimePoint(...) failed", MessageType.ERROR_MESSAGE);
    } finally {
        displayProgressBar(false, "displaying Image...", "VCell Model Loader", 100, uiService);
    }
}
Also used : ImgPlus(net.imagej.ImgPlus) DefaultLinearAxis(net.imagej.axis.DefaultLinearAxis) DoubleType(net.imglib2.type.numeric.real.DoubleType) IJDataList(org.vcell.imagej.helper.VCellHelper.IJDataList) BasicStackDimensions(org.vcell.imagej.helper.VCellHelper.BasicStackDimensions) DefaultImageDisplay(net.imagej.display.DefaultImageDisplay) DoubleArray(net.imglib2.img.basictypeaccess.array.DoubleArray) DefaultDatasetView(net.imagej.display.DefaultDatasetView)

Example 4 with IJDataList

use of org.vcell.imagej.helper.VCellHelper.IJDataList in project vcell by virtualcell.

the class ModelLoad method run.

@Override
public void run() {
    displayProgressBar(true, "Checking listening ports...", "Checking for VCell Client");
    startJProgressThread0(null, "Check");
    try {
        // Find the port that a separately running VCell client is listening on
        // 
        System.out.println("vcell service port=" + vcellHelper.findVCellApiServerPort());
        // uiService.getDisplayViewer(textDisplay).dispose();
        displayProgressBar(false, null, null);
    } catch (Exception e) {
        // e.printStackTrace();
        displayProgressBar(false, null, null);
        // uiService.getDisplayViewer(textDisplay).dispose();
        uiService.showDialog("Activate VCell client ImageJ service\nTools->'Start Fiji (ImageJ) service'\n" + e.getMessage(), "Couldn't contact VCell client", MessageType.ERROR_MESSAGE);
        return;
    }
    displayProgressBar(true, "Searching...", "Searching VCell Models");
    startJProgressThread0("Check", "Search");
    String theCacheKey = null;
    VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.bm, vCellUser, vCellModel, application, simulation, null, null);
    try {
        ArrayList<VCellModelSearchResults> vcmsr = vcellHelper.getSearchedModelSimCacheKey(false, vcms, null);
        if (vcmsr.size() == 0) {
            throw new Exception("No Results for search found");
        }
        theCacheKey = vcmsr.get(0).getCacheKey();
        System.out.println("theCacheKey=" + theCacheKey);
        displayProgressBar(false, null, null);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        // e.printStackTrace();
        uiService.showDialog("VCellHelper.ModelType.bm,vCellUser,vCellModel,application,simulation,null,null\n" + e.getMessage(), "Search failed", MessageType.ERROR_MESSAGE);
        displayProgressBar(false, null, null);
    }
    displayProgressBar(true, "Loading Data...", "Loading Data");
    startJProgressThread0("Search", "getTimePointData");
    try {
        String var = variable;
        int[] time = new int[] { timePoint };
        IJDataList tpd = vcellHelper.getTimePointData(theCacheKey, var, VCellHelper.VARTYPE_POSTPROC.NotPostProcess, time, 0);
        double[] data = tpd.ijData[0].getDoubleData();
        BasicStackDimensions bsd = tpd.ijData[0].stackInfo;
        System.out.println(bsd.xsize + " " + bsd.ysize);
        ArrayImg<DoubleType, DoubleArray> testimg = ArrayImgs.doubles(data, bsd.xsize, bsd.ysize);
        uiService.show(testimg);
        displayProgressBar(false, null, null);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        // e.printStackTrace();
        uiService.showDialog("theCacheKey,var,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0\n" + e.getMessage(), "getTimePoint(...) failed", MessageType.ERROR_MESSAGE);
        displayProgressBar(false, null, null);
    }
    startJProgressThread0("getTimePointData", null);
}
Also used : VCellModelSearchResults(org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults) VCellHelper(org.vcell.imagej.helper.VCellHelper) DoubleType(net.imglib2.type.numeric.real.DoubleType) IJDataList(org.vcell.imagej.helper.VCellHelper.IJDataList) BasicStackDimensions(org.vcell.imagej.helper.VCellHelper.BasicStackDimensions) DoubleArray(net.imglib2.img.basictypeaccess.array.DoubleArray)

Example 5 with IJDataList

use of org.vcell.imagej.helper.VCellHelper.IJDataList in project vcell by virtualcell.

the class LinePlot method run.

@Override
public void run() {
    try {
        // Find the port that a separately running VCell client is listening on
        System.out.println("vcell service port=" + vcellHelper.findVCellApiServerPort());
    } catch (Exception e) {
        uiService.showDialog("Activate VCell client ImageJ service\nTools->'Start Fiji (ImageJ) service'\n" + e.getMessage(), "Couldn't contact VCell client", MessageType.ERROR_MESSAGE);
        return;
    }
    String theCacheKey = null;
    VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.valueOf(modelType), vCellUser, vCellModel, application, simulation, null, null);
    try {
        ArrayList<VCellModelSearchResults> vcmsr = vcellHelper.getSearchedModelSimCacheKey(false, vcms, null);
        if (vcmsr.size() == 0) {
            throw new Exception("No Results for search found");
        }
        theCacheKey = vcmsr.get(0).getCacheKey();
        System.out.println("theCacheKey=" + theCacheKey);
    } catch (Exception e) {
        uiService.showDialog(modelType + ", " + vCellUser + ", " + vCellModel + ", " + application + ", " + simulation + ", null, null\n" + e.getMessage(), "Search failed", MessageType.ERROR_MESSAGE);
        return;
    }
    IJDataList timePointData = null;
    // there is 1 timePoint
    int[] timePointIndexes = new int[1];
    int theTimePointIndex = 0;
    timePointIndexes[theTimePointIndex] = timePoint;
    try {
        timePointData = vcellHelper.getTimePointData(theCacheKey, variable, VARTYPE_POSTPROC.NotPostProcess, timePointIndexes, 0);
    } catch (Exception e) {
        uiService.showDialog(modelType + ", " + vCellUser + ", " + vCellModel + ", " + application + ", " + simulation + ", " + variable + ", " + timePoint + "\n" + e.getMessage(), "Get Data failed", MessageType.ERROR_MESSAGE);
        return;
    }
    double[] theTimePointData = timePointData.ijData[theTimePointIndex].getDoubleData();
    Range xAxisRange = null;
    int[] dataIndexes = new int[endIndex - startIndex + 1];
    // This is just for JFreeChart
    double[] dataIndexesDouble = new double[dataIndexes.length];
    for (int i = startIndex; i <= endIndex; i++) {
        dataIndexes[i - startIndex] = i;
        dataIndexesDouble[i - startIndex] = i;
        xAxisRange = Range.expandToInclude(xAxisRange, dataIndexesDouble[i - startIndex]);
    }
    Range yAxisRange = null;
    double[] chartTheseDataPoints = new double[dataIndexes.length];
    for (int i = 0; i < dataIndexes.length; i++) {
        chartTheseDataPoints[i] = theTimePointData[dataIndexes[i]];
        yAxisRange = Range.expandToInclude(yAxisRange, chartTheseDataPoints[i]);
    // ijTimeSeriesJobResults.data[0/*index of "r"*/][i+1/*data, skip 0 because it holds copy of times*/][0/*0 always because we had only 1 timePoint=22.0*/]
    }
    try {
        // LINE plot of data at 1 timePoint along defined indexes
        // Create JFreechart x,y axis arrays for plotting x=data indexes, y=dataPoint values
        double[][] data = new double[][] { dataIndexesDouble, chartTheseDataPoints };
        String title = "LINE Plot at time=" + timePoint;
        String xAxisLabel = "distance";
        String yAxisLabel = "val";
        DefaultXYDataset xyDataset = new DefaultXYDataset();
        xyDataset.addSeries("data1", data);
        JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, xyDataset, PlotOrientation.VERTICAL, false, false, false);
        // Y
        chart.getXYPlot().getDomainAxis().setRange(xAxisRange);
        // X
        chart.getXYPlot().getRangeAxis().setRange(yAxisRange);
        ChartPanel chartPanel = new ChartPanel(chart);
        JFrame frame = new JFrame("Chart");
        // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(chartPanel);
        // Display the window.
        frame.pack();
        frame.setVisible(true);
    } catch (Exception e) {
        uiService.showDialog("LINE PlotGet Data failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
    IJTimeSeriesJobResults timeSeries = null;
    try {
        IJVarInfos simulationInfo = vcellHelper.getSimulationInfo(theCacheKey);
        double[] times = simulationInfo.getTimes();
        timeSeries = vcellHelper.getTimeSeries(new String[] { variable }, new int[] { dataIndexes[0] }, times[0], 1, times[times.length - 1], false, false, 0, Integer.parseInt(theCacheKey));
    } catch (Exception e) {
        uiService.showDialog("TIME Plot Get Data failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
    try {
        // TIME plot of data at 1 timePoint along defined indexes
        // Create JFreechart x,y axis arrays for plotting x=data indexes, y=dataPoint values
        double[][] data = new double[][] { timeSeries.data[0][0], timeSeries.data[0][1] };
        String title = "TIME Plot at dataIndex=" + dataIndexes[0];
        String xAxisLabel = "time";
        String yAxisLabel = "val";
        DefaultXYDataset xyDataset = new DefaultXYDataset();
        xyDataset.addSeries("data1", data);
        JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, xyDataset, PlotOrientation.VERTICAL, false, false, false);
        // chart.getXYPlot().getDomainAxis().setRange(yAxisRange);//Y
        // chart.getXYPlot().getRangeAxis().setRange(xAxisRange);//X
        ChartPanel chartPanel = new ChartPanel(chart);
        JFrame frame = new JFrame("Chart");
        // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(chartPanel);
        // Display the window.
        frame.pack();
        frame.setVisible(true);
    } catch (Exception e) {
        uiService.showDialog("TIME Plot show chart failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) IJVarInfos(org.vcell.imagej.helper.VCellHelper.IJVarInfos) DefaultXYDataset(org.jfree.data.xy.DefaultXYDataset) VCellModelSearchResults(org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults) Range(org.jfree.data.Range) VCellHelper(org.vcell.imagej.helper.VCellHelper) JFreeChart(org.jfree.chart.JFreeChart) JFrame(javax.swing.JFrame) IJDataList(org.vcell.imagej.helper.VCellHelper.IJDataList) IJTimeSeriesJobResults(org.vcell.imagej.helper.VCellHelper.IJTimeSeriesJobResults)

Aggregations

IJDataList (org.vcell.imagej.helper.VCellHelper.IJDataList)6 DoubleArray (net.imglib2.img.basictypeaccess.array.DoubleArray)4 DoubleType (net.imglib2.type.numeric.real.DoubleType)4 BasicStackDimensions (org.vcell.imagej.helper.VCellHelper.BasicStackDimensions)4 VCellHelper (org.vcell.imagej.helper.VCellHelper)3 VCellModelSearchResults (org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults)3 JFrame (javax.swing.JFrame)2 ImgPlus (net.imagej.ImgPlus)2 DefaultLinearAxis (net.imagej.axis.DefaultLinearAxis)2 DefaultDatasetView (net.imagej.display.DefaultDatasetView)2 DefaultImageDisplay (net.imagej.display.DefaultImageDisplay)2 ChartPanel (org.jfree.chart.ChartPanel)2 JFreeChart (org.jfree.chart.JFreeChart)2 Range (org.jfree.data.Range)2 DefaultXYDataset (org.jfree.data.xy.DefaultXYDataset)2 IJTimeSeriesJobResults (org.vcell.imagej.helper.VCellHelper.IJTimeSeriesJobResults)2 IJVarInfos (org.vcell.imagej.helper.VCellHelper.IJVarInfos)2