/** * */ package analyze; import java.awt.*; import java.awt.geom.*; // Front End Imports import util.*; /** * @author John * */ public class PlotChangeDir { private double negDiff = 0; private double posDiff = 0; // if there is a change of direction at this location // the size of the differens is recorded here private boolean posPeak = false; private boolean negPeak = false; // flag to indicate if peak has been found // flag to indicate the direction of the max or min // private static final int UP_DOWN = 0; // private static final int LEFT_RIGHT = 1; // private static final int POS_DIAG = 2; // private static final int NEG_DIAG = 3; // objects to control asymmetrical private boolean allowAsymmetrical = false; // weight lines flag private boolean weightLines = false; // internal variables double agl = 0; // internal angle in radians int wgt = 0; // weight of line in luminance value // flag to weight the angle private boolean weightAngle = false; WeightAngle wa = new WeightAngle(); double angles [] = {0,10,20,30,40,50,60,70,80,90,100,110,120, 130,140,150,160,170}; int avgRange = 2; public final static int AVG_RANGE_MAX = 5; // tester for max or min MaxMinTest maxMin = new MaxMinTest(); // empty constructor public PlotChangeDir(){} // the painting routine public double [] plotActivity(Graphics2D g2d, // graphics object Rectangle2D [][] rfArray, // array of rectangles double [][][] columns, // the data Summarize sum, // the summary data int y, int x, // the point of interest int range, // range for the testing of the max or min double maxVal, double minVal, // overal max and minimum double limit // the difference must exceed this value ){ double output [] = new double[2]; // output angle then act. output[PlotOutput.ANGLE] = PlotOutput.NO_ANGLE; output[PlotOutput.ACTIVITY] = sum.getPointSummary(y,x)[Summarize.MEAN]; if (y >= range & y < rfArray.length-range & x >= range & x < rfArray[0].length-range){ // clear the differences posDiff = -1; negDiff = -1; negPeak = false; posPeak = false; // find if there is a maximum or minimum at this position // check for positive peak posDiff = maxMin.testAllDirMaxMin(sum, x, y, range, Summarize.MAX, allowAsymmetrical, limit); if (posDiff != -1){ posPeak = true; } // check for negative peak negDiff = maxMin.testAllDirMaxMin(sum, x, y, range, Summarize.MIN, allowAsymmetrical, limit); if (negDiff != -1){ negPeak = true; } // if both a maxima and a minima, take the biggist if (posPeak & negPeak){ if (posDiff >= negDiff) negPeak = false; else posPeak = false; } // debugging //g2d.setPaint(Color.green); //if (x == 84 & y == 72) //g2d.drawString("neg diff = "+negDiff+" pos diff = "+posDiff // +" negPeak = "+negPeak+" posPeak = "+posPeak, // 5,25); if (posPeak | negPeak){ // draw the line g2d.setPaint(Color.CYAN); if (negPeak) g2d.setPaint(new Color(255,75,0)); // find the center of the box double ctrX = rfArray[y][x].getCenterX(); double ctrY = rfArray[y][x].getCenterY(); double hs = rfArray[y][x].getHeight()/2.0; agl = Math.PI* sum.getPointSummary(y, x) [Summarize.MAXORIENT]/ 180.0; if (weightAngle){ agl = Math.PI* wa.getWeightAngle(angles, columns[y][x],avgRange)/ 180.0; } if (negPeak){ agl = Math.PI* sum.getPointSummary(y, x) [Summarize.MINORIENT]/ 180.0; } // determine the weight of the line g2d.setStroke(new BasicStroke(1.0f)); if (weightLines){ wgt = 0; if (posPeak){ wgt = (int)(posDiff/(double)range*10.0+100.0); } else { wgt = (int)(negDiff/(double)range*10.0+100); } if (wgt < 0) wgt = 0; if (wgt > 255) wgt = 255; if (posPeak){ g2d.setPaint(new Color(0,wgt,wgt)); } else { g2d.setPaint(new Color(wgt,wgt,0)); } } // output output[PlotOutput.ANGLE] = 180*agl/Math.PI; if (negPeak) { output[PlotOutput.ANGLE]+=PlotOutput.NEG_OFFSET; } // output[PlotOutput.ACTIVITY] = wgt; // move to the center of the box being drawn g2d.translate(ctrX,ctrY); // rotate the angle g2d.rotate(agl); // draw the line g2d.draw(new Line2D.Double( 0,-hs,0,+hs)); // rotate back g2d.rotate(-agl); // move back to upter left g2d.translate(-ctrX,-ctrY); } // end draing lin }// end if in draw range. // return the output return output; } // set methods public void setAllowAsymmtrical(boolean b){ allowAsymmetrical = b; } public void setWeightLines(boolean b){ weightLines = b; } public void setWeightAngles(boolean b){ weightAngle = b; } // get methods public boolean getPosPeak() { return posPeak; } public boolean getNegPeak() { return negPeak; } }