Changeset 2427 in josm for trunk/src/org/openstreetmap/josm/data/osm
- Timestamp:
- 2009-11-10T08:15:02+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/osm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r2419 r2427 5 5 import org.openstreetmap.josm.data.coor.EastNorth; 6 6 import org.openstreetmap.josm.data.coor.LatLon; 7 import org.openstreetmap.josm.data.osm.QuadBuckets.BBox; 7 8 import org.openstreetmap.josm.data.osm.visitor.Visitor; 8 9 … … 175 176 return OsmPrimitiveType.NODE; 176 177 } 178 179 public BBox getBBox() { 180 if (coor == null) 181 return new BBox(0, 0, 0, 0); 182 else 183 return new BBox(coor, coor); 184 } 177 185 } -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r2417 r2427 19 19 20 20 import org.openstreetmap.josm.Main; 21 import org.openstreetmap.josm.data.osm.QuadBuckets.BBox; 21 22 import org.openstreetmap.josm.data.osm.visitor.Visitor; 22 23 import org.openstreetmap.josm.gui.mappaint.ElemStyle; … … 1007 1008 } 1008 1009 1010 public abstract BBox getBBox(); 1011 1009 1012 } 1010 1013 -
trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java
r2425 r2427 1 1 package org.openstreetmap.josm.data.osm; 2 2 3 import java.lang.reflect.Array; 3 4 import java.util.ArrayList; … … 5 6 import java.util.Collection; 6 7 import java.util.Collections; 7 import java.util.HashMap;8 8 import java.util.Iterator; 9 9 import java.util.LinkedList; … … 190 190 } 191 191 } 192 /*193 * This is a quick hack. The problem is that we need the194 * way's bounding box a *bunch* of times when it gets195 * inserted. It gets expensive if we have to recreate196 * them each time.197 *198 * An alternative would be to calculate it at .add() time199 * and passing it down the call chain.200 */201 HashMap<Way,BBox> way_bbox_cache = new HashMap<Way, BBox>();202 BBox way_bbox(Way w)203 {204 if (way_bbox_cache.size() > 100) {205 way_bbox_cache.clear();206 }207 BBox b = way_bbox_cache.get(w);208 if (b == null) {209 b = new BBox(w);210 way_bbox_cache.put(w, b);211 }212 return b;213 //return new BBox(w);214 }215 216 192 class QBLevel 217 193 { … … 247 223 this.content = null; 248 224 } 249 if (this.canRemove()) 225 if (this.canRemove()) { 250 226 this.remove_from_parent(); 227 } 251 228 return ret; 252 229 } … … 268 245 out("getting index for " + o + " at level: " + level); 269 246 } 270 if (o instanceof Node) { 271 LatLon coor = ((Node)o).getCoor(); 272 if (coor == null) 247 int index = -1; 248 for (LatLon c : o.getBBox().points()) { 249 if (debug) { 250 out("getting index for point: " + c); 251 } 252 if (index == -1) { 253 index = QuadTiling.index(c, level); 254 if (debug) { 255 out("set initial index to: " + index); 256 } 257 continue; 258 } 259 int another_index = QuadTiling.index(c, level); 260 if (debug) { 261 out("other point index: " + another_index); 262 } 263 if (another_index != index) { 264 // This happens at level 0 sometimes when a way has no 265 // nodes present. 266 if (debug) { 267 out("primitive ("+o.getId()+") would have gone across two quads " 268 + another_index + "/" + index + " at level: " + level + " "); 269 } 273 270 return -1; 274 return QuadTiling.index(coor, level); 275 } 276 if (o instanceof Way) { 277 Way w = (Way)o; 278 int index = -1; 279 //for (Node n : w.getNodes()) { 280 for (LatLon c : way_bbox(w).points()) { 281 // LatLon c = n.getCoor(); 282 if (debug) { 283 out("getting index for point: " + c); 284 } 285 if (index == -1) { 286 index = QuadTiling.index(c, level); 287 if (debug) { 288 out("set initial way index to: " + index); 289 } 290 continue; 291 } 292 int node_index = QuadTiling.index(c, level); 293 if (debug) { 294 out("other node way index: " + node_index); 295 } 296 if (node_index != index) { 297 // This happens at level 0 sometimes when a way has no 298 // nodes present. 299 if (debug) { 300 out("way ("+w.getId()+") would have gone across two quads " 301 + node_index + "/" + index + " at level: " + level + " "); 302 out("node count: " + w.getNodes().size()); 303 for (LatLon c2 : way_bbox(w).points()) { 304 out("points: " + c2); 305 } 306 } 307 return -1; 308 } 309 } 310 return index; 311 } 312 abort("bad primitive: " + o); 313 return -1; 271 } 272 } 273 return index; 314 274 } 315 275 void split() … … 367 327 } 368 328 if (level >= NR_LEVELS-1) { 369 if (debug) 329 if (debug) { 370 330 out("can not split, but too deep: " + level + " size: " + content.size()); 331 } 371 332 return; 372 333 } … … 388 349 boolean matches(T o, BBox search_bbox) 389 350 { 390 if (o instanceof Node) { 391 LatLon coor = ((Node)o).getCoor(); 392 if (coor == null) 393 return false; 394 return search_bbox.bounds(coor); 395 } 396 if (o instanceof Way) { 397 BBox bbox = way_bbox((Way)o); 398 return bbox.intersects(search_bbox); 399 } 400 abort("matches() bad primitive: " + o); 401 return false; 351 return o.getBBox().intersects(search_bbox); 402 352 } 403 353 private List<T> search_contents(BBox search_bbox) … … 497 447 if (debug) { 498 448 out("no siblings at level["+next.level+"], moving to parent"); 499 449 } 500 450 next = next.parent; 501 451 if (next == null) { 502 452 break; 503 453 } 504 454 sibling = next.next_sibling(); 505 455 } … … 510 460 { 511 461 QBLevel next = this; 512 if (this.isLeaf()) 462 if (this.isLeaf()) { 513 463 next = this.nextSibling(); 464 } 514 465 if (next == null) 515 466 return null; 516 467 // Walk back down the tree 517 468 // and find the first leaf 518 while ( next != null &&!next.isLeaf()) {519 if (next.hasContent() && next != this) 469 while (!next.isLeaf()) { 470 if (next.hasContent() && next != this) { 520 471 break; 521 if (debug) 472 } 473 if (debug) { 522 474 out("["+next.level+"] next node ("+next+") is a branch (content: "+next.hasContent()+"), moving down..."); 475 } 523 476 boolean progress = false; 524 477 for (QBLevel child : next.children) { 525 if (child == null) 478 if (child == null) { 526 479 continue; 480 } 527 481 next = child; 528 482 progress = true; … … 817 771 for (int i = 0; i < parent.children.length; i++) { 818 772 QBLevel sibling = parent.children[i]; 819 if (sibling != null) 773 if (sibling != null) { 820 774 nr_siblings++; 821 if (sibling != this) 775 } 776 if (sibling != this) { 822 777 continue; 823 if (!canRemove()) 778 } 779 if (!canRemove()) { 824 780 abort("attempt to remove non-empty child: " + this.content + " " + this.children); 781 } 825 782 parent.children[i] = null; 826 783 nr_siblings--; 827 784 } 828 if (parent.canRemove()) 785 if (parent.canRemove()) { 829 786 parent.remove_from_parent(); 787 } 830 788 } 831 789 boolean canRemove() … … 911 869 return true; 912 870 } 913 boolean canStore(Object o)914 {915 if (o instanceof Way)916 return true;917 if (o instanceof Node)918 return true;919 return false;920 }921 871 public boolean removeAll(Collection<?> objects) 922 872 { 873 boolean changed = false; 923 874 for (Object o : objects) { 924 if (!canStore(o)) 925 return false; 926 if (!this.remove(o)) 875 changed = changed | remove(o); 876 } 877 return changed; 878 } 879 public boolean addAll(Collection<? extends T> objects) 880 { 881 boolean changed = false; 882 for (Object o : objects) { 883 changed = changed | this.add(convert(o)); 884 } 885 return changed; 886 } 887 public boolean containsAll(Collection<?> objects) 888 { 889 for (Object o : objects) { 890 if (!this.contains(o)) 927 891 return false; 928 892 } 929 893 return true; 930 }931 public boolean addAll(Collection<? extends T> objects)932 {933 for (Object o : objects) {934 if (!canStore(o))935 return false;936 if (!this.add(convert(o)))937 return false;938 }939 return true;940 }941 public boolean containsAll(Collection<?> objects)942 {943 for (Object o : objects) {944 if (!canStore(o))945 return false;946 if (!this.contains(o))947 return false;948 }949 return true;950 }951 private void check_type(Object o)952 {953 if (canStore(o))954 return;955 unsupported();956 894 } 957 895 // If anyone has suggestions for how to fix … … 964 902 public boolean remove(Object o) 965 903 { 966 check_type(o);967 904 return this.remove(convert(o)); 968 905 } … … 991 928 */ 992 929 QBLevel bucket = root.find_exact(o); 993 if (o instanceof Way) {994 way_bbox_cache.remove(o);995 }996 930 /* 997 931 * That may fail because the object was … … 1009 943 public boolean contains(Object o) 1010 944 { 1011 if (!canStore(o))1012 return false;1013 945 QBLevel bucket = root.find_exact(convert(o)); 1014 946 if (bucket == null) -
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r2410 r2427 7 7 import java.util.Set; 8 8 9 import org.openstreetmap.josm.data.osm.QuadBuckets.BBox; 9 10 import org.openstreetmap.josm.data.osm.visitor.Visitor; 10 11 import org.openstreetmap.josm.tools.CopyList; … … 324 325 return OsmPrimitiveType.RELATION; 325 326 } 327 328 @Override 329 public BBox getBBox() { 330 return new BBox(0, 0, 0, 0); 331 } 326 332 } -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r2419 r2427 9 9 import java.util.List; 10 10 11 import org.openstreetmap.josm.data.osm.QuadBuckets.BBox; 11 12 import org.openstreetmap.josm.data.osm.visitor.Visitor; 12 13 import org.openstreetmap.josm.tools.CopyList; … … 362 363 } 363 364 } 365 366 @Override 367 public BBox getBBox() { 368 // TODO Precalculate way bbox (and update it every time nodes are moved or edited) 369 return new BBox(this); 370 } 364 371 }
Note:
See TracChangeset
for help on using the changeset viewer.