Changeset 21519 in osm for applications/editors/josm/plugins/videomapping/src
- Timestamp:
- 2010-05-30T19:59:11+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/GpsPlayer.java
r21468 r21519 1 1 package org.openstreetmap.josm.plugins.videomapping; 2 2 3 import java.awt.Point; 4 import java.sql.Time; 5 import java.text.SimpleDateFormat; 6 import java.util.Date; 3 7 import java.util.List; 4 8 import java.util.ListIterator; … … 9 13 import org.openstreetmap.josm.data.gpx.WayPoint; 10 14 11 //for GPS play control secure stepping througt list15 //for GPS play control, secure stepping through list and interpolation work in current projection 12 16 public class GpsPlayer { 13 17 private List<WayPoint> ls; … … 53 57 next =curr; 54 58 curr=prev; 55 prev=ls.get(ls.indexOf(curr)-1);;59 if(ls.indexOf(curr)==0) prev=null;else prev=ls.get(ls.indexOf(curr)-1); 56 60 } 57 61 else prev=null; … … 68 72 } 69 73 else prev=null; 70 if(ls.indexOf(curr) <ls.size())74 if(ls.indexOf(curr)+1<ls.size()) 71 75 { 72 76 next=ls.get(ls.indexOf(curr)+1); … … 85 89 } 86 90 91 //gets only points on the line of the GPS track between waypoints nearby the point m 92 private Point getInterpolated(Point m) 93 { 94 Point leftP,rightP,highP,lowP; 95 boolean invalid = false; 96 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 122 if(m.x<leftP.x) 123 { 124 Point c = Main.map.mapView.getPoint(getCurr().getEastNorth()); 125 Point n = Main.map.mapView.getPoint(getNext().getEastNorth()); 126 if(n.x<c.x) next(); else prev(); 127 invalid=true; 128 m=leftP; 129 System.out.println("entering left segment"); 130 } 131 if(m.x>rightP.x) 132 { 133 Point c = Main.map.mapView.getPoint(getCurr().getEastNorth()); 134 Point n = Main.map.mapView.getPoint(getNext().getEastNorth()); 135 if(n.x>c.x) next(); else prev(); 136 invalid=true; 137 m=rightP; 138 System.out.println("entering right segment"); 139 } 140 //highP = Main.map.mapView.getPoint(l.getCurr().getEastNorth()); 141 //lowP = Main.map.mapView.getPoint(l.getNext().getEastNorth()); 142 if(!invalid) 143 { 144 float slope=(float)(highP.y-lowP.y) / (float)(highP.x - lowP.x); 145 m.y = highP.y+Math.round(slope*(m.x-highP.x)); 146 } 147 } 148 else 149 { 150 //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; 156 } 157 else 158 { 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)); 174 return m; 175 } 176 177 //gets further infos for a point between two Waypoints 178 public WayPoint getInterpolatedWaypoint(Point m) 179 { int a,b,length,lengthSeg; 180 long timeSeg; 181 float ratio; 182 Time base; 183 Point p2; 184 185 Point curr =Main.map.mapView.getPoint(getCurr().getEastNorth()); 186 m =getInterpolated(m); 187 if (getNext()!=null) 188 { 189 p2 =Main.map.mapView.getPoint(getNext().getEastNorth()); 190 timeSeg=getNext().getTime().getTime()-getCurr().getTime().getTime(); 191 } 192 else 193 { 194 p2 =Main.map.mapView.getPoint(getPrev().getEastNorth()); 195 timeSeg=-(getPrev().getTime().getTime()-getCurr().getTime().getTime()); 196 } 197 WayPoint w =new WayPoint(Main.map.mapView.getLatLon(m.x, m.y)); 198 //calc total traversal length 199 a=Math.abs(curr.x-p2.x); 200 b=Math.abs(curr.y-p2.y); 201 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 87 240 88 241 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/PositionLayer.java
r21468 r21519 2 2 3 3 4 import java.sql.Time; 5 import java.text.DateFormat; 6 import java.text.SimpleDateFormat; 4 7 import java.util.ArrayList; 5 8 import java.util.Collection; 9 import java.util.Date; 6 10 import java.util.Iterator; 7 11 import java.util.List; … … 47 51 private TimerTask ani; 48 52 private boolean dragIcon=false; //do we move the icon by hand? 53 private WayPoint iconPosition; 49 54 private Point mouse; 50 55 private ImageIcon icon; … … 55 60 l= new GpsPlayer(ls); 56 61 selected = new ArrayList<WayPoint>(); 57 icon=ImageProvider.get("videomapping.png"); 58 Action a = new AbstractAction() { 59 public void actionPerformed(ActionEvent e) { 60 // TODO Auto-generated method stub 61 System.err.println("!!!boom!!!"); 62 }}; 62 icon=ImageProvider.get("videomapping.png"); 63 63 Main.map.mapView.addMouseListener(this); 64 64 Main.map.mapView.addMouseMotionListener(this); 65 65 Main.map.mapView.getRootPane().getGlassPane().addKeyListener(this); 66 66 //Main.panel.addKeyListener(this); 67 Main.map.mapView.addKeyListener(this);67 //Main.map.mapView.addKeyListener(this); 68 68 //Main.contentPane.getInputMap().put(KeyStroke.getKeyStroke("SPACE"),"pressed"); 69 69 //Main.contentPane.getActionMap().put("pressed",a); … … 83 83 Timer t= new Timer(); 84 84 //t.schedule(ani,2000,2000); 85 l.next();l.next();85 //l.next(); 86 86 87 87 } … … 167 167 if(dragIcon) 168 168 { 169 if( mouse!=null)170 { 171 p= mouse;169 if(iconPosition!=null) 170 { 171 p=Main.map.mapView.getPoint(iconPosition.getEastNorth()); 172 172 icon.paintIcon(null, g, p.x-icon.getIconWidth()/2, p.y-icon.getIconHeight()/2); 173 g.drawString(iconPosition.getTime().toString(),p.x,p.y); 173 174 } 174 175 } … … 183 184 } 184 185 185 private void markNearest Node(Point mouse) {186 private void markNearestWayPoints(Point mouse) { 186 187 final int MAX=10; 187 188 Point p; 188 Rectangle rect = new Rectangle(mouse.x-MAX/2,mouse.y-MAX/2, mouse.x+MAX/2,mouse.y+MAX/2);189 Rectangle rect = new Rectangle(mouse.x-MAX/2,mouse.y-MAX/2,MAX,MAX); 189 190 //iterate through all possible notes 190 191 for(WayPoint n : ls) … … 199 200 } 200 201 201 private WayPoint getNearest Point(Point mouse)202 private WayPoint getNearestWayPoint(Point mouse) 202 203 { 203 204 final int MAX=10; 204 205 Point p; 205 Rectangle rect = new Rectangle(mouse.x-MAX/2,mouse.y-MAX/2, mouse.x+MAX/2,mouse.y+MAX/2);206 Rectangle rect = new Rectangle(mouse.x-MAX/2,mouse.y-MAX/2,MAX,MAX); 206 207 //iterate through all possible notes 207 208 for(WayPoint n : ls) //TODO this is not very clever, what better way to find this WP? … … 261 262 { 262 263 //JOptionPane.showMessageDialog(Main.parent,"test"); 263 markNearest Node(e.getPoint());264 WayPoint wp = getNearest Point(e.getPoint());264 markNearestWayPoints(e.getPoint()); 265 WayPoint wp = getNearestWayPoint(e.getPoint()); 265 266 if(wp!=null) 266 267 { … … 273 274 } 274 275 275 //gets point on the line between276 private Point getInterpolated(Point m)277 {278 Point highest = Main.map.mapView.getPoint(l.getCurr().getEastNorth());279 Point smallest = Main.map.mapView.getPoint(l.getNext().getEastNorth());280 float slope=(float)(highest.y-smallest.y) / (float)(highest.x - smallest.x);281 282 m.y = highest.y+Math.round(slope*(m.x-highest.x));283 if(m.x<smallest.x)284 {285 m=smallest;286 }287 if(m.x>highest.x) m=highest;288 System.out.println((m));289 return m;290 }291 276 292 277 public void mouseDragged(MouseEvent e) { … … 295 280 mouse=e.getPoint(); 296 281 //restrict to GPS track 297 mouse=getInterpolated(mouse);282 iconPosition=l.getInterpolatedWaypoint(mouse); 298 283 299 284 Main.map.mapView.repaint(); … … 330 315 case KeyEvent.VK_RIGHT: 331 316 { 332 l.jump(1 0);317 l.jump(1); 333 318 };break; 334 319 case KeyEvent.VK_LEFT: 335 320 { 336 l.jump(-1 0);321 l.jump(-1); 337 322 338 323 };break; -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoMappingPlugin.java
r21299 r21519 36 36 //setup 37 37 MapView.addLayerChangeListener(this); 38 38 //plugin informations are provided by build.xml properties 39 39 } 40 40 41 41 42 //only used with GPS layers 42 43 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 43 44 if (newLayer instanceof GpxLayer)
Note:
See TracChangeset
for help on using the changeset viewer.