Changeset 29270 in osm


Ignore:
Timestamp:
2013-02-20T20:10:33+01:00 (11 years ago)
Author:
malcolmh
Message:

save

Location:
applications/editors/josm/plugins/smed2/src/seamap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/smed2/src/seamap/Renderer.java

    r29266 r29270  
    173173
    174174        public static void lineVector (Feature feature, LineStyle style) {
    175                 if (feature.flag != Fflag.POINT) {
    176                         ArrayList<Long> ways = new ArrayList<Long>();
    177 //                      if (map.outers.containsKey(feature.refs)) {
    178 //                              ways.addAll(map.mpolys.get(map.outers.get(feature.refs)));
    179 //                      } else {
    180 //                              if (map.mpolys.containsKey(feature.refs)) {
    181 //                                      ways.addAll(map.mpolys.get(feature.refs));
    182 //                              } else {
    183 //                                      ways.add(feature.refs);
    184 //                              }
    185 //                      }
    186                         Path2D.Double p = new Path2D.Double();
    187                         p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
     175                Path2D.Double p = new Path2D.Double();
     176                p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
     177                switch (feature.flag) {
     178                case LINE:
     179                        break;
     180                case AREA:
     181                        break;
     182/*                      ArrayList<Long> ways = new ArrayList<Long>();
     183                        if (map.outers.containsKey(feature.refs)) {
     184                                ways.addAll(map.mpolys.get(map.outers.get(feature.refs)));
     185                        } else {
     186                                if (map.mpolys.containsKey(feature.refs)) {
     187                                        ways.addAll(map.mpolys.get(feature.refs));
     188                                } else {
     189                                        ways.add(feature.refs);
     190                                }
     191                        }
    188192                        for (long way : ways) {
    189193                                boolean first = true;
    190 /*                              for (long node : map.ways.get(way)) {
     194                                for (long node : map.ways.get(way)) {
    191195                                        Point2D point = helper.getPoint(map.points.get(node));
    192196                                        if (first) {
     
    215219                                g2.setPaint(style.fill);
    216220                                g2.fill(p);
    217 */                      }
     221                        }*/
    218222                }
    219223        }
  • applications/editors/josm/plugins/smed2/src/seamap/SeaMap.java

    r29266 r29270  
    2424                ANON, ISOL, CONN
    2525        }
    26        
     26
    2727        public class Snode {
    2828                public double lat;
     
    3535                        lon = 0;
    3636                }
     37
    3738                public Snode(double ilat, double ilon) {
    3839                        flg = Nflag.ANON;
     
    4041                        lon = ilon;
    4142                }
     43
    4244                public Snode(double ilat, double ilon, Nflag iflg) {
    4345                        lat = ilat;
     
    4648                }
    4749        }
    48        
     50
    4951        public class Edge {
    5052                public boolean forward;
     
    5254                public long last;
    5355                public ArrayList<Long> nodes;
     56
    5457                public Edge() {
    5558                        forward = true;
     
    5962                }
    6063        }
    61        
     64
    6265        public class Side {
    6366                Edge edge;
    6467                boolean forward;
     68
    6569                public Side(Edge iedge, boolean ifwd) {
    6670                        edge = iedge;
     
    6872                }
    6973        }
    70        
     74
    7175        public class Bound {
    7276                public boolean outer;
    7377                ArrayList<Side> sides;
     78
    7479                public Bound() {
    7580                        outer = true;
    7681                        sides = new ArrayList<Side>();
    7782                }
     83
    7884                public Bound(Side iside, boolean irole) {
    7985                        outer = irole;
     
    98104                }
    99105        }
    100        
     106
    101107        public class AttMap extends EnumMap<Att, AttItem> {
    102108                public AttMap() {
     
    104110                }
    105111        }
    106        
     112
    107113        public class ObjTab extends HashMap<Integer, AttMap> {
    108114                public ObjTab() {
     
    110116                }
    111117        }
    112        
     118
    113119        public class ObjMap extends EnumMap<Obj, ObjTab> {
    114120                public ObjMap() {
     
    116122                }
    117123        }
    118        
     124
    119125        public class NodeTab extends HashMap<Long, Snode> {
    120126                public NodeTab() {
     
    122128                }
    123129        }
    124        
     130
    125131        public class EdgeTab extends HashMap<Long, Edge> {
    126132                public EdgeTab() {
     
    128134                }
    129135        }
    130        
     136
    131137        public class AreaTab extends HashMap<Long, Area> {
    132138                public AreaTab() {
     
    134140                }
    135141        }
    136        
     142
    137143        public class FtrMap extends EnumMap<Obj, ArrayList<Feature>> {
    138144                public FtrMap() {
     
    140146                }
    141147        }
    142        
     148
    143149        public class FtrTab extends HashMap<Long, Feature> {
    144150                public FtrTab() {
     
    146152                }
    147153        }
    148        
     154
    149155        public enum Fflag {
    150156                UNKN, POINT, LINE, AREA
    151157        }
    152        
     158
    153159        public class Feature {
    154160                public Fflag flag;
     
    174180        public EdgeTab edges;
    175181        public AreaTab areas;
    176        
     182
    177183        public FtrMap features;
    178184        public FtrTab index;
     
    182188        private ArrayList<Long> outers;
    183189        private ArrayList<Long> inners;
     190
     191        public class EdgeIterator {
     192                Edge edge;
     193                boolean forward;
     194                ListIterator<Long> it;
     195
     196                public EdgeIterator(Edge iedge, boolean dir) {
     197                        edge = iedge;
     198                        forward = dir;
     199                        it = null;
     200                }
     201
     202                public boolean hasNext() {
     203                        return (edge != null) && ((it == null) || (forward && it.hasNext()) || (!forward && it.hasPrevious()));
     204                }
     205
     206                public Snode next() {
     207                        long ref = 0;
     208                        if (forward) {
     209                                if (it == null) {
     210                                        ref = edge.first;
     211                                        it = edge.nodes.listIterator();
     212                                } else {
     213                                        if (it.hasNext()) {
     214                                                ref = it.next();
     215                                        } else {
     216                                                ref = edge.last;
     217                                                edge = null;
     218                                        }
     219                                }
     220                        } else {
     221                                if (it == null) {
     222                                        ref = edge.last;
     223                                        it = edge.nodes.listIterator(edge.nodes.size());
     224                                } else {
     225                                        if (it.hasPrevious()) {
     226                                                ref = it.previous();
     227                                        } else {
     228                                                ref = edge.first;
     229                                                edge = null;
     230                                        }
     231                                }
     232                        }
     233                        return nodes.get(ref);
     234                }
     235        }
     236
     237        public class BoundIterator {
     238                Bound bound;
     239                Side side;
     240                ListIterator<Side> sit;
     241                EdgeIterator eit;
     242
     243                public BoundIterator(Bound ibound) {
     244                        bound = ibound;
     245                        sit = bound.sides.listIterator();
     246                        if (sit.hasNext()) {
     247                                side = sit.next();
     248                                eit = new EdgeIterator(side.edge, side.forward);
     249                        } else {
     250                                side = null;
     251                        }
     252                }
     253
     254                public boolean hasNext() {
     255                        return side != null;
     256                }
     257
     258                public Snode next() {
     259                        Snode node = null;
     260                        if (side != null) {
     261                                if (eit.hasNext()) {
     262                                        node = eit.next();
     263                                } else {
     264                                        if (sit.hasNext()) {
     265                                                side = sit.next();
     266                                                eit = new EdgeIterator(side.edge, side.forward);
     267                                                node = eit.next();
     268                                        } else {
     269                                                side = null;
     270                                        }
     271                                }
     272                        }
     273                        return node;
     274                }
     275        }
     276       
     277        public class AreaIterator {
     278                Area area;
     279        }
     280
     281        public class FeatureIterator {
     282                Feature feature;
     283        }
    184284
    185285        public SeaMap() {
     
    234334                }
    235335        }
    236        
     336
    237337        public void addTag(String key, String val) {
    238338                String subkeys[] = key.split(":");
     
    261361                                }
    262362                                AttVal attval = S57val.convertValue(val, att);
    263                                 if (attval.val != null) atts.put(att, new AttItem(attval.conv, attval.val));
     363                                if (attval.val != null)
     364                                        atts.put(att, new AttItem(attval.conv, attval.val));
    264365                        } else {
    265366                                if (subkeys[1].equals("type")) {
     
    269370                                        if (att != Att.UNKATT) {
    270371                                                AttVal attval = S57val.convertValue(val, att);
    271                                                 if (attval.val != null) feature.atts.put(att, new AttItem(attval.conv, attval.val));
     372                                                if (attval.val != null)
     373                                                        feature.atts.put(att, new AttItem(attval.conv, attval.val));
    272374                                        }
    273375                                }
     
    311413                                        Bound bound = new Bound(new Side(edge, edge.forward), (role == outers));
    312414                                        if (node1 != node2) {
    313                                                 for (ListIterator<Long> it = role.listIterator(0); it.hasNext(); ) {
    314                                             Edge nedge = edges.get(it.next());
    315                                             if (nedge.first == node2) {
    316                                                 bound.sides.add(new Side(nedge, true));
    317                                                 it.remove();
    318                                                 if (nedge.last == node2) break;
    319                                             } else if (nedge.last == node2) {
    320                                                 bound.sides.add(new Side(nedge, false));
    321                                                 it.remove();
    322                                                 if (nedge.first == node2) break;
    323                                             }
     415                                                for (ListIterator<Long> it = role.listIterator(0); it.hasNext();) {
     416                                                        Edge nedge = edges.get(it.next());
     417                                                        if (nedge.first == node2) {
     418                                                                bound.sides.add(new Side(nedge, true));
     419                                                                it.remove();
     420                                                                if (nedge.last == node2)
     421                                                                        break;
     422                                                        } else if (nedge.last == node2) {
     423                                                                bound.sides.add(new Side(nedge, false));
     424                                                                it.remove();
     425                                                                if (nedge.first == node2)
     426                                                                        break;
     427                                                        }
    324428                                                }
    325429                                        }
     
    344448                lat = lon = llon = llat = 0;
    345449                double sigma = 0;
    346                 ListIterator<Long> it;
    347                 for (Side side : bound.sides) {
    348                         if (side.forward) {
    349                                 node = nodes.get(side.edge.first);
    350                                 lat = node.lat;
    351                                 lon = node.lon;
    352                                 it = side.edge.nodes.listIterator();
    353                                 while (it.hasNext()) {
    354                                         llon = lon;
    355                                         llat = lat;
    356                                         node = nodes.get(it.next());
    357                                         lat = node.lat;
    358                                         lon = node.lon;
    359                                         sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat));
    360                                 }
    361                                 llon = lon;
    362                                 llat = lat;
    363                                 node = nodes.get(side.edge.last);
    364                                 lat = node.lat;
    365                                 lon = node.lon;
    366                                 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat));
    367                         } else {
    368                                 node = nodes.get(side.edge.last);
    369                                 lat = node.lat;
    370                                 lon = node.lon;
    371                                 it = side.edge.nodes.listIterator(side.edge.nodes.size());
    372                                 while (it.hasPrevious()) {
    373                                         llon = lon;
    374                                         llat = lat;
    375                                         node = nodes.get(it.previous());
    376                                         lat = node.lat;
    377                                         lon = node.lon;
    378                                         sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat));
    379                                 }
    380                                 llon = lon;
    381                                 llat = lat;
    382                                 node = nodes.get(side.edge.first);
    383                                 lat = node.lat;
    384                                 lon = node.lon;
    385                                 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat));
    386                         }
     450                BoundIterator it = new BoundIterator(bound);
     451                while (it.hasNext()) {
     452                        llon = lon;
     453                        llat = lat;
     454                        node = it.next();
     455                        lat = node.lat;
     456                        lon = node.lon;
     457                        sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat));
    387458                }
    388459                return sigma;
     
    392463                return (signedArea(bound) < 0);
    393464        }
    394        
     465
    395466        public double calcArea(Bound bound) {
    396           return Math.abs(signedArea(bound)) * 3444 * 3444 / 2.0;
     467                return Math.abs(signedArea(bound)) * 3444 * 3444 / 2.0;
    397468        }
    398469
    399470        public Snode findCentroid(Feature feature) {
    400     double lat, lon, slat, slon, sarc, llat, llon;
    401     lat = lon = slat = slon = sarc = llat = llon = 0;
     471                double lat, lon, slat, slon, sarc, llat, llon;
     472                lat = lon = slat = slon = sarc = llat = llon = 0;
    402473                switch (feature.flag) {
    403474                case POINT:
     
    405476                case LINE:
    406477                        Edge edge = edges.get(feature.refs);
    407                         llat = nodes.get(edge.first).lat;
    408                         llon = nodes.get(edge.first).lon;
    409                         for (long id : edge.nodes) {
    410                                 lat = nodes.get(id).lat;
    411                                 lon = nodes.get(id).lon;
    412                                 sarc += (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
     478                        EdgeIterator eit = new EdgeIterator(edge, true);
     479                        while (eit.hasNext()) {
     480                                Snode node = eit.next();
     481                                lat = node.lat;
     482                                lon = node.lon;
     483                                sarc += (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat)));
    413484                                llat = lat;
    414485                                llon = lon;
    415486                        }
    416                         lat = nodes.get(edge.last).lat;
    417                         lon = nodes.get(edge.last).lon;
    418                         sarc += (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
    419487                        double harc = sarc / 2;
    420488                        sarc = 0;
    421                         llat = nodes.get(edge.first).lat;
    422                         llon = nodes.get(edge.first).lon;
    423                         for (long id : edge.nodes) {
    424                                 lat = nodes.get(id).lat;
    425                                 lon = nodes.get(id).lon;
    426                                 sarc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
    427                                 if (sarc > harc) break;
     489                        eit = new EdgeIterator(edge, true);
     490                        while (eit.hasNext()) {
     491                                Snode node = eit.next();
     492                                lat = node.lat;
     493                                lon = node.lon;
     494                                sarc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat)));
     495                                if (sarc > harc)
     496                                        break;
    428497                                harc -= sarc;
    429498                                llat = lat;
    430499                                llon = lon;
    431                         }
    432                         if (sarc <= harc) {
    433                                 lat = nodes.get(edge.last).lat;
    434                                 lon = nodes.get(edge.last).lon;
    435                                 sarc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
    436500                        }
    437501                        double frac = harc / sarc;
     
    439503                case AREA:
    440504                        Bound bound = areas.get(feature.refs).get(0);
    441                         Snode node;
    442                         ListIterator<Long> it;
    443                         for (Side side : bound.sides) {
    444                                 if (side.forward) {
    445                                         node = nodes.get(side.edge.first);
    446                                         lat = node.lat;
    447                                         lon = node.lon;
    448                                         it = side.edge.nodes.listIterator();
    449                                         while (it.hasNext()) {
    450                                                 llon = lon;
    451                                                 llat = lat;
    452                                                 node = nodes.get(it.next());
    453                                                 lat = node.lat;
    454                                                 lon = node.lon;
    455                                                 double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
    456                                                 slat += (lat * arc);
    457                                                 slon += (lon * arc);
    458                                                 sarc += arc;
    459                                         }
    460                                         llon = lon;
    461                                         llat = lat;
    462                                         node = nodes.get(side.edge.last);
    463                                         lat = node.lat;
    464                                         lon = node.lon;
    465                                         double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
    466                                         slat += (lat * arc);
    467                                         slon += (lon * arc);
    468                                         sarc += arc;
    469                                 } else {
    470                                         node = nodes.get(side.edge.last);
    471                                         lat = node.lat;
    472                                         lon = node.lon;
    473                                         it = side.edge.nodes.listIterator(side.edge.nodes.size());
    474                                         while (it.hasPrevious()) {
    475                                                 llon = lon;
    476                                                 llat = lat;
    477                                                 node = nodes.get(it.previous());
    478                                                 lat = node.lat;
    479                                                 lon = node.lon;
    480                                                 double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
    481                                                 slat += (lat * arc);
    482                                                 slon += (lon * arc);
    483                                                 sarc += arc;
    484                                         }
    485                                         llon = lon;
    486                                         llat = lat;
    487                                         node = nodes.get(side.edge.first);
    488                                         lat = node.lat;
    489                                         lon = node.lon;
    490                                         double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
    491                                         slat += (lat * arc);
    492                                         slon += (lon * arc);
    493                                         sarc += arc;
    494                                 }
    495                         }
    496                         return new Snode((sarc > 0.0 ? slat/sarc : 0.0), (sarc > 0.0 ? slon/sarc : 0.0));
     505                        BoundIterator bit = new BoundIterator(bound);
     506                        while (bit.hasNext()) {
     507                                llon = lon;
     508                                llat = lat;
     509                                Snode node = bit.next();
     510                                lat = node.lat;
     511                                lon = node.lon;
     512                                double arc = (Math.acos(Math.cos(lon - llon) * Math.cos(lat - llat)));
     513                                slat += (lat * arc);
     514                                slon += (lon * arc);
     515                                sarc += arc;
     516                        }
     517                        return new Snode((sarc > 0.0 ? slat / sarc : 0.0), (sarc > 0.0 ? slon / sarc : 0.0));
    497518                }
    498519                return null;
    499520        }
    500        
     521
    501522}
Note: See TracChangeset for help on using the changeset viewer.