Search in sources :

Example 1 with DefaultImageDisplay

use of net.imagej.display.DefaultImageDisplay 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 2 with DefaultImageDisplay

use of net.imagej.display.DefaultImageDisplay 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)

Aggregations

ImgPlus (net.imagej.ImgPlus)2 DefaultLinearAxis (net.imagej.axis.DefaultLinearAxis)2 DefaultDatasetView (net.imagej.display.DefaultDatasetView)2 DefaultImageDisplay (net.imagej.display.DefaultImageDisplay)2 DoubleArray (net.imglib2.img.basictypeaccess.array.DoubleArray)2 DoubleType (net.imglib2.type.numeric.real.DoubleType)2 BasicStackDimensions (org.vcell.imagej.helper.VCellHelper.BasicStackDimensions)2 IJDataList (org.vcell.imagej.helper.VCellHelper.IJDataList)2