/** * */ package output; import java.awt.*; import java.awt.geom.*; import java.awt.event.*; import java.io.*; import java.text.*; import javax.swing.*; import javax.swing.event.*; import javax.imageio.*; // FrontEnd import analyze.*; //import io.*; import image.create.*; import model.*; import model.color.ColorConst; import util.*; import gui.*; /** * @author John Krantz * */ public class Analyze { static final long serialVersionUID = 0; // public MainFrame wf = new MainFrame("Visual Front End Data Analysis"); private Container c = wf.getContentPane(); // panels private JPanel inputPanel = new JPanel(new BorderLayout()); private JPanel dataPanel = new JPanel(new BorderLayout()); private JPanel modelSumPanel = new JPanel(new GridLayout(16,1)); private JPanel summaryPanel = new JPanel(new GridLayout(16,1)); private JPanel controlPanel = new JPanel(); // file opener object private JFileChooser fileChooser; private ProcessImage model = new ProcessImage(this); private boolean showFile = true; // image creator objects private MainFrame image = new MainFrame("Image Creator/Grabber",360,700); private CreateImage createImage; private JButton imageGrab = new JButton("Grab Image"); // tool bar objects private JButton openImage = new JButton("Open Image"); // private JButton openFile = new JButton("Open Data"); // private JButton getModelData = new JButton("Get Model"); private JButton plotButton = new JButton("Plot"); private JCheckBox segmentCBX = new JCheckBox("Segment"); private JLabel clickMeans = new JLabel(" Click: "); private JCheckBox getData = new JCheckBox("Show Data", false); private JCheckBox scale = new JCheckBox("Scale",true); private boolean doScale = true; private JButton restoreButton = new JButton("100%"); // flags // private boolean newImage = false; // private boolean dataReady = false; // picture movement objects private JButton centerButton = new JButton("Center"); private int startX = 0; private int startY = 0; private JPanel channelPanel = new JPanel(); private JLabel channelLabel = new JLabel("Color Opponent Channel"); private JComboBox channelCBX = new JComboBox(ColorConst.OPPONENT_CHANNELS); private JPanel orientPanel = new JPanel(); private JLabel orientLabel = new JLabel("Orientation to Display: "); private JComboBox orientCBX; // data objects private Rectangle2D [][] rfArray; // model summary objects private JLabel modelLabel = new JLabel("Current model cell is: "); private JLabel nameLabel = new JLabel(ModelConst.CELL_NAMES[ModelConst.SIMPLE_CELL]); private JLabel stepLabel = new JLabel(ModelConst.STEP_NAME); private JLabel sep0 = new JLabel("---------------------"); private JLabel paramLabel [] = new JLabel[ModelConst.MAX_PARAM]; private JLabel paramValLabel [] = new JLabel[ModelConst.MAX_PARAM]; private JLabel sep2 = new JLabel("---------------------"); private JLabel eyeJitterLabel = new JLabel("Eye Jitter Parameters"); private JLabel jitterMaxLabel = new JLabel("Maximum Jitter Step = "+model.getJitterMax()); private JLabel jitterNumLabel = new JLabel("Number of times = "+model.getNumJit()); private JLabel infoLabel = new JLabel("White = excite; Magenta = inhib"); private JLabel angleLabel = new JLabel("Cyan = Pos; Orange = Neg"); // data analysis object private Summarize sum = new Summarize(); // summary output objects //private DecimalFormat d0 = new DecimalFormat("0"); private DecimalFormat d2 = new DecimalFormat("0.00"); private JLabel fileSum = new JLabel("File Summary"); private JLabel maxAct = new JLabel("Max act = "); private JLabel maxNegAct = new JLabel("Max Neg act = "); private JLabel meanAct = new JLabel("Mean act = "); private JLabel stdAct = new JLabel("std dev = "); private JLabel meanPosAct = new JLabel("Mean Pos act = "); private JLabel stdPosAct = new JLabel("std dev = "); private JLabel meanNegAct = new JLabel("Mean Neg act = "); private JLabel stdNegAct = new JLabel("std dev = "); private JLabel meanMean = new JLabel("Pos/Neg not include 0"); private JLabel sep1 = new JLabel("---------------------"); private JLabel threshSet = new JLabel("Threshold Settings"); private JLabel thresholdLabel = new JLabel("Threshold = "); private JLabel actThreshLabel = new JLabel("Range Threshold = "); private JLabel changeThreshLabel = new JLabel("Change Threshold = "); private double thresh = 0; private double rangeThresh = 0; private double changeThresh = 0; // data as 2d array // private double [][] flatData = new double [0][0]; // data in columns private double [][][] columns; private double [][][] simpleCells; private double [][][] dogCells; private boolean [] modelDone = {false,false}; // the data file private File inputFile; // private FileReader fr; // file parameters private String directory = ""; // data analysis and plotting objects private PlotOutput plot = new PlotOutput(); // menus and tools // Menu creator Menus menu; private JButton output = new JButton("Save"); // Analysis Type Menu private int analysisType = PlotOutput.CHANGE_AND_ACT3; // plotting parameters change objects private ParameterFrame thresholds; private DialogFrame weights; // objects for drawing options private JCheckBox showGridCBX = new JCheckBox("Show Grid"); private JCheckBox weightLinesCBX = new JCheckBox("Weight Lines"); private JCheckBox weightFromThreshCBX = new JCheckBox("Weight From Threshold"); private JCheckBox weightAngleCBX = new JCheckBox("Weight Angles"); private JCheckBox autoThreshCBX = new JCheckBox("Autothresholds"); private JLabel autoThreshTypeLabel = new JLabel("Method Thresholds Selected"); private JComboBox autoThreshTypeCBX = new JComboBox(PlotOutput.OPT_TYPE_NAMES); private JPanel autoThreshTypePanel = new JPanel(new FlowLayout()); private JLabel segRuleLabel = new JLabel("Segmentation Rule"); private String [] segRules = PlotOutput.RULE_DESC; private JComboBox segRuleCBX = new JComboBox(segRules); private JPanel segRulePanel = new JPanel(); private JLabel difRangLabel = new JLabel("Different to Range Proportion"); private JSlider difRangSlider = new JSlider(); private JLabel difRangVal = new JLabel("= "); private JPanel difRangPanel = new JPanel(new BorderLayout()); private Component [] drawOpt = new Component[8]; // objects to change range private JLabel rangeLbl = new JLabel("Range"); private JSlider range = new JSlider(); private JLabel rangeOutput = new JLabel("= 1"); private DialogFrame rangeFrame; // point summary values private int mean = Summarize.MEAN; private int std = Summarize.STDEV; private int max = Summarize.MAX; private int min = Summarize.MIN; private int rng = Summarize.RANGE; private int maxOr = Summarize.MAXORIENT; private int minOr = Summarize.MINORIENT; // output information // location on the grid for getting point data // they can be used for output as well private int y = -1; // default out of bounds private int x = -1; // Analysis Objects CorrelOneImage cGG; DiffPlot diffPlot; /** * */ public Analyze() { super(); doLayout(); } public Analyze(boolean showF) { super(); showFile = showF; doLayout(); } private void doLayout(){ // setup inputpanel JPanel toolboxPanel = new JPanel(new FlowLayout()); toolboxPanel.add(openImage); openImage.setVisible(showFile); // toolboxPanel.add(openFile); // toolboxPanel.add(getModelData); toolboxPanel.add(plotButton); toolboxPanel.add(segmentCBX); toolboxPanel.add(clickMeans); toolboxPanel.add(getData); toolboxPanel.add(scale); toolboxPanel.add(restoreButton); toolboxPanel.add(centerButton); channelPanel.add(channelLabel); channelPanel.add(channelCBX); toolboxPanel.add(channelPanel); channelPanel.setVisible(false); orientCBX = new JComboBox(getOrients()); orientPanel.add(orientLabel); orientPanel.add(orientCBX); toolboxPanel.add(orientPanel); orientPanel.setVisible(false); inputPanel.add(toolboxPanel,BorderLayout.WEST); // setup the data analysis panel dataPanel.add(plot,BorderLayout.CENTER); // setup the control panel segmentCBX.setSelected(false); // getModelData.setEnabled(false); plotButton.setEnabled(false); range.setEnabled(false); output.setEnabled(false); // range setup range.setOrientation(JSlider.HORIZONTAL); range.setMinimum(1);range.setMaximum(20); range.setValue(1); // setup the model summary information panel modelSumPanel.add(modelLabel); nameLabel.setFont(new Font("SansSerif",Font.ITALIC,16)); modelSumPanel.add(nameLabel); modelSumPanel.add(stepLabel); modelSumPanel.add(sep0); for (int i = 0; i < paramLabel.length; i ++){ paramLabel[i] = new JLabel(ModelConst.SIMPLE_PARAM[i]); paramValLabel[i] = new JLabel(" "); modelSumPanel.add(paramLabel[i]); modelSumPanel.add(paramValLabel[i]); } modelSumPanel.add(sep2); modelSumPanel.add(eyeJitterLabel); modelSumPanel.add(jitterMaxLabel); modelSumPanel.add(jitterNumLabel); jitterSumSetVisible(false); modelSumPanel.add(infoLabel); modelSumPanel.add(angleLabel); angleLabel.setVisible(false); // setup the summary panel summaryPanel.add(fileSum); fileSum.setForeground(new Color(110,110,110)); summaryPanel.add(maxAct); summaryPanel.add(maxNegAct); summaryPanel.add(meanAct); summaryPanel.add(stdAct); summaryPanel.add(meanPosAct); summaryPanel.add(stdPosAct); summaryPanel.add(meanNegAct); summaryPanel.add(stdNegAct); summaryPanel.add(meanMean); meanMean.setForeground(new Color(150,0,0)); summaryPanel.add(sep1); summaryPanel.add(threshSet); threshSet.setForeground(new Color(110,110,110)); summaryPanel.add(thresholdLabel); summaryPanel.add(actThreshLabel); summaryPanel.add(changeThreshLabel); // set up the range slider. difRangSlider.setMaximum(200); // set up the panels c.add(inputPanel,BorderLayout.NORTH); c.add(dataPanel,BorderLayout.CENTER); c.add(controlPanel,BorderLayout.SOUTH); c.add(modelSumPanel,BorderLayout.WEST); c.add(summaryPanel,BorderLayout.EAST); // set defaults plot.setThreshold(3.0); plot.setRangeThreshold(3.0); plot.setChangeThreshold(0.1); thresh = 3.0; rangeThresh = 3.0; changeThresh = 0.1; updateThreshLabel(); updateModelInfo(); changeTitle(); // set up the menu menu = new Menus(wf, this); menu.enableModel(false); menu.enableSettings(false); // create the change threshold window String names [] = {"Activity Threshold", "Range Threshod", "Change Threshold"}; String defaults [] = new String [3]; defaults[0] = ""+thresh; defaults[1] = ""+rangeThresh; defaults[2] = ""+changeThresh; setupListeners(); // create the window thresholds = new ParameterFrame("Set Threshold Values", names,defaults,this); } private String [] getOrients(){ String [] orients = new String[model.getNumOrientations()]; for (int i = 0; i < orients.length; i ++){ orients[i] = ""+(double)i*180.0/ (double)model.getNumOrientations(); } return orients; } public void startAnalysis(){ wf.setVisible(true); plot.repaint(); } private void jitterSumSetVisible(boolean b){ sep2.setVisible(b); eyeJitterLabel.setVisible(b); jitterMaxLabel.setVisible(b); jitterNumLabel.setVisible(b); } private void setupListeners(){ // tool box listeners openImage.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ getImage(); } }); // openFile.addActionListener(new ActionListener(){ // public void actionPerformed(ActionEvent e){ // getFile(); // } // }); // get the model data from an image that has been opened /* getModelData.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ arrangeImageData(model.getProcessedData()); summarize(); } }); */ imageGrab.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ model.setImage(createImage.getImage(),createImage.getName()); System.gc(); plotButton.setEnabled(true); menu.enableModel(true); } }); // listeners for plotting buttons plotButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ runModel(); showPlot(); } }); // end plot peaks button listener // listener to the mouse click check boxes getData.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if (!getData.isSelected()){ getData.setSelected(true); } if (scale.isSelected()){ scale.setSelected(false); doScale = false; } } }); scale.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if (!scale.isSelected()){ scale.setSelected(true); } if (getData.isSelected()){ getData.setSelected(false); doScale = true; } } }); restoreButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ plot.setDrawScale(1.0); plot.setCenter(true); plot.repaint(); } }); centerButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ plot.setCenter(true); plot.repaint(); } }); plot.addMouseListener(new MouseListener(){ public void mouseClicked(MouseEvent e){ if (doScale){// change the scale of the image double curScale = plot.getDrawScale(); if (e.getButton()==MouseEvent.BUTTON1){ curScale = curScale*1.25; } else { curScale = curScale/1.25; if (curScale < 0.5) curScale = 0.5; } plot.setDrawScale(curScale); plot.repaint(); } } public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mousePressed(MouseEvent e){ if (doScale){ // get the starting location of the mouse // during dragging startX = e.getX(); startY = e.getY(); } else { // get data and determine location to // get output y = -1; // default out of bounds x = -1; showOutput(); if (rfArray != null){ // give summary data for a single location output.setEnabled(true); // allow to save data now. // first determine which column for (int i = 0; i < rfArray.length; i ++){ for (int j = 0; j < rfArray[0].length; j ++){ if (rfArray[i][j].contains(e.getX(), e.getY())){ y = i; x = j; } // end checking if clicked in box } // end j } // end i showPointSum(x,y); plot.grabFocus(); } } } public void mouseReleased(MouseEvent e){} });// end peaks mouse listener // plot mouse motion listener plot.addMouseMotionListener(new MouseMotionListener(){ public void mouseMoved(MouseEvent e){} public void mouseDragged(MouseEvent e){ if (doScale){ int curX = e.getX(); int curY = e.getY(); int moveX = curX - startX; int moveY = curY - startY; startX = curX; startY = curY; plot.moveFigure(moveX, moveY); plot.repaint(); } } }); // end plot mouse motion listener // change the range for detecting maxima and minima range.addChangeListener(new ChangeListener(){ public void stateChanged(ChangeEvent e){ if (range.isEnabled()) rangeOutput.setText("= "+range.getValue()); } }); // dif range slider listener difRangSlider.addChangeListener(new ChangeListener(){ public void stateChanged(ChangeEvent e){ difRangVal.setText("= " + (double)difRangSlider.getValue()/100.0); } }); // listener to pick channel to plot channelCBX.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ showPlot(); } }); }// end setup listeners // show the summary information for a point on the screen private void showPointSum(int x, int y){ // now if in one of the boxes, report summary if (x != -1 & y != -1){ if (model.getCurrentCell() == ModelConst.SIMPLE_CELL){ double [] s = sum.getPointSummary(y,x); String st = "Summary Simple Cell Values for x = "+x; st += " y = "+y+"\n"; st += "mean = "+d2.format(s[mean])+" : "; st += "s = "+d2.format(s[std])+"\n"; st += "Max = "+d2.format(s[max])+" : "; st += "Orient= "+d2.format(s[maxOr])+"\n"; st += "Min = "+d2.format(s[min])+" : "; st += "Orient= "+d2.format(s[minOr])+"\n"; st += "Range = "+d2.format(s[rng]); JOptionPane.showMessageDialog(null,st, "Point Summary for Simple Cell Results", JOptionPane.PLAIN_MESSAGE); } // show simple cell summary else { // dog sell summary String st = "Summary DOG Cell Values for x = "+x; st += " y = "+y+"\n"; st += "Achromatic = "+ d2.format(dogCells[y][x][ColorConst.BL_WH])+"\n"; st += "Red/Green = "+ d2.format(dogCells[y][x][ColorConst.R_G])+"\n"; st += "Blue/Yellow = "+ d2.format(dogCells[y][x][ColorConst.B_Y])+"\n"; JOptionPane.showMessageDialog(null,st, "Point Summary for DOG Cell Results", JOptionPane.PLAIN_MESSAGE); } } } // file menu's methods // not using for now /* public void getFile(){ // clear out the system a bit inputFile = null; fileChooser = null; System.gc(); fileChooser = new JFileChooser(); JFrame chooserFrame = new JFrame("Open Data File"); fileChooser.setDialogTitle("Read Model Data File"); fileChooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES); File dflt = new File("*.txt"); fileChooser.setSelectedFile(dflt); int result = fileChooser.showOpenDialog(chooserFrame); chooserFrame.setVisible(true); chooserFrame.setVisible(false); // user hit cancel button if (result == JFileChooser.CANCEL_OPTION){ inputFile = null; } else { rfArray = null; inputFile = fileChooser.getSelectedFile(); changeTitle(); // try to open the file try { fr = new FileReader(inputFile); directory = inputFile.getAbsolutePath(); readData(); } catch (IOException er){ JOptionPane.showMessageDialog(null, "Error Opening File\n"+ er.getMessage(), "Open Error", JOptionPane.ERROR_MESSAGE); } } } */ // open an image to analyze public void getImage(){ inputFile = null; Image source = null; fileChooser = null; System.gc(); fileChooser = new JFileChooser(); if (directory != ""){ fileChooser.setCurrentDirectory( new File(directory)); } plotButton.setEnabled(false); menu.enableModel(false); JFrame chooserFrame = new JFrame("Open Image File"); fileChooser.setDialogTitle("Open Image File"); fileChooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES); int result = fileChooser.showOpenDialog(chooserFrame); chooserFrame.setVisible(true); chooserFrame.setVisible(false); // user hit cancel button if (result == JFileChooser.CANCEL_OPTION){ inputFile = null; } else { inputFile = fileChooser.getSelectedFile(); // try to open the file try { source = ImageIO.read(inputFile); directory = inputFile.getAbsolutePath(); model.setDirectory(directory); model.setImage(source,inputFile.getName(),2,2); source = null; System.gc(); plotButton.setEnabled(true); menu.enableModel(true); } catch (IOException er){ JOptionPane.showMessageDialog(null, "Error Opening File\n"+ er.getMessage(), "Open Error", JOptionPane.ERROR_MESSAGE); } } } public void saveCortex(){ plot.SaveCortexData(directory,createSummary()); plot.grabFocus(); } public void saveCell(){ plot.saveProcessedData(directory,createSummary()); plot.grabFocus(); } public String createSummary(){ String s = "ModelCell: " + ModelConst.CELL_NAMES[model.getCurrentCell()]+"\n"; if (model.getCurrentCell()==ModelConst.SIMPLE_CELL){ s += "StandardDeviation: "+model.getSimpleParam()[0]+"\n"; s += "Phase: "+model.getSimpleParam()[1]+"\n"; s += "PlotType: "+PlotOutput.ANANAMES[plot.getSimplePlotType()]+"\n"; } else { s += "ExcitStandardDeviation: "+model.getDOGParam()[0]+"\n"; s += "InhibStandardDeviation: "+model.getDOGParam()[1]+"\n"; } if (model.getEyeJitter()){ s += "ModelEyeJitter\n"; s += "JitterMax: "+model.getJitterMax(); s += "NumJitter: "+model.getNumJit(); } s += "\n\n"; return s; } // image menu methods public void createImage(CreateImage create){ createImage = create; Container cI = image.getContentPane(); cI.removeAll(); cI.add(createImage, BorderLayout.CENTER); cI.add(createImage.getControlPanel(),BorderLayout.SOUTH); JPanel igPanel = new JPanel(); igPanel.add(imageGrab); cI.add(igPanel,BorderLayout.NORTH); image.setVisible(true); int height = createImage.getHeight(); int width = image.getWidth(); height += createImage.getControlPanel().getHeight(); height += 2*igPanel.getHeight(); image.setSize(width,height); } // Model menu methods public void setCellModel(){ model.setCellType(); enableAnalysis(); } public void setCellModel(int modelCell){ model.setCellType(modelCell); enableAnalysis(); if (modelCell == ModelConst.SIMPLE_CELL){ columns = simpleCells; } else { columns=dogCells; } } public void enableAnalysis(){ if (model.getCurrentCell() == ModelConst.SIMPLE_CELL){ menu.enableAnalysis(true); } else { menu.enableAnalysis(false); } } public void setParameters(){ model.setParameters(); } public void runModel(){ if (!modelDone[model.getCurrentCell()]){ if (orientPanel.isVisible()){ showOrientMenu(); } model.runModel(); } showPlot(); } // Gabor display type menu method public void setGaborDisp(int typeVal){ analysisType = typeVal; if (analysisType == PlotOutput.SINGLE_ORIENT){ showOrientMenu(); } else { orientPanel.setVisible(false); } changeTitle(); updateModelInfo(); showPlot(); } private void showOrientMenu(){ orientPanel.setVisible(false); orientPanel.remove(orientCBX); orientCBX = null; System.gc(); String orients [] = getOrients(); orientCBX = new JComboBox(orients); orientPanel.add(orientCBX); plot.setCurrentOrientation(0); orientPanel.setVisible(true); // listener to pick an orient to plot orientCBX.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ plot.setCurrentOrientation(orientCBX.getSelectedIndex()); showPlot(); } }); } // settings menu's methods public void changeThresholds(){ if (!plot.getThresholdsAutomatically()){ // String names [] = {"Activity Threshold", // "Range Threshod", "Change Threshold"}; String defaults [] = new String [3]; defaults[0] = ""+thresh; defaults[1] = ""+rangeThresh; defaults[2] = ""+changeThresh; thresholds.setParamValues(defaults); thresholds.setVisible(true); } // if if not doing autothresholds } public void changeDrawingOptions(){ // create the window autoThreshTypePanel.add(autoThreshTypeLabel); autoThreshTypePanel.add(autoThreshTypeCBX); showGridCBX.setSelected(plot.getShowGrid()); weightLinesCBX.setSelected(plot.getWeightLines()); weightFromThreshCBX.setSelected(plot.getWeightFromThresh()); weightAngleCBX.setSelected(plot.getWeightAngles()); autoThreshCBX.setSelected(plot.getThresholdsAutomatically()); autoThreshTypeCBX.setSelectedIndex(plot.getThreshOptType()); difRangPanel.add(difRangLabel,BorderLayout.NORTH); difRangPanel.add(difRangSlider,BorderLayout.CENTER); difRangPanel.add(difRangVal,BorderLayout.EAST); difRangSlider.setValue((int)(plot.getDifToRangeWeight()*100.0)); difRangVal.setText("= " + (double)difRangSlider.getValue()/100.0); segRulePanel.add(segRuleLabel); segRulePanel.add(segRuleCBX); drawOpt[0] = showGridCBX; drawOpt[1] = weightLinesCBX; drawOpt[2] = weightFromThreshCBX; drawOpt[3] = weightAngleCBX; drawOpt[4] = autoThreshCBX; drawOpt[5] = autoThreshTypePanel; drawOpt[6] = difRangPanel; drawOpt[7] = segRulePanel; weights = new DialogFrame("Drawing Options", drawOpt); weights.setVisible(true); // read the thresholds setting panel's apply button weights.applyButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ updateDrawOpt(); } }); // read the thresholds setting panel's done button weights.doneButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ updateDrawOpt(); weights.setVisible(false); } }); } private void updateDrawOpt(){ plot.setShowGrid(showGridCBX.isSelected()); plot.setWeightLines(weightLinesCBX.isSelected()); plot.setWeightFromThresh(weightFromThreshCBX.isSelected()); plot.setWeightAngles(weightAngleCBX.isSelected()); plot.setThresholdsAutomatically(autoThreshCBX.isSelected()); plot.setOptimizeThresholdType(autoThreshTypeCBX.getSelectedIndex()); plot.setDifToRangeWeight((double)difRangSlider.getValue()/100.0); plot.setSegmetRule(segRuleCBX.getSelectedIndex()); // if thresholds are to be determined automatically // hid all of the threshold options and // turn off threshold dialog box sep1.setVisible(!plot.getThresholdsAutomatically()); threshSet.setVisible(!plot.getThresholdsAutomatically()); thresholdLabel.setVisible(!plot.getThresholdsAutomatically()); actThreshLabel.setVisible(!plot.getThresholdsAutomatically()); changeThreshLabel.setVisible(!plot.getThresholdsAutomatically()); updateThreshLabel(); plot.repaint(); } public void changeRange(){ JPanel out1 = new JPanel(new FlowLayout()); out1.add(rangeLbl); out1.add(range); out1.add(rangeOutput); Component [] vals = {out1}; rangeFrame = new DialogFrame( "Change Range", vals); rangeFrame.setVisible(true); rangeFrame.applyButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if (range.isEnabled()) { rangeOutput.setText("= "+range.getValue()); plot.setChangeRange(range.getValue()); plot.repaint(); } } }); rangeFrame.doneButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if (range.isEnabled()) { rangeOutput.setText("= "+range.getValue()); plot.setChangeRange(range.getValue()); plot.repaint(); } rangeFrame.setVisible(false); } }); } private void updateThreshLabel(){ plot.setThreshold(thresh); plot.setRangeThreshold(rangeThresh); plot.setChangeThreshold(changeThresh); thresholdLabel.setText("Threshold = "+thresh); actThreshLabel.setText("Range Threshold = " + rangeThresh); changeThreshLabel.setText("Change Threshold = " + changeThresh); } // Analysis Menu Methods public void correlWithin(){ // only launch the correlation routine if // the simple cell model has been run. if (modelDone[ModelConst.SIMPLE_CELL] & modelDone[ModelConst.DOG_CELL]){ cGG = new CorrelOneImage(simpleCells,dogCells); } else { String s = "You need to run both the Simple Cell\nand Dog Cell models first."; JOptionPane.showMessageDialog(null, s,"Model Run Error", JOptionPane.ERROR_MESSAGE); } } public void diffPlot(){ // only launch the correlation routine if // the simple cell model has been run. if (modelDone[ModelConst.SIMPLE_CELL] & modelDone[ModelConst.DOG_CELL]){ diffPlot = new DiffPlot(simpleCells,dogCells); diffPlot.setDirectory(directory); } else{ String s = "You need to run both the Simple Cell\nand Dog Cell models first."; JOptionPane.showMessageDialog(null, s,"Model Run Error", JOptionPane.ERROR_MESSAGE); } } // plotting methods public void showPlot(){ if (!modelDone[model.getCurrentCell()]){ arrangeImageData(model.getProcessedData()); } summarize(); String [] vals = thresholds.getParameters(); thresh = Double.parseDouble(vals[0]); rangeThresh = Double.parseDouble(vals[1]); changeThresh = Double.parseDouble(vals[2]); updateThreshLabel(); showOutput(); } private void showOutput(){ changeTitle(); plot.setCurrentModelCell(model.getCurrentCell()); plot.setCurrentDOGChannel(channelCBX.getSelectedIndex()); plot.setDrawSegmentedObjects(segmentCBX.isSelected()); plot.setCellData(columns); plot.setNumOrientation(model.getNumOrientations()); plot.setChangeRange(range.getValue()); rfArray = null; rfArray = plot.plot(analysisType); updateModelInfo(); } private void changeTitle(){ String s = model.getCurrentModelCell()+" : "; if (inputFile != null){ s += inputFile.getName()+" : "; } if (analysisType != 0 & model.getCurrentModelCell()== ModelConst.CELL_NAMES[ModelConst.SIMPLE_CELL]){ s += PlotOutput.ANANAMES[analysisType]+ " : "; } s += "Visual Front End Data Analysis"; wf.setTitle(s); } // not using for now /* // now read the data private void readData(){ flatData = new double [0][0];// clear old data char c[] = new char[1]; // character read from file String valString = ""; // String holding a number in // the file Character space = new Character(' '); // how to track // spaces as separators between numbers in the files. // these are the delimiters char cr = Character.LINE_SEPARATOR; // flag to indicate the end of the line double tempVal = 0; // one value that has be read in from the file. double [] row = new double [0]; // one row in the file try { // -1 equal end of file flag while (fr.read(c) != -1){ // add a character to the current value being read if (c[0] != space.charValue() & c[0] != cr){ valString += c[0]; } else { // if done add to the current row if (valString.length()> 0){ tempVal = Double.parseDouble( valString); // JOptionPane.showMessageDialog(null, // valString+ " " + tempVal); row = addToRow(row,tempVal); } valString = ""; if (c[0] == cr){ // if end of row, add it to the // flat array. // JOptionPane.showMessageDialog(null, // "carriage return"); addRow(row); row = new double [0]; } } } // data is in, put them into the proper arrangement arrangeColumns(); } catch (IOException e){ JOptionPane.showMessageDialog(null, "Error Reading File\n"+ e.getMessage(), "Read Error", JOptionPane.ERROR_MESSAGE); } summarize(); } // add an item to the row. private double [] addToRow(double [] row, double newVal){ double [] tr = new double [row.length]; for (int i = 0; i < tr.length; i ++){ tr[i] = row[i]; } row = new double[tr.length + 1]; for (int i = 0; i < tr.length; i ++){ row[i] = tr[i]; } row[row.length-1] = newVal; return row; } // add a row private void addRow(double [] row){ double [][] temp = new double [flatData.length][]; for (int i = 0; i < temp.length; i ++){ temp[i] = flatData[i]; } flatData = new double[temp.length+1][]; for (int i = 0; i < temp.length; i ++){ flatData[i] = temp[i]; } flatData[flatData.length-1] = row; } // make the columns private void arrangeColumns(){ int numRows = flatData.length/18; columns = new double[numRows] [flatData[0].length] [18]; // arrange the data for (int row = 0; row < columns.length; row ++){ for (int or = 0; or < 18; or ++){ for (int col = 0; col < columns[0].length; col ++){ columns[columns.length-row-1][col][or]= flatData[or*numRows+row][col]; } } } // Inform the user String s = "File has been read\n"; s += "Data Array: Total rows = "+flatData.length; s += " Cols = " + flatData[0].length; s += "\n ActRows = "+ numRows; JOptionPane.showMessageDialog(null,s,"File Loaded", JOptionPane.INFORMATION_MESSAGE); // activate the data analysis objects plotButton.setEnabled(true); range.setEnabled(true); menu.enableSettings(true); output.setEnabled(false); plot.repaint(); } */ // make the columns from data processed from an input image private void arrangeImageData(double [][][] imageData){ // image data is in angle,x,y order // this program does it y,x,angle columns = new double [imageData[0][0].length] [imageData[0].length] [imageData.length]; for (int i = 0; i < columns.length; i ++){ for (int j = 0; j < columns[0].length; j ++){ for (int l = 0; l < columns[0][0].length; l ++){ columns[i][j][l] = imageData[l][j][i]; } } } // save the arranged data if (model.getCurrentCell()==ModelConst.SIMPLE_CELL){ simpleCells = new double [columns.length] [columns[0].length] [columns[0][0].length]; for (int i = 0; i < columns.length; i ++){ for (int j = 0; j < columns[0].length; j ++){ for (int l = 0; l < columns[0][0].length; l ++){ simpleCells[i][j][l] = columns[i][j][l]; } } } } else { dogCells = new double [columns.length] [columns[0].length] [columns[0][0].length]; for (int i = 0; i < columns.length; i ++){ for (int j = 0; j < columns[0].length; j ++){ for (int l = 0; l < columns[0][0].length; l ++){ dogCells[i][j][l] = columns[i][j][l]; } } } } modelDone[model.getCurrentCell()] = true; // activate the data analysis objects plotButton.setEnabled(true); range.setEnabled(true); menu.enableSettings(true); output.setEnabled(false); plot.repaint(); } public void resetModelDone(int model){ modelDone[model] = false; } public void resetCurrentModelDone(){ modelDone[model.getCurrentCell()] = false; } // summarize the data private void summarize(){ sum.setColumns(columns); maxAct.setText("Max act = " +d2.format(sum.getMaxAct())); maxNegAct.setText("Max Neg act = " +d2.format(sum.getMaxNegAct())); meanAct.setText("Mean act = " +d2.format(sum.getMeanAct())); stdAct.setText("std dev = " +d2.format(sum.getStdAct())); meanPosAct.setText("Mean Pos act = " +d2.format(sum.getMeanPosAct())); stdPosAct.setText("std dev = " +d2.format(sum.getStdPosAct())); meanNegAct.setText("Mean Neg act = " +d2.format(sum.getMeanNegAct())); stdNegAct.setText("std dev = " +d2.format(sum.getStdNegAct())); } public void updateModelInfo(){ nameLabel.setText(ModelConst.CELL_NAMES[model.getCurrentCell()]); stepLabel.setText(ModelConst.STEP_NAME+": "+ model.getStep()+ "pxls"); // set up the parameters for the given cell if (model.getCurrentCell() == ModelConst.SIMPLE_CELL){ if (plot.getSimplePlotType() >= PlotOutput.MIN_DIR_TYPE){ angleLabel.setVisible(true); } else { angleLabel.setVisible(false); } if (plot.getSimplePlotType() == PlotOutput.SINGLE_ORIENT){ orientPanel.setVisible(true); } else { orientPanel.setVisible(false); } channelPanel.setVisible(false); for (int i = 0; i < paramLabel.length; i ++){ if (i < ModelConst.SIMPLE_PARAM.length){ paramLabel[i].setText(ModelConst.SIMPLE_PARAM[i]+":"); paramValLabel[i].setText(""+model.getSimpleParam()[i]); if (i == 1){// phase if (model.getSimpleParam()[i] == -1){ // dynamic phase paramValLabel[1].setText("Dynamic"); } } paramLabel[i].setVisible(true); paramValLabel[i].setVisible(true); } else { paramLabel[i].setVisible(false); paramValLabel[i].setVisible(false); } } }// end if simple cell else { angleLabel.setVisible(false); channelPanel.setVisible(true); orientPanel.setVisible(false); for (int i = 0; i < paramLabel.length; i ++){ if (i < ModelConst.DOG_PARAM.length){ paramLabel[i].setText(ModelConst.DOG_PARAM[i]+":"); paramValLabel[i].setText(""+model.getDOGParam()[i]); if (i == ModelConst.DOG_PARAM.length-1){ paramValLabel[i].setText( ColorConst.OPPONENT_CHANNELS[ channelCBX.getSelectedIndex()]); } paramLabel[i].setVisible(true); paramValLabel[i].setVisible(true); } else { paramLabel[i].setVisible(false); paramValLabel[i].setVisible(false); } } }// end if DOG Cell // update common elements // jitter jitterSumSetVisible(model.getEyeJitter()); jitterMaxLabel.setText("Maximum Jitter Step = "+model.getJitterMax()); jitterNumLabel.setText("Number of times = "+model.getNumJit()); } // get methods public boolean getShowFile() { return showFile; } }