/** * */ package analyze; import java.awt.*; import java.awt.geom.*; import javax.swing.*; //FrontEnd Imports import io.*; /** * @author John Krantz * */ public class PlotDiff extends JPanel { static final long serialVersionUID = 0; // data arrays private double [][] diffs; // input array // with the activity of all cells private Rectangle2D [][] rfArray; // array of plotting // rectangles // drawing flags private boolean showGrid = true; // scaling parameter private double scale = 1.0; // allow image to be changes in size // 1.0 means that the image is the best fit to the screen. private Point start = new Point (0,0); // upper left corner of the drawing private boolean center = true; // set if want to center the image // will always center if image is smaller than screen. // Assistant Plotting objects // use the plot dog, I think it will do the trick private PlotDOG plotAct = new PlotDOG(); // need to generate an output eventually private SaveFile save = new SaveFile(); /** * */ public PlotDiff() { super(); } public void paint(Graphics g){ Graphics2D g2d = (Graphics2D)g; // clear the screen white as a background g2d.setPaint(Color.black); int width = getWidth(); int height = this.getHeight(); g2d.fill(new Rectangle(0,0,width,height)); if (diffs != null){ rfArray = new Rectangle2D[diffs.length][diffs[0].length]; // determine box size, want steps // the same size in x and y so need smallest int yStep = height/diffs.length; int xStep = width/diffs[0].length; // use the smaller int step = yStep; if (xStep < yStep) step = xStep; // scale the step step = (int)Math.round((double)step*scale); // determine the upper left corner. if appropriate double top = start.y; double left = start.x; if (center | scale <= 1.0){ top = (double)height/2.0-((double)step* (double)diffs.length/2.0); left = (double)width/2.0-((double)step* (double)diffs[0].length/2.0); start.x = (int)left; start.y = (int)top; } start.setLocation(new Point((int)left,(int)top)); // outline the drawing area in light blue g2d.setPaint(new Color(128,128,255)); g2d.draw(new Rectangle2D.Double(left,top, step*diffs[0].length, step*diffs.length)); // create the RF array // and extract the 2d retinal response array for (int y = 0; y < diffs.length; y ++){ for (int x = 0; x < diffs[0].length; x ++){ rfArray[y][x] = new Rectangle2D.Double( left+x*step,top+y*step, step,step); } } plotAct.plotDOG(g2d, rfArray, diffs); if (showGrid){ g2d.setPaint(Color.darkGray); g2d.setStroke(new BasicStroke(1.0f)); for (int y = 0; y < rfArray.length; y ++){ for (int x = 0; x < rfArray[0].length; x ++){ g2d.draw(rfArray[y][x]); } } } // end if showGrid } } // end paint // plot methods /** * Save the image plotted data for the simple cell, * the first array is the orientation plotted * the second is some measure of activity * @param directory * @param summary * @return */ public String SaveDiffData(String directory, String summary){ // add dividers save.setFlipVertical(false); directory = save.saveDiff(diffs, summary, directory); return directory; } // set methods /** * Set the column data * @param double [][][] cols the column data */ public void setDifferences(double [][] differences){ if (diffs != null){ if (differences.length != diffs.length | differences[0].length != diffs[0].length){ rfArray = null; } } diffs = differences; } /** * Determine if the grid is to be shown and repaint afterwards * @param boolean b flag, true to show. */ public void setShowGrid(boolean b){ showGrid = b; repaint(); } /** * Change the drawing scale so that people can zoom * in to a region of the output * @param double sc - the scale relative to the best * fit to the screen (1.0). */ public void setDrawScale(double sc){ scale = (sc > 0 ? sc : scale); } /** * set true to center an image. *@param boolean b flag true to center the image. */ public void setCenter(boolean b){ center = b; } public void moveFigure(int xMove, int yMove){ start.x += xMove; start.y += yMove; center = false; } // get methods /** * Return the plotting array to allow summarizing * of point * @return Rectangle2D [][] the receptive field array */ public Rectangle2D[][] getRFArray(){ return rfArray; } public double getDrawScale() { return scale; } public boolean getShowGrid() { return showGrid; } }