Changeset 30761 in osm for applications


Ignore:
Timestamp:
2014-10-21T13:32:12+02:00 (10 years ago)
Author:
donvip
Message:

[josm_gpsblam] fix sonar issues

Location:
applications/editors/josm/plugins/gpsblam
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/gpsblam/.settings/org.eclipse.jdt.core.prefs

    r30736 r30761  
    99org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
    1010org.eclipse.jdt.core.compiler.compliance=1.7
     11org.eclipse.jdt.core.compiler.doc.comment.support=enabled
    1112org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
    1213org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
     
    3233org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
    3334org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
     35org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
     36org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
     37org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=disabled
     38org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=disabled
     39org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public
    3440org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
    3541org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
     
    3844org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
    3945org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
     46org.eclipse.jdt.core.compiler.problem.missingJavadocComments=warning
     47org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
     48org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
     49org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
     50org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning
     51org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
     52org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
     53org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
    4054org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
    4155org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
  • applications/editors/josm/plugins/gpsblam/src/org/openstreetmap/josm/plugins/gpsblam/GPSBlamInputData.java

    r30737 r30761  
    1 /** GPSBlam JOSM Plugin
    2  * Copyright (C) 2012 Russell Edwards
    3    This program is free software: you can redistribute it and/or modify
    4    it under the terms of the GNU General Public License as published by
    5    the Free Software Foundation, either version 3 of the License, or
    6    (at your option) any later version.
    7 
    8    This program is distributed in the hope that it will be useful,
    9    but WITHOUT ANY WARRANTY; without even the implied warranty of
    10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11    GNU General Public License for more details.
    12 
    13    You should have received a copy of the GNU General Public License
    14    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  */
     1// License: GPL. Copyright (C) 2012 Russell Edwards
    162package org.openstreetmap.josm.plugins.gpsblam;
    173
     
    3117import org.openstreetmap.josm.gui.layer.Layer;
    3218
    33 public class GPSBlamInputData extends LinkedList<CachedLatLon> {
    34         private Collection<Calendar> datesSeen = new HashSet<>();
     19class GPSBlamInputData extends LinkedList<CachedLatLon> {
     20    private final Collection<Calendar> datesSeen = new HashSet<>();
    3521
    36         public int getNDays() { return datesSeen.size(); }
     22    public int getNDays() {
     23        return datesSeen.size();
     24    }
    3725
    38         // select a set of GPX points and count how many tracks they have come from,
    39         // within given radius of line between given points
    40         public GPSBlamInputData(Point p1, Point p2, int radius)
    41         {
    42                 // Build a list of waypoints in all visible layers -
    43                 //      Collection<WayPoint> wayPoints = new LinkedList<WayPoint>();
     26    // select a set of GPX points and count how many tracks they have come from,
     27    // within given radius of line between given points
     28    GPSBlamInputData(Point p1, Point p2, int radius) {
     29        Collection<Layer> layers = Main.map.mapView.getAllLayers();
     30        for (Layer l : layers) {
     31            if (l.isVisible() && l instanceof GpxLayer) {
     32                for (GpxTrack track : ((GpxLayer)l).data.tracks) {
     33                    for (GpxTrackSegment segment: track.getSegments()) {
     34                        for (WayPoint wayPoint : segment.getWayPoints()) {
    4435
    45                 Collection<Layer> layers = Main.map.mapView.getAllLayers();
    46                 for (Layer l : layers)
    47                 {     
    48                         if (l.isVisible() && l instanceof GpxLayer)
    49                         {
    50                                 for (GpxTrack track : ((GpxLayer)l).data.tracks)
    51                                 {
    52                                         //                                      System.out.println("TRACK");
    53                                         for (GpxTrackSegment segment: track.getSegments())
    54                                         {
    55                                                 //                                              wayPoints.addAll(segment.getWayPoints());/*
    56                                                 for (WayPoint wayPoint : segment.getWayPoints())
    57                                                 {
    58                                                         //                                      points.add(Main.map.mapView.getPoint(wayPoint.getCoor().getEastNorth()));
    59                                                         //                                                      wayPoints.add(Main.map.mapView.getPoint(wayPoint.getCoor().getEastNorth()));
     36                            if (p2.equals(p1)) {
     37                                // circular selection
     38                                CachedLatLon cll = new CachedLatLon(wayPoint.getCoor());
     39                                Point p = Main.map.mapView.getPoint(cll.getEastNorth());
     40                                if (p.distance(p1) < radius) {
     41                                    this.add(cll, wayPoint);
     42                                }
     43                            } else {
     44                                // selection based on distance from line from p1 to p2
     45                                // hack to work for zero length
     46                                double length = Math.sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y))+1e-5;
     47                                // unit direction vector from p1.x,p1.y to p2.x, p2.y
     48                                double dirX = (p2.x-p1.x)/length, dirY = (p2.y-p1.y)/length;
     49                                // unit vector 90deg CW from direction vector
     50                                double perpdirX = dirY, perpdirY = -dirX;
    6051
    61                                                         if (p2.equals(p1)) // circular selection
    62                                                         {
    63                                                                 CachedLatLon cll = new CachedLatLon(wayPoint.getCoor());
    64                                                                 Point p = Main.map.mapView.getPoint(cll.getEastNorth());
    65                                                                 if (p.distance(p1) < radius)
    66                                                                 {
    67                                                                         this.add(cll, wayPoint);
    68                                                                 }
    69                                                         }
    70                                                         else  // selection based on distance from line from p1 to p2
    71                                                         {
    72                                                                 double length = Math.sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y))+1e-5; // hack to work for zero length           
    73                                                                 double dir_x = (p2.x-p1.x)/length, dir_y = (p2.y-p1.y)/length; // unit direction vector from p1.x,p1.y to p2.x, p2.y
    74                                                                 double perpdir_x = dir_y, perpdir_y = -dir_x; // unit vector 90deg CW from direction vector
     52                                CachedLatLon cll = new CachedLatLon(wayPoint.getCoor());
     53                                Point p = Main.map.mapView.getPoint(cll.getEastNorth());
     54                                double pX = p.x-p1.x, pY=p.y-p1.y; // vector from point clicked to waypoint
     55                                double pPar = pX*dirX + pY*dirY; // parallel component
     56                                double pPerp = pX*perpdirX + pY*perpdirY; // perpendicular component
     57                                double pardist = 0.0;
    7558
    76                                                                 CachedLatLon cll = new CachedLatLon(wayPoint.getCoor());
    77                                                                 Point p = Main.map.mapView.getPoint(cll.getEastNorth());
    78                                                                 double p_x = p.x-p1.x, p_y=p.y-p1.y; // vector from point clicked to waypoint
    79                                                                 double p_par = p_x*dir_x + p_y*dir_y; // parallel component
    80                                                                 double p_perp = p_x*perpdir_x + p_y*perpdir_y; // perpendicular component
    81                                                                 double pardist = 0.0;
     59                                if (pPar < 0)
     60                                    pardist = -pPar;
     61                                else if (pPar > length)
     62                                    pardist = pPar-length;
    8263
    83                                                                 if (p_par < 0)
    84                                                                         pardist = -p_par;
    85                                                                 else if (p_par > length)
    86                                                                         pardist = p_par-length;
     64                                double distsq = pardist*pardist + pPerp*pPerp;
    8765
    88                                                                 double distsq = pardist*pardist + p_perp*p_perp;
     66                                if (distsq < radius*radius) {
     67                                    this.add(cll, wayPoint);
     68                                }
     69                            } // end if circular else line based selection
     70                        } // end loop over wayponts in segment
     71                    } // end loop over segments in track
     72                } // end loop over tracks in layer
     73            } // end if layer visible
     74        } // end loop over layers
     75    } // end constructor
    8976
    90                                                                 //              System.out.printf("dist %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f\n", Math.sqrt(distsq), p_x, p_y, p1.x, p1.y, p_par, p_perp, dir_x, dir_y);
    91                                                                 if (distsq < radius*radius)
    92                                                                 {
    93                                                                         this.add(cll, wayPoint);
    94                                                                 }
    95                                                         } // end if circular else line based selection
    96                                                 }// end loop over wayponts in segment
    97                                         } // end loop over segments in track
    98                                        
    99                                 }       // end loop over tracks in layer
    100                         } // end if layer visible
    101                 } // end loop over layers
    102         } // end constructor
    103 
    104         private void add(CachedLatLon cll, WayPoint wayPoint) {
    105                 this.add(cll);
    106                 Calendar day = new GregorianCalendar();
    107                 day.setTimeInMillis((long)wayPoint.time*1000);
    108                 day.set(Calendar.HOUR_OF_DAY, 0);
    109                 day.set(Calendar.MINUTE, 0);
    110                 day.set(Calendar.SECOND, 0);
    111                 datesSeen.add(day);             
    112         }
     77    private void add(CachedLatLon cll, WayPoint wayPoint) {
     78        this.add(cll);
     79        Calendar day = new GregorianCalendar();
     80        day.setTimeInMillis((long)wayPoint.time*1000);
     81        day.set(Calendar.HOUR_OF_DAY, 0);
     82        day.set(Calendar.MINUTE, 0);
     83        day.set(Calendar.SECOND, 0);
     84        datesSeen.add(day);
     85    }
    11386}
  • applications/editors/josm/plugins/gpsblam/src/org/openstreetmap/josm/plugins/gpsblam/GPSBlamLayer.java

    r30737 r30761  
     1// License: GPL. Copyright (C) 2012 Russell Edwards
    12package org.openstreetmap.josm.plugins.gpsblam;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    25
    36import java.awt.Graphics2D;
     
    69import java.util.LinkedList;
    710
    8 import javax.swing.ImageIcon;
    9 
    1011import javax.swing.Action;
    1112import javax.swing.Icon;
     13import javax.swing.ImageIcon;
    1214
    1315import org.openstreetmap.josm.data.Bounds;
     
    1719import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    1820import org.openstreetmap.josm.gui.layer.Layer;
    19 import static org.openstreetmap.josm.tools.I18n.tr;
    2021
    21 public class GPSBlamLayer extends Layer {
    22        
    23         private Collection<GPSBlamMarker> blamMarkers;
    24        
    25     public GPSBlamLayer(String name) {
    26                 super(name);
    27                 blamMarkers = new LinkedList<>();
    28         }
     22class GPSBlamLayer extends Layer {
    2923
    30         private static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(GPSBlamPlugin.class.getResource("/images/gpsblam_layer.png")));
     24    private final Collection<GPSBlamMarker> blamMarkers;
    3125
    32         @Override
    33         public Icon getIcon() {
    34         return icon;
    35         }
     26    GPSBlamLayer(String name) {
     27        super(name);
     28        blamMarkers = new LinkedList<>();
     29    }
    3630
    37         @Override
    38         public Object getInfoComponent() {
    39                 return getToolTipText();
    40         }
     31    private static final Icon ICON = new ImageIcon(Toolkit.getDefaultToolkit().createImage(
     32            GPSBlamPlugin.class.getResource("/images/gpsblam_layer.png")));
    4133
    42         @Override
    43         public Action[] getMenuEntries() {
     34    @Override
     35    public Icon getIcon() {
     36        return ICON;
     37    }
     38
     39    @Override
     40    public Object getInfoComponent() {
     41        return getToolTipText();
     42    }
     43
     44    @Override
     45    public Action[] getMenuEntries() {
    4446        return new Action[] {
    4547                LayerListDialog.getInstance().createShowHideLayerAction(),
    4648                LayerListDialog.getInstance().createDeleteLayerAction(),
    4749                new LayerListPopup.InfoAction(this)};
    48         }
     50    }
    4951
    50         @Override
    51         public String getToolTipText() {
    52                 return tr("GPS Blams");
    53         }
     52    @Override
     53    public String getToolTipText() {
     54        return tr("GPS Blams");
     55    }
    5456
    55         @Override
    56         public boolean isMergable(Layer arg0) {
    57                 return false;
    58         }
     57    @Override
     58    public boolean isMergable(Layer arg0) {
     59        return false;
     60    }
    5961
    60         @Override
    61         public void mergeFrom(Layer arg0) {
     62    @Override
     63    public void mergeFrom(Layer arg0) {
     64        // Do nothing
     65    }
    6266
    63         }
     67    @Override
     68    public void paint(Graphics2D g, MapView mv, Bounds bounds) {
     69        for (GPSBlamMarker blamMarker : blamMarkers){
     70            blamMarker.paint(g, mv);
     71        }
     72    }
    6473
    65         @Override
    66         public void paint(Graphics2D g, MapView mv, Bounds bounds) {
    67                 for (GPSBlamMarker blamMarker : blamMarkers){
    68                         blamMarker.paint(g, mv);
    69                 }
    70         }
     74    @Override
     75    public void visitBoundingBox(BoundingXYVisitor arg0) {
     76        // Do nothing
     77    }
    7178
    72         @Override
    73         public void visitBoundingBox(BoundingXYVisitor arg0) {
    74         }
    75 
    76         public void addBlamMarker(GPSBlamMarker blamMarker) {
    77                 blamMarkers.add(blamMarker);   
    78         }
    79        
     79    void addBlamMarker(GPSBlamMarker blamMarker) {
     80        blamMarkers.add(blamMarker);
     81    }
    8082}
  • applications/editors/josm/plugins/gpsblam/src/org/openstreetmap/josm/plugins/gpsblam/GPSBlamMarker.java

    r30701 r30761  
    1 /** GPSBlam JOSM Plugin
    2  * Copyright (C) 2012 Russell Edwards
    3    This program is free software: you can redistribute it and/or modify
    4    it under the terms of the GNU General Public License as published by
    5    the Free Software Foundation, either version 3 of the License, or
    6    (at your option) any later version.
    7 
    8    This program is distributed in the hope that it will be useful,
    9    but WITHOUT ANY WARRANTY; without even the implied warranty of
    10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11    GNU General Public License for more details.
    12 
    13    You should have received a copy of the GNU General Public License
    14    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  */
     1// License: GPL. Copyright (C) 2012 Russell Edwards
    162package org.openstreetmap.josm.plugins.gpsblam;
    173
     
    3117import org.openstreetmap.josm.gui.MapView;
    3218
    33 public class GPSBlamMarker {
    34         private CachedLatLon mean;
    35         private CachedLatLon hair1Coord1, hair1Coord2, hair2Coord1, hair2Coord2;
    36         private CachedLatLon ellipseCoord1, ellipseCoord2, ellipseCoord3; // 1=TL 2=TR 3=BL, where main axis = +R, minor +U
    37         static final double fac = 2.45; // 2.45 gives 95% CI for 2D
    38        
    39         // construct a blammarker by analysis of selected GPS points
    40         public GPSBlamMarker(GPSBlamInputData inputData)
    41             {
    42                 // get mean east, north
    43                 double mean_east=0.0, mean_north=0.0;
    44                 for (CachedLatLon cll : inputData)
    45                 {
    46                         EastNorth en = cll.getEastNorth();
    47                         mean_east += en.east();
    48                         mean_north += en.north();
    49                 }
    50                 double n = (double)inputData.size();
    51                 mean_east /= n;
    52                 mean_north /= n;
    53                
    54                 // get covariance matrix
    55                 double ca=0.0, cb=0.0, cc=0.0, cd=0.0;
    56                 double deast, dnorth;
    57                 for (CachedLatLon cll : inputData)
    58                 {
    59                         EastNorth en = cll.getEastNorth();
    60                         deast = en.east()-mean_east;
    61                         dnorth = en.north()-mean_north;
    62                         ca += deast*deast;
    63                         cb += deast*dnorth;
    64                         cd += dnorth*dnorth;
    65                 }
    66                 cc = cb;
    67                 ca /= n;
    68                 cb /= n;
    69                 cc /= n;
    70                 cd /= n;
    71                
    72                 // direction and spread analysis
    73                 double T = ca+cd, D = ca*cd-cb*cc; // trace, determinant
    74                 double variance1 = 0.5*T + Math.sqrt(0.25*T*T-D); // Eigenvalue 1
    75                 double variance2 = 0.5*T - Math.sqrt(0.25*T*T-D); // Eigenvalue 2
    76                 double evec1_east = (variance1-cd), evec1_north = cc; // eigenvec1
    77                 double evec2_east = (variance2-cd), evec2_north = cc; // eigenvec2
    78                
    79                 double evec1_fac = Math.sqrt(variance1)/Math.sqrt(evec1_east*evec1_east+evec1_north*evec1_north);
    80                 double evec2_fac = Math.sqrt(variance2)/Math.sqrt(evec2_east*evec2_east+evec2_north*evec2_north);
    81                 double sigma1_east = evec1_east * evec1_fac, sigma1_north = evec1_north * evec1_fac;
    82                 double sigma2_east = evec2_east * evec2_fac, sigma2_north = evec2_north * evec2_fac;                     
    83              
    84                // save latlon coords of the mean and the ends of the crosshairs
    85                Projection proj = Main.getProjection();
    86                mean = new CachedLatLon(proj.eastNorth2latlon(new EastNorth(mean_east, mean_north)));
    87                hair1Coord1 = new CachedLatLon(proj.eastNorth2latlon(
    88                            new EastNorth(mean_east-sigma1_east*fac, mean_north-sigma1_north*fac)));
    89                hair1Coord2 = new CachedLatLon(proj.eastNorth2latlon(
    90                            new EastNorth(mean_east+sigma1_east*fac, mean_north+sigma1_north*fac)));
    91                hair2Coord1 = new CachedLatLon(proj.eastNorth2latlon(
    92                            new EastNorth(mean_east-sigma2_east*fac, mean_north-sigma2_north*fac)));
    93                hair2Coord2 = new CachedLatLon(proj.eastNorth2latlon(
    94                            new EastNorth(mean_east+sigma2_east*fac, mean_north+sigma2_north*fac)));
    95                double efac = fac/Math.sqrt(inputData.getNDays());
    96                // TopLeft, TopRight, BottomLeft in frame where sigma1=R sigma2=Top
    97                ellipseCoord1 = new CachedLatLon(proj.eastNorth2latlon(
    98                            new EastNorth(mean_east+(-sigma1_east+sigma2_east)*efac, mean_north+(-sigma1_north+sigma2_north)*efac))); //
    99                ellipseCoord2 = new CachedLatLon(proj.eastNorth2latlon(
    100                            new EastNorth(mean_east+(sigma1_east+sigma2_east)*efac, mean_north+(sigma1_north+sigma2_north)*efac))); //
    101                ellipseCoord3 = new CachedLatLon(proj.eastNorth2latlon(
    102                            new EastNorth(mean_east+(-sigma1_east-sigma2_east)*efac, mean_north+(-sigma1_north-sigma2_north)*efac))); //
    103         }
     19class GPSBlamMarker {
     20    private final CachedLatLon mean;
     21    private final CachedLatLon hair1Coord1, hair1Coord2, hair2Coord1, hair2Coord2;
     22    private final CachedLatLon ellipseCoord1, ellipseCoord2, ellipseCoord3; // 1=TL 2=TR 3=BL, where main axis = +R, minor +U
     23    private static final double FAC = 2.45; // 2.45 gives 95% CI for 2D
    10424
    105         public void paint(Graphics2D g, MapView mv)
    106         {
    107                 g.setColor(Color.GREEN);
    108                 g.setPaintMode();
     25    /** construct a blammarker by analysis of selected GPS points */
     26    GPSBlamMarker(GPSBlamInputData inputData) {
     27        // get mean east, north
     28        double meanEast=0.0, meanNorth=0.0;
     29        for (CachedLatLon cll : inputData) {
     30            EastNorth en = cll.getEastNorth();
     31            meanEast += en.east();
     32            meanNorth += en.north();
     33        }
     34        double n = inputData.size();
     35        meanEast /= n;
     36        meanNorth /= n;
     37
     38        // get covariance matrix
     39        double ca=0.0, cb=0.0, cc=0.0, cd=0.0;
     40        double deast, dnorth;
     41        for (CachedLatLon cll : inputData) {
     42            EastNorth en = cll.getEastNorth();
     43            deast = en.east()-meanEast;
     44            dnorth = en.north()-meanNorth;
     45            ca += deast*deast;
     46            cb += deast*dnorth;
     47            cd += dnorth*dnorth;
     48        }
     49        cc = cb;
     50        ca /= n;
     51        cb /= n;
     52        cc /= n;
     53        cd /= n;
     54
     55        // direction and spread analysis
     56        double t = ca+cd, d = ca*cd-cb*cc; // trace, determinant
     57        double variance1 = 0.5*t + Math.sqrt(0.25*t*t-d); // Eigenvalue 1
     58        double variance2 = 0.5*t - Math.sqrt(0.25*t*t-d); // Eigenvalue 2
     59        double evec1East = variance1-cd, evec1North = cc; // eigenvec1
     60        double evec2East = variance2-cd, evec2North = cc; // eigenvec2
     61
     62        double evec1Fac = Math.sqrt(variance1)/Math.sqrt(evec1East*evec1East+evec1North*evec1North);
     63        double evec2Fac = Math.sqrt(variance2)/Math.sqrt(evec2East*evec2East+evec2North*evec2North);
     64        double sigma1East = evec1East * evec1Fac, sigma1North = evec1North * evec1Fac;
     65        double sigma2East = evec2East * evec2Fac, sigma2North = evec2North * evec2Fac;
     66
     67        // save latlon coords of the mean and the ends of the crosshairs
     68        Projection proj = Main.getProjection();
     69        mean = new CachedLatLon(proj.eastNorth2latlon(new EastNorth(meanEast, meanNorth)));
     70        hair1Coord1 = new CachedLatLon(proj.eastNorth2latlon(
     71                   new EastNorth(meanEast-sigma1East*FAC, meanNorth-sigma1North*FAC)));
     72        hair1Coord2 = new CachedLatLon(proj.eastNorth2latlon(
     73                   new EastNorth(meanEast+sigma1East*FAC, meanNorth+sigma1North*FAC)));
     74        hair2Coord1 = new CachedLatLon(proj.eastNorth2latlon(
     75                   new EastNorth(meanEast-sigma2East*FAC, meanNorth-sigma2North*FAC)));
     76        hair2Coord2 = new CachedLatLon(proj.eastNorth2latlon(
     77                   new EastNorth(meanEast+sigma2East*FAC, meanNorth+sigma2North*FAC)));
     78        double efac = FAC/Math.sqrt(inputData.getNDays());
     79        // TopLeft, TopRight, BottomLeft in frame where sigma1=R sigma2=Top
     80        ellipseCoord1 = new CachedLatLon(proj.eastNorth2latlon(
     81                   new EastNorth(meanEast+(-sigma1East+sigma2East)*efac, meanNorth+(-sigma1North+sigma2North)*efac))); //
     82        ellipseCoord2 = new CachedLatLon(proj.eastNorth2latlon(
     83                   new EastNorth(meanEast+(sigma1East+sigma2East)*efac, meanNorth+(sigma1North+sigma2North)*efac))); //
     84        ellipseCoord3 = new CachedLatLon(proj.eastNorth2latlon(
     85                   new EastNorth(meanEast+(-sigma1East-sigma2East)*efac, meanNorth+(-sigma1North-sigma2North)*efac))); //
     86    }
     87
     88    void paint(Graphics2D g, MapView mv) {
     89        g.setColor(Color.GREEN);
     90        g.setPaintMode();
    10991        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    11092        g.setStroke(new BasicStroke(2.0f));
    111                 Point hair1Point1 = mv.getPoint(hair1Coord1.getEastNorth());
    112                 Point hair1Point2 = mv.getPoint(hair1Coord2.getEastNorth());
    113                 Point hair2Point1 = mv.getPoint(hair2Coord1.getEastNorth());
    114                 Point hair2Point2 = mv.getPoint(hair2Coord2.getEastNorth());           
    115                 g.drawLine(hair1Point1.x, hair1Point1.y, hair1Point2.x, hair1Point2.y);
    116                 g.drawLine(hair2Point1.x, hair2Point1.y, hair2Point2.x, hair2Point2.y);
    117                
    118                 Point2D meanPoint = mv.getPoint2D(mean.getEastNorth());
    119                 Point2D ellipsePoint1 = mv.getPoint2D(ellipseCoord1.getEastNorth());
    120                 Point2D ellipsePoint2 = mv.getPoint2D(ellipseCoord2.getEastNorth());
    121                 Point2D ellipsePoint3 = mv.getPoint2D(ellipseCoord3.getEastNorth());
    122                 double majorAxis = ellipsePoint2.distance(ellipsePoint1);
    123                 double minorAxis = ellipsePoint3.distance(ellipsePoint1);               
    124                 double angle = -Math.atan2(-(ellipsePoint2.getY()-ellipsePoint1.getY()), ellipsePoint2.getX()-ellipsePoint1.getX());
    125             Shape e = new Ellipse2D.Double(meanPoint.getX()-majorAxis*0.5, meanPoint.getY()-minorAxis*0.5,
    126                                                                         majorAxis, minorAxis);
    127             g.rotate(angle, meanPoint.getX(), meanPoint.getY());
    128             g.draw(e);
    129             g.rotate(-angle, meanPoint.getX(), meanPoint.getY());
    130         }
     93        Point hair1Point1 = mv.getPoint(hair1Coord1.getEastNorth());
     94        Point hair1Point2 = mv.getPoint(hair1Coord2.getEastNorth());
     95        Point hair2Point1 = mv.getPoint(hair2Coord1.getEastNorth());
     96        Point hair2Point2 = mv.getPoint(hair2Coord2.getEastNorth());
     97        g.drawLine(hair1Point1.x, hair1Point1.y, hair1Point2.x, hair1Point2.y);
     98        g.drawLine(hair2Point1.x, hair2Point1.y, hair2Point2.x, hair2Point2.y);
     99
     100        Point2D meanPoint = mv.getPoint2D(mean.getEastNorth());
     101        Point2D ellipsePoint1 = mv.getPoint2D(ellipseCoord1.getEastNorth());
     102        Point2D ellipsePoint2 = mv.getPoint2D(ellipseCoord2.getEastNorth());
     103        Point2D ellipsePoint3 = mv.getPoint2D(ellipseCoord3.getEastNorth());
     104        double majorAxis = ellipsePoint2.distance(ellipsePoint1);
     105        double minorAxis = ellipsePoint3.distance(ellipsePoint1);
     106        double angle = -Math.atan2(-(ellipsePoint2.getY()-ellipsePoint1.getY()), ellipsePoint2.getX()-ellipsePoint1.getX());
     107        Shape e = new Ellipse2D.Double(meanPoint.getX()-majorAxis*0.5, meanPoint.getY()-minorAxis*0.5,
     108                                        majorAxis, minorAxis);
     109        g.rotate(angle, meanPoint.getX(), meanPoint.getY());
     110        g.draw(e);
     111        g.rotate(-angle, meanPoint.getX(), meanPoint.getY());
     112    }
    131113}
  • applications/editors/josm/plugins/gpsblam/src/org/openstreetmap/josm/plugins/gpsblam/GPSBlamMode.java

    r30444 r30761  
    1 /** GPSBlam JOSM Plugin
    2  * Copyright (C) 2012 Russell Edwards
    3    This program is free software: you can redistribute it and/or modify
    4    it under the terms of the GNU General Public License as published by
    5    the Free Software Foundation, either version 3 of the License, or
    6    (at your option) any later version.
    7 
    8    This program is distributed in the hope that it will be useful,
    9    but WITHOUT ANY WARRANTY; without even the implied warranty of
    10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11    GNU General Public License for more details.
    12 
    13    You should have received a copy of the GNU General Public License
    14    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  */
     1// License: GPL. Copyright (C) 2012 Russell Edwards
    162package org.openstreetmap.josm.plugins.gpsblam;
    173
     
    4329import org.openstreetmap.josm.gui.layer.Layer;
    4430
    45 public class GPSBlamMode extends MapMode implements LayerChangeListener, MouseWheelListener, AWTEventListener {
     31class GPSBlamMode extends MapMode implements LayerChangeListener, MouseWheelListener, AWTEventListener {
    4632
    4733    Point pointPressed;
     
    4935    private Point oldP2;
    5036    int radius;
    51     MouseWheelListener mapViewWheelListeners[];
     37    MouseWheelListener[] mapViewWheelListeners;
    5238    GPSBlamLayer currentBlamLayer;
    5339
    54     public GPSBlamMode(MapFrame mapFrame, String name, String desc) {
     40    GPSBlamMode(MapFrame mapFrame, String name, String desc) {
    5541        super(name, "gpsblam_mode.png", desc, mapFrame, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    5642        radius = 10;
    5743    }
    5844
    59     @Override public void enterMode() {
     45    @Override
     46    public void enterMode() {
    6047        super.enterMode();
    6148        Main.map.mapView.addMouseListener(this);
     
    6451        try {
    6552            Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
    66         } catch (SecurityException ex) {}
     53        } catch (SecurityException ex) {
     54            Main.error(ex);
     55        }
    6756
    6857        MapView.addLayerChangeListener(this);
    6958    }
    7059
     60    @Override
    7161    public void eventDispatched(AWTEvent e) {
    7262        if (e instanceof KeyEvent) {
     
    7969    }
    8070
    81     @Override public void exitMode() {
     71    @Override
     72    public void exitMode() {
    8273        super.exitMode();
    8374        Main.map.mapView.removeMouseListener(this);
     
    8778    }
    8879
    89     @Override public void mousePressed(MouseEvent e) {
     80    @Override
     81    public void mousePressed(MouseEvent e) {
    9082        if (e.getButton() == MouseEvent.BUTTON1) {
    9183            pointPressed = new Point(e.getPoint());
     
    10092    }
    10193
    102     @Override public void mouseDragged(MouseEvent e) {
    103          if ( (e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) ==  InputEvent.BUTTON1_DOWN_MASK) {
     94    @Override
     95    public void mouseDragged(MouseEvent e) {
     96        if ( (e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) ==  InputEvent.BUTTON1_DOWN_MASK) {
    10497            //if button1 is hold, draw the line
    10598            paintBox(e.getPoint(), radius);
     
    107100    }
    108101
    109     @Override public void mouseReleased(MouseEvent e) {
     102    @Override
     103    public void mouseReleased(MouseEvent e) {
    110104        if (e.getButton() != MouseEvent.BUTTON1) {
    111105            return;
     
    113107        // give mapView back its mouse wheel
    114108        for (MouseWheelListener l : mapViewWheelListeners) {
    115              if (l != this)
    116                  Main.map.mapView.addMouseWheelListener(l);
     109            if (l != this)
     110                Main.map.mapView.addMouseWheelListener(l);
    117111        }
    118112
    119113        xorDrawBox(pointPressed, oldP2, radius); // clear box
    120114
    121         // Collection <CachedLatLon> selectedCLLs = getSelectedGPXCLLs(pointPressed, e.getPoint());
    122115        GPSBlamInputData inputData = new GPSBlamInputData(pointPressed, e.getPoint(), radius);
    123116        if (!inputData.isEmpty()) {
    124117            if(currentBlamLayer == null) {
    125118                currentBlamLayer = new GPSBlamLayer(tr("GPSBlam"));
    126                 Main.main.addLayer(currentBlamLayer);           
    127             }
    128              currentBlamLayer.addBlamMarker(new GPSBlamMarker(inputData));
     119                Main.main.addLayer(currentBlamLayer);
     120            }
     121            currentBlamLayer.addBlamMarker(new GPSBlamMarker(inputData));
    129122            Main.map.mapView.repaint();
    130123        }
     
    133126    }
    134127
    135     public void changeRadiusBy(int delta) {
     128    private void changeRadiusBy(int delta) {
    136129        if (pointPressed != null) {
    137             int new_radius = radius + delta;
    138             if (new_radius < 1)
    139                 new_radius = 1;
    140             paintBox(oldP2, new_radius);
    141             radius = new_radius;
    142         }
    143     }
    144    
    145     @Override public void mouseWheelMoved(MouseWheelEvent e) {
     130            int newRadius = radius + delta;
     131            if (newRadius < 1)
     132                newRadius = 1;
     133            paintBox(oldP2, newRadius);
     134            radius = newRadius;
     135        }
     136    }
     137
     138    @Override
     139    public void mouseWheelMoved(MouseWheelEvent e) {
    146140        if ( (e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) ==  InputEvent.BUTTON1_DOWN_MASK) {
    147141            changeRadiusBy(-e.getWheelRotation());
     
    154148            g.setXORMode(Color.BLACK);
    155149            g.setColor(Color.WHITE);
    156             g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);// AA+XOR broken in some versions of Java
     150            // AA+XOR broken in some versions of Java
     151            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    157152            g.setStroke(new BasicStroke(2.0f));
    158153            if (p2==null)
    159154                p2 = p1;
    160             double length = Math.sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)); 
     155            double length = Math.sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
    161156            if (length > 0) {
    162                 double dir_x = (p2.x-p1.x)/length, dir_y = (p2.y-p1.y)/length; // unit direction vector from p1.x,p1.y to p2.x, p2.y
    163                 double perpdir_x = dir_y, perpdir_y = -dir_x; // unit vector 90deg CW from direction vector
    164                 double angle = Math.atan2(-perpdir_y, perpdir_x); // polar angle of perpdir
    165                 double ofs_x = radius * perpdir_x, ofs_y = radius * perpdir_y; // radius vector, 90deg CW from dir vector
     157                double dirX = (p2.x-p1.x)/length, dirY = (p2.y-p1.y)/length; // unit direction vector from p1.x,p1.y to p2.x, p2.y
     158                double perpdirX = dirY, perpdirY = -dirX; // unit vector 90deg CW from direction vector
     159                double angle = Math.atan2(-perpdirY, perpdirX); // polar angle of perpdir
     160                double ofsX = radius * perpdirX, ofsY = radius * perpdirY; // radius vector, 90deg CW from dir vector
    166161
    167162                Path2D path = new Path2D.Double();
    168                 path.append(new Line2D.Double(p1.x+ofs_x, p1.y+ofs_y,p2.x+ofs_x, p2.y+ofs_y), false);
    169                 path.append(new Arc2D.Double(p2.x-radius, p2.y-radius,radius*2, radius*2, 
     163                path.append(new Line2D.Double(p1.x+ofsX, p1.y+ofsY,p2.x+ofsX, p2.y+ofsY), false);
     164                path.append(new Arc2D.Double(p2.x-radius, p2.y-radius,radius*2, radius*2,
    170165                        Math.toDegrees(angle), -180, Arc2D.OPEN), true);
    171                 path.append(new Line2D.Double(p2.x-ofs_x, p2.y-ofs_y,p1.x-ofs_x, p1.y-ofs_y), true);
    172                 path.append(new Arc2D.Double(p1.x-radius, p1.y-radius,radius*2, radius*2, 
     166                path.append(new Line2D.Double(p2.x-ofsX, p2.y-ofsY,p1.x-ofsX, p1.y-ofsY), true);
     167                path.append(new Arc2D.Double(p1.x-radius, p1.y-radius,radius*2, radius*2,
    173168                        Math.toDegrees(angle)-180, -180, Arc2D.OPEN), true);
    174169                path.closePath();
     
    178173                    g.setXORMode(Color.BLACK);
    179174                    g.setColor(Color.WHITE);
    180                     g.drawOval((int)Math.round(p2.x-radius), (int)Math.round(p2.y-radius),
    181                     (int)Math.round(radius*2), (int)Math.round(radius*2));
     175                    g.drawOval(Math.round(p2.x-radius), Math.round(p2.y-radius),
     176                    Math.round(radius*2), Math.round(radius*2));
    182177                } catch (InternalError e) {
    183178                    // Robustness against Java bug https://bugs.openjdk.java.net/browse/JDK-8041647
     
    190185    }
    191186
    192     private void paintBox(Point p2, int new_radius) {
     187    private void paintBox(Point p2, int newRadius) {
    193188        if (frame != null) {
    194189            if (oldP2 != null) {
    195190                xorDrawBox(pointPressed, oldP2, radius); // clear old box
    196191            }
    197             xorDrawBox(pointPressed, p2, new_radius); // draw new box
     192            xorDrawBox(pointPressed, p2, newRadius); // draw new box
    198193            oldP2 = p2;
    199194        }
    200     }   
     195    }
    201196
    202197    public void setFrame(MapFrame mapFrame) {
     
    206201    @Override
    207202    public void activeLayerChange(Layer arg0, Layer arg1) {
     203        // Do nothing
    208204    }
    209205
    210206    @Override
    211207    public void layerAdded(Layer arg0) {
     208        // Do nothing
    212209    }
    213210
  • applications/editors/josm/plugins/gpsblam/src/org/openstreetmap/josm/plugins/gpsblam/GPSBlamPlugin.java

    r28741 r30761  
    1 /** GPSBlam JOSM Plugin
    2  * Copyright (C) 2012 Russell Edwards
    3    This program is free software: you can redistribute it and/or modify
    4    it under the terms of the GNU General Public License as published by
    5    the Free Software Foundation, either version 3 of the License, or
    6    (at your option) any later version.
    7 
    8    This program is distributed in the hope that it will be useful,
    9    but WITHOUT ANY WARRANTY; without even the implied warranty of
    10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11    GNU General Public License for more details.
    12 
    13    You should have received a copy of the GNU General Public License
    14    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  */
    16 
     1// License: GPL. Copyright (C) 2012 Russell Edwards
    172package org.openstreetmap.josm.plugins.gpsblam;
    183
    194import static org.openstreetmap.josm.tools.I18n.tr;
    20 
    21 import java.net.URL;
    22 
    23 import javax.swing.ImageIcon;
    245
    256import org.openstreetmap.josm.Main;
     
    2910import org.openstreetmap.josm.plugins.PluginInformation;
    3011
     12/**
     13 * GPSBlam is a JOSM plugin designed to exploit the availability of multiple GPS tracks over the same straight-line path,
     14 * to obtain a handle on the location and direction of the path with optimal accuracy.
     15 * This can be useful to nail down any offsets in existing content or imagery.
     16 */
    3117public class GPSBlamPlugin extends Plugin {
    3218
    33     private IconToggleButton btn;
    34     private GPSBlamMode mode;
     19    private final IconToggleButton btn;
     20    private final GPSBlamMode mode;
    3521
     22    /**
     23     * Constructs a new {@code GPSBlamPlugin}.
     24     * @param info plugin info
     25     */
    3626    public GPSBlamPlugin(PluginInformation info) {
    3727        super(info);
     
    4131        btn.setVisible(true);
    4232    }
    43  
     33
    4434    @Override
    4535    public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
    4636        mode.setFrame(newFrame);
    47         if (oldFrame == null && newFrame != null) {
    48             if (Main.map != null)
    49                 Main.map.addMapMode(btn);
     37        if (oldFrame == null && newFrame != null && Main.map != null) {
     38            Main.map.addMapMode(btn);
    5039        }
    5140    }
    52     public static ImageIcon loadIcon(String name) {
    53         URL url = GPSBlamPlugin.class.getResource("/images/gpsblam.png");
    54         return new ImageIcon(url);
    55     }
    56 
    57 
    5841}
Note: See TracChangeset for help on using the changeset viewer.