/** * Update the Dynamic reslice window. Called by the * Updater(), which lives in a separate thread. */ private void refresh() { // Only update if the roi is large enough, if ( imp.getRoi().getLength() < 2.0) return; // If not initialized, initialize if (!hasStarted) start(); // Re-calculate slice reslice(); }
/** * Create a new instance of this plugin, linked to the ImagePlus given in * argument. This ImagePlus will be used as the source for dynamic * reslicing. This constructor is meant to be called from a scripting * context, and take care of setting all properties according the ImagePlus * argument or defaults. * * @param _imp the source ImagePlus */ public Dynamic_Reslice(final ImagePlus _imp) { this.imp = _imp; setup(); }
line = getIrregularProfile(ip, roi); } else if (ortho) // orthogonal straight line line = getOrthoLine(ip, (int) x1, (int) y1, (int) x2, (int) y2); else line = getLine(ip, x1, y1, x2, y2); putColumn(ip_out, i, 0, line, line.length); } else { if (i == 0) ip_out = ip.createProcessor(line.length, stackSize); putRow(ip_out, 0, i, line, line.length);
/** * Main method, called when the plugin is launched from ImageJ menu. */ @Override public void run(final String arg) { if (imp == null) { IJ.noImage(); return; } final int stackSize = imp.getStackSize(); final Roi roi = imp.getRoi(); final int roiType = roi != null ? roi.getType() : 0; // stack required except for ROI = none or RECT if (stackSize < 2 && roi != null && roiType != Roi.RECTANGLE) { IJ.error("Dynamic Reslice...", "Stack required"); return; } // permissible ROI types: none,*LINE if (roi == null || (roiType != Roi.LINE && roiType != Roi.POLYLINE && roiType != Roi.FREELINE)) { IJ.error("Dynamic Reslice...", "Line selection required"); return; } // Show dialog (and quit if it was canceled). setup(); if (!showDialog()) return; start(); }
/** * Main method that actually dispatch the work. Update the destination * ImagePlus ({@link #dest_imp}) with the new content resulting from the * reslice. Also deal with calibration. */ protected void reslice() { ImageProcessor ip_out; final Roi roi = imp.getRoi(); final int roiType = roi != null ? roi.getType() : 0; /* * Save calibration */ final Calibration origCal = imp.getCalibration(); final double zSpacing = inputZSpacing / imp.getCalibration().pixelWidth; /* * Do reslice and update dest_imp */ ip_out = getSlice(imp, roi); dest_imp.setProcessor(null, ip_out); dealWithCalibration(); }
doIrregularSetup(roi); final float[] values = new float[(int) length]; double leftOver = 1.0;
/** * Method to start the dynamic reslice process after all parameters * have been set. Will not initiate as long as there is no ROI. */ public void start() { if (hasStarted || imp.getRoi() == null) return; // Get type of source window rgb = imp.getType() == ImagePlus.COLOR_RGB; notFloat = !rgb && imp.getType() != ImagePlus.GRAY32; // Create the destination ImagePlus dest_imp by get a slice a first time. dest_imp = new ImagePlus("Dynamic Reslice of "+imp.getShortTitle(), getSlice(imp, imp.getRoi())); dealWithCalibration(); // Copy min & max to new result final ImageProcessor ip = imp.getProcessor(); final double min = ip.getMin(); final double max = ip.getMax(); if (!rgb) dest_imp.getProcessor().setMinAndMax(min, max); // Display window result dest_imp.show(); // Add listeners imp.getCanvas().addMouseMotionListener(this); imp.getWindow().addWindowListener(this); dest_imp.getWindow().addWindowListener(this); // Set the started flag to true hasStarted = true; }