public double[] fitfunc(double[] fitparams) {
   Bindings b = engine.createBindings();
   for (int i = 0; i < 10; i++) b.put("P" + (i + 1), fitparams[i]);
   /*String script1="P1="+fitparams[0]+"; "+
   "P2="+fitparams[1]+"; "+
   "P3="+fitparams[2]+"; "+
   "P4="+fitparams[3]+"; "+
   "P5="+fitparams[4]+"; "+
   "P6="+fitparams[5]+"; "+
   "P7="+fitparams[6]+"; "+
   "P8="+fitparams[7]+"; "+
   "P9="+fitparams[8]+"; "+
   "P10="+fitparams[9]+"; "+
   exdef+"; x=";
   String script2="; retval="+function+";";*/
   try {
     double[] temp = new double[tempx.length];
     for (int i = 0; i < tempx.length; i++) {
       // temp[i]=((Double)engine.eval(script1+(double)tempx[i]+script2)).doubleValue();
       b.put("x", tempx[i]);
       b.put("y", tempdata[i]);
       temp[i] = (Double) cs.eval(b);
     }
     return temp;
   } catch (Exception e) {
     IJ.log(e.getMessage());
     return null;
   }
 }
Beispiel #2
0
 /**
  * Notify any DialogListeners of changes having occurred If a listener returns false, do not call
  * further listeners and disable the OK button and preview Checkbox (if it exists). For
  * PlugInFilters, this ensures that the PlugInFilterRunner, which listens as the last one, is not
  * called if the PlugInFilter has detected invalid parameters. Thus, unnecessary calling the
  * run(ip) method of the PlugInFilter for preview is avoided in that case.
  */
 private void notifyListeners(AWTEvent e) {
   if (dialogListeners == null) return;
   boolean everythingOk = true;
   for (int i = 0; everythingOk && i < dialogListeners.size(); i++)
     try {
       resetCounters();
       if (!((DialogListener) dialogListeners.elementAt(i)).dialogItemChanged(this, e))
         everythingOk = false;
     } // disable further listeners if false (invalid parameters) returned
     catch (Exception err) { // for exceptions, don't cover the input by a window but
       IJ.beep(); // show them at in the "Log"
       IJ.log(
           "ERROR: "
               + err
               + "\nin DialogListener of "
               + dialogListeners.elementAt(i)
               + "\nat "
               + (err.getStackTrace()[0])
               + "\nfrom "
               + (err.getStackTrace()[1])); // requires Java 1.4
     }
   boolean workaroundOSXbug = IJ.isMacOSX() && okay != null && !okay.isEnabled() && everythingOk;
   if (previewCheckbox != null) previewCheckbox.setEnabled(everythingOk);
   if (okay != null) okay.setEnabled(everythingOk);
   if (workaroundOSXbug) repaint(); // OSX 10.4 bug delays update of enabled until the next input
 }
