Changeset 24080 in osm for applications/editors/josm/plugins/pdfimport/src
- Timestamp:
- 2010-11-05T14:48:46+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/pdfimport/src/pdfimport
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pdfimport/src/pdfimport/FilePlacement.java
r24056 r24080 91 91 } 92 92 93 EastNorth en = new EastNorth(0, 0); 94 93 95 public LatLon tranformCoords(double x, double y) { 94 96 95 97 if (this.projection == null){ 96 return new LatLon(y/1000, x/1000); 98 //en.setLocation(x * 1024,y * 1024); 99 //return Main.proj.eastNorth2latlon( en); 100 return new LatLon(y / 1000, x / 1000); 97 101 } 98 102 else{ 103 99 104 x = (x - this.minX) * (this.maxEast - this.minEast) / (this.maxX - this.minX) + this.minEast; 100 105 y = (y - this.minY) * (this.maxNorth - this.minNorth) / (this.maxY - this.minY) + this.minNorth; 101 return this.projection.eastNorth2latlon(new EastNorth(x, y)); 106 en.setLocation(x,y); 107 return this.projection.eastNorth2latlon(en); 102 108 } 103 109 } … … 105 111 public EastNorth reverseTransform(LatLon coor) { 106 112 if (this.projection == null){ 113 //EastNorth result = this.projection.latlon2eastNorth(coor); 114 //result.setLocation(result.east() / 1024, result.north() / 1024); 115 //return result; 107 116 return new EastNorth(coor.lon() * 1000, coor.lat() * 1000); 108 117 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/LoadPdfDialog.java
r24060 r24080 78 78 private JTextField colorFilterColor; 79 79 private JCheckBox colorFilterCheck; 80 private JCheckBox removeParallelSegmentsCheck; 81 private JTextField removeParallelSegmentsTolerance; 82 private JCheckBox removeLargeObjectsCheck; 83 private JTextField removeLargeObjectsSize; 80 84 81 85 public LoadPdfDialog() { … … 177 181 this.removeSmallObjectsSize = new JTextField("1"); 178 182 183 this.removeLargeObjectsCheck = new JCheckBox(tr("Remove objects larger than")); 184 this.removeLargeObjectsSize = new JTextField("10"); 185 186 179 187 this.colorFilterCheck = new JCheckBox(tr("Only this color")); 180 188 this.colorFilterColor = new JTextField("#000000"); 189 190 this.removeParallelSegmentsCheck = new JCheckBox(tr("Remove parallel lines")); 191 this.removeParallelSegmentsTolerance = new JTextField("3"); 192 181 193 182 194 JPanel configPanel = new JPanel(new GridBagLayout()); … … 197 209 198 210 c.gridx = 0; c.gridy = 2; c.gridwidth = 1; 211 configPanel.add(this.removeLargeObjectsCheck, c); 212 c.gridx = 1; c.gridy = 2; c.gridwidth = 1; c.anchor = c.NORTHEAST; 213 configPanel.add(new JLabel("Tolerance :"), c); 214 c.gridx = 2; c.gridy = 2; c.gridwidth = 1; c.anchor = c.NORTHWEST; 215 configPanel.add(this.removeLargeObjectsSize, c); 216 217 c.gridx = 0; c.gridy = 3; c.gridwidth = 1; 218 configPanel.add(this.removeParallelSegmentsCheck, c); 219 c.gridx = 1; c.gridy = 3; c.gridwidth = 1; c.anchor = c.NORTHEAST; 220 configPanel.add(new JLabel("Max distance :"), c); 221 c.gridx = 2; c.gridy = 3; c.gridwidth = 1; c.anchor = c.NORTHWEST; 222 configPanel.add(this.removeParallelSegmentsTolerance, c); 223 224 c.gridx = 0; c.gridy = 4; c.gridwidth = 1; 199 225 configPanel.add(this.colorFilterCheck, c); 200 c.gridx = 2; c.gridy = 2; c.gridwidth = 1;226 c.gridx = 2; c.gridy = 4; c.gridwidth = 1; 201 227 configPanel.add(this.colorFilterColor, c); 202 228 203 c.gridx = 0; c.gridy = 3; c.gridwidth = 2;229 c.gridx = 0; c.gridy = 5; c.gridwidth = 2; 204 230 configPanel.add(this.debugModeCheck, c); 205 231 … … 270 296 panel.add(okCancelPanel, c); 271 297 272 this.setSize(400, 5 00);298 this.setSize(400, 520); 273 299 this.setContentPane(panel); 274 300 } … … 396 422 397 423 LatLon ll = ((Node)selected.iterator().next()).getCoor(); 398 return this.placement.reverseTransform(ll); 424 FilePlacement pl = new FilePlacement(); 425 return pl.reverseTransform(ll); 399 426 } 400 427 … … 509 536 510 537 538 if (this.removeParallelSegmentsCheck.isSelected()) { 539 try { 540 double tolerance = Double.parseDouble(this.removeParallelSegmentsTolerance.getText()); 541 data.removeParallelLines(tolerance); 542 } 543 catch (Exception e) { 544 JOptionPane 545 .showMessageDialog( 546 Main.parent, 547 tr("Max distance is not a number")); 548 return null; 549 } 550 } 551 511 552 if (this.mergeCloseNodesCheck.isSelected()) { 512 553 try { … … 539 580 } 540 581 582 583 if (this.removeLargeObjectsCheck.isSelected()) { 584 try { 585 double tolerance = Double.parseDouble(this.removeLargeObjectsSize.getText()); 586 data.removeLargeObjects(tolerance); 587 } 588 catch (Exception e) { 589 JOptionPane 590 .showMessageDialog( 591 Main.parent, 592 tr("Tolerance is not a number")); 593 return null; 594 } 595 } 541 596 542 597 data.splitLayersByPathKind(); -
applications/editors/josm/plugins/pdfimport/src/pdfimport/PathOptimizer.java
r24069 r24080 47 47 48 48 public void addMultiPath(LayerInfo info, List<PdfPath> paths) { 49 49 50 LayerContents layer = this.getLayer(info); 50 PdfMultiPath p = new PdfMultiPath(paths); 51 layer.multiPaths.add(p); 51 boolean goodMultiPath = true; 52 53 for(PdfPath path: paths) { 54 goodMultiPath &= path.isClosed(); 55 } 56 57 if (goodMultiPath) { 58 PdfMultiPath p = new PdfMultiPath(paths); 59 layer.multiPaths.add(p); 60 } else { 61 layer.paths.addAll(paths); 62 } 52 63 } 53 64 … … 78 89 79 90 91 public void removeParallelLines(double maxDistance){ 92 for(LayerContents layer: this.layers) { 93 this.removeParallelLines(layer, maxDistance); 94 } 95 } 80 96 81 97 public void mergeNodes(double tolerance) { … … 96 112 public void removeSmallObjects(double tolerance) { 97 113 for(LayerContents layer: this.layers) { 98 this.removeSmallObjects(layer, tolerance); 114 this.removeSmallObjects(layer, tolerance, Double.POSITIVE_INFINITY); 115 } 116 } 117 118 119 public void removeLargeObjects(double tolerance) { 120 for(LayerContents layer: this.layers) { 121 this.removeSmallObjects(layer, 0.0, tolerance); 99 122 } 100 123 } … … 232 255 233 256 234 private void removeSmallObjects(LayerContents layer, double tolerance) {257 private void removeSmallObjects(LayerContents layer, double min, double max) { 235 258 List<PdfPath> newPaths = new ArrayList<PdfPath>(layer.paths.size()); 236 259 237 260 for(PdfPath path: layer.paths) { 238 boolean good = getShapeSize(path) >= tolerance; 261 double size = getShapeSize(path); 262 boolean good = size >= min && size <= max; 239 263 240 264 if (good) { … … 250 274 boolean good = true; 251 275 for(PdfPath path: mp.paths) { 252 good &= getShapeSize(path) >= tolerance; 276 double size = getShapeSize(path); 277 good &= size >= min && size <= max; 253 278 } 254 279 … … 274 299 } 275 300 301 302 303 /*** 304 * This method finds parralel lines with similar distance and removes them. 305 * @param layer 306 */ 307 private void removeParallelLines(LayerContents layer, double maxDistance) { 308 double angleTolerance = 1.0 / 180.0 * Math.PI; // 1 degree 309 int minSegments = 10; 310 311 //filter paths by direction 312 List<ParallelSegmentsFinder> angles = new ArrayList<ParallelSegmentsFinder>(); 313 314 for(PdfPath path: layer.paths) { 315 if (path.points.size() != 2){ 316 continue; 317 } 318 319 Point2D p1 = path.firstPoint(); 320 Point2D p2 = path.lastPoint(); 321 double angle = Math.atan2(p2.getX() - p1.getX(), p2.getY() - p1.getY()); 322 //normalize between 0 and 180 degrees 323 while (angle < 0) angle += Math.PI; 324 while (angle > Math.PI) angle -= Math.PI; 325 boolean added = false; 326 327 for(ParallelSegmentsFinder pa: angles) { 328 if (Math.abs(pa.angle - angle) < angleTolerance){ 329 pa.addPath(path, angle); 330 added = true; 331 break; 332 } 333 } 334 335 if (!added) { 336 ParallelSegmentsFinder pa = new ParallelSegmentsFinder(); 337 pa.addPath(path, angle); 338 angles.add(pa); 339 } 340 } 341 342 Set<PdfPath> pathsToRemove = new HashSet<PdfPath>(); 343 344 //process each direction 345 for (ParallelSegmentsFinder pa: angles){ 346 if (pa.paths.size() < minSegments){ 347 continue; 348 } 349 350 List<ParallelSegmentsFinder> parts = pa.splitByDistance(maxDistance); 351 352 for(ParallelSegmentsFinder part: parts) { 353 if (part.paths.size() >= minSegments){ 354 pathsToRemove.addAll(part.paths); 355 } 356 } 357 } 358 359 //generate new path list 360 List<PdfPath> result = new ArrayList<PdfPath>(layer.paths.size() - pathsToRemove.size()); 361 362 for(PdfPath path: layer.paths) { 363 if (!pathsToRemove.contains(path)) { 364 result.add(path); 365 } 366 } 367 368 layer.paths = result; 369 } 276 370 277 371 … … 354 448 //remove excess segments from start of chain 355 449 while (lastPoint != firstPoint) { 356 PdfPath pathToRemove = pathChain.remove(0); 450 PdfPath pathToRemove = pathChain.remove(0); 357 451 firstPoint = pathToRemove.getOtherEnd(firstPoint); 358 452 } … … 639 733 640 734 735 641 736 }
Note:
See TracChangeset
for help on using the changeset viewer.