/** Starts the program. */ public void runAlgorithm() { int[] destExtents = null; if (srcImage == null) { displayError("Source Image is null"); return; } if (srcImage.getNDims() == 2) { makeKernels2D(); } else if ((srcImage.getNDims() == 3) && (image25D == false)) { makeKernels3D(); } else if ((srcImage.getNDims() == 3) && (image25D == true)) { makeKernels2D(); } try { if (srcImage.getNDims() == 2) { destExtents = new int[2]; destExtents[0] = srcImage.getExtents()[0]; // X dim destExtents[1] = srcImage.getExtents()[1]; // Y dim } else if (srcImage.getNDims() == 3) { destExtents = new int[3]; destExtents[0] = srcImage.getExtents()[0]; // X dim destExtents[1] = srcImage.getExtents()[1]; // Y dim destExtents[2] = srcImage.getExtents()[2]; // Z dim } zXMask = new ModelImage(ModelImage.UBYTE, destExtents, " Edges"); } catch (OutOfMemoryError e) { destImage = null; srcImage = null; zXMask.disposeLocal(); zXMask = null; errorCleanUp("Algorithm EdgeLapSep : Out of memory", true); return; } if (destImage != null) { // NEW if (srcImage.getNDims() == 2) { calcStoreInDest2D(1, zeroDetectionType); } else if ((srcImage.getNDims() == 3) && (image25D == false)) { calcStoreInDest3D(zeroDetectionType); } else if ((srcImage.getNDims() == 3) && (image25D == true)) { calcStoreInDest2D(srcImage.getExtents()[2], zeroDetectionType); } } if (threadStopped) { finalize(); return; } }
/** dispose memory. */ public void disposeLocal() { if (mathAlgo != null) { mathAlgo.finalize(); mathAlgo = null; } if (image != null) { image.disposeLocal(); } image = null; if (resultImage != null) { resultImage.disposeLocal(); } resultImage = null; }
/** * This method is required if the AlgorithmPerformed interface is implemented. It is called by the * algorithms when it has completed or failed to to complete, so that the dialog can be display * the result image and/or clean up. * * @param algorithm Algorithm that caused the event. */ public void algorithmPerformed(AlgorithmBase algorithm) { ViewJFrameImage imageFrame = null; if (algorithm instanceof AlgorithmMosaicToSlices) { if ((mathAlgo.isCompleted() == true) && (mathAlgo.getResultImage() != null)) { // The algorithm has completed and produced a new image to be displayed. if (displayLoc == NEW) { try { resultImage = mathAlgo.getResultImage(); new ViewJFrameImage(resultImage, null, new Dimension(610, 200)); } catch (OutOfMemoryError error) { System.gc(); MipavUtil.displayError("Out of memory: unable to open new frame"); } } else { // These next lines set the titles in all frames where the source image is displayed to // image name so as to indicate that the image is now unlocked! // The image frames are enabled and then registed to the userinterface. resultImage = mathAlgo.getResultImage(); Vector<ViewImageUpdateInterface> imageFrames = image.getImageFrameVector(); for (int i = 0; i < imageFrames.size(); i++) { ((Frame) (imageFrames.elementAt(i))).setTitle(titles[i]); ((Frame) (imageFrames.elementAt(i))).setEnabled(true); if ((((Frame) (imageFrames.elementAt(i))) != parentFrame) && (parentFrame != null)) { userInterface.registerFrame((Frame) (imageFrames.elementAt(i))); } } Point pt; if (parentFrame != null) { pt = ((ViewJFrameBase) parentFrame).getLocation(); } else { pt = new Point( Toolkit.getDefaultToolkit().getScreenSize().width / 2, Toolkit.getDefaultToolkit().getScreenSize().height / 2); } imageFrame = new ViewJFrameImage(resultImage, null, new Dimension(pt.x, pt.y)); if (parentFrame != null) { ((ViewJFrameBase) parentFrame).close(); } else { ((ViewJFrameBase) image.getParentFrame()).close(); } // Not so sure about this. if (image.getLightBoxFrame() != null) { try { pt = image.getLightBoxFrame().getLocation(); image.getLightBoxFrame().close(); new ViewJFrameLightBox( imageFrame, "LightBox", resultImage, imageFrame.getComponentImage().getLUTa(), imageFrame.getComponentImage().getImageB(), imageFrame.getComponentImage().getLUTb(), imageFrame.getComponentImage().getResolutionX(), imageFrame.getComponentImage().getResolutionY(), new Dimension(pt.x, pt.y), imageFrame.getControls(), imageFrame.getVOIManager()); } catch (OutOfMemoryError error) { MipavUtil.displayError("Out of memory: unable to open new frame"); } } } } else if (resultImage == null) { // These next lines set the titles in all frames where the source image is displayed to // image name so as to indicate that the image is now unlocked! // The image frames are enabled and then registered to the userinterface. /*Vector imageFrames = imageA.getImageFrameVector(); for (int i = 0; i < imageFrames.size(); i++) { ((Frame) (imageFrames.elementAt(i))).setTitle(titles[i]); ((Frame) (imageFrames.elementAt(i))).setEnabled(true); if (((Frame) (imageFrames.elementAt(i))) != parentFrame) { userInterface.registerFrame((Frame) (imageFrames.elementAt(i))); } }*/ if (parentFrame != null) { userInterface.registerFrame(parentFrame); } image.notifyImageDisplayListeners(null, true); } else if (resultImage != null) { // algorithm failed but result image still has garbage resultImage.disposeLocal(); // clean up memory System.gc(); } } if (algorithm.isCompleted()) { insertScriptLine(); } mathAlgo.finalize(); mathAlgo = null; dispose(); }