Beispiel #3
0
 public Zipper<Map<Integer, MZipper<RoiContainer>>> exec(
     Zipper<Map<Integer, MZipper<RoiContainer>>> z, int frame) {
   JFileChooser fc = new JFileChooser();
   int returnVal = fc.showOpenDialog(WindowManager.getCurrentWindow().getCanvas());
   Map<Integer, MZipper<RoiContainer>> newRois;
   if (returnVal == JFileChooser.APPROVE_OPTION) {
     try {
       FileInputStream f = new FileInputStream(fc.getSelectedFile().getCanonicalPath());
       MroiLisp parser = new MroiLisp(f);
       parser.ReInit(f);
       newRois = parser.roiFile();
       //				z.rights.clear();
       //				z.rights.add(newRois);
       //				z = z.right();
       //				return z;
       return z.insertAndStep(newRois);
     } catch (IOException e) {
       IJ.error("Couldn't open from " + fc.getSelectedFile().getName() + ": " + e.getMessage());
     } catch (mroi.ParseException e) {
       IJ.error("Failed in parsing: " + e.getMessage());
     } catch (Exception e) {
       IJ.error("Malformed input file: " + e.getMessage());
     }
   }
   return z;
 }
 boolean init_functions() {
   GenericDialog gd = new GenericDialog("Fitting Options");
   gd.addStringField("Extra Definitions", exdef, 50);
   gd.addCheckbox("Weight Using Plot Errors", false);
   gd.addStringField("Weighting Equation (y is for data)", weightfunction, 50);
   gd.addStringField("Fit_Equation", function, 50);
   gd.showDialog();
   if (gd.wasCanceled()) {
     return false;
   }
   exdef = gd.getNextString();
   boolean errweights = gd.getNextBoolean();
   weightfunction = gd.getNextString();
   function = gd.getNextString();
   // first initialize the weights
   weights = new float[tempdata.length];
   if (errweights
       || weightfunction.equals("")
       || weightfunction == null
       || weightfunction == "1.0") {
     if (errweights) {
       for (int i = 0; i < tempdata.length; i++) weights[i] = 1.0f / (errs[i] * errs[i]);
     } else {
       for (int i = 0; i < tempdata.length; i++) weights[i] = 1.0f;
     }
   } else {
     for (int i = 0; i < tempdata.length; i++) {
       String script =
           "y =" + tempdata[i] + "; " + "x =" + tempx[i] + "; " + "retval=" + weightfunction + ";";
       Double temp = new Double(0.0);
       try {
         temp = (Double) engine.eval(script);
       } catch (Exception e) {
         IJ.log(e.getMessage());
       }
       if (!(temp.isInfinite() || temp.isNaN())) {
         weights[i] = temp.floatValue();
       }
     }
   }
   // now compile the function script
   try {
     String script1 = exdef + "; retval=" + function + ";";
     cs = ce.compile(script1);
   } catch (Exception e) {
     IJ.log(e.toString());
     return false;
   }
   return true;
 }
Beispiel #5
0
 /** Reads the pixel data from an image described by a FileInfo object. */
 Object readPixels(FileInfo fi) {
   Object pixels = null;
   try {
     InputStream is = createInputStream(fi);
     if (is == null) return null;
     ImageReader reader = new ImageReader(fi);
     pixels = reader.readPixels(is);
     minValue = reader.min;
     maxValue = reader.max;
     is.close();
   } catch (Exception e) {
     if (!Macro.MACRO_CANCELED.equals(e.getMessage())) IJ.handleException(e);
   }
   return pixels;
 }
 String open(String path) {
   if (path == null) return null;
   try {
     StringBuffer sb = new StringBuffer(5000);
     BufferedReader r = new BufferedReader(new FileReader(path));
     while (true) {
       String s = r.readLine();
       if (s == null) break;
       else sb.append(s + "\n");
     }
     r.close();
     return new String(sb);
   } catch (Exception e) {
     IJ.error(e.getMessage());
     return null;
   }
 }
Beispiel #7
0
  public void run(String arg) {
    boolean display = false;
    File test = new File(arg);
    display = !test.exists();
    OpenDialog od = new OpenDialog("Open mkt file...", arg);
    if (od != null) {
      String file = od.getFileName();
      if (file == null) return;
      String directory = od.getDirectory();
      directory = directory.replace('\\', '/'); // Windows safe
      if (!directory.endsWith("/")) directory += "/";
      arg = directory + file;
    }

    try {
      FileProjectionSource fileSource = new MKTProjectionSource();

      fileSource.initStream(arg);
      ImagePlusDataSink sink = new ImagePlusDataSink();
      Grid2D imp = fileSource.getNextProjection();
      int i = 0;
      while (imp != null) {
        sink.process(imp, i);
        i++;
        imp = fileSource.getNextProjection();
      }
      sink.close();
      setStack(ImageUtil.wrapGrid3D(sink.getResult(), "").getStack());
      setTitle(new File(arg).getName());
      fileSource.close();
      if (display) show();

    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }