| Line | Hits | Source |
|---|---|---|
| 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) { | |
| 39 | 0 | this(component, new MutableAffineTransformer()); |
| 40 | 0 | } |
| 41 | /** | |
| 42 | * create an instance with a possibly shared transform | |
| 43 | * @param component | |
| 44 | * @param delegate | |
| 45 | */ | |
| 46 | public HyperbolicTransformer(Component component, MutableTransformer delegate) { | |
| 47 | 0 | super(component, delegate); |
| 48 | 0 | } |
| 49 | ||
| 50 | /** | |
| 51 | * override base class transform to project the fisheye effect | |
| 52 | */ | |
| 53 | public Point2D transform(Point2D graphPoint) { | |
| 54 | 0 | if(graphPoint == null) return null; |
| 55 | 0 | Point2D viewCenter = getViewCenter(); |
| 56 | 0 | double viewRadius = getViewRadius(); |
| 57 | 0 | double ratio = getRatio(); |
| 58 | // transform the point from the graph to the view | |
| 59 | 0 | Point2D viewPoint = delegate.transform(graphPoint); |
| 60 | // calculate point from center | |
| 61 | 0 | double dx = viewPoint.getX() - viewCenter.getX(); |
| 62 | 0 | double dy = viewPoint.getY() - viewCenter.getY(); |
| 63 | // factor out ellipse | |
| 64 | 0 | dx *= ratio; |
| 65 | 0 | Point2D pointFromCenter = new Point2D.Double(dx, dy); |
| 66 | ||
| 67 | 0 | PolarPoint polar = cartesianToPolar(pointFromCenter); |
| 68 | 0 | double theta = polar.getTheta(); |
| 69 | 0 | double radius = polar.getRadius(); |
| 70 | 0 | if(radius > viewRadius) return viewPoint; |
| 71 | ||
| 72 | 0 | double mag = Math.tan(Math.PI/2*magnification); |
| 73 | 0 | radius *= mag; |
| 74 | ||
| 75 | 0 | radius = Math.min(radius, viewRadius); |
| 76 | 0 | radius /= viewRadius; |
| 77 | 0 | radius *= Math.PI/2; |
| 78 | 0 | radius = Math.abs(Math.atan(radius)); |
| 79 | 0 | radius *= viewRadius; |
| 80 | 0 | Point2D projectedPoint = polarToCartesian(theta, radius); |
| 81 | 0 | projectedPoint.setLocation(projectedPoint.getX()/ratio, projectedPoint.getY()); |
| 82 | 0 | Point2D translatedBack = new Point2D.Double(projectedPoint.getX()+viewCenter.getX(), |
| 83 | projectedPoint.getY()+viewCenter.getY()); | |
| 84 | 0 | return translatedBack; |
| 85 | } | |
| 86 | ||
| 87 | /** | |
| 88 | * override base class to un-project the fisheye effect | |
| 89 | */ | |
| 90 | public Point2D inverseTransform(Point2D viewPoint) { | |
| 91 | ||
| 92 | 0 | Point2D viewCenter = getViewCenter(); |
| 93 | 0 | double viewRadius = getViewRadius(); |
| 94 | 0 | double ratio = getRatio(); |
| 95 | 0 | double dx = viewPoint.getX() - viewCenter.getX(); |
| 96 | 0 | double dy = viewPoint.getY() - viewCenter.getY(); |
| 97 | // factor out ellipse | |
| 98 | 0 | dx *= ratio; |
| 99 | ||
| 100 | 0 | Point2D pointFromCenter = new Point2D.Double(dx, dy); |
| 101 | ||
| 102 | 0 | PolarPoint polar = cartesianToPolar(pointFromCenter); |
| 103 | ||
| 104 | 0 | double radius = polar.getRadius(); |
| 105 | 0 | if(radius > viewRadius) return delegate.inverseTransform(viewPoint); |
| 106 | ||
| 107 | 0 | radius /= viewRadius; |
| 108 | 0 | radius = Math.abs(Math.tan(radius)); |
| 109 | 0 | radius /= Math.PI/2; |
| 110 | 0 | radius *= viewRadius; |
| 111 | 0 | double mag = Math.tan(Math.PI/2*magnification); |
| 112 | 0 | radius /= mag; |
| 113 | 0 | polar.setRadius(radius); |
| 114 | 0 | Point2D projectedPoint = polarToCartesian(polar); |
| 115 | 0 | projectedPoint.setLocation(projectedPoint.getX()/ratio, projectedPoint.getY()); |
| 116 | 0 | Point2D translatedBack = new Point2D.Double(projectedPoint.getX()+viewCenter.getX(), |
| 117 | projectedPoint.getY()+viewCenter.getY()); | |
| 118 | 0 | return delegate.inverseTransform(translatedBack); |
| 119 | } | |
| 120 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |