Ignore:
Timestamp:
2009-11-14T18:47:09+01:00 (16 years ago)
Author:
jttt
Message:

Added parameter Bounds to MapView, draw only currently visible primitives in MapPaintVisititor

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r2439 r2450  
    2020
    2121import org.openstreetmap.josm.data.SelectionChangedListener;
    22 import org.openstreetmap.josm.data.osm.QuadBuckets.BBox;
    2322
    2423/**
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r2437 r2450  
    55import org.openstreetmap.josm.data.coor.EastNorth;
    66import org.openstreetmap.josm.data.coor.LatLon;
    7 import org.openstreetmap.josm.data.osm.QuadBuckets.BBox;
    87import org.openstreetmap.josm.data.osm.visitor.Visitor;
    98
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r2448 r2450  
    1919
    2020import org.openstreetmap.josm.Main;
    21 import org.openstreetmap.josm.data.osm.QuadBuckets.BBox;
    2221import org.openstreetmap.josm.data.osm.visitor.Visitor;
    2322import org.openstreetmap.josm.gui.mappaint.ElemStyle;
     
    219218     * @param disabled true, if this primitive is disabled; false, otherwise
    220219     */
    221     public void setDisabled(boolean disabled) {
     220    void setDisabled(boolean disabled) {
    222221        if (disabled) {
    223222            flags |= FLAG_DISABLED;
  • trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java

    r2449 r2450  
    5858    public static double WORLD_PARTS = (1 << NR_LEVELS);
    5959
    60     public static int MAX_OBJECTS_PER_LEVEL = 16;
    61     // has to be a power of 2
    62     public static int TILES_PER_LEVEL_SHIFT = 2;
    63     public static int TILES_PER_LEVEL = 1<<TILES_PER_LEVEL_SHIFT;
    64     // Maybe this should just be a Rectangle??
    65     public static class BBox
    66     {
    67         private double xmin = Double.POSITIVE_INFINITY;
    68         private double xmax = Double.NEGATIVE_INFINITY;
    69         private double ymin = Double.POSITIVE_INFINITY;
    70         private double ymax = Double.NEGATIVE_INFINITY;
    71         void sanity()
    72         {
    73             if (xmin < -180.0) {
    74                 xmin = -180.0;
    75             }
    76             if (xmax >  180.0) {
    77                 xmax =  180.0;
    78             }
    79             if (ymin <  -90.0) {
    80                 ymin =  -90.0;
    81             }
    82             if (ymax >   90.0) {
    83                 ymax =   90.0;
    84             }
    85             if ((xmin < -180.0) ||
    86                     (xmax >  180.0) ||
    87                     (ymin <  -90.0) ||
    88                     (ymax >   90.0))
    89                 throw new IllegalArgumentException("bad BBox: " + this);
    90         }
    91         @Override
    92         public String toString()
    93         {
    94             return "[ x: " + xmin + " -> " + xmax +
    95             ", y: " + ymin + " -> " + ymax + " ]";
    96         }
    97         double min(double a, double b)
    98         {
    99             if (a < b)
    100                 return a;
    101             return b;
    102         }
    103         double max(double a, double b)
    104         {
    105             if (a > b)
    106                 return a;
    107             return b;
    108         }
    109         private void add(LatLon c)
    110         {
    111             xmin = min(xmin, c.lon());
    112             xmax = max(xmax, c.lon());
    113             ymin = min(ymin, c.lat());
    114             ymax = max(ymax, c.lat());
    115         }
    116         public BBox(LatLon a, LatLon b)
    117         {
    118             add(a);
    119             add(b);
    120             sanity();
    121         }
    122         public BBox(double a_x, double a_y, double b_x, double b_y)
    123         {
    124             xmin = min(a_x, b_x);
    125             xmax = max(a_x, b_x);
    126             ymin = min(a_y, b_y);
    127             ymax = max(a_y, b_y);
    128             sanity();
    129         }
    130         public BBox(Way w)
    131         {
    132             for (Node n : w.getNodes()) {
    133                 LatLon coor = n.getCoor();
    134                 if (coor == null) {
    135                     continue;
    136                 }
    137                 add(coor);
    138             }
    139             this.sanity();
    140         }
    141         public double height()
    142         {
    143             return ymax-ymin;
    144         }
    145         public double width()
    146         {
    147             return xmax-xmin;
    148         }
    149         boolean bounds(BBox b)
    150         {
    151             if (!(xmin <= b.xmin) ||
    152                     !(xmax >= b.xmax) ||
    153                     !(ymin <= b.ymin) ||
    154                     !(ymax >= b.ymax))
    155                 return false;
    156             return true;
    157         }
    158         boolean bounds(LatLon c)
    159         {
    160             if ((xmin <= c.lon()) &&
    161                     (xmax >= c.lon()) &&
    162                     (ymin <= c.lat()) &&
    163                     (ymax >= c.lat()))
    164                 return true;
    165             return false;
    166         }
    167         boolean inside(BBox b)
    168         {
    169             if (xmin >= b.xmax)
    170                 return false;
    171             if (xmax <= b.xmin)
    172                 return false;
    173             if (ymin >= b.ymax)
    174                 return false;
    175             if (ymax <= b.ymin)
    176                 return false;
    177             return true;
    178         }
    179         boolean intersects(BBox b)
    180         {
    181             return this.inside(b) || b.inside(this);
    182         }
    183         List<LatLon> points()
    184         {
    185             LatLon p1 = new LatLon(ymin, xmin);
    186             LatLon p2 = new LatLon(ymin, xmax);
    187             LatLon p3 = new LatLon(ymax, xmin);
    188             LatLon p4 = new LatLon(ymax, xmax);
    189             List<LatLon> ret = new ArrayList<LatLon>();
    190             ret.add(p1);
    191             ret.add(p2);
    192             ret.add(p3);
    193             ret.add(p4);
    194             return ret;
    195         }
    196     }
     60    public static int MAX_OBJECTS_PER_LEVEL = 2;
    19761    class QBLevel
    19862    {
     
    294158                    continue;
    295159                }
    296                 if (children == null)
     160                if (children == null) {
    297161                    children = newChildren();
     162                }
    298163                if (children[new_index] == null) {
    299164                    children[new_index] = new QBLevel(this, new_index);
     
    725590        public BBox bbox()
    726591        {
    727             if (bbox != null) {
    728                 bbox.sanity();
     592            if (bbox != null)
    729593                return bbox;
    730             }
    731594            if (level == 0) {
    732595                bbox = new BBox(-180, 90, 180, -90);
     
    738601                bbox = new BBox(bottom_left, top_right);
    739602            }
    740             bbox.sanity();
    741603            return bbox;
    742604        }
     
    1100962            out("search bbox before sanity: " +  bbox);
    1101963        }
    1102         bbox.sanity();
    1103964        if (debug) {
    1104965            out("search bbox after sanity: " +  bbox);
     
    1124985    {
    1125986        BBox bbox = new BBox(b1.lon(), b1.lat(), b2.lon(), b2.lat());
    1126         bbox.sanity();
    1127987        return this.search(bbox);
    1128988    }
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r2439 r2450  
    77import java.util.Set;
    88
    9 import org.openstreetmap.josm.data.osm.QuadBuckets.BBox;
    109import org.openstreetmap.josm.data.osm.visitor.Visitor;
    1110import org.openstreetmap.josm.tools.CopyList;
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r2437 r2450  
    99import java.util.List;
    1010
    11 import org.openstreetmap.josm.data.osm.QuadBuckets.BBox;
    1211import org.openstreetmap.josm.data.osm.visitor.Visitor;
    1312import org.openstreetmap.josm.tools.CopyList;
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

    r2392 r2450  
    3232
    3333import org.openstreetmap.josm.Main;
     34import org.openstreetmap.josm.data.Bounds;
    3435import org.openstreetmap.josm.data.coor.EastNorth;
    3536import org.openstreetmap.josm.data.coor.LatLon;
     37import org.openstreetmap.josm.data.osm.BBox;
    3638import org.openstreetmap.josm.data.osm.DataSet;
    3739import org.openstreetmap.josm.data.osm.Node;
     
    114116            return (styles != null) ? styles.getIcon(osm) : null;
    115117
    116         if(osm.mappaintStyle == null && styles != null) {
    117             osm.mappaintStyle = styles.getIcon(osm);
    118         }
    119 
    120         return (IconElemStyle)osm.mappaintStyle;
     118            if(osm.mappaintStyle == null && styles != null) {
     119                osm.mappaintStyle = styles.getIcon(osm);
     120            }
     121
     122            return (IconElemStyle)osm.mappaintStyle;
    121123    }
    122124
     
    14451447    /* Shows areas before non-areas */
    14461448    @Override
    1447     public void visitAll(DataSet data, Boolean virtual) {
     1449    public void visitAll(DataSet data, boolean virtual, Bounds bounds) {
     1450        BBox bbox = new BBox(bounds);
    14481451        this.data = data;
    14491452        //boolean profiler = Main.pref.getBoolean("mappaint.profiler",false);
     
    15211524            /*** AREAS ***/
    15221525            //    profilerN = 0;
    1523             for (final Way osm : selectedLast(data, data.getWays())) {
     1526            for (final Way osm : selectedLast(data, data.searchWays(bbox))) {
    15241527                if (drawable(osm)
    15251528                        && osm.mappaintVisibleCode != viewid && osm.mappaintDrawnCode != paintid) {
     
    16141617        /*** NODES ***/
    16151618        //profilerN = 0;
    1616         for (final Node osm: data.getNodes()) {
     1619        for (final Node osm: data.searchNodes(bbox)) {
    16171620            if (!osm.incomplete && !osm.isDeleted() && (data.isSelected(osm) || !osm.isFiltered())
    16181621                    && osm.mappaintVisibleCode != viewid && osm.mappaintDrawnCode != paintid)
     
    16341637            //    profilerN = 0;
    16351638            currentColor = nodeColor;
    1636             for (final OsmPrimitive osm: data.getWays()) {
     1639            for (final OsmPrimitive osm: data.searchWays(bbox)) {
    16371640                if (osm.isUsable() && !osm.isFiltered()
    16381641                        && osm.mappaintVisibleCode != viewid )
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r2381 r2450  
    1919
    2020import org.openstreetmap.josm.Main;
     21import org.openstreetmap.josm.data.Bounds;
    2122import org.openstreetmap.josm.data.osm.DataSet;
    2223import org.openstreetmap.josm.data.osm.Node;
     
    129130
    130131    DataSet ds;
    131     public void visitAll(DataSet data, Boolean virtual) {
     132    public void visitAll(DataSet data, boolean virtual, Bounds bounds) {
    132133        this.ds = data;
    133134        //boolean profiler = Main.pref.getBoolean("simplepaint.profiler",false);
Note: See TracChangeset for help on using the changeset viewer.