Coverage details for edu.uci.ics.jung.visualization.transform.HyperbolicTransformer

LineHitsSource
1 /*
2  * Copyright (c) 2003, the JUNG Project and the Regents of the University of
3  * California All rights reserved.
4  *
5  * This software is open-source under the BSD license; see either "license.txt"
6  * or http://jung.sourceforge.net/license.txt for a description.
7  *
8  */
9 package edu.uci.ics.jung.visualization.transform;
10  
11 import java.awt.Component;
12 import java.awt.geom.Point2D;
13  
14 /**
15  * HyperbolicTransformer wraps a MutableAffineTransformer and modifies
16  * the transform and inverseTransform methods so that they create a
17  * fisheye projection of the graph points, with points near the
18  * center spread out and points near the edges collapsed onto the
19  * circumference of an ellipse.
20  *
21  * HyperBolicTransformer is not an affine transform, but it uses an
22  * affine transform to cause translation, scaling, rotation, and shearing
23  * while applying a non-affine hyperbolic filter in its transform and
24  * inverseTransform methods.
25  *
26  * @author Tom Nelson - RABA Technologies
27  *
28  *
29  */
30 public class HyperbolicTransformer extends LensTransformer implements MutableTransformer {
31  
32     
33     /**
34      * create an instance, setting values from the passed component
35      * and registering to listen for size changes on the component
36      * @param component
37      */
38     public HyperbolicTransformer(Component component) {
390        this(component, new MutableAffineTransformer());
400    }
41     /**
42      * create an instance with a possibly shared transform
43      * @param component
44      * @param delegate
45      */
46     public HyperbolicTransformer(Component component, MutableTransformer delegate) {
470            super(component, delegate);
480   }
49     
50     /**
51      * override base class transform to project the fisheye effect
52      */
53     public Point2D transform(Point2D graphPoint) {
540        if(graphPoint == null) return null;
550        Point2D viewCenter = getViewCenter();
560        double viewRadius = getViewRadius();
570        double ratio = getRatio();
58         // transform the point from the graph to the view
590        Point2D viewPoint = delegate.transform(graphPoint);
60         // calculate point from center
610        double dx = viewPoint.getX() - viewCenter.getX();
620        double dy = viewPoint.getY() - viewCenter.getY();
63         // factor out ellipse
640        dx *= ratio;
650        Point2D pointFromCenter = new Point2D.Double(dx, dy);
66         
670        PolarPoint polar = cartesianToPolar(pointFromCenter);
680        double theta = polar.getTheta();
690        double radius = polar.getRadius();
700        if(radius > viewRadius) return viewPoint;
71         
720        double mag = Math.tan(Math.PI/2*magnification);
730        radius *= mag;
74         
750        radius = Math.min(radius, viewRadius);
760        radius /= viewRadius;
770        radius *= Math.PI/2;
780        radius = Math.abs(Math.atan(radius));
790        radius *= viewRadius;
800        Point2D projectedPoint = polarToCartesian(theta, radius);
810        projectedPoint.setLocation(projectedPoint.getX()/ratio, projectedPoint.getY());
820        Point2D translatedBack = new Point2D.Double(projectedPoint.getX()+viewCenter.getX(),
83                 projectedPoint.getY()+viewCenter.getY());
840        return translatedBack;
85     }
86     
87     /**
88      * override base class to un-project the fisheye effect
89      */
90     public Point2D inverseTransform(Point2D viewPoint) {
91         
920        Point2D viewCenter = getViewCenter();
930        double viewRadius = getViewRadius();
940        double ratio = getRatio();
950        double dx = viewPoint.getX() - viewCenter.getX();
960        double dy = viewPoint.getY() - viewCenter.getY();
97         // factor out ellipse
980        dx *= ratio;
99  
1000        Point2D pointFromCenter = new Point2D.Double(dx, dy);
101         
1020        PolarPoint polar = cartesianToPolar(pointFromCenter);
103  
1040        double radius = polar.getRadius();
1050        if(radius > viewRadius) return delegate.inverseTransform(viewPoint);
106         
1070        radius /= viewRadius;
1080        radius = Math.abs(Math.tan(radius));
1090        radius /= Math.PI/2;
1100        radius *= viewRadius;
1110        double mag = Math.tan(Math.PI/2*magnification);
1120        radius /= mag;
1130        polar.setRadius(radius);
1140        Point2D projectedPoint = polarToCartesian(polar);
1150        projectedPoint.setLocation(projectedPoint.getX()/ratio, projectedPoint.getY());
1160        Point2D translatedBack = new Point2D.Double(projectedPoint.getX()+viewCenter.getX(),
117                 projectedPoint.getY()+viewCenter.getY());
1180        return delegate.inverseTransform(translatedBack);
119     }
120 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.