Ignore:
Timestamp:
2010-01-10T20:41:49+01:00 (15 years ago)
Author:
pieren
Message:

More about raster image rotation

Location:
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java

    r19371 r19387  
    3030    // bbox of the georeferenced original image (raster only) (inclined if rotated and before cropping)
    3131    // P[0] is bottom,left then next are clockwise.
    32     private EastNorth[] orgRaster = new EastNorth[4];
     32    public EastNorth[] orgRaster = new EastNorth[4];
    3333    // bbox of the georeferenced original image (raster only) after cropping
    34     private EastNorth[] orgCroppedRaster = new EastNorth[4];
     34    public EastNorth[] orgCroppedRaster = new EastNorth[4];
    3535    // angle with georeferenced original image after rotation (raster images only)(in radian)
    36     private double angle = 0;
     36    public double angle = 0;
    3737
    3838    public BufferedImage image;
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSAdjustAction.java

    r19371 r19387  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.Color;
    67import java.awt.Cursor;
     8import java.awt.Graphics2D;
    79import java.awt.Toolkit;
    810import java.awt.event.ActionEvent;
     
    1618import org.openstreetmap.josm.Main;
    1719import org.openstreetmap.josm.gui.MapFrame;
     20import org.openstreetmap.josm.gui.MapView;
    1821import org.openstreetmap.josm.actions.mapmode.MapMode;
    1922import org.openstreetmap.josm.data.coor.EastNorth;
     
    3033    private EastNorth prevEastNorth;
    3134    enum Mode { moveXY, moveZ, rotate}
    32     private Mode mode = null;
     35    private static Mode mode = null;
     36    private static EastNorth[] croppedRaster = new EastNorth[5];;
    3337
    3438    public WMSAdjustAction(MapFrame mapFrame) {
     
    6064                Main.map.mapView.addMouseMotionListener(this);
    6165                rasterMoved = false;
     66                selectedLayer.adjustModeEnabled = true;
    6267            } else {
    6368                JOptionPane.showMessageDialog(Main.parent,tr("This mode works only if active layer is\n"
     
    8186        }
    8287        modifiedLayers.clear();
     88        selectedLayer.adjustModeEnabled = false;
    8389        selectedLayer = null;
    8490    }
     
    104110    @Override public void mouseDragged(MouseEvent e) {
    105111        EastNorth newEastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY());
    106         if (mode == Mode.moveXY) {
    107             displace(prevEastNorth, newEastNorth);
    108         } else if (mode == Mode.moveZ) {
    109             resize(newEastNorth);
    110         } else if (mode == Mode.rotate) {
    111             rotate(prevEastNorth, newEastNorth);
     112        if (mode == Mode.rotate) {
     113            rotateFrameOnly(prevEastNorth, newEastNorth);
     114        } else {
     115            if (mode == Mode.moveXY) {
     116                displace(prevEastNorth, newEastNorth);
     117            } else if (mode == Mode.moveZ) {
     118                resize(newEastNorth);
     119            }
     120            prevEastNorth = newEastNorth;
    112121        }
    113122        if (!modifiedLayers.contains(selectedLayer))
    114123            modifiedLayers.add(selectedLayer);
    115124        Main.map.mapView.repaint();
    116         prevEastNorth = newEastNorth;
     125    }
     126   
     127    public static void paintAdjustFrames(Graphics2D g, final MapView mv) {
     128        if (mode == Mode.rotate && croppedRaster != null) {
     129            g.setColor(Color.red);
     130            for (int i=0; i<4; i++)
     131                g.drawLine(mv.getPoint(croppedRaster[i]).x,
     132                        mv.getPoint(croppedRaster[i]).y,
     133                        mv.getPoint(croppedRaster[i+1]).x,
     134                        mv.getPoint(croppedRaster[i+1]).y);
     135        }
    117136    }
    118137
     
    136155    }
    137156
     157    private void rotateFrameOnly(EastNorth start, EastNorth end) {
     158        if (start != null && end != null) {
     159            EastNorth pivot = selectedLayer.getRasterCenter();
     160            double startAngle = Math.atan2(start.east()-pivot.east(), start.north()-pivot.north());
     161            double endAngle = Math.atan2(end.east()-pivot.east(), end.north()-pivot.north());
     162            double rotationAngle = endAngle - startAngle;
     163            if (selectedLayer.images.get(0).orgCroppedRaster != null) {
     164                for (int i=0; i<4; i++) {
     165                    croppedRaster[i] = selectedLayer.images.get(0).orgCroppedRaster[i].rotate(pivot, rotationAngle);
     166                }
     167                croppedRaster[4] = croppedRaster[0];
     168            }
     169        }
     170    }
     171
    138172    @Override public void mouseReleased(MouseEvent e) {
    139173        //Main.map.mapView.repaint();
     174        if (mode == Mode.rotate) {
     175            EastNorth newEastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY());
     176            rotate(prevEastNorth, newEastNorth);
     177            Main.map.mapView.repaint();
     178        }
    140179        Main.map.mapView.setCursor(Cursor.getDefaultCursor());
    141180        prevEastNorth = null;
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java

    r19371 r19387  
    8181
    8282    private JMenuItem saveAsPng;
     83   
     84    public boolean adjustModeEnabled;
    8385
    8486    public WMSLayer() {
     
    237239            paintCrosspieces(g, mv);
    238240        }
     241        if (this.adjustModeEnabled) {
     242            WMSAdjustAction.paintAdjustFrames(g, mv);
     243        }           
    239244    }
    240245
Note: See TracChangeset for help on using the changeset viewer.