Changeset 30761 in osm for applications
- Timestamp:
- 2014-10-21T13:32:12+02:00 (10 years ago)
- 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 9 9 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 10 10 org.eclipse.jdt.core.compiler.compliance=1.7 11 org.eclipse.jdt.core.compiler.doc.comment.support=enabled 11 12 org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning 12 13 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error … … 32 33 org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning 33 34 org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore 35 org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning 36 org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled 37 org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=disabled 38 org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=disabled 39 org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public 34 40 org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore 35 41 org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning … … 38 44 org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled 39 45 org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore 46 org.eclipse.jdt.core.compiler.problem.missingJavadocComments=warning 47 org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled 48 org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public 49 org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag 50 org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning 51 org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled 52 org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled 53 org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public 40 54 org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore 41 55 org.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 16 2 package org.openstreetmap.josm.plugins.gpsblam; 17 3 … … 31 17 import org.openstreetmap.josm.gui.layer.Layer; 32 18 33 publicclass GPSBlamInputData extends LinkedList<CachedLatLon> {34 privateCollection<Calendar> datesSeen = new HashSet<>();19 class GPSBlamInputData extends LinkedList<CachedLatLon> { 20 private final Collection<Calendar> datesSeen = new HashSet<>(); 35 21 36 public int getNDays() { return datesSeen.size(); } 22 public int getNDays() { 23 return datesSeen.size(); 24 } 37 25 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()) { 44 35 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; 60 51 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; 75 58 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; 82 63 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; 87 65 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 89 76 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 } 113 86 } -
applications/editors/josm/plugins/gpsblam/src/org/openstreetmap/josm/plugins/gpsblam/GPSBlamLayer.java
r30737 r30761 1 // License: GPL. Copyright (C) 2012 Russell Edwards 1 2 package org.openstreetmap.josm.plugins.gpsblam; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 2 5 3 6 import java.awt.Graphics2D; … … 6 9 import java.util.LinkedList; 7 10 8 import javax.swing.ImageIcon;9 10 11 import javax.swing.Action; 11 12 import javax.swing.Icon; 13 import javax.swing.ImageIcon; 12 14 13 15 import org.openstreetmap.josm.data.Bounds; … … 17 19 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 18 20 import org.openstreetmap.josm.gui.layer.Layer; 19 import static org.openstreetmap.josm.tools.I18n.tr;20 21 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 } 22 class GPSBlamLayer extends Layer { 29 23 30 private static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(GPSBlamPlugin.class.getResource("/images/gpsblam_layer.png")));24 private final Collection<GPSBlamMarker> blamMarkers; 31 25 32 @Override 33 public Icon getIcon() { 34 return icon;35 26 GPSBlamLayer(String name) { 27 super(name); 28 blamMarkers = new LinkedList<>(); 29 } 36 30 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"))); 41 33 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() { 44 46 return new Action[] { 45 47 LayerListDialog.getInstance().createShowHideLayerAction(), 46 48 LayerListDialog.getInstance().createDeleteLayerAction(), 47 49 new LayerListPopup.InfoAction(this)}; 48 50 } 49 51 50 51 52 53 52 @Override 53 public String getToolTipText() { 54 return tr("GPS Blams"); 55 } 54 56 55 56 57 58 57 @Override 58 public boolean isMergable(Layer arg0) { 59 return false; 60 } 59 61 60 @Override 61 public void mergeFrom(Layer arg0) { 62 @Override 63 public void mergeFrom(Layer arg0) { 64 // Do nothing 65 } 62 66 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 } 64 73 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 } 71 78 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 } 80 82 } -
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 16 2 package org.openstreetmap.josm.plugins.gpsblam; 17 3 … … 31 17 import org.openstreetmap.josm.gui.MapView; 32 18 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 } 19 class 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 104 24 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(); 109 91 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 110 92 g.setStroke(new BasicStroke(2.0f)); 111 112 113 114 Point hair2Point2 = mv.getPoint(hair2Coord2.getEastNorth()); 115 116 117 118 119 120 121 122 123 double minorAxis = ellipsePoint3.distance(ellipsePoint1); 124 125 126 127 128 129 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 } 131 113 } -
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 16 2 package org.openstreetmap.josm.plugins.gpsblam; 17 3 … … 43 29 import org.openstreetmap.josm.gui.layer.Layer; 44 30 45 publicclass GPSBlamMode extends MapMode implements LayerChangeListener, MouseWheelListener, AWTEventListener {31 class GPSBlamMode extends MapMode implements LayerChangeListener, MouseWheelListener, AWTEventListener { 46 32 47 33 Point pointPressed; … … 49 35 private Point oldP2; 50 36 int radius; 51 MouseWheelListener mapViewWheelListeners[];37 MouseWheelListener[] mapViewWheelListeners; 52 38 GPSBlamLayer currentBlamLayer; 53 39 54 publicGPSBlamMode(MapFrame mapFrame, String name, String desc) {40 GPSBlamMode(MapFrame mapFrame, String name, String desc) { 55 41 super(name, "gpsblam_mode.png", desc, mapFrame, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); 56 42 radius = 10; 57 43 } 58 44 59 @Override public void enterMode() { 45 @Override 46 public void enterMode() { 60 47 super.enterMode(); 61 48 Main.map.mapView.addMouseListener(this); … … 64 51 try { 65 52 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); 66 } catch (SecurityException ex) {} 53 } catch (SecurityException ex) { 54 Main.error(ex); 55 } 67 56 68 57 MapView.addLayerChangeListener(this); 69 58 } 70 59 60 @Override 71 61 public void eventDispatched(AWTEvent e) { 72 62 if (e instanceof KeyEvent) { … … 79 69 } 80 70 81 @Override public void exitMode() { 71 @Override 72 public void exitMode() { 82 73 super.exitMode(); 83 74 Main.map.mapView.removeMouseListener(this); … … 87 78 } 88 79 89 @Override public void mousePressed(MouseEvent e) { 80 @Override 81 public void mousePressed(MouseEvent e) { 90 82 if (e.getButton() == MouseEvent.BUTTON1) { 91 83 pointPressed = new Point(e.getPoint()); … … 100 92 } 101 93 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) { 104 97 //if button1 is hold, draw the line 105 98 paintBox(e.getPoint(), radius); … … 107 100 } 108 101 109 @Override public void mouseReleased(MouseEvent e) { 102 @Override 103 public void mouseReleased(MouseEvent e) { 110 104 if (e.getButton() != MouseEvent.BUTTON1) { 111 105 return; … … 113 107 // give mapView back its mouse wheel 114 108 for (MouseWheelListener l : mapViewWheelListeners) { 115 116 109 if (l != this) 110 Main.map.mapView.addMouseWheelListener(l); 117 111 } 118 112 119 113 xorDrawBox(pointPressed, oldP2, radius); // clear box 120 114 121 // Collection <CachedLatLon> selectedCLLs = getSelectedGPXCLLs(pointPressed, e.getPoint());122 115 GPSBlamInputData inputData = new GPSBlamInputData(pointPressed, e.getPoint(), radius); 123 116 if (!inputData.isEmpty()) { 124 117 if(currentBlamLayer == null) { 125 118 currentBlamLayer = new GPSBlamLayer(tr("GPSBlam")); 126 Main.main.addLayer(currentBlamLayer); 127 } 128 119 Main.main.addLayer(currentBlamLayer); 120 } 121 currentBlamLayer.addBlamMarker(new GPSBlamMarker(inputData)); 129 122 Main.map.mapView.repaint(); 130 123 } … … 133 126 } 134 127 135 p ublicvoid changeRadiusBy(int delta) {128 private void changeRadiusBy(int delta) { 136 129 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) { 146 140 if ( (e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) == InputEvent.BUTTON1_DOWN_MASK) { 147 141 changeRadiusBy(-e.getWheelRotation()); … … 154 148 g.setXORMode(Color.BLACK); 155 149 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); 157 152 g.setStroke(new BasicStroke(2.0f)); 158 153 if (p2==null) 159 154 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)); 161 156 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.y163 double perpdir _x = dir_y, perpdir_y = -dir_x; // unit vector 90deg CW from direction vector164 double angle = Math.atan2(-perpdir _y, perpdir_x); // polar angle of perpdir165 double ofs _x = radius * perpdir_x, ofs_y = radius * perpdir_y; // radius vector, 90deg CW from dir vector157 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 166 161 167 162 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, 170 165 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, 173 168 Math.toDegrees(angle)-180, -180, Arc2D.OPEN), true); 174 169 path.closePath(); … … 178 173 g.setXORMode(Color.BLACK); 179 174 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)); 182 177 } catch (InternalError e) { 183 178 // Robustness against Java bug https://bugs.openjdk.java.net/browse/JDK-8041647 … … 190 185 } 191 186 192 private void paintBox(Point p2, int new _radius) {187 private void paintBox(Point p2, int newRadius) { 193 188 if (frame != null) { 194 189 if (oldP2 != null) { 195 190 xorDrawBox(pointPressed, oldP2, radius); // clear old box 196 191 } 197 xorDrawBox(pointPressed, p2, new _radius); // draw new box192 xorDrawBox(pointPressed, p2, newRadius); // draw new box 198 193 oldP2 = p2; 199 194 } 200 } 195 } 201 196 202 197 public void setFrame(MapFrame mapFrame) { … … 206 201 @Override 207 202 public void activeLayerChange(Layer arg0, Layer arg1) { 203 // Do nothing 208 204 } 209 205 210 206 @Override 211 207 public void layerAdded(Layer arg0) { 208 // Do nothing 212 209 } 213 210 -
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 17 2 package org.openstreetmap.josm.plugins.gpsblam; 18 3 19 4 import static org.openstreetmap.josm.tools.I18n.tr; 20 21 import java.net.URL;22 23 import javax.swing.ImageIcon;24 5 25 6 import org.openstreetmap.josm.Main; … … 29 10 import org.openstreetmap.josm.plugins.PluginInformation; 30 11 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 */ 31 17 public class GPSBlamPlugin extends Plugin { 32 18 33 private IconToggleButton btn;34 private GPSBlamMode mode;19 private final IconToggleButton btn; 20 private final GPSBlamMode mode; 35 21 22 /** 23 * Constructs a new {@code GPSBlamPlugin}. 24 * @param info plugin info 25 */ 36 26 public GPSBlamPlugin(PluginInformation info) { 37 27 super(info); … … 41 31 btn.setVisible(true); 42 32 } 43 33 44 34 @Override 45 35 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 46 36 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); 50 39 } 51 40 } 52 public static ImageIcon loadIcon(String name) {53 URL url = GPSBlamPlugin.class.getResource("/images/gpsblam.png");54 return new ImageIcon(url);55 }56 57 58 41 }
Note:
See TracChangeset
for help on using the changeset viewer.