Ignore:
Timestamp:
2010-06-01T19:36:49+02:00 (14 years ago)
Author:
guardian
Message:
 
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  
    55        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
    66        <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">
    88                <attributes>
    99                        <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  
    44        <comment></comment>
    55        <projects>
     6                <project>JOSM</project>
    67        </projects>
    78        <buildSpec>
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/GpsPlayer.java

    r21519 r21555  
    55import java.text.SimpleDateFormat;
    66import java.util.Date;
     7import java.util.LinkedList;
    78import java.util.List;
    89import java.util.ListIterator;
     
    9394        {
    9495                Point leftP,rightP,highP,lowP;
    95                 boolean invalid = false;
     96                boolean invalid = false; //when we leave this segment
    9697                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
    122107                        if(m.x<leftP.x)
    123108                        {
     
    138123                                System.out.println("entering right segment");
    139124                        }
    140                         //highP = Main.map.mapView.getPoint(l.getCurr().getEastNorth());
    141                         //lowP = Main.map.mapView.getPoint(l.getNext().getEastNorth());
    142125                        if(!invalid)
    143126                        {
    144                                 float slope=(float)(highP.y-lowP.y) / (float)(highP.x - lowP.x);
     127                                float slope = getSlope(highP, lowP);
    145128                                m.y = highP.y+Math.round(slope*(m.x-highP.x));
    146129                        }
     
    149132                {
    150133                        //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
    156137                        }
    157138                        else
    158139                        {
    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                }
    174143                return m;
    175144        }
    176145       
     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
    177170        //gets further infos for a point between two Waypoints
    178171        public WayPoint getInterpolatedWaypoint(Point m)
     
    184177               
    185178                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();
    187182                if (getNext()!=null)
    188183                {
    189                         p2 =Main.map.mapView.getPoint(getNext().getEastNorth());
    190184                        timeSeg=getNext().getTime().getTime()-getCurr().getTime().getTime();
    191185                }
    192186                else
    193187                {
    194                         p2 =Main.map.mapView.getPoint(getPrev().getEastNorth());
    195188                        timeSeg=-(getPrev().getTime().getTime()-getCurr().getTime().getTime());
    196189                }
    197190                WayPoint w =new WayPoint(Main.map.mapView.getLatLon(m.x, m.y));
    198191                //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;
    199276                a=Math.abs(curr.x-p2.x);
    200277                b=Math.abs(curr.y-p2.y);
    201278                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       
    241288}
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/PositionLayer.java

    r21524 r21555  
    99import java.util.Date;
    1010import java.util.Iterator;
     11import java.util.LinkedList;
    1112import java.util.List;
    1213import java.util.ListIterator;
     
    4445import org.openstreetmap.josm.gui.layer.Layer;
    4546import org.openstreetmap.josm.tools.ImageProvider;
     47import org.openstreetmap.josm.tools.Shortcut;
    4648
    4749public class PositionLayer extends Layer implements MouseListener,MouseMotionListener, KeyListener {
     
    4951        private GpsPlayer l;
    5052        private Collection<WayPoint> selected;
     53        private Timer t;
    5154        private TimerTask ani;
    5255        private boolean dragIcon=false; //do we move the icon by hand?
     
    5457        private Point mouse;
    5558        private ImageIcon icon;
     59        private SimpleDateFormat df;
    5660               
    5761        public PositionLayer(String name, final List<WayPoint> ls) {
     
    6064                l= new GpsPlayer(ls);
    6165                selected = new ArrayList<WayPoint>();
    62                 icon=ImageProvider.get("videomapping.png");             
     66                icon=ImageProvider.get("videomapping.png");
     67                df = new SimpleDateFormat("hh:mm:ss:S");
    6368                Main.map.mapView.addMouseListener(this);
    6469                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() {
    7177                        public void actionPerformed(ActionEvent e) {
    72                                 // TODO Auto-generated method stub
    73                                 System.err.println("!!!boom!!!");
     78                                if(l!=null)l.prev();
     79                                Main.map.mapView.repaint();
    7480                        }};
    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() {
    8581                       
    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();
    9085                                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));
    97114        }
    98115
     
    174191                        g.drawLine(p.x, p.y, p2.x, p2.y);
    175192                }
     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                }
    176202                //draw cam icon
     203                g.setColor(Color.RED);
    177204                if(dragIcon)
    178205                {
     
    180207                        {
    181208                                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);
    184211                        }
    185212                }
     
    188215                        if (l.getCurr()!=null){
    189216                        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;                                 
    193244                }
    194245        }
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoMappingPlugin.java

    r21519 r21555  
    22
    33import java.awt.Component;
     4import java.awt.event.ActionEvent;
    45import java.awt.event.KeyEvent;
    56
     
    1011import org.openstreetmap.josm.Main;
    1112import org.openstreetmap.josm.plugins.*;
     13import org.openstreetmap.josm.plugins.videomapping.actions.StartStopAction;
     14import org.openstreetmap.josm.plugins.videomapping.actions.VideoAddAction;
    1215import org.openstreetmap.josm.tools.ImageProvider;
     16import org.openstreetmap.josm.actions.JosmAction;
    1317import org.openstreetmap.josm.data.gpx.GpxData;
    1418import org.openstreetmap.josm.gui.MainMenu;
     
    2125import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    2226
    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 */
     32public class VideoMappingPlugin extends Plugin implements LayerChangeListener{
    2433          private JMenu VMenu;
    2534          private GpxData GPSTrack;
    26           private VideoAction VAction;
     35          private VideoAddAction VAdd;
     36          private StartStopAction VStart;
    2737         
    2838
     
    3040                super(info);
    3141                //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();
    3644                //setup
    3745                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
    4350        public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    4451                if (newLayer instanceof GpxLayer)
    4552                {
    46                         VMenu.setEnabled(true);
     53                        VAdd.setEnabled(true);
    4754                        GPSTrack=((GpxLayer) newLayer).data;                   
    48                         VAction.setGps(GPSTrack);
     55                        VAdd.setGps(GPSTrack);
    4956                        //TODO append to GPS Layer menu
    50                        
    5157                }
    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                }
    5370               
    5471        }
    5572
    5673        public void layerAdded(Layer arg0) {
    57                 activeLayerChange(null,arg0);           
     74                activeLayerChange(null,arg0);
    5875        }
    5976
    6077        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);
    6186        }
    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        }
    6598  }
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/actions/VideoAddAction.java

    r21530 r21555  
    1 package org.openstreetmap.josm.plugins.videomapping;
     1package org.openstreetmap.josm.plugins.videomapping.actions;
    22
    33import java.awt.event.ActionEvent;
     
    1919import org.openstreetmap.josm.data.osm.Way;
    2020import org.openstreetmap.josm.gui.layer.GpxLayer;
     21import org.openstreetmap.josm.plugins.videomapping.PositionLayer;
     22import org.openstreetmap.josm.plugins.videomapping.VideoMappingPlugin;
    2123import org.openstreetmap.josm.tools.DateUtils;
    2224import org.openstreetmap.josm.tools.Shortcut;
     
    2426import static org.openstreetmap.josm.tools.I18n.*;
    2527
    26 public class VideoAction extends JosmAction {
    27 
     28public class VideoAddAction extends JosmAction {
     29        private VideoMappingPlugin plugin;
    2830        private GpxData gps;
    2931        private DataSet ds; //all extracted GPS points
    3032        private List<WayPoint> ls;
    3133
    32         public VideoAction() {
     34        public VideoAddAction(VideoMappingPlugin plugin) {
    3335                super("Sync Video","videomapping","Sync a video against this GPS track",null,true);
     36                this.plugin=plugin;
    3437        }
    3538
    3639        // Choose a file
    3740        public void actionPerformed(ActionEvent arg0) {
     41               
    3842                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);
    4046
    4147        }
     
    4652        }
    4753       
    48         //makes a private flat copy for interaction
     54        //makes a local flat copy for interaction
    4955        private void copyGPSLayer()
    5056        {
     
    5965
    6066}
     67
     68
Note: See TracChangeset for help on using the changeset viewer.