import java.awt.*; import java.awt.event.*; import java.awt.SystemColor; import java.io.*; import java.lang.*; import ij.*; import ij.gui.*; import ij.measure.*; import ij.plugin.Converter; import ij.plugin.frame.*; import ij.plugin.filter.*; import ij.plugin.filter.Duplicater; import ij.process.*; import ij.process.StackConverter; import ij.util.*; import ij.util.Tools.*; public class Manual_Tracking extends PlugInFrame implements ActionListener, ItemListener, MouseListener { double calxy=0.166; double calt=2; double dotsize=5; double linewidth=1; static Frame instance; Font bold = new Font("",3,12); Panel panel; TextField caltfield; Choice choicecalt; TextField calxyfield; Choice choicecalxy; TextField dotsizefield; TextField linewidthfield; String imgtitle; Button butAdd; Button butDlp; Button butEnd; Button butDel; Button butDelAll; Choice trackdel; Checkbox checkPath; Button butOvd; Button butOvl; Button butOvdl; Button butOverdots; Button butOverlines; Button butOverboth; int[] xRoi; int[] yRoi; Roi roi; int ox; int oy; int prevx; int prevy; double Distance; double Velocity; int PixVal; boolean islistening=false; ImagePlus img; ImageCanvas canvas; ImagePlus imgRGB; int Nbtrack=1; int i=1; ResultsTable rt; ImageStack stack; ImagePlus ov; Color[] col={Color.blue,Color.green,Color.red,Color.cyan,Color.magenta,Color.yellow,Color.white}; public Manual_Tracking() { //Interface setup ---------------------------------------------------------------------------------------------------------------------------- super ("Tracking"); instance=this; panel = new Panel(); panel.setLayout (new GridLayout (0,3)); panel.setBackground (SystemColor.control); //1st title panel.add (new Label ()); Label title=new Label (); title.setText ("Tracking Parameters:"); title.setFont(bold); panel.add(title); panel.add (new Label ()); //2nd row panel.add (new Label ("Time Interval :")); caltfield = new TextField (Double.toString(calt)); panel.add(caltfield); choicecalt = new Choice(); choicecalt.add("sec"); choicecalt.add("min"); choicecalt.add("unit"); panel.add (choicecalt); //3rd row panel.add (new Label ("Distance calibration :")); calxyfield = new TextField (Double.toString(calxy)); panel.add(calxyfield); choicecalxy = new Choice(); choicecalxy.add("nm"); choicecalxy.add("µm"); choicecalxy.add("unit"); choicecalxy.select("µm"); panel.add (choicecalxy); //4th row butAdd = new Button("Add track"); butAdd.addActionListener (this); panel.add(butAdd); butDlp = new Button("Delete last point"); butDlp.addActionListener (this); panel.add(butDlp); butEnd = new Button("End track"); butEnd.addActionListener (this); panel.add(butEnd); //5th row butDel = new Button("Delete track n°"); butDel.addActionListener (this); panel.add(butDel); trackdel = new Choice(); panel.add (trackdel); butDelAll = new Button("Delete all tracks"); butDelAll.addActionListener (this); panel.add(butDelAll); //6th row panel.add (new Label ()); checkPath=new Checkbox("Show path ?", true); checkPath.addItemListener(this); panel.add(checkPath); panel.add (new Label ()); //Empty row panel.add (new Label ()); panel.add (new Label ()); panel.add (new Label ()); //2nd title panel.add (new Label ()); Label title2=new Label(); title2.setText ("Drawing Parameters:"); title2.setFont(bold); panel.add(title2); panel.add (new Label ()); //9th row panel.add (new Label ("Dot Size :")); dotsizefield = new TextField (Double.toString(dotsize)); panel.add(dotsizefield); panel.add (new Label ()); //10th row panel.add (new Label ("Line width :")); linewidthfield = new TextField (Double.toString(linewidth)); panel.add(linewidthfield); panel.add (new Label ()); //11th row butOvd = new Button("Dots"); butOvd.addActionListener (this); panel.add(butOvd); butOvl = new Button("Progressive Lines"); butOvl.addActionListener (this); panel.add(butOvl); butOvdl = new Button("Dots & Lines"); butOvdl.addActionListener (this); panel.add(butOvdl); //12th row butOverdots = new Button("Overlay Dots"); butOverdots.addActionListener (this); panel.add (butOverdots); butOverlines = new Button("Overlay Lines"); butOverlines.addActionListener (this); panel.add (butOverlines); butOverboth = new Button("Overlay Dots & Lines"); butOverboth.addActionListener (this); panel.add (butOverboth); add(panel,BorderLayout.CENTER); pack(); show(); IJ.showProgress(0); rt=new ResultsTable(); } // Show/Hide the current path----------------------------------------------------------------------------------------------------------------- public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { img.setRoi(roi); } else { img.killRoi(); } } public void actionPerformed(ActionEvent e) { // Button Add Track pressed--------------------------------------------------------------------------------------------------------------- if (e.getSource() == butAdd) { img=WindowManager.getCurrentImage(); xRoi=new int[img.getStackSize()]; yRoi=new int[img.getStackSize()]; if (img==null){ IJ.showMessage("Error", "Man,\n"+"You're in deep troubles:\n"+"no opened stack..."); return; } imgtitle = img.getTitle(); ImageWindow win = img.getWindow(); canvas=win.getCanvas(); img.setSlice(1); calt=Tools.parseDouble(caltfield.getText()); calxy=Tools.parseDouble(calxyfield.getText()); if (calt==0 || calxy==0) { IJ.showMessage("Error", "Calibration values\n"+"should not be equal to zero !!!"); return; } i=1; IJ.showProgress(0); canvas.addMouseListener(this); islistening=true; return; } // Button Delete last point pressed--------------------------------------------------------------------------------------------------------------- if (e.getSource() == butDlp) { GenericDialog gd = new GenericDialog("Delete last point"); gd.addMessage ("Are you sure you want to \n" + "delete last point ?"); gd.showDialog(); if (gd.wasCanceled()) return; //Create a temporary ResultTable and copy only the non deleted data ResultsTable rtmp=new ResultsTable(); for (int j=0; j<(rt.getCounter()); j++) { rtmp.incrementCounter(); for (int k=0; k<7; k++) rtmp.addValue(k, rt.getValue(k,j)); } rt.reset(); //Copy data back to original table except last point String[] head={"Track n°","Slice n°","X","Y","Distance","Velocity","Pixel Value"}; for (int j=0; j