Revision 20162

View differences:

trunk/libraries/libAnimation3D/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0"
2
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<groupId>com.iver.cit.gvsig.animation</groupId>
6
	<artifactId>libAnimation3D</artifactId>
7
	<packaging>jar</packaging>
8
	<version>1.0-SNAPSHOT</version>
9
	<name>libAnimation3D</name>
10
	<url>http://maven.apache.org</url>
11
	<parent>
12
		<groupId>org.gvsig</groupId>
13
		<artifactId>gvsig-library-base-pom</artifactId>
14
		<version>1.0-SNAPSHOT</version>
15
	</parent>
16
	<dependencies>
17
		<dependency>
18
			<groupId>org.gvsig</groupId>
19
			<artifactId>lib3DMap</artifactId>
20
			<version>1.0-SNAPSHOT</version>
21
		</dependency>
22
		<dependency>
23
			<groupId>org.gvsig</groupId>
24
			<artifactId>lib3DMap-share</artifactId>
25
			<version>1.0-SNAPSHOT</version>
26
		</dependency>
27
		<dependency>
28
			<groupId>org.gvsig</groupId>
29
			<artifactId>gvsig-animation</artifactId>
30
			<version>1.0-SNAPSHOT</version>
31
		</dependency>
32
		<dependency>
33
			<groupId>org.gvsig</groupId>
34
			<artifactId>ext3Dgui</artifactId>
35
			<version>1.0-SNAPSHOT</version>
36
		</dependency>
37
	</dependencies>
