001    package ui.recognizer;
002    
003    import java.awt.Rectangle;
004    import java.awt.geom.Rectangle2D;
005    
006    /** A class containing plot calibration information necessary for the correct mapping
007     *  from image coordinates to data coordinates.  Plot specific knowlegde such
008     *  as tic borders and tic location and spacing are part of the state.
009     */
010    public class PlotCalibration extends Calibration {
011    
012        // can be more precise than integer pixels by locating the exact center of the border (sub-pixel resolution)
013    
014        /** The tic zone is a 'safe' area without tics in image units.*/
015        protected Rectangle ticZone;
016    
017        /** The tic is the x, y position corresponding to a tic center on both axes and whose width and height is the spacing between tics. */
018        protected Rectangle2D.Double tic;
019    
020        public PlotCalibration(Rectangle aBorder, Rectangle aTicZone,
021                               double xMinimum, double xMaximum, double yMinimum, double yMaximum) {
022            super(aBorder, xMinimum, xMaximum, yMinimum, yMaximum);
023            ticZone = aTicZone;
024        }
025    
026        /** Get the tic zone or a 'safe' area without tics.
027         * This zone should be contained within the border zone however no checks are made.
028         * @return a rectangle in image units
029         */
030        public Rectangle getTicZone() {
031            return ticZone;
032        }
033    
034        /** Set the tic zone or a 'safe' area without tics.
035         * @param aTicZone a rectangle in image units
036         */
037        public void setTicZone(Rectangle aTicZone) {
038            ticZone = aTicZone;
039        }
040    
041        /** Get the axis tics as x-y position and width/height of one tic interval.
042         * The coordinates must be double precision because it is based on an average
043         * which requires subpixel precision to correctly scale after being multiplied by an integer.
044         * The getTic() method is equivalent to getTic(0, 0) but is coded more efficiently.
045         * @return a rectangle whose x, y position corresponds to a tic center on both axes and whose width and height is the spacing between tics.
046         */
047        public Rectangle2D.Double getTic() {
048            return tic;
049        }
050    
051        /** Set the first tic as an x-y position and a width/height of a tic interval.
052         * The coordinates must be double precision because it is based on an average
053         * which requires subpixel precision to correctly scale after being multiplied by an integer.
054         * @param aTic rectangle whose x, y position corresponds to a tic center on both axes and whose width and height is the spacing between tics.
055         */
056        public void setTic(Rectangle2D.Double aTic) {
057            tic = aTic;
058        }
059    
060        /** Get the tic at xTicNumber and yTicNumber in integer units.
061         * @return a rectangle positioned at the chosen tic and with the tic spacing encoded as width and height.
062         */
063    
064        public Rectangle getTic(int xTicNumber, int yTicNumber) {
065            double x = getTic().getX();
066            double y = getTic().getY();
067            double width  = getTic().getWidth();
068            double height = getTic().getHeight();
069            return null;
070    // TODO:
071    //      return (Rectangle) (new Rectangle2D.Double(x + width * (double) xTicNumber,
072    //                                                 y + height* (double) yTicNumber, width, height));
073        }
074    
075    
076    }
077