Changeset 32556 in osm for applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java
- Timestamp:
- 2016-07-04T14:18:17+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java
r26835 r32556 1 // License: GPL. v2 and later. Copyright 2008-2009 by Pieren <pieren3@gmail.com> and others1 // License: GPL. For details, see LICENSE file. 2 2 package cadastre_fr; 3 3 … … 44 44 private double pixelPerEast; 45 45 private double pixelPerNorth; 46 47 46 48 47 public GeorefImage(BufferedImage img, EastNorth min, EastNorth max, WMSLayer wmsLayer) { 49 48 image = img; 50 49 51 50 this.min = min; 52 51 this.max = max; … … 81 80 */ 82 81 private EastNorthBound computeNewBounding(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) { 83 EastNorth pt[]= new EastNorth[4];82 EastNorth[] pt = new EastNorth[4]; 84 83 pt[0] = p1; 85 84 pt[1] = p2; … … 90 89 double highestEast = Double.MIN_VALUE; 91 90 double highestNorth = Double.MIN_VALUE; 92 for (int i=0; i<=3; i++) {91 for (int i = 0; i <= 3; i++) { 93 92 smallestEast = Math.min(pt[i].east(), smallestEast); 94 93 smallestNorth = Math.min(pt[i].north(), smallestNorth); … … 111 110 112 111 // apply offsets defined manually when vector images are translated manually (not saved in cache) 113 double dx =0, dy=0;114 if (wmsLayer !=null) {112 double dx = 0, dy = 0; 113 if (wmsLayer != null) { 115 114 dx = wmsLayer.deltaEast; 116 115 dy = wmsLayer.deltaNorth; … … 131 130 } else { 132 131 Point[] croppedPoint = new Point[5]; 133 for (int i =0; i<4; i++)132 for (int i = 0; i < 4; i++) { 134 133 croppedPoint[i] = nc.getPoint( 135 134 new EastNorth(orgCroppedRaster[i].east()+dx, orgCroppedRaster[i].north()+dy)); 135 } 136 136 croppedPoint[4] = croppedPoint[0]; 137 for (int i =0; i<4; i++) {137 for (int i = 0; i < 4; i++) { 138 138 g.setColor(Color.green); 139 139 g.drawLine(croppedPoint[i].x, croppedPoint[i].y, croppedPoint[i+1].x, croppedPoint[i+1].y); … … 173 173 /** 174 174 * Make all pixels masked by the given georefImage transparent in this image 175 *176 * @param georefImage177 175 */ 178 176 public void withdraw(GeorefImage georefImage) { … … 189 187 int heightYMaskPixel = Math.abs((int) ((maxMaskNorth - minMaskNorth) / pxPerNorth)); 190 188 Graphics g = image.getGraphics(); 191 for (int x = minXMaskPixel; x < minXMaskPixel + widthXMaskPixel; x++) 192 for (int y = minYMaskPixel; y < minYMaskPixel + heightYMaskPixel; y++) 189 for (int x = minXMaskPixel; x < minXMaskPixel + widthXMaskPixel; x++) { 190 for (int y = minYMaskPixel; y < minYMaskPixel + heightYMaskPixel; y++) { 193 191 image.setRGB(x, y, VectorImageModifier.cadastreBackgroundTransp); 192 } 193 } 194 194 g.dispose(); 195 195 } … … 222 222 if (WMSLayer.currentFormat >= 4) { 223 223 imageOriginalHeight = in.readInt(); 224 imageOriginalWidth = 225 } 226 image = (BufferedImage)ImageIO.read(ImageIO.createImageInputStream(in));224 imageOriginalWidth = in.readInt(); 225 } 226 image = ImageIO.read(ImageIO.createImageInputStream(in)); 227 227 updatePixelPer(); 228 228 } … … 285 285 min = new EastNorth(min.east() + dx, min.north() + dy); 286 286 max = new EastNorth(max.east() + dx, max.north() + dy); 287 for (int i =0; i<4; i++) {287 for (int i = 0; i < 4; i++) { 288 288 orgRaster[i] = new EastNorth(orgRaster[i].east() + dx, orgRaster[i].north() + dy); 289 289 orgCroppedRaster[i] = new EastNorth(orgCroppedRaster[i].east() + dx, orgCroppedRaster[i].north() + dy); 290 290 } 291 291 } 292 292 293 293 /** 294 294 * Change this image scale by moving the min,max coordinates around an anchor 295 * @param anchor296 * @param proportion297 295 */ 298 296 public void scale(EastNorth anchor, double proportion) { 299 297 min = anchor.interpolate(min, proportion); 300 298 max = anchor.interpolate(max, proportion); 301 for (int i =0; i<4; i++) {299 for (int i = 0; i < 4; i++) { 302 300 orgRaster[i] = anchor.interpolate(orgRaster[i], proportion); 303 301 orgCroppedRaster[i] = anchor.interpolate(orgCroppedRaster[i], proportion); … … 316 314 return; 317 315 // rotate the bounding boxes coordinates first 318 for (int i =0; i<4; i++) {316 for (int i = 0; i < 4; i++) { 319 317 orgRaster[i] = orgRaster[i].rotate(anchor, delta_ang); 320 318 orgCroppedRaster[i] = orgCroppedRaster[i].rotate(anchor, delta_ang); … … 323 321 double sin = Math.abs(Math.sin(angle+delta_ang)), cos = Math.abs(Math.cos(angle+delta_ang)); 324 322 int w = imageOriginalWidth, h = imageOriginalHeight; 325 int neww = (int)Math.floor(w*cos+h*sin); 326 int newh = (int)Math.floor(h*cos+w*sin); 323 int neww = (int) Math.floor(w*cos+h*sin); 324 int newh = (int) Math.floor(h*cos+w*sin); 327 325 GraphicsConfiguration gc = getDefaultConfiguration(); 328 326 BufferedImage result = gc.createCompatibleImage(neww, newh, image.getTransparency()); … … 336 334 min = enb.min; 337 335 max = enb.max; 338 angle +=delta_ang;336 angle += delta_ang; 339 337 } 340 338 … … 346 344 public void crop(EastNorth adj1, EastNorth adj2) { 347 345 // s1 and s2 have 0,0 at top, left where all EastNorth coord. have 0,0 at bottom, left 348 int sx1 = (int)((adj1.getX() - min.getX())*getPixelPerEast()); 349 int sy1 = (int)((max.getY() - adj2.getY())*getPixelPerNorth()); 350 int sx2 = (int)((adj2.getX() - min.getX())*getPixelPerEast()); 351 int sy2 = (int)((max.getY() - adj1.getY())*getPixelPerNorth()); 346 int sx1 = (int) ((adj1.getX() - min.getX())*getPixelPerEast()); 347 int sy1 = (int) ((max.getY() - adj2.getY())*getPixelPerNorth()); 348 int sx2 = (int) ((adj2.getX() - min.getX())*getPixelPerEast()); 349 int sy2 = (int) ((max.getY() - adj1.getY())*getPixelPerNorth()); 352 350 int newWidth = Math.abs(sx2 - sx1); 353 351 int newHeight = Math.abs(sy2 - sy1);
Note:
See TracChangeset
for help on using the changeset viewer.