Changeset 25796 in osm for applications/editors/josm/plugins/videomapping/src
- Timestamp:
- 2011-04-05T19:10:54+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping
- Files:
-
- 2 edited
-
VideoPlugin.java (modified) (2 diffs)
-
VideoPositionLayer.java (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoPlugin.java
r25765 r25796 37 37 import uk.co.caprica.vlcj.runtime.windows.WindowsRuntimeUtil; 38 38 39 import com.sun.jna.LastErrorException; 39 40 import com.sun.jna.NativeLibrary; 40 41 … … 50 51 //Here we manage properties and start the other classes 51 52 public class VideoPlugin extends Plugin implements LayerChangeListener{ 53 private JMenu VMenu,VDeinterlacer; 54 private JosmAction VAdd,VRemove,VStart,Vbackward,Vforward,VJump,Vfaster,Vslower,Vloop; 55 private JRadioButtonMenuItem VIntBob,VIntNone,VIntLinear; 56 private JCheckBoxMenuItem VCenterIcon,VSubTitles; 57 private JMenuItem VJumpLength,VLoopLength; 58 private final String PROP_MRU="videomapping.mru"; 59 private final String PROP_AUTOCENTER="videomapping.autocenter"; 60 private final String PROP_JUMPLENGTH="videomapping.jumplength"; 61 private final String PROP_LOOPLENGTH="videomapping.looplength"; 62 private String deinterlacer; 63 private boolean autoCenter; 64 private Integer jumpLength,loopLength; 65 private String mostRecentFolder; 66 private GpxLayer gpsLayer; 52 67 53 68 public VideoPlugin(PluginInformation info) { 54 69 super(info); 55 // TODO Auto-generated constructor stub 56 } 57 58 public void activeLayerChange(Layer arg0, Layer arg1) { 59 // TODO Auto-generated method stub 70 MapView.addLayerChangeListener(this); 71 createMenusAndShortCuts(); 72 enableVideoControlMenus(false); 73 setDefaults(); 74 loadProperties(); 75 } 76 77 private void createMenusAndShortCuts() { 78 VMenu = Main.main.menu.addMenu(" Video", KeyEvent.VK_V, Main.main.menu.defaultMenuPos,ht("/Plugin/Videomapping")); 79 VMenu.setEnabled(false); 80 VAdd= new JosmAction(tr("Import Video"),"videomapping",tr("Sync a video against this GPS track"),null,false) { 81 public void actionPerformed(ActionEvent arg0) { 82 importVideoFile(); 83 } 84 85 }; 86 VRemove= new JosmAction(tr("Remove Video"),"videomapping",tr("removes current video from layer"),null,false) { 87 private static final long serialVersionUID = 1L; 88 89 public void actionPerformed(ActionEvent arg0) { 90 } 91 }; 92 VStart = new JosmAction(tr("Play/Pause"), "audio-playpause", tr("starts/pauses video playback"), 93 Shortcut.registerShortcut("videomapping:startstop","Video: "+tr("Play/Pause"),KeyEvent.VK_NUMPAD5, Shortcut.GROUP_DIRECT), false) { 94 public void actionPerformed(ActionEvent e) { 95 96 } 97 }; 98 Vbackward = new JosmAction(tr("Backward"), "audio-prev", tr("jumps n sec back"), 99 Shortcut.registerShortcut("videomapping:backward","Video: "+tr("Backward"),KeyEvent.VK_NUMPAD4, Shortcut.GROUP_DIRECT), false) { 100 public void actionPerformed(ActionEvent e) { 101 102 } 103 }; 104 Vforward= new JosmAction(tr("Forward"), "audio-next", tr("jumps n sec forward"), 105 Shortcut.registerShortcut("videomapping:forward","Video: "+tr("Forward"),KeyEvent.VK_NUMPAD6, Shortcut.GROUP_DIRECT), false) { 106 public void actionPerformed(ActionEvent e) { 107 108 109 } 110 }; 111 Vfaster= new JosmAction(tr("Faster"), "audio-faster", tr("faster playback"), 112 Shortcut.registerShortcut("videomapping:faster","Video: "+tr("Faster"),KeyEvent.VK_NUMPAD8, Shortcut.GROUP_DIRECT), false) { 113 114 public void actionPerformed(ActionEvent e) { 115 116 117 } 118 }; 119 Vslower= new JosmAction(tr("Slower"), "audio-slower", tr("slower playback"), 120 Shortcut.registerShortcut("videomapping:slower","Video: "+tr("Slower"),KeyEvent.VK_NUMPAD2, Shortcut.GROUP_DIRECT), false) { 121 122 public void actionPerformed(ActionEvent e) { 123 124 125 } 126 }; 127 VJump= new JosmAction(tr("Jump To"), "jumpto", tr("jumps to the entered gps time"),null, false) { 128 public void actionPerformed(ActionEvent e) { 129 130 131 } 132 133 134 }; 135 Vloop= new JosmAction(tr("Loop"), "loop", tr("loops n sec around current position"), 136 Shortcut.registerShortcut("videomapping:loop","Video: "+tr("loop"),KeyEvent.VK_NUMPAD7, Shortcut.GROUP_DIRECT), false) { 137 public void actionPerformed(ActionEvent e) { 138 139 140 } 141 }; 142 143 //now the options menu 144 VCenterIcon = new JCheckBoxMenuItem(new JosmAction(tr("Keep centered"), null, tr("follows the video icon automaticly"),null, false) { 145 public void actionPerformed(ActionEvent e) { 146 147 148 } 149 }); 150 //now the options menu 151 VSubTitles = new JCheckBoxMenuItem(new JosmAction(tr("Subtitles"), null, tr("Show subtitles in video"),null, false) { 152 public void actionPerformed(ActionEvent e) { 153 154 155 } 156 }); 157 158 VJumpLength = new JMenuItem(new JosmAction(tr("Jump length"), null, tr("Set the length of a jump"),null, false) { 159 public void actionPerformed(ActionEvent e) { 160 } 161 }); 162 163 VLoopLength = new JMenuItem(new JosmAction(tr("Loop length"), null, tr("Set the length around a looppoint"),null, false) { 164 public void actionPerformed(ActionEvent e) { 165 166 167 } 168 }); 169 VDeinterlacer= new JMenu("Deinterlacer"); 170 VIntNone= new JRadioButtonMenuItem(new JosmAction(tr("none"), null, tr("no deinterlacing"),null, false) { 171 public void actionPerformed(ActionEvent e) { 172 } 173 }); 174 VIntBob= new JRadioButtonMenuItem(new JosmAction("bob", null, tr("deinterlacing using line doubling"),null, false) { 175 public void actionPerformed(ActionEvent e) { 176 177 } 178 }); 179 VIntLinear= new JRadioButtonMenuItem(new JosmAction("linear", null, tr("deinterlacing using linear interpolation"),null, false) { 180 public void actionPerformed(ActionEvent e) { 181 182 } 183 }); 184 VDeinterlacer.add(VIntNone); 185 VDeinterlacer.add(VIntBob); 186 VDeinterlacer.add(VIntLinear); 187 VMenu.add(VAdd); 188 VMenu.add(VStart); 189 VMenu.add(Vbackward); 190 VMenu.add(Vforward); 191 VMenu.add(Vfaster); 192 VMenu.add(Vslower); 193 VMenu.add(Vloop); 194 VMenu.add(VJump); 195 VMenu.addSeparator(); 196 VMenu.add(VCenterIcon); 197 VMenu.add(VJumpLength); 198 VMenu.add(VLoopLength); 199 VMenu.add(VDeinterlacer); 200 VMenu.add(VSubTitles); 201 202 } 203 204 protected void importVideoFile() { 205 JFileChooser fc = new JFileChooser(mostRecentFolder); 206 fc.setSelectedFile(new File(mostRecentFolder)); 207 if(fc.showOpenDialog(Main.main.parent)!=JFileChooser.CANCEL_OPTION) 208 { 209 // mostRecentFolder=fc.getSelectedFile().getAbsolutePath(); 210 // saveProperties(); 211 VideoPositionLayer videoPositionLayer= new VideoPositionLayer(gpsLayer); 212 } 60 213 61 214 } 62 215 216 private void enableVideoControlMenus(boolean b) { 217 VStart.setEnabled(b); 218 Vbackward.setEnabled(b); 219 Vforward.setEnabled(b); 220 Vloop.setEnabled(b); 221 Vfaster.setEnabled(b); 222 Vslower.setEnabled(b); 223 VJump.setEnabled(b); 224 } 225 226 private void setDefaults() 227 { 228 autoCenter=false; 229 deinterlacer=""; 230 jumpLength=1000; 231 loopLength=6000; 232 mostRecentFolder=System.getProperty("user.home"); 233 } 234 235 private void loadProperties() { 236 String temp; 237 temp=Main.pref.get(PROP_AUTOCENTER); 238 if((temp!=null)&&(temp.length()!=0)) 239 autoCenter=Boolean.getBoolean(temp); 240 temp=Main.pref.get(PROP_JUMPLENGTH); 241 if((temp!=null)&&(temp.length()!=0)) 242 jumpLength=Integer.valueOf(temp); 243 temp=Main.pref.get(PROP_LOOPLENGTH); 244 if((temp!=null)&&(temp.length()!=0)) 245 loopLength=Integer.valueOf(temp); 246 temp=Main.pref.get(PROP_MRU); 247 if((temp!=null)&&(temp.length()!=0)) 248 mostRecentFolder=Main.pref.get(PROP_MRU); 249 } 250 251 private void saveProperties(){ 252 Main.pref.put(PROP_AUTOCENTER, autoCenter); 253 Main.pref.put(PROP_JUMPLENGTH, jumpLength.toString()); 254 Main.pref.put(PROP_LOOPLENGTH, loopLength.toString()); 255 Main.pref.put(PROP_MRU, mostRecentFolder); 256 } 257 258 private void applySettings() 259 { 260 //GUI 261 VCenterIcon.setSelected(autoCenter); 262 VIntNone.setSelected(true); 263 if(deinterlacer=="") 264 VIntNone.setSelected(true); 265 if(deinterlacer=="bob") 266 VIntBob.setSelected(true); 267 if(deinterlacer=="linear") 268 VIntLinear.setSelected(true); 269 } 270 271 272 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 273 VMenu.setEnabled(true); 274 if (newLayer instanceof GpxLayer) 275 { 276 VAdd.setEnabled(true); 277 gpsLayer=((GpxLayer) newLayer); 278 //TODO append to GPS Layer menu 279 } 280 } 281 63 282 public void layerAdded(Layer arg0) { 64 // TODO Auto-generated method stub283 activeLayerChange(null,arg0); 65 284 66 285 } 67 286 68 287 public void layerRemoved(Layer arg0) { 69 // TODO Auto-generated method stub288 activeLayerChange(null,arg0); 70 289 71 290 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoPositionLayer.java
r25765 r25796 2 2 3 3 4 import java.text.DateFormat; 4 5 import java.text.SimpleDateFormat; 5 6 import java.util.Collections; … … 23 24 import org.openstreetmap.josm.Main; 24 25 import org.openstreetmap.josm.data.Bounds; 26 import org.openstreetmap.josm.data.coor.LatLon; 25 27 import org.openstreetmap.josm.data.gpx.GpxData; 26 28 import org.openstreetmap.josm.data.gpx.GpxTrack; … … 37 39 //Basic rendering and GPS layer interaction 38 40 public class VideoPositionLayer extends Layer implements MouseListener,MouseMotionListener { 39 40 public VideoPositionLayer(String name) { 41 super(name); 42 // TODO Auto-generated constructor stub 43 } 41 private List<WayPoint> gpsTrack; 42 private ImageIcon layerIcon; 43 private DateFormat gpsTimeFormat; 44 private WayPoint iconPosition; 45 private final int GPS_INTERVALL=1000; 46 47 public VideoPositionLayer(GpxLayer gpsLayer) { 48 super("videolayer"); 49 layerIcon = new ImageIcon("images/videomapping.png"); 50 gpsTrack=importGPSLayer(gpsLayer.data); 51 gpsTimeFormat= new SimpleDateFormat("HH:mm:ss"); 52 Main.map.mapView.addMouseListener(this); 53 Main.map.mapView.addMouseMotionListener(this); 54 iconPosition=gpsTrack.get(0); 55 Main.main.addLayer(this); 56 57 } 58 59 //make a flat copy 60 private List<WayPoint> importGPSLayer(GpxData gps) { 61 LinkedList<WayPoint> ls = new LinkedList<WayPoint>(); 62 for (GpxTrack trk : gps.tracks) { 63 for (GpxTrackSegment segment : trk.getSegments()) { 64 ls.addAll(segment.getWayPoints()); 65 } 66 } 67 Collections.sort(ls); //sort basing upon time 68 return ls; 69 70 } 71 72 @Override 73 public void paint(Graphics2D g, MapView map, Bounds bound) { 74 paintGpsTrack(g); 75 paintPositionIcon(g); 76 paintInterpolatedSegment(g); 77 } 78 79 private void paintGpsTrack(Graphics2D g) { 80 g.setColor(Color.YELLOW); 81 for(WayPoint n: gpsTrack) { 82 Point p = Main.map.mapView.getPoint(n.getEastNorth()); 83 g.drawOval(p.x - 2, p.y - 2, 4, 4); 84 } 85 } 86 87 private void paintPositionIcon(Graphics2D g) { 88 Point p=Main.map.mapView.getPoint(iconPosition.getEastNorth()); 89 layerIcon.paintIcon(null, g, p.x-layerIcon.getIconWidth()/2, p.y-layerIcon.getIconHeight()/2); 90 g.drawString(gpsTimeFormat.format(iconPosition.getTime()),p.x-15,p.y-15); 91 } 92 93 private void paintInterpolatedSegment(Graphics2D g) { 94 g.setColor(Color.CYAN); 95 List<WayPoint>ls=getInterpolatedSegment(iconPosition,5,5); 96 for(WayPoint n: ls) { 97 Point p = Main.map.mapView.getPoint(n.getEastNorth()); 98 g.drawOval(p.x - 2, p.y - 2, 4, 4); 99 } 100 101 } 102 103 private List<WayPoint> getInterpolatedSegment(WayPoint center, int before, int after) { 104 LinkedList<WayPoint> ls = new LinkedList<WayPoint>(); 105 if(gpsTrack.indexOf(iconPosition)!=0) 106 { 107 WayPoint prev=gpsTrack.get(gpsTrack.indexOf(iconPosition)-1); 108 for(int i=1;i<=before;i++) 109 { 110 ls.add(interpolate(prev,(float)100f/before*i)); 111 } 112 } 113 for(int i=1;i<=after;i++) 114 { 115 ls.add(interpolate(iconPosition,(float)100f/before*i)); 116 } 117 //test code 118 Date test=getFirstWayPoint().getTime(); 119 test.setHours(14); 120 test.setMinutes(50); 121 test.setSeconds(33); 122 123 ls.add(getWayPointBefore(new Date(test.getTime()+500))); 124 ls.add(interpolate(new Date(test.getTime()+500))); 125 System.out.print(test); 126 return ls; 127 } 128 129 //creates a waypoint for the corresponding time 130 private WayPoint interpolate(Date GPSTime) 131 { 132 WayPoint before =getWayPointBefore(GPSTime); 133 long diff=GPSTime.getTime()-before.getTime().getTime(); 134 assert diff>=0; 135 assert diff<GPS_INTERVALL; 136 float perc=((float)diff/(float)GPS_INTERVALL)*100; 137 return interpolate(before,perc); 138 } 139 140 private WayPoint getWayPointBefore(Date GPSTime) 141 { 142 assert GPSTime.after(getFirstWayPoint().getTime())==true; 143 assert GPSTime.before(getLastWayPoint().getTime())==true; 144 145 Date first=getFirstWayPoint().getTime(); 146 long diff=GPSTime.getTime()-first.getTime(); 147 //assumes that GPS intervall is constant 148 int id=(int) (diff/GPS_INTERVALL); 149 return gpsTrack.get(id); 150 } 151 152 public WayPoint getFirstWayPoint() 153 { 154 return gpsTrack.get(0); 155 } 156 157 public WayPoint getLastWayPoint() 158 { 159 return gpsTrack.get(gpsTrack.size()-1); 160 } 161 162 //interpolates a waypoint between this and the following waypoint at percent 163 private WayPoint interpolate(WayPoint first, float percent) { 164 assert (percent>0); 165 assert (percent<100); 166 double dX,dY; 167 WayPoint leftP,rightP; 168 169 170 WayPoint next=gpsTrack.get(gpsTrack.indexOf(first)+1); 171 //determine which point is what 172 leftP=getLeftPoint(first, next); 173 rightP=getRightPoint(first,next); 174 //calc increment 175 percent=percent/100; 176 dX=(rightP.getCoor().lon()-leftP.getCoor().lon())*percent; 177 dY=(rightP.getCoor().lat()-leftP.getCoor().lat())*percent; 178 //move in the right direction 179 if (first==leftP) 180 { 181 return new WayPoint(new LatLon(leftP.getCoor().lat()+dY,leftP.getCoor().lon()+dX)); 182 } 183 else 184 return new WayPoint(new LatLon(rightP.getCoor().lat()-dY,rightP.getCoor().lon()-dX)); 185 186 187 } 188 189 private WayPoint getLeftPoint(WayPoint p1,WayPoint p2) 190 { 191 if(p1.getCoor().lon()<p2.getCoor().lon()) return p1; else return p2; 192 } 193 194 private WayPoint getRightPoint(WayPoint p1, WayPoint p2) 195 { 196 if(p1.getCoor().lon()>p2.getCoor().lon()) return p1; else return p2; 197 } 198 199 public void mouseReleased(MouseEvent e) { 200 //only leftclicks on our layer 201 if(e.getButton() == MouseEvent.BUTTON1) { 202 WayPoint wp = getNearestWayPoint(e.getPoint()); 203 if(wp!=null) 204 { 205 iconPosition=wp; 206 } 207 Main.map.mapView.repaint(); 208 } 209 210 } 211 212 //finds the first waypoint that is nearby the given point 213 private WayPoint getNearestWayPoint(Point mouse) 214 { 215 final int MAX=10; 216 Point p; 217 Rectangle rect = new Rectangle(mouse.x-MAX/2,mouse.y-MAX/2,MAX,MAX); 218 //iterate through all possible notes 219 for(WayPoint n : gpsTrack) 220 { 221 p = Main.map.mapView.getPoint(n.getEastNorth()); 222 if (rect.contains(p)) 223 { 224 return n; 225 } 226 227 } 228 return null; 229 230 } 44 231 45 232 @Override 46 233 public Icon getIcon() { 234 return layerIcon; 235 } 236 237 @Override 238 public Object getInfoComponent() { 47 239 // TODO Auto-generated method stub 48 240 return null; … … 50 242 51 243 @Override 52 public Object getInfoComponent() {53 // TODO Auto-generated method stub54 return null;55 }56 57 @Override58 244 public Action[] getMenuEntries() { 59 // TODO Auto-generated method stub 60 return null; 61 } 245 return new Action[]{ 246 LayerListDialog.getInstance().createActivateLayerAction(this), 247 LayerListDialog.getInstance().createShowHideLayerAction(), 248 LayerListDialog.getInstance().createDeleteLayerAction(), 249 SeparatorLayerAction.INSTANCE, 250 new LayerListPopup.InfoAction(this)}; 251 } 252 62 253 63 254 @Override 64 255 public String getToolTipText() { 65 // TODO Auto-generated method stub 66 return null; 67 } 68 69 @Override 70 public boolean isMergable(Layer arg0) { 71 // TODO Auto-generated method stub 256 return tr("Shows current position in the video"); 257 } 258 259 @Override 260 public boolean isMergable(Layer arg0) { 72 261 return false; 73 262 } … … 75 264 @Override 76 265 public void mergeFrom(Layer arg0) { 77 // TODO Auto-generated method stub78 79 }80 81 @Override82 public void paint(Graphics2D arg0, MapView arg1, Bounds arg2) {83 // TODO Auto-generated method stub84 266 85 267 } … … 107 289 108 290 public void mousePressed(MouseEvent arg0) { 109 // TODO Auto-generated method stub110 111 }112 113 public void mouseReleased(MouseEvent arg0) {114 291 // TODO Auto-generated method stub 115 292
Note:
See TracChangeset
for help on using the changeset viewer.
