Changeset 27662 in osm for applications/editors/josm/plugins/piclayer
- Timestamp:
- 2012-01-30T11:42:14+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/piclayer
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/piclayer/build.xml
r27627 r27662 22 22 --> 23 23 <project name="PicLayer" default="dist" basedir="."> 24 <property name="commit.message" value="PicLayer - fix #7319"/>24 <property name="commit.message" value="PicLayer - added possibility to edit transformation with 1 or 2 points (move or rect transformation)"/> 25 25 <property name="plugin.main.version" value="4669"/> 26 26 <!-- -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerPlugin.java
r27296 r27662 52 52 import org.openstreetmap.josm.plugins.piclayer.actions.transform.ShearPictureAction; 53 53 import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.MovePointAction; 54 import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.RemovePointAction; 54 55 import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.TransformPointAction; 55 56 import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract; … … 97 98 MovePointAction movePointAction = new MovePointAction(newFrame); 98 99 TransformPointAction transformPointAction = new TransformPointAction(newFrame); 100 RemovePointAction removePointAction = new RemovePointAction(newFrame); 99 101 100 102 RotatePictureAction rotatePictureAction = new RotatePictureAction(newFrame); … … 109 111 buttonList.add(picLayerActionButtonFactory(movePointAction)); 110 112 buttonList.add(picLayerActionButtonFactory(transformPointAction)); 113 buttonList.add(picLayerActionButtonFactory(removePointAction)); 111 114 buttonList.add(picLayerActionButtonFactory(rotatePictureAction)); 112 115 buttonList.add(picLayerActionButtonFactory(scaleXYPictureAction)); … … 120 123 } 121 124 } 122 125 123 126 private IconToggleButton picLayerActionButtonFactory(MapMode action) { 124 127 IconToggleButton button = new IconToggleButton(action); … … 134 137 boolean oldPic = oldLayer instanceof PicLayerAbstract; 135 138 boolean newPic = newLayer instanceof PicLayerAbstract; 136 // actually that should be not enough - JOSM should hide all buttons that are disabled for current layer! 137 if (oldPic) { // leave picture layer if (oldLayer != null)139 140 if (oldPic) { 138 141 ((PicLayerAbstract)oldLayer).setDrawPoints(false); 139 142 } 143 140 144 if (newPic) { 141 145 ((PicLayerAbstract)newLayer).setDrawPoints(true); -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/affine/TransformPointAction.java
r27403 r27662 6 6 import java.awt.geom.NoninvertibleTransformException; 7 7 import java.awt.geom.Point2D; 8 9 import javax.swing.JOptionPane;10 8 11 9 import org.openstreetmap.josm.gui.MapFrame; … … 25 23 Point2D pressed = currentLayer.transformPoint(e.getPoint()); 26 24 if (selectedPoint != null) { 27 if (currentLayer.getTransformer().getOriginPoints().size() < 3)25 /*if (currentLayer.getTransformer().getOriginPoints().size() < 3) 28 26 JOptionPane.showMessageDialog(null, tr("You should have 3 checkpoints to transform the image!"), tr("PicLayer"), JOptionPane.ERROR_MESSAGE, null); 29 else 27 else*/ 28 { 30 29 currentLayer.getTransformer().updatePair(selectedPoint, pressed); 30 } 31 31 } 32 32 -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/command/TransformCommand.java
r27435 r27662 50 50 layer.getTransformer().setTransform(transform.getTransform()); 51 51 layer.getTransformer().setOriginPoints(transform.getOriginPoints()); 52 layer.getTransformer().setImagePosition(transform.getImagePosition()); 52 53 } 53 54 … … 56 57 transform.setOriginPoints(layer.getTransformer().getOriginPoints()); 57 58 transform.setTransform(layer.getTransformer().getTransform()); 59 transform.setImagePosition(layer.getTransformer().getImagePosition()); 58 60 return transform; 59 61 } … … 78 80 79 81 boolean changed = !(beforeTransform.getTransform().equals(afterTransform.getTransform())) || 80 !(beforeTransform.getOriginPoints().equals(afterTransform.getOriginPoints())); 82 !(beforeTransform.getOriginPoints().equals(afterTransform.getOriginPoints())) || 83 !(beforeTransform.getImagePosition().equals(afterTransform.getImagePosition())); 81 84 if (changed && !alreadyAdded) { 82 85 Main.main.undoRedo.add(this); -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerAbstract.java
r27403 r27662 72 72 73 73 // Initial position of the image in the real world 74 protected EastNorth initialImagePosition;74 // protected EastNorth initialImagePosition; 75 75 76 76 // Position of the image in the real world 77 protected EastNorth imagePosition;77 //protected EastNorth imagePosition; 78 78 79 79 // The scale that was set on the map during image creation … … 96 96 97 97 // Keys for loading from old/new Properties 98 private static final String INITIAL_POS_X = "INITIAL_POS_X";99 private static final String INITIAL_POS_Y = "INITIAL_POS_y";100 98 private static final String POSITION_X = "POSITION_X"; 101 99 private static final String POSITION_Y = "POSITION_Y"; … … 148 146 // First, we initialize the calibration, so that createImage() can rely on it 149 147 148 transformer = new PictureTransform(); 149 150 150 // If the map does not exist - we're screwed. We should not get into this situation in the first place! 151 151 if ( Main.map != null && Main.map.mapView != null ) { … … 153 153 EastNorth center = Main.map.mapView.getCenter(); 154 154 155 imagePosition = new EastNorth(center.east(), center.north()); 156 initialImagePosition = new EastNorth(imagePosition.east(), imagePosition.north()); 155 // imagePosition = new EastNorth(center.east(), center.north()); 156 transformer.setImagePosition(new EastNorth(center.east(), center.north())); 157 // initialImagePosition = new EastNorth(imagePosition.east(), imagePosition.north()); 157 158 // Initial scale at which the image was loaded 158 159 initialImageScale = Main.map.mapView.getDist100Pixel(); … … 168 169 // Load image completely 169 170 (new ImageIcon(image)).getImage(); 170 171 transformer = new PictureTransform();172 171 173 172 lookForCalibration(); … … 233 232 234 233 // This is now the offset in screen pixels 234 EastNorth imagePosition = transformer.getImagePosition(); 235 235 double pic_offset_x = (( imagePosition.east() - leftop.east() ) * pixel_per_en); 236 236 double pic_offset_y = (( leftop.north() - imagePosition.north() ) * pixel_per_en); … … 348 348 return; 349 349 350 EastNorth center = imagePosition;350 EastNorth center = transformer.getImagePosition(); 351 351 double w = image.getWidth(null); 352 352 double h = image.getHeight(null); … … 382 382 props.put(MATRIXm02, Double.toString(matrix[4])); 383 383 props.put(MATRIXm12, Double.toString(matrix[5])); 384 props.put(POSITION_X, Double.toString( imagePosition.getX()));385 props.put(POSITION_Y, Double.toString( imagePosition.getY()));384 props.put(POSITION_X, Double.toString(transformer.getImagePosition().getX())); 385 props.put(POSITION_Y, Double.toString(transformer.getImagePosition().getY())); 386 386 props.put(INITIAL_SCALE, Double.toString(initialImageScale)); 387 387 … … 413 413 double pos_y = Double.valueOf(props.getProperty(POSITION_Y, "0")); 414 414 415 imagePosition = new EastNorth(pos_x, pos_y); 415 EastNorth imagePosition = new EastNorth(pos_x, pos_y); 416 transformer.setImagePosition(imagePosition); 417 416 418 initialImageScale = Double.valueOf(props.getProperty(INITIAL_SCALE, "1")); //in_scale 417 419 if (props.containsKey(SCALEX)) {// old format 418 double in_pos_x = Double.valueOf(props.getProperty(INITIAL_POS_X, "0"));419 double in_pos_y = Double.valueOf(props.getProperty(INITIAL_POS_Y, "0"));420 //double in_pos_x = Double.valueOf(props.getProperty(INITIAL_POS_X, "0")); 421 //double in_pos_y = Double.valueOf(props.getProperty(INITIAL_POS_Y, "0")); 420 422 double angle = Double.valueOf(props.getProperty(ANGLE, "0")); 421 423 double scale_x = Double.valueOf(props.getProperty(SCALEX, "1")); … … 423 425 double shear_x = Double.valueOf(props.getProperty(SHEARX, "0")); 424 426 double shear_y = Double.valueOf(props.getProperty(SHEARY, "0")); 425 426 initialImagePosition.setLocation(in_pos_x, in_pos_y);427 427 428 428 // transform to matrix from these values - need testing … … 462 462 int w = image.getWidth(null); 463 463 int h = image.getHeight(null); 464 imagePosition.setLocation(464 EastNorth imagePosition = new EastNorth( 465 465 dx + w/2*sx + h/2*rx, 466 466 dy + w/2*ry + h/2*sy 467 467 ); 468 initialImagePosition.setLocation(imagePosition);468 // initialImagePosition.setLocation(imagePosition); 469 469 // m_angle = 0; 470 470 double scalex = 100*sx*getMetersPerEasting(imagePosition); … … 473 473 double sheary = ry / sy; 474 474 475 transformer.setImagePosition(imagePosition); 475 476 transformer.resetCalibration(); 476 477 AffineTransform tr = transformer.getTransform(); … … 494 495 double pixel_per_en = ( Main.map.mapView.getWidth() / 2.0 ) / ( center.east() - leftop.east() ); 495 496 497 EastNorth imageCenter = transformer.getImagePosition(); 496 498 // This is now the offset in screen pixels 497 double pic_offset_x = (( image Position.east() - leftop.east() ) * pixel_per_en);498 double pic_offset_y = (( leftop.north() - image Position.north() ) * pixel_per_en); // something bad...499 double pic_offset_x = (( imageCenter.east() - leftop.east() ) * pixel_per_en); 500 double pic_offset_y = (( leftop.north() - imageCenter.north() ) * pixel_per_en); // something bad... 499 501 500 502 AffineTransform pointTrans = AffineTransform.getTranslateInstance(pic_offset_x, pic_offset_y); 501 503 502 double scalex = initialImageScale * pixel_per_en / getMetersPerEasting(image Position) / 100;503 double scaley = initialImageScale * pixel_per_en / getMetersPerNorthing(image Position) / 100;504 double scalex = initialImageScale * pixel_per_en / getMetersPerEasting(imageCenter) / 100; 505 double scaley = initialImageScale * pixel_per_en / getMetersPerNorthing(imageCenter) / 100; 504 506 505 507 pointTrans.scale(scalex, scaley); // ok here … … 515 517 */ 516 518 public void movePictureBy(double x, double y) { 517 imagePosition = imagePosition.add(x, y); 518 transformer.setModified(); 519 transformer.setImagePosition(transformer.getImagePosition().add(x, y)); 519 520 } 520 521 … … 552 553 public void resetCalibration() { 553 554 transformer.resetCalibration(); 554 imagePosition.setLocation(initialImagePosition);555 555 } 556 556 … … 575 575 return selected; 576 576 } 577 578 public void saveTransformCommand() {579 580 }581 577 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerFromKML.java
r27231 r27662 57 57 58 58 59 imagePosition.setLocation((en1.getX()+en2.getX())/2, (en1.getY()+en2.getY())/2); 59 EastNorth imagePosition = new EastNorth((en1.getX()+en2.getX())/2, (en1.getY()+en2.getY())/2); 60 transformer.setImagePosition(imagePosition); 61 60 62 initialImageScale = 100*getMetersPerEasting(imagePosition); 61 initialImagePosition.setLocation(imagePosition);62 63 63 64 AffineTransform transform = AffineTransform.getScaleInstance((en1.getX()-en2.getX())/w, (en1.getY()-en2.getY())/h); -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/transform/PictureTransform.java
r27403 r27662 6 6 import java.util.List; 7 7 8 import org.openstreetmap.josm.data.coor.EastNorth; 9 8 10 public class PictureTransform { 9 11 10 12 private AffineTransform cachedTransform; 11 private boolean modified = false; 13 private EastNorth imagePosition; 14 15 public EastNorth getImagePosition() { 16 return imagePosition; 17 } 18 19 public void setImagePosition(EastNorth imagePosition) { 20 this.imagePosition = imagePosition; 21 } 22 23 private boolean modified = false; 12 24 13 25 private List<Point2D> originPoints; … … 50 62 */ 51 63 public void updatePair(Point2D originPoint, Point2D desiredPoint) { 52 if (originPoints.size() < 3) // not enough information for creating transform - 3 points needed53 return;54 55 64 if (originPoint == null) 56 65 return; 57 66 58 List<Point2D> desiredPoints = new ArrayList<Point2D>(3); 67 switch (originPoints.size()) { 68 case 1: { 69 cachedTransform.concatenate(AffineTransform.getTranslateInstance(desiredPoint.getX()-originPoint.getX(), 70 desiredPoint.getY()-originPoint.getY())); 71 break; 72 } 73 case 2: { 74 // find triangle and move it 75 List<Point2D> desiredPoints = new ArrayList<Point2D>(3); 76 Point2D o1 = originPoints.get(0); 77 Point2D o2 = originPoints.get(1); 78 Point2D d1, d2; 79 if (o2 == originPoint) { 80 d2 = desiredPoint; 81 d1 = (Point2D) o1.clone(); 82 } else { 83 d1 = desiredPoint; 84 d2 = (Point2D) o2.clone(); 85 } 86 Point2D o3 = calculateTrianglePoint(o1, o2); 87 Point2D d3 = calculateTrianglePoint(d1, d2); 88 originPoints.add(o3); 89 desiredPoints.add(d1); desiredPoints.add(d2); desiredPoints.add(d3); 90 trySolve(desiredPoints); 91 originPoints.remove(2); 92 break; 93 } 94 case 3: { 95 List<Point2D> desiredPoints = new ArrayList<Point2D>(3); 59 96 60 for (Point2D origin : originPoints) { 61 if (origin.equals(originPoint)) 62 desiredPoints.add(desiredPoint); 63 else 64 desiredPoints.add(origin); 97 for (Point2D origin : originPoints) { 98 if (origin.equals(originPoint)) 99 desiredPoints.add(desiredPoint); 100 else 101 desiredPoints.add(origin); 102 } 103 trySolve(desiredPoints); 104 break; 65 105 } 66 trySolve(desiredPoints); 106 default: 107 108 } 109 67 110 } 111 112 private Point2D calculateTrianglePoint(Point2D d1, Point2D d2) { 113 Point2D result; 114 if (d1 instanceof Point2D.Double) { 115 result = new Point2D.Double(); 116 } else { 117 result = new Point2D.Float(); 118 } 119 result.setLocation((d1.getX()+d2.getX()-d2.getY()+d1.getY())/2, (d1.getY()+d2.getY()+d2.getX()-d1.getX())/2); 120 return result; 121 } 68 122 69 123 private void trySolve(List<Point2D> desiredPoints) { … … 92 146 public void concatenateTransformPoint(AffineTransform transform, Point2D trans) { 93 147 94 AffineTransform centered = AffineTransform.getTranslateInstance(trans.getX(), trans.getY()); 95 centered.concatenate(transform); 96 centered.translate(-trans.getX(), -trans.getY()); 97 cachedTransform.concatenate(centered); 148 if (trans != null) { 149 AffineTransform centered = AffineTransform.getTranslateInstance(trans.getX(), trans.getY()); 150 centered.concatenate(transform); 151 centered.translate(-trans.getX(), -trans.getY()); 152 cachedTransform.concatenate(centered); 153 } else { 154 cachedTransform.concatenate(transform); 155 } 98 156 99 157 … … 129 187 this.originPoints = new ArrayList<Point2D>(list); 130 188 } 189 190 public void removeOriginPoint(Point2D selectedPoint) { 191 originPoints.remove(selectedPoint); 192 } 131 193 }
Note:
See TracChangeset
for help on using the changeset viewer.