예제 #1
0
 void interpolate() {
   Roi roi = imp.getRoi();
   if (roi == null) {
     noRoi("Interpolate");
     return;
   }
   if (roi.getType() == Roi.POINT) return;
   if (IJ.isMacro() && Macro.getOptions() == null) Macro.setOptions("interval=1");
   GenericDialog gd = new GenericDialog("Interpolate");
   gd.addNumericField("Interval:", 1.0, 1, 4, "pixel");
   gd.addCheckbox("Smooth", IJ.isMacro() ? false : smooth);
   gd.showDialog();
   if (gd.wasCanceled()) return;
   double interval = gd.getNextNumber();
   smooth = gd.getNextBoolean();
   Undo.setup(Undo.ROI, imp);
   FloatPolygon poly = roi.getInterpolatedPolygon(interval, smooth);
   int t = roi.getType();
   int type = roi.isLine() ? Roi.FREELINE : Roi.FREEROI;
   if (t == Roi.POLYGON && interval > 1.0) type = Roi.POLYGON;
   if ((t == Roi.RECTANGLE || t == Roi.OVAL || t == Roi.FREEROI) && interval >= 5.0)
     type = Roi.POLYGON;
   if ((t == Roi.LINE || t == Roi.FREELINE) && interval >= 5.0) type = Roi.POLYLINE;
   if (t == Roi.POLYLINE && interval >= 1.0) type = Roi.POLYLINE;
   ImageCanvas ic = imp.getCanvas();
   if (poly.npoints <= 150 && ic != null && ic.getMagnification() >= 12.0)
     type = roi.isLine() ? Roi.POLYLINE : Roi.POLYGON;
   Roi p = new PolygonRoi(poly, type);
   if (roi.getStroke() != null) p.setStrokeWidth(roi.getStrokeWidth());
   p.setStrokeColor(roi.getStrokeColor());
   p.setName(roi.getName());
   transferProperties(roi, p);
   imp.setRoi(p);
 }
예제 #2
0
  public void run(String arg) {
    ImagePlus image = WindowManager.getCurrentImage();
    try {
      Image3DUniverse univ = new Image3DUniverse();
      univ.show();
      GUI.center(univ.getWindow());
      // only when there is an image and we are not called
      // from a macro
      if (image != null && !IJ.isMacro()) univ.getExecuter().addContent(image, null);

    } catch (Exception e) {
      StringBuffer buf = new StringBuffer();
      StackTraceElement[] st = e.getStackTrace();
      buf.append(
          "An unexpected exception occurred. \n"
              + "Please mail me the following lines if you \n"
              + "need help.\n"
              + "[email protected]\n   \n");
      buf.append(e.getClass().getName() + ":" + e.getMessage() + "\n");
      for (int i = 0; i < st.length; i++) {
        buf.append(
            "    at "
                + st[i].getClassName()
                + "."
                + st[i].getMethodName()
                + "("
                + st[i].getFileName()
                + ":"
                + st[i].getLineNumber()
                + ")\n");
      }
      new ij.text.TextWindow("Error", buf.toString(), 500, 400);
    }
  }
예제 #3
0
파일: Opener.java 프로젝트: kkkkxu/BioImage
 /**
  * Opens a single TIFF or DICOM contained in a ZIP archive, or a ZIPed collection of ".roi" files
  * created by the ROI manager.
  */
 public ImagePlus openZip(String path) {
   ImagePlus imp = null;
   try {
     ZipInputStream zis = new ZipInputStream(new FileInputStream(path));
     ZipEntry entry = zis.getNextEntry();
     if (entry == null) {
       zis.close();
       return null;
     }
     String name = entry.getName();
     if (name.endsWith(".roi")) {
       zis.close();
       if (!silentMode)
         if (IJ.isMacro() && Interpreter.isBatchMode() && RoiManager.getInstance() == null)
           IJ.log(
               "Use roiManager(\"Open\", path) instead of open(path)\nto open ROI sets in batch mode macros.");
         else IJ.runMacro("roiManager(\"Open\", getArgument());", path);
       return null;
     }
     if (name.endsWith(".tif")) {
       imp = openTiff(zis, name);
     } else if (name.endsWith(".dcm")) {
       DICOM dcm = new DICOM(zis);
       dcm.run(name);
       imp = dcm;
     } else {
       zis.close();
       IJ.error(
           "Opener",
           "This ZIP archive does not appear to contain a \nTIFF (\".tif\") or DICOM (\".dcm\") file, or ROIs (\".roi\").");
       return null;
     }
     zis.close();
   } catch (Exception e) {
     IJ.error("Opener", "" + e);
     return null;
   }
   File f = new File(path);
   FileInfo fi = imp.getOriginalFileInfo();
   if (fi != null) {
     fi.fileFormat = FileInfo.ZIP_ARCHIVE;
     fi.fileName = f.getName();
     fi.directory = f.getParent() + File.separator;
   }
   return imp;
 }
