/** Saves a string as a file. Displays a file save dialog if 'path' is null or blank. Returns an error message if there is an exception, otherwise returns null. */ public static String saveString(String string, String path) { return write(string, path, false); }
/** Appends a string to the end of a file. A newline character ("\n") is added to the end of the string before it is written. Returns an error message if there is an exception, otherwise returns null. */ public static String append(String string, String path) { return write(string+"\n", path, true); }
/** Saves a string as a file. Displays a file save dialog if 'path' is null or blank. Returns an error message if there is an exception, otherwise returns null. */ public static String saveString(String string, String path) { return write(string, path, false); }
/** Appends a string to the end of a file. A newline character ("\n") is added to the end of the string before it is written. Returns an error message if there is an exception, otherwise returns null. */ public static String append(String string, String path) { return write(string+"\n", path, true); }
public static void write(String s) { IJ.write(s); } public static void showProgress(float d) { IJ.showProgress(d); }
private void writefloat(float d, OutputStream s) { byte[] buffer = new byte[4]; int tmp = Float.floatToIntBits(d); buffer[0] = (byte)((tmp>>24)&0xff); buffer[1] = (byte)((tmp>>16)&0xff); buffer[2] = (byte)((tmp>>8)&0xff); buffer[3] = (byte)(tmp&0xff); try {s.write(buffer, 0, buffer.length); } catch (IOException e) {IJ.write("error writing float" + e); return;} } /**
/** Read a flow field (Burkitt format) from a file. */ private float readfloat(InputStream s) { byte[] buffer = new byte[4]; try {s.read(buffer, 0, buffer.length); } catch (IOException e) {IJ.write("error reading float" + e); return (0);} int tmp = (int)(((buffer[0]&0xff)<<24) | ((buffer[1]&0xff)<<16) | ((buffer[2]&0xff)<<8) | (buffer[3]&0xff)); return Float.intBitsToFloat(tmp); } private void writefloat(float d, OutputStream s)
private void getDimensions(String fileName) { InputStream os = null; try {os = new FileInputStream(fileName);} catch (IOException e) {IJ.write("" + e); return;} byte[] buffer = new byte[2*3]; try {os.read(buffer, 0, buffer.length); } catch (IOException e) {IJ.write("" + e); return;} int j = 0; width = (int) (((buffer[j*2]&0xff)<<8) | (buffer[j*2+1]&0xff)); j++; height = (int) (((buffer[j*2]&0xff)<<8) | (buffer[j*2+1]&0xff)); j++; depth = (int) (((buffer[j*2]&0xff)<<8) | (buffer[j*2+1]&0xff)); try {os.close(); } catch (IOException e) {IJ.write("" + e); return;} } private void read(String fileName)
public void decodeImageDescription(byte[] description, FileInfo fi) { imageInfo = new String(description); if (new String (description,0,8).equals("[GLOBAL]")) { if (debugMode) IJ.write ("Leica file detected..." + "\n"); String file_specs = new String (description); fi.info = file_specs; if (debugMode) IJ.write(file_specs); StringTokenizer st = new StringTokenizer(file_specs, "\n= "); while (st.hasMoreTokens()) { String s = st.nextToken(); if (s.equals ("NumOfFrames")) { nr_frames = getInt(st); if (debugMode) IJ.write(nr_channels + " channels detected\n"); } else if (s.equals ("VoxelSizeX")) fi.pixelWidth = getDouble(st); else if (s.equals ("VoxelSizeY")) fi.pixelHeight = getDouble(st); else if (s.equals ("VoxelSizeZ")) fi.pixelDepth = getDouble(st); } } }
/** * Writes a string to an output channel. IJ cannot write if an applet, divert to showStatus instead. * @param s the String that will be output. */ static void write(String s) { if (IJ.getApplet() == null) IJ.write(s); else IJ.showStatus(s); } /**
public static void test() //throws Exception { IJ.write("Testing matrices."); float [][] h = { {1,2,3,4,5},{6,7,8,9,10} }; IJ.write("h = "+BIJutil.toString(h)); float [][] i = transpose(h); IJ.write("i = "+BIJutil.toString(i)); float [][] j = mul(i, h); IJ.write("i*h=j = "+BIJutil.toString(j)); float [][] k = mul(h, i); IJ.write("h*i=k = "+BIJutil.toString(k)); BIJJacobi jac = new BIJJacobi(j); jac.compute(); IJ.write(jac.toString()); } /**
public FileInfo[] getFileInfo(String directory, String name) throws IOException { LeicaTiffDecoder td = new LeicaTiffDecoder(directory, name); if (IJ.debugMode) td.enableDebugging(); FileInfo[] info = td.getTiffInfo(); if (info==null) throw new IOException("This file does not appear to be in " + "TIFF format."); if (IJ.debugMode) // dump tiff tags IJ.write(info[0].info); return info; }
/** * Crop a float image to the rectangular size of a ROI defined by x,y,newwidth,newheight * @param image a float[] vector image * @param width the width in pixels of image * @param height the width in pixels of image * @param x, y, newwidth, newheight the ROI * @return the cropped image as a float[]. */ public static float [] crop(float [] image, int width, int height, int x, int y, int newwidth, int newheight) { // Make an ImageProcessor out of image. ImageProcessor ipp = new FloatProcessor(width, height, image, null); float [] a = null; try { ipp.setRoi(x, y, newwidth, newheight); // Crop the imageprocessor. ipp = ipp.crop(); a = (float []) ipp.getPixels(); } catch (Exception e) { CharArrayWriter c = new CharArrayWriter(); e.printStackTrace(new PrintWriter(c)); IJ.write(c.toString()); } return a; } /**
/** * Renders a view. */ public void newView() { if (! running) IJ.write("newView not initialized!"); renderer.setTransformation(m, mLight); long start = System.currentTimeMillis(); // Render a single view. ImageProcessor ip = renderToImageProcessor(); // Show the rendering in the preset imp. imp.setProcessor(message, ip); long elapsedTime = System.currentTimeMillis() - start; report(elapsedTime); } /**
/** * User pressed mouse button, moved mouse, and released. * Change the view and start rendering. */ public void effectDragging(int dx, int dy) { float roty = distanceToAngle(dy); float rotx = distanceToAngle(dx); if (! (renderView instanceof VJRenderViewInteractive)) IJ.write("VJViewerCanvas error: renderView not initialize"); // X-axis in volume is parellel to y-axis on viewing plane and vv. renderView.rotateInPlane(roty, -rotx); } /**
/** * Access the data in the ImageStack in imp into a float[][] matrix * for further processing. Do not use ROI. * If the is contains float images, does not convert and the float[][] are the actual pixels. * If not, the float[][] are copies of whatever is in the is. * Uses getFloatPixels(ipp.getPixels()), which converts 16-bit images to * @return a float[][] with the images. */ public static float [][] matrixFromImageStack(ImageStack is) { float [][] a = new float[is.getSize()][]; try{ int width = is.getWidth(); int height = is.getHeight(); int x = 0; int y = 0; // Make a matrix out of the images in the stack. for (int i = 0; i < a.length; i++) { ImageProcessor ipp = is.getProcessor(i+1); a[i] = getFloatPixels(ipp.getPixels()); // (float []) (ipp.convertToFloat()).duplicate().getPixels(); } }catch (Exception e) { CharArrayWriter c = new CharArrayWriter(); e.printStackTrace(new PrintWriter(c)); IJ.write(c.toString()); } return a; } public static ImagePlus showVectorAsImage(float [] v, int width)
public void convolvez(VolumeFloat v1) /* "Convolution" without kernel computes the difference for the adjacent slices in v1. */ { if (width < v1.getWidth() || height < v1.getHeight() || depth > v1.getDepth()) IJ.error("convolvez: destination volume wrong size."); if (v1.getDepth() < 2) IJ.error("convolvez: volume depth doesn't fit kernel"); if (v1.edge > edge) edge = v1.edge; IJ.write("z: "+(-depth/2)+"index "+(-depth/2 + depth/2)); for (int z = -depth/2; z < (depth+1)/2; z++) for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) { int index = z + depth/2; v[index][y][x] = v1.v[index+1][y][x]-v1.v[index][y][x]; } } public void convolvez(VolumeFloat v1, Kernel2D kernel)
/** * Rotate the transformation matrix by viewing plane rotation angles rotx, roty. * @param anglex angle in degrees in x direction. * @param angley angle in degrees in y direction. */ public void rotateInPlane(float anglex, float angley) { VJMatrix mm = new VJMatrix(); mm.rotatex(anglex); m.mul(mm); mLight.mul(mm); mm = new VJMatrix(); mm.rotatey(angley); m.mul(mm); IJ.write("rotated by: "+anglex+", "+angley+" starting rendering now..."); newView(); } /**
/** Writes the last row in the system results table to the Results window. */ public void displayResults() { if (rt.columnDeleted()) return; int counter = rt.size(); if (counter==1) IJ.setColumnHeadings(rt.getColumnHeadings()); TextPanel tp = IJ.isResultsWindow()?IJ.getTextPanel():null; int lineCount = tp!=null?IJ.getTextPanel().getLineCount():0; if (counter>lineCount+1) { // delete rt rows added by particle analyzer int n = counter - lineCount - 1; int index = lineCount; for (int i=0; i<n; i++) rt.deleteRow(index); counter = rt.size(); } IJ.write(rt.getRowAsString(counter-1)); }
/** Writes the last row in the system results table to the Results window. */ public void displayResults() { if (rt.columnDeleted()) return; int counter = rt.size(); if (counter==1) IJ.setColumnHeadings(rt.getColumnHeadings()); TextPanel tp = IJ.isResultsWindow()?IJ.getTextPanel():null; int lineCount = tp!=null?IJ.getTextPanel().getLineCount():0; if (counter>lineCount+1) { // delete rt rows added by particle analyzer int n = counter - lineCount - 1; int index = lineCount; for (int i=0; i<n; i++) rt.deleteRow(index); counter = rt.size(); } IJ.write(rt.getRowAsString(counter-1)); }