01: package prefuse.action.animate;
02:
03: import java.util.logging.Logger;
04:
05: import prefuse.action.ItemAction;
06: import prefuse.util.PrefuseLib;
07: import prefuse.visual.VisualItem;
08:
09: /**
10: * Animator that inerpolates an array of numerical values.
11: *
12: * @author <a href="http://jheer.org">jeffrey heer</a>
13: */
14: public class ArrayAnimator extends ItemAction {
15:
16: private static final Logger s_logger = Logger
17: .getLogger(ArrayAnimator.class.getName());
18:
19: private String m_field; // the field
20: private String m_start; // the start field
21: private String m_end; // the end field
22:
23: /**
24: * Create a new ArrayAnimator that processes the given data group
25: * and interpolates arrays in the given data field.
26: * @param group the data group to process
27: * @param field the data field to interpolate. This should be an
28: * interpolated field (have start and end instances as well as
29: * the field name itself).
30: */
31: public ArrayAnimator(String group, String field) {
32: super (group);
33: m_field = field;
34: m_start = PrefuseLib.getStartField(field);
35: m_end = PrefuseLib.getEndField(field);
36: }
37:
38: /**
39: * @see prefuse.action.ItemAction#process(prefuse.visual.VisualItem, double)
40: */
41: public void process(VisualItem item, double frac) {
42: Object o = item.get(m_field);
43: if (o instanceof float[]) {
44: float[] a = (float[]) o;
45: float[] s = (float[]) item.get(m_start);
46: float[] e = (float[]) item.get(m_end);
47:
48: float f = (float) frac;
49: for (int i = 0; i < a.length; ++i) {
50: if (Float.isNaN(a[i]))
51: break;
52: a[i] = s[i] + f * (e[i] - s[i]);
53: }
54: item.setValidated(false);
55: } else if (o instanceof double[]) {
56: double[] a = (double[]) o;
57: double[] s = (double[]) item.get(m_start);
58: double[] e = (double[]) item.get(m_end);
59:
60: for (int i = 0; i < a.length; ++i) {
61: if (Double.isNaN(a[i]))
62: break;
63: a[i] = s[i] + frac * (e[i] - s[i]);
64: }
65: item.setValidated(false);
66: } else {
67: s_logger
68: .warning("Encountered non-double/non-float array type: "
69: + (o == null ? "null" : o.getClass()
70: .getName()));
71: }
72: }
73:
74: } // end of class ArrayAnimator
|