Changeset 21555 in osm for applications
- Timestamp:
- 2010-06-01T19:36:49+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/videomapping
- Files:
-
- 2 added
- 2 deleted
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/videomapping/.classpath
r21519 r21555 5 5 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> 6 6 <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/> 7 <classpathentry kind="lib" path=" C:/Dokumente und Einstellungen/g/Eigene Dateien/Workspace/vlcj/vlcj-1.1f.jar">7 <classpathentry kind="lib" path="D:/Projekte/Studium/GeoProjekt/working/VideoMapping/lib/vlcj-1.1f.jar"> 8 8 <attributes> 9 9 <attribute name="javadoc_location" value="jar:file:/C:/Dokumente und Einstellungen/g/Eigene Dateien/Workspace/vlcj/vlcj-1.1f-javadoc.jar!/"/> -
applications/editors/josm/plugins/videomapping/.project
r21226 r21555 4 4 <comment></comment> 5 5 <projects> 6 <project>JOSM</project> 6 7 </projects> 7 8 <buildSpec> -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/GpsPlayer.java
r21519 r21555 5 5 import java.text.SimpleDateFormat; 6 6 import java.util.Date; 7 import java.util.LinkedList; 7 8 import java.util.List; 8 9 import java.util.ListIterator; … … 93 94 { 94 95 Point leftP,rightP,highP,lowP; 95 boolean invalid = false; 96 boolean invalid = false; //when we leave this segment 96 97 Point p1 = Main.map.mapView.getPoint(getCurr().getEastNorth()); 97 if(getNext()!=null) //TODO outsource certain dub routines 98 { 99 Point p2 = Main.map.mapView.getPoint(getNext().getEastNorth()); 100 //determine which point is what 101 if(p1.x<p2.x) 102 { 103 leftP=p1; 104 rightP=p2; 105 } 106 else 107 { 108 leftP=p2; 109 rightP=p1; 110 } 111 if(p1.y<p2.y) 112 { 113 highP=p1; 114 lowP=p2; 115 } 116 else 117 { 118 highP=p2; 119 lowP=p1; 120 } 121 //we might switch to neighbor segment 98 Point p2 = getEndpoint(); 99 //determine which point is what 100 leftP=getLeftPoint(p1, p2); 101 rightP=getRightPoint(p1,p2); 102 highP=getHighPoint(p1, p2); 103 lowP=getLowPoint(p1, p2); 104 if(getNext()!=null) 105 { 106 //we might switch to one neighbor segment 122 107 if(m.x<leftP.x) 123 108 { … … 138 123 System.out.println("entering right segment"); 139 124 } 140 //highP = Main.map.mapView.getPoint(l.getCurr().getEastNorth());141 //lowP = Main.map.mapView.getPoint(l.getNext().getEastNorth());142 125 if(!invalid) 143 126 { 144 float slope =(float)(highP.y-lowP.y) / (float)(highP.x - lowP.x);127 float slope = getSlope(highP, lowP); 145 128 m.y = highP.y+Math.round(slope*(m.x-highP.x)); 146 129 } … … 149 132 { 150 133 //currently we are at the end 151 Point p2 = Main.map.mapView.getPoint(getPrev().getEastNorth()); 152 if (p1.x>p2.x) 153 { 154 leftP=p2; 155 rightP=p1; 134 if(m.x>rightP.x) 135 { 136 m=rightP; //we can't move anywhere 156 137 } 157 138 else 158 139 { 159 leftP=p1; 160 rightP=p2; 161 } 162 if(m.x>rightP.x) 163 { 164 m=rightP; //we can't move anywhere 165 } 166 else 167 { 168 prev(); 169 } 170 171 172 } 173 //System.out.println((m)); 140 prev(); //walk back to the segment before 141 } 142 } 174 143 return m; 175 144 } 176 145 146 private Point getInterpolated(float percent) 147 { 148 149 int dX,dY; 150 Point p; 151 Point leftP,rightP,highP,lowP; 152 Point c = Main.map.mapView.getPoint(getCurr().getEastNorth()); 153 Point p1 = Main.map.mapView.getPoint(getCurr().getEastNorth()); 154 Point p2 = getEndpoint(); 155 //determine which point is what 156 leftP=getLeftPoint(p1, p2); 157 rightP=getRightPoint(p1,p2); 158 highP=getHighPoint(p1, p2); 159 lowP=getLowPoint(p1, p2); 160 //we will never go over the segment 161 percent=percent/100; 162 dX=Math.round((rightP.x-leftP.x)*percent); 163 dY=Math.round((rightP.y-leftP.y)*percent); 164 //move in the right direction 165 p=new Point(rightP.x-dX,rightP.y-dY); 166 167 return p; 168 } 169 177 170 //gets further infos for a point between two Waypoints 178 171 public WayPoint getInterpolatedWaypoint(Point m) … … 184 177 185 178 Point curr =Main.map.mapView.getPoint(getCurr().getEastNorth()); 186 m =getInterpolated(m); 179 m =getInterpolated(m); //get the right position 180 //get the right time 181 p2=getEndpoint(); 187 182 if (getNext()!=null) 188 183 { 189 p2 =Main.map.mapView.getPoint(getNext().getEastNorth());190 184 timeSeg=getNext().getTime().getTime()-getCurr().getTime().getTime(); 191 185 } 192 186 else 193 187 { 194 p2 =Main.map.mapView.getPoint(getPrev().getEastNorth());195 188 timeSeg=-(getPrev().getTime().getTime()-getCurr().getTime().getTime()); 196 189 } 197 190 WayPoint w =new WayPoint(Main.map.mapView.getLatLon(m.x, m.y)); 198 191 //calc total traversal length 192 lengthSeg = getTraversalLength(p2, curr); 193 length = getTraversalLength(p2, m); 194 length=lengthSeg-length; 195 //calc time difference 196 ratio=(float)length/(float)lengthSeg; 197 long inc=(long) (timeSeg*ratio); 198 long old = getCurr().getTime().getTime(); 199 old=old+inc; 200 Date t = new Date(old); 201 w.time = t.getTime()/1000; //TODO need better way to set time 202 SimpleDateFormat df = new SimpleDateFormat("hh:mm:ss:S"); 203 /*System.out.print(length+"px "); 204 System.out.print(ratio+"% "); 205 System.out.print(inc+"ms "); 206 System.out.println(df.format(t.getTime()));+*/ 207 System.out.println(df.format(w.getTime())); 208 //TODO we have to publish the new date to the node... 209 return w; 210 } 211 212 private WayPoint getInterpolatedWaypoint(float percentage) 213 { 214 Point p = getInterpolated(percentage); 215 WayPoint w =new WayPoint(Main.map.mapView.getLatLon(p.x, p.y)); 216 return w; 217 } 218 219 public List<WayPoint> getInterpolatedLine(int interval) 220 { 221 List<WayPoint> ls; 222 Point p2; 223 float step; 224 int length; 225 226 step=100/(float)interval; 227 ls=new LinkedList<WayPoint>(); 228 for(float i=step;i<100;i+=step) 229 { 230 ls.add(getInterpolatedWaypoint(i)); 231 } 232 return ls; 233 } 234 235 private Point getLeftPoint(Point p1,Point p2) 236 { 237 if(p1.x<p2.x) return p1; else return p2; 238 } 239 240 private Point getRightPoint(Point p1, Point p2) 241 { 242 if(p1.x>p2.x) return p1; else return p2; 243 } 244 245 private Point getHighPoint(Point p1, Point p2) 246 { 247 if(p1.y<p2.y)return p1; else return p2; 248 } 249 250 private Point getLowPoint(Point p1, Point p2) 251 { 252 if(p1.y>p2.y)return p1; else return p2; 253 } 254 255 private Point getEndpoint() { 256 if(getNext()!=null) 257 { 258 return Main.map.mapView.getPoint(getNext().getEastNorth()); 259 } 260 else 261 { 262 return Main.map.mapView.getPoint(getPrev().getEastNorth()); 263 } 264 265 } 266 267 private float getSlope(Point highP, Point lowP) { 268 float slope=(float)(highP.y-lowP.y) / (float)(highP.x - lowP.x); 269 return slope; 270 } 271 272 private int getTraversalLength(Point p2, Point curr) { 273 int a; 274 int b; 275 int lengthSeg; 199 276 a=Math.abs(curr.x-p2.x); 200 277 b=Math.abs(curr.y-p2.y); 201 278 lengthSeg= (int) Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2)); 202 a=Math.abs(m.x-p2.x); 203 b=Math.abs(m.y-p2.y); 204 length= (int) Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2)); 205 length=lengthSeg-length; 206 ratio=(float)length/(float)lengthSeg; 207 long inc=(long) (timeSeg*ratio); 208 SimpleDateFormat df = new SimpleDateFormat("hh:mm:ss:S"); 209 long old = getCurr().getTime().getTime(); 210 old=old+inc; 211 System.out.print(length+"px "); 212 System.out.print(ratio+"% "); 213 System.out.print(inc+"ms "); 214 System.out.println(df.format(old)); 215 Date t = new Date(old); 216 //TODO we have to publish the new date to the node... 217 return w; 218 } 219 220 public List<WayPoint> getInterpolatedLine(int interval) 221 { 222 Point p2; 223 Point curr =Main.map.mapView.getPoint(getCurr().getEastNorth()); 224 if (getNext()!=null) 225 { 226 p2 =Main.map.mapView.getPoint(getNext().getEastNorth()); 227 } 228 else 229 { 230 p2 =Main.map.mapView.getPoint(getPrev().getEastNorth()); 231 } 232 int a=Math.abs(curr.x-p2.x); 233 int b=Math.abs(curr.y-p2.y); 234 int length= (int) Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2)); 235 float step=length/interval; 236 //TODO here we go 237 return null; 238 } 239 240 279 return lengthSeg; 280 } 281 282 public void pause() { 283 // TODO Auto-generated method stub 284 285 } 286 287 241 288 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/PositionLayer.java
r21524 r21555 9 9 import java.util.Date; 10 10 import java.util.Iterator; 11 import java.util.LinkedList; 11 12 import java.util.List; 12 13 import java.util.ListIterator; … … 44 45 import org.openstreetmap.josm.gui.layer.Layer; 45 46 import org.openstreetmap.josm.tools.ImageProvider; 47 import org.openstreetmap.josm.tools.Shortcut; 46 48 47 49 public class PositionLayer extends Layer implements MouseListener,MouseMotionListener, KeyListener { … … 49 51 private GpsPlayer l; 50 52 private Collection<WayPoint> selected; 53 private Timer t; 51 54 private TimerTask ani; 52 55 private boolean dragIcon=false; //do we move the icon by hand? … … 54 57 private Point mouse; 55 58 private ImageIcon icon; 59 private SimpleDateFormat df; 56 60 57 61 public PositionLayer(String name, final List<WayPoint> ls) { … … 60 64 l= new GpsPlayer(ls); 61 65 selected = new ArrayList<WayPoint>(); 62 icon=ImageProvider.get("videomapping.png"); 66 icon=ImageProvider.get("videomapping.png"); 67 df = new SimpleDateFormat("hh:mm:ss:S"); 63 68 Main.map.mapView.addMouseListener(this); 64 69 Main.map.mapView.addMouseMotionListener(this); 65 Main.map.mapView.getRootPane().getGlassPane().addKeyListener(this); 66 //Main.panel.addKeyListener(this); 67 //Main.map.mapView.addKeyListener(this); 68 System.err.println("key :"); 69 70 Action a = new AbstractAction() { 70 addKeys(); 71 72 } 73 74 //add key bindings for navigate through the track (and if synced trough the video, too) 75 private void addKeys() { 76 Action backward = new AbstractAction() { 71 77 public void actionPerformed(ActionEvent e) { 72 // TODO Auto-generated method stub73 System.err.println("!!!boom!!!");78 if(l!=null)l.prev(); 79 Main.map.mapView.repaint(); 74 80 }}; 75 Main.registerActionShortcut(a, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0));76 77 //Main.map.mapView.addKeyListener(this);78 //Main.contentPane.getInputMap().put(KeyStroke.getKeyStroke("SPACE"),"pressed");79 //Main.contentPane.getActionMap().put("pressed",a);80 81 //Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE,0),a);82 //Main.contentPane.getActionMap().put("doSomething",a);83 84 TimerTask ani=new TimerTask() {85 81 86 @Override 87 //some cheap animation stuff 88 public void run() { 89 l.next(); 82 Action forward = new AbstractAction() { 83 public void actionPerformed(ActionEvent e) { 84 if(l!=null)l.next(); 90 85 Main.map.mapView.repaint(); 91 } 92 }; 93 Timer t= new Timer(); 94 //t.schedule(ani,2000,2000); 95 //l.next(); 96 86 }}; 87 Action startStop = new AbstractAction() { 88 public void actionPerformed(ActionEvent e) { 89 if (t==null) 90 { 91 //start 92 t= new Timer(); 93 TimerTask ani=new TimerTask() { 94 @Override 95 //some cheap animation stuff 96 public void run() { 97 l.next(); 98 Main.map.mapView.repaint(); 99 } 100 }; 101 t.schedule(ani,500,500); 102 } 103 else 104 { 105 //stop 106 t.cancel(); 107 t=null; 108 } 109 }}; 110 //TODO custome Shortkey management 111 Main.registerActionShortcut(backward, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)); 112 Main.registerActionShortcut(forward, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)); 113 //Main.registerActionShortcut(startStop, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)); 97 114 } 98 115 … … 174 191 g.drawLine(p.x, p.y, p2.x, p2.y); 175 192 } 193 //draw interpolated points 194 g.setColor(Color.CYAN); 195 g.setBackground(Color.CYAN); 196 LinkedList<WayPoint> ipo=(LinkedList<WayPoint>) l.getInterpolatedLine(5); 197 for (WayPoint wp : ipo) { 198 p=Main.map.mapView.getPoint(wp.getEastNorth()); 199 g.fillArc(p.x, p.y, 4, 4, 0, 360); 200 //g.drawOval(p.x - 2, p.y - 2, 4, 4); 201 } 176 202 //draw cam icon 203 g.setColor(Color.RED); 177 204 if(dragIcon) 178 205 { … … 180 207 { 181 208 p=Main.map.mapView.getPoint(iconPosition.getEastNorth()); 182 icon.paintIcon(null, g, p.x-icon.getIconWidth()/2, p.y-icon.getIconHeight()/2); 183 g.drawString( iconPosition.getTime().toString(),p.x,p.y);209 icon.paintIcon(null, g, p.x-icon.getIconWidth()/2, p.y-icon.getIconHeight()/2); 210 g.drawString(df.format(iconPosition.getTime()),p.x,p.y); 184 211 } 185 212 } … … 188 215 if (l.getCurr()!=null){ 189 216 p=Main.map.mapView.getPoint(l.getCurr().getEastNorth()); 190 icon.paintIcon(null, g, p.x-icon.getIconWidth()/2, p.y-icon.getIconHeight()/2); 191 g.drawString(l.getCurr().getTime().toString(), p.x, p.y); 192 } 217 icon.paintIcon(null, g, p.x-icon.getIconWidth()/2, p.y-icon.getIconHeight()/2); 218 g.drawString(df.format(l.getCurr().getTime()),p.x,p.y); 219 } 220 } 221 } 222 223 public void pause() 224 { 225 if (t==null) 226 { 227 //start 228 t= new Timer(); 229 TimerTask ani=new TimerTask() { 230 @Override 231 //some cheap animation stuff 232 public void run() { 233 l.next(); 234 Main.map.mapView.repaint(); 235 } 236 }; 237 t.schedule(ani,500,500); 238 } 239 else 240 { 241 //stop 242 t.cancel(); 243 t=null; 193 244 } 194 245 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoMappingPlugin.java
r21519 r21555 2 2 3 3 import java.awt.Component; 4 import java.awt.event.ActionEvent; 4 5 import java.awt.event.KeyEvent; 5 6 … … 10 11 import org.openstreetmap.josm.Main; 11 12 import org.openstreetmap.josm.plugins.*; 13 import org.openstreetmap.josm.plugins.videomapping.actions.StartStopAction; 14 import org.openstreetmap.josm.plugins.videomapping.actions.VideoAddAction; 12 15 import org.openstreetmap.josm.tools.ImageProvider; 16 import org.openstreetmap.josm.actions.JosmAction; 13 17 import org.openstreetmap.josm.data.gpx.GpxData; 14 18 import org.openstreetmap.josm.gui.MainMenu; … … 21 25 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 22 26 23 public class VideoMappingPlugin extends Plugin implements LayerChangeListener{ 27 /** 28 * @author Matthias Meißer 29 * @ released under GPL 30 * This Plugin allows you to link a video against a GPS track and playback both synchronously 31 */ 32 public class VideoMappingPlugin extends Plugin implements LayerChangeListener{ 24 33 private JMenu VMenu; 25 34 private GpxData GPSTrack; 26 private VideoAction VAction; 35 private VideoAddAction VAdd; 36 private StartStopAction VStart; 27 37 28 38 … … 30 40 super(info); 31 41 //Register for GPS menu 32 VMenu = Main.main.menu.addMenu(" Video", KeyEvent.VK_V, Main.main.menu.defaultMenuPos,ht("/Plugin/Videomapping"));//TODO no more ugly " video" hack 33 VMenu.setEnabled(false); //enabled only on GPS Layers 34 VAction = new VideoAction(); 35 VMenu.add(VAction); 42 VMenu = Main.main.menu.addMenu(" Video", KeyEvent.VK_V, Main.main.menu.defaultMenuPos,ht("/Plugin/Videomapping"));//TODO no more ugly " video" hack 43 addMenuItems(); 36 44 //setup 37 45 MapView.addLayerChangeListener(this); 38 //plugin informations are provided by build.xml properties 39 } 40 41 42 //only used with GPS layers 46 //further plugin informations are provided by build.xml properties 47 } 48 49 //only use with GPS and own layers 43 50 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 44 51 if (newLayer instanceof GpxLayer) 45 52 { 46 V Menu.setEnabled(true);53 VAdd.setEnabled(true); 47 54 GPSTrack=((GpxLayer) newLayer).data; 48 VA ction.setGps(GPSTrack);55 VAdd.setGps(GPSTrack); 49 56 //TODO append to GPS Layer menu 50 51 57 } 52 else VMenu.setEnabled(false); 58 else 59 { 60 VAdd.setEnabled(false); 61 if(newLayer instanceof PositionLayer) 62 { 63 enableControlMenus(true); 64 } 65 else 66 { 67 enableControlMenus(false); 68 } 69 } 53 70 54 71 } 55 72 56 73 public void layerAdded(Layer arg0) { 57 activeLayerChange(null,arg0); 74 activeLayerChange(null,arg0); 58 75 } 59 76 60 77 public void layerRemoved(Layer arg0) { 78 } //well ok we have a local copy of the GPS track.... 79 80 private void addMenuItems() { 81 VAdd= new VideoAddAction(this); 82 VStart = new StartStopAction(); 83 VMenu.add(VAdd); 84 enableControlMenus(false); 85 VMenu.add(VStart); 61 86 } 62 63 64 87 88 public void setMyLayer(PositionLayer layer) 89 { 90 VStart.setLayer(layer); 91 enableControlMenus(true); 92 } 93 94 private void enableControlMenus(boolean enabled) 95 { 96 VStart.setEnabled(enabled); 97 } 65 98 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/actions/VideoAddAction.java
r21530 r21555 1 package org.openstreetmap.josm.plugins.videomapping ;1 package org.openstreetmap.josm.plugins.videomapping.actions; 2 2 3 3 import java.awt.event.ActionEvent; … … 19 19 import org.openstreetmap.josm.data.osm.Way; 20 20 import org.openstreetmap.josm.gui.layer.GpxLayer; 21 import org.openstreetmap.josm.plugins.videomapping.PositionLayer; 22 import org.openstreetmap.josm.plugins.videomapping.VideoMappingPlugin; 21 23 import org.openstreetmap.josm.tools.DateUtils; 22 24 import org.openstreetmap.josm.tools.Shortcut; … … 24 26 import static org.openstreetmap.josm.tools.I18n.*; 25 27 26 public class VideoA ction extends JosmAction {27 28 public class VideoAddAction extends JosmAction { 29 private VideoMappingPlugin plugin; 28 30 private GpxData gps; 29 31 private DataSet ds; //all extracted GPS points 30 32 private List<WayPoint> ls; 31 33 32 public VideoA ction() {34 public VideoAddAction(VideoMappingPlugin plugin) { 33 35 super("Sync Video","videomapping","Sync a video against this GPS track",null,true); 36 this.plugin=plugin; 34 37 } 35 38 36 39 // Choose a file 37 40 public void actionPerformed(ActionEvent arg0) { 41 38 42 copyGPSLayer(); 39 Main.main.addLayer(new PositionLayer("test",ls)); 43 PositionLayer l = new PositionLayer("test",ls); 44 Main.main.addLayer(l); 45 plugin.setMyLayer(l); 40 46 41 47 } … … 46 52 } 47 53 48 //makes a privateflat copy for interaction54 //makes a local flat copy for interaction 49 55 private void copyGPSLayer() 50 56 { … … 59 65 60 66 } 67 68
Note:
See TracChangeset
for help on using the changeset viewer.