// BIOP Functions Library /* * Returns the name of the parameters window, as we cannot use global variables, * we just define a function that can act as a global variable */ function getWinTitle() { win_title= toolName(); // If something is already open, keep it as-is. if(!isOpen(win_title)) { run("New... ", "name=["+win_title+"] type=Table"); print("["+win_title+"]", "\\Update0:This window contains data "+win_title+" needs."); print("["+win_title+"]", "\\Update1:Please do not close it."); } return win_title; } /* * Based on an example by Wayne Rasband, we use the "getData" and "setData" functions to * read and write data to and from an opened text window. This allows us to save parameters * for an ActionBar in a visible way for the user, instead of relying on IJ.prefs. */ function getData(key) { winTitle = getWinTitle(); win = "["+winTitle+"]"; selectWindow(winTitle); lines = split(getInfo(),'\n'); i=0; done=false; value = ""; while (!done && i < lines.length) { // The structure for the data is "key : value", so we use a regex to find the key and place ourselves after the " : " if(matches(lines[i], ".*"+key+".*")) { value = substring(lines[i], indexOf(lines[i]," : ")+3,lengthOf(lines[i])); done = true; } else { i++; } } return value; } /* Like getData, but takes a default argument * and returns it if the key is not found */ function getDataD(key, default) { value = getData(key); if (value == "") { return default; } else { return value; } } /* * See Above Comment */ function setData(key, value) { //Open the file and parse the data winTitle = getWinTitle(); win = "["+winTitle+"]"; selectWindow(winTitle); lines = split(getInfo(),'\n'); i=0; done=false; if (lines.length > 0) { while (!done && i < lines.length) { if(matches(lines[i], ".*"+key+".*")) { done=true; } else { i++; } } print(win, "\\Update"+i+":"+key+" : "+value); } else { // The key did not exist print(win, key+" : "+value); } } /* * Setter and getter for boolean values */ function setBool(key, bool) { if (bool) { setData(key, "Yes"); } else { setData(key, "No"); } } function getBool(key) { val = getData(key); if (val == "Yes") { val = true; } else { val=false; } return val; } /* * Functions to read and write from a text file to a parameters window * These are sued by the Save Parameters and Load Parameters Buttons */ function loadParameters() { // Get the file file = File.openDialog("Select Parameters File"); //Get the contents filestr = File.openAsString(file); lines = split(filestr, "\n"); //Open the file and parse the data settingName = getWinTitle();; t = "["+settingName+"]"; // If something is already open, keep it as-is. if(!isOpen(settingName)) { run("New... ", "name="+t+" type=Table"); } selectWindow("Tile Scan Opener Parameters"); for (i=0; i 0) { //Save Roi Set File.makeDirectory(roiDir); roiManager("Save", roiDir+name+".zip"); print("ROI Set Saved for image "+name); } } /* * Saves the current image as a TIFF in the currentImage Folder */ function saveCurrentImage() { name = getTitle(); print(name); dir = getSaveFolder(); print(dir); File.makeDirectory(dir); name = getFileNameNoExt(name); saveAs("TIFF", dir+name+".tif"); } /* * Returns the file name witout the extension */ function getFileNameNoExt(file) { // Get the file name without the extension, regex if (matches(file,".+\\.\\w{3,4}")) { file = substring(file,0,lastIndexOf(file,".")); } return file; }