/** * */ package util; import analyze.Summarize; /** *

This object determines if there is a maximum or a minum * at a given location *

* @author John H. Krantz, Ph.D. * */ public class MaxMinTest { // empty constructor public MaxMinTest(){} // 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; // flag for no peak public static final double NO_PEAK = -1; // all testing for all directions public double testAllDirMaxMin(Summarize sum, int x, int y, int range, int maxMin, boolean allowAsym, double limit){ // find if there is a maximum or minimum at this position double diff = 0; boolean isDiff = false; for (int i = 0; i < 4; i ++){ // check for positive peak double mxDif = isMaxMin(sum, x, y, range, maxMin, allowAsym, limit, i); if (mxDif != -1){ diff += mxDif; isDiff = true; } } if (!isDiff) diff = -1; // flag for no difference return diff; } // is there a maxima or a minimal at this location public double isMaxMin(Summarize sum, int x, int y, int range, int maxMin, boolean allowAsym, double limit, int dir){ double diff = -1;// return flag -1 if no peak // create the array double vals[] = new double [range*2+1]; // now get the data int xMult = 1; int yMult = 0; // these multiplies will get the proper set for each // direction switch (dir){ case UP_DOWN : xMult = 0; yMult = 1; break; case LEFT_RIGHT : xMult = 1; yMult = 0; break; case POS_DIAG : xMult = 1; yMult = 1; break; case NEG_DIAG : xMult = 1; yMult = -1; break; } // get the data for (int i = -range; i <= range; i ++){ vals[i+range]=sum.getPointSummary(y+(i*yMult), x+(i*xMult))[maxMin]; } // if doing minimum, just invert the numbers if (maxMin == Summarize.MIN){ for (int i = 0; i < vals.length; i ++){ vals[i]=-vals[i]; } } // figure out max first using the inverted minima to be // maxima. boolean lowLeg = false; boolean upLeg = false; boolean lowLegSt = false; boolean upLegSt = false; double lLeg = 0; double uLeg = 0; // find the initial values double low = vals[range]-vals[range-1]; double up = vals[range]-vals[range+1]; if(low > limit){ lowLeg = true; lowLegSt = true; lLeg = low; } if (up > limit){ upLeg = true; upLegSt = true; uLeg = up; } // now do the rest of the range if (range > 1 & upLegSt & lowLegSt){ int step = 2; do { low = vals[range]-vals[range-step]; up = vals[range]-vals[range+step]; if(low > limit & lowLeg){ lLeg += low; } else { lowLeg = false; } if (up > limit & upLeg){ uLeg += up; } else { upLeg = false; } step ++; } while ((lowLeg | upLeg) & step <= range); } if (!allowAsym){ // get results from not // asymmetrical model if (lowLeg & upLeg){ diff = lLeg +uLeg; } } else { // asymmetrical models if ((lowLeg & upLegSt) | (lowLegSt & upLeg)){ diff = lLeg + uLeg; } } return diff; } }