38
</project>
trunk/libraries/libAnimation3D/src/main/java/com/iver/cit/gvsig/animation/animatedObject/AnimationObject3DFlat.java
1
package com.iver.cit.gvsig.animation.animatedObject;
2

  
3
import com.iver.cit.gvsig.animation.animatedObject.AnimatedObjectBase;
4
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
5

  
6
public class AnimationObject3DFlat extends AnimatedObjectBase {
7
	
8
	private String nameClassView;
9
	
10
	public String getClassName() {
11
		return this.getClass().getName();
12
	}
13
	
14
	public void setClassName(String className) {
15
	}
16
	
17
	public String getNameClassView() {
18
		return nameClassView;
19
		
20
	}
21
	
22
	public void setNameView(String nameView) {
23
		this.nameClassView = nameView;
24
		
25
	}
26
	
27
	public Object getAnimatedView() {
28
		return this.getAnimatedObject("view");
29
	}
30
	
31
	public void setAnimatedView(Object object) {
32
		this.addAnimatedObject("view", object);
33
		this.nameClassView = ((BaseView) object).getClass().getName();
34
	}
35
	
36
	
37
}
trunk/libraries/libAnimation3D/src/main/java/com/iver/cit/gvsig/animation/animationType/AnimationTypeFactoryLayer3DFlat.java
1
package com.iver.cit.gvsig.animation.animationType;
2

  
3
import com.iver.cit.gvsig.animation.AnimationFactory;
4

  
5
public class AnimationTypeFactoryLayer3DFlat extends AnimationFactory {
6

  
7
	public static String registerName = "AnimationLayer3DFlat";
8
	
9
	
10
	public static AnimationLayer3DFlat animationLayer3DFlat;
11
	
12
	static {
13
		if (animationLayer3DFlat == null) {
14
			animationLayer3DFlat = new AnimationLayer3DFlat();
15
			animationLayer3DFlat.setClassName("AnimationLayer3DFlat");
16
			animationLayer3DFlat.setName("AnimationLayer3DFlat");
17
			animationLayer3DFlat.setDescription("Animacion basada en encuadres para vista 3D plana");
18
		}
19
	}
20
	
21
	/**
22
	 * Creating a new animation type.
23
	 */
24
	
25
	public Object create() {
26
		
27
       return animationLayer3DFlat;
28
	}
29
	
30
	/**
31
	 * Registers in the points of extension the Factory with alias.
32
	 * 
33
	 */
34
	public static void register() {
35
		register(registerName, new AnimationTypeFactoryLayer3DFlat(), "com.iver.cit.gvsig.animation.AnimationLayer3DFlat");
36
	}
37

  
38
	public String getRegisterName() {
39
		return registerName;
40
	}
41

  
42
}
trunk/libraries/libAnimation3D/src/main/java/com/iver/cit/gvsig/animation/animationType/AnimationLayer3DFlat.java
1
package com.iver.cit.gvsig.animation.animationType;
2

  
3
import com.iver.ai2.gvsig3d.camera.ProjectCamera;
4
import com.iver.ai2.gvsig3dgui.view.View3D;
5
import com.iver.andami.PluginServices;
6
import com.iver.andami.ui.mdiManager.IWindow;
7
import com.iver.cit.gvsig.animation.IAnimationType;
8
import com.iver.cit.gvsig.animation.animatedObject.AnimationObject3DFlat;
9
import com.iver.cit.gvsig.animation.animatedObject.IAnimatedObject;
10
import com.iver.cit.gvsig.animation.interpolator.Interpolator3DFlat;
11
import com.iver.cit.gvsig.animation.keyFrame.KeyFrame3DFlat;
12
import com.iver.cit.gvsig.animation.keyframe.IAnimationTypeKeyFrame;
13
import com.iver.cit.gvsig.animation.keyframe.interpolator.FuntionFactory;
14
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator;
15
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorTimeFuntion;
16
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
17
import com.iver.utiles.IPersistence;
18
import com.iver.utiles.XMLEntity;
19

  
20
public class AnimationLayer3DFlat implements IAnimationTypeKeyFrame {
21

  
22
	private String className = this.getClass().getName();
23
	private String description = "Animacion basada en encuadres para vista 3D plana";
24
	private String name = "Animacion vista 3D plana";
25
	private int typeTrack = IAnimationType.TIME_TYPE_TRACK;
26
	private IInterpolator interpolator;
27
	private String nameClassView;
28
	
29
	private IAnimatedObject animationObject3DFlat = new AnimationObject3DFlat() ;
30
	private String titleWindow;
31

  
32
	public AnimationLayer3DFlat() {
33
		this.interpolator = new Interpolator3DFlat();
34
	}
35

  
36
	public String getClassName() {
37
		return className;
38
	}
39

  
40
	public String getDescription() {
41
		return description;
42
	}
43

  
44
	public String getName() {
45
		return name;
46
	}
47

  
48
	public void setClassName(String className) {
49
		this.className = className;
50
	}
51

  
52
	public void setDescription(String description) {
53
		this.description = description;
54
	}
55

  
56
	public void setName(String name) {
57
		this.name = name;
58
	}
59

  
60
	public void AppliesToObject(Object animated) {
61

  
62
		// TODO implementar esta funcion para vistas 3D esfericas.
63
		KeyFrame3DFlat keyf = (KeyFrame3DFlat) animated;
64
		ProjectCamera projectCamera = (ProjectCamera) keyf.getAnimatedObject();
65

  
66
		View3D  view3D = (View3D) animationObject3DFlat.getAnimatedObject("view");
67
		view3D.setCamera(projectCamera.getCamera());	
68
//		Hud hud = (Hud) view.getCanvas3d().getOSGViewer().getNodeFromHUD(0);
69
//		hud.setAnimationTime(AnimationPlayer.getCurrentTime()/1000);
70
//		hud.updateHud();
71
		
72
		
73
		view3D.getCanvas3d().repaint();
74
	
75
	}
76

  
77
	public int getTypeTrack() {
78
		return typeTrack;
79
	}
80

  
81
	public void setTypeTrack(int typeTrack) {
82
		this.typeTrack = typeTrack;
83

  
84
	}
85

  
86
	public IInterpolator getInterpolator() {
87
		return this.interpolator;
88
	}
89

  
90
	public void setInterpolator(IInterpolator interpolator) {
91
		this.interpolator = interpolator;
92

  
93
	}
94

  
95
	public Object getAnimatedObject() {
96
		// if view is null.
97
		if(this.animationObject3DFlat == null){
98
			// getting all views.
99
			try{
100
				IWindow[] viewArray = PluginServices.getMDIManager().getAllWindows();
101
				for (int i = 0; i < viewArray.length; i++) {
102
					IWindow window = viewArray[i];
103
					if (window.getClass().getName().equals(this.nameClassView)){
104
						// get the actual name of the view, and compare it with the view saved in xml.
105
						if(window.getWindowInfo().getTitle().equals(this.titleWindow)){
106
							BaseView newView = (BaseView)window;
107
							this.animationObject3DFlat.addAnimatedObject("view", newView);
108
//							this.animationObject3DFlat.setAnimatedView(newView);
109
							this.setAnimatedObject(this.animationObject3DFlat);
110
							IInterpolatorTimeFuntion funtion = FuntionFactory.createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion");
111
							this.interpolator.setFuntion(funtion);
112
						}
113
							//this.view = (View3D)newView;
114
					}
115
				}
116
			}catch(Exception e) {
117
				e.printStackTrace();
118
			}
119
		}
120
		return this.animationObject3DFlat;
121
	}
122

  
123
	public void setAnimatedObject(Object object) {
124
		this.animationObject3DFlat = (IAnimatedObject) object;
125

  
126
	}
127

  
128
	public XMLEntity getXMLEntity() {
129
		
130
		View3D myActualView = null;
131
		
132
		XMLEntity xml = new XMLEntity();
133
		xml.putProperty("className", this.getClassName());
134
		xml.putProperty("description", description);
135
		xml.putProperty("animationTrackTipe", typeTrack);
136
		xml.putProperty("nameClassView", ((AnimationObject3DFlat)animationObject3DFlat).getNameClassView());
137
		myActualView = (View3D) ((AnimationObject3DFlat)animationObject3DFlat).getAnimatedView();
138
		titleWindow = myActualView.getWindowInfo().getTitle();
139
		xml.putProperty("titleWindow", titleWindow);
140
		xml.addChild(((IPersistence)this.interpolator).getXMLEntity());
141
		return xml;
142
	}
143

  
144
	public void setXMLEntity(XMLEntity xml) {
145
//		if (xml.contains("className"))
146
//			this.className=	xml.getStringProperty("className");
147
		if (xml.contains("animationTrackTipe"))
148
			this.typeTrack = xml.getIntProperty("animationTrackTipe");
149
		if (xml.contains("nameClassView"))
150
			this.nameClassView = xml.getStringProperty("nameClassView");
151
		if (xml.contains("titleWindow"))
152
			this.titleWindow = xml.getStringProperty("titleWindow");
153
		
154
		XMLEntity xmlInterpolator = xml.getChild(0);
155
		
156
		try {
157
			String class_name = xmlInterpolator.getStringProperty("className");
158
			Class classInterpolator = Class.forName(class_name);
159
			Object obj = classInterpolator .newInstance();
160
			IPersistence objPersist = (IPersistence) obj;
161
			objPersist.setXMLEntity(xmlInterpolator);
162
			this.interpolator = (IInterpolator) obj;
163
			this.setInterpolator(interpolator);
164
			
165
		} catch (Exception e) {
166
			e.printStackTrace();
167
		}
168
	}
169
}
trunk/libraries/libAnimation3D/src/main/java/com/iver/cit/gvsig/animation/interpolator/Interpolator3DFlat.java
1
package com.iver.cit.gvsig.animation.interpolator;
2

  
3
import java.util.List;
4

  
5
import com.iver.ai2.gvsig3d.camera.ProjectCamera;
6
import com.iver.cit.gvsig.animation.keyFrame.KeyFrame3DFlat;
7
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame;
8
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator;
9
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorTimeFuntion;
10
import com.iver.utiles.XMLEntity;
11

  
12
import es.upv.ai2.osgvp.Vec3;
13
import es.upv.ai2.osgvp.viewer.Camera;
14

  
15
public class Interpolator3DFlat implements IInterpolator {
16

  
17
	private IInterpolatorTimeFuntion funtion;
18
	private String description = "Interpolaci?n basada en encuadres";
19
	private String name = "Interpolator3DFlat";
20
	
21
	public IKeyFrame interpolate(List kfList, int index, double time) {
22
		KeyFrame3DFlat KF = new KeyFrame3DFlat();
23

  
24
		if (kfList == null)
25
			return null;
26

  
27
		// convert the time in the new time using funtion
28
		double newTime = this.getFuntion().interpolate(time);
29
		
30
		switch (kfList.size()) {
31
		// this case when there are only has 2 keyframes
32
		case 2:
33
			// getting the keyframes
34
			KeyFrame3DFlat kf1 = (KeyFrame3DFlat) kfList.get(0);
35
			KeyFrame3DFlat kf2 = (KeyFrame3DFlat) kfList.get(1);
36

  
37
			if (index == 1) {
38
				KeyFrame3DFlat kaux = kf1;
39
				kf1 = kf2;
40
				kf2 = kaux;
41
			}
42

  
43
			if ((kf1 == null) ||(kf2 == null))
44
				return null;
45
			ProjectCamera vp1 = (ProjectCamera) kf1.getAnimatedObject();
46
			ProjectCamera vp2 = (ProjectCamera) kf2.getAnimatedObject();
47

  
48
			// ViewPort vp = view.getMapControl().getViewPort();
49

  
50
			Camera cam1 = vp1.getCamera();
51
			Camera cam2 = vp2.getCamera();
52
			double time1 = kf1.getTime();
53
			double time2 = kf2.getTime();
54
			
55
			Vec3 eye = linearInterpolate(cam1.getEye(), cam2.getEye(), time1, time2, newTime);
56
			Vec3 center = linearInterpolate(cam1.getCenter(), cam2.getCenter(), time1, time2, newTime);
57
			Vec3 up = linearInterpolate(cam1.getUp(), cam2.getUp(), time1, time2, newTime);
58
		
59
			Camera newCamera = new Camera();
60
//			newCamera.setViewByLookAt(eye, center, cam1.getUp());
61
			newCamera.setViewByLookAt(eye, center, up);
62

  
63
			ProjectCamera pe = new ProjectCamera();
64
			pe.setCamera(newCamera);
65
			KF.setName("temporal_keyframe");
66
			KF.setAnimatedObject(pe);
67
			break;
68
		}
69
		return KF;
70
	}
71

  
72
	private double linearInterpolate(double minX, double minX2, double timePos,
73
			double timePos2, double time) {
74
		// P1 + (P2-P1)*((t-t1)/(t2-t1))
75
		return (minX + (minX2 - minX)
76
				* ((time - timePos) / (timePos2 - timePos)));
77
	}
78

  
79
	private Vec3 linearInterpolate(Vec3 minX, Vec3 minX2, double timePos,
80
			double timePos2, double time) {
81

  
82
		Vec3 result = new Vec3();
83

  
84
		double ele1 = linearInterpolate(minX.x(), minX2.x(), timePos, timePos2,
85
				time);
86
		double ele2 = linearInterpolate(minX.y(), minX2.y(), timePos, timePos2,
87
				time);
88
		double ele3 = linearInterpolate(minX.z(), minX2.z(), timePos, timePos2,
89
				time);
90

  
91
		result.setX(ele1);
92
		result.setY(ele2);
93
		result.setZ(ele3);
94
		return result;
95
	}
96

  
97
//	public Object getAnimatedObject() {
98
////		return this.animationObject3DFlat;
99
//		//return this.view;
100
//		return null;
101
//	}
102
//
103
//
104
//	public void setAnimatedObject(Object object) {
105
////		this.animationObject3DFlat = (AnimationObject3DFlat) object;
106
////		this.view = (View3D) animationObject3DFlat.getAnimatedView();
107
//	}
108
	
109
	
110
	
111
//	public void setAnimatedObject(Object ani) {
112
//		this.view = (View3D) ani;
113
//
114
//	}
115

  
116
	public IInterpolatorTimeFuntion getFuntion() {
117
		return this.funtion;
118
	}
119

  
120
	public void setFuntion(IInterpolatorTimeFuntion funtion) {
121
		this.funtion = funtion;
122
		
123
	}
124

  
125
	public String getClassName() {
126
		return this.getClass().getName();
127
	}
128

  
129
	public String getDescription() {
130
		return this.description;
131
	}
132

  
133
	public String getName() {
134
		return this.name;
135
	}
136

  
137
	/*
138
	 * IPersistence methods.
139
	 */
140
	
141
	public XMLEntity getXMLEntity() {
142
		XMLEntity xml = new XMLEntity();	
143
		xml.putProperty("className", this.getClassName());
144
		xml.putProperty("description", this.description);
145
		return xml;
146
	}
147
	
148
	public void setXMLEntity(XMLEntity xml) {
149
//		if (xml.contains("className"))
150
//			this.className=	xml.getStringProperty("className");
151
		if (xml.contains("description"))
152
			this.description = xml.getStringProperty("description");
153
		
154
	}
155
}
trunk/libraries/libAnimation3D/src/main/java/com/iver/cit/gvsig/animation/keyFrame/AnimationKeyFrame3DFlatFactory.java
1
package com.iver.cit.gvsig.animation.keyFrame;
2

  
3
import com.iver.cit.gvsig.animation.AnimationFactory;
4

  
5

  
6
public class AnimationKeyFrame3DFlatFactory extends AnimationFactory {
7

  
8
	public static String registerName = "KeyFrame3DFlat";
9
	
10
	
11
	/**
12
	 * Creating a new keyFrmame 3DFlat in the factory.
13
	 */
14
	public Object create() {
15
		KeyFrame3DFlat keyFrameFlat = new KeyFrame3DFlat();
16
        return keyFrameFlat;
17
	}
18
	
19
	/**
20
	 * Registers in the points of extension the Factory with alias.
21
	 */
22
	public static void register() {
23
		register(registerName, new AnimationKeyFrame3DFlatFactory(), "com.iver.cit.gvsig.animation.KeyFrame3DFlat");
24
	}
25

  
26
	public String getRegisterName() {
27
		return registerName;
28
	}
29

  
30
}
trunk/libraries/libAnimation3D/src/main/java/com/iver/cit/gvsig/animation/keyFrame/KeyFrame3DFlat.java
1
package com.iver.cit.gvsig.animation.keyFrame;
2

  
3
import java.util.List;
4

  
5
import com.iver.ai2.gvsig3d.camera.ProjectCamera;
6
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame;
7
import com.iver.utiles.IPersistence;
8
import com.iver.utiles.XMLEntity;
9

  
10
public class KeyFrame3DFlat implements IKeyFrame {
11

  
12
	private String name;
13
	private double time;
14

  
15
	ProjectCamera projectCamera = null;
16

  
17
	
18

  
19
	public void CapturesProperties() {
20
		// TODO Auto-generated method stub
21

  
22
	}
23

  
24
	public String getName() {
25
		// TODO Auto-generated method stub
26
		return this.name;
27
	}
28

  
29
	public List getPropertiesList() {
30
		// TODO Auto-generated method stub
31
		return null;
32
	}
33

  
34
	public void setName(String name) {
35
		this.name = name;
36

  
37
	}
38

  
39
	public void setPropertiesList(List list) {
40
		// TODO Auto-generated method stub
41

  
42
	}
43

  
44
	public String toString() {
45
		String result;
46
		result = " keyframe3DFlats:\n";
47
		result += " tiempo: " + this.time;
48
		result += " nombre del extent: " + this.projectCamera.getDescription();
49

  
50
		// result= "Name: " + this.getName();
51
		return result;
52
	}
53

  
54
	
55

  
56
	public Object getAnimatedObject() {
57
		// TODO Auto-generated method stub
58
		return projectCamera;
59
	}
60
	public void setAnimatedObject(Object object) {
61
		this.projectCamera = (ProjectCamera) object;
62
	}
63

  
64
	public double getTime() {
65
		return time;
66
	}
67

  
68
	public void setTime(double time) {
69
		this.time = time;
70
	}
71

  
72
	public String getClassName() {
73
		return this.getClass().getName();
74
	}
75

  
76
	public XMLEntity getXMLEntity() {
77
		XMLEntity xml = new XMLEntity();
78
		
79
		xml.putProperty("className", this.getClassName());
80
		xml.putProperty("keyFrameName", name);
81
		xml.putProperty("time", time);
82
		
83
		xml.addChild(((IPersistence)projectCamera).getXMLEntity());
84
		
85
		return xml;
86
	}
87

  
88
	public void setXMLEntity(XMLEntity xml) {
89
		
90
		if (xml.contains("keyFrameName"))
91
			this.name = xml.getStringProperty("keyFrameName");
92
		if (xml.contains("time"))
93
			this.time = xml.getDoubleProperty("time");
94
		
95
		//this.projectCamera.setXMLEntity(xml.getChild(0));
96
		
97
		// Get camera
98
		XMLEntity xmlProp = xml.getChild(0);
99
		if (xmlProp.contains("eyeX")) {
100
			try {
101
				String className = xmlProp.getStringProperty("className");
102
				Class classProp = Class.forName(className);
103
				Object obj = classProp.newInstance();
104
				IPersistence objPersist = (IPersistence) obj;
105
				objPersist.setXMLEntity(xmlProp);
106
				projectCamera = (ProjectCamera) obj;
107
			} catch (Exception e) {
108

  
109
			}
110
		}
111
	}
112
}
trunk/libraries/libAnimation3D/src/test/java/com/iver/cit/gvsig/animation/AppTest.java
1
package com.iver.cit.gvsig.animation;
2

  
3
import junit.framework.Test;
4
import junit.framework.TestCase;
5
import junit.framework.TestSuite;
6

  
7
/**
8
 * Unit test for simple App.
9
 */
10
public class AppTest 
11
    extends TestCase
12
{
13
    /**
14
     * Create the test case
15
     *
16
     * @param testName name of the test case
17
     */
18
    public AppTest( String testName )
19
    {
20
        super( testName );
21
    }
22

  
23
    /**
24
     * @return the suite of tests being tested
25
     */
26
    public static Test suite()
27
    {
28
        return new TestSuite( AppTest.class );
29
    }
30

  
31
    /**
32
     * Rigourous Test :-)
33
     */
34
    public void testApp()
35
    {
36
        assertTrue( true );
37
    }
38
}

Also available in: Unified diff