00001 package edu.tum.cs.vis;
00002
00003 import java.io.IOException;
00004 import java.sql.ResultSet;
00005
00006 import edu.tum.cs.util.db.MySQLConnection;
00007 import edu.tum.cs.util.math.Vector3f;
00008 import edu.tum.cs.vis.items.FrameDisplay;
00009 import edu.tum.cs.vis.items.Trajectory;
00010
00011 public class TrajectoryApplet extends AnimatedCanvas {
00012 private static final long serialVersionUID = 1L;
00016 public boolean centerTrajectory = false;
00017
00018 public TrajectoryApplet() {
00019 }
00020
00025 public TrajectoryApplet(String table) {
00026 String host = "atradig131";
00027 String db = "stt-human-import";
00028 String user = "tenorth";
00029 String password = "UEY9KbNb";
00030
00031
00032 Trajectory traj = new Trajectory();
00033 try {
00034 MySQLConnection conn = new MySQLConnection(host, user, password, db);
00035 ResultSet rs = conn.select("select x,y,z from " + table + " where episode_nr=0 and occurrence_nr=1 order by instance_nr");
00036 while (rs.next()) {
00037 float x = rs.getFloat(1);
00038 float y = rs.getFloat(2);
00039 float z = rs.getFloat(3);
00040 System.out.printf("%f/%f/%f\n", x, y, z);
00041 traj.addPoint(x, y, z);
00042 }
00043 }
00044 catch (Exception e) {
00045 throw new RuntimeException(e.getClass().getCanonicalName() + ": " + e.getMessage());
00046 }
00047 init(traj);
00048 }
00049
00050 public TrajectoryApplet(java.io.File matlabAsciiFile) throws IOException {
00051 readTrajectory(matlabAsciiFile);
00052 }
00053
00054 public Trajectory readTrajectory(java.io.File matlabAsciiFile) throws NumberFormatException, IOException {
00055 return readTrajectory(matlabAsciiFile, 0);
00056 }
00057
00065 public Trajectory readTrajectory(java.io.File matlabAsciiFile, int startLine) throws NumberFormatException, IOException {
00066 Trajectory traj = new Trajectory();
00067 traj.readAsc(matlabAsciiFile, startLine);
00068 init(traj);
00069 return traj;
00070 }
00071
00072 public void init(Trajectory traj) {
00073 if(centerTrajectory)
00074 traj.center();
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 float sceneSize = traj.getMaxAbsCoord();
00092 add(new CoordinateSystem(sceneSize));
00093 this.setSceneSize(sceneSize);
00094
00095
00096 addAnimated(traj);
00097
00098
00099 useCamera = false;
00100 this.eye = new Vector3f(sceneSize, sceneSize, sceneSize/2);
00101 this.eyeUp = new Vector3f(sceneSize, sceneSize, -sceneSize);
00102 this.eyeUp = new Vector3f(0,0,1);
00103 this.eyeUp.normalize();
00104
00105 add(new FrameDisplay(this, 5, 5+13, LEFT, null));
00106
00107 redraw();
00108 }
00109
00110 public void keyPressed() {
00111 if(this.keyCode == java.awt.event.KeyEvent.VK_A) {
00112 for(DrawableAnimated i : this.animatedItems) {
00113 if(i instanceof Trajectory) {
00114 Trajectory traj = (Trajectory) i;
00115 traj.animationMode = traj.animationMode == Trajectory.AnimationMode.BuildUp ? Trajectory.AnimationMode.AllAtOnce : Trajectory.AnimationMode.BuildUp;
00116 System.out.println("TrajectoryApplet: Switching animation mode");
00117 }
00118 }
00119 redraw();
00120 }
00121 else if(this.keyCode == java.awt.event.KeyEvent.VK_D) {
00122 for(DrawableAnimated i : this.animatedItems) {
00123 if(i instanceof Trajectory) {
00124 Trajectory traj = (Trajectory) i;
00125 traj.pointsAsSpheres ^= true;
00126 System.out.println("TrajectoryApplet: Switching point drawing style");
00127 }
00128 }
00129 redraw();
00130 }
00131 super.keyPressed();
00132 }
00133
00134 public static void main(String[] args) {
00135 try {
00136
00137 Canvas applet = new TrajectoryApplet("STT_DETAILED_ABSTRACT_EXP_ISOMAP3D_INTERVAL_LOCAL");
00138
00139 applet.runMain();
00140 }
00141 catch (Exception e) {
00142 e.printStackTrace();
00143 }
00144 }
00145 }