svn-gvsig-desktop / trunk / libraries / libAnimation2D / src / main / java / com / iver / cit / gvsig / animation / interpolator / Interpolator2D.java @ 23597
History | View | Annotate | Download (3.93 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
|
20 |
package com.iver.cit.gvsig.animation.interpolator; |
21 |
|
22 |
import java.awt.geom.Rectangle2D; |
23 |
import java.util.List; |
24 |
|
25 |
import com.iver.cit.gvsig.animation.keyFrame.KeyFrame2D; |
26 |
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame; |
27 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator; |
28 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorTimeFuntion; |
29 |
import com.iver.cit.gvsig.project.ProjectExtent; |
30 |
import com.iver.utiles.XMLEntity; |
31 |
|
32 |
public class Interpolator2D implements IInterpolator { |
33 |
|
34 |
private String description = "Interpolaci?n basada en encuadres"; |
35 |
private String name = "Interpolator2D"; |
36 |
|
37 |
private IInterpolatorTimeFuntion funtion;
|
38 |
|
39 |
public IKeyFrame interpolate(List<IKeyFrame> kfList, int index, double time) { |
40 |
KeyFrame2D KF = new KeyFrame2D();
|
41 |
|
42 |
if (kfList == null) |
43 |
return null; |
44 |
|
45 |
|
46 |
switch (kfList.size()) {
|
47 |
// this case when there are only has 2 keyframes
|
48 |
case 2: |
49 |
// getting the keyframes
|
50 |
KeyFrame2D kf1 = (KeyFrame2D) kfList.get(0);
|
51 |
KeyFrame2D kf2 = (KeyFrame2D) kfList.get(1);
|
52 |
|
53 |
if (index == 1) { |
54 |
KeyFrame2D kaux = kf1; |
55 |
kf1 = kf2; |
56 |
kf2 = kaux; |
57 |
} |
58 |
|
59 |
ProjectExtent vp1 = (ProjectExtent) kf1.getAnimatedObject(); |
60 |
ProjectExtent vp2 = (ProjectExtent) kf2.getAnimatedObject(); |
61 |
|
62 |
|
63 |
double min1 = vp1.getExtent().getMinX();
|
64 |
double time1 = kf1.getTime();
|
65 |
double min2 = vp2.getExtent().getMinX();
|
66 |
double time2 = kf2.getTime();
|
67 |
double left = linearInterpolate(min1, min2, time1, time2, time);
|
68 |
min1 = vp1.getExtent().getMinY(); |
69 |
min2 = vp2.getExtent().getMinY(); |
70 |
double top = linearInterpolate(min1, min2, time1, time2, time);
|
71 |
min1 = vp1.getExtent().getWidth(); |
72 |
min2 = vp2.getExtent().getWidth(); |
73 |
double right = linearInterpolate(min1, min2, time1, time2, time);
|
74 |
min1 = vp1.getExtent().getHeight(); |
75 |
min2 = vp2.getExtent().getHeight(); |
76 |
double bottom = linearInterpolate(min1, min2, time1, time2, time);
|
77 |
|
78 |
Rectangle2D newExtent = new Rectangle2D.Double(left, top, right, |
79 |
bottom); |
80 |
ProjectExtent pe = new ProjectExtent();
|
81 |
pe.setExtent(newExtent); |
82 |
KF.setAnimatedObject(pe); |
83 |
break;
|
84 |
} |
85 |
|
86 |
return KF;
|
87 |
} |
88 |
|
89 |
private double linearInterpolate(double minX, double minX2, double timePos, |
90 |
double timePos2, double time) { |
91 |
// P1 + (P2-P1)*((t-t1)/(t2-t1))
|
92 |
return (minX + (minX2 - minX)
|
93 |
* ((time - timePos) / (timePos2 - timePos))); |
94 |
} |
95 |
|
96 |
public IInterpolatorTimeFuntion getFuntion() {
|
97 |
return this.funtion; |
98 |
} |
99 |
|
100 |
public void setFuntion(IInterpolatorTimeFuntion funtion) { |
101 |
this.funtion = funtion;
|
102 |
} |
103 |
|
104 |
public String getClassName() { |
105 |
return this.getClass().getName(); |
106 |
} |
107 |
|
108 |
public String getDescription() { |
109 |
return this.description; |
110 |
} |
111 |
|
112 |
public String getName() { |
113 |
return this.name; |
114 |
} |
115 |
|
116 |
public XMLEntity getXMLEntity() {
|
117 |
XMLEntity xml = new XMLEntity();
|
118 |
xml.putProperty("className", this.getClassName()); |
119 |
xml.putProperty("description", this.description); |
120 |
return xml;
|
121 |
} |
122 |
|
123 |
public void setXMLEntity(XMLEntity xml) { |
124 |
if (xml.contains("description")) |
125 |
this.description = xml.getStringProperty("description"); |
126 |
|
127 |
} |
128 |
} |