Changeset 35005 in osm for applications/editors


Ignore:
Timestamp:
2019-05-22T18:19:28+02:00 (5 years ago)
Author:
rebeccas95
Message:

Plugin enhancement - auto calibration functionality.

Location:
applications/editors/josm/plugins/piclayer
Files:
18 added
17 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/piclayer

    • Property svn:ignore
      •  

        old new  
        33findbugs-josm-PicLayer.xml
        44javadoc
         5.git
  • applications/editors/josm/plugins/piclayer/.classpath

    r35003 r35005  
    11<?xml version="1.0" encoding="UTF-8"?>
    22<classpath>
     3        <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    34        <classpathentry kind="src" path="src"/>
    4         <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
    55        <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
     6        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
    67        <classpathentry kind="output" path="build"/>
    78</classpath>
  • applications/editors/josm/plugins/piclayer/.project

    r35003 r35005  
    11<?xml version="1.0" encoding="UTF-8"?>
    22<projectDescription>
    3         <name>JOSM-piclayer</name>
     3        <name>piclayer</name>
    44        <comment></comment>
    55        <projects>
     6                <project>JOSM</project>
     7                <project>JOSM-indoorhelper</project>
    68        </projects>
    79        <buildSpec>
     
    1113                        </arguments>
    1214                </buildCommand>
    13                 <buildCommand>
    14                         <name>org.sonarlint.eclipse.core.sonarlintBuilder</name>
    15                         <arguments>
    16                         </arguments>
    17                 </buildCommand>
    18                 <buildCommand>
    19                         <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
    20                         <arguments>
    21                         </arguments>
    22                 </buildCommand>
    2315        </buildSpec>
    2416        <natures>
    2517                <nature>org.eclipse.jdt.core.javanature</nature>
    26                 <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
    2718        </natures>
    2819</projectDescription>
  • applications/editors/josm/plugins/piclayer/.settings/org.eclipse.jdt.core.prefs

    r35003 r35005  
    1010org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
    1111org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
     12org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
    1213org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
     14org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
    1315org.eclipse.jdt.core.compiler.compliance=1.8
     16org.eclipse.jdt.core.compiler.debug.lineNumber=generate
     17org.eclipse.jdt.core.compiler.debug.localVariable=generate
     18org.eclipse.jdt.core.compiler.debug.sourceFile=generate
    1419org.eclipse.jdt.core.compiler.doc.comment.support=enabled
    1520org.eclipse.jdt.core.compiler.problem.APILeak=warning
     
    118123org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
    119124org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
     125org.eclipse.jdt.core.compiler.release=disabled
    120126org.eclipse.jdt.core.compiler.source=1.8
  • applications/editors/josm/plugins/piclayer/build.xml

    r35003 r35005  
    11<?xml version="1.0" encoding="utf-8"?>
     2
    23<project name="PicLayer" default="dist" basedir=".">
     4
    35    <property name="commit.message" value="[josm/PicLayer] - #12045 add ability to localize dialog titles"/>
     6
    47    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    5     <property name="plugin.main.version" value="14153"/>
    6        
     8
     9    <property name="plugin.main.version" value="11713"/>
     10
     11
     12
    713    <!-- Configure these properties (replace "..." accordingly).
     14
    815         See https://josm.openstreetmap.de/wiki/DevelopersGuide/DevelopingPlugins
     16
    917    -->
    10     <property name="plugin.author" value="Tomasz Stelmach"/>
     18
     19    <property name="plugin.author" value="Tomasz Stelmach, Rebecca Schmidt"/>
     20
    1121    <property name="plugin.class" value="org.openstreetmap.josm.plugins.piclayer.PicLayerPlugin"/>
     22
    1223    <property name="plugin.description" value="This plugin allows to display any picture as a background in the editor and align it with the map."/>
     24
    1325    <property name="plugin.icon" value="images/layericon.png"/>
     26
    1427    <property name="plugin.link" value="https://josm.openstreetmap.de/wiki/Help/Plugin/PicLayer"/>
     28
    1529    <property name="plugin.canloadatruntime" value="true"/>
    1630
     31
     32
    1733    <!-- ** include targets that all plugins have in common ** -->
     34
    1835    <import file="../build-common.xml"/>
    1936
     37
     38
    2039</project>
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerPlugin.java

    r35003 r35005  
    3636import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.RemovePointAction;
    3737import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.TransformPointAction;
     38import org.openstreetmap.josm.plugins.piclayer.actions.transform.autocalibrate.AutoCalibratePictureAction;
    3839import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract;
    3940
     
    8485            ScaleYPictureAction scaleYPictureAction = new ScaleYPictureAction();
    8586            ShearPictureAction shearPictureAction = new ShearPictureAction();
     87            AutoCalibratePictureAction autoCalibratePictureAction = new AutoCalibratePictureAction();
     88
    8689            // Create plugin buttons and add them to the toolbar
    8790
     
    9699            buttonList.add(picLayerActionButtonFactory(scaleYPictureAction));
    97100            buttonList.add(picLayerActionButtonFactory(shearPictureAction));
     101            buttonList.add(picLayerActionButtonFactory(autoCalibratePictureAction));
    98102
    99103            for (IconToggleButton btn : buttonList) {
     
    120124
    121125        if (oldPic) {
    122             ((PicLayerAbstract) oldLayer).setDrawPoints(false);
     126            ((PicLayerAbstract) oldLayer).setDrawOriginPoints(false);
    123127        }
    124128
    125129        if (newPic) {
    126             ((PicLayerAbstract) newLayer).setDrawPoints(true);
     130            ((PicLayerAbstract) newLayer).setDrawOriginPoints(true);
    127131        }
    128132    }
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/GenericPicTransformAction.java

    r35003 r35005  
    103103        Layer active = MainApplication.getLayerManager().getActiveLayer();
    104104        if (active instanceof PicLayerAbstract) {
    105             ((PicLayerAbstract) active).setDrawPoints(value);
     105            ((PicLayerAbstract) active).setDrawOriginPoints(value);
    106106            active.invalidate();
    107107        }
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/MovePointAction.java

    r35003 r35005  
    88import java.awt.geom.Point2D;
    99
     10import org.openstreetmap.josm.data.coor.LatLon;
     11import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager;
     12import org.openstreetmap.josm.data.coor.conversion.ICoordinateFormat;
     13import org.openstreetmap.josm.gui.MainApplication;
    1014import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction;
    1115import org.openstreetmap.josm.tools.ImageProvider;
    1216import org.openstreetmap.josm.tools.Logging;
     17
    1318
    1419/**
     
    4146
    4247        try {
     48                setLatLonOriginPoints(e.getPoint());    // collect lat/lon data points for auto calibration
     49
    4350            Point2D pressed = currentLayer.transformPoint(e.getPoint());
    4451            if (selectedPoint == null)
     
    6269        updateDrawPoints(false);
    6370    }
     71
     72    /**
     73     * Method to collect raw data points for additional auto calibration and transforms them into LatLon.
     74     * Transformed points will be stored into {@code PictureTransform } attribute to make them accessible for actions.
     75     * @param point to collect
     76     */
     77    private void setLatLonOriginPoints(Point2D point) {
     78        LatLon latLonPoint = MainApplication.getMap().mapView.getLatLon(point.getX(), point.getY());
     79        ICoordinateFormat mCoord = CoordinateFormatManager.getDefaultFormat();
     80        double latY = Double.parseDouble(mCoord.latToString(latLonPoint));
     81        double lonX = Double.parseDouble(mCoord.lonToString(latLonPoint));
     82        currentLayer.getTransformer().addLatLonOriginPoint(new Point2D.Double(lonX, latY));
     83    }
     84
    6485}
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/RemovePointAction.java

    r35003 r35005  
    2525
    2626        if (selectedPoint != null) {
     27                currentLayer.getTransformer().removeLatLonOriginPoint(selectedPoint);
    2728            currentLayer.getTransformer().removeOriginPoint(selectedPoint);
    2829            selectedPoint = null;
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerAbstract.java

    r35003 r35005  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6
     7import java.awt.BasicStroke;
    68import java.awt.Color;
    79import java.awt.Graphics2D;
     
    1921import java.io.Reader;
    2022import java.nio.charset.StandardCharsets;
     23import java.util.ArrayList;
     24import java.util.List;
    2125import java.util.Properties;
    2226
     
    5862    // Tiles of pin images
    5963    private static Image pinTiledImage;
     64    private static Image pinTiledImageOrange;
    6065
    6166    // Initial position of the image in the real world
     
    6873    protected double initialImageScale = 1.0;
    6974
    70     // Layer icon
     75    // Layer icon / lines
    7176    private Icon layerIcon = null;
    7277
    73     private boolean drawMarkers = true;
    74 
    75     public void setDrawPoints(boolean value) {
    76         drawMarkers = value;
     78    private boolean drawOriginMarkers = true;
     79
     80    private boolean drawRefMarkers = false;
     81
     82    private boolean drawFirstLine = false;
     83
     84    private boolean drawSecLine = false;
     85
     86    public void setDrawOriginPoints(boolean value) {
     87        drawOriginMarkers = value;
     88    }
     89
     90    private List<Point2D> refPointsBuffer = new ArrayList<>(3); // only for buffering
     91
     92    public void setDrawReferencePoints(boolean value, Point2D pointToDraw) {
     93        drawRefMarkers = value;
     94        if(this.refPointsBuffer == null)        refPointsBuffer = new ArrayList<>(3);
     95        if(pointToDraw != null)                         this.refPointsBuffer.add(pointToDraw);
     96    }
     97
     98    public void clearDrawReferencePoints() {
     99        drawRefMarkers = false;
     100        this.refPointsBuffer = null;
     101    }
     102
     103    public void setDrawFirstLine(boolean value) {
     104        drawFirstLine = value;
     105    }
     106
     107    public void setDrawSecLine(boolean value) {
     108        drawSecLine = value;
    77109    }
    78110
     
    126158            // allow system to load the image and use it in future
    127159            pinTiledImage = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/v6_64.png"))).getImage();
     160            pinTiledImageOrange = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/v6_64o.png"))).getImage();
    128161        }
    129162
     
    139172        // First, we initialize the calibration, so that createImage() can rely on it
    140173
    141         transformer = new PictureTransform();
     174          if(transformer == null)               transformer = new PictureTransform();
    142175
    143176        // If the map does not exist - we're screwed. We should not get into this situation in the first place!
     
    181214     */
    182215    public abstract String getPicLayerName();
     216
     217    public Image getImage() {
     218        return this.image;
     219    }
    183220
    184221    @Override
     
    270307                );
    271308            }
    272             if (drawMarkers) {
     309            if (drawOriginMarkers) {
    273310                // draw markers for selection
    274311                Graphics2D gPoints = (Graphics2D) g2.create();
     
    290327                           pinTileOffsetX[i], pinTileOffsetY[i], pinTileOffsetX[i]+pinWidth, pinTileOffsetY[i]+pinHeight, null);
    291328                }
     329            }
     330            if (drawRefMarkers) {
     331                // draw markers for selection
     332                Graphics2D gPoints = (Graphics2D) g2.create();
     333
     334                gPoints.translate(pic_offset_x, pic_offset_y);
     335
     336                gPoints.setColor(Color.RED); // red color for points output
     337
     338                AffineTransform tr = AffineTransform.getScaleInstance(scalex, scaley);
     339                tr.concatenate(transformer.getTransform());
     340
     341                for (int i = 0; i < refPointsBuffer.size(); i++) {
     342                   Point2D trP = tr.transform(refPointsBuffer.get(i), null);
     343                   int x = (int) trP.getX(), y = (int) trP.getY();
     344
     345                   int dstx = x-pinAnchorX;
     346                   int dsty = y-pinAnchorY;
     347                   gPoints.drawImage(pinTiledImageOrange, dstx, dsty, dstx+pinWidth, dsty+pinHeight,
     348                           pinTileOffsetX[i], pinTileOffsetY[i], pinTileOffsetX[i]+pinWidth, pinTileOffsetY[i]+pinHeight, null);
     349                }
     350            }
     351            if (drawFirstLine) {
     352                // set line from point1 to point2
     353                List<Point2D> points = this.getTransformer().getOriginPoints();
     354                Point2D p1 = points.get(0);
     355                Point2D p2 = points.get(1);
     356                g.setColor(Color.green);
     357                g.setStroke(new BasicStroke(5));
     358                g.drawLine((int)p1.getX(), (int)p1.getY(), (int)p2.getX(), (int)p2.getY());
     359            }
     360            if (drawSecLine) {
     361                // set line from point2 to point3
     362                List<Point2D> points = this.getTransformer().getOriginPoints();
     363                Point2D p2 = points.get(1);
     364                Point2D p3 = points.get(2);
     365                g.setColor(Color.green);
     366                g.setStroke(new BasicStroke(5));
     367                g.drawLine((int)p2.getX(), (int)p2.getY(), (int)p3.getX(), (int)p3.getY());
    292368            }
    293369        } else {
     
    523599    }
    524600
    525     public Point2D transformPoint(Point p) throws NoninvertibleTransformException {
     601    public Point2D transformPoint(Point2D p) throws NoninvertibleTransformException {
    526602        // Position image at the right graphical place
    527603
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/transform/PictureTransform.java

    r35003 r35005  
    88
    99import org.openstreetmap.josm.data.coor.EastNorth;
     10import org.openstreetmap.josm.plugins.piclayer.actions.transform.autocalibrate.helper.ObservableArrayList;
    1011
    1112public class PictureTransform {
     
    2930        cachedTransform = new AffineTransform();
    3031        originPoints = new ArrayList<>(3);
     32        latLonOriginPoints = new ObservableArrayList<>(3);
    3133    }
    3234
     
    186188
    187189    public void setOriginPoints(List<Point2D> list) {
    188         this.originPoints = new ArrayList<>(list);
     190        if(originPoints == null)        originPoints = new ArrayList<>(list);
     191        else {
     192                originPoints.clear();
     193                originPoints.addAll(list);
     194        }
    189195    }
    190196
     
    192198        originPoints.remove(selectedPoint);
    193199    }
     200
     201    public void clearOriginPoints() {
     202        originPoints.clear();
     203    }
     204
     205    // similar to originPointList - points scaled in LatLon, list observable
     206    private ObservableArrayList<Point2D> latLonOriginPoints = new ObservableArrayList<>(3);
     207
     208    public ObservableArrayList<Point2D> getLatLonOriginPoints() {
     209        return this.latLonOriginPoints;
     210    }
     211
     212    public void addLatLonOriginPoint(Point2D p) {
     213        latLonOriginPoints.add(p);
     214    }
     215
     216    public void removeLatLonOriginPoint(Point2D selectedPoint) {
     217        int index = originPoints.indexOf(selectedPoint);
     218        Point2D toDelete = this.latLonOriginPoints.get(index);
     219        this.latLonOriginPoints.remove(toDelete);
     220    }
     221
     222    public void setLatLonOriginPoint(List<Point2D> list) {
     223        if(latLonOriginPoints == null)  latLonOriginPoints = new ObservableArrayList<>(list);
     224        else {
     225                latLonOriginPoints.clear();
     226                latLonOriginPoints.addAll(list);
     227        }
     228    }
     229
     230    public void clearLatLonOriginPoints() {
     231        latLonOriginPoints.clear();
     232    }
    194233}
Note: See TracChangeset for help on using the changeset viewer.