예제 #4
0
 void checkForCalibrationConflict(ImagePlus imp, Calibration cal) {
   Calibration gcal = imp.getGlobalCalibration();
   if (gcal == null || !showConflictMessage || IJ.isMacro()) return;
   if (cal.pixelWidth == gcal.pixelWidth && cal.getUnit().equals(gcal.getUnit())) return;
   GenericDialog gd = new GenericDialog(imp.getTitle());
   gd.addMessage("The calibration of this image conflicts\nwith the current global calibration.");
   gd.addCheckbox("Disable_Global Calibration", true);
   gd.addCheckbox("Disable_these Messages", false);
   gd.showDialog();
   if (gd.wasCanceled()) return;
   boolean disable = gd.getNextBoolean();
   if (disable) {
     imp.setGlobalCalibration(null);
     imp.setCalibration(cal);
     WindowManager.repaintImageWindows();
   }
   boolean dontShow = gd.getNextBoolean();
   if (dontShow) showConflictMessage = false;
 }
예제 #5
0
파일: Opener.java 프로젝트: kkkkxu/BioImage
 /**
  * Opens and displays the specified tiff, dicom, fits, pgm, jpeg, bmp, gif, lut, roi, or text
  * file. Displays an error message if the file is not in a supported format.
  *
  * @see ij.IJ#open(String)
  * @see ij.IJ#openImage(String)
  */
 public void open(String path) {
   boolean isURL = path.indexOf("://") > 0;
   if (isURL && isText(path)) {
     openTextURL(path);
     return;
   }
   if (path.endsWith(".jar") || path.endsWith(".class")) {
     (new PluginInstaller()).install(path);
     return;
   }
   boolean fullPath =
       path.startsWith("/") || path.startsWith("\\") || path.indexOf(":\\") == 1 || isURL;
   if (!fullPath) {
     String defaultDir = OpenDialog.getDefaultDirectory();
     if (defaultDir != null) path = defaultDir + path;
     else path = (new File(path)).getAbsolutePath();
   }
   if (!silentMode) IJ.showStatus("Opening: " + path);
   long start = System.currentTimeMillis();
   ImagePlus imp = openImage(path);
   if (imp == null && isURL) return;
   if (imp != null) {
     WindowManager.checkForDuplicateName = true;
     if (isRGB48) openRGB48(imp);
     else imp.show(getLoadRate(start, imp));
   } else {
     switch (fileType) {
       case LUT:
         imp = (ImagePlus) IJ.runPlugIn("ij.plugin.LutLoader", path);
         if (imp.getWidth() != 0) imp.show();
         break;
       case ROI:
         IJ.runPlugIn("ij.plugin.RoiReader", path);
         break;
       case JAVA_OR_TEXT:
       case TEXT:
         if (IJ.altKeyDown()) { // open in TextWindow if alt key down
           new TextWindow(path, 400, 450);
           IJ.setKeyUp(KeyEvent.VK_ALT);
           break;
         }
         File file = new File(path);
         int maxSize = 250000;
         long size = file.length();
         if (size >= 28000) {
           String osName = System.getProperty("os.name");
           if (osName.equals("Windows 95")
               || osName.equals("Windows 98")
               || osName.equals("Windows Me")) maxSize = 60000;
         }
         if (size < maxSize) {
           Editor ed = (Editor) IJ.runPlugIn("ij.plugin.frame.Editor", "");
           if (ed != null) ed.open(getDir(path), getName(path));
         } else new TextWindow(path, 400, 450);
         break;
       case OJJ: // ObjectJ project
         IJ.runPlugIn("ObjectJ_", path);
         break;
       case TABLE: // ImageJ Results table
         openResultsTable(path);
         break;
       case RAW:
         IJ.runPlugIn("ij.plugin.Raw", path);
         break;
       case UNKNOWN:
         String msg =
             "File is not in a supported format, a reader\n"
                 + "plugin is not available, or it was not found.";
         if (path != null) {
           if (path.length() > 64) path = (new File(path)).getName();
           if (path.length() <= 64) {
             if (IJ.redirectingErrorMessages()) msg += " \n   " + path;
             else msg += " \n	 \n" + path;
           }
         }
         if (openUsingPlugins) msg += "\n \nNOTE: The \"OpenUsingPlugins\" option is set.";
         IJ.wait(IJ.isMacro() ? 500 : 100); // work around for OS X thread deadlock problem
         IJ.error("Opener", msg);
         error = true;
         break;
     }
   }
 }