Changeset 30725 in osm


Ignore:
Timestamp:
2014-10-16T02:11:23+02:00 (10 years ago)
Author:
donvip
Message:

[josm_junctionchecking] code cleanup: replace tabs by spaces

Location:
applications/editors/josm/plugins/junctionchecking
Files:
1 added
1 deleted
41 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/ChannelDiGraphLayer.java

    r26509 r30725  
    3636public class ChannelDiGraphLayer extends Layer implements LayerChangeListener, PropertyChangeListener{
    3737
    38         private ChannelDiGraph digraph;
    39         private static final int POINTSIZE = 5;//original 3
    40         private static final float LINEWIDTH = 4; //original 2
    41         private final ColorSchemeXMLReader cXMLReader;
    42         private static final Shape ARROW_HEAD;
    43 
    44         static {
    45                 Polygon head = new Polygon();
    46                 head.addPoint(  0,  0);
    47                 head.addPoint(-15, +4);
    48                 head.addPoint(-15, -4);
    49                 ARROW_HEAD = head;
    50         }
    51 
    52         //die Farben für die zu zeichnenden Elemente
    53         private Color twoWayChannelColor;
    54         private Color oneWayChannelColor;
    55         private Color toNodeColor;
    56         private Color fromNodeColor;
    57         private Color nsccChannelColor;
    58         private Color selectedChannelColor;
    59         private Color partOfJunctionColor;
    60 
    61         public ChannelDiGraphLayer(ColorSchemeXMLReader cXMLReader){
    62                 super("ChannelDiGraphLayer");
    63                 MapView.addLayerChangeListener(this);
    64                 this.cXMLReader = cXMLReader;
    65                 initColors();
    66         }
    67 
    68         public void initColors() {
    69                 twoWayChannelColor = cXMLReader.getColor("TwoWayChannel");
    70                 oneWayChannelColor = cXMLReader.getColor("OneWayChannel");
    71                 toNodeColor = cXMLReader.getColor("ToNode");
    72                 fromNodeColor = cXMLReader.getColor("FromNode");
    73                 nsccChannelColor = cXMLReader.getColor("NotConnectedChannel");
    74                 selectedChannelColor = cXMLReader.getColor("selectedChannel");
    75                 partOfJunctionColor = cXMLReader.getColor("partOfJunction");
    76         }
    77 
    78         @Override
    79         public Icon getIcon() {
    80                 return ImageProvider.get("dialogs", "junctionchecker");
    81         }
    82 
    83         @Override
    84         public Object getInfoComponent() {
    85                 return null;
    86         }
    87 
    88         @Override
    89         public Action[] getMenuEntries() {
    90                 Action[] action = new Action[0];
    91                 return action;
    92         }
    93 
    94         @Override
    95         public String getToolTipText() {
    96                 return tr ("Channel-Digraph created from the active OSM-Layer");
    97         }
    98 
    99         @Override
    100         public boolean isMergable(Layer other) {
    101                 return false;
    102         }
    103 
    104         @Override
    105         public void mergeFrom(Layer from) {
    106         }
    107 
    108         @Override
    109         public void paint(Graphics2D g, MapView mv, Bounds box) {
    110                 if (digraph != null) {
    111                         for (int i = 0; i < digraph.getChannels().size(); i++) {
    112                                 paintChannel(digraph.getChannelAtPosition(i), g, mv);
    113                         }
    114                 }
    115         }
    116 
    117         private void paintChannel(final Channel channel, final Graphics2D g, final MapView mv) {
    118                 Point fromPoint = getCoord(channel.getFromNode(), mv);
    119                 g.setColor(fromNodeColor);
    120                 g.fillOval(fromPoint.x - POINTSIZE, fromPoint.y - POINTSIZE, 2 * POINTSIZE, 2 * POINTSIZE);
    121                 Point toPoint = getCoord(channel.getToNode(), mv);
    122                 g.setColor(toNodeColor);
    123                 g.fillOval(toPoint.x - POINTSIZE, toPoint.y - POINTSIZE, 2 * POINTSIZE, 2 * POINTSIZE);
    124                 Color c;
    125                 if (channel.isPartOfJunction()) {
    126                         c = partOfJunctionColor;
    127                 }
    128                 else if (channel.isSelected() == true) {
    129                         c = selectedChannelColor;
    130                 }
    131                 else if (channel.isStrongConnected() == false) {
    132                         c= nsccChannelColor;
    133                 }
    134                 else if (channel.getBackChannelID() != -100) {
    135                         c = twoWayChannelColor;
    136                 }
    137                 else {
    138                         c = oneWayChannelColor;
    139                 }
    140                 g.setColor(c);
    141                 g.setStroke(new BasicStroke(LINEWIDTH));
    142                 g.draw(new Line2D.Float(fromPoint.x, fromPoint.y, toPoint.x, toPoint.y));
    143                 double angle = angleFromXAxis(fromPoint, toPoint);
    144                 Shape head = ARROW_HEAD;
    145                 head = AffineTransform.getRotateInstance(angle).createTransformedShape(head);
    146                 head = AffineTransform.getTranslateInstance(toPoint.x, toPoint.y).createTransformedShape(head);
    147                 g.fill(head);
    148 
    149         }
    150 
    151         private Point getCoord(OSMNode node, MapView mv) {
    152                 return mv.getPoint(Main.getProjection().latlon2eastNorth(new LatLon(node.getLatitude(), node.getLongitude())));
    153         }
    154 
    155         /**
    156         * calculates the angle between the x axis and a vector given by two points
    157         * @param p1  first point for vector; != null
    158         * @param p2  second point for vector; != null
    159         * @return  angle in radians, in range [-Pi .. +Pi]
    160         */
    161         private double angleFromXAxis(Point p1, Point p2) {
    162                 assert p1 != null && p2 != null;
    163 
    164                 final float vecX = p2.x - p1.x;
    165                 final float vecY = p2.y - p1.y;
    166 
    167                 final float vecLength = (float)Math.sqrt(vecX*vecX + vecY*vecY);
    168 
    169                 final float dotProductVecAxis = vecX;
    170 
    171                 float angle = (float)Math.acos(dotProductVecAxis / vecLength);
    172 
    173                 if (p2.y < p1.y) {
    174                         angle = -angle;
    175                 }
    176 
    177                 assert -Math.PI*0.5 < angle && angle <= Math.PI*0.5;
    178 
    179                 return angle;
    180         }
    181 
    182 
    183         @Override
    184         public void visitBoundingBox(BoundingXYVisitor v) {
    185         }
    186 
    187         public void setDiGraph(ChannelDiGraph digraph) {
    188                 this.digraph = digraph;
    189         }
    190 
    191         public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    192 
    193         }
    194 
    195         public void layerAdded(Layer newLayer) {
    196         }
    197 
    198         public void layerRemoved(Layer oldLayer) {
    199                 if (oldLayer == this) {
    200                         MapView.removeLayerChangeListener(this);
    201                 }
    202         }
    203 
    204         public ChannelDiGraph getDigraph() {
    205                 return digraph;
    206         }
    207 
    208         public void setDigraph(ChannelDiGraph digraph) {
    209                 this.digraph = digraph;
    210         }
    211 
    212         public void propertyChange(PropertyChangeEvent evt) {
    213         }
     38    private ChannelDiGraph digraph;
     39    private static final int POINTSIZE = 5;//original 3
     40    private static final float LINEWIDTH = 4; //original 2
     41    private final ColorSchemeXMLReader cXMLReader;
     42    private static final Shape ARROW_HEAD;
     43
     44    static {
     45        Polygon head = new Polygon();
     46        head.addPoint(  0,  0);
     47        head.addPoint(-15, +4);
     48        head.addPoint(-15, -4);
     49        ARROW_HEAD = head;
     50    }
     51
     52    //die Farben für die zu zeichnenden Elemente
     53    private Color twoWayChannelColor;
     54    private Color oneWayChannelColor;
     55    private Color toNodeColor;
     56    private Color fromNodeColor;
     57    private Color nsccChannelColor;
     58    private Color selectedChannelColor;
     59    private Color partOfJunctionColor;
     60
     61    public ChannelDiGraphLayer(ColorSchemeXMLReader cXMLReader){
     62        super("ChannelDiGraphLayer");
     63        MapView.addLayerChangeListener(this);
     64        this.cXMLReader = cXMLReader;
     65        initColors();
     66    }
     67
     68    public void initColors() {
     69        twoWayChannelColor = cXMLReader.getColor("TwoWayChannel");
     70        oneWayChannelColor = cXMLReader.getColor("OneWayChannel");
     71        toNodeColor = cXMLReader.getColor("ToNode");
     72        fromNodeColor = cXMLReader.getColor("FromNode");
     73        nsccChannelColor = cXMLReader.getColor("NotConnectedChannel");
     74        selectedChannelColor = cXMLReader.getColor("selectedChannel");
     75        partOfJunctionColor = cXMLReader.getColor("partOfJunction");
     76    }
     77
     78    @Override
     79    public Icon getIcon() {
     80        return ImageProvider.get("dialogs", "junctionchecker");
     81    }
     82
     83    @Override
     84    public Object getInfoComponent() {
     85        return null;
     86    }
     87
     88    @Override
     89    public Action[] getMenuEntries() {
     90        Action[] action = new Action[0];
     91        return action;
     92    }
     93
     94    @Override
     95    public String getToolTipText() {
     96        return tr ("Channel-Digraph created from the active OSM-Layer");
     97    }
     98
     99    @Override
     100    public boolean isMergable(Layer other) {
     101        return false;
     102    }
     103
     104    @Override
     105    public void mergeFrom(Layer from) {
     106    }
     107
     108    @Override
     109    public void paint(Graphics2D g, MapView mv, Bounds box) {
     110        if (digraph != null) {
     111            for (int i = 0; i < digraph.getChannels().size(); i++) {
     112                paintChannel(digraph.getChannelAtPosition(i), g, mv);
     113            }
     114        }
     115    }
     116
     117    private void paintChannel(final Channel channel, final Graphics2D g, final MapView mv) {
     118        Point fromPoint = getCoord(channel.getFromNode(), mv);
     119        g.setColor(fromNodeColor);
     120        g.fillOval(fromPoint.x - POINTSIZE, fromPoint.y - POINTSIZE, 2 * POINTSIZE, 2 * POINTSIZE);
     121        Point toPoint = getCoord(channel.getToNode(), mv);
     122        g.setColor(toNodeColor);
     123        g.fillOval(toPoint.x - POINTSIZE, toPoint.y - POINTSIZE, 2 * POINTSIZE, 2 * POINTSIZE);
     124        Color c;
     125        if (channel.isPartOfJunction()) {
     126            c = partOfJunctionColor;
     127        }
     128        else if (channel.isSelected() == true) {
     129            c = selectedChannelColor;
     130        }
     131        else if (channel.isStrongConnected() == false) {
     132            c= nsccChannelColor;
     133        }
     134        else if (channel.getBackChannelID() != -100) {
     135            c = twoWayChannelColor;
     136        }
     137        else {
     138            c = oneWayChannelColor;
     139        }
     140        g.setColor(c);
     141        g.setStroke(new BasicStroke(LINEWIDTH));
     142        g.draw(new Line2D.Float(fromPoint.x, fromPoint.y, toPoint.x, toPoint.y));
     143        double angle = angleFromXAxis(fromPoint, toPoint);
     144        Shape head = ARROW_HEAD;
     145        head = AffineTransform.getRotateInstance(angle).createTransformedShape(head);
     146        head = AffineTransform.getTranslateInstance(toPoint.x, toPoint.y).createTransformedShape(head);
     147        g.fill(head);
     148
     149    }
     150
     151    private Point getCoord(OSMNode node, MapView mv) {
     152        return mv.getPoint(Main.getProjection().latlon2eastNorth(new LatLon(node.getLatitude(), node.getLongitude())));
     153    }
     154
     155    /**
     156    * calculates the angle between the x axis and a vector given by two points
     157    * @param p1  first point for vector; != null
     158    * @param p2  second point for vector; != null
     159    * @return  angle in radians, in range [-Pi .. +Pi]
     160    */
     161    private double angleFromXAxis(Point p1, Point p2) {
     162        assert p1 != null && p2 != null;
     163
     164        final float vecX = p2.x - p1.x;
     165        final float vecY = p2.y - p1.y;
     166
     167        final float vecLength = (float)Math.sqrt(vecX*vecX + vecY*vecY);
     168
     169        final float dotProductVecAxis = vecX;
     170
     171        float angle = (float)Math.acos(dotProductVecAxis / vecLength);
     172
     173        if (p2.y < p1.y) {
     174            angle = -angle;
     175        }
     176
     177        assert -Math.PI*0.5 < angle && angle <= Math.PI*0.5;
     178
     179        return angle;
     180    }
     181
     182
     183    @Override
     184    public void visitBoundingBox(BoundingXYVisitor v) {
     185    }
     186
     187    public void setDiGraph(ChannelDiGraph digraph) {
     188        this.digraph = digraph;
     189    }
     190
     191    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     192
     193    }
     194
     195    public void layerAdded(Layer newLayer) {
     196    }
     197
     198    public void layerRemoved(Layer oldLayer) {
     199        if (oldLayer == this) {
     200            MapView.removeLayerChangeListener(this);
     201        }
     202    }
     203
     204    public ChannelDiGraph getDigraph() {
     205        return digraph;
     206    }
     207
     208    public void setDigraph(ChannelDiGraph digraph) {
     209        this.digraph = digraph;
     210    }
     211
     212    public void propertyChange(PropertyChangeEvent evt) {
     213    }
    214214}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/DigraphCreationTask.java

    r30664 r30725  
    3232public class DigraphCreationTask extends PleaseWaitRunnable {
    3333
    34         private final JunctionCheckerPlugin plugin;
    35         private final boolean sealGraph;
    36         private boolean canceled;
    37         private final boolean calculateSCC;
     34    private final JunctionCheckerPlugin plugin;
     35    private final boolean sealGraph;
     36    private boolean canceled;
     37    private final boolean calculateSCC;
    3838
    39         private static final String WAYFILTERFILE = "/resources/xml/waysfilter.xml";
     39    private static final String WAYFILTERFILE = "/resources/xml/waysfilter.xml";
    4040
    41         public DigraphCreationTask(JunctionCheckerPlugin plugin, boolean sealGraph, boolean calculateSCC) {
    42                 super(tr ("Create Channel Digraph"), false);
    43                 this.plugin = plugin;
    44                 this.sealGraph = sealGraph;
    45                 this.calculateSCC = calculateSCC;
    46         }
     41    public DigraphCreationTask(JunctionCheckerPlugin plugin, boolean sealGraph, boolean calculateSCC) {
     42        super(tr ("Create Channel Digraph"), false);
     43        this.plugin = plugin;
     44        this.sealGraph = sealGraph;
     45        this.calculateSCC = calculateSCC;
     46    }
    4747
    48         @Override
    49         protected void cancel() {
    50                 canceled = true;
    51                 progressMonitor.cancel();
    52         }
     48    @Override
     49    protected void cancel() {
     50        canceled = true;
     51        progressMonitor.cancel();
     52    }
    5353
    54         @Override
    55         protected void finish() {
    56                 if (canceled) {
    57                         Main.main.removeLayer(plugin.getChannelDigraphLayer());
    58                         return;
    59                 }
    60         }
     54    @Override
     55    protected void finish() {
     56        if (canceled) {
     57            Main.main.removeLayer(plugin.getChannelDigraphLayer());
     58            return;
     59        }
     60    }
    6161
    62         @Override
    63         protected void realRun() throws SAXException, IOException,
    64         OsmTransferException {
    65                 //Prüfen, ob der ausgewählte Layer ein OSMDataLayer ist
    66                 if (Main.map == null
    67                                 || !Main.map.isVisible() || !(Main.map.mapView.getActiveLayer() instanceof OsmDataLayer)) {
    68                         JOptionPane.showMessageDialog(Main.parent, tr("this layer is no osm data layer"));
    69                         return;
    70                 }
    71                 Main.main.removeLayer(plugin.getChannelDigraphLayer());
    72                 int tickscounter = 4;
    73                 if (sealGraph) {
    74                         tickscounter++;
    75                 }
    76                 if (calculateSCC) {
    77                         tickscounter++;
    78                 }
    79                 getProgressMonitor().setTicksCount(tickscounter);
    80                 tickscounter = 1;
    81                 getProgressMonitor().subTask(tr ("Converting OSM graph into Channel Digraph"));
    82                 getProgressMonitor().setTicks(tickscounter++);
     62    @Override
     63    protected void realRun() throws SAXException, IOException,
     64    OsmTransferException {
     65        //Prüfen, ob der ausgewählte Layer ein OSMDataLayer ist
     66        if (Main.map == null
     67                || !Main.map.isVisible() || !(Main.map.mapView.getActiveLayer() instanceof OsmDataLayer)) {
     68            JOptionPane.showMessageDialog(Main.parent, tr("this layer is no osm data layer"));
     69            return;
     70        }
     71        Main.main.removeLayer(plugin.getChannelDigraphLayer());
     72        int tickscounter = 4;
     73        if (sealGraph) {
     74            tickscounter++;
     75        }
     76        if (calculateSCC) {
     77            tickscounter++;
     78        }
     79        getProgressMonitor().setTicksCount(tickscounter);
     80        tickscounter = 1;
     81        getProgressMonitor().subTask(tr ("Converting OSM graph into Channel Digraph"));
     82        getProgressMonitor().setTicks(tickscounter++);
    8383
    84                 OSMGraph graph = new OSMGraph();
    85                 //Der vom Benutzer in JOSM ausgewählte, zur Zeit aktive Layer wird der PLugin-OSM-Layer
    86                 plugin.setOsmlayer((OsmDataLayer)Main.map.mapView.getActiveLayer());
    87                 Iterator<Node> it = Main.main.getCurrentDataSet().getNodes().iterator();
    88                 while (it.hasNext()) {
    89                         graph.addNode(it.next());
    90                 }
     84        OSMGraph graph = new OSMGraph();
     85        //Der vom Benutzer in JOSM ausgewählte, zur Zeit aktive Layer wird der PLugin-OSM-Layer
     86        plugin.setOsmlayer((OsmDataLayer)Main.map.mapView.getActiveLayer());
     87        Iterator<Node> it = Main.main.getCurrentDataSet().getNodes().iterator();
     88        while (it.hasNext()) {
     89            graph.addNode(it.next());
     90        }
    9191
    92                 Iterator<Way> itway = Main.main.getCurrentDataSet().getWays()
    93                 .iterator();
    94                 while (itway.hasNext()) {
    95                         graph.addWay(itway.next());
    96                 }
    97                 Iterator<Relation> itrel = Main.main.getCurrentDataSet().getRelations()
    98                 .iterator();
    99                 while (itrel.hasNext()) {
    100                         graph.addRelation(itrel.next());
    101                 }
    102                 Iterator<DataSource> itdata = Main.main.getCurrentDataSet().dataSources.iterator();
    103                 while (itdata.hasNext()) {
    104                         Bounds b = itdata.next().bounds;
    105                         graph.setBbbottom(b.getMin().getY());
    106                         graph.setBbleft(b.getMin().getX());
    107                         graph.setBbright(b.getMax().getX());
    108                         graph.setBbtop(b.getMax().getY());
    109                 }
    110                 getProgressMonitor().subTask(tr("filtering ways"));
    111                 getProgressMonitor().setTicks(tickscounter++);
    112                 // Filter mit gewünschten Ways laden
    113                 XMLFilterReader reader = new XMLFilterReader(
    114                                 WAYFILTERFILE);
    115                 reader.parseXML();
    116                 // gewünschte Ways filtern
    117                 ExecuteFilter ef = new ExecuteFilter(reader.getFilters(), graph);
    118                 ef.filter();
    119                 getProgressMonitor().subTask(tr ("creating Channel-Digraph"));
    120                 getProgressMonitor().setTicks(tickscounter++);
    121                 // ChannelDiGraphen erzeugen
    122                 ChannelDigraphBuilder cdgb = new ChannelDigraphBuilder(ef.getOutgoinggraph());
    123                 cdgb.buildChannelDigraph();
    124                 StrongConnectednessCalculator scc = new StrongConnectednessCalculator(cdgb.getDigraph());
    125                 // DiGraph "versiegeln"
    126                 if (sealGraph) {
    127                         getProgressMonitor().subTask(tr ("sealing Digraph"));
    128                         getProgressMonitor().setTicks(tickscounter++);
    129                         DiGraphSealer sealer = new DiGraphSealer(cdgb.getDigraph(), cdgb
    130                                         .getNewid());
    131                         sealer.sealingGraph();
    132                 }
    133                 //Digraph starke Zusammenhangskomponenten berechnen
    134                 if (calculateSCC) {
    135                         getProgressMonitor().subTask(tr ("calculating Strong Connectedness"));
    136                         getProgressMonitor().setTicks(tickscounter++);
    137                         scc.calculateSCC();
    138                 }
    139                 getProgressMonitor().subTask(tr ("creating DigraphLayer"));
    140                 getProgressMonitor().setTicks(tickscounter++);
    141                 plugin.setChannelDigraph(cdgb.getDigraph());
    142                 plugin.getOsmlayer().setBackgroundLayer(true);
    143                 plugin.getChannelDigraphLayer().setDigraph(cdgb.getDigraph());
    144                 plugin.setChannelDigraph(cdgb.getDigraph());
    145                 plugin.getJcMapMode().setDigraph(cdgb.getDigraph());
    146                 plugin.setNormalMapMode(Main.map.mapMode);
    147                 Main.map.selectMapMode(plugin.getJcMapMode());
    148                 Main.main.addLayer(plugin.getChannelDigraphLayer());
    149                 Main.map.mapView.setActiveLayer(plugin.getChannelDigraphLayer());
    150         }
     92        Iterator<Way> itway = Main.main.getCurrentDataSet().getWays()
     93        .iterator();
     94        while (itway.hasNext()) {
     95            graph.addWay(itway.next());
     96        }
     97        Iterator<Relation> itrel = Main.main.getCurrentDataSet().getRelations()
     98        .iterator();
     99        while (itrel.hasNext()) {
     100            graph.addRelation(itrel.next());
     101        }
     102        Iterator<DataSource> itdata = Main.main.getCurrentDataSet().dataSources.iterator();
     103        while (itdata.hasNext()) {
     104            Bounds b = itdata.next().bounds;
     105            graph.setBbbottom(b.getMin().getY());
     106            graph.setBbleft(b.getMin().getX());
     107            graph.setBbright(b.getMax().getX());
     108            graph.setBbtop(b.getMax().getY());
     109        }
     110        getProgressMonitor().subTask(tr("filtering ways"));
     111        getProgressMonitor().setTicks(tickscounter++);
     112        // Filter mit gewünschten Ways laden
     113        XMLFilterReader reader = new XMLFilterReader(
     114                WAYFILTERFILE);
     115        reader.parseXML();
     116        // gewünschte Ways filtern
     117        ExecuteFilter ef = new ExecuteFilter(reader.getFilters(), graph);
     118        ef.filter();
     119        getProgressMonitor().subTask(tr ("creating Channel-Digraph"));
     120        getProgressMonitor().setTicks(tickscounter++);
     121        // ChannelDiGraphen erzeugen
     122        ChannelDigraphBuilder cdgb = new ChannelDigraphBuilder(ef.getOutgoinggraph());
     123        cdgb.buildChannelDigraph();
     124        StrongConnectednessCalculator scc = new StrongConnectednessCalculator(cdgb.getDigraph());
     125        // DiGraph "versiegeln"
     126        if (sealGraph) {
     127            getProgressMonitor().subTask(tr ("sealing Digraph"));
     128            getProgressMonitor().setTicks(tickscounter++);
     129            DiGraphSealer sealer = new DiGraphSealer(cdgb.getDigraph(), cdgb
     130                    .getNewid());
     131            sealer.sealingGraph();
     132        }
     133        //Digraph starke Zusammenhangskomponenten berechnen
     134        if (calculateSCC) {
     135            getProgressMonitor().subTask(tr ("calculating Strong Connectedness"));
     136            getProgressMonitor().setTicks(tickscounter++);
     137            scc.calculateSCC();
     138        }
     139        getProgressMonitor().subTask(tr ("creating DigraphLayer"));
     140        getProgressMonitor().setTicks(tickscounter++);
     141        plugin.setChannelDigraph(cdgb.getDigraph());
     142        plugin.getOsmlayer().setBackgroundLayer(true);
     143        plugin.getChannelDigraphLayer().setDigraph(cdgb.getDigraph());
     144        plugin.setChannelDigraph(cdgb.getDigraph());
     145        plugin.getJcMapMode().setDigraph(cdgb.getDigraph());
     146        plugin.setNormalMapMode(Main.map.mapMode);
     147        Main.map.selectMapMode(plugin.getJcMapMode());
     148        Main.main.addLayer(plugin.getChannelDigraphLayer());
     149        Main.map.mapView.setActiveLayer(plugin.getChannelDigraphLayer());
     150    }
    151151}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/JunctionCheckDialog.java

    r30205 r30725  
    3333public class JunctionCheckDialog extends ToggleDialog implements SelectionChangedListener{
    3434
    35         private final JunctionCheckerPlugin plugin;
    36         /** Serializable ID */
    37         private static final long serialVersionUID = 2952292777351992696L;
    38         private final SideButton checkJunctionButton;
    39         private final SideButton createDigraphButton;
    40         private final SideButton searchJunctionButton;
    41         private final JCheckBox digraphsealcb;
    42         private final JCheckBox produceRelation;
    43         private final JCheckBox sccCB;
    44         private final JSpinner nways;
    45         private final SpinnerNumberModel smodel;
    46         private final JLabel nwayslabel;
     35    private final JunctionCheckerPlugin plugin;
     36    /** Serializable ID */
     37    private static final long serialVersionUID = 2952292777351992696L;
     38    private final SideButton checkJunctionButton;
     39    private final SideButton createDigraphButton;
     40    private final SideButton searchJunctionButton;
     41    private final JCheckBox digraphsealcb;
     42    private final JCheckBox produceRelation;
     43    private final JCheckBox sccCB;
     44    private final JSpinner nways;
     45    private final SpinnerNumberModel smodel;
     46    private final JLabel nwayslabel;
    4747
    48         public JunctionCheckDialog(JunctionCheckerPlugin junctionCheckerGuiPlugin) {
    49                 super(tr("JunctionChecking"), "junctionchecker", tr("Open the junctionchecking window."),
    50                                 Shortcut.registerShortcut("subwindow:junctionchecker", tr("Toggle: {0}", tr("junctions")),
    51                                                 KeyEvent.VK_J, Shortcut.ALT_SHIFT), 150);
    52                 plugin = junctionCheckerGuiPlugin;
    53                 //das Digraph Create Panel
    54                 JPanel digraphPanel = new JPanel(new GridLayout(1, 2));
    55                 digraphPanel.setBorder(new TitledBorder(tr("Channel-Digraph creation")));
    56                 digraphsealcb = new JCheckBox(tr("seal Channel Digraph"));
    57                 digraphsealcb.setSelected(false);
    58                 //digraphPanel.add(digraphsealcb);
     48    public JunctionCheckDialog(JunctionCheckerPlugin junctionCheckerGuiPlugin) {
     49        super(tr("JunctionChecking"), "junctionchecker", tr("Open the junctionchecking window."),
     50                Shortcut.registerShortcut("subwindow:junctionchecker", tr("Toggle: {0}", tr("junctions")),
     51                        KeyEvent.VK_J, Shortcut.ALT_SHIFT), 150);
     52        plugin = junctionCheckerGuiPlugin;
     53        //das Digraph Create Panel
     54        JPanel digraphPanel = new JPanel(new GridLayout(1, 2));
     55        digraphPanel.setBorder(new TitledBorder(tr("Channel-Digraph creation")));
     56        digraphsealcb = new JCheckBox(tr("seal Channel Digraph"));
     57        digraphsealcb.setSelected(false);
     58        //digraphPanel.add(digraphsealcb);
    5959
    60                 sccCB = new JCheckBox(tr("calculate strong connected channels"));
    61                 sccCB.setSelected(true);
    62                 digraphPanel.add(sccCB);
     60        sccCB = new JCheckBox(tr("calculate strong connected channels"));
     61        sccCB.setSelected(true);
     62        digraphPanel.add(sccCB);
    6363
    64                 //das Panel zum Junctionchecken
    65                 JPanel jcPanel = new JPanel(new GridLayout(4, 1));
    66                 jcPanel.setBorder(new TitledBorder(tr("Junctionchecking/junctions searching")));
     64        //das Panel zum Junctionchecken
     65        JPanel jcPanel = new JPanel(new GridLayout(4, 1));
     66        jcPanel.setBorder(new TitledBorder(tr("Junctionchecking/junctions searching")));
    6767
    68                 //Elemente für Grad-Auswahl der Kreuzung
    69                 JPanel spinnerpanel = new JPanel(new GridLayout(1,2));
    70                 smodel = new SpinnerNumberModel(3, 1, 20, 1);
    71                 nways = new JSpinner(smodel);
    72                 nwayslabel = new JLabel(tr("order of junction (n):"));
    73                 nwayslabel.setEnabled(false);
    74                 spinnerpanel.add(nwayslabel);
    75                 spinnerpanel.add(nways);
     68        //Elemente für Grad-Auswahl der Kreuzung
     69        JPanel spinnerpanel = new JPanel(new GridLayout(1,2));
     70        smodel = new SpinnerNumberModel(3, 1, 20, 1);
     71        nways = new JSpinner(smodel);
     72        nwayslabel = new JLabel(tr("order of junction (n):"));
     73        nwayslabel.setEnabled(false);
     74        spinnerpanel.add(nwayslabel);
     75        spinnerpanel.add(nways);
    7676
    77                 //Elemente zur OSM-Relationen-Erzeugung
    78                 produceRelation = new JCheckBox(tr("produce OSM-Relations: junction"));
    79                 produceRelation.setToolTipText(tr("if enabled the plugin produces osm-relations from the junction subgraphs"));
    80                 produceRelation.setSelected(true);
    81                 produceRelation.setEnabled(false);
    82                 jcPanel.add(produceRelation);
    83                 jcPanel.add(spinnerpanel);
     77        //Elemente zur OSM-Relationen-Erzeugung
     78        produceRelation = new JCheckBox(tr("produce OSM-Relations: junction"));
     79        produceRelation.setToolTipText(tr("if enabled the plugin produces osm-relations from the junction subgraphs"));
     80        produceRelation.setSelected(true);
     81        produceRelation.setEnabled(false);
     82        jcPanel.add(produceRelation);
     83        jcPanel.add(spinnerpanel);
    8484
    85                 JPanel centerPanel = new JPanel();
    86                 centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
    87                 centerPanel.add(digraphPanel);
    88                 centerPanel.add(jcPanel);
     85        JPanel centerPanel = new JPanel();
     86        centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
     87        centerPanel.add(digraphPanel);
     88        centerPanel.add(jcPanel);
    8989
    90                 // ButtonPanel
    91                 createDigraphButton = new SideButton(new AbstractAction() {
    92                         {
    93                                 putValue(NAME, marktr("Create"));
    94                                 putValue(SHORT_DESCRIPTION, tr("create the channel digraph"));
    95                                 putValue(SMALL_ICON, ImageProvider.get("dialogs", "digraphcreation"));
    96                         }
    97                         @Override
    98                         public void actionPerformed(ActionEvent e) {
    99                                         DigraphCreationTask dct = new DigraphCreationTask(plugin, digraphsealcb.isSelected(), sccCB.isSelected());
    100                                         Main.worker.submit(dct);
    101                                         setActivateJunctionCheckOrSearch(true);
    102                         }
    103                 });
    104                 checkJunctionButton = new SideButton(new AbstractAction() {
    105                         {
    106                                 putValue(NAME, marktr("Check "));
    107                                 putValue(SHORT_DESCRIPTION, tr("check the subust for junction properties"));
    108                                 putValue(SMALL_ICON, ImageProvider.get("dialogs", "junctioncheck"));
    109                         }
    110                         @Override
    111                         public void actionPerformed(ActionEvent e) {
    112                                 PrepareJunctionCheckorSearch pjc = new PrepareJunctionCheckorSearch(plugin, smodel.getNumber().intValue(), produceRelation.isSelected());
    113                                 pjc.prepareJunctionCheck();
    114                         }
    115                 });
    116                 checkJunctionButton.setEnabled(false);
    117                 searchJunctionButton = new SideButton(new AbstractAction() {
    118                         {
    119                                 putValue(NAME, marktr("Search "));
    120                                 putValue(SHORT_DESCRIPTION, tr("search for junctions in the channel subset"));
    121                                 putValue(SMALL_ICON, ImageProvider.get("dialogs", "junctionsearch"));
    122                         }
    123                         @Override
    124                         public void actionPerformed(ActionEvent e) {
    125                                 PrepareJunctionCheckorSearch pjc = new PrepareJunctionCheckorSearch(plugin, smodel.getNumber().intValue(), produceRelation.isSelected());
    126                                 pjc.prepareJunctionSearch();
    127                         }
    128                 });
    129                 searchJunctionButton.setEnabled(false);
     90        // ButtonPanel
     91        createDigraphButton = new SideButton(new AbstractAction() {
     92            {
     93                putValue(NAME, marktr("Create"));
     94                putValue(SHORT_DESCRIPTION, tr("create the channel digraph"));
     95                putValue(SMALL_ICON, ImageProvider.get("dialogs", "digraphcreation"));
     96            }
     97            @Override
     98            public void actionPerformed(ActionEvent e) {
     99                    DigraphCreationTask dct = new DigraphCreationTask(plugin, digraphsealcb.isSelected(), sccCB.isSelected());
     100                    Main.worker.submit(dct);
     101                    setActivateJunctionCheckOrSearch(true);
     102            }
     103        });
     104        checkJunctionButton = new SideButton(new AbstractAction() {
     105            {
     106                putValue(NAME, marktr("Check "));
     107                putValue(SHORT_DESCRIPTION, tr("check the subust for junction properties"));
     108                putValue(SMALL_ICON, ImageProvider.get("dialogs", "junctioncheck"));
     109            }
     110            @Override
     111            public void actionPerformed(ActionEvent e) {
     112                PrepareJunctionCheckorSearch pjc = new PrepareJunctionCheckorSearch(plugin, smodel.getNumber().intValue(), produceRelation.isSelected());
     113                pjc.prepareJunctionCheck();
     114            }
     115        });
     116        checkJunctionButton.setEnabled(false);
     117        searchJunctionButton = new SideButton(new AbstractAction() {
     118            {
     119                putValue(NAME, marktr("Search "));
     120                putValue(SHORT_DESCRIPTION, tr("search for junctions in the channel subset"));
     121                putValue(SMALL_ICON, ImageProvider.get("dialogs", "junctionsearch"));
     122            }
     123            @Override
     124            public void actionPerformed(ActionEvent e) {
     125                PrepareJunctionCheckorSearch pjc = new PrepareJunctionCheckorSearch(plugin, smodel.getNumber().intValue(), produceRelation.isSelected());
     126                pjc.prepareJunctionSearch();
     127            }
     128        });
     129        searchJunctionButton.setEnabled(false);
    130130
    131                 createLayout(centerPanel, false, Arrays.asList(new SideButton[] {
    132                         createDigraphButton, checkJunctionButton, searchJunctionButton
    133                 }));
    134         }
     131        createLayout(centerPanel, false, Arrays.asList(new SideButton[] {
     132            createDigraphButton, checkJunctionButton, searchJunctionButton
     133        }));
     134    }
    135135
    136136
    137         /**
    138         * (de)aktiviert Buttons zum JunctionCheck oder Suche
    139         * @param activate
    140         */
    141         public void setActivateJunctionCheckOrSearch(boolean activate) {
    142                 checkJunctionButton.setEnabled(activate);
    143                 nways.setEnabled(activate);
    144                 nwayslabel.setEnabled(activate);
    145                 produceRelation.setEnabled(activate);
    146                 searchJunctionButton.setEnabled(activate);
    147         }
     137    /**
     138    * (de)aktiviert Buttons zum JunctionCheck oder Suche
     139    * @param activate
     140    */
     141    public void setActivateJunctionCheckOrSearch(boolean activate) {
     142        checkJunctionButton.setEnabled(activate);
     143        nways.setEnabled(activate);
     144        nwayslabel.setEnabled(activate);
     145        produceRelation.setEnabled(activate);
     146        searchJunctionButton.setEnabled(activate);
     147    }
    148148
    149         /**
    150         * (de)aktiviert Buttons zur Channel Digraph Erstellung
    151         * @param activate
    152         */
    153         public void setActivateCreateDigraph(final boolean activate) {
    154                 GuiHelper.runInEDTAndWait(new Runnable() {
     149    /**
     150    * (de)aktiviert Buttons zur Channel Digraph Erstellung
     151    * @param activate
     152    */
     153    public void setActivateCreateDigraph(final boolean activate) {
     154        GuiHelper.runInEDTAndWait(new Runnable() {
    155155            @Override
    156156            public void run() {
     
    160160            }
    161161        });
    162         }
     162    }
    163163
    164         @Override
    165         public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
     164    @Override
     165    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    166166
    167         }
     167    }
    168168}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/JunctionCheckTask.java

    r25501 r30725  
    2323public class JunctionCheckTask extends PleaseWaitRunnable{
    2424
    25         private final JunctionChecker jc;
    26         private final JunctionCheckerPlugin plugin;
    27         private final int n; //Grad der Kreuzung
    28         private final HashSet<Channel> subset; //Teilmge der zu prüfenden Channel
    29         private final boolean producerelation;
    30         private boolean canceled;
     25    private final JunctionChecker jc;
     26    private final JunctionCheckerPlugin plugin;
     27    private final int n; //Grad der Kreuzung
     28    private final HashSet<Channel> subset; //Teilmge der zu prüfenden Channel
     29    private final boolean producerelation;
     30    private boolean canceled;
    3131
    32         public JunctionCheckTask(JunctionCheckerPlugin plugin, int n, HashSet<Channel> subset, boolean produceRelation) {
    33                 super("JunctionCheck", false);
    34                 this.plugin = plugin;
    35                 this.n = n;
    36                 this.subset = subset;
    37                 this.producerelation = produceRelation;
    38                 jc = new JunctionChecker(plugin.getChannelDigraph() , n);
    39         }
     32    public JunctionCheckTask(JunctionCheckerPlugin plugin, int n, HashSet<Channel> subset, boolean produceRelation) {
     33        super("JunctionCheck", false);
     34        this.plugin = plugin;
     35        this.n = n;
     36        this.subset = subset;
     37        this.producerelation = produceRelation;
     38        jc = new JunctionChecker(plugin.getChannelDigraph() , n);
     39    }
    4040
    41         @Override
    42         protected void cancel() {
    43                 canceled = true;
    44                 progressMonitor.cancel();
    45         }
     41    @Override
     42    protected void cancel() {
     43        canceled = true;
     44        progressMonitor.cancel();
     45    }
    4646
    47         @Override
    48         protected void finish() {
    49                 if (canceled) {
    50                         return;
    51                 }
    52                 progressMonitor.finishTask();
    53                 if (jc.isSmallerJunction() ) {
    54                         showjunction();
    55                         JOptionPane.showMessageDialog(Main.parent, tr ("The marked channels contains a junctioncandidate (white). To test this candidat mark these channel and press the \"Check\" button again."));
    56                 }
    57                 else if (jc.getCheck()) {
    58                         showjunction();
    59                         JOptionPane.showMessageDialog(Main.parent, tr ("The marked channels are a {0}-ways junction", n));
    60                         plugin.getChannelDigraph().ereaseJunctioncandidate();
    61                         for (int i = 0; i < jc.getSubJunction().size(); i++) {
    62                                 plugin.getChannelDigraph().addJunctioncandidateChannel(jc.getSubJunction().get(i));
    63                         }
    64                         if (producerelation) {
    65                                 this.plugin.getRelationProducer().produceRelation(subset, n);
    66                         }
    67                 }
    68                 else if (!jc.getCheck()) {
    69                         JOptionPane.showMessageDialog(Main.parent, tr ("The marked channels are not a junction:") + jc.getJCheckResult());
     47    @Override
     48    protected void finish() {
     49        if (canceled) {
     50            return;
     51        }
     52        progressMonitor.finishTask();
     53        if (jc.isSmallerJunction() ) {
     54            showjunction();
     55            JOptionPane.showMessageDialog(Main.parent, tr ("The marked channels contains a junctioncandidate (white). To test this candidat mark these channel and press the \"Check\" button again."));
     56        }
     57        else if (jc.getCheck()) {
     58            showjunction();
     59            JOptionPane.showMessageDialog(Main.parent, tr ("The marked channels are a {0}-ways junction", n));
     60            plugin.getChannelDigraph().ereaseJunctioncandidate();
     61            for (int i = 0; i < jc.getSubJunction().size(); i++) {
     62                plugin.getChannelDigraph().addJunctioncandidateChannel(jc.getSubJunction().get(i));
     63            }
     64            if (producerelation) {
     65                this.plugin.getRelationProducer().produceRelation(subset, n);
     66            }
     67        }
     68        else if (!jc.getCheck()) {
     69            JOptionPane.showMessageDialog(Main.parent, tr ("The marked channels are not a junction:") + jc.getJCheckResult());
    7070
    71                 }
     71        }
    7272
    73         }
     73    }
    7474
    75         @Override
    76         protected void realRun() throws SAXException, IOException,
    77         OsmTransferException {
    78                 jc.checkjunctions(new ArrayList<Channel>(subset), getProgressMonitor());
    79         }
     75    @Override
     76    protected void realRun() throws SAXException, IOException,
     77    OsmTransferException {
     78        jc.checkjunctions(new ArrayList<Channel>(subset), getProgressMonitor());
     79    }
    8080
    81         public JunctionChecker getJunctionChecker() {
    82                 return jc;
    83         }
     81    public JunctionChecker getJunctionChecker() {
     82        return jc;
     83    }
    8484
    85         /**
    86         * zeigt den gefundenen Kreuzungskandidatena an
    87         */
    88         private void showjunction() {
    89                 plugin.getChannelDigraph().ereaseJunctioncandidate();
    90                 for (int i = 0; i < jc.getSubJunction().size(); i++) {
    91                         plugin.getChannelDigraph().addJunctioncandidateChannel(jc.getSubJunction().get(i));
    92                 }
    93                 Main.map.mapView.setActiveLayer(plugin.getChannelDigraphLayer());
    94         }
     85    /**
     86    * zeigt den gefundenen Kreuzungskandidatena an
     87    */
     88    private void showjunction() {
     89        plugin.getChannelDigraph().ereaseJunctioncandidate();
     90        for (int i = 0; i < jc.getSubJunction().size(); i++) {
     91            plugin.getChannelDigraph().addJunctioncandidateChannel(jc.getSubJunction().get(i));
     92        }
     93        Main.map.mapView.setActiveLayer(plugin.getChannelDigraphLayer());
     94    }
    9595}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/JunctionCheckerMapMode.java

    r29595 r30725  
    2424public class JunctionCheckerMapMode extends MapMode implements LayerChangeListener{
    2525
    26         MapFrame frame;
    27         Point pointPressed;
    28         ChannelDiGraphLayer layer;
    29         Rectangle oldRect;
    30         ChannelDiGraph digraph;
     26    MapFrame frame;
     27    Point pointPressed;
     28    ChannelDiGraphLayer layer;
     29    Rectangle oldRect;
     30    ChannelDiGraph digraph;
    3131
    32         private static final long serialVersionUID = 3442408951505263850L;
     32    private static final long serialVersionUID = 3442408951505263850L;
    3333
    34         public JunctionCheckerMapMode(MapFrame mapFrame, String name, String desc) {
    35                 super(name, "junctionchecker.png", desc, mapFrame, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    36         }
     34    public JunctionCheckerMapMode(MapFrame mapFrame, String name, String desc) {
     35        super(name, "junctionchecker.png", desc, mapFrame, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
     36    }
    3737
    38         @Override public void enterMode() {
    39                 super.enterMode();
    40                 Main.map.mapView.addMouseListener(this);
    41                 Main.map.mapView.addMouseMotionListener(this);
    42                 MapView.addLayerChangeListener(this);
    43         }
     38    @Override public void enterMode() {
     39        super.enterMode();
     40        Main.map.mapView.addMouseListener(this);
     41        Main.map.mapView.addMouseMotionListener(this);
     42        MapView.addLayerChangeListener(this);
     43    }
    4444
    45         @Override public void exitMode() {
    46                 super.exitMode();
    47                 Main.map.mapView.removeMouseListener(this);
    48                 Main.map.mapView.removeMouseMotionListener(this);
    49         }
     45    @Override public void exitMode() {
     46        super.exitMode();
     47        Main.map.mapView.removeMouseListener(this);
     48        Main.map.mapView.removeMouseMotionListener(this);
     49    }
    5050
    5151
    52         public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    53                 if (newLayer instanceof ChannelDiGraphLayer) {
    54                         layer = (ChannelDiGraphLayer) newLayer;
    55                 }
    56         }
     52    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     53        if (newLayer instanceof ChannelDiGraphLayer) {
     54            layer = (ChannelDiGraphLayer) newLayer;
     55        }
     56    }
    5757
    58         public void layerAdded(Layer newLayer) {
    59         }
     58    public void layerAdded(Layer newLayer) {
     59    }
    6060
    61         public void layerRemoved(Layer oldLayer) {
    62         }
     61    public void layerRemoved(Layer oldLayer) {
     62    }
    6363
    6464
    65         public void setFrame(MapFrame newFrame) {
    66                 frame = newFrame;
    67         }
     65    public void setFrame(MapFrame newFrame) {
     66        frame = newFrame;
     67    }
    6868
    69         @Override public void mousePressed(MouseEvent e) {
    70                 pointPressed = new Point(e.getPoint());
    71         }
     69    @Override public void mousePressed(MouseEvent e) {
     70        pointPressed = new Point(e.getPoint());
     71    }
    7272
    7373
    74         @Override public void mouseDragged(MouseEvent e) {
    75                 if ( (e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) ==  InputEvent.BUTTON1_DOWN_MASK) {
    76                         //if button1 is hold, draw the rectangle.
    77                         paintRect(pointPressed, e.getPoint());
    78                 }
    79         }
     74    @Override public void mouseDragged(MouseEvent e) {
     75        if ( (e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) ==  InputEvent.BUTTON1_DOWN_MASK) {
     76            //if button1 is hold, draw the rectangle.
     77            paintRect(pointPressed, e.getPoint());
     78        }
     79    }
    8080
    81         @Override public void mouseReleased(MouseEvent e) {
    82                 if (e.getButton() != MouseEvent.BUTTON1) {
    83                         return;
    84                 }
    85                 requestFocusInMapView();
    86                 digraph.ereaseJunctioncandidate();//um zu verhindern, dass gefundene Kreuzungen/Kandidaten weiterhin weiß gezeichnet werden
    87                 Point pointReleased = e.getPoint();
     81    @Override public void mouseReleased(MouseEvent e) {
     82        if (e.getButton() != MouseEvent.BUTTON1) {
     83            return;
     84        }
     85        requestFocusInMapView();
     86        digraph.ereaseJunctioncandidate();//um zu verhindern, dass gefundene Kreuzungen/Kandidaten weiterhin weiß gezeichnet werden
     87        Point pointReleased = e.getPoint();
    8888
    89                 Rectangle r = createRect(pointReleased, pointPressed);
    90                 //boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
    91                 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
    92                 //boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;
    93                 if (shift == false) {
    94                         digraph.ereaseSelectedChannels();
    95                 }
    96                 //go through nodes and mark the ones in the selection rect as deleted
    97                 if (layer != null && digraph != null) {
    98                         LatLon lefttop = Main.map.mapView.getLatLon(r.x + r.width, r.y + r.height);
    99                         LatLon rightbottom = Main.map.mapView.getLatLon(r.x, r.y);
    100                         digraph.detectSelectedChannels(rightbottom.lon(), rightbottom.lat(), lefttop.lon(), lefttop.lat());
    101                 }
    102                 oldRect = null;
    103                 Main.map.mapView.repaint();
     89        Rectangle r = createRect(pointReleased, pointPressed);
     90        //boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
     91        boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
     92        //boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;
     93        if (shift == false) {
     94            digraph.ereaseSelectedChannels();
     95        }
     96        //go through nodes and mark the ones in the selection rect as deleted
     97        if (layer != null && digraph != null) {
     98            LatLon lefttop = Main.map.mapView.getLatLon(r.x + r.width, r.y + r.height);
     99            LatLon rightbottom = Main.map.mapView.getLatLon(r.x, r.y);
     100            digraph.detectSelectedChannels(rightbottom.lon(), rightbottom.lat(), lefttop.lon(), lefttop.lat());
     101        }
     102        oldRect = null;
     103        Main.map.mapView.repaint();
    104104
    105         }
     105    }
    106106
    107         /**
    108         * create rectangle out of two given corners
    109         */
    110         public Rectangle createRect(Point p1, Point p2) {
    111                 int x,y,w,h;
    112                 if (p1.x == p2.x && p1.y == p2.y) {
    113                         //if p1 and p2 same points draw a small rectangle around them
    114                         x = p1.x -1;
    115                         y = p1.y -1;
    116                         w = 3;
    117                         h = 3;
    118                 } else {
    119                         if (p1.x < p2.x){
    120                                 x = p1.x;
    121                                 w = p2.x-p1.x;
    122                         } else {
    123                                 x = p2.x;
    124                                 w = p1.x-p2.x;
    125                         }
    126                         if (p1.y < p2.y) {
    127                                 y = p1.y;
    128                                 h = p2.y-p1.y;
    129                         } else {
    130                                 y = p2.y;
    131                                 h = p1.y-p2.y;
    132                         }
    133                 }
    134                 return new Rectangle(x,y,w,h);
    135         }
     107    /**
     108    * create rectangle out of two given corners
     109    */
     110    public Rectangle createRect(Point p1, Point p2) {
     111        int x,y,w,h;
     112        if (p1.x == p2.x && p1.y == p2.y) {
     113            //if p1 and p2 same points draw a small rectangle around them
     114            x = p1.x -1;
     115            y = p1.y -1;
     116            w = 3;
     117            h = 3;
     118        } else {
     119            if (p1.x < p2.x){
     120                x = p1.x;
     121                w = p2.x-p1.x;
     122            } else {
     123                x = p2.x;
     124                w = p1.x-p2.x;
     125            }
     126            if (p1.y < p2.y) {
     127                y = p1.y;
     128                h = p2.y-p1.y;
     129            } else {
     130                y = p2.y;
     131                h = p1.y-p2.y;
     132            }
     133        }
     134        return new Rectangle(x,y,w,h);
     135    }
    136136
    137         /**
    138         * Draw a selection rectangle on screen.
    139         */
    140         private void paintRect(Point p1, Point p2) {
    141                 if (frame != null) {
    142                         Graphics g = frame.getGraphics();
    143        
    144                         Rectangle r = oldRect;
    145                         if (r != null) {
    146                                 //overwrite old rct
    147                                 g.setXORMode(Color.BLACK);
    148                                 g.setColor(Color.WHITE);
    149                                 g.drawRect(r.x,r.y,r.width,r.height);
    150                         }
    151        
    152                         g.setXORMode(Color.BLACK);
    153                         g.setColor(Color.WHITE);
    154                         r = createRect(p1,p2);
    155                         g.drawRect(r.x,r.y,r.width,r.height);
    156                         oldRect = r;
    157                 }
    158         }
     137    /**
     138    * Draw a selection rectangle on screen.
     139    */
     140    private void paintRect(Point p1, Point p2) {
     141        if (frame != null) {
     142            Graphics g = frame.getGraphics();
     143   
     144            Rectangle r = oldRect;
     145            if (r != null) {
     146                //overwrite old rct
     147                g.setXORMode(Color.BLACK);
     148                g.setColor(Color.WHITE);
     149                g.drawRect(r.x,r.y,r.width,r.height);
     150            }
     151   
     152            g.setXORMode(Color.BLACK);
     153            g.setColor(Color.WHITE);
     154            r = createRect(p1,p2);
     155            g.drawRect(r.x,r.y,r.width,r.height);
     156            oldRect = r;
     157        }
     158    }
    159159
    160         public ChannelDiGraph getDigraph() {
    161                 return digraph;
    162         }
     160    public ChannelDiGraph getDigraph() {
     161        return digraph;
     162    }
    163163
    164         public void setDigraph(ChannelDiGraph digraph) {
    165                 this.digraph = digraph;
    166         }
     164    public void setDigraph(ChannelDiGraph digraph) {
     165        this.digraph = digraph;
     166    }
    167167
    168         @Override
    169         public void destroy() {
    170                 super.destroy();
    171                 MapView.removeLayerChangeListener(this);
    172         }
     168    @Override
     169    public void destroy() {
     170        super.destroy();
     171        MapView.removeLayerChangeListener(this);
     172    }
    173173}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/JunctionSearchTask.java

    r26337 r30725  
    2222public class JunctionSearchTask extends PleaseWaitRunnable{
    2323
    24         private final JunctionChecker jc;
    25         private final JunctionCheckerPlugin plugin;
    26         private final int n;
    27         private final HashSet<Channel> subset;
    28         private final boolean produceRelation;
    29         private boolean canceled;
     24    private final JunctionChecker jc;
     25    private final JunctionCheckerPlugin plugin;
     26    private final int n;
     27    private final HashSet<Channel> subset;
     28    private final boolean produceRelation;
     29    private boolean canceled;
    3030
    31         public JunctionSearchTask(JunctionCheckerPlugin plugin, int n,
    32                         HashSet<Channel> subset,
    33                         boolean produceRelation) {
    34                 super("JunctionSearch",false);
    35                 this.plugin = plugin;
    36                 this.n = n;
    37                 this.subset = subset;
    38                 this.produceRelation = produceRelation;
    39                 jc = new JunctionChecker(plugin.getChannelDigraph(), n);
    40         }
     31    public JunctionSearchTask(JunctionCheckerPlugin plugin, int n,
     32            HashSet<Channel> subset,
     33            boolean produceRelation) {
     34        super("JunctionSearch",false);
     35        this.plugin = plugin;
     36        this.n = n;
     37        this.subset = subset;
     38        this.produceRelation = produceRelation;
     39        jc = new JunctionChecker(plugin.getChannelDigraph(), n);
     40    }
    4141
    42         @Override
    43         protected void cancel() {
    44                 this.canceled = true;
    45                 progressMonitor.cancel();
    46         }
     42    @Override
     43    protected void cancel() {
     44        this.canceled = true;
     45        progressMonitor.cancel();
     46    }
    4747
    48         @Override
    49         protected void finish() {
    50                 progressMonitor.finishTask();
    51                 if (canceled) {
    52                         return;
    53                 }
    54                 ArrayList<HashSet<Channel>> junctions = jc.getJunctions();
    55                 JOptionPane.showMessageDialog(Main.parent, tr("Number of {0}-ways junctions found: {1}", n, junctions.size()));
    56                 if (produceRelation) {
    57                         for (int i = 0; i < junctions.size(); i++) {
    58                                 plugin.getRelationProducer().produceRelation(junctions.get(i) , n);
    59                         }
    60                 }
    61         }
     48    @Override
     49    protected void finish() {
     50        progressMonitor.finishTask();
     51        if (canceled) {
     52            return;
     53        }
     54        ArrayList<HashSet<Channel>> junctions = jc.getJunctions();
     55        JOptionPane.showMessageDialog(Main.parent, tr("Number of {0}-ways junctions found: {1}", n, junctions.size()));
     56        if (produceRelation) {
     57            for (int i = 0; i < junctions.size(); i++) {
     58                plugin.getRelationProducer().produceRelation(junctions.get(i) , n);
     59            }
     60        }
     61    }
    6262
    63         @Override
    64         protected void realRun() throws SAXException, IOException,
    65         OsmTransferException {
    66                 jc.junctionSearch(new ArrayList<Channel>(subset), getProgressMonitor());
    67         }
     63    @Override
     64    protected void realRun() throws SAXException, IOException,
     65    OsmTransferException {
     66        jc.junctionSearch(new ArrayList<Channel>(subset), getProgressMonitor());
     67    }
    6868
    6969}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/PrepareJunctionCheckorSearch.java

    r25501 r30725  
    1414public class PrepareJunctionCheckorSearch {
    1515
    16         private final JunctionCheckerPlugin plugin;
    17         private final int n;
    18         private HashSet<Channel> subset;
    19         private JunctionCheckTask jct;
    20         private final boolean produceRelation;
     16    private final JunctionCheckerPlugin plugin;
     17    private final int n;
     18    private HashSet<Channel> subset;
     19    private JunctionCheckTask jct;
     20    private final boolean produceRelation;
    2121
    22         public PrepareJunctionCheckorSearch(JunctionCheckerPlugin plugin, int n, boolean producerelation) {
    23                 this.plugin = plugin;
    24                 this.n = n;
    25                 this.subset = new HashSet<Channel>();
    26                 this.produceRelation = producerelation;
    27         }
     22    public PrepareJunctionCheckorSearch(JunctionCheckerPlugin plugin, int n, boolean producerelation) {
     23        this.plugin = plugin;
     24        this.n = n;
     25        this.subset = new HashSet<Channel>();
     26        this.produceRelation = producerelation;
     27    }
    2828
    2929
    30         protected void prepareJunctionCheck() {
    31                 if (prepareSubset()) {
    32                         jct = new JunctionCheckTask(plugin, n, subset, produceRelation);
    33                         Main.worker.submit(jct);
    34                 }
    35         }
     30    protected void prepareJunctionCheck() {
     31        if (prepareSubset()) {
     32            jct = new JunctionCheckTask(plugin, n, subset, produceRelation);
     33            Main.worker.submit(jct);
     34        }
     35    }
    3636
    37         protected void prepareJunctionSearch() {
    38                 if (prepareSubset()) {
    39                         JunctionSearchTask jst = new JunctionSearchTask(plugin, n, subset, produceRelation);
    40                         Main.worker.submit(jst);
    41                 }
    42         }
     37    protected void prepareJunctionSearch() {
     38        if (prepareSubset()) {
     39            JunctionSearchTask jst = new JunctionSearchTask(plugin, n, subset, produceRelation);
     40            Main.worker.submit(jst);
     41        }
     42    }
    4343
    44         private boolean prepareSubset(){
    45                 if (plugin.getChannelDigraph().getSelectedChannels().size() < 6) {
    46                         JOptionPane.showMessageDialog(Main.parent, "Less then 6 channels are selected");
    47                         return false;
    48                 }
    49                 subset = plugin.getChannelDigraph().getSelectedChannels();
    50                 return true;
    51         }
     44    private boolean prepareSubset(){
     45        if (plugin.getChannelDigraph().getSelectedChannels().size() < 6) {
     46            JOptionPane.showMessageDialog(Main.parent, "Less then 6 channels are selected");
     47            return false;
     48        }
     49        subset = plugin.getChannelDigraph().getSelectedChannels();
     50        return true;
     51    }
    5252}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/commandlineinterface/CLI.java

    r25501 r30725  
    1818public class CLI {
    1919
    20         /**
    21         * Die Klasse ist zum Erstellen statistischer Tests, oder zur Erzeugung einer Channel-Digraph-XML-Datei
    22         * @param args
    23         */
    24         public static void main(String[] args) {
     20    /**
     21    * Die Klasse ist zum Erstellen statistischer Tests, oder zur Erzeugung einer Channel-Digraph-XML-Datei
     22    * @param args
     23    */
     24    public static void main(String[] args) {
    2525
    26                 String inputosm = "";
    27                 String outputosm = "";
    28                 int maxchannelsearch = 0;
    29                 int ticks = 0;
    30                 int n = 0;
    31                 int runs = 0;
     26        String inputosm = "";
     27        String outputosm = "";
     28        int maxchannelsearch = 0;
     29        int ticks = 0;
     30        int n = 0;
     31        int runs = 0;
    3232
    33                 final String WAYFILTERFILE = "/resources/xml/waysfilter.xml";
     33        final String WAYFILTERFILE = "/resources/xml/waysfilter.xml";
    3434
    35                 if (args.length != 6) {
    36                         System.out.println("Parameter:\n inputosm (osmxml) \n outputchannelosm (outputosmxml) \n maxchannelsearch (wieviele channel sollen max. überprüft werdne) \n ticks (schrittweite) \n n (n-wege-kreuzung) \n durchläufe (wieviele durchläufe pro suchdurchgang)");
    37                         return;
    38                 } else {
    39                         inputosm = args[0];
    40                         outputosm = args[1];
    41                         maxchannelsearch = Integer.parseInt(args[2]);
    42                         ticks = Integer.parseInt(args[3]);
    43                         n = Integer.parseInt(args[4]);
    44                         runs = Integer.parseInt(args[5]);
    45                 }
     35        if (args.length != 6) {
     36            System.out.println("Parameter:\n inputosm (osmxml) \n outputchannelosm (outputosmxml) \n maxchannelsearch (wieviele channel sollen max. überprüft werdne) \n ticks (schrittweite) \n n (n-wege-kreuzung) \n durchläufe (wieviele durchläufe pro suchdurchgang)");
     37            return;
     38        } else {
     39            inputosm = args[0];
     40            outputosm = args[1];
     41            maxchannelsearch = Integer.parseInt(args[2]);
     42            ticks = Integer.parseInt(args[3]);
     43            n = Integer.parseInt(args[4]);
     44            runs = Integer.parseInt(args[5]);
     45        }
    4646
    47                 // XML datei einlesen
    48                 File file = new File(inputosm);
    49                 OSMXMLReader xmlreader = new OSMXMLReader(file);
    50                 xmlreader.parseXML();
     47        // XML datei einlesen
     48        File file = new File(inputosm);
     49        OSMXMLReader xmlreader = new OSMXMLReader(file);
     50        xmlreader.parseXML();
    5151
    52                 // Filter mit gewünschten Ways laden
    53                 XMLFilterReader reader = new XMLFilterReader(
    54                                 WAYFILTERFILE);
    55                 reader.parseXML();
     52        // Filter mit gewünschten Ways laden
     53        XMLFilterReader reader = new XMLFilterReader(
     54                WAYFILTERFILE);
     55        reader.parseXML();
    5656
    57                 // gewünschte Ways filtern
    58                 ExecuteFilter ef = new ExecuteFilter(reader.getFilters(), xmlreader
    59                                 .getOSMGraph());
    60                 ef.filter();
     57        // gewünschte Ways filtern
     58        ExecuteFilter ef = new ExecuteFilter(reader.getFilters(), xmlreader
     59                .getOSMGraph());
     60        ef.filter();
    6161
    62                 // ChannelDiGraphen erzeugen
    63                 ChannelDigraphBuilder cdgb = new ChannelDigraphBuilder(ef.getOutgoinggraph());
    64                 cdgb.buildChannelDigraph();
     62        // ChannelDiGraphen erzeugen
     63        ChannelDigraphBuilder cdgb = new ChannelDigraphBuilder(ef.getOutgoinggraph());
     64        cdgb.buildChannelDigraph();
    6565
    66                 // DiGraph "versiegeln"
    67                 //DiGraphSealer sealer = new DiGraphSealer(cdgb.getDigraph(), cdgb
    68                 //              .getNewid());
    69                 //sealer.sealingGraph();
     66        // DiGraph "versiegeln"
     67        //DiGraphSealer sealer = new DiGraphSealer(cdgb.getDigraph(), cdgb
     68        //        .getNewid());
     69        //sealer.sealingGraph();
    7070
    71                 StrongConnectednessCalculator scc = new StrongConnectednessCalculator(cdgb.getDigraph());
    72                 scc.calculateSCC();
    73                 //System.out.println(scc.showNotstronglyConnectednessParts());
     71        StrongConnectednessCalculator scc = new StrongConnectednessCalculator(cdgb.getDigraph());
     72        scc.calculateSCC();
     73        //System.out.println(scc.showNotstronglyConnectednessParts());
    7474
    75                 if (maxchannelsearch == 0) {
    76                         OSMXMLWriter oxw = new OSMXMLWriter(outputosm, cdgb.getDigraph());
    77                         try {
    78                                 oxw.writeXML();
    79                         } catch (FileNotFoundException e) {
    80                                 // TODO Auto-generated catch block
    81                                 e.printStackTrace();
    82                         } catch (XMLStreamException e) {
    83                                 // TODO Auto-generated catch block
    84                                 e.printStackTrace();
    85                         }
    86                         ;
     75        if (maxchannelsearch == 0) {
     76            OSMXMLWriter oxw = new OSMXMLWriter(outputosm, cdgb.getDigraph());
     77            try {
     78                oxw.writeXML();
     79            } catch (FileNotFoundException e) {
     80                // TODO Auto-generated catch block
     81                e.printStackTrace();
     82            } catch (XMLStreamException e) {
     83                // TODO Auto-generated catch block
     84                e.printStackTrace();
     85            }
     86            ;
    8787
    88                         System.out.println("OSMXML erzeugt, breche an dieser Stelle ab");
    89                         return;
    90                 }
     88            System.out.println("OSMXML erzeugt, breche an dieser Stelle ab");
     89            return;
     90        }
    9191
    92                 JunctionChecker jc = new JunctionChecker(cdgb.getDigraph(), n);
    93                 ArrayList<Channel> subset = new ArrayList<Channel>();
     92        JunctionChecker jc = new JunctionChecker(cdgb.getDigraph(), n);
     93        ArrayList<Channel> subset = new ArrayList<Channel>();
    9494
    95                 Channel seed = new Channel();
    96                 Channel vorChannel;
    97                 Channel tempChannel;
    98                 boolean isIn = false;
    99                 int jcf;
    100                 long measuredIterateThroughTime = 0;
    101                 long measuredGenerateSubColumnTime = 0;
    102                 long measuredTime = 0;
    103                 long start;
     95        Channel seed = new Channel();
     96        Channel vorChannel;
     97        Channel tempChannel;
     98        boolean isIn = false;
     99        int jcf;
     100        long measuredIterateThroughTime = 0;
     101        long measuredGenerateSubColumnTime = 0;
     102        long measuredTime = 0;
     103        long start;
    104104
    105                 //Unzusammenhängenden Teilgraph erzeugen
    106                 /*
    107                 for (int i = 6; i < maxchannelsearch; i = i + ticks) {
    108                         //diff = 0;
    109                         start = System.currentTimeMillis();
    110                         jcf = 0;
    111                         //System.out.println("maxchannel: " + i);
    112                         for (int j = 0; j < runs; j++) {
    113                                 //System.out.println("run: " +j);
    114                                 subset.clear();
    115                                 for (int j2 = 0; j2 <= i; j2++) {
    116                                         subset.add(cdgb.getDigraph()
    117                                                         .getChannelAtPosition(
    118                                                                         (int) ((cdgb.getDigraph().getChannels()
    119                                                                                         .size()) * Math.random())));
    120                                 }
    121                                 //System.out.println("jc gestartet");
    122                                 start = System.currentTimeMillis();
    123                                 jc.junctionSearch(subset);
    124                                 measuredTime += (System.currentTimeMillis() - start);
    125                                 //System.out.println("jc beendet");
    126                                 //diff = diff + (System.currentTimeMillis() - start);
    127                                 measuredIterateThroughTime += jc.getMeasuredIterateTime();
    128                                 measuredGenerateSubColumnTime += jc.getMeasuredGenerateTime();
    129                         }
    130                         System.out.println("Channels: " + (i) + " Time(Iterate): " + (measuredIterateThroughTime/runs) + " Time(Generate): " + (measuredGenerateSubColumnTime/runs) +" Time(overall): "+ (measuredTime/runs) + " junctionsfound: " + jcf);
    131                 }*/
     105        //Unzusammenhängenden Teilgraph erzeugen
     106        /*
     107        for (int i = 6; i < maxchannelsearch; i = i + ticks) {
     108            //diff = 0;
     109            start = System.currentTimeMillis();
     110            jcf = 0;
     111            //System.out.println("maxchannel: " + i);
     112            for (int j = 0; j < runs; j++) {
     113                //System.out.println("run: " +j);
     114                subset.clear();
     115                for (int j2 = 0; j2 <= i; j2++) {
     116                    subset.add(cdgb.getDigraph()
     117                            .getChannelAtPosition(
     118                                    (int) ((cdgb.getDigraph().getChannels()
     119                                            .size()) * Math.random())));
     120                }
     121                //System.out.println("jc gestartet");
     122                start = System.currentTimeMillis();
     123                jc.junctionSearch(subset);
     124                measuredTime += (System.currentTimeMillis() - start);
     125                //System.out.println("jc beendet");
     126                //diff = diff + (System.currentTimeMillis() - start);
     127                measuredIterateThroughTime += jc.getMeasuredIterateTime();
     128                measuredGenerateSubColumnTime += jc.getMeasuredGenerateTime();
     129            }
     130            System.out.println("Channels: " + (i) + " Time(Iterate): " + (measuredIterateThroughTime/runs) + " Time(Generate): " + (measuredGenerateSubColumnTime/runs) +" Time(overall): "+ (measuredTime/runs) + " junctionsfound: " + jcf);
     131        }*/
    132132
    133                 //Zusammenhängenden Teilgraph erzeugen
     133        //Zusammenhängenden Teilgraph erzeugen
    134134
    135                 for (int i = 5; i < maxchannelsearch; i = i + ticks) {
    136                         measuredIterateThroughTime = 0;
    137                         measuredGenerateSubColumnTime = 0;
    138                         measuredTime =0;
    139                         jcf = 0;
    140                         //System.out.println("maxchannel: " + i);
    141                         for (int j = 0; j < runs; j++) {
    142                                 //System.out.println("run: " +j);
    143                                 subset.clear();
    144                                 do {
    145                                         seed = cdgb.getDigraph()
    146                                         .getChannelAtPosition(
    147                                                         (int) ((cdgb.getDigraph().getChannels()
    148                                                                         .size()) * Math.random()));
    149                                 }
    150                                 while(!seed.isStrongConnected());
    151                                 subset.add(seed);
    152                                 //System.out.println("Seed: " + seed.getNewid());
    153                                 vorChannel = seed;
    154                                 for (int k = 0; k < i - 1; k++) {
    155                                         isIn = false;
    156                                         do {
    157                                                 tempChannel = getNeighbourChannel(vorChannel);
    158                                                 if (!subset.contains(tempChannel)) {
    159                                                         subset.add(tempChannel);
    160                                                         //System.out.println("zugefügt: " + tempChannel.getNewid());
    161                                                         seed = tempChannel;
    162                                                         isIn = true;
    163                                                 }
    164                                                 else {
    165                                                         vorChannel = tempChannel;
    166                                                         isIn = false;
    167                                                 }
    168                                         }while (isIn == false);
    169                                 }
    170                                 start = System.currentTimeMillis();
    171                                 jc.junctionSearch(subset);
    172                                 measuredTime += (System.currentTimeMillis() - start);
    173                                 //System.out.println("jc beendet");
    174                                 measuredIterateThroughTime += jc.getMeasuredIterateTime();
    175                                 measuredGenerateSubColumnTime += jc.getMeasuredGenerateTime();
    176                                 jcf = jcf + jc.getJunctions().size();
    177                         }
    178                         System.out.println("Channels: " + (i) + " Time(Iterate): " + (measuredIterateThroughTime/runs) + " Time(Generate): " + (measuredGenerateSubColumnTime/runs) +" Time(overall): "+ (measuredTime/runs) + " junctionsfound: " + jcf);
    179                 }
    180         }
     135        for (int i = 5; i < maxchannelsearch; i = i + ticks) {
     136            measuredIterateThroughTime = 0;
     137            measuredGenerateSubColumnTime = 0;
     138            measuredTime =0;
     139            jcf = 0;
     140            //System.out.println("maxchannel: " + i);
     141            for (int j = 0; j < runs; j++) {
     142                //System.out.println("run: " +j);
     143                subset.clear();
     144                do {
     145                    seed = cdgb.getDigraph()
     146                    .getChannelAtPosition(
     147                            (int) ((cdgb.getDigraph().getChannels()
     148                                    .size()) * Math.random()));
     149                }
     150                while(!seed.isStrongConnected());
     151                subset.add(seed);
     152                //System.out.println("Seed: " + seed.getNewid());
     153                vorChannel = seed;
     154                for (int k = 0; k < i - 1; k++) {
     155                    isIn = false;
     156                    do {
     157                        tempChannel = getNeighbourChannel(vorChannel);
     158                        if (!subset.contains(tempChannel)) {
     159                            subset.add(tempChannel);
     160                            //System.out.println("zugefügt: " + tempChannel.getNewid());
     161                            seed = tempChannel;
     162                            isIn = true;
     163                        }
     164                        else {
     165                            vorChannel = tempChannel;
     166                            isIn = false;
     167                        }
     168                    }while (isIn == false);
     169                }
     170                start = System.currentTimeMillis();
     171                jc.junctionSearch(subset);
     172                measuredTime += (System.currentTimeMillis() - start);
     173                //System.out.println("jc beendet");
     174                measuredIterateThroughTime += jc.getMeasuredIterateTime();
     175                measuredGenerateSubColumnTime += jc.getMeasuredGenerateTime();
     176                jcf = jcf + jc.getJunctions().size();
     177            }
     178            System.out.println("Channels: " + (i) + " Time(Iterate): " + (measuredIterateThroughTime/runs) + " Time(Generate): " + (measuredGenerateSubColumnTime/runs) +" Time(overall): "+ (measuredTime/runs) + " junctionsfound: " + jcf);
     179        }
     180    }
    181181
    182         private static Channel getNeighbourChannel(Channel seedChannel) {
    183                 if (Math.random() < 0.5) {
    184                         if (seedChannel.getPredChannels().size() >=1 ) {
    185                                 return seedChannel.getPredChannels().get((int) (seedChannel.getPredChannels().size() * Math.random()));
    186                         }
    187                         else return seedChannel;
    188                 }
    189                 else {
    190                         if (seedChannel.getLeadsTo().size() >=1 ) {
    191                                 return seedChannel.getLeadsTo().get((int) (seedChannel.getLeadsTo().size() * Math.random())).getToChannel();
    192                         }
    193                         else return seedChannel;
    194                 }
    195         }
     182    private static Channel getNeighbourChannel(Channel seedChannel) {
     183        if (Math.random() < 0.5) {
     184            if (seedChannel.getPredChannels().size() >=1 ) {
     185                return seedChannel.getPredChannels().get((int) (seedChannel.getPredChannels().size() * Math.random()));
     186            }
     187            else return seedChannel;
     188        }
     189        else {
     190            if (seedChannel.getLeadsTo().size() >=1 ) {
     191                return seedChannel.getLeadsTo().get((int) (seedChannel.getLeadsTo().size() * Math.random())).getToChannel();
     192            }
     193            else return seedChannel;
     194        }
     195    }
    196196}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/connectedness/BacktrackingColors.java

    r25501 r30725  
    55 */
    66public class BacktrackingColors {
    7        
    8         public static final int WHITE = -1;
    9         public static final int GREY = 0;
    10         public static final int BLACK = 1;
     7   
     8    public static final int WHITE = -1;
     9    public static final int GREY = 0;
     10    public static final int BLACK = 1;
    1111
    1212}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/connectedness/DiGraphSealer.java

    r29854 r30725  
    1515
    1616
    17         // vorsichtshalber auf einen hohen negativen Wert gesetzt. besser
    18         // automatisch setzen!
    19         // TODO: NewID automatisch setzen
    20         private int newID = 1000000;
    21         private ChannelDiGraph digraph;
     17    // vorsichtshalber auf einen hohen negativen Wert gesetzt. besser
     18    // automatisch setzen!
     19    // TODO: NewID automatisch setzen
     20    private int newID = 1000000;
     21    private ChannelDiGraph digraph;
    2222
    23         public DiGraphSealer(ChannelDiGraph digraph) {
    24                 this.digraph = digraph;
    25         }
     23    public DiGraphSealer(ChannelDiGraph digraph) {
     24        this.digraph = digraph;
     25    }
    2626
    27         public DiGraphSealer(ChannelDiGraph digraph, int newID) {
    28                 this.digraph = digraph;
    29                 this.newID = newID;
    30         }
     27    public DiGraphSealer(ChannelDiGraph digraph, int newID) {
     28        this.digraph = digraph;
     29        this.newID = newID;
     30    }
    3131
    32         /**
    33         * versiegelt den vorher gesetzten DiGraphen
    34         */
    35         public void sealingGraph() {
    36                 Vector<Integer> outgoingChannelIDs = new Vector<Integer>();
    37                 Vector<Integer> incomingChannelIDs = new Vector<Integer>();
     32    /**
     33    * versiegelt den vorher gesetzten DiGraphen
     34    */
     35    public void sealingGraph() {
     36        Vector<Integer> outgoingChannelIDs = new Vector<Integer>();
     37        Vector<Integer> incomingChannelIDs = new Vector<Integer>();
    3838
    39                 for (int i = 0; i < digraph.numberOfChannels(); i++) {
    40                         if (digraph.isInBBox(digraph.getChannelAtPosition(i).getFromNode()) == false) {
    41                                 incomingChannelIDs.add(i);
    42                         }
    43                         if (digraph.isInBBox(digraph.getChannelAtPosition(i).getToNode()) == false) {
    44                                 outgoingChannelIDs.add(i);
    45                         }
    46                 }
    47                 Channel tempChannel;
    48                 LeadsTo tempLeadsTo;
    49                 for (int i = 0; i < outgoingChannelIDs.size(); i++) {
    50                         if (digraph.getChannelAtPosition(outgoingChannelIDs.get(i))
    51                                         .getLeadsTo().size() == 0) {
     39        for (int i = 0; i < digraph.numberOfChannels(); i++) {
     40            if (digraph.isInBBox(digraph.getChannelAtPosition(i).getFromNode()) == false) {
     41                incomingChannelIDs.add(i);
     42            }
     43            if (digraph.isInBBox(digraph.getChannelAtPosition(i).getToNode()) == false) {
     44                outgoingChannelIDs.add(i);
     45            }
     46        }
     47        Channel tempChannel;
     48        LeadsTo tempLeadsTo;
     49        for (int i = 0; i < outgoingChannelIDs.size(); i++) {
     50            if (digraph.getChannelAtPosition(outgoingChannelIDs.get(i))
     51                    .getLeadsTo().size() == 0) {
    5252
    53                                 tempChannel = new Channel(digraph.getChannelAtPosition(
    54                                                 outgoingChannelIDs.get(i)).getToNode(), digraph
    55                                                 .getChannelAtPosition(incomingChannelIDs.get(0))
    56                                                 .getFromNode());
    57                                 //dem Channel auch den neuen Channel als Nachfolger übergeben!!!
    58                                 //sonst gibts Probleme beim JunctionCheck
    59                                 tempLeadsTo = new LeadsTo(digraph
    60                                                 .getChannelAtPosition(outgoingChannelIDs.get(i)),
    61                                                 tempChannel);
    62                                 digraph.getChannelAtPosition(outgoingChannelIDs.get(i))
    63                                                 .addLeadsTo(tempLeadsTo);
    64                                 digraph.addLeadsTo(tempLeadsTo);
    65                                 tempLeadsTo = new LeadsTo(tempChannel, digraph
    66                                                 .getChannelAtPosition(incomingChannelIDs.get(0)));
    67                                 tempChannel.addLeadsTo(tempLeadsTo);
    68                                 digraph.addLeadsTo(tempLeadsTo);
    69                                 tempChannel.addWay(digraph.getChannelAtPosition(
    70                                                 outgoingChannelIDs.get(i)).getWay());
    71                                 tempChannel.setNewid(newID);
    72                                 newID++;
    73                                 digraph.addChannel(tempChannel);
    74                         }
    75                 }
     53                tempChannel = new Channel(digraph.getChannelAtPosition(
     54                        outgoingChannelIDs.get(i)).getToNode(), digraph
     55                        .getChannelAtPosition(incomingChannelIDs.get(0))
     56                        .getFromNode());
     57                //dem Channel auch den neuen Channel als Nachfolger übergeben!!!
     58                //sonst gibts Probleme beim JunctionCheck
     59                tempLeadsTo = new LeadsTo(digraph
     60                        .getChannelAtPosition(outgoingChannelIDs.get(i)),
     61                        tempChannel);
     62                digraph.getChannelAtPosition(outgoingChannelIDs.get(i))
     63                        .addLeadsTo(tempLeadsTo);
     64                digraph.addLeadsTo(tempLeadsTo);
     65                tempLeadsTo = new LeadsTo(tempChannel, digraph
     66                        .getChannelAtPosition(incomingChannelIDs.get(0)));
     67                tempChannel.addLeadsTo(tempLeadsTo);
     68                digraph.addLeadsTo(tempLeadsTo);
     69                tempChannel.addWay(digraph.getChannelAtPosition(
     70                        outgoingChannelIDs.get(i)).getWay());
     71                tempChannel.setNewid(newID);
     72                newID++;
     73                digraph.addChannel(tempChannel);
     74            }
     75        }
    7676
    77                 for (int i = 0; i < incomingChannelIDs.size(); i++) {
    78                         if (digraph.getChannelAtPosition(incomingChannelIDs.get(i))
    79                                         .getPredChannels().size() == 0) {
    80                                 tempChannel = new Channel(digraph.getChannelAtPosition(
    81                                                 outgoingChannelIDs.get(0)).getToNode(), digraph
    82                                                 .getChannelAtPosition(incomingChannelIDs.get(i))
    83                                                 .getFromNode());
    84                                 //dem Channel auch den neuen Channel als Nachfolger überegeben
    85                                 // sonst gibt es Probleme beim JuncitonCheck
    86                                 digraph
    87                                 .getChannelAtPosition(incomingChannelIDs.get(i)).addPredChannel(tempChannel);
    88                                 tempLeadsTo = new LeadsTo(tempChannel, digraph
    89                                                 .getChannelAtPosition(incomingChannelIDs.get(i)));
    90                                 tempChannel.addLeadsTo(tempLeadsTo);
    91                                 digraph.addLeadsTo(tempLeadsTo);
    92                                 tempLeadsTo = new LeadsTo(digraph
    93                                                 .getChannelAtPosition(outgoingChannelIDs.get(0)),
    94                                                 tempChannel);
    95                                 digraph.getChannelAtPosition(outgoingChannelIDs.get(0))
    96                                                 .addLeadsTo(tempLeadsTo);
    97                                 digraph.addLeadsTo(tempLeadsTo);
    98                                 tempChannel.addWay(digraph.getChannelAtPosition(
    99                                                 incomingChannelIDs.get(i)).getWay());
    100                                 tempChannel.setNewid(newID);
    101                                 newID++;
    102                                 digraph.addChannel(tempChannel);
    103                         }
    104                 }
    105                 this.deleteDuplicateChannels();
    106         }
    107        
    108         /*
    109         private void showLeadsTo() {
    110                 for (int i = 0; i < digraph.getChannels().size(); i++) {
    111                         log.debug("Untersuche CHannel: " + digraph.getChannelAtPosition(i).getNewid());
    112                         for (int j = 0; j < digraph.getChannelAtPosition(i).getLeadsTo().size(); j++) {
    113                                 log.debug("LeadsTo: " + digraph.getChannelAtPosition(i).getLeadsTo().get(j).toString());
    114                         }
    115                 }
    116         }*/
     77        for (int i = 0; i < incomingChannelIDs.size(); i++) {
     78            if (digraph.getChannelAtPosition(incomingChannelIDs.get(i))
     79                    .getPredChannels().size() == 0) {
     80                tempChannel = new Channel(digraph.getChannelAtPosition(
     81                        outgoingChannelIDs.get(0)).getToNode(), digraph
     82                        .getChannelAtPosition(incomingChannelIDs.get(i))
     83                        .getFromNode());
     84                //dem Channel auch den neuen Channel als Nachfolger überegeben
     85                // sonst gibt es Probleme beim JuncitonCheck
     86                digraph
     87                .getChannelAtPosition(incomingChannelIDs.get(i)).addPredChannel(tempChannel);
     88                tempLeadsTo = new LeadsTo(tempChannel, digraph
     89                        .getChannelAtPosition(incomingChannelIDs.get(i)));
     90                tempChannel.addLeadsTo(tempLeadsTo);
     91                digraph.addLeadsTo(tempLeadsTo);
     92                tempLeadsTo = new LeadsTo(digraph
     93                        .getChannelAtPosition(outgoingChannelIDs.get(0)),
     94                        tempChannel);
     95                digraph.getChannelAtPosition(outgoingChannelIDs.get(0))
     96                        .addLeadsTo(tempLeadsTo);
     97                digraph.addLeadsTo(tempLeadsTo);
     98                tempChannel.addWay(digraph.getChannelAtPosition(
     99                        incomingChannelIDs.get(i)).getWay());
     100                tempChannel.setNewid(newID);
     101                newID++;
     102                digraph.addChannel(tempChannel);
     103            }
     104        }
     105        this.deleteDuplicateChannels();
     106    }
     107   
     108    /*
     109    private void showLeadsTo() {
     110        for (int i = 0; i < digraph.getChannels().size(); i++) {
     111            log.debug("Untersuche CHannel: " + digraph.getChannelAtPosition(i).getNewid());
     112            for (int j = 0; j < digraph.getChannelAtPosition(i).getLeadsTo().size(); j++) {
     113                log.debug("LeadsTo: " + digraph.getChannelAtPosition(i).getLeadsTo().get(j).toString());
     114            }
     115        }
     116    }*/
    117117
    118         /**
    119         * dirt'n'quick methode zum löschen doppelter channels TODO:
    120         * versiegeln-methode überarbeiten
    121         *TODO: benutze ich die überhaupt noch?
    122         */
    123         private void deleteDuplicateChannels() {
     118    /**
     119    * dirt'n'quick methode zum löschen doppelter channels TODO:
     120    * versiegeln-methode überarbeiten
     121    *TODO: benutze ich die überhaupt noch?
     122    */
     123    private void deleteDuplicateChannels() {
    124124
    125                 for (int i = 0; i < digraph.getChannels().size(); i++) {
    126                         for (int j = i + 1; j < digraph.getChannels().size(); j++) {
    127                                 if (digraph.getChannelAtPosition(i).getFromNode() == digraph
    128                                                 .getChannelAtPosition(j).getFromNode()
    129                                                 && digraph.getChannelAtPosition(i).getToNode() == digraph
    130                                                                 .getChannelAtPosition(j).getToNode()) {
    131                                         digraph.removeChannel(digraph.getChannelAtPosition(j));
    132                                 }
    133                         }
    134                 }
    135         }
     125        for (int i = 0; i < digraph.getChannels().size(); i++) {
     126            for (int j = i + 1; j < digraph.getChannels().size(); j++) {
     127                if (digraph.getChannelAtPosition(i).getFromNode() == digraph
     128                        .getChannelAtPosition(j).getFromNode()
     129                        && digraph.getChannelAtPosition(i).getToNode() == digraph
     130                                .getChannelAtPosition(j).getToNode()) {
     131                    digraph.removeChannel(digraph.getChannelAtPosition(j));
     132                }
     133            }
     134        }
     135    }
    136136
    137         /*
    138         * setzt Wert für IDs für neu angelegte Ways
    139         */
    140         /**
    141         * @param newID
    142         */
    143         public void setNewID(int newID) {
    144                 this.newID = newID;
    145         }
     137    /*
     138    * setzt Wert für IDs für neu angelegte Ways
     139    */
     140    /**
     141    * @param newID
     142    */
     143    public void setNewID(int newID) {
     144        this.newID = newID;
     145    }
    146146
    147         /**
    148         * @return
    149         * @uml.property  name="newID"
    150         */
    151         public int getNewID() {
    152                 return newID;
    153         }
     147    /**
     148    * @return
     149    * @uml.property  name="newID"
     150    */
     151    public int getNewID() {
     152        return newID;
     153    }
    154154
    155         public ChannelDiGraph getDiGraph() {
    156                 return digraph;
    157         }
     155    public ChannelDiGraph getDiGraph() {
     156        return digraph;
     157    }
    158158}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/connectedness/StrongConnectednessCalculator.java

    r25501 r30725  
    77public class StrongConnectednessCalculator {
    88
    9         private int index = 0;
    10         private final ArrayList<Channel> stack = new ArrayList<Channel>();
    11         private final ArrayList<ArrayList<Channel>> SCC = new ArrayList<ArrayList<Channel>>();
    12         private final int numberOfNodes;
    13         private int calculatedNodes = 0;
    14         private ArrayList<Channel> nsccchannels = new ArrayList<Channel>();
    15         private final ChannelDiGraph digraph;
    16         int biggestPart = 0;
     9    private int index = 0;
     10    private final ArrayList<Channel> stack = new ArrayList<Channel>();
     11    private final ArrayList<ArrayList<Channel>> SCC = new ArrayList<ArrayList<Channel>>();
     12    private final int numberOfNodes;
     13    private int calculatedNodes = 0;
     14    private ArrayList<Channel> nsccchannels = new ArrayList<Channel>();
     15    private final ChannelDiGraph digraph;
     16    int biggestPart = 0;
    1717
    18         public StrongConnectednessCalculator(ChannelDiGraph digraph) {
    19                 this.digraph = digraph;
    20                 numberOfNodes = digraph.numberOfChannels();
    21         }
     18    public StrongConnectednessCalculator(ChannelDiGraph digraph) {
     19        this.digraph = digraph;
     20        numberOfNodes = digraph.numberOfChannels();
     21    }
    2222
    23         private int findUncalculatedNodes() {
    24                 for (int i = 0; i < numberOfNodes; i++) {
    25                         if (digraph.getChannelAtPosition(i).getLowlink() == -1) {
    26                                 return i;
    27                         }
    28                 }
    29                 return 0;
    30         }
     23    private int findUncalculatedNodes() {
     24        for (int i = 0; i < numberOfNodes; i++) {
     25            if (digraph.getChannelAtPosition(i).getLowlink() == -1) {
     26                return i;
     27            }
     28        }
     29        return 0;
     30    }
    3131
    32         /**
    33         * berechnet die starken Zusammenhangskomponenten
    34         */
    35         public void calculateSCC() {
    36                 while (calculatedNodes != numberOfNodes) {
    37                         //log.trace("calculatedNodes: " + calculatedNodes + ", gesamtnodes: " + numberOfNodes);
    38                         tarjan(digraph.getChannelAtPosition(findUncalculatedNodes()));
    39                 }
    40                 //log.trace("Berechnung der starken Zusammenhangskomponenten beendet: \n " +numberOfNodes + " Nodes sind wie folgt aufgeteilt: ");
    41                 for (int i = 0; i < SCC.size(); i++) {
    42                         //log.trace("Komponente: " + i + " besteht aus " + SCC.get(i).size()+ " Knoten");
    43                         /**
    44                         * for (int j = 1; j < list.getNumberOfNodes(); j++) { if
    45                         * (list.getAdjacencyListnodes()[j].getIndex()== -1) {
    46                         * System.out.println("====");
    47                         * System.out.println(list.getAdjacencyListnodes
    48                         * ()[j].getNode().toString()); } }
    49                         **/
    50                 }
    51                 findBiggestPiece();
    52                 saveNotSCCChannel();
    53         }
     32    /**
     33    * berechnet die starken Zusammenhangskomponenten
     34    */
     35    public void calculateSCC() {
     36        while (calculatedNodes != numberOfNodes) {
     37            //log.trace("calculatedNodes: " + calculatedNodes + ", gesamtnodes: " + numberOfNodes);
     38            tarjan(digraph.getChannelAtPosition(findUncalculatedNodes()));
     39        }
     40        //log.trace("Berechnung der starken Zusammenhangskomponenten beendet: \n " +numberOfNodes + " Nodes sind wie folgt aufgeteilt: ");
     41        for (int i = 0; i < SCC.size(); i++) {
     42            //log.trace("Komponente: " + i + " besteht aus " + SCC.get(i).size()+ " Knoten");
     43            /**
     44            * for (int j = 1; j < list.getNumberOfNodes(); j++) { if
     45            * (list.getAdjacencyListnodes()[j].getIndex()== -1) {
     46            * System.out.println("====");
     47            * System.out.println(list.getAdjacencyListnodes
     48            * ()[j].getNode().toString()); } }
     49            **/
     50        }
     51        findBiggestPiece();
     52        saveNotSCCChannel();
     53    }
    5454
    55         /**
    56         * speichert alle Channel, die nicht stark zusammenhängend sind, in einer ArrayList
    57         **/
    58         private void saveNotSCCChannel() {
    59                 nsccchannels = new ArrayList<Channel>();
    60                 for (int i = 0; i < SCC.size(); i++) {
    61                         if (i != biggestPart) {
    62                                 nsccchannels.addAll(SCC.get(i));
    63                         }
    64                 }
    65                 //alle Channels auf nicht zusammenhängend setzen
    66                 for (int i = 0; i < nsccchannels.size(); i++) {
    67                         nsccchannels.get(i).setStrongConnected(false);
    68                 }
    69         }
     55    /**
     56    * speichert alle Channel, die nicht stark zusammenhängend sind, in einer ArrayList
     57    **/
     58    private void saveNotSCCChannel() {
     59        nsccchannels = new ArrayList<Channel>();
     60        for (int i = 0; i < SCC.size(); i++) {
     61            if (i != biggestPart) {
     62                nsccchannels.addAll(SCC.get(i));
     63            }
     64        }
     65        //alle Channels auf nicht zusammenhängend setzen
     66        for (int i = 0; i < nsccchannels.size(); i++) {
     67            nsccchannels.get(i).setStrongConnected(false);
     68        }
     69    }
    7070
    71         private void findBiggestPiece() {
    72                 int number = 0;
    73                 for (int i = 0; i < SCC.size(); i++) {
    74                         if (SCC.get(i).size() > number) {
    75                                 biggestPart = i;
    76                                 number = SCC.get(i).size();
    77                         }
    78                 }
    79         }
     71    private void findBiggestPiece() {
     72        int number = 0;
     73        for (int i = 0; i < SCC.size(); i++) {
     74            if (SCC.get(i).size() > number) {
     75                biggestPart = i;
     76                number = SCC.get(i).size();
     77            }
     78        }
     79    }
    8080
    81         public String showNotstronglyConnectednessParts() {
    82                 String s = new String();
    83                 for (int i = 0; i < SCC.size(); i++) {
    84                         if (i != biggestPart) {
    85                                 s += "GraphKomponente: " + i + "\n";
    86                                 for (int j = 0; j < SCC.get(i).size(); j++) {
    87                                         s += "Channel: " + SCC.get(i).get(j).getNewid();
    88                                 }
    89                                 s += "\n";
    90                         }
    91                 }
    92                 return s;
    93         }
     81    public String showNotstronglyConnectednessParts() {
     82        String s = new String();
     83        for (int i = 0; i < SCC.size(); i++) {
     84            if (i != biggestPart) {
     85                s += "GraphKomponente: " + i + "\n";
     86                for (int j = 0; j < SCC.get(i).size(); j++) {
     87                    s += "Channel: " + SCC.get(i).get(j).getNewid();
     88                }
     89                s += "\n";
     90            }
     91        }
     92        return s;
     93    }
    9494
    95         /**
    96         * gibt eine Arraylist mit all den Channels zurück, welche nicht
    97         * im größten zusammenhägendem Teil des Channel-Digraphen sind
    98         * @return
    99         */
    100         public ArrayList<Channel> getNotConnectedChannels() {
    101                 return nsccchannels;
    102         }
     95    /**
     96    * gibt eine Arraylist mit all den Channels zurück, welche nicht
     97    * im größten zusammenhägendem Teil des Channel-Digraphen sind
     98    * @return
     99    */
     100    public ArrayList<Channel> getNotConnectedChannels() {
     101        return nsccchannels;
     102    }
    103103
    104         private void tarjan(Channel v) {
    105                 //log.trace("tarjan für channel aufgerufen mit id: " + v.getNewid());
    106                 v.setIndex(index);
    107                 v.setLowlink(index);
    108                 index++;
    109                 stack.add(0, v);
    110                 //log.trace("channel "+v.getNewid() + " hat nachbarn: " + v.getLeadsTo().size());
    111                 for (int i = 0; i < v.getLeadsTo().size(); i++) {
    112                         //log.trace("schleifendurchlauf: " + i);
    113                         Channel n = v.getLeadsTo().get(i).getToChannel();
    114                         if (n.getIndex() == -1) {
    115                                 //log.trace("n hat index =-1");
    116                                 tarjan(n);
    117                                 v.setLowlink(Math.min(v.getLowlink(), n.getLowlink()));
    118                         }
    119                         else if (stack.contains(n)) {
    120                                 //log.trace("setze lowlink von n auf: " + v.getLowlink());
    121                                 v.setLowlink(Math.min(v.getLowlink(), n.getLowlink()));
    122                         }
    123                 }
    124                 if (v.getLowlink() == v.getIndex()) {
    125                         Channel n;
    126                         ArrayList<Channel> component = new ArrayList<Channel>();
    127                         do {
    128                                 n = stack.remove(0);
    129                                 component.add(n);
    130                         } while (n != v);
    131                         SCC.add(component);
    132                         calculatedNodes += component.size();
    133                 }
    134         }
     104    private void tarjan(Channel v) {
     105        //log.trace("tarjan für channel aufgerufen mit id: " + v.getNewid());
     106        v.setIndex(index);
     107        v.setLowlink(index);
     108        index++;
     109        stack.add(0, v);
     110        //log.trace("channel "+v.getNewid() + " hat nachbarn: " + v.getLeadsTo().size());
     111        for (int i = 0; i < v.getLeadsTo().size(); i++) {
     112            //log.trace("schleifendurchlauf: " + i);
     113            Channel n = v.getLeadsTo().get(i).getToChannel();
     114            if (n.getIndex() == -1) {
     115                //log.trace("n hat index =-1");
     116                tarjan(n);
     117                v.setLowlink(Math.min(v.getLowlink(), n.getLowlink()));
     118            }
     119            else if (stack.contains(n)) {
     120                //log.trace("setze lowlink von n auf: " + v.getLowlink());
     121                v.setLowlink(Math.min(v.getLowlink(), n.getLowlink()));
     122            }
     123        }
     124        if (v.getLowlink() == v.getIndex()) {
     125            Channel n;
     126            ArrayList<Channel> component = new ArrayList<Channel>();
     127            do {
     128                n = stack.remove(0);
     129                component.add(n);
     130            } while (n != v);
     131            SCC.add(component);
     132            calculatedNodes += component.size();
     133        }
     134    }
    135135}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/converting/ChannelDigraphBuilder.java

    r25501 r30725  
    1313public class ChannelDigraphBuilder {
    1414
    15         private final ChannelDiGraph digraph;
    16         private final OSMGraph osmgraph;
    17         private final OSMWay[] osmways;
    18         private Channel newChannel = new Channel();
    19         private final NodesConnectionProducer ncp;
    20         // Variable wird für die IDs der neu erstellten Ways benötigt, die
    21         // Hinrichtung bekommt den des ursprungs-Way, die Rückrichtung
    22         // eine fiktive negative (OSM-XML-Standard für neue, noch nicht in der DB
    23         // gespeicherte Entities)
    24         private int newid = 1;
    25         private TurnRestrictionChecker trchecker;
    26         Channel backChannel;
     15    private final ChannelDiGraph digraph;
     16    private final OSMGraph osmgraph;
     17    private final OSMWay[] osmways;
     18    private Channel newChannel = new Channel();
     19    private final NodesConnectionProducer ncp;
     20    // Variable wird für die IDs der neu erstellten Ways benötigt, die
     21    // Hinrichtung bekommt den des ursprungs-Way, die Rückrichtung
     22    // eine fiktive negative (OSM-XML-Standard für neue, noch nicht in der DB
     23    // gespeicherte Entities)
     24    private int newid = 1;
     25    private TurnRestrictionChecker trchecker;
     26    Channel backChannel;
    2727
    28         public ChannelDigraphBuilder(OSMGraph osmgraph) {
    29                 //Nodesbeziehungen erstellen
    30                 ncp = new NodesConnectionProducer(osmgraph);
    31                 ncp.produceNodesConnections();
    32                 digraph = new ChannelDiGraph();
    33                 this.osmways = osmgraph.getWays();
    34                 digraph.setBbbottom(osmgraph.getBbbottom());
    35                 digraph.setBbleft(osmgraph.getBbleft());
    36                 digraph.setBbright(osmgraph.getBbright());
    37                 digraph.setBbtop(osmgraph.getBbtop());
    38                 this.osmgraph = osmgraph;
    39         }
     28    public ChannelDigraphBuilder(OSMGraph osmgraph) {
     29        //Nodesbeziehungen erstellen
     30        ncp = new NodesConnectionProducer(osmgraph);
     31        ncp.produceNodesConnections();
     32        digraph = new ChannelDiGraph();
     33        this.osmways = osmgraph.getWays();
     34        digraph.setBbbottom(osmgraph.getBbbottom());
     35        digraph.setBbleft(osmgraph.getBbleft());
     36        digraph.setBbright(osmgraph.getBbright());
     37        digraph.setBbtop(osmgraph.getBbtop());
     38        this.osmgraph = osmgraph;
     39    }
    4040
    41         private void setNewWayID(Channel channel) {
    42                 channel.setNewid(newid);
    43                 newid++;
    44         }
     41    private void setNewWayID(Channel channel) {
     42        channel.setNewid(newid);
     43        newid++;
     44    }
    4545
    46         /**
    47         * Hilfemethode zur Erstellung eines Channels
    48         * @param fromNode fromNode des zu erstellenden Channels
    49         * @param toNode toNode  des zu erstellnenden Channels
    50         * @param way ein zu dem Channel gehörender Way
    51         * @return
    52         */
    53         private Channel createChannel(OSMNode fromNode, OSMNode toNode, OSMWay way) {
    54                 newChannel = new Channel();
    55                 newChannel.setFromNode(fromNode);
    56                 newChannel.setToNode(toNode);
    57                 setNewWayID(newChannel);
    58                 digraph.addChannel(newChannel);
    59                 fromNode.addOutgoingChannel(newChannel);
    60                 newChannel.addWay(way);
    61                 return newChannel;
    62         }
     46    /**
     47    * Hilfemethode zur Erstellung eines Channels
     48    * @param fromNode fromNode des zu erstellenden Channels
     49    * @param toNode toNode  des zu erstellnenden Channels
     50    * @param way ein zu dem Channel gehörender Way
     51    * @return
     52    */
     53    private Channel createChannel(OSMNode fromNode, OSMNode toNode, OSMWay way) {
     54        newChannel = new Channel();
     55        newChannel.setFromNode(fromNode);
     56        newChannel.setToNode(toNode);
     57        setNewWayID(newChannel);
     58        digraph.addChannel(newChannel);
     59        fromNode.addOutgoingChannel(newChannel);
     60        newChannel.addWay(way);
     61        return newChannel;
     62    }
    6363
    64         private void createBackChannel(OSMNode fromNode, OSMNode toNode, OSMWay way, Channel channel) {
    65                 backChannel = new Channel();
    66                 backChannel = createChannel(fromNode, toNode, way);
    67                 backChannel.setBackChannelID(channel.getNewid());
    68                 channel.setBackChannelID(backChannel.getNewid());
    69         }
     64    private void createBackChannel(OSMNode fromNode, OSMNode toNode, OSMWay way, Channel channel) {
     65        backChannel = new Channel();
     66        backChannel = createChannel(fromNode, toNode, way);
     67        backChannel.setBackChannelID(channel.getNewid());
     68        channel.setBackChannelID(backChannel.getNewid());
     69    }
    7070
    71         /**
    72         * erzeugt den Digraphen
    73         */
    74         private void buildChannels(OSMWay way, boolean oneway) {
    75                 Channel tempChannel = new Channel();
     71    /**
     72    * erzeugt den Digraphen
     73    */
     74    private void buildChannels(OSMWay way, boolean oneway) {
     75        Channel tempChannel = new Channel();
    7676
    77                 OSMNode lastUsedNode = way.getFromNode();
    78                 OSMNode[] nodes = way.getNodes();
    79                 /*
    80                 * log.debug("Way mit ID " + way.getId() + " , startnode: " +
    81                 * way.getFromNode().getId() + " , EndNode: " + way.getToNode().getId()
    82                 * + " wird bearbeitet.");
    83                 */
    84                 // alle Knoten eines ways durchgehen
    85                 for (int i = 1; i < nodes.length; i++) {
    86                         // nur wenn der aktuelle Knoten mehr als einen Vorgänger/Nachfolger
    87                         // hat, wird in die if-Abfrage gesprungen und ein neuer Channel mit
    88                         //mit dem aktuell betrachtetem Node als Endnode erzeugt
    89                         if (nodes[i].getPredNodeList().size() > 1 || nodes[i].getSuccNodeList().size() > 1) {
    90                                 tempChannel = createChannel(lastUsedNode, nodes[i], way);
    91                                 // bei Nichteinbahnstraße wird Channel in die andere Richtung
    92                                 // erzeugt
    93                                 if (oneway == false) {
    94                                         createBackChannel(nodes[i], lastUsedNode, way, tempChannel);
    95                                 }
    96                                 lastUsedNode = nodes[i];
    97                         }
    98                         // wenn der betrachtete Knoten keine Nachfolger hat, ist ein
    99                         // Straßenende erreicht. Auch in diesem Fall muß ein Channel erzeugt werden
    100                         else if (nodes[i].getSuccNodeList().size() == 0) {
    101                                 tempChannel = createChannel(lastUsedNode, nodes[i], way);
    102                                 // Rückrichtung wird nur erzeugt, wenn der OSM-Way keine Einbahnstraße ist
    103                                 if (oneway == false) {
    104                                         createBackChannel(nodes[i], lastUsedNode, way, tempChannel);
    105                                 }
    106                         }
    107                         // eine Straße besteht aus 2 Ways, obwohl eigentlich eine reicht
    108                         // tritt z.b. bei einer brücke auf, brücke wird neuer channel
    109                         //TODO: kann an dieser stelle das erzeugen von pseudo-channels verhindert werden?
    110                         //      Idee: speichern eines flags, um diese erzeugten Channels zu markieren. aus diesen informationen
    111                         //            später den CHannel löschen!!!
    112                         else if (i == nodes.length - 1
    113                                         && nodes[i].getSuccNodeList().size() == 1) {
    114                                 // damit ist ein Channel gefunden, und wird mit Werten gefüllt
    115                                 tempChannel = createChannel(lastUsedNode, nodes[i], way);
    116                                 // bei Nichteinbahnstraße wird Channel in die andere Richtung
    117                                 // erzeugt
    118                                 if (oneway == false) {
    119                                         createBackChannel(nodes[i], lastUsedNode, way, tempChannel);
    120                                 }
    121                                 lastUsedNode = nodes[i];
     77        OSMNode lastUsedNode = way.getFromNode();
     78        OSMNode[] nodes = way.getNodes();
     79        /*
     80        * log.debug("Way mit ID " + way.getId() + " , startnode: " +
     81        * way.getFromNode().getId() + " , EndNode: " + way.getToNode().getId()
     82        * + " wird bearbeitet.");
     83        */
     84        // alle Knoten eines ways durchgehen
     85        for (int i = 1; i < nodes.length; i++) {
     86            // nur wenn der aktuelle Knoten mehr als einen Vorgänger/Nachfolger
     87            // hat, wird in die if-Abfrage gesprungen und ein neuer Channel mit
     88            //mit dem aktuell betrachtetem Node als Endnode erzeugt
     89            if (nodes[i].getPredNodeList().size() > 1 || nodes[i].getSuccNodeList().size() > 1) {
     90                tempChannel = createChannel(lastUsedNode, nodes[i], way);
     91                // bei Nichteinbahnstraße wird Channel in die andere Richtung
     92                // erzeugt
     93                if (oneway == false) {
     94                    createBackChannel(nodes[i], lastUsedNode, way, tempChannel);
     95                }
     96                lastUsedNode = nodes[i];
     97            }
     98            // wenn der betrachtete Knoten keine Nachfolger hat, ist ein
     99            // Straßenende erreicht. Auch in diesem Fall muß ein Channel erzeugt werden
     100            else if (nodes[i].getSuccNodeList().size() == 0) {
     101                tempChannel = createChannel(lastUsedNode, nodes[i], way);
     102                // Rückrichtung wird nur erzeugt, wenn der OSM-Way keine Einbahnstraße ist
     103                if (oneway == false) {
     104                    createBackChannel(nodes[i], lastUsedNode, way, tempChannel);
     105                }
     106            }
     107            // eine Straße besteht aus 2 Ways, obwohl eigentlich eine reicht
     108            // tritt z.b. bei einer brücke auf, brücke wird neuer channel
     109            //TODO: kann an dieser stelle das erzeugen von pseudo-channels verhindert werden?
     110            //      Idee: speichern eines flags, um diese erzeugten Channels zu markieren. aus diesen informationen
     111            //            später den CHannel löschen!!!
     112            else if (i == nodes.length - 1
     113                    && nodes[i].getSuccNodeList().size() == 1) {
     114                // damit ist ein Channel gefunden, und wird mit Werten gefüllt
     115                tempChannel = createChannel(lastUsedNode, nodes[i], way);
     116                // bei Nichteinbahnstraße wird Channel in die andere Richtung
     117                // erzeugt
     118                if (oneway == false) {
     119                    createBackChannel(nodes[i], lastUsedNode, way, tempChannel);
     120                }
     121                lastUsedNode = nodes[i];
    122122
    123                         }
     123            }
    124124
    125                 }
    126         }
     125        }
     126    }
    127127
    128         /**
    129         * baut den ChannelDigraph
    130         */
    131         public void buildChannelDigraph() {
    132                 // alle Wege eines OSMGraphen durchgehen
    133                 for (int i = 0; i < osmways.length; i++) {
    134                         buildChannels(osmways[i], osmways[i].isOneWay());
    135                 }
    136                 trchecker = new TurnRestrictionChecker(osmgraph, digraph);
    137                 trchecker.createLeadsTo();
    138                 PseudoChannelRemover pcr = new PseudoChannelRemover(digraph); //überflüssige Channels entfernen
    139                 pcr.removePseudoChannels();
    140         }
     128    /**
     129    * baut den ChannelDigraph
     130    */
     131    public void buildChannelDigraph() {
     132        // alle Wege eines OSMGraphen durchgehen
     133        for (int i = 0; i < osmways.length; i++) {
     134            buildChannels(osmways[i], osmways[i].isOneWay());
     135        }
     136        trchecker = new TurnRestrictionChecker(osmgraph, digraph);
     137        trchecker.createLeadsTo();
     138        PseudoChannelRemover pcr = new PseudoChannelRemover(digraph); //überflüssige Channels entfernen
     139        pcr.removePseudoChannels();
     140    }
    141141
    142         public ChannelDiGraph getDigraph() {
    143                 return digraph;
    144         }
     142    public ChannelDiGraph getDigraph() {
     143        return digraph;
     144    }
    145145
    146         public void setNewid(int newid) {
    147                 this.newid = newid;
    148         }
     146    public void setNewid(int newid) {
     147        this.newid = newid;
     148    }
    149149
    150         public int getNewid() {
    151                 return newid;
    152         }
     150    public int getNewid() {
     151        return newid;
     152    }
    153153}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/converting/NodesConnectionProducer.java

    r25501 r30725  
    1111 */
    1212public class NodesConnectionProducer {
    13        
    14         private OSMGraph osmgraph;
    15         private OSMWay[] osmways;
     13   
     14    private OSMGraph osmgraph;
     15    private OSMWay[] osmways;
    1616
    17         public NodesConnectionProducer(OSMGraph osmgraph) {
    18                 this.osmgraph = osmgraph;
    19                 osmways = this.osmgraph.getWays();
    20         }
    21        
    22         public void produceNodesConnections() {
    23                 OSMNode[] waynodes;
    24                 for (int i = 0; i < osmways.length; i++) {
    25                         waynodes = osmways[i].getNodes();
    26                         for (int j = 0; j < waynodes.length - 1; j++) {
    27                                 waynodes[j].addSuccNode(waynodes[j+1]);
    28                                 waynodes[j+1].addPredNode(waynodes[j]);
    29                         }
    30                 }
    31         }
     17    public NodesConnectionProducer(OSMGraph osmgraph) {
     18        this.osmgraph = osmgraph;
     19        osmways = this.osmgraph.getWays();
     20    }
     21   
     22    public void produceNodesConnections() {
     23        OSMNode[] waynodes;
     24        for (int i = 0; i < osmways.length; i++) {
     25            waynodes = osmways[i].getNodes();
     26            for (int j = 0; j < waynodes.length - 1; j++) {
     27                waynodes[j].addSuccNode(waynodes[j+1]);
     28                waynodes[j+1].addPredNode(waynodes[j]);
     29            }
     30        }
     31    }
    3232
    3333}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/converting/PseudoChannelRemover.java

    r29854 r30725  
    1212public class PseudoChannelRemover {
    1313
    14         private final ChannelDiGraph digraph;
    15         //private final ArrayList<Channel> pseudochannels = new ArrayList<Channel>();
    16         private Channel succChannel;
    17         private Channel tempToChannel;
    18         private LeadsTo tempLeadsTo;
     14    private final ChannelDiGraph digraph;
     15    //private final ArrayList<Channel> pseudochannels = new ArrayList<Channel>();
     16    private Channel succChannel;
     17    private Channel tempToChannel;
     18    private LeadsTo tempLeadsTo;
    1919
    20         public PseudoChannelRemover(ChannelDiGraph digraph) {
    21                 this.digraph = digraph;
    22         }
     20    public PseudoChannelRemover(ChannelDiGraph digraph) {
     21        this.digraph = digraph;
     22    }
    2323
    24         private void mergeChannel(Channel tempchannel) {
    25                 succChannel = tempchannel.getLeadsTo().get(0).getToChannel();
    26                 tempchannel.setToNode(succChannel.getToNode());
    27                 //log.trace("---Folgender Channel ist überflüssig: " + succChannel.getNewid() + "---");
    28                 //log.trace("... und wird durch diesen ersetzt: " + tempchannel.getNewid());
    29                 //VorgängerChannel der nachfolgenden Channels des zu löschenden, überflüssigen Channels neu setzen
    30                 for (int i = 0; i < succChannel.getLeadsTo().size(); i++) {
    31                         for (int j = 0; j < succChannel.getLeadsTo().get(i).getToChannel().getPredChannels().size(); j++) {
    32                                 if (succChannel.getLeadsTo().get(i).getToChannel().getPredChannels().get(j).getNewid() == succChannel.getNewid()) {
    33                                         succChannel.getLeadsTo().get(i).getToChannel().getPredChannels().remove(j);
    34                                         succChannel.getLeadsTo().get(i).getToChannel().addPredChannel(tempchannel);
    35                                 }
    36                         }
    37                 }
     24    private void mergeChannel(Channel tempchannel) {
     25        succChannel = tempchannel.getLeadsTo().get(0).getToChannel();
     26        tempchannel.setToNode(succChannel.getToNode());
     27        //log.trace("---Folgender Channel ist überflüssig: " + succChannel.getNewid() + "---");
     28        //log.trace("... und wird durch diesen ersetzt: " + tempchannel.getNewid());
     29        //VorgängerChannel der nachfolgenden Channels des zu löschenden, überflüssigen Channels neu setzen
     30        for (int i = 0; i < succChannel.getLeadsTo().size(); i++) {
     31            for (int j = 0; j < succChannel.getLeadsTo().get(i).getToChannel().getPredChannels().size(); j++) {
     32                if (succChannel.getLeadsTo().get(i).getToChannel().getPredChannels().get(j).getNewid() == succChannel.getNewid()) {
     33                    succChannel.getLeadsTo().get(i).getToChannel().getPredChannels().remove(j);
     34                    succChannel.getLeadsTo().get(i).getToChannel().addPredChannel(tempchannel);
     35                }
     36            }
     37        }
    3838
    39                 //LeadsTo des zu ersetzenden Channels für den neuen Channel neu erzeugen
    40                 tempchannel.removeLeadsTo();
    41                 for (int i = 0; i < succChannel.getLeadsTo().size(); i++) {
    42                         tempToChannel = succChannel.getLeadsTo().get(i).getToChannel();
    43                         //log.trace("tempToChannel: " + tempToChannel.toString());
    44                         tempLeadsTo = new LeadsTo(tempchannel, tempToChannel);
    45                         //log.trace(i + ". Durchlauf: Füge ledasTo hinzu: " + tempLeadsTo.toString());
    46                         digraph.addLeadsTo(tempLeadsTo);
    47                 }
     39        //LeadsTo des zu ersetzenden Channels für den neuen Channel neu erzeugen
     40        tempchannel.removeLeadsTo();
     41        for (int i = 0; i < succChannel.getLeadsTo().size(); i++) {
     42            tempToChannel = succChannel.getLeadsTo().get(i).getToChannel();
     43            //log.trace("tempToChannel: " + tempToChannel.toString());
     44            tempLeadsTo = new LeadsTo(tempchannel, tempToChannel);
     45            //log.trace(i + ". Durchlauf: Füge ledasTo hinzu: " + tempLeadsTo.toString());
     46            digraph.addLeadsTo(tempLeadsTo);
     47        }
    4848
    49                 //TODO: quick'n'dirty
    50                 ArrayList< LeadsTo> tls = succChannel.getLeadsTo();
    51                 for (int i = 0; i < tls.size(); i++) {
    52                         digraph.removeLeadsTo(tls.get(i));
    53                 }
    54                 digraph.removeChannel(succChannel);
    55                 //pseudochannels.add(tempchannel.getSuccChannels().get(0));
    56         }
     49        //TODO: quick'n'dirty
     50        ArrayList< LeadsTo> tls = succChannel.getLeadsTo();
     51        for (int i = 0; i < tls.size(); i++) {
     52            digraph.removeLeadsTo(tls.get(i));
     53        }
     54        digraph.removeChannel(succChannel);
     55        //pseudochannels.add(tempchannel.getSuccChannels().get(0));
     56    }
    5757
    58         public void removePseudoChannels() {
    59                 Channel tempChannel;
    60                 for (int i = 0; i < digraph.getChannels().size(); i++) {
    61                         tempChannel = digraph.getChannelAtPosition(i);
    62                         while (digraph.isInBBox(tempChannel.getToNode())
    63                                         && (tempChannel.getLeadsTo().size() == 1)
    64                                         && (tempChannel.getLeadsTo().get(0).getToChannel().getPredChannels().size() <= 1)
    65                                         && (tempChannel.getBackChannelID() != tempChannel.getLeadsTo().get(0).getToChannel().getNewid())) {
    66                                 // dies if-abfrage verhindert eine endlosschleife, wenn der
    67                                 // channel ein kreisverkehr istjava
    68                                 if (tempChannel.getLeadsTo().get(0).getToChannel().equals(tempChannel)) {
    69                                         break;
    70                                 } else {
    71                                         mergeChannel(tempChannel);
    72                                 }
    73                         }
     58    public void removePseudoChannels() {
     59        Channel tempChannel;
     60        for (int i = 0; i < digraph.getChannels().size(); i++) {
     61            tempChannel = digraph.getChannelAtPosition(i);
     62            while (digraph.isInBBox(tempChannel.getToNode())
     63                    && (tempChannel.getLeadsTo().size() == 1)
     64                    && (tempChannel.getLeadsTo().get(0).getToChannel().getPredChannels().size() <= 1)
     65                    && (tempChannel.getBackChannelID() != tempChannel.getLeadsTo().get(0).getToChannel().getNewid())) {
     66                // dies if-abfrage verhindert eine endlosschleife, wenn der
     67                // channel ein kreisverkehr istjava
     68                if (tempChannel.getLeadsTo().get(0).getToChannel().equals(tempChannel)) {
     69                    break;
     70                } else {
     71                    mergeChannel(tempChannel);
     72                }
     73            }
    7474
    75                 }
    76         }
     75        }
     76    }
    7777}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/converting/TurnRestrictionChecker.java

    r29854 r30725  
    1818public class TurnRestrictionChecker {
    1919
    20         private final ArrayList<OSMRelation> turnrestrictionsrelations = new ArrayList<OSMRelation>();
    21         private final ChannelDiGraph channelDigraph;
    22         private int relationpointer;
    23         private LeadsTo tempLeadsTo;
     20    private final ArrayList<OSMRelation> turnrestrictionsrelations = new ArrayList<OSMRelation>();
     21    private final ChannelDiGraph channelDigraph;
     22    private int relationpointer;
     23    private LeadsTo tempLeadsTo;
    2424
    25         public TurnRestrictionChecker(OSMGraph graph, ChannelDiGraph channelDigraph) {
    26                 // von den Relationen des Graphen nur die Abbiegevorschriften kopieren
    27                 for (int i = 0; i < graph.getRelations().length; i++) {
    28                         if (graph.getRelations()[i].hasKey("type")) {
    29                                 if (graph.getRelations()[i].getValue("type").equals(
    30                                 "restriction")) {
    31                                         turnrestrictionsrelations.add(graph.getRelations()[i]);
    32                                 }
    33                         }
    34                 }
    35                 this.channelDigraph = channelDigraph;
    36         }
     25    public TurnRestrictionChecker(OSMGraph graph, ChannelDiGraph channelDigraph) {
     26        // von den Relationen des Graphen nur die Abbiegevorschriften kopieren
     27        for (int i = 0; i < graph.getRelations().length; i++) {
     28            if (graph.getRelations()[i].hasKey("type")) {
     29                if (graph.getRelations()[i].getValue("type").equals(
     30                "restriction")) {
     31                    turnrestrictionsrelations.add(graph.getRelations()[i]);
     32                }
     33            }
     34        }
     35        this.channelDigraph = channelDigraph;
     36    }
    3737
    38         private boolean checkForRelations(Channel channel) {
    39                 for (int k = 0; k < turnrestrictionsrelations.size(); k++) {
    40                         //log.trace("betrachte relation in liste an position:" + k);
    41                         for (int i = 0; i < channel.getWays().size(); i++) {
    42                                 if (turnrestrictionsrelations.get(k).getMember("from").getId() == channel
    43                                                 .getWays().get(i).getId()
    44                                                 && turnrestrictionsrelations.get(k).getMember("via")
    45                                                 .getId() == channel.getToNode().getId()) {
    46                                         relationpointer = k;
    47                                         return true;
    48                                 }
    49                         }
    50                 }
    51                 return false;
    52         }
     38    private boolean checkForRelations(Channel channel) {
     39        for (int k = 0; k < turnrestrictionsrelations.size(); k++) {
     40            //log.trace("betrachte relation in liste an position:" + k);
     41            for (int i = 0; i < channel.getWays().size(); i++) {
     42                if (turnrestrictionsrelations.get(k).getMember("from").getId() == channel
     43                        .getWays().get(i).getId()
     44                        && turnrestrictionsrelations.get(k).getMember("via")
     45                        .getId() == channel.getToNode().getId()) {
     46                    relationpointer = k;
     47                    return true;
     48                }
     49            }
     50        }
     51        return false;
     52    }
    5353
    54         private void produceLeadsToFromRelation(Channel fromChannel,
    55                         Channel toChannel) {
    56                 if (toChannel.getWays().contains(
    57                                 turnrestrictionsrelations.get(relationpointer).getMember("to"))) {
    58                         if (turnrestrictionsrelations.get(relationpointer).getValue(
    59                         "restriction").startsWith("only")) {
     54    private void produceLeadsToFromRelation(Channel fromChannel,
     55            Channel toChannel) {
     56        if (toChannel.getWays().contains(
     57                turnrestrictionsrelations.get(relationpointer).getMember("to"))) {
     58            if (turnrestrictionsrelations.get(relationpointer).getValue(
     59            "restriction").startsWith("only")) {
    6060
    61                                 tempLeadsTo = new LeadsTo(fromChannel, toChannel);
    62                                 channelDigraph.addLeadsTo(tempLeadsTo);
    63                                 toChannel.addPredChannel(fromChannel);
    64                         }
    65                         /*
    66                         * der no_* Fall: wie oben, nur das hier nichts geschieht
    67                         */
    68                         else if (turnrestrictionsrelations.get(relationpointer).getValue(
    69                         "restriction").startsWith("no")) {
    70                                 for (int i = 0; i < fromChannel.getToNode()
    71                                 .getOutgoingChannels().size(); i++) {
    72                                         if (fromChannel.getToNode().getOutgoingChannels().get(i) != toChannel) {
    73                                                 tempLeadsTo = new LeadsTo(fromChannel, fromChannel
    74                                                                 .getToNode().getOutgoingChannels().get(i));
    75                                                 channelDigraph.addLeadsTo(tempLeadsTo);
    76                                                 fromChannel.getToNode().getOutgoingChannels().get(i)
    77                                                 .addPredChannel(fromChannel);
    78                                         }
    79                                 }
    80                         }
    81                 }
     61                tempLeadsTo = new LeadsTo(fromChannel, toChannel);
     62                channelDigraph.addLeadsTo(tempLeadsTo);
     63                toChannel.addPredChannel(fromChannel);
     64            }
     65            /*
     66            * der no_* Fall: wie oben, nur das hier nichts geschieht
     67            */
     68            else if (turnrestrictionsrelations.get(relationpointer).getValue(
     69            "restriction").startsWith("no")) {
     70                for (int i = 0; i < fromChannel.getToNode()
     71                .getOutgoingChannels().size(); i++) {
     72                    if (fromChannel.getToNode().getOutgoingChannels().get(i) != toChannel) {
     73                        tempLeadsTo = new LeadsTo(fromChannel, fromChannel
     74                                .getToNode().getOutgoingChannels().get(i));
     75                        channelDigraph.addLeadsTo(tempLeadsTo);
     76                        fromChannel.getToNode().getOutgoingChannels().get(i)
     77                        .addPredChannel(fromChannel);
     78                    }
     79                }
     80            }
     81        }
    8282
    83         }
     83    }
    8484
    85         /**
    86         * startet die LeadsTo Erstellung
    87         */
    88         public void createLeadsTo() {
    89                 Channel tempChannel;
    90                 for (int i = 0; i < channelDigraph.getChannels().size(); i++) {
    91                         tempChannel = channelDigraph.getChannelAtPosition(i);
    92                         boolean isInRelation = checkForRelations(tempChannel);
    93                         for (int j = 0; j < tempChannel.getToNode().getOutgoingChannels()
    94                         .size(); j++) {
    95                                 if (isInRelation) {
    96                                         produceLeadsToFromRelation(tempChannel, tempChannel
    97                                                         .getToNode().getOutgoingChannels().get(j));
    98                                         // es wird nur dann ein leadsTo erzeugt, wenn der vom
    99                                         // Endknoten des Channels
    100                                         // ausgehende Channel NICHT der Channel in Rückrichtung ist
    101                                         // Ausnahme: es gibt nur diesen einen Channel (Wegende eines
    102                                         // Ways, der an keine weitere
    103                                         // Straße trifft
    104                                 } else if (tempChannel.getBackChannelID() != tempChannel
    105                                                 .getToNode().getOutgoingChannels().get(j).getNewid()
    106                                                 || tempChannel.getToNode().getOutgoingChannels().size() == 1) {
    107                                         tempLeadsTo = new LeadsTo(tempChannel, tempChannel
    108                                                         .getToNode().getOutgoingChannels().get(j));
    109                                         channelDigraph.addLeadsTo(tempLeadsTo);
    110                                         tempChannel.getToNode().getOutgoingChannels().get(j)
    111                                         .addPredChannel(tempChannel);
    112                                 }
    113                         }
    114                 }
    115         }
     85    /**
     86    * startet die LeadsTo Erstellung
     87    */
     88    public void createLeadsTo() {
     89        Channel tempChannel;
     90        for (int i = 0; i < channelDigraph.getChannels().size(); i++) {
     91            tempChannel = channelDigraph.getChannelAtPosition(i);
     92            boolean isInRelation = checkForRelations(tempChannel);
     93            for (int j = 0; j < tempChannel.getToNode().getOutgoingChannels()
     94            .size(); j++) {
     95                if (isInRelation) {
     96                    produceLeadsToFromRelation(tempChannel, tempChannel
     97                            .getToNode().getOutgoingChannels().get(j));
     98                    // es wird nur dann ein leadsTo erzeugt, wenn der vom
     99                    // Endknoten des Channels
     100                    // ausgehende Channel NICHT der Channel in Rückrichtung ist
     101                    // Ausnahme: es gibt nur diesen einen Channel (Wegende eines
     102                    // Ways, der an keine weitere
     103                    // Straße trifft
     104                } else if (tempChannel.getBackChannelID() != tempChannel
     105                        .getToNode().getOutgoingChannels().get(j).getNewid()
     106                        || tempChannel.getToNode().getOutgoingChannels().size() == 1) {
     107                    tempLeadsTo = new LeadsTo(tempChannel, tempChannel
     108                            .getToNode().getOutgoingChannels().get(j));
     109                    channelDigraph.addLeadsTo(tempLeadsTo);
     110                    tempChannel.getToNode().getOutgoingChannels().get(j)
     111                    .addPredChannel(tempChannel);
     112                }
     113            }
     114        }
     115    }
    116116}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/datastructure/BasicChannel.java

    r25501 r30725  
    99public class BasicChannel {
    1010
    11         private OSMNode toNode;
    12         private OSMNode fromNode;
    13         private ArrayList<LeadsTo> leadsTo = new ArrayList<LeadsTo>();
    14         private final ArrayList<OSMWay> ways = new ArrayList<OSMWay>();
    15         private int newid;
    16         //gibt es nur, wenn ein Channelobjekt aus einer Nichteinbahnstraße erzeugt wurde (backchannelID ist dann die ID des anderen Channels)
    17         private int backChannelID = -100;
    18         private final ArrayList<Channel> predChannels = new ArrayList<Channel>();
    19 
    20         //werden für den Tarjan-Algorithmus gebraucht
    21         private int lowlink = -1;
    22         private int index = -1;
    23 
    24         /**
    25         * fügt einen Vorgängerchannel hinzu
    26         * @param channel der voherige Channel
    27         */
    28         public void addPredChannel(Channel channel) {
    29                 predChannels.add(channel);
    30         }
    31 
    32         /**
    33         * setzt den ToNode
    34         * @param toNode
    35         */
    36         public void setToNode(OSMNode toNode) {
    37                 this.toNode = toNode;
    38         }
    39 
    40         /**
    41         * gbit den ToNode zurück
    42         */
    43         public OSMNode getToNode() {
    44                 return toNode;
    45         }
    46 
    47         /**
    48         * setzt den FromNode
    49         */
    50         public void setFromNode(OSMNode fromNode) {
    51                 this.fromNode = fromNode;
    52         }
    53 
    54         /**
    55         * gibt den FromNode zurück
    56         */
    57         public OSMNode getFromNode() {
    58                 return fromNode;
    59         }
    60 
    61         /**
    62         * fügt eine LeadsTo-Beziehung hinzu
    63         * @param leadsTo
    64         */
    65         public void addLeadsTo(LeadsTo leadsTo) {
    66                 this.leadsTo.add(leadsTo);
    67         }
    68 
    69         /**
    70         * setzt alle leadsTo-Beziehungen (löscht alle voherigen)
    71         */
    72         public void setLeadsTo(ArrayList<LeadsTo> leadsTo) {
    73                 this.leadsTo = leadsTo;
    74         }
    75 
    76         /**
    77         * löscht alle LeadsTo des Channels
    78         */
    79         public void removeLeadsTo() {
    80                 this.leadsTo.clear();
    81         }
    82 
    83         /**
    84         * gibt alle leadsTo zurück
    85         * @return
    86         */
    87         public ArrayList<LeadsTo> getLeadsTo() {
    88                 return leadsTo;
    89         }
    90 
    91         /**
    92         * fügt einen Way hinzu, aus dem der Channel enstanden ist
    93         * es gibt immer mind. einen Way, es können aber auch mehr sein
    94         * @param way
    95         */
    96         public void addWay(OSMWay way) {
    97                 this.ways.add(way);
    98         }
    99 
    100         /**
    101         * gibt alle Ways zurück
    102         * @return
    103         */
    104         public ArrayList<OSMWay> getWays() {
    105                 return ways;
    106         }
    107 
    108         /**
    109         * gibt nur den ersten Way der ArrayList zurück! wird bei der
    110         * XML-datei-Erzeugung benutzt, um den Way, der aus dem Channel entsteht,
    111         * mit Werten zu füllen dabei gehen Informationen verloren, da ein Channel
    112         * aus mehr als einem Way bestehen kann
    113         *
    114         * @return
    115         */
    116         public OSMWay getWay() {
    117                 return ways.get(0);
    118         }
    119 
    120         /**
    121         * setzt die ID des Channels. es kann nicht die ID des Ways übernommen werden, da aus einem Way oftmals mehrere Channels entstehen (z.B. bei jeder Nichteinbahnstraße mind. 2)
    122         */
    123         public void setNewid(int newid) {
    124                 this.newid = newid;
    125         }
    126 
    127         /**
    128         * gbit die NewID zurück
    129         */
    130         public int getNewid() {
    131                 return newid;
    132         }
    133 
    134         /**
    135         * gibt alle VorgängerChannels zurück
    136         * @return
    137         */
    138         public ArrayList<Channel> getPredChannels() {
    139                 return predChannels;
    140         }
    141 
    142         /**
    143         * ToString Methode
    144         */
    145         @Override
    146         public String toString() {
    147                 String lt ="";
    148                 for (int i = 0; i < leadsTo.size(); i++) {
    149                         lt += leadsTo.get(i).getToChannel().getNewid() + ", ";
    150                 }
    151                 String predch = "";
    152                 for (int i = 0; i < predChannels.size(); i++) {
    153                         predch += predChannels.get(i).getNewid() + ", ";
    154                 }
    155                 return "[ChannelID: "+ newid + ":AnzahlPredCH: " + predChannels.size() + ":PredCh: " + predch +  ":AnzahlSuccCH: " + leadsTo.size() +":LeadsTo: " + lt+ ":backCHID: " + backChannelID + "]";
    156         }
    157 
    158         public void setBackChannelID(int backChannelID) {
    159                 this.backChannelID = backChannelID;
    160         }
    161 
    162         public int getBackChannelID() {
    163                 return backChannelID;
    164         }
    165 
    166         /**
    167         * wandelt den Channel in einen OSMWay um
    168         * dabie werden die Werte des 1. Way, der im Channel ist, übernommen, wenn ein
    169         * 1. Channel existiert
    170         */
    171         public OSMWay ToOSMWay() {
    172                 OSMWay way = new OSMWay();
    173                 way.addNode(this.fromNode);
    174                 way.addNode(this.toNode);
    175                 way.setId((long)this.newid);
    176                 if (this.getWay() != null) {
    177                         way.setHashmap(this.getWay().getHashmap());
    178                 }
    179                 return way;
    180         }
    181 
    182         public void ereasePredChannel(Channel rchannel) {
    183                 predChannels.remove(rchannel);
    184         }
    185 
    186         public int getLowlink() {
    187                 return lowlink;
    188         }
    189 
    190         public void setLowlink(int lowlink) {
    191                 this.lowlink = lowlink;
    192         }
    193 
    194         public int getIndex() {
    195                 return index;
    196         }
    197 
    198         public void setIndex(int index) {
    199                 this.index = index;
    200         }
    201 
    202         public void removeLeadsTo(LeadsTo leadsTo) {
    203                 this.leadsTo.remove(leadsTo);
    204         }
     11    private OSMNode toNode;
     12    private OSMNode fromNode;
     13    private ArrayList<LeadsTo> leadsTo = new ArrayList<LeadsTo>();
     14    private final ArrayList<OSMWay> ways = new ArrayList<OSMWay>();
     15    private int newid;
     16    //gibt es nur, wenn ein Channelobjekt aus einer Nichteinbahnstraße erzeugt wurde (backchannelID ist dann die ID des anderen Channels)
     17    private int backChannelID = -100;
     18    private final ArrayList<Channel> predChannels = new ArrayList<Channel>();
     19
     20    //werden für den Tarjan-Algorithmus gebraucht
     21    private int lowlink = -1;
     22    private int index = -1;
     23
     24    /**
     25    * fügt einen Vorgängerchannel hinzu
     26    * @param channel der voherige Channel
     27    */
     28    public void addPredChannel(Channel channel) {
     29        predChannels.add(channel);
     30    }
     31
     32    /**
     33    * setzt den ToNode
     34    * @param toNode
     35    */
     36    public void setToNode(OSMNode toNode) {
     37        this.toNode = toNode;
     38    }
     39
     40    /**
     41    * gbit den ToNode zurück
     42    */
     43    public OSMNode getToNode() {
     44        return toNode;
     45    }
     46
     47    /**
     48    * setzt den FromNode
     49    */
     50    public void setFromNode(OSMNode fromNode) {
     51        this.fromNode = fromNode;
     52    }
     53
     54    /**
     55    * gibt den FromNode zurück
     56    */
     57    public OSMNode getFromNode() {
     58        return fromNode;
     59    }
     60
     61    /**
     62    * fügt eine LeadsTo-Beziehung hinzu
     63    * @param leadsTo
     64    */
     65    public void addLeadsTo(LeadsTo leadsTo) {
     66        this.leadsTo.add(leadsTo);
     67    }
     68
     69    /**
     70    * setzt alle leadsTo-Beziehungen (löscht alle voherigen)
     71    */
     72    public void setLeadsTo(ArrayList<LeadsTo> leadsTo) {
     73        this.leadsTo = leadsTo;
     74    }
     75
     76    /**
     77    * löscht alle LeadsTo des Channels
     78    */
     79    public void removeLeadsTo() {
     80        this.leadsTo.clear();
     81    }
     82
     83    /**
     84    * gibt alle leadsTo zurück
     85    * @return
     86    */
     87    public ArrayList<LeadsTo> getLeadsTo() {
     88        return leadsTo;
     89    }
     90
     91    /**
     92    * fügt einen Way hinzu, aus dem der Channel enstanden ist
     93    * es gibt immer mind. einen Way, es können aber auch mehr sein
     94    * @param way
     95    */
     96    public void addWay(OSMWay way) {
     97        this.ways.add(way);
     98    }
     99
     100    /**
     101    * gibt alle Ways zurück
     102    * @return
     103    */
     104    public ArrayList<OSMWay> getWays() {
     105        return ways;
     106    }
     107
     108    /**
     109    * gibt nur den ersten Way der ArrayList zurück! wird bei der
     110    * XML-datei-Erzeugung benutzt, um den Way, der aus dem Channel entsteht,
     111    * mit Werten zu füllen dabei gehen Informationen verloren, da ein Channel
     112    * aus mehr als einem Way bestehen kann
     113    *
     114    * @return
     115    */
     116    public OSMWay getWay() {
     117        return ways.get(0);
     118    }
     119
     120    /**
     121    * setzt die ID des Channels. es kann nicht die ID des Ways übernommen werden, da aus einem Way oftmals mehrere Channels entstehen (z.B. bei jeder Nichteinbahnstraße mind. 2)
     122    */
     123    public void setNewid(int newid) {
     124        this.newid = newid;
     125    }
     126
     127    /**
     128    * gbit die NewID zurück
     129    */
     130    public int getNewid() {
     131        return newid;
     132    }
     133
     134    /**
     135    * gibt alle VorgängerChannels zurück
     136    * @return
     137    */
     138    public ArrayList<Channel> getPredChannels() {
     139        return predChannels;
     140    }
     141
     142    /**
     143    * ToString Methode
     144    */
     145    @Override
     146    public String toString() {
     147        String lt ="";
     148        for (int i = 0; i < leadsTo.size(); i++) {
     149            lt += leadsTo.get(i).getToChannel().getNewid() + ", ";
     150        }
     151        String predch = "";
     152        for (int i = 0; i < predChannels.size(); i++) {
     153            predch += predChannels.get(i).getNewid() + ", ";
     154        }
     155        return "[ChannelID: "+ newid + ":AnzahlPredCH: " + predChannels.size() + ":PredCh: " + predch +  ":AnzahlSuccCH: " + leadsTo.size() +":LeadsTo: " + lt+ ":backCHID: " + backChannelID + "]";
     156    }
     157
     158    public void setBackChannelID(int backChannelID) {
     159        this.backChannelID = backChannelID;
     160    }
     161
     162    public int getBackChannelID() {
     163        return backChannelID;
     164    }
     165
     166    /**
     167    * wandelt den Channel in einen OSMWay um
     168    * dabie werden die Werte des 1. Way, der im Channel ist, übernommen, wenn ein
     169    * 1. Channel existiert
     170    */
     171    public OSMWay ToOSMWay() {
     172        OSMWay way = new OSMWay();
     173        way.addNode(this.fromNode);
     174        way.addNode(this.toNode);
     175        way.setId((long)this.newid);
     176        if (this.getWay() != null) {
     177            way.setHashmap(this.getWay().getHashmap());
     178        }
     179        return way;
     180    }
     181
     182    public void ereasePredChannel(Channel rchannel) {
     183        predChannels.remove(rchannel);
     184    }
     185
     186    public int getLowlink() {
     187        return lowlink;
     188    }
     189
     190    public void setLowlink(int lowlink) {
     191        this.lowlink = lowlink;
     192    }
     193
     194    public int getIndex() {
     195        return index;
     196    }
     197
     198    public void setIndex(int index) {
     199        this.index = index;
     200    }
     201
     202    public void removeLeadsTo(LeadsTo leadsTo) {
     203        this.leadsTo.remove(leadsTo);
     204    }
    205205}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/datastructure/Channel.java

    r25501 r30725  
    1212public class Channel extends BasicChannel{
    1313
    14         //für den Junctioncheck
    15         private int indegree;
    16         private int outdegree;
    17         private boolean subgraph;
    18         private int visited = BacktrackingColors.WHITE;
    19         private final ArrayList<Channel> reachableNodes = new ArrayList<Channel>();
    20         private int ennr;
    21         private boolean isStrongConnected = true;
    22         private boolean isSelected = false; //wird für den eigenen Layer benötigt, um markierte Channels zu erhalten
    23         private boolean isPartOfJunction = false; //wird für den eigenen Layer benötigt, um Teile einer Kreuzung farbig repräsentieren zu können
    24        
    25         private final HashMap<Channel , ArrayList<Channel>> paths2 = new HashMap<Channel , ArrayList<Channel>>();
    26 
    27 
    28         public Channel(OSMNode fromNode, OSMNode toNode) {
    29                 super();
    30                 this.setFromNode(fromNode);
    31                 this.setToNode(toNode);
    32                 this.subgraph = false;
    33                 this.indegree = 0;
    34                 this.outdegree = 0;
    35         }
    36 
    37         public Channel(){
    38                 super();
    39                 //this.insidenodes = new ArrayList<OSMNode>();
    40                 this.subgraph = false;
    41                 this.indegree = 0;
    42                 this.outdegree = 0;
    43         }
    44 
    45         /**
    46         * gibt die Anzahl der auf diesen Channel verweisenden leadsTo zurück
    47         * @return
    48         */
    49         public int getIndegree() {
    50                 return indegree;
    51         }
    52 
    53         /**
    54         * gibt die Anzahl der aus diesem Channel gehenden leadsTo zurück
    55         * @return
    56         */
    57         public int getOutdegree() {
    58                 return outdegree;
    59         }
    60 
    61         public void setIndegree(int i) {
    62                 this.indegree = i;
    63         }
    64 
    65         public void setOutdegree(int i){
    66                 this.outdegree = i;
    67         }
    68 
    69         /**
    70         * ist dieser Channel Teil der zu untersuchenden Kreuzung?
    71         */
    72         public boolean isSubgraph() {
    73                 return subgraph;
    74         }
    75 
    76         public void setSubgraph(boolean subgraph) {
    77                 this.subgraph = subgraph;
    78         }
    79 
    80         /**
    81         * setzt die Farbe des Channels für den TRDFS white = unbesucht grey = besucht, aber noch nicht beendet black = besucht nund abgeschlossen
    82         */
    83         public int getVisited() {
    84                 return visited;
    85         }
    86 
    87         public void setVisited(int visited) {
    88                 this.visited = visited;
    89         }
    90 
    91         /**
    92         * gibt die von diesem Channel zu erreichenden anderen CHannels zurück
    93         * @return
    94         */
    95         public ArrayList<Channel> getReachableNodes() {
    96                 return reachableNodes;
    97         }
    98 
    99         /**
    100         * setzt die zu erreichenden Channels alle anderen werden gelöscht
    101         * @param  reachableNodes
    102         */
    103         public int getEnnr() {
    104                 return ennr;
    105         }
    106 
    107         /**
    108         * setzt die Anzahl der EingangsChannel
    109         * @param  ennr
    110         */
    111         public void setEnnr(int ennr) {
    112                 this.ennr = ennr;
    113         }
    114 
    115         /**
    116         * erhöht den Wert der Anzhal der EingangsledasTo um 1
    117         */
    118         public void countupIndegree() {
    119                 indegree++;
    120         }
    121 
    122         /**
    123         * erhöht den Wert der Anzahl der AusgangsleadsTo um 1
    124         */
    125         public void countupOutdegree() {
    126                 outdegree++;
    127         }
    128 
    129         /**
    130         * fügt einen erreichbaren Channel hinzu
    131         * @param node
    132         */
    133         public void addReachableNode(Channel node) {
    134                 if (!reachableNodes.contains(node)) {
    135                         reachableNodes.add(node);
    136                         paths2.put(node, new ArrayList<Channel>());
    137                 }
    138         }
    139 
    140         /**
    141         * gibt den an der Position i gespeicherten erreichbaren Channel zurück
    142         * @param i
    143         * @return
    144         */
    145         public Channel getReachableNodeAt(int i) {
    146                 return reachableNodes.get(i);
    147         }
    148 
    149         /**
    150         * löscht alle erreichbaren Channels
    151         */
    152         public void ereaseReachableNodes() {
    153                 reachableNodes.clear();
    154         }
    155 
    156         /**
    157         * setzt Wert der erreichbaren Eingangschannel auf 0
    158         */
    159         public void setEnnrZero() {
    160                 ennr = 0;
    161         }
    162 
    163         /**
    164         * erhöht den Wert der Eingänge um 1
    165         */
    166         public void increaseEnnr() {
    167                 ennr++;
    168         }
    169 
    170 
    171         /**
    172         * fügt einen Pfad den Pfaden zu
    173         * @param path
    174         */
    175         public void appendPath(Channel node, ArrayList<Channel> path) {
    176                 for (int i = 0; i < path.size(); i++) {
    177                         if (!paths2.get(node).contains(path.get(i))) {
    178                                 paths2.get(node).add(path.get(i));
    179                         }
    180                 }
    181         }
    182 
    183         public void appendChannelToPath(Channel node, Channel channel) {
    184                 if (!paths2.containsKey(node)) {
    185                         paths2.put(node, new ArrayList<Channel>());
    186 
    187                 }
    188                 if (!paths2.get(node).contains(channel)) {
    189                         paths2.get(node).add(channel);
    190 
    191                 }
    192         }
    193 
    194         /**
    195         * gibt alle Pfade zurück
    196         * @return
    197         */
    198         public ArrayList<ArrayList<Channel>> getPaths() {
    199                 ArrayList<ArrayList<Channel>> t = new ArrayList<ArrayList<Channel>>();
    200                 t.addAll(paths2.values());
    201                 return t;
    202         }
    203 
    204         public ArrayList<Channel> getPathsAt(Channel node) {
    205                 if (paths2.containsKey(node)) {
    206                         return paths2.get(node);
    207                 }
    208                 else {
    209                         //log.error("das darf nicht bei Channel: " + this.getNewid() + ", kein Node " + node.getNewid());
    210                         return null;
    211                 }
    212 
    213         }
    214 
    215         public boolean isStrongConnected() {
    216                 return isStrongConnected;
    217         }
    218 
    219         public void setStrongConnected(boolean isStrongConnected) {
    220                 this.isStrongConnected = isStrongConnected;
    221         }
    222 
    223         public boolean isSelected() {
    224                 return isSelected;
    225         }
    226 
    227         public void setSelected(boolean isSelected) {
    228                 this.isSelected = isSelected;
    229         }
    230 
    231         public boolean isPartOfJunction() {
    232                 return isPartOfJunction;
    233         }
    234 
    235         public void setPartOfJunction(boolean isPartOfJunction) {
    236                 this.isPartOfJunction = isPartOfJunction;
    237         }
    238 
    239        
     14    //für den Junctioncheck
     15    private int indegree;
     16    private int outdegree;
     17    private boolean subgraph;
     18    private int visited = BacktrackingColors.WHITE;
     19    private final ArrayList<Channel> reachableNodes = new ArrayList<Channel>();
     20    private int ennr;
     21    private boolean isStrongConnected = true;
     22    private boolean isSelected = false; //wird für den eigenen Layer benötigt, um markierte Channels zu erhalten
     23    private boolean isPartOfJunction = false; //wird für den eigenen Layer benötigt, um Teile einer Kreuzung farbig repräsentieren zu können
     24   
     25    private final HashMap<Channel , ArrayList<Channel>> paths2 = new HashMap<Channel , ArrayList<Channel>>();
     26
     27
     28    public Channel(OSMNode fromNode, OSMNode toNode) {
     29        super();
     30        this.setFromNode(fromNode);
     31        this.setToNode(toNode);
     32        this.subgraph = false;
     33        this.indegree = 0;
     34        this.outdegree = 0;
     35    }
     36
     37    public Channel(){
     38        super();
     39        //this.insidenodes = new ArrayList<OSMNode>();
     40        this.subgraph = false;
     41        this.indegree = 0;
     42        this.outdegree = 0;
     43    }
     44
     45    /**
     46    * gibt die Anzahl der auf diesen Channel verweisenden leadsTo zurück
     47    * @return
     48    */
     49    public int getIndegree() {
     50        return indegree;
     51    }
     52
     53    /**
     54    * gibt die Anzahl der aus diesem Channel gehenden leadsTo zurück
     55    * @return
     56    */
     57    public int getOutdegree() {
     58        return outdegree;
     59    }
     60
     61    public void setIndegree(int i) {
     62        this.indegree = i;
     63    }
     64
     65    public void setOutdegree(int i){
     66        this.outdegree = i;
     67    }
     68
     69    /**
     70    * ist dieser Channel Teil der zu untersuchenden Kreuzung?
     71    */
     72    public boolean isSubgraph() {
     73        return subgraph;
     74    }
     75
     76    public void setSubgraph(boolean subgraph) {
     77        this.subgraph = subgraph;
     78    }
     79
     80    /**
     81    * setzt die Farbe des Channels für den TRDFS white = unbesucht grey = besucht, aber noch nicht beendet black = besucht nund abgeschlossen
     82    */
     83    public int getVisited() {
     84        return visited;
     85    }
     86
     87    public void setVisited(int visited) {
     88        this.visited = visited;
     89    }
     90
     91    /**
     92    * gibt die von diesem Channel zu erreichenden anderen CHannels zurück
     93    * @return
     94    */
     95    public ArrayList<Channel> getReachableNodes() {
     96        return reachableNodes;
     97    }
     98
     99    /**
     100    * setzt die zu erreichenden Channels alle anderen werden gelöscht
     101    * @param  reachableNodes
     102    */
     103    public int getEnnr() {
     104        return ennr;
     105    }
     106
     107    /**
     108    * setzt die Anzahl der EingangsChannel
     109    * @param  ennr
     110    */
     111    public void setEnnr(int ennr) {
     112        this.ennr = ennr;
     113    }
     114
     115    /**
     116    * erhöht den Wert der Anzhal der EingangsledasTo um 1
     117    */
     118    public void countupIndegree() {
     119        indegree++;
     120    }
     121
     122    /**
     123    * erhöht den Wert der Anzahl der AusgangsleadsTo um 1
     124    */
     125    public void countupOutdegree() {
     126        outdegree++;
     127    }
     128
     129    /**
     130    * fügt einen erreichbaren Channel hinzu
     131    * @param node
     132    */
     133    public void addReachableNode(Channel node) {
     134        if (!reachableNodes.contains(node)) {
     135            reachableNodes.add(node);
     136            paths2.put(node, new ArrayList<Channel>());
     137        }
     138    }
     139
     140    /**
     141    * gibt den an der Position i gespeicherten erreichbaren Channel zurück
     142    * @param i
     143    * @return
     144    */
     145    public Channel getReachableNodeAt(int i) {
     146        return reachableNodes.get(i);
     147    }
     148
     149    /**
     150    * löscht alle erreichbaren Channels
     151    */
     152    public void ereaseReachableNodes() {
     153        reachableNodes.clear();
     154    }
     155
     156    /**
     157    * setzt Wert der erreichbaren Eingangschannel auf 0
     158    */
     159    public void setEnnrZero() {
     160        ennr = 0;
     161    }
     162
     163    /**
     164    * erhöht den Wert der Eingänge um 1
     165    */
     166    public void increaseEnnr() {
     167        ennr++;
     168    }
     169
     170
     171    /**
     172    * fügt einen Pfad den Pfaden zu
     173    * @param path
     174    */
     175    public void appendPath(Channel node, ArrayList<Channel> path) {
     176        for (int i = 0; i < path.size(); i++) {
     177            if (!paths2.get(node).contains(path.get(i))) {
     178                paths2.get(node).add(path.get(i));
     179            }
     180        }
     181    }
     182
     183    public void appendChannelToPath(Channel node, Channel channel) {
     184        if (!paths2.containsKey(node)) {
     185            paths2.put(node, new ArrayList<Channel>());
     186
     187        }
     188        if (!paths2.get(node).contains(channel)) {
     189            paths2.get(node).add(channel);
     190
     191        }
     192    }
     193
     194    /**
     195    * gibt alle Pfade zurück
     196    * @return
     197    */
     198    public ArrayList<ArrayList<Channel>> getPaths() {
     199        ArrayList<ArrayList<Channel>> t = new ArrayList<ArrayList<Channel>>();
     200        t.addAll(paths2.values());
     201        return t;
     202    }
     203
     204    public ArrayList<Channel> getPathsAt(Channel node) {
     205        if (paths2.containsKey(node)) {
     206            return paths2.get(node);
     207        }
     208        else {
     209            //log.error("das darf nicht bei Channel: " + this.getNewid() + ", kein Node " + node.getNewid());
     210            return null;
     211        }
     212
     213    }
     214
     215    public boolean isStrongConnected() {
     216        return isStrongConnected;
     217    }
     218
     219    public void setStrongConnected(boolean isStrongConnected) {
     220        this.isStrongConnected = isStrongConnected;
     221    }
     222
     223    public boolean isSelected() {
     224        return isSelected;
     225    }
     226
     227    public void setSelected(boolean isSelected) {
     228        this.isSelected = isSelected;
     229    }
     230
     231    public boolean isPartOfJunction() {
     232        return isPartOfJunction;
     233    }
     234
     235    public void setPartOfJunction(boolean isPartOfJunction) {
     236        this.isPartOfJunction = isPartOfJunction;
     237    }
     238
     239   
    240240}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/datastructure/ChannelDiGraph.java

    r25501 r30725  
    1111public class ChannelDiGraph extends Graph {
    1212
    13         private ArrayList<Channel> channels = new ArrayList<Channel>();
    14         private final ArrayList<LeadsTo> leadsTos = new ArrayList<LeadsTo>();
    15         private final HashSet<Channel> selectedChannels = new HashSet<Channel>();
    16         private HashSet<Channel> junctioncandidate = new HashSet<Channel>();
    17 
    18         public void setChannels(ArrayList<Channel> channels) {
    19                 this.channels = channels;
    20         }
    21 
    22         /*
    23         * gibt den Channel mit dem übergebendem OSMNode als FromNode zurück
    24         */
    25         public Channel getChannelWithFromNode(OSMNode node) {
    26                 for (int i = 0; i < channels.size(); i++) {
    27                         if (channels.get(i).getFromNode() == node) {
    28                                 return channels.get(i);
    29                         }
    30                 }
    31                 return null;
    32         }
    33 
    34         /**
    35         * gibt alle CHannels des Digraphen zurück
    36         * @return  Channels des Digraphen
    37         */
    38         public ArrayList<Channel> getChannels() {
    39                 return channels;
    40         }
    41 
    42         /**
    43         * löscht den übergebenden Channel im Digraphen
    44         *
    45         * @param channel
    46         */
    47         public void removeChannel(Channel channel) {
    48                 channels.remove(channel);
    49         }
    50 
    51         /**
    52         * fügt einen Channel des ChannelDigraphen hinzu
    53         *
    54         * @param channel
    55         *            hinzuzufügender Channel
    56         */
    57         public void addChannel(Channel channel) {
    58                 this.channels.add(channel);
    59         }
    60 
    61         /**
    62         * Anzahl der innerhalb des DiGraphen gespeicherten Channels
    63         *
    64         * @return Anzahl der Channels
    65         */
    66         public int numberOfChannels() {
    67                 return channels.size();
    68         }
    69 
    70         /**
    71         * gibt Channel i an der Position i in der ArrayList zurück
    72         *
    73         * @param i
    74         *            Position innerhalb der ArrayList
    75         * @return gewünschter Channel
    76         */
    77         public Channel getChannelAtPosition(int i) {
    78                 return channels.get(i);
    79         }
    80 
    81         /**
    82         * gibt den Channel mit der gesuchten ID zurück
    83         * @param id ID des Channels
    84         * @return der gesuchte Channel, wenn nicht vorhanden null
    85         */
    86         public Channel getChannelWithID(int id) {
    87                 for (int i = 0; i < channels.size(); i++) {
    88                         if (channels.get(i).getNewid() == id) {
    89                                 return channels.get(i);
    90                         }
    91                 }
    92                 return null;
    93         }
    94 
    95         /**
    96         * gibt alle From und To OSMNodes eines Graphen zurück (nicht die
    97         * ZWischenknoten)
    98         *
    99         * @return alle From und To Nodes aller Channels des Digraphen
    100         */
    101         public OSMNode[] getAllOSMNodes() {
    102                 HashMap<Long, OSMNode> nodes = new HashMap<Long, OSMNode>();
    103                 for (int i = 0; i < channels.size(); i++) {
    104                         if (!nodes.containsKey(channels.get(i).getFromNode().getId())) {
    105                                 nodes.put(channels.get(i).getFromNode().getId(), channels
    106                                                 .get(i).getFromNode());
    107                         }
    108                         if (!nodes.containsKey(channels.get(i).getToNode().getId())) {
    109                                 nodes.put(channels.get(i).getToNode().getId(), channels.get(i)
    110                                                 .getToNode());
    111                         }
    112                 }
    113                 OSMNode[] nodearray = new OSMNode[nodes.size()];
    114                 return nodes.values().toArray(nodearray);
    115         }
    116 
    117         public ArrayList<LeadsTo> getLeadsTo() {
    118                 return leadsTos;
    119         }
    120 
    121         /*
    122         public void setLeadsTo(ArrayList<LeadsTo> leadsTo) {
    123                 this.leadsTos = leadsTo;
    124         }*/
    125 
    126         public void setForwardEdge(Channel fromChannel, Channel toChannel) {
    127                 for (int i = 0; i < leadsTos.size(); i++) {
    128                         if (leadsTos.get(i).getFromChannel() == fromChannel) {
    129                                 if (leadsTos.get(i).getToChannel() == toChannel)
    130                                         leadsTos.get(i).setForwardEdge(true);
    131                         }
    132                 }
    133 
    134         }
    135 
    136         /**
    137         * fügt eine leadsto-relation dem digraphen und dem entsprechendem Channel hinzu
    138         * @param leadsTo
    139         */
    140         public void addLeadsTo(LeadsTo leadsTo) {
    141                 leadsTos.add(leadsTo);
    142                 for (int i = 0; i < channels.size(); i++) {
    143                         if (channels.get(i).getNewid() == leadsTo.getFromChannel().getNewid()) {
    144                                 channels.get(i).addLeadsTo(leadsTo);
    145                                 return;
    146                         }
    147                 }
    148         }
    149 
    150         public void removeLeadsTo(LeadsTo leadsTo) {
    151                 leadsTos.remove(leadsTo);
    152                 for (int i = 0; i < channels.size(); i++) {
    153                         if (channels.get(i).equals(leadsTo.getFromChannel())) {
    154                                 channels.get(i).removeLeadsTo(leadsTo);
    155                                 return;
    156                         }
    157                 }
    158         }
    159 
    160         /**
    161         * gibt den Channel zurück, der paßt. Sind Channel doppelt vorhanden, wird
    162         * nur der erste passende zurückgegeben!
    163         *
    164         * @param fromChannel
    165         * @param toChannel
    166         * @return
    167         */
    168         public LeadsTo getLeadsTo(Channel fromChannel, Channel toChannel) {
    169                 for (int i = 0; i < leadsTos.size(); i++) {
    170                         if (leadsTos.get(i).getFromChannel().getNewid() == fromChannel.getNewid()) {
    171                                 //log.trace("FromChannel mit ID gefunden: " + fromChannel.getNewid());
    172                                 if (leadsTos.get(i).getToChannel().getNewid() == toChannel.getNewid()) {
    173                                         //log.trace("Leads To gefunden: " + leadsTos.get(i).toString());
    174                                         return leadsTos.get(i);
    175                                 }
    176                         }
    177                 }
    178                 return null;
    179         }
    180 
    181         /**
    182         * gibt alle Channels zurück, die von diesen OSM-Knoten abgehen/hingehen
    183         * @param nodes
    184         * @return
    185         */
    186         public ArrayList<Channel> getChannelsTouchingOSMNodes (ArrayList<OSMNode> nodes) {
    187                 ArrayList<Channel> touchingChannel = new ArrayList<Channel>();
    188                 for (int i = 0; i < nodes.size(); i++) {
    189                         for (int j = 0; j < channels.size(); j++) {
    190                                 if (channels.get(j).getFromNode().getId() == nodes.get(i).getId()) {
    191                                         if (!touchingChannel.contains(channels.get(j))) {
    192                                                 touchingChannel.add(channels.get(j));
    193                                         }
    194                                 }
    195                                 else if (channels.get(j).getToNode().getId() == nodes.get(i).getId()) {
    196                                         if (!touchingChannel.contains(channels.get(j))) {
    197                                                 touchingChannel.add(channels.get(j));
    198                                         }
    199                                 }
    200                         }
    201                 }
    202                 return touchingChannel;
    203         }
    204 
    205         public ArrayList<Channel> getChannelsTouchingOSMNode(long id) {
    206                 ArrayList<Channel> returnchannels = new ArrayList<Channel>();
    207                 for (int i = 0; i < channels.size(); i++) {
    208                         if (channels.get(i).getFromNode().getId() == id) {
    209                                 returnchannels.add(channels.get(i));
    210                         }
    211                         if (channels.get(i).getToNode().getId() == id) {
    212                                 returnchannels.add(channels.get(i));
    213                         }
    214                 }
    215                 return returnchannels;
    216         }
    217 
    218         /**
    219         * gibt den oder die Channels twischen diesen OSM-Punkten zurück
    220         * @param idfrom
    221         * @param idto
    222         * @return
    223         */
    224         public ArrayList<Channel> getChannelsBetween(int idfrom, int idto) {
    225                 ArrayList<Channel> channelsresult = new ArrayList<Channel>();
    226                 for (int i = 0; i < channels.size(); i++) {
    227                         if (channels.get(i).getFromNode().getId() == idfrom) {
    228                                 if (channels.get(i).getToNode().getId() == idto) {
    229                                         channelsresult.add(channels.get(i));
    230                                 }
    231                         }
    232                         else if (channels.get(i).getFromNode().getId() == idto) {
    233                                 if (channels.get(i).getToNode().getId() == idfrom) {
    234                                         channelsresult.add(channels.get(i));
    235                                 }
    236                         }
    237                 }
    238                 return channelsresult;
    239         }
    240 
    241         public ArrayList<Channel> getChannelswithWayID(int id) {
    242                 ArrayList<Channel> channelsresult = new ArrayList<Channel>();
    243                 for (int i = 0; i < channels.size(); i++) {
    244                         if (channels.get(i).getWay().getId() == id) {
    245                                 channelsresult.add(channels.get(i));
    246                         }
    247                 }
    248                 return channelsresult;
    249         }
    250 
    251         public void detectSelectedChannels(double left, double top, double right, double bottom) {
    252                 for (int i = 0; i < channels.size(); i++) {
    253                         //log.trace(channels.get(i).getFromNode().toString());
    254                         if ( (channels.get(i).getFromNode().getLatitude() <= top) && (channels.get(i).getFromNode().getLatitude() >= bottom)
    255                                         && (channels.get(i).getFromNode().getLongitude() >= left) && (channels.get(i).getFromNode().getLongitude() <=right)) {
    256                                 channels.get(i).setSelected(true);
    257                                 selectedChannels.add(channels.get(i));
    258                         }
    259                         if ( (channels.get(i).getToNode().getLatitude() <= top) && (channels.get(i).getToNode().getLatitude() >= bottom)
    260                                         && (channels.get(i).getToNode().getLongitude() >= left) && (channels.get(i).getToNode().getLongitude() <=right)) {
    261                                 channels.get(i).setSelected(true);
    262                                 selectedChannels.add(channels.get(i));
    263                         }
    264                 }
    265         }
    266 
    267         /**
    268         * löscht die markierten Channels aus der Liste der markierten Channels und setzt die
    269         * Eigenschaft isSelected auf false
    270         */
    271         public void ereaseSelectedChannels() {
    272                 for (int i = 0; i < selectedChannels.size(); i++) {
    273                         Iterator<Channel> it = selectedChannels.iterator();
    274                         while (it.hasNext()) {
    275                                 it.next().setSelected(false);
    276                         }
    277                 }
    278                 selectedChannels.clear();
    279         }
    280 
    281         public HashSet<Channel> getSelectedChannels() {
    282                 return selectedChannels;
    283         }
    284 
    285         public HashSet<Channel> getJunctionCandidate() {
    286                 return junctioncandidate;
    287         }
    288 
    289         public void ereaseJunctioncandidate() {
    290                 Iterator<Channel> it = junctioncandidate.iterator();
    291                 while (it.hasNext()) {
    292                         it.next().setPartOfJunction(false);
    293                 }
    294                 junctioncandidate.clear();
    295         }
    296 
    297         /**
    298         * setzt die Channels eines Kreuzungskandidaten
    299         * falls in im Hashset vorher Channels gespeichert waren, werden diese vorher gelöscht!
    300         * @param junctionCandidate
    301         */
    302         public void setJunctioncandidate(HashSet<Channel> junctionCandidate) {
    303                 this.junctioncandidate.clear();
    304                 this.junctioncandidate = junctionCandidate;
    305                 Iterator<Channel> it = junctionCandidate.iterator();
    306                 while (it.hasNext()) {
    307                         it.next().setPartOfJunction(true);
    308                 }
    309         }
    310 
    311         public void addJunctioncandidateChannel(Channel channel) {
    312                 junctioncandidate.add(channel);
    313                 channel.setPartOfJunction(true);
    314         }
    315 
    316         /*TODO: kann weg oder?
    317         public void ereaseChannelsSubgraph() {
    318                 for (int i = 0; i < channels.size(); i++) {
    319                         channels.get(i).setSubgraph(false);
    320                 }
    321         }
    322 
    323         public void ereaseChannelsInDegree() {
    324                 for (int i = 0; i < channels.size(); i++) {
    325                         channels.get(i).setIndegree(0);
    326                 }
    327         }
    328 
    329         public void ereaseChannelsOutDegree() {
    330                 for (int i = 0; i < channels.size(); i++) {
    331                         channels.get(i).setOutdegree(0);
    332                 }
    333         }
    334         */
     13    private ArrayList<Channel> channels = new ArrayList<Channel>();
     14    private final ArrayList<LeadsTo> leadsTos = new ArrayList<LeadsTo>();
     15    private final HashSet<Channel> selectedChannels = new HashSet<Channel>();
     16    private HashSet<Channel> junctioncandidate = new HashSet<Channel>();
     17
     18    public void setChannels(ArrayList<Channel> channels) {
     19        this.channels = channels;
     20    }
     21
     22    /*
     23    * gibt den Channel mit dem übergebendem OSMNode als FromNode zurück
     24    */
     25    public Channel getChannelWithFromNode(OSMNode node) {
     26        for (int i = 0; i < channels.size(); i++) {
     27            if (channels.get(i).getFromNode() == node) {
     28                return channels.get(i);
     29            }
     30        }
     31        return null;
     32    }
     33
     34    /**
     35    * gibt alle CHannels des Digraphen zurück
     36    * @return  Channels des Digraphen
     37    */
     38    public ArrayList<Channel> getChannels() {
     39        return channels;
     40    }
     41
     42    /**
     43    * löscht den übergebenden Channel im Digraphen
     44    *
     45    * @param channel
     46    */
     47    public void removeChannel(Channel channel) {
     48        channels.remove(channel);
     49    }
     50
     51    /**
     52    * fügt einen Channel des ChannelDigraphen hinzu
     53    *
     54    * @param channel
     55    *            hinzuzufügender Channel
     56    */
     57    public void addChannel(Channel channel) {
     58        this.channels.add(channel);
     59    }
     60
     61    /**
     62    * Anzahl der innerhalb des DiGraphen gespeicherten Channels
     63    *
     64    * @return Anzahl der Channels
     65    */
     66    public int numberOfChannels() {
     67        return channels.size();
     68    }
     69
     70    /**
     71    * gibt Channel i an der Position i in der ArrayList zurück
     72    *
     73    * @param i
     74    *            Position innerhalb der ArrayList
     75    * @return gewünschter Channel
     76    */
     77    public Channel getChannelAtPosition(int i) {
     78        return channels.get(i);
     79    }
     80
     81    /**
     82    * gibt den Channel mit der gesuchten ID zurück
     83    * @param id ID des Channels
     84    * @return der gesuchte Channel, wenn nicht vorhanden null
     85    */
     86    public Channel getChannelWithID(int id) {
     87        for (int i = 0; i < channels.size(); i++) {
     88            if (channels.get(i).getNewid() == id) {
     89                return channels.get(i);
     90            }
     91        }
     92        return null;
     93    }
     94
     95    /**
     96    * gibt alle From und To OSMNodes eines Graphen zurück (nicht die
     97    * ZWischenknoten)
     98    *
     99    * @return alle From und To Nodes aller Channels des Digraphen
     100    */
     101    public OSMNode[] getAllOSMNodes() {
     102        HashMap<Long, OSMNode> nodes = new HashMap<Long, OSMNode>();
     103        for (int i = 0; i < channels.size(); i++) {
     104            if (!nodes.containsKey(channels.get(i).getFromNode().getId())) {
     105                nodes.put(channels.get(i).getFromNode().getId(), channels
     106                        .get(i).getFromNode());
     107            }
     108            if (!nodes.containsKey(channels.get(i).getToNode().getId())) {
     109                nodes.put(channels.get(i).getToNode().getId(), channels.get(i)
     110                        .getToNode());
     111            }
     112        }
     113        OSMNode[] nodearray = new OSMNode[nodes.size()];
     114        return nodes.values().toArray(nodearray);
     115    }
     116
     117    public ArrayList<LeadsTo> getLeadsTo() {
     118        return leadsTos;
     119    }
     120
     121    /*
     122    public void setLeadsTo(ArrayList<LeadsTo> leadsTo) {
     123        this.leadsTos = leadsTo;
     124    }*/
     125
     126    public void setForwardEdge(Channel fromChannel, Channel toChannel) {
     127        for (int i = 0; i < leadsTos.size(); i++) {
     128            if (leadsTos.get(i).getFromChannel() == fromChannel) {
     129                if (leadsTos.get(i).getToChannel() == toChannel)
     130                    leadsTos.get(i).setForwardEdge(true);
     131            }
     132        }
     133
     134    }
     135
     136    /**
     137    * fügt eine leadsto-relation dem digraphen und dem entsprechendem Channel hinzu
     138    * @param leadsTo
     139    */
     140    public void addLeadsTo(LeadsTo leadsTo) {
     141        leadsTos.add(leadsTo);
     142        for (int i = 0; i < channels.size(); i++) {
     143            if (channels.get(i).getNewid() == leadsTo.getFromChannel().getNewid()) {
     144                channels.get(i).addLeadsTo(leadsTo);
     145                return;
     146            }
     147        }
     148    }
     149
     150    public void removeLeadsTo(LeadsTo leadsTo) {
     151        leadsTos.remove(leadsTo);
     152        for (int i = 0; i < channels.size(); i++) {
     153            if (channels.get(i).equals(leadsTo.getFromChannel())) {
     154                channels.get(i).removeLeadsTo(leadsTo);
     155                return;
     156            }
     157        }
     158    }
     159
     160    /**
     161    * gibt den Channel zurück, der paßt. Sind Channel doppelt vorhanden, wird
     162    * nur der erste passende zurückgegeben!
     163    *
     164    * @param fromChannel
     165    * @param toChannel
     166    * @return
     167    */
     168    public LeadsTo getLeadsTo(Channel fromChannel, Channel toChannel) {
     169        for (int i = 0; i < leadsTos.size(); i++) {
     170            if (leadsTos.get(i).getFromChannel().getNewid() == fromChannel.getNewid()) {
     171                //log.trace("FromChannel mit ID gefunden: " + fromChannel.getNewid());
     172                if (leadsTos.get(i).getToChannel().getNewid() == toChannel.getNewid()) {
     173                    //log.trace("Leads To gefunden: " + leadsTos.get(i).toString());
     174                    return leadsTos.get(i);
     175                }
     176            }
     177        }
     178        return null;
     179    }
     180
     181    /**
     182    * gibt alle Channels zurück, die von diesen OSM-Knoten abgehen/hingehen
     183    * @param nodes
     184    * @return
     185    */
     186    public ArrayList<Channel> getChannelsTouchingOSMNodes (ArrayList<OSMNode> nodes) {
     187        ArrayList<Channel> touchingChannel = new ArrayList<Channel>();
     188        for (int i = 0; i < nodes.size(); i++) {
     189            for (int j = 0; j < channels.size(); j++) {
     190                if (channels.get(j).getFromNode().getId() == nodes.get(i).getId()) {
     191                    if (!touchingChannel.contains(channels.get(j))) {
     192                        touchingChannel.add(channels.get(j));
     193                    }
     194                }
     195                else if (channels.get(j).getToNode().getId() == nodes.get(i).getId()) {
     196                    if (!touchingChannel.contains(channels.get(j))) {
     197                        touchingChannel.add(channels.get(j));
     198                    }
     199                }
     200            }
     201        }
     202        return touchingChannel;
     203    }
     204
     205    public ArrayList<Channel> getChannelsTouchingOSMNode(long id) {
     206        ArrayList<Channel> returnchannels = new ArrayList<Channel>();
     207        for (int i = 0; i < channels.size(); i++) {
     208            if (channels.get(i).getFromNode().getId() == id) {
     209                returnchannels.add(channels.get(i));
     210            }
     211            if (channels.get(i).getToNode().getId() == id) {
     212                returnchannels.add(channels.get(i));
     213            }
     214        }
     215        return returnchannels;
     216    }
     217
     218    /**
     219    * gibt den oder die Channels twischen diesen OSM-Punkten zurück
     220    * @param idfrom
     221    * @param idto
     222    * @return
     223    */
     224    public ArrayList<Channel> getChannelsBetween(int idfrom, int idto) {
     225        ArrayList<Channel> channelsresult = new ArrayList<Channel>();
     226        for (int i = 0; i < channels.size(); i++) {
     227            if (channels.get(i).getFromNode().getId() == idfrom) {
     228                if (channels.get(i).getToNode().getId() == idto) {
     229                    channelsresult.add(channels.get(i));
     230                }
     231            }
     232            else if (channels.get(i).getFromNode().getId() == idto) {
     233                if (channels.get(i).getToNode().getId() == idfrom) {
     234                    channelsresult.add(channels.get(i));
     235                }
     236            }
     237        }
     238        return channelsresult;
     239    }
     240
     241    public ArrayList<Channel> getChannelswithWayID(int id) {
     242        ArrayList<Channel> channelsresult = new ArrayList<Channel>();
     243        for (int i = 0; i < channels.size(); i++) {
     244            if (channels.get(i).getWay().getId() == id) {
     245                channelsresult.add(channels.get(i));
     246            }
     247        }
     248        return channelsresult;
     249    }
     250
     251    public void detectSelectedChannels(double left, double top, double right, double bottom) {
     252        for (int i = 0; i < channels.size(); i++) {
     253            //log.trace(channels.get(i).getFromNode().toString());
     254            if ( (channels.get(i).getFromNode().getLatitude() <= top) && (channels.get(i).getFromNode().getLatitude() >= bottom)
     255                    && (channels.get(i).getFromNode().getLongitude() >= left) && (channels.get(i).getFromNode().getLongitude() <=right)) {
     256                channels.get(i).setSelected(true);
     257                selectedChannels.add(channels.get(i));
     258            }
     259            if ( (channels.get(i).getToNode().getLatitude() <= top) && (channels.get(i).getToNode().getLatitude() >= bottom)
     260                    && (channels.get(i).getToNode().getLongitude() >= left) && (channels.get(i).getToNode().getLongitude() <=right)) {
     261                channels.get(i).setSelected(true);
     262                selectedChannels.add(channels.get(i));
     263            }
     264        }
     265    }
     266
     267    /**
     268    * löscht die markierten Channels aus der Liste der markierten Channels und setzt die
     269    * Eigenschaft isSelected auf false
     270    */
     271    public void ereaseSelectedChannels() {
     272        for (int i = 0; i < selectedChannels.size(); i++) {
     273            Iterator<Channel> it = selectedChannels.iterator();
     274            while (it.hasNext()) {
     275                it.next().setSelected(false);
     276            }
     277        }
     278        selectedChannels.clear();
     279    }
     280
     281    public HashSet<Channel> getSelectedChannels() {
     282        return selectedChannels;
     283    }
     284
     285    public HashSet<Channel> getJunctionCandidate() {
     286        return junctioncandidate;
     287    }
     288
     289    public void ereaseJunctioncandidate() {
     290        Iterator<Channel> it = junctioncandidate.iterator();
     291        while (it.hasNext()) {
     292            it.next().setPartOfJunction(false);
     293        }
     294        junctioncandidate.clear();
     295    }
     296
     297    /**
     298    * setzt die Channels eines Kreuzungskandidaten
     299    * falls in im Hashset vorher Channels gespeichert waren, werden diese vorher gelöscht!
     300    * @param junctionCandidate
     301    */
     302    public void setJunctioncandidate(HashSet<Channel> junctionCandidate) {
     303        this.junctioncandidate.clear();
     304        this.junctioncandidate = junctionCandidate;
     305        Iterator<Channel> it = junctionCandidate.iterator();
     306        while (it.hasNext()) {
     307            it.next().setPartOfJunction(true);
     308        }
     309    }
     310
     311    public void addJunctioncandidateChannel(Channel channel) {
     312        junctioncandidate.add(channel);
     313        channel.setPartOfJunction(true);
     314    }
     315
     316    /*TODO: kann weg oder?
     317    public void ereaseChannelsSubgraph() {
     318        for (int i = 0; i < channels.size(); i++) {
     319            channels.get(i).setSubgraph(false);
     320        }
     321    }
     322
     323    public void ereaseChannelsInDegree() {
     324        for (int i = 0; i < channels.size(); i++) {
     325            channels.get(i).setIndegree(0);
     326        }
     327    }
     328
     329    public void ereaseChannelsOutDegree() {
     330        for (int i = 0; i < channels.size(); i++) {
     331            channels.get(i).setOutdegree(0);
     332        }
     333    }
     334    */
    335335}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/datastructure/Graph.java

    r25501 r30725  
    55 */
    66public class Graph {
    7        
    8         //Boundingbox
    9         private double bbleft;
    10         private double bbright;
    11         private double bbbottom;
    12         private double bbtop;
    13        
    14        
    15         public double getBbleft() {
    16                 return bbleft;
    17         }
    18         public void setBbleft(double bbleft) {
    19                 this.bbleft = bbleft;
    20         }
    21         public double getBbright() {
    22                 return bbright;
    23         }
    24         public void setBbright(double bbright) {
    25                 this.bbright = bbright;
    26         }
    27         public double getBbbottom() {
    28                 return bbbottom;
    29         }
    30         public void setBbbottom(double bbbottom) {
    31                 this.bbbottom = bbbottom;
    32         }
    33         public double getBbtop() {
    34                 return bbtop;
    35         }
    36         public void setBbtop(double bbtop) {
    37                 this.bbtop = bbtop;
    38         }
    39         public boolean isInBBox(OSMNode node) {
    40                 if ( (node.getLatitude() <= bbtop) && (node.getLatitude() >= bbbottom)
    41                                 && (node.getLongitude() >= bbleft) && (node.getLongitude() <=bbright)) {
    42                         return true;
    43                 }
    44                 else {
    45                         return false;
    46                 }
    47         }
    48        
    49        
     7   
     8    //Boundingbox
     9    private double bbleft;
     10    private double bbright;
     11    private double bbbottom;
     12    private double bbtop;
     13   
     14   
     15    public double getBbleft() {
     16        return bbleft;
     17    }
     18    public void setBbleft(double bbleft) {
     19        this.bbleft = bbleft;
     20    }
     21    public double getBbright() {
     22        return bbright;
     23    }
     24    public void setBbright(double bbright) {
     25        this.bbright = bbright;
     26    }
     27    public double getBbbottom() {
     28        return bbbottom;
     29    }
     30    public void setBbbottom(double bbbottom) {
     31        this.bbbottom = bbbottom;
     32    }
     33    public double getBbtop() {
     34        return bbtop;
     35    }
     36    public void setBbtop(double bbtop) {
     37        this.bbtop = bbtop;
     38    }
     39    public boolean isInBBox(OSMNode node) {
     40        if ( (node.getLatitude() <= bbtop) && (node.getLatitude() >= bbbottom)
     41                && (node.getLongitude() >= bbleft) && (node.getLongitude() <=bbright)) {
     42            return true;
     43        }
     44        else {
     45            return false;
     46        }
     47    }
     48   
     49   
    5050}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/datastructure/LeadsTo.java

    r25501 r30725  
    66public class LeadsTo {
    77
    8         private Channel fromChannel;
    9         private Channel toChannel;
     8    private Channel fromChannel;
     9    private Channel toChannel;
    1010
    11         //für den JunctionCheck
    12         private boolean isForwardEdge;
     11    //für den JunctionCheck
     12    private boolean isForwardEdge;
    1313
    14         public LeadsTo() {
    15         }
     14    public LeadsTo() {
     15    }
    1616
    17         public LeadsTo(Channel fromcChannel, Channel toChannel) {
    18                 this.fromChannel = fromcChannel;
    19                 this.toChannel = toChannel;
    20         }
     17    public LeadsTo(Channel fromcChannel, Channel toChannel) {
     18        this.fromChannel = fromcChannel;
     19        this.toChannel = toChannel;
     20    }
    2121
    22         public Channel getFromChannel() {
    23                 return fromChannel;
    24         }
     22    public Channel getFromChannel() {
     23        return fromChannel;
     24    }
    2525
    26         public void setFromChannel(Channel fromChannel) {
    27                 this.fromChannel = fromChannel;
    28         }
     26    public void setFromChannel(Channel fromChannel) {
     27        this.fromChannel = fromChannel;
     28    }
    2929
    30         public Channel getToChannel() {
    31                 return toChannel;
    32         }
     30    public Channel getToChannel() {
     31        return toChannel;
     32    }
    3333
    34         public void setToChannel(Channel toChannel) {
    35                 this.toChannel = toChannel;
    36         }
     34    public void setToChannel(Channel toChannel) {
     35        this.toChannel = toChannel;
     36    }
    3737
    38         public boolean isForwardEdge() {
    39                 return isForwardEdge;
    40         }
     38    public boolean isForwardEdge() {
     39        return isForwardEdge;
     40    }
    4141
    42         public void setForwardEdge(boolean isForwardEdge) {
    43                 this.isForwardEdge = isForwardEdge;
    44         }
     42    public void setForwardEdge(boolean isForwardEdge) {
     43        this.isForwardEdge = isForwardEdge;
     44    }
    4545
    46         @Override
    47         public String toString() {
    48                 return "fromChannel:::" + fromChannel.getNewid()  + ", toChannel:::" + toChannel.getNewid() + " über Node " + toChannel.getFromNode().getId();
    49         }
     46    @Override
     47    public String toString() {
     48        return "fromChannel:::" + fromChannel.getNewid()  + ", toChannel:::" + toChannel.getNewid() + " über Node " + toChannel.getFromNode().getId();
     49    }
    5050
    5151
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/datastructure/OSMEntity.java

    r25501 r30725  
    88 */
    99public class OSMEntity {
    10        
    11         //TODO Idee: alle Wertestandardmäßig auf -1 setzen, so muß
    12         //man bei der Umwandlung nicht auf null-Werte prüfen
    13         /**
    14         * @uml.property  name="id"
    15         */
    16         private long id;
    17         /**
    18         * @uml.property  name="visible"
    19         */
    20         private boolean visible;
    21         /**
    22         * @uml.property  name="timestamp"
    23         */
    24         private String timestamp;
    25         /**
    26         * @uml.property  name="user"
    27         */
    28         private String user;
    29         /**
    30         * @uml.property  name="uid"
    31         */
    32         private int uid;
    33         /**
    34         * @uml.property  name="changeset"
    35         */
    36         private int changeset;
    37         /**
    38         * @uml.property  name="hashmap"
    39         */
    40         private HashMap<String, String> hashmap = new HashMap<String, String>();
    41         /**
    42         * @uml.property  name="version"
    43         */
    44         private int version;
    45        
    46         public void setversion(int version) {
    47                 this.version = version;
    48         }
    49        
    50         /**
    51         * @return
    52         * @uml.property  name="version"
    53         */
    54         public int getVersion() {
    55                 return version;
    56         }
    57        
    58         /**
    59         * @return
    60         * @uml.property  name="id"
    61         */
    62         public long getId() {
    63                 return id;
    64         }
    65         public void setId(Long id) {
    66                 this.id = id;
    67         }
    68         /**
    69         * @return
    70         * @uml.property  name="visible"
    71         */
    72         public boolean isVisible() {
    73                 return visible;
    74         }
    75         /**
    76         * @param visible
    77         * @uml.property  name="visible"
    78         */
    79         public void setVisible(boolean visible) {
    80                 this.visible = visible;
    81         }
    82         /**
    83         * @return
    84         * @uml.property  name="timestamp"
    85         */
    86         public String getTimestamp() {
    87                 return timestamp;
    88         }
    89         /**
    90         * @param timestamp
    91         * @uml.property  name="timestamp"
    92         */
    93         public void setTimestamp(String timestamp) {
    94                 this.timestamp = timestamp;
    95         }
    96         /**
    97         * @return
    98         * @uml.property  name="user"
    99         */
    100         public String getUser() {
    101                 return user;
    102         }
    103         /**
    104         * @param user
    105         * @uml.property  name="user"
    106         */
    107         public void setUser(String user) {
    108                 this.user = user;
    109         }
    110         /**
    111         * @return
    112         * @uml.property  name="uid"
    113         */
    114         public int getUid() {
    115                 return uid;
    116         }
    117         /**
    118         * @param uid
    119         * @uml.property  name="uid"
    120         */
    121         public void setUid(int uid) {
    122                 this.uid = uid;
    123         }
    124         /**
    125         * @return
    126         * @uml.property  name="changeset"
    127         */
    128         public int getChangeset() {
    129                 return changeset;
    130         }
    131         /**
    132         * @param changeset
    133         * @uml.property  name="changeset"
    134         */
    135         public void setChangeset(int changeset) {
    136                 this.changeset = changeset;
    137         }
    138         /**
    139         * @return
    140         * @uml.property  name="hashmap"
    141         */
    142         public HashMap<String, String> getHashmap() {
    143                 return hashmap;
    144         }
    145         /**
    146         * @param hashmap
    147         * @uml.property  name="hashmap"
    148         */
    149         public void setHashmap(HashMap<String, String> hashmap) {
    150                 this.hashmap = hashmap;
    151         }
    152        
    153         public void setKeyValue(String key, String value){
    154                 hashmap.put(key, value);
    155         }
    156        
    157         public String getValue(String key){
    158                 return hashmap.get(key);
    159         }
     10   
     11    //TODO Idee: alle Wertestandardmäßig auf -1 setzen, so muß
     12    //man bei der Umwandlung nicht auf null-Werte prüfen
     13    /**
     14    * @uml.property  name="id"
     15    */
     16    private long id;
     17    /**
     18    * @uml.property  name="visible"
     19    */
     20    private boolean visible;
     21    /**
     22    * @uml.property  name="timestamp"
     23    */
     24    private String timestamp;
     25    /**
     26    * @uml.property  name="user"
     27    */
     28    private String user;
     29    /**
     30    * @uml.property  name="uid"
     31    */
     32    private int uid;
     33    /**
     34    * @uml.property  name="changeset"
     35    */
     36    private int changeset;
     37    /**
     38    * @uml.property  name="hashmap"
     39    */
     40    private HashMap<String, String> hashmap = new HashMap<String, String>();
     41    /**
     42    * @uml.property  name="version"
     43    */
     44    private int version;
     45   
     46    public void setversion(int version) {
     47        this.version = version;
     48    }
     49   
     50    /**
     51    * @return
     52    * @uml.property  name="version"
     53    */
     54    public int getVersion() {
     55        return version;
     56    }
     57   
     58    /**
     59    * @return
     60    * @uml.property  name="id"
     61    */
     62    public long getId() {
     63        return id;
     64    }
     65    public void setId(Long id) {
     66        this.id = id;
     67    }
     68    /**
     69    * @return
     70    * @uml.property  name="visible"
     71    */
     72    public boolean isVisible() {
     73        return visible;
     74    }
     75    /**
     76    * @param visible
     77    * @uml.property  name="visible"
     78    */
     79    public void setVisible(boolean visible) {
     80        this.visible = visible;
     81    }
     82    /**
     83    * @return
     84    * @uml.property  name="timestamp"
     85    */
     86    public String getTimestamp() {
     87        return timestamp;
     88    }
     89    /**
     90    * @param timestamp
     91    * @uml.property  name="timestamp"
     92    */
     93    public void setTimestamp(String timestamp) {
     94        this.timestamp = timestamp;
     95    }
     96    /**
     97    * @return
     98    * @uml.property  name="user"
     99    */
     100    public String getUser() {
     101        return user;
     102    }
     103    /**
     104    * @param user
     105    * @uml.property  name="user"
     106    */
     107    public void setUser(String user) {
     108        this.user = user;
     109    }
     110    /**
     111    * @return
     112    * @uml.property  name="uid"
     113    */
     114    public int getUid() {
     115        return uid;
     116    }
     117    /**
     118    * @param uid
     119    * @uml.property  name="uid"
     120    */
     121    public void setUid(int uid) {
     122        this.uid = uid;
     123    }
     124    /**
     125    * @return
     126    * @uml.property  name="changeset"
     127    */
     128    public int getChangeset() {
     129        return changeset;
     130    }
     131    /**
     132    * @param changeset
     133    * @uml.property  name="changeset"
     134    */
     135    public void setChangeset(int changeset) {
     136        this.changeset = changeset;
     137    }
     138    /**
     139    * @return
     140    * @uml.property  name="hashmap"
     141    */
     142    public HashMap<String, String> getHashmap() {
     143        return hashmap;
     144    }
     145    /**
     146    * @param hashmap
     147    * @uml.property  name="hashmap"
     148    */
     149    public void setHashmap(HashMap<String, String> hashmap) {
     150        this.hashmap = hashmap;
     151    }
     152   
     153    public void setKeyValue(String key, String value){
     154        hashmap.put(key, value);
     155    }
     156   
     157    public String getValue(String key){
     158        return hashmap.get(key);
     159    }
    160160
    161         public boolean hasKey(String key){
    162                 return hashmap.containsKey(key);
    163         }
    164        
    165         /**
    166         * prüft, ob der übergebene String als Wert existiert
    167         * @param value
    168         * @return
    169         */
    170         public boolean hasValue(String value){
    171                 return hashmap.containsValue(value);
    172         }
    173        
    174         protected String valuestoString() {
    175                 return ("ID: " + (id) + "\n" + "User: " + user + "\n");
    176         }
     161    public boolean hasKey(String key){
     162        return hashmap.containsKey(key);
     163    }
     164   
     165    /**
     166    * prüft, ob der übergebene String als Wert existiert
     167    * @param value
     168    * @return
     169    */
     170    public boolean hasValue(String value){
     171        return hashmap.containsValue(value);
     172    }
     173   
     174    protected String valuestoString() {
     175        return ("ID: " + (id) + "\n" + "User: " + user + "\n");
     176    }
    177177}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/datastructure/OSMGraph.java

    r25501 r30725  
    1616public class OSMGraph extends Graph{
    1717
    18         private final HashMap<Long, OSMWay> ways = new HashMap<Long, OSMWay>();
    19         private HashMap<Long, OSMRelation> relations = new HashMap<Long, OSMRelation>();
    20         private final HashMap<Long, OSMNode> nodes = new HashMap<Long, OSMNode>();
     18    private final HashMap<Long, OSMWay> ways = new HashMap<Long, OSMWay>();
     19    private HashMap<Long, OSMRelation> relations = new HashMap<Long, OSMRelation>();
     20    private final HashMap<Long, OSMNode> nodes = new HashMap<Long, OSMNode>();
    2121
    22         public void addNode(OSMNode node) {
    23                 nodes.put(node.getId(), node);
    24         }
     22    public void addNode(OSMNode node) {
     23        nodes.put(node.getId(), node);
     24    }
    2525
    26         /**
    27         * gibt den Knoten mit der gesuchten OSM-ID zurück
    28         * @param id OSM-iD des Knotens!
    29         * @return
    30         */
    31         public OSMNode getNode(long id) {
    32                 return nodes.get(id);
    33         }
     26    /**
     27    * gibt den Knoten mit der gesuchten OSM-ID zurück
     28    * @param id OSM-iD des Knotens!
     29    * @return
     30    */
     31    public OSMNode getNode(long id) {
     32        return nodes.get(id);
     33    }
    3434
    35         public void removeWay(OSMWay way) {
    36                 ways.remove(way);
    37         }
     35    public void removeWay(OSMWay way) {
     36        ways.remove(way);
     37    }
    3838
    39         public OSMNode[] getNodes(){
    40                 OSMNode[] nodearray= new OSMNode[nodes.size()];
    41                 return nodes.values().toArray(nodearray);
    42         }
     39    public OSMNode[] getNodes(){
     40        OSMNode[] nodearray= new OSMNode[nodes.size()];
     41        return nodes.values().toArray(nodearray);
     42    }
    4343
    44         public void addWay(OSMWay way) {
    45                 ways.put(way.getId(), way);
    46         }
     44    public void addWay(OSMWay way) {
     45        ways.put(way.getId(), way);
     46    }
    4747
    48         public OSMWay getWay(long id) {
    49                 return ways.get(id);
    50         }
     48    public OSMWay getWay(long id) {
     49        return ways.get(id);
     50    }
    5151
    52         public OSMRelation getRelation(int id) {
    53                 return relations.get(id);
    54         }
     52    public OSMRelation getRelation(int id) {
     53        return relations.get(id);
     54    }
    5555
    56         public  HashMap<Long, OSMRelation> getRelationsAshashmap() {
    57                 return relations;
    58         }
     56    public  HashMap<Long, OSMRelation> getRelationsAshashmap() {
     57        return relations;
     58    }
    5959
    60         public void setRelations( HashMap<Long, OSMRelation> relations) {
    61                 this.relations = relations;
    62         }
     60    public void setRelations( HashMap<Long, OSMRelation> relations) {
     61        this.relations = relations;
     62    }
    6363
    64         public OSMWay[] getWays() {
    65                 OSMWay[] wayarray= new OSMWay[ways.size()];
    66                 return ways.values().toArray(wayarray);
    67         }
     64    public OSMWay[] getWays() {
     65        OSMWay[] wayarray= new OSMWay[ways.size()];
     66        return ways.values().toArray(wayarray);
     67    }
    6868
    69         public void addRelation(OSMRelation relation) {
    70                 relations.put(relation.getId(), relation);
    71         }
     69    public void addRelation(OSMRelation relation) {
     70        relations.put(relation.getId(), relation);
     71    }
    7272
    73         public OSMRelation[] getRelations(){
    74                 OSMRelation[] relationarray = new OSMRelation[relations.size()];
    75                 return relations.values().toArray(relationarray);
    76         }
     73    public OSMRelation[] getRelations(){
     74        OSMRelation[] relationarray = new OSMRelation[relations.size()];
     75        return relations.values().toArray(relationarray);
     76    }
    7777
    78         public Collection<OSMRelation> getRelationsCollection() {
    79                 return relations.values();
    80         }
     78    public Collection<OSMRelation> getRelationsCollection() {
     79        return relations.values();
     80    }
    8181
    82         public boolean hasNode(Long id) {
    83                 return nodes.containsKey(id);
    84         }
     82    public boolean hasNode(Long id) {
     83        return nodes.containsKey(id);
     84    }
    8585
    86         public ArrayList<Long> getIDsfromWay(int id) {
    87                 OSMWay w = ways.get(id);
    88                 ArrayList<Long> ids  = new ArrayList<Long>();
    89                 ids.add(w.getToNode().getId());
    90                 ids.add(w.getFromNode().getId());
    91                 return ids;
    92         }
     86    public ArrayList<Long> getIDsfromWay(int id) {
     87        OSMWay w = ways.get(id);
     88        ArrayList<Long> ids  = new ArrayList<Long>();
     89        ids.add(w.getToNode().getId());
     90        ids.add(w.getFromNode().getId());
     91        return ids;
     92    }
    9393
    94         public void addNode(Node node) {
    95                 OSMNode OSMnode = new OSMNode();
    96                 OSMnode.setId(node.getId());
    97                 OSMnode.setLatitude(node.getBBox().getTopLeft().lat());
    98                 OSMnode.setLongitude(node.getBBox().getTopLeft().lon());
    99                 OSMnode.setHashmap(new HashMap<String, String>(node.getKeys()));
    100                 nodes.put(OSMnode.getId(), OSMnode);
    101         }
     94    public void addNode(Node node) {
     95        OSMNode OSMnode = new OSMNode();
     96        OSMnode.setId(node.getId());
     97        OSMnode.setLatitude(node.getBBox().getTopLeft().lat());
     98        OSMnode.setLongitude(node.getBBox().getTopLeft().lon());
     99        OSMnode.setHashmap(new HashMap<String, String>(node.getKeys()));
     100        nodes.put(OSMnode.getId(), OSMnode);
     101    }
    102102
    103         public void addWay(Way way) {
    104                 OSMWay osmway = new OSMWay();
    105                 osmway.setId(way.getId());
    106                 Iterator<Node> it = way.getNodes().iterator();
    107                 while (it.hasNext()) {
    108                         osmway.addNode(getNode(it.next().getId()));
    109                 }
    110                 osmway.setHashmap(new HashMap<String, String>(way.getKeys()));
    111                 ways.put(osmway.getId(), osmway);
    112         }
     103    public void addWay(Way way) {
     104        OSMWay osmway = new OSMWay();
     105        osmway.setId(way.getId());
     106        Iterator<Node> it = way.getNodes().iterator();
     107        while (it.hasNext()) {
     108            osmway.addNode(getNode(it.next().getId()));
     109        }
     110        osmway.setHashmap(new HashMap<String, String>(way.getKeys()));
     111        ways.put(osmway.getId(), osmway);
     112    }
    113113
    114         public void addRelation(Relation relation) {
    115                 OSMRelation osmrelation = new OSMRelation();
    116                 osmrelation.setId(relation.getId());
    117                 osmrelation.setHashmap(new HashMap<String, String>(relation.getKeys()));
    118                 RelationMember rmember;
    119                 for (int i = 0; i < relation.getMembers().size(); i++) {
    120                         rmember = relation.getMember(i);
    121                         if (rmember.getMember() instanceof Node) {
    122                                 osmrelation.addMember(getNode(rmember.getMember().getId()), rmember.getRole());
    123                         }
    124                         else if (rmember.getMember() instanceof Way) {
    125                                 osmrelation.addMember(getWay(rmember.getMember().getId()), rmember.getRole());
    126                         }
    127                 }
    128                 relations.put(osmrelation.getId(), osmrelation);
    129         }
     114    public void addRelation(Relation relation) {
     115        OSMRelation osmrelation = new OSMRelation();
     116        osmrelation.setId(relation.getId());
     117        osmrelation.setHashmap(new HashMap<String, String>(relation.getKeys()));
     118        RelationMember rmember;
     119        for (int i = 0; i < relation.getMembers().size(); i++) {
     120            rmember = relation.getMember(i);
     121            if (rmember.getMember() instanceof Node) {
     122                osmrelation.addMember(getNode(rmember.getMember().getId()), rmember.getRole());
     123            }
     124            else if (rmember.getMember() instanceof Way) {
     125                osmrelation.addMember(getWay(rmember.getMember().getId()), rmember.getRole());
     126            }
     127        }
     128        relations.put(osmrelation.getId(), osmrelation);
     129    }
    130130}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/datastructure/OSMNode.java

    r25501 r30725  
    88 */
    99public class OSMNode extends OSMEntity {
    10        
    11         private double latitude;
    12         private double longitude;
    13         private ArrayList<Channel> outgoingChannels = new ArrayList<Channel>();
    14         private ArrayList<OSMNode> succNodeList = new ArrayList<OSMNode>();
    15         private ArrayList<OSMNode> predNodeList = new ArrayList<OSMNode>();
    16        
    17         public void addOutgoingChannel(Channel channel) {
    18                 outgoingChannels.add(channel);
    19         }
    20        
    21         public ArrayList<Channel> getOutgoingChannels() {
    22                 return outgoingChannels;
    23         }
    24        
    25         public double getLatitude() {
    26                 return latitude;
    27         }
    28         public void setLatitude(double latitude) {
    29                 this.latitude = latitude;
    30         }
    31         public double getLongitude() {
    32                 return longitude;
    33         }
    34         public void setLongitude(double longitude) {
    35                 this.longitude = longitude;
    36         }
    37        
    38         public String toString(){
    39                 return valuestoString() + "Lat: " + latitude + "\n" + "Lon: " + longitude;
    40         }
     10   
     11    private double latitude;
     12    private double longitude;
     13    private ArrayList<Channel> outgoingChannels = new ArrayList<Channel>();
     14    private ArrayList<OSMNode> succNodeList = new ArrayList<OSMNode>();
     15    private ArrayList<OSMNode> predNodeList = new ArrayList<OSMNode>();
     16   
     17    public void addOutgoingChannel(Channel channel) {
     18        outgoingChannels.add(channel);
     19    }
     20   
     21    public ArrayList<Channel> getOutgoingChannels() {
     22        return outgoingChannels;
     23    }
     24   
     25    public double getLatitude() {
     26        return latitude;
     27    }
     28    public void setLatitude(double latitude) {
     29        this.latitude = latitude;
     30    }
     31    public double getLongitude() {
     32        return longitude;
     33    }
     34    public void setLongitude(double longitude) {
     35        this.longitude = longitude;
     36    }
     37   
     38    public String toString(){
     39        return valuestoString() + "Lat: " + latitude + "\n" + "Lon: " + longitude;
     40    }
    4141
    42         public ArrayList<OSMNode> getSuccNodeList() {
    43                 return succNodeList;
    44         }
     42    public ArrayList<OSMNode> getSuccNodeList() {
     43        return succNodeList;
     44    }
    4545
    46         public ArrayList<OSMNode> getPredNodeList() {
    47                 return predNodeList;
    48         }
    49        
    50         public void addSuccNode(OSMNode node) {
    51                 succNodeList.add(node);
    52         }
    53        
    54         public void addPredNode(OSMNode node) {
    55                 predNodeList.add(node);
    56         }
    57        
    58        
    59        
     46    public ArrayList<OSMNode> getPredNodeList() {
     47        return predNodeList;
     48    }
     49   
     50    public void addSuccNode(OSMNode node) {
     51        succNodeList.add(node);
     52    }
     53   
     54    public void addPredNode(OSMNode node) {
     55        predNodeList.add(node);
     56    }
     57   
     58   
     59   
    6060}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/datastructure/OSMRelation.java

    r29854 r30725  
    99public class OSMRelation extends OSMEntity {
    1010
    11         private ArrayList<Member> members = new ArrayList<Member>();
     11    private ArrayList<Member> members = new ArrayList<Member>();
    1212
    13         public void setMembers(ArrayList<Member> members) {
    14                 this.members = members;
    15         }
     13    public void setMembers(ArrayList<Member> members) {
     14        this.members = members;
     15    }
    1616
    17         public ArrayList<Member> getMembers() {
    18                 return members;
    19         }
    20        
    21         /**
    22         * gibt den Member mit der Rolle zurück, wenn vorhanden. Sonst null
    23         * @param role
    24         * @return
    25         */
    26         public OSMEntity getMember(String role) {
    27                 for (int i = 0; i < members.size(); i++) {
    28                         if (members.get(i).getRole().equals(role)) {
    29                                 return members.get(i).getMember();
    30                         }
    31                 }
    32                 return null;
    33         }
    34        
    35         public void addMember(OSMEntity member, String role) {
    36                 members.add(new Member(member, role));
    37         }
    38        
    39         public String getRelationType(String key) {
    40                 return this.getValue(key);
    41         }
    42        
    43         public String toString() {
    44                 String s = ("Relation-ID: " + this.getId() + " Relation-Type: " + this.getRelationType("type") +"\n");
    45                 for (int i = 0; i < members.size(); i++) {
    46                         s += ("Member: " + members.get(i).getRole() + ", ref:" + members.get(i).getId() + ", type:" + members.get(i).getType().getClass().getName() );
    47                 }
    48                 return s;
    49         }
    50        
     17    public ArrayList<Member> getMembers() {
     18        return members;
     19    }
     20   
     21    /**
     22    * gibt den Member mit der Rolle zurück, wenn vorhanden. Sonst null
     23    * @param role
     24    * @return
     25    */
     26    public OSMEntity getMember(String role) {
     27        for (int i = 0; i < members.size(); i++) {
     28            if (members.get(i).getRole().equals(role)) {
     29                return members.get(i).getMember();
     30            }
     31        }
     32        return null;
     33    }
     34   
     35    public void addMember(OSMEntity member, String role) {
     36        members.add(new Member(member, role));
     37    }
     38   
     39    public String getRelationType(String key) {
     40        return this.getValue(key);
     41    }
     42   
     43    public String toString() {
     44        String s = ("Relation-ID: " + this.getId() + " Relation-Type: " + this.getRelationType("type") +"\n");
     45        for (int i = 0; i < members.size(); i++) {
     46            s += ("Member: " + members.get(i).getRole() + ", ref:" + members.get(i).getId() + ", type:" + members.get(i).getType().getClass().getName() );
     47        }
     48        return s;
     49    }
     50   
    5151
    52         /**
    53         * Klasse dient zum Verwalten eines Member-Objektes. Muß ein Objekt vom Typ OSMEntitysein.
    54         * @author  joerg
    55         */
    56         class Member {
     52    /**
     53    * Klasse dient zum Verwalten eines Member-Objektes. Muß ein Objekt vom Typ OSMEntitysein.
     54    * @author  joerg
     55    */
     56    class Member {
    5757
    58                 private OSMEntity member;
    59                 private String role;
     58        private OSMEntity member;
     59        private String role;
    6060
    61                 public Member(OSMEntity member, String role) {
    62                         this.member = member;
    63                         this.setRole(role);
    64                 }
    65                
    66                 public Class<? extends OSMEntity> getType() {
    67                         return member.getClass();
    68                 }
     61        public Member(OSMEntity member, String role) {
     62            this.member = member;
     63            this.setRole(role);
     64        }
     65       
     66        public Class<? extends OSMEntity> getType() {
     67            return member.getClass();
     68        }
    6969
    70                 public void setMember(OSMEntity member) {
    71                         this.member = member;
    72                 }
     70        public void setMember(OSMEntity member) {
     71            this.member = member;
     72        }
    7373
    74                 public OSMEntity getMember() {
    75                         return member;
    76                 }
     74        public OSMEntity getMember() {
     75            return member;
     76        }
    7777
    78                 public Long getId() {
    79                         return member.getId();
    80                 }
     78        public Long getId() {
     79            return member.getId();
     80        }
    8181
    82                 public void setRole(String role) {
    83                         this.role = role;
    84                 }
     82        public void setRole(String role) {
     83            this.role = role;
     84        }
    8585
    86                 public String getRole() {
    87                         return role;
    88                 }
    89         }
     86        public String getRole() {
     87            return role;
     88        }
     89    }
    9090}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/datastructure/OSMWay.java

    r25501 r30725  
    88public class OSMWay extends OSMEntity {
    99
    10         private Vector<OSMNode> nodes = new Vector<OSMNode>();
     10    private Vector<OSMNode> nodes = new Vector<OSMNode>();
    1111
    12         public OSMNode[] getNodes() {
    13                 OSMNode[] nodearray = new OSMNode[nodes.size()];
    14                 return (OSMNode[]) nodes.toArray(nodearray);
    15         }
     12    public OSMNode[] getNodes() {
     13        OSMNode[] nodearray = new OSMNode[nodes.size()];
     14        return (OSMNode[]) nodes.toArray(nodearray);
     15    }
    1616
    17         public OSMNode getToNode() {
    18                 return nodes.lastElement();
    19         }
     17    public OSMNode getToNode() {
     18        return nodes.lastElement();
     19    }
    2020
    21         public OSMNode getFromNode() {
    22                 return nodes.firstElement();
    23         }
     21    public OSMNode getFromNode() {
     22        return nodes.firstElement();
     23    }
    2424
    25         public void addNode(OSMNode node) {
    26                 nodes.add(node);
    27         }
     25    public void addNode(OSMNode node) {
     26        nodes.add(node);
     27    }
    2828
    29         public String tosString() {
    30                 System.out.println(this.getId());
    31                 return this.valuestoString() + "fromNodeID: "
    32                                 + this.getFromNode().getId() + "\ntoNodeID: "
    33                                 + this.getToNode().getId();
    34         }
     29    public String tosString() {
     30        System.out.println(this.getId());
     31        return this.valuestoString() + "fromNodeID: "
     32                + this.getFromNode().getId() + "\ntoNodeID: "
     33                + this.getToNode().getId();
     34    }
    3535
    36         /**
    37         * ist der OSMWay eine Einbahnstraße?
    38         *
    39         * @return true wenn ja, sonst nein
    40         */
    41         public boolean isOneWay() {
    42                 // TODO Tippfehler berücksichtigen
    43                 // evtl. doch über ein XML-File konfigurieren?
    44                 if (this.hasKey("oneway")) {
    45                         String t = this.getValue("oneway");
    46                         if (t.equals("1") || t.equals("true") || t.equals("yes")) {
    47                                 return true;
    48                         }
    49                 }
    50                 String t = this.getValue("highway");
    51                 if (t != null) {
    52                         if (t.equals("motorway") || t.equals("motorway_link")) {
    53                                 return true;
    54                         }
     36    /**
     37    * ist der OSMWay eine Einbahnstraße?
     38    *
     39    * @return true wenn ja, sonst nein
     40    */
     41    public boolean isOneWay() {
     42        // TODO Tippfehler berücksichtigen
     43        // evtl. doch über ein XML-File konfigurieren?
     44        if (this.hasKey("oneway")) {
     45            String t = this.getValue("oneway");
     46            if (t.equals("1") || t.equals("true") || t.equals("yes")) {
     47                return true;
     48            }
     49        }
     50        String t = this.getValue("highway");
     51        if (t != null) {
     52            if (t.equals("motorway") || t.equals("motorway_link")) {
     53                return true;
     54            }
    5555
    56                         else {
    57                                 return false;
    58                         }
    59                 } else
    60                         return false;
    61         }
     56            else {
     57                return false;
     58            }
     59        } else
     60            return false;
     61    }
    6262}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/filter/ExecuteFilter.java

    r25501 r30725  
    99 */
    1010public class ExecuteFilter {
    11        
    12         private Filter[] filter;
    13         private XMLFilterReader xmlfilterreader;
    14         private OSMGraph incominggraph;
    15         private OSMGraph outgoinggraph;
    16        
    17         public ExecuteFilter(Filter[] filter, OSMGraph incoming){
    18                 this.filter = filter;
    19                 this.incominggraph = incoming;
    20                 outgoinggraph = new OSMGraph();
    21                 outgoinggraph.setBbbottom(incoming.getBbbottom());
    22                 outgoinggraph.setBbleft(incoming.getBbleft());
    23                 outgoinggraph.setBbright(incoming.getBbright());
    24                 outgoinggraph.setBbtop(incoming.getBbtop());
    25                 outgoinggraph.setRelations(incoming.getRelationsAshashmap());
    26         }
    27        
    28         public ExecuteFilter() {
    29         }
    30        
    31         public void filter(){
    32                 OSMWay[] tempWays = incominggraph.getWays();
    33                 String key;
    34                 //alle Einträge im Filter durchgehen
    35                 for (int i = 0; i < filter.length; i++) {
    36                         //alle Ways durchgehen
    37                         for (int j = 0; j < tempWays.length; j++) {
    38                                 key = filter[i].getKeyValue();
    39                                 //prüfen, ob Way Key-Wert des Filters enthält
    40                                 if (tempWays[j].hasKey(key)) {
    41                                         //prüfen, ob Way auch einen Value-Wert des Filtereintrags enthält
    42                                         if (filter[i].hasTagValue(tempWays[j].getValue(key))) {
    43                                                 //Way outgoinggraph hinzufügen
    44                                                 outgoinggraph.addWay(tempWays[j]);
    45                                                 for (int j2 = 0; j2 < tempWays[j].getNodes().length; j2++) {
    46                                                         //zum way gehörende Nodes einfügen, aber nur, wenn diese
    47                                                         //vorher noch nicht im outgoinggraph vorhanden sind
    48                                                         if (!outgoinggraph.hasNode(tempWays[j].getNodes()[j2].getId())) {
    49                                                                 outgoinggraph.addNode(tempWays[j].getNodes()[j2]);
    50                                                         }
    51                                                        
    52                                                 }
    53                                         }
    54                                 }
    55                         }
    56                 }
    57         }
    58        
    59         public Filter[] getFilter() {
    60                 return filter;
    61         }
     11   
     12    private Filter[] filter;
     13    private XMLFilterReader xmlfilterreader;
     14    private OSMGraph incominggraph;
     15    private OSMGraph outgoinggraph;
     16   
     17    public ExecuteFilter(Filter[] filter, OSMGraph incoming){
     18        this.filter = filter;
     19        this.incominggraph = incoming;
     20        outgoinggraph = new OSMGraph();
     21        outgoinggraph.setBbbottom(incoming.getBbbottom());
     22        outgoinggraph.setBbleft(incoming.getBbleft());
     23        outgoinggraph.setBbright(incoming.getBbright());
     24        outgoinggraph.setBbtop(incoming.getBbtop());
     25        outgoinggraph.setRelations(incoming.getRelationsAshashmap());
     26    }
     27   
     28    public ExecuteFilter() {
     29    }
     30   
     31    public void filter(){
     32        OSMWay[] tempWays = incominggraph.getWays();
     33        String key;
     34        //alle Einträge im Filter durchgehen
     35        for (int i = 0; i < filter.length; i++) {
     36            //alle Ways durchgehen
     37            for (int j = 0; j < tempWays.length; j++) {
     38                key = filter[i].getKeyValue();
     39                //prüfen, ob Way Key-Wert des Filters enthält
     40                if (tempWays[j].hasKey(key)) {
     41                    //prüfen, ob Way auch einen Value-Wert des Filtereintrags enthält
     42                    if (filter[i].hasTagValue(tempWays[j].getValue(key))) {
     43                        //Way outgoinggraph hinzufügen
     44                        outgoinggraph.addWay(tempWays[j]);
     45                        for (int j2 = 0; j2 < tempWays[j].getNodes().length; j2++) {
     46                            //zum way gehörende Nodes einfügen, aber nur, wenn diese
     47                            //vorher noch nicht im outgoinggraph vorhanden sind
     48                            if (!outgoinggraph.hasNode(tempWays[j].getNodes()[j2].getId())) {
     49                                outgoinggraph.addNode(tempWays[j].getNodes()[j2]);
     50                            }
     51                           
     52                        }
     53                    }
     54                }
     55            }
     56        }
     57    }
     58   
     59    public Filter[] getFilter() {
     60        return filter;
     61    }
    6262
    63         public void setFilter(Filter[] filter) {
    64                 this.filter = filter;
    65         }
     63    public void setFilter(Filter[] filter) {
     64        this.filter = filter;
     65    }
    6666
    67         public XMLFilterReader getXmlfilterreader() {
    68                 return xmlfilterreader;
    69         }
     67    public XMLFilterReader getXmlfilterreader() {
     68        return xmlfilterreader;
     69    }
    7070
    71         public void setXmlfilterreader(XMLFilterReader xmlfilterreader) {
    72                 this.xmlfilterreader = xmlfilterreader;
    73         }
     71    public void setXmlfilterreader(XMLFilterReader xmlfilterreader) {
     72        this.xmlfilterreader = xmlfilterreader;
     73    }
    7474
    75         public OSMGraph getIncominggraph() {
    76                 return incominggraph;
    77         }
     75    public OSMGraph getIncominggraph() {
     76        return incominggraph;
     77    }
    7878
    79         public void setIncominggraph(OSMGraph incominggraph) {
    80                 this.incominggraph = incominggraph;
    81         }
     79    public void setIncominggraph(OSMGraph incominggraph) {
     80        this.incominggraph = incominggraph;
     81    }
    8282
    83         public OSMGraph getOutgoinggraph() {
    84                 return outgoinggraph;
    85         }
     83    public OSMGraph getOutgoinggraph() {
     84        return outgoinggraph;
     85    }
    8686
    87         public void setOutgoinggraph(OSMGraph outgoinggraph) {
    88                 this.outgoinggraph = outgoinggraph;
    89         }
     87    public void setOutgoinggraph(OSMGraph outgoinggraph) {
     88        this.outgoinggraph = outgoinggraph;
     89    }
    9090}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/filter/Filter.java

    r30722 r30725  
    88 */
    99public class Filter {
    10        
    11         private HashSet<String> tagValues = new HashSet<String>();
    12         private String keyValue;
    13        
    14         public Filter(String keyname, ArrayList<String> values) {
    15                 this.keyValue = keyname;
    16                 tagValues.addAll(values);
    17         }
    18        
    19         public boolean hasTagValue(String value) {
    20                 return tagValues.contains(value);
    21         }
    22        
    23         public Filter() {       
    24         }
    25        
    26         public String[] getTagValues() {
    27                 return tagValues.toArray(new String[tagValues.size()]);
    28         }
     10   
     11    private HashSet<String> tagValues = new HashSet<String>();
     12    private String keyValue;
     13   
     14    public Filter(String keyname, ArrayList<String> values) {
     15        this.keyValue = keyname;
     16        tagValues.addAll(values);
     17    }
     18   
     19    public boolean hasTagValue(String value) {
     20        return tagValues.contains(value);
     21    }
     22   
     23    public Filter() {   
     24    }
     25   
     26    public String[] getTagValues() {
     27        return tagValues.toArray(new String[tagValues.size()]);
     28    }
    2929
    30         public void setTagValues(HashSet<String> tagValues) {
    31                 this.tagValues = tagValues;
    32         }
    33        
    34         public void setTagValue(String value) {
    35                 tagValues.add(value);
    36         }
     30    public void setTagValues(HashSet<String> tagValues) {
     31        this.tagValues = tagValues;
     32    }
     33   
     34    public void setTagValue(String value) {
     35        tagValues.add(value);
     36    }
    3737
    38         public String getKeyValue() {
    39                 return keyValue;
    40         }
     38    public String getKeyValue() {
     39        return keyValue;
     40    }
    4141
    42         public void setKeyValue(String keyValue) {
    43                 this.keyValue = keyValue;
    44         }
     42    public void setKeyValue(String keyValue) {
     43        this.keyValue = keyValue;
     44    }
    4545}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/junctionchecking/BackPropagation.java

    r29854 r30725  
    1111public class BackPropagation {
    1212
    13         private final ChannelDiGraph digraph;
     13    private final ChannelDiGraph digraph;
    1414
    15         public BackPropagation(ChannelDiGraph digraph) {
    16                 this.digraph = digraph;
    17         }
     15    public BackPropagation(ChannelDiGraph digraph) {
     16        this.digraph = digraph;
     17    }
    1818
    19         /**
    20         *
    21         * @param y fromNode
    22         * @param z toNode
    23         */
    24         public void backPropagation(Channel y, Channel z, Channel zstrich) {
    25                 for (int i = 0; i < z.getReachableNodes().size(); i++) {
    26                         y.addReachableNode(z.getReachableNodeAt(i));
    27                         //z.appendChannelToPath(i, z);
    28                         y.appendPath(z.getReachableNodeAt(i), z.getPathsAt(z.getReachableNodeAt(i)));
    29                         y.appendPath(z.getReachableNodeAt(i), y.getPathsAt(z));
    30                 }
    31                 for (int i = 0; i < y.getPredChannels().size(); i++) {
    32                         if (zstrich !=
    33                                 y.getPredChannels().get(i) &&
    34                                 digraph.getLeadsTo(
    35                                                 y.getPredChannels().get(i), y).
    36                                                 isForwardEdge()
    37                         ) {
    38                                 backPropagation(y.getPredChannels().get(i), y, zstrich);
    39                         }
    40                 }
    41         }
     19    /**
     20    *
     21    * @param y fromNode
     22    * @param z toNode
     23    */
     24    public void backPropagation(Channel y, Channel z, Channel zstrich) {
     25        for (int i = 0; i < z.getReachableNodes().size(); i++) {
     26            y.addReachableNode(z.getReachableNodeAt(i));
     27            //z.appendChannelToPath(i, z);
     28            y.appendPath(z.getReachableNodeAt(i), z.getPathsAt(z.getReachableNodeAt(i)));
     29            y.appendPath(z.getReachableNodeAt(i), y.getPathsAt(z));
     30        }
     31        for (int i = 0; i < y.getPredChannels().size(); i++) {
     32            if (zstrich !=
     33                y.getPredChannels().get(i) &&
     34                digraph.getLeadsTo(
     35                        y.getPredChannels().get(i), y).
     36                        isForwardEdge()
     37            ) {
     38                backPropagation(y.getPredChannels().get(i), y, zstrich);
     39            }
     40        }
     41    }
    4242}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/junctionchecking/Combination.java

    r25501 r30725  
    22
    33public class Combination {
    4        
    5         private long n = 0;
    6         private long k = 0;
    7         long[] data = null;
    8        
    9         public Combination(long n, long k){
    10             if (n < 0 || k < 0)
    11                         try {
    12                                 throw new Exception("Negative parameter in constructor");
    13                         } catch (Exception e) {
    14                                 // TODO Auto-generated catch block
    15                                 e.printStackTrace();
    16                        
    17             this.n = n;
    18             this.k = k;
    19             this.data = new long[(int)k];
    20             for (long i = 0; i < k; ++i)
    21               this.data[(int)i] = i;
    22           }
    23        
    24         public static long Choose(long n, long k)
    25         {
    26           if (n < 0 || k < 0)
    27                 try {
    28                         throw new Exception("Invalid negative parameter in Choose()");
    29                 } catch (Exception e) {
    30                         // TODO Auto-generated catch block
    31                         e.printStackTrace();
    32                 }
    33           if (n < k) return 0;
    34           if (n == k) return 1;
     4   
     5    private long n = 0;
     6    private long k = 0;
     7    long[] data = null;
     8   
     9    public Combination(long n, long k){
     10        if (n < 0 || k < 0)
     11            try {
     12                throw new Exception("Negative parameter in constructor");
     13            } catch (Exception e) {
     14                // TODO Auto-generated catch block
     15                e.printStackTrace();
     16           
     17        this.n = n;
     18        this.k = k;
     19        this.data = new long[(int)k];
     20        for (long i = 0; i < k; ++i)
     21          this.data[(int)i] = i;
     22      }
     23   
     24    public static long Choose(long n, long k)
     25    {
     26      if (n < 0 || k < 0)
     27        try {
     28            throw new Exception("Invalid negative parameter in Choose()");
     29        } catch (Exception e) {
     30            // TODO Auto-generated catch block
     31            e.printStackTrace();
     32        }
     33      if (n < k) return 0;
     34      if (n == k) return 1;
    3535
    36           long delta, iMax;
     36      long delta, iMax;
    3737
    38           if (k < n-k) // ex: Choose(100,3)
    39           {
    40             delta = n-k;
    41             iMax = k;
    42           }
    43           else         // ex: Choose(100,97)
    44           {
    45             delta = k;
    46             iMax = n-k;
    47           }
     38      if (k < n-k) // ex: Choose(100,3)
     39      {
     40        delta = n-k;
     41        iMax = k;
     42      }
     43      else         // ex: Choose(100,97)
     44      {
     45        delta = k;
     46        iMax = n-k;
     47      }
    4848
    49           long ans = delta + 1;
     49      long ans = delta + 1;
    5050
    51           for (long i = 2; i <= iMax; ++i)
    52           {
    53             ans = (ans * (delta + i)) / i;
    54           }
     51      for (long i = 2; i <= iMax; ++i)
     52      {
     53        ans = (ans * (delta + i)) / i;
     54      }
    5555
    56           return ans;
    57         }
    58         public long Choose()
    59         {
    60        
    61           if (n < k) return 0;
    62           if (n == k) return 1;
     56      return ans;
     57    }
     58    public long Choose()
     59    {
     60   
     61      if (n < k) return 0;
     62      if (n == k) return 1;
    6363
    64           long delta, iMax;
     64      long delta, iMax;
    6565
    66           if (k < n-k) // ex: Choose(100,3)
    67           {
    68             delta = n-k;
    69             iMax = k;
    70           }
    71           else         // ex: Choose(100,97)
    72           {
    73             delta = k;
    74             iMax = n-k;
    75           }
     66      if (k < n-k) // ex: Choose(100,3)
     67      {
     68        delta = n-k;
     69        iMax = k;
     70      }
     71      else         // ex: Choose(100,97)
     72      {
     73        delta = k;
     74        iMax = n-k;
     75      }
    7676
    77           long ans = delta + 1;
     77      long ans = delta + 1;
    7878
    79           for (long i = 2; i <= iMax; ++i)
    80           {
    81             ans = (ans * (delta + i)) / i;
    82           }
     79      for (long i = 2; i <= iMax; ++i)
     80      {
     81        ans = (ans * (delta + i)) / i;
     82      }
    8383
    84           return ans;
    85         }
     84      return ans;
     85    }
    8686
    87        
    88         public Combination Successor()
    89         {
    90           if (this.data.length == 0 ||
    91               this.data[0] == this.n - this.k)
    92             return null;
     87   
     88    public Combination Successor()
     89    {
     90      if (this.data.length == 0 ||
     91          this.data[0] == this.n - this.k)
     92        return null;
    9393
    94           Combination ans = new Combination(this.n, this.k);
     94      Combination ans = new Combination(this.n, this.k);
    9595
    96           long i;
    97           for (i = 0; i < this.k; ++i){
    98             ans.data[(int)i] = this.data[(int)i];
    99           }
    100           for (i = this.k - 1; i > 0 && ans.data[(int)i] == this.n - this.k + i; --i) {};
    101        
    102           ++ans.data[(int)i];
     96      long i;
     97      for (i = 0; i < this.k; ++i){
     98        ans.data[(int)i] = this.data[(int)i];
     99      }
     100      for (i = this.k - 1; i > 0 && ans.data[(int)i] == this.n - this.k + i; --i) {};
     101   
     102      ++ans.data[(int)i];
    103103
    104           for (long j = i; j < this.k - 1; ++j){
    105             ans.data[(int)j+1] = ans.data[(int)j] + 1;
    106           } 
    107           return ans;
    108         }
    109        
    110         public String ToString()
    111           {
    112             StringBuilder sb = new StringBuilder();
    113             sb.append("{");
    114             for (long i = 0; i < this.k; ++i){
    115               sb.append(this.data[(int)i]);
    116               if (i<this.k-1) sb.append(", ");
    117             }
    118             sb.append("}");
    119             return sb.toString();
    120           }
     104      for (long j = i; j < this.k - 1; ++j){
     105        ans.data[(int)j+1] = ans.data[(int)j] + 1;
     106      } 
     107      return ans;
     108    }
     109   
     110    public String ToString()
     111      {
     112        StringBuilder sb = new StringBuilder();
     113        sb.append("{");
     114        for (long i = 0; i < this.k; ++i){
     115          sb.append(this.data[(int)i]);
     116          if (i<this.k-1) sb.append(", ");
     117        }
     118        sb.append("}");
     119        return sb.toString();
     120      }
    121121
    122122}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/junctionchecking/JCheck.java

    r25501 r30725  
    99public class JCheck {
    1010
    11         private int exnr;
    12         private String result = "";
     11    private int exnr;
     12    private String result = "";
    1313
    14         public boolean jCheck(ArrayList<Channel> entries, ArrayList<Channel> exits,
    15                         int n) {
    16                 for (int i = 0; i < exits.size(); i++) {
    17                         exits.get(i).setEnnrZero();
    18                 }
    19                 if (!(entries.size() == exits.size() && exits.size() == n)) {
    20                         result="Rule 1 broken: " + entries.size() + " entries but "
    21                                         + exits.size() + " exits and n=" + n;
    22                         return false;
    23                 }
    24                 for (int i = 0; i < entries.size(); i++) {
    25                         if (!(entries.get(i).getIndegree() + entries.get(i).getOutdegree() >= 2)) {
    26                                 result="rule 4 broken: indegree from entrynode with ID: "
    27                                                 + entries.get(i).getNewid() + ": "
    28                                                 + entries.get(i).getIndegree() + " OutDegree: "
    29                                                 + entries.get(i).getOutdegree();
    30                                 return false;
    31                         }
    32                         exnr = 0;
    33                         for (int j = 0; j < exits.size(); j++) {
    34                                 if (!(exits.get(j).getIndegree() + exits.get(j).getOutdegree() >= 2)) {
    35                                         result="Rule 4 broken, indegree from exitnode with ID: "
    36                                                         + exits.get(j).getNewid() + ": "
    37                                                         + exits.get(j).getIndegree() + " and outdegree: "
    38                                                         + exits.get(j).getOutdegree();
    39                                         //log.debug(exits.get(j).toString());
    40                                         return false;
    41                                 }
    42                                 if (entries.get(i).getReachableNodes().contains(exits.get(j))) {
    43                                         exnr++;
    44                                         exits.get(j).increaseEnnr();
    45                                 }
    46                                 if (exits.get(j).equals(entries.get(i))) {
    47                                         result="Rule 2 broken: node with ID: "
    48                                                         + "entries.get(i).getNode().getId()"
    49                                                         + "is both entry and exit node";
    50                                         return false;
    51                                 }
    52                         }
     14    public boolean jCheck(ArrayList<Channel> entries, ArrayList<Channel> exits,
     15            int n) {
     16        for (int i = 0; i < exits.size(); i++) {
     17            exits.get(i).setEnnrZero();
     18        }
     19        if (!(entries.size() == exits.size() && exits.size() == n)) {
     20            result="Rule 1 broken: " + entries.size() + " entries but "
     21                    + exits.size() + " exits and n=" + n;
     22            return false;
     23        }
     24        for (int i = 0; i < entries.size(); i++) {
     25            if (!(entries.get(i).getIndegree() + entries.get(i).getOutdegree() >= 2)) {
     26                result="rule 4 broken: indegree from entrynode with ID: "
     27                        + entries.get(i).getNewid() + ": "
     28                        + entries.get(i).getIndegree() + " OutDegree: "
     29                        + entries.get(i).getOutdegree();
     30                return false;
     31            }
     32            exnr = 0;
     33            for (int j = 0; j < exits.size(); j++) {
     34                if (!(exits.get(j).getIndegree() + exits.get(j).getOutdegree() >= 2)) {
     35                    result="Rule 4 broken, indegree from exitnode with ID: "
     36                            + exits.get(j).getNewid() + ": "
     37                            + exits.get(j).getIndegree() + " and outdegree: "
     38                            + exits.get(j).getOutdegree();
     39                    //log.debug(exits.get(j).toString());
     40                    return false;
     41                }
     42                if (entries.get(i).getReachableNodes().contains(exits.get(j))) {
     43                    exnr++;
     44                    exits.get(j).increaseEnnr();
     45                }
     46                if (exits.get(j).equals(entries.get(i))) {
     47                    result="Rule 2 broken: node with ID: "
     48                            + "entries.get(i).getNode().getId()"
     49                            + "is both entry and exit node";
     50                    return false;
     51                }
     52            }
    5353
    54                 }
    55                 if (!(exnr >= n - 1)) {
    56                         result="Rule 1 broken";
    57                         return false;
    58                 }
    59                 for (int i = 0; i < exits.size(); i++) {
    60                         if (!(exits.get(i).getEnnr() >= (n - 1))) {
    61                                 result="Rule 1 broken, exit node with ID "
    62                                                 + exits.get(i).getNewid() + "can only reached from "
    63                                                 + exits.get(i).getEnnr() + " entries.";
    64                                 return false;
    65                         }
    66                 }
    67                 result = "Jcheck erfolgreich bestanden";
    68                 return true;
    69         }
    70        
    71         /**
    72         * gibt das Ergebnis des JChecks in Form als Satz mit Informationen zurück
    73         * @return
    74         */
    75         public String getResult() {
    76                 return result;
    77         }
     54        }
     55        if (!(exnr >= n - 1)) {
     56            result="Rule 1 broken";
     57            return false;
     58        }
     59        for (int i = 0; i < exits.size(); i++) {
     60            if (!(exits.get(i).getEnnr() >= (n - 1))) {
     61                result="Rule 1 broken, exit node with ID "
     62                        + exits.get(i).getNewid() + "can only reached from "
     63                        + exits.get(i).getEnnr() + " entries.";
     64                return false;
     65            }
     66        }
     67        result = "Jcheck erfolgreich bestanden";
     68        return true;
     69    }
     70   
     71    /**
     72    * gibt das Ergebnis des JChecks in Form als Satz mit Informationen zurück
     73    * @return
     74    */
     75    public String getResult() {
     76        return result;
     77    }
    7878}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/junctionchecking/JMinimality.java

    r29854 r30725  
    99import java.util.Iterator;
    1010import java.util.List;
     11
    1112import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1213import org.openstreetmap.josm.plugins.JunctionChecker.datastructure.Channel;
     
    2122public class JMinimality {
    2223
    23         private boolean CheckMinimal = true;
    24         private final ArrayList<Channel> E;
    25         private final int Grid[][];
    26         private final ArrayList<Channel> OrEn;
    27         private final ArrayList<Channel> OrEx;
    28         private final int n;
    29         private final List<List<Object>> L = new ArrayList<List<Object>>(); //The list of columns to be sorted
    30         private long EEovern = 0;
    31         private final HashSet<Channel> subgraph = new HashSet<Channel>();//The candidate subgraph to be tested
    32         private ProgressMonitor pm;
    33         private final boolean pmenabled;
    34         private final ArrayList<HashSet<Channel>> junctions = new ArrayList<HashSet<Channel>>();
    35         private final boolean searchFirstJunction;
    36         private final ArrayList<Channel> subJunction = new ArrayList<Channel>();
    37         private final JPrepare jprepare;
    38         private boolean Check = false;
    39         private Iterator<int[]> it;
    40 
    41 
    42         public JMinimality(int[][] Grid, int n,
    43                         ArrayList<Channel> E,
    44                         ArrayList<Channel> entries,
    45                         ArrayList<Channel> exits,
    46                         ChannelDiGraph channeldigraph,
    47                         boolean junctionsearch) {
    48 
    49                 this.E = E;
    50                 this.n = n;
    51                 this.Grid = Grid;
    52                 this.OrEn = entries;
    53                 this.OrEx = exits;
    54                 this.pmenabled = false;
    55                 this.searchFirstJunction = junctionsearch;
    56                 this.jprepare = new JPrepare(channeldigraph);
    57         }
    58 
    59         public JMinimality(int[][] Grid, int n,
    60                         ArrayList<Channel> E,
    61                         ArrayList<Channel> entries,
    62                         ArrayList<Channel> exits,
    63                         ChannelDiGraph channeldigraph,
    64                         ProgressMonitor pm,
    65                         boolean junctionsearch) {
    66 
    67                 this.E = E;
    68                 this.n = n;
    69                 this.Grid = Grid;
    70                 this.OrEn = entries;
    71                 this.OrEx = exits;
    72                 this.pm = pm;
    73                 this.pmenabled = true;
    74                 this.searchFirstJunction = junctionsearch;
    75                 this.jprepare = new JPrepare(channeldigraph);
    76                 //this.jCheck= new JCheck();
    77         }
    78 
    79         public void GenerateSubcolumns () {/*Generates all combinations of subcolumns in the grid*/
    80                 if (pmenabled) {
    81                         pm.setCustomText(tr ("generate all combinations from entrie/exit candidates"));
    82                 }
    83 
    84                 Combination c = new Combination(Grid.length, n);
    85                 EEovern = (int) Combination.Choose(Grid.length*Grid.length, n*n);
    86                 long ans = c.Choose(); //This is the number of subcolumns to be generated
    87                 int[][] v; // this is a column variable containing n y-index entries plus true false values (0/1)
    88                 List<Object> C; //The column is packed together with 2 indices into this variable
    89                 for (int i = 0; i < Grid.length;i++) {
    90                         int h = 0;      //this is the index denoting the "n out of Grid.length"- combination, indicating a subcolumn of length n
    91                         do {
    92                                 int missing = 0;
    93                                 C = new ArrayList<Object>(3);
    94                                 v = new int[n][2];
    95                                 C.add(i);//the first position of column variable C is the column index
    96                                 C.add(h);//the second is the entry-subset index
    97                                 for(int t = 0; t < c.data.length; t++){
    98                                         if (Grid[(int)c.data[t]][i] == 0){
    99                                                 missing++;
    100                                                 v[t][1]= 0; //false
    101                                         }
    102                                         else{
    103                                                 v[t][1]= 1;
    104                                         } //true
    105                                         v[t][0]=(int)c.data[t]; //Write a y index of the combination into column
    106                                 }
    107                                 if (missing <=1){//If column has at most one missing entry
    108                                         C.add(v);//insert column as the third position of column variable C
    109                                         L.add(C); //Insert C in list to be ordered
    110                                 }
    111                                 h++; //Iterate through all subcolumns
    112                                 if (h < ans){c = c.Successor();}//generate the next combination
    113                         }while(h < ans);
    114                         c = new Combination(Grid.length, n); //For each original column in the grid, generate new subcolumns
    115                 }
    116                 Collections.sort(L, new Comparator<List<Object>>() {
     24    private boolean CheckMinimal = true;
     25    private final ArrayList<Channel> E;
     26    private final int Grid[][];
     27    private final ArrayList<Channel> OrEn;
     28    private final ArrayList<Channel> OrEx;
     29    private final int n;
     30    private final List<List<Object>> L = new ArrayList<List<Object>>(); //The list of columns to be sorted
     31    private long EEovern = 0;
     32    private final HashSet<Channel> subgraph = new HashSet<Channel>();//The candidate subgraph to be tested
     33    private ProgressMonitor pm;
     34    private final boolean pmenabled;
     35    private final ArrayList<HashSet<Channel>> junctions = new ArrayList<HashSet<Channel>>();
     36    private final boolean searchFirstJunction;
     37    private final ArrayList<Channel> subJunction = new ArrayList<Channel>();
     38    private final JPrepare jprepare;
     39    private boolean Check = false;
     40    private Iterator<int[]> it;
     41
     42
     43    public JMinimality(int[][] Grid, int n,
     44            ArrayList<Channel> E,
     45            ArrayList<Channel> entries,
     46            ArrayList<Channel> exits,
     47            ChannelDiGraph channeldigraph,
     48            boolean junctionsearch) {
     49
     50        this.E = E;
     51        this.n = n;
     52        this.Grid = Grid;
     53        this.OrEn = entries;
     54        this.OrEx = exits;
     55        this.pmenabled = false;
     56        this.searchFirstJunction = junctionsearch;
     57        this.jprepare = new JPrepare(channeldigraph);
     58    }
     59
     60    public JMinimality(int[][] Grid, int n,
     61            ArrayList<Channel> E,
     62            ArrayList<Channel> entries,
     63            ArrayList<Channel> exits,
     64            ChannelDiGraph channeldigraph,
     65            ProgressMonitor pm,
     66            boolean junctionsearch) {
     67
     68        this.E = E;
     69        this.n = n;
     70        this.Grid = Grid;
     71        this.OrEn = entries;
     72        this.OrEx = exits;
     73        this.pm = pm;
     74        this.pmenabled = true;
     75        this.searchFirstJunction = junctionsearch;
     76        this.jprepare = new JPrepare(channeldigraph);
     77        //this.jCheck= new JCheck();
     78    }
     79
     80    public void GenerateSubcolumns () {/*Generates all combinations of subcolumns in the grid*/
     81        if (pmenabled) {
     82            pm.setCustomText(tr ("generate all combinations from entrie/exit candidates"));
     83        }
     84
     85        Combination c = new Combination(Grid.length, n);
     86        EEovern = (int) Combination.Choose(Grid.length*Grid.length, n*n);
     87        long ans = c.Choose(); //This is the number of subcolumns to be generated
     88        int[][] v; // this is a column variable containing n y-index entries plus true false values (0/1)
     89        List<Object> C; //The column is packed together with 2 indices into this variable
     90        for (int i = 0; i < Grid.length;i++) {
     91            int h = 0;    //this is the index denoting the "n out of Grid.length"- combination, indicating a subcolumn of length n
     92            do {
     93                int missing = 0;
     94                C = new ArrayList<Object>(3);
     95                v = new int[n][2];
     96                C.add(i);//the first position of column variable C is the column index
     97                C.add(h);//the second is the entry-subset index
     98                for(int t = 0; t < c.data.length; t++){
     99                    if (Grid[(int)c.data[t]][i] == 0){
     100                        missing++;
     101                        v[t][1]= 0; //false
     102                    }
     103                    else{
     104                        v[t][1]= 1;
     105                    } //true
     106                    v[t][0]=(int)c.data[t];    //Write a y index of the combination into column
     107                }
     108                if (missing <=1){//If column has at most one missing entry
     109                    C.add(v);//insert column as the third position of column variable C
     110                    L.add(C); //Insert C in list to be ordered
     111                }
     112                h++; //Iterate through all subcolumns
     113                if (h < ans){c = c.Successor();}//generate the next combination
     114            }while(h < ans);
     115            c = new Combination(Grid.length, n); //For each original column in the grid, generate new subcolumns
     116        }
     117        Collections.sort(L, new Comparator<List<Object>>() {
     118            @Override
    117119                        public int compare(List<Object> o1, List<Object> o2) {
    118                                 return (Integer)o1.get(1) - (Integer)o2.get(1); //sort according to h index in each column
    119                         }});
    120         }
    121 
    122         public boolean IterateThroughKn() {//Iterates through all K_{n-1} subgrids of the Grid and tests them
    123                 if (L.size()==0) {
    124                         return true;
    125                 }
    126                 if (pmenabled) {
    127                         pm.setTicksCount(L.size());
    128                         pm.setCustomText("Iterates through all K_{n-1} subgrids of the Grid and tests them");
    129                 }
    130                 Combination c;
    131                 Iterator<List<Object>> l = L.listIterator();
    132                 List<Object> C;
    133                 ArrayList<int[]> CandidateK = new ArrayList<int[]>(n*n); //saves the candidate K_{n-1} in entry-exit pairs
    134                 long lindex= 0;
    135                 int h = 0;
    136                 int m = 0;
    137                 int[][] v;
    138                 int x_i;
    139                 int y_j;
    140                 int progressmonitorcounter = 1;
    141                 boolean mchanged = false;
    142                 boolean hchanged = false;
    143                 C = l.next();
    144                 do{ //Loop over list of columns L
    145                         if (mchanged){
    146                                 C = l.next(); //Iterator in L
    147                                 lindex++; //Index in L
    148                                 if (hchanged) {
    149                                         m=1;
    150                                         hchanged = false;
    151                                 }
    152                         }
    153                         if ((Integer)C.get(1)==h && l.hasNext()){ //m counts the set of columns with index h
    154                                 m++;
    155                                 mchanged = true;
    156                         }
    157                         else{
    158                                 if (l.hasNext()==false){
    159                                         m++;lindex++;
    160                                 } //At the end of L, counter are set one up
    161                                 c = new Combination(m, n);
    162                                 long ans = c.Choose();
    163                                 int missing = 0;
    164                                 boolean smallerjunction = false;
    165                                 for (int k =0; k<ans;k++){ //Makes sure that subset of m columns contains an n*n subgrid, because ans = m over n would be 0 otherwise
    166                                         for (int y = 0; y < n; y++){//Iterates over all rows of subgrid k
    167                                                 missing =0;     //test = "";
    168                                                 for (int x = 0; x <c.data.length;x++) { //Iterates over all columns of subgrid k
    169                                                         x_i=((Integer)L.get((int)(lindex-m+c.data[x])).get(0));//columnindex in grid
    170                                                         v=((int[][])(L.get((int)(lindex-m+c.data[x])).get(2))); //subcolumn of grid
    171                                                         y_j= v[y][0]; //rowindex in grid
    172                                                         if (v[y][1]==0){
    173                                                                 missing++;
    174                                                         }else{
    175                                                                 CandidateK.add(new int[]{y_j,x_i});
    176                                                         }//save entry/exit tuple
    177                                                         if (smallerjunction == false && ((!OrEn.contains(E.get(v[y][0]))) &&(!OrEx.contains(E.get(x_i))))){ // Tests, whether y or x is not an original entry/exit
    178                                                                 smallerjunction = true; //Then k identifies a different junction than the original one
    179                                                         }
    180                                                         //test = test+" ("+y_j+", "+x_i+", "+v[y][1]+")";
    181                                                 }
    182                                                 if (missing > 1){
    183                                                         break;
    184                                                 }//If a row has more than one missing value, break
    185                                         }
    186                                         if (missing <=1 && smallerjunction == true){//The k-subgrid is a different junction candidate satisfying total reachability
    187                                                 CheckMinimal = CheckSmallJunction(CandidateK)==false;// If the candidate is a smaller junction, then minimality is false
    188                                                 //log.info("durchlauf: " + durchlauf + " Wert von CheckMinimal: " + CheckMinimal);
    189                                                 if (!CheckMinimal) {
    190                                                         break;
    191                                                 }
    192                                         }
    193                                         CandidateK.clear();
    194                                         if (k+1 < ans){c = c.Successor();} //Produces the m over n combinations
    195                                 }
    196                                 m=1; //Sets m to the first column with next index h+1
    197                                 h++;
    198                                 mchanged = false;
    199                                 hchanged = true;
    200                         }
    201                         if (pmenabled) {
    202                                 progressmonitorcounter++;
    203                                 pm.setTicks(progressmonitorcounter);
    204                         }
    205                 }
    206                 while(l.hasNext() && CheckMinimal);
    207                 return CheckMinimal;
    208         }
    209 
    210         /**
    211         * gibt true zurück, wenn Kandidat eine Kreuzung ist, aber nicht, wenn junctionsearch auf true gesetzt ist
    212         * @param CandidateK
    213         * @return
    214         */
    215         public boolean CheckSmallJunction(ArrayList<int[]> CandidateK){
    216                 Check = false;
    217                 subgraph.clear();//Zu konstruierender Subgraph
    218                 it = CandidateK.iterator();
    219                 //Reconstruct small Junction from paths
    220                 while (it.hasNext()){
    221                         int[]point = it.next();
    222                         for (int j = 0; j < E.get(point[0]).getReachableNodes().size(); j++) {
    223                                 if(E.get(point[0]).getReachableNodeAt(j).equals(E.get(point[1]))){
    224                                         subgraph.addAll(E.get(point[0]).getPathsAt(E.get(point[0]).getReachableNodeAt(j)));
    225                                         subgraph.add(E.get(point[0]));
    226                                 }
    227                         }
    228                 }
    229                 jprepare.jPrepare(new ArrayList<Channel>(subgraph));
    230                 JCheck jCheck = new JCheck();
    231                 Check = jCheck.jCheck(jprepare.getEntries(), jprepare.getExits(), n);
    232                 jprepare.resetSubgraph();
    233                 if (Check) {
    234                         subJunction.clear();
    235                         subJunction.addAll(subgraph);
    236                         //soll mehr als ein Kandidat gesucht werden? Dann Kandidaten speichern und Check wieder auf false stellen, damit die Hauptschleife weitergeht
    237                         if (!searchFirstJunction) {
    238                                 boolean isin = false;
    239                                 for (int i = 0; i < junctions.size(); i++) {
    240                                         //log.debug("Kreuzung " + i +" hat Channels: " + junctions.get(i).size() + " subgraph: " + subgraph.size());
    241                                         if (junctions.get(i).size() == subgraph.size()) {
    242                                                 Iterator<Channel> it = subgraph.iterator();
    243                                                 isin = true;
    244                                                 while (it.hasNext()) {
    245                                                         if (!junctions.get(i).contains(it.next())) {
    246                                                                 isin = false;
    247                                                                 //log.info("nicht drin");
    248                                                         }
    249                                                 }
    250                                         }
    251                                 }
    252                                 if (isin == false) {
    253                                         junctions.add(new HashSet<Channel>(subgraph));
    254                                         //log.info("Kreuzungskandidat der Liste zugefügt" + junctions.size());
    255                                 }
    256                                 Check = false;
    257                         }
    258                 }
    259                 return Check;
    260         }
    261 
    262         /**
    263         * enthält alle Channels des zuletzt durchlaufenden Kreuzungskandidaten (muß keine gültige Kreuzung sein)
    264         * @return
    265         */
    266         public ArrayList<Channel> getSubJunctionCandidate(){
    267                 return new ArrayList<Channel>(subgraph);
    268         }
    269 
    270         /**
    271         * gibt alle gefundenen Kreuzungskandidaten zurück (ist leer, wenn junctionsearch auf true gesetzt wurde)
    272         * @return
    273         */
    274         public ArrayList<HashSet<Channel>> getJunctionCandidates() {
    275                 return junctions;
    276         }
     120                return (Integer)o1.get(1) - (Integer)o2.get(1); //sort according to h index in each column
     121            }});
     122    }
     123
     124    public boolean IterateThroughKn() {//Iterates through all K_{n-1} subgrids of the Grid and tests them
     125        if (L.size()==0) {
     126            return true;
     127        }
     128        if (pmenabled) {
     129            pm.setTicksCount(L.size());
     130            pm.setCustomText("Iterates through all K_{n-1} subgrids of the Grid and tests them");
     131        }
     132        Combination c;
     133        Iterator<List<Object>> l = L.listIterator();
     134        List<Object> C;
     135        ArrayList<int[]> CandidateK = new ArrayList<int[]>(n*n); //saves the candidate K_{n-1} in entry-exit pairs
     136        long lindex= 0;
     137        int h = 0;
     138        int m = 0;
     139        int[][] v;
     140        int x_i;
     141        int y_j;
     142        int progressmonitorcounter = 1;
     143        boolean mchanged = false;
     144        boolean hchanged = false;
     145        C = l.next();
     146        do{ //Loop over list of columns L
     147            if (mchanged){
     148                C = l.next(); //Iterator in L
     149                lindex++; //Index in L
     150                if (hchanged) {
     151                    m=1;
     152                    hchanged = false;
     153                }
     154            }
     155            if ((Integer)C.get(1)==h && l.hasNext()){ //m counts the set of columns with index h
     156                m++;
     157                mchanged = true;
     158            }
     159            else{
     160                if (l.hasNext()==false){
     161                    m++;lindex++;
     162                } //At the end of L, counter are set one up
     163                c = new Combination(m, n);
     164                long ans = c.Choose();
     165                int missing = 0;
     166                boolean smallerjunction = false;
     167                for (int k =0; k<ans;k++){ //Makes sure that subset of m columns contains an n*n subgrid, because ans = m over n would be 0 otherwise
     168                    for (int y = 0; y < n; y++){//Iterates over all rows of subgrid k
     169                        missing =0;    //test = "";
     170                        for (int x = 0; x <c.data.length;x++) { //Iterates over all columns of subgrid k
     171                            x_i=((Integer)L.get((int)(lindex-m+c.data[x])).get(0));//columnindex in grid
     172                            v=((int[][])(L.get((int)(lindex-m+c.data[x])).get(2))); //subcolumn of grid
     173                            y_j= v[y][0]; //rowindex in grid
     174                            if (v[y][1]==0){
     175                                missing++;
     176                            }else{
     177                                CandidateK.add(new int[]{y_j,x_i});
     178                            }//save entry/exit tuple
     179                            if (smallerjunction == false && ((!OrEn.contains(E.get(v[y][0]))) &&(!OrEx.contains(E.get(x_i))))){ // Tests, whether y or x is not an original entry/exit
     180                                smallerjunction = true; //Then k identifies a different junction than the original one
     181                            }
     182                            //test = test+" ("+y_j+", "+x_i+", "+v[y][1]+")";
     183                        }
     184                        if (missing > 1){
     185                            break;
     186                        }//If a row has more than one missing value, break
     187                    }
     188                    if (missing <=1 && smallerjunction == true){//The k-subgrid is a different junction candidate satisfying total reachability
     189                        CheckMinimal = CheckSmallJunction(CandidateK)==false;// If the candidate is a smaller junction, then minimality is false
     190                        //log.info("durchlauf: " + durchlauf + " Wert von CheckMinimal: " + CheckMinimal);
     191                        if (!CheckMinimal) {
     192                            break;
     193                        }
     194                    }
     195                    CandidateK.clear();
     196                    if (k+1 < ans){c = c.Successor();} //Produces the m over n combinations
     197                }
     198                m=1; //Sets m to the first column with next index h+1
     199                h++;
     200                mchanged = false;
     201                hchanged = true;
     202            }
     203            if (pmenabled) {
     204                progressmonitorcounter++;
     205                pm.setTicks(progressmonitorcounter);
     206            }
     207        }
     208        while(l.hasNext() && CheckMinimal);
     209        return CheckMinimal;
     210    }
     211
     212    /**
     213    * gibt true zurück, wenn Kandidat eine Kreuzung ist, aber nicht, wenn junctionsearch auf true gesetzt ist
     214    * @param CandidateK
     215    * @return
     216    */
     217    public boolean CheckSmallJunction(ArrayList<int[]> CandidateK){
     218        Check = false;
     219        subgraph.clear();//Zu konstruierender Subgraph
     220        it = CandidateK.iterator();
     221        //Reconstruct small Junction from paths
     222        while (it.hasNext()){
     223            int[]point = it.next();
     224            for (int j = 0; j < E.get(point[0]).getReachableNodes().size(); j++) {
     225                if(E.get(point[0]).getReachableNodeAt(j).equals(E.get(point[1]))){
     226                    subgraph.addAll(E.get(point[0]).getPathsAt(E.get(point[0]).getReachableNodeAt(j)));
     227                    subgraph.add(E.get(point[0]));
     228                }
     229            }
     230        }
     231        jprepare.jPrepare(new ArrayList<Channel>(subgraph));
     232        JCheck jCheck = new JCheck();
     233        Check = jCheck.jCheck(jprepare.getEntries(), jprepare.getExits(), n);
     234        jprepare.resetSubgraph();
     235        if (Check) {
     236            subJunction.clear();
     237            subJunction.addAll(subgraph);
     238            //soll mehr als ein Kandidat gesucht werden? Dann Kandidaten speichern und Check wieder auf false stellen, damit die Hauptschleife weitergeht
     239            if (!searchFirstJunction) {
     240                boolean isin = false;
     241                for (int i = 0; i < junctions.size(); i++) {
     242                    //log.debug("Kreuzung " + i +" hat Channels: " + junctions.get(i).size() + " subgraph: " + subgraph.size());
     243                    if (junctions.get(i).size() == subgraph.size()) {
     244                        Iterator<Channel> it = subgraph.iterator();
     245                        isin = true;
     246                        while (it.hasNext()) {
     247                            if (!junctions.get(i).contains(it.next())) {
     248                                isin = false;
     249                                //log.info("nicht drin");
     250                            }
     251                        }
     252                    }
     253                }
     254                if (isin == false) {
     255                    junctions.add(new HashSet<Channel>(subgraph));
     256                    //log.info("Kreuzungskandidat der Liste zugefügt" + junctions.size());
     257                }
     258                Check = false;
     259            }
     260        }
     261        return Check;
     262    }
     263
     264    /**
     265    * enthält alle Channels des zuletzt durchlaufenden Kreuzungskandidaten (muß keine gültige Kreuzung sein)
     266    * @return
     267    */
     268    public ArrayList<Channel> getSubJunctionCandidate(){
     269        return new ArrayList<Channel>(subgraph);
     270    }
     271
     272    /**
     273    * gibt alle gefundenen Kreuzungskandidaten zurück (ist leer, wenn junctionsearch auf true gesetzt wurde)
     274    * @return
     275    */
     276    public ArrayList<HashSet<Channel>> getJunctionCandidates() {
     277        return junctions;
     278    }
    277279}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/junctionchecking/JPrepare.java

    r25501 r30725  
    1111public class JPrepare {
    1212
    13         private final ArrayList<Channel> entries;
    14         private final ArrayList<Channel> exits;
    15         private ArrayList<Channel> vertices;
    16         private final ChannelDiGraph digraph;
     13    private final ArrayList<Channel> entries;
     14    private final ArrayList<Channel> exits;
     15    private ArrayList<Channel> vertices;
     16    private final ChannelDiGraph digraph;
    1717
    18         public JPrepare(ChannelDiGraph digraph) {
    19                 entries = new ArrayList<Channel>();
    20                 exits = new ArrayList<Channel>();
    21                 this.digraph = digraph;
    22         }
     18    public JPrepare(ChannelDiGraph digraph) {
     19        entries = new ArrayList<Channel>();
     20        exits = new ArrayList<Channel>();
     21        this.digraph = digraph;
     22    }
    2323
    24         public void jPrepare (ArrayList<Channel> vertices) {
    25                 this.vertices = vertices;
    26                 entries.clear();
    27                 exits.clear();
     24    public void jPrepare (ArrayList<Channel> vertices) {
     25        this.vertices = vertices;
     26        entries.clear();
     27        exits.clear();
    2828
    29                 /*TODO: kann weg?
    30                 digraph.ereaseChannelsInDegree();
    31                 digraph.ereaseChannelsOutDegree();
    32                 digraph.ereaseChannelsSubgraph();
    33                 */
    34                 for (int i = 0; i < vertices.size(); i++) {
    35                         vertices.get(i).setSubgraph(true);
    36                 }
    37                 for (int i = 0; i < vertices.size(); i++) {
    38                         for (int j = 0; j < vertices.get(i).getPredChannels().size(); j++) {
    39                                 if (vertices.get(i).getPredChannels().get(j).isSubgraph() == false ) {
    40                                         if (!entries.contains(vertices.get(i))) {
    41                                                 entries.add(vertices.get(i));
    42                                         }
    43                                 }
    44                                 else {
    45                                         vertices.get(i).countupIndegree();
    46                                         //log.trace(vertices.get(i).toString());
    47                                 }
    48                         }
    49                         for (int j = 0; j < vertices.get(i).getLeadsTo().size(); j++) {
    50                                 if (vertices.get(i).getLeadsTo().get(j).getToChannel().isSubgraph() == false) {
    51                                         if (!exits.contains(vertices.get(i))) {
    52                                                 exits.add(vertices.get(i));
    53                                         }
    54                                 }
    55                                 else {
    56                                         vertices.get(i).countupOutdegree();
    57                                 }
    58                         }
    59                 }
    60         }
     29        /*TODO: kann weg?
     30        digraph.ereaseChannelsInDegree();
     31        digraph.ereaseChannelsOutDegree();
     32        digraph.ereaseChannelsSubgraph();
     33        */
     34        for (int i = 0; i < vertices.size(); i++) {
     35            vertices.get(i).setSubgraph(true);
     36        }
     37        for (int i = 0; i < vertices.size(); i++) {
     38            for (int j = 0; j < vertices.get(i).getPredChannels().size(); j++) {
     39                if (vertices.get(i).getPredChannels().get(j).isSubgraph() == false ) {
     40                    if (!entries.contains(vertices.get(i))) {
     41                        entries.add(vertices.get(i));
     42                    }
     43                }
     44                else {
     45                    vertices.get(i).countupIndegree();
     46                    //log.trace(vertices.get(i).toString());
     47                }
     48            }
     49            for (int j = 0; j < vertices.get(i).getLeadsTo().size(); j++) {
     50                if (vertices.get(i).getLeadsTo().get(j).getToChannel().isSubgraph() == false) {
     51                    if (!exits.contains(vertices.get(i))) {
     52                        exits.add(vertices.get(i));
     53                    }
     54                }
     55                else {
     56                    vertices.get(i).countupOutdegree();
     57                }
     58            }
     59        }
     60    }
    6161
    62         public void resetSubgraph(){
    63                 for (int i = 0; i < vertices.size(); i++) {
    64                         vertices.get(i).setSubgraph(false);
    65                         vertices.get(i).setIndegree(0);
    66                         vertices.get(i).setOutdegree(0);
    67                 }
    68         }
     62    public void resetSubgraph(){
     63        for (int i = 0; i < vertices.size(); i++) {
     64            vertices.get(i).setSubgraph(false);
     65            vertices.get(i).setIndegree(0);
     66            vertices.get(i).setOutdegree(0);
     67        }
     68    }
    6969
    70         /**
    71         * gibt die Anzahl der gefundenen Eingänge zurück
    72         * @return
    73         */
    74         public ArrayList<Channel> getEntries() {
    75                 return entries;
    76         }
     70    /**
     71    * gibt die Anzahl der gefundenen Eingänge zurück
     72    * @return
     73    */
     74    public ArrayList<Channel> getEntries() {
     75        return entries;
     76    }
    7777
    78         /**
    79         * gibt die Anzahl der gefundenen Ausgänge zurück
    80         * @return
    81         */
    82         public ArrayList<Channel> getExits() {
    83                 return exits;
    84         }
     78    /**
     79    * gibt die Anzahl der gefundenen Ausgänge zurück
     80    * @return
     81    */
     82    public ArrayList<Channel> getExits() {
     83        return exits;
     84    }
    8585}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/junctionchecking/JProcess.java

    r25501 r30725  
    1414public class JProcess {
    1515
    16         private ArrayList<Channel> vertices;
    17         private ChannelDiGraph digraph;
    18         private TRDFS trdfs;
    19         private BackPropagation backpropagation;
    20         private ArrayList<LeadsTo> cycleEdges;
     16    private ArrayList<Channel> vertices;
     17    private ChannelDiGraph digraph;
     18    private TRDFS trdfs;
     19    private BackPropagation backpropagation;
     20    private ArrayList<LeadsTo> cycleEdges;
    2121
    22         public JProcess(ArrayList<Channel> subgraph, ChannelDiGraph digraph) {
    23                 this.digraph = digraph;
    24                 this.vertices = subgraph;
    25                 this.trdfs = new TRDFS(vertices, digraph);
    26                 this.backpropagation = new BackPropagation(digraph);
    27         }
     22    public JProcess(ArrayList<Channel> subgraph, ChannelDiGraph digraph) {
     23        this.digraph = digraph;
     24        this.vertices = subgraph;
     25        this.trdfs = new TRDFS(vertices, digraph);
     26        this.backpropagation = new BackPropagation(digraph);
     27    }
    2828
    29         /**
    30         * ruft den TR-DFS und danach den Backpropagation-Algorithmus auf jPrepare
    31         * muß vorher durchgelaufen sein (die Eingänge müssen bekannt sein)
    32         *
    33         * @param entries
    34         */
    35         public void jProcess(ArrayList<Channel> entries) {
    36                 ArrayList<Channel> nodes = digraph.getChannels();
    37                 // alle Knoten des Subgraphen auf unbesucht stellen und
    38                 // die evtl. gespeicherten erreichbaren Knoten löschen
    39                 for (int i = 0; i < nodes.size(); i++) {
    40                         nodes.get(i).setVisited(BacktrackingColors.WHITE);
    41                         nodes.get(i).ereaseReachableNodes();
    42                 }
    43                 // alle Kanten auf keine ForwardEdge stellen
    44                 for (int i = 0; i < digraph.getLeadsTo().size(); i++) {
    45                         digraph.getLeadsTo().get(i).setForwardEdge(false);
    46                 }
    47                 trdfs.ereaseCycleEdges();
     29    /**
     30    * ruft den TR-DFS und danach den Backpropagation-Algorithmus auf jPrepare
     31    * muß vorher durchgelaufen sein (die Eingänge müssen bekannt sein)
     32    *
     33    * @param entries
     34    */
     35    public void jProcess(ArrayList<Channel> entries) {
     36        ArrayList<Channel> nodes = digraph.getChannels();
     37        // alle Knoten des Subgraphen auf unbesucht stellen und
     38        // die evtl. gespeicherten erreichbaren Knoten löschen
     39        for (int i = 0; i < nodes.size(); i++) {
     40            nodes.get(i).setVisited(BacktrackingColors.WHITE);
     41            nodes.get(i).ereaseReachableNodes();
     42        }
     43        // alle Kanten auf keine ForwardEdge stellen
     44        for (int i = 0; i < digraph.getLeadsTo().size(); i++) {
     45            digraph.getLeadsTo().get(i).setForwardEdge(false);
     46        }
     47        trdfs.ereaseCycleEdges();
    4848
    49                 for (int i = 0; i < entries.size(); i++) {
    50                         if (entries.get(i).getVisited() == BacktrackingColors.WHITE) {
    51                                 trdfs.trdfs(entries.get(i));
    52                         }
    53                 }
    54                 cycleEdges = trdfs.getCycleEdges();
    55                 for (int j = 0; j < cycleEdges.size(); j++) {
    56                         backpropagation.backPropagation(cycleEdges.get(j).getFromChannel(),
    57                                         cycleEdges.get(j).getToChannel(), cycleEdges.get(j).getToChannel());
    58                 }
    59         }
     49        for (int i = 0; i < entries.size(); i++) {
     50            if (entries.get(i).getVisited() == BacktrackingColors.WHITE) {
     51                trdfs.trdfs(entries.get(i));
     52            }
     53        }
     54        cycleEdges = trdfs.getCycleEdges();
     55        for (int j = 0; j < cycleEdges.size(); j++) {
     56            backpropagation.backPropagation(cycleEdges.get(j).getFromChannel(),
     57                    cycleEdges.get(j).getToChannel(), cycleEdges.get(j).getToChannel());
     58        }
     59    }
    6060}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/junctionchecking/JunctionChecker.java

    r30532 r30725  
    1717public class JunctionChecker {
    1818
    19         private ArrayList<Channel> subgraph;
    20         private ArrayList<Channel> entries;
    21         private ArrayList<Channel> exits;
    22         private ArrayList<Channel> cycleedges;
    23         private ArrayList<Channel> subjunction;
    24         private int n;
    25         private final JPrepare jPrepare;
    26         private JProcess jProcess;
    27         private final ChannelDiGraph channeldigraph;
    28         private final JCheck jCheck;
    29         private ArrayList<Channel> E;
    30         private int Grid[][];
    31         private boolean Check;
    32         private boolean smallerJunction;
    33         private JMinimality m;
    34         // Variable wird beim KreuzungsSuchen benutzt, sonst ist sie leer!
    35         private ArrayList<HashSet<Channel>> junctions = new ArrayList<HashSet<Channel>>();
    36         //dient zur Zeitmessung
    37         private long startIterate = 0;
    38         private long stopIterate = 0;
    39         private long startGenerate = 0;
    40 
    41         public JunctionChecker(ChannelDiGraph channeldigraph, int n) {
    42                 this.jPrepare = new JPrepare(channeldigraph);
    43                 this.channeldigraph = channeldigraph;
    44                 this.n = n;
    45                 this.jCheck = new JCheck();
    46                 this.subjunction = new ArrayList<Channel>();
    47                 smallerJunction = false;
    48         }
    49 
    50         /**
    51         * startet das Überprüfen einer Teilmenge auf die Kreuzungskriterien
    52         * @param subgraph
    53         * @param pm
    54         */
    55         public void checkjunctions(ArrayList<Channel> subgraph, ProgressMonitor pm) {
    56                 jPrepare.jPrepare(subgraph);
    57                 entries = jPrepare.getEntries();
    58                 exits = jPrepare.getExits();
    59                 jProcess = new JProcess(subgraph, channeldigraph);
    60                 jProcess.jProcess(jPrepare.getEntries());
    61                 boolean result = jCheck.jCheck(entries, exits, n);
    62                 //jPrepare.resetSubgraph();
    63                 if (result == true) {
    64                         this.collectECandidates(subgraph);
    65                         this.ConstructGrid();
    66                         m = new JMinimality(Grid, n, E, entries, exits, channeldigraph, pm,
    67                                         true);
    68                         m.GenerateSubcolumns();
    69                         Check = m.IterateThroughKn();
    70                         if (!Check) {
    71                                 smallerJunction = true;
    72                         }
    73                         subjunction = m.getSubJunctionCandidate();
    74                 } else {
    75                         Check = false;
    76                 }
    77         }
    78 
    79         /**
    80         * Diese Methode wird aufgerufen, wenn nach Kreuzungen in einer Teilmenge
    81         * gesucht werden soll
    82         *
    83         * @param subgraph
    84         * @param firstjunction soll nur die erste mögliche Kreuzung ausgegeben werden oder alle
    85         */
    86         public void junctionSearch(ArrayList<Channel> subgraph, ProgressMonitor pm) {
    87                 jPrepare.jPrepare(subgraph);
    88                 entries = jPrepare.getEntries();
    89                 exits = jPrepare.getExits();
    90                 jProcess = new JProcess(subgraph, channeldigraph);
    91                 jProcess.jProcess(jPrepare.getEntries());
    92                 this.collectECandidates(subgraph);
    93                 this.ConstructGrid();
    94                 jPrepare.resetSubgraph();
    95                 m = new JMinimality(Grid, n, E, new ArrayList<Channel>(), new ArrayList<Channel>(), channeldigraph, pm, false);
    96                 m.GenerateSubcolumns();
    97                 Check = m.IterateThroughKn();
    98                 junctions = checkJunctionCandidates(m.getJunctionCandidates());
    99         }
    100 
    101         public void junctionSearch(ArrayList<Channel> subgraph) {
    102                 jPrepare.jPrepare(subgraph);
    103                 entries = jPrepare.getEntries();
    104                 exits = jPrepare.getExits();
    105                 jProcess = new JProcess(subgraph, channeldigraph);
    106                 jProcess.jProcess(jPrepare.getEntries());
    107                 this.collectECandidates(subgraph);
    108                 this.ConstructGrid();
    109                 jPrepare.resetSubgraph();
    110                 m = new JMinimality(Grid, n, E, new ArrayList<Channel>(), new ArrayList<Channel>(), channeldigraph, false);
    111                 startGenerate = System.currentTimeMillis();
    112                 m.GenerateSubcolumns();
    113                 startIterate = System.currentTimeMillis();
    114                 Check = m.IterateThroughKn();
    115                 stopIterate = System.currentTimeMillis();
    116                 junctions = checkJunctionCandidates(m.getJunctionCandidates());
    117         }
    118 
    119         /**
    120         * Überprüft die Kreuzunskandidaten, die JMinimality gefunden hat, welche davon eine Kreuzung darstellen (eine Kreuzung
    121         * darf keine weiteren Kreuzungen enthalten)
    122         */
    123         private ArrayList<HashSet<Channel>> checkJunctionCandidates(ArrayList<HashSet<Channel>> junctioncandidates){
    124                 @SuppressWarnings("unchecked")
     19    private ArrayList<Channel> subgraph;
     20    private ArrayList<Channel> entries;
     21    private ArrayList<Channel> exits;
     22    private ArrayList<Channel> cycleedges;
     23    private ArrayList<Channel> subjunction;
     24    private int n;
     25    private final JPrepare jPrepare;
     26    private JProcess jProcess;
     27    private final ChannelDiGraph channeldigraph;
     28    private final JCheck jCheck;
     29    private ArrayList<Channel> E;
     30    private int Grid[][];
     31    private boolean Check;
     32    private boolean smallerJunction;
     33    private JMinimality m;
     34    // Variable wird beim KreuzungsSuchen benutzt, sonst ist sie leer!
     35    private ArrayList<HashSet<Channel>> junctions = new ArrayList<HashSet<Channel>>();
     36    //dient zur Zeitmessung
     37    private long startIterate = 0;
     38    private long stopIterate = 0;
     39    private long startGenerate = 0;
     40
     41    public JunctionChecker(ChannelDiGraph channeldigraph, int n) {
     42        this.jPrepare = new JPrepare(channeldigraph);
     43        this.channeldigraph = channeldigraph;
     44        this.n = n;
     45        this.jCheck = new JCheck();
     46        this.subjunction = new ArrayList<Channel>();
     47        smallerJunction = false;
     48    }
     49
     50    /**
     51    * startet das Überprüfen einer Teilmenge auf die Kreuzungskriterien
     52    * @param subgraph
     53    * @param pm
     54    */
     55    public void checkjunctions(ArrayList<Channel> subgraph, ProgressMonitor pm) {
     56        jPrepare.jPrepare(subgraph);
     57        entries = jPrepare.getEntries();
     58        exits = jPrepare.getExits();
     59        jProcess = new JProcess(subgraph, channeldigraph);
     60        jProcess.jProcess(jPrepare.getEntries());
     61        boolean result = jCheck.jCheck(entries, exits, n);
     62        //jPrepare.resetSubgraph();
     63        if (result == true) {
     64            this.collectECandidates(subgraph);
     65            this.ConstructGrid();
     66            m = new JMinimality(Grid, n, E, entries, exits, channeldigraph, pm,
     67                    true);
     68            m.GenerateSubcolumns();
     69            Check = m.IterateThroughKn();
     70            if (!Check) {
     71                smallerJunction = true;
     72            }
     73            subjunction = m.getSubJunctionCandidate();
     74        } else {
     75            Check = false;
     76        }
     77    }
     78
     79    /**
     80    * Diese Methode wird aufgerufen, wenn nach Kreuzungen in einer Teilmenge
     81    * gesucht werden soll
     82    *
     83    * @param subgraph
     84    * @param firstjunction soll nur die erste mögliche Kreuzung ausgegeben werden oder alle
     85    */
     86    public void junctionSearch(ArrayList<Channel> subgraph, ProgressMonitor pm) {
     87        jPrepare.jPrepare(subgraph);
     88        entries = jPrepare.getEntries();
     89        exits = jPrepare.getExits();
     90        jProcess = new JProcess(subgraph, channeldigraph);
     91        jProcess.jProcess(jPrepare.getEntries());
     92        this.collectECandidates(subgraph);
     93        this.ConstructGrid();
     94        jPrepare.resetSubgraph();
     95        m = new JMinimality(Grid, n, E, new ArrayList<Channel>(), new ArrayList<Channel>(), channeldigraph, pm, false);
     96        m.GenerateSubcolumns();
     97        Check = m.IterateThroughKn();
     98        junctions = checkJunctionCandidates(m.getJunctionCandidates());
     99    }
     100
     101    public void junctionSearch(ArrayList<Channel> subgraph) {
     102        jPrepare.jPrepare(subgraph);
     103        entries = jPrepare.getEntries();
     104        exits = jPrepare.getExits();
     105        jProcess = new JProcess(subgraph, channeldigraph);
     106        jProcess.jProcess(jPrepare.getEntries());
     107        this.collectECandidates(subgraph);
     108        this.ConstructGrid();
     109        jPrepare.resetSubgraph();
     110        m = new JMinimality(Grid, n, E, new ArrayList<Channel>(), new ArrayList<Channel>(), channeldigraph, false);
     111        startGenerate = System.currentTimeMillis();
     112        m.GenerateSubcolumns();
     113        startIterate = System.currentTimeMillis();
     114        Check = m.IterateThroughKn();
     115        stopIterate = System.currentTimeMillis();
     116        junctions = checkJunctionCandidates(m.getJunctionCandidates());
     117    }
     118
     119    /**
     120    * Überprüft die Kreuzunskandidaten, die JMinimality gefunden hat, welche davon eine Kreuzung darstellen (eine Kreuzung
     121    * darf keine weiteren Kreuzungen enthalten)
     122    */
     123    private ArrayList<HashSet<Channel>> checkJunctionCandidates(ArrayList<HashSet<Channel>> junctioncandidates){
     124        @SuppressWarnings("unchecked")
    125125        ArrayList<HashSet<Channel>> junctions = (ArrayList<HashSet<Channel>>) junctioncandidates.clone();
    126                 for (int i = 0; i < junctioncandidates.size(); i++) {
    127                         for (int j = 0; j < junctioncandidates.size(); j++) {
    128                                 if (junctioncandidates.get(i).containsAll(junctioncandidates.get(j))) {
    129                                         junctions.removeAll(junctioncandidates.get(i));
    130                                 }
    131                                 else {
    132                                 }
    133                         }
    134                 }
    135                 return junctions;
    136         }
    137 
    138 
    139         private void collectECandidates(ArrayList<Channel> subgraph) {
    140                 E = new ArrayList<Channel>();
    141                 for (int i = 0; i < subgraph.size(); i++) {
    142                         if ((subgraph.get(i).getIndegree() + subgraph.get(i).getOutdegree() >= 3)
    143                                         || entries.contains(subgraph.get(i))
    144                                         || exits.contains(subgraph.get(i))) {
    145                                 E.add(subgraph.get(i));
    146                         }
    147                 }
    148         }
    149 
    150         private void ConstructGrid() {
    151                 Grid = new int[E.size()][E.size()];
    152                 for (int y = 0; y < E.size(); y++) {
    153                         for (int x = 0; x < E.size(); x++) {
    154                                 if (x != y && !(entries.contains(E.get(x)))
    155                                                 && !(exits.contains(E.get(y)))
    156                                                 && E.get(y).getReachableNodes().contains(E.get(x))) {
    157                                         Grid[y][x] = 1;
    158                                         //log.trace("Grid-Position auf 1 gesetzT (y/x): " + y + ":"
    159                                         //              + x + "(Entry/exit):" + E.get(y).getNewid() + ":" +
    160                                         //              E.get(x).getNewid());
    161                                 } else {
    162                                         Grid[y][x] = 0;
    163                                 }
    164                         }
    165                 }
    166         }
    167 
    168         public long getMeasuredIterateTime() {
    169                 return (stopIterate - startIterate);
    170         }
    171 
    172         public long getMeasuredGenerateTime() {
    173                 return (startIterate - startGenerate);
    174         }
    175 
    176         public ArrayList<Channel> getSubgraph() {
    177                 return subgraph;
    178         }
    179 
    180         public void setSubgraph(ArrayList<Channel> subgraph) {
    181                 this.subgraph = subgraph;
    182         }
    183 
    184         public ArrayList<Channel> getEntries() {
    185                 return entries;
    186         }
    187 
    188         public void setEntries(ArrayList<Channel> entries) {
    189                 this.entries = entries;
    190         }
    191 
    192         public ArrayList<Channel> getExits() {
    193                 return exits;
    194         }
    195 
    196         public void setExits(ArrayList<Channel> exits) {
    197                 this.exits = exits;
    198         }
    199 
    200         public ArrayList<Channel> getCycleedges() {
    201                 return cycleedges;
    202         }
    203 
    204         public void setCycleedges(ArrayList<Channel> cycleedges) {
    205                 this.cycleedges = cycleedges;
    206         }
    207 
    208         public int getN() {
    209                 return n;
    210         }
    211 
    212         public void setN(int n) {
    213                 this.n = n;
    214         }
    215 
    216         /**
    217         * gibt die kleinere, gefundene Kreuzung zurück (wenn es sie gibt)
    218         *
    219         * @return
    220         */
    221         public ArrayList<Channel> getSubJunction() {
    222                 return subjunction;
    223         }
    224 
    225         /**
    226         * gibt das Ergebnis des JCheck zurück (bei false keine generelle Aussage
    227         * möglich)
    228         *
    229         * @return false = keine Kreuzung ODER enthält kleinere Kreuzung true =
    230         *         Kreuzung
    231         *
    232         */
    233         public boolean getCheck() {
    234                 return Check;
    235         }
    236 
    237         /**
    238         * gibt den Wert des JMinimality zurück (wenn er ausgeführt wurde)
    239         *
    240         * @return true = keine kleinere kreuzung, false = kleinere kreuzung
    241         *         enthalten
    242         */
    243         public boolean isSmallerJunction() {
    244                 return smallerJunction;
    245         }
    246 
    247         /**
    248         * das Ergebnis des JCheck als String
    249         *
    250         * @return
    251         */
    252         public String getJCheckResult() {
    253                 return jCheck.getResult();
    254         }
    255 
    256         /**
    257         * gitb die bei der Kruezungssuche gefundenen Kreuzungen zurück, sonst
    258         * nichts
    259         *
    260         * @return
    261         */
    262         public ArrayList<HashSet<Channel>> getJunctions() {
    263                 return junctions;
    264         }
     126        for (int i = 0; i < junctioncandidates.size(); i++) {
     127            for (int j = 0; j < junctioncandidates.size(); j++) {
     128                if (junctioncandidates.get(i).containsAll(junctioncandidates.get(j))) {
     129                    junctions.removeAll(junctioncandidates.get(i));
     130                }
     131                else {
     132                }
     133            }
     134        }
     135        return junctions;
     136    }
     137
     138
     139    private void collectECandidates(ArrayList<Channel> subgraph) {
     140        E = new ArrayList<Channel>();
     141        for (int i = 0; i < subgraph.size(); i++) {
     142            if ((subgraph.get(i).getIndegree() + subgraph.get(i).getOutdegree() >= 3)
     143                    || entries.contains(subgraph.get(i))
     144                    || exits.contains(subgraph.get(i))) {
     145                E.add(subgraph.get(i));
     146            }
     147        }
     148    }
     149
     150    private void ConstructGrid() {
     151        Grid = new int[E.size()][E.size()];
     152        for (int y = 0; y < E.size(); y++) {
     153            for (int x = 0; x < E.size(); x++) {
     154                if (x != y && !(entries.contains(E.get(x)))
     155                        && !(exits.contains(E.get(y)))
     156                        && E.get(y).getReachableNodes().contains(E.get(x))) {
     157                    Grid[y][x] = 1;
     158                    //log.trace("Grid-Position auf 1 gesetzT (y/x): " + y + ":"
     159                    //        + x + "(Entry/exit):" + E.get(y).getNewid() + ":" +
     160                    //        E.get(x).getNewid());
     161                } else {
     162                    Grid[y][x] = 0;
     163                }
     164            }
     165        }
     166    }
     167
     168    public long getMeasuredIterateTime() {
     169        return (stopIterate - startIterate);
     170    }
     171
     172    public long getMeasuredGenerateTime() {
     173        return (startIterate - startGenerate);
     174    }
     175
     176    public ArrayList<Channel> getSubgraph() {
     177        return subgraph;
     178    }
     179
     180    public void setSubgraph(ArrayList<Channel> subgraph) {
     181        this.subgraph = subgraph;
     182    }
     183
     184    public ArrayList<Channel> getEntries() {
     185        return entries;
     186    }
     187
     188    public void setEntries(ArrayList<Channel> entries) {
     189        this.entries = entries;
     190    }
     191
     192    public ArrayList<Channel> getExits() {
     193        return exits;
     194    }
     195
     196    public void setExits(ArrayList<Channel> exits) {
     197        this.exits = exits;
     198    }
     199
     200    public ArrayList<Channel> getCycleedges() {
     201        return cycleedges;
     202    }
     203
     204    public void setCycleedges(ArrayList<Channel> cycleedges) {
     205        this.cycleedges = cycleedges;
     206    }
     207
     208    public int getN() {
     209        return n;
     210    }
     211
     212    public void setN(int n) {
     213        this.n = n;
     214    }
     215
     216    /**
     217    * gibt die kleinere, gefundene Kreuzung zurück (wenn es sie gibt)
     218    *
     219    * @return
     220    */
     221    public ArrayList<Channel> getSubJunction() {
     222        return subjunction;
     223    }
     224
     225    /**
     226    * gibt das Ergebnis des JCheck zurück (bei false keine generelle Aussage
     227    * möglich)
     228    *
     229    * @return false = keine Kreuzung ODER enthält kleinere Kreuzung true =
     230    *         Kreuzung
     231    *
     232    */
     233    public boolean getCheck() {
     234        return Check;
     235    }
     236
     237    /**
     238    * gibt den Wert des JMinimality zurück (wenn er ausgeführt wurde)
     239    *
     240    * @return true = keine kleinere kreuzung, false = kleinere kreuzung
     241    *         enthalten
     242    */
     243    public boolean isSmallerJunction() {
     244        return smallerJunction;
     245    }
     246
     247    /**
     248    * das Ergebnis des JCheck als String
     249    *
     250    * @return
     251    */
     252    public String getJCheckResult() {
     253        return jCheck.getResult();
     254    }
     255
     256    /**
     257    * gitb die bei der Kruezungssuche gefundenen Kreuzungen zurück, sonst
     258    * nichts
     259    *
     260    * @return
     261    */
     262    public ArrayList<HashSet<Channel>> getJunctions() {
     263        return junctions;
     264    }
    265265}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/junctionchecking/TRDFS.java

    r25501 r30725  
    1313public class TRDFS {
    1414
    15         private final ArrayList<Channel> vertices;
    16         private Channel startNode;
    17         private final ArrayList<LeadsTo> cycleEdges;
    18         private final ChannelDiGraph digraph;
     15    private final ArrayList<Channel> vertices;
     16    private Channel startNode;
     17    private final ArrayList<LeadsTo> cycleEdges;
     18    private final ChannelDiGraph digraph;
    1919
    20         /**
    21         *
    22         *
    23         * @param adnodes
    24         */
    25         public TRDFS(ArrayList<Channel> adnodes, ChannelDiGraph digraph) {
    26                 this.vertices = adnodes;
    27                 this.digraph = digraph;
    28                 this.cycleEdges = new ArrayList<LeadsTo>();
    29         }
     20    /**
     21    *
     22    *
     23    * @param adnodes
     24    */
     25    public TRDFS(ArrayList<Channel> adnodes, ChannelDiGraph digraph) {
     26        this.vertices = adnodes;
     27        this.digraph = digraph;
     28        this.cycleEdges = new ArrayList<LeadsTo>();
     29    }
    3030
    3131
    32         public void trdfs(Channel startNode) {
    33                 Channel succNode;
    34                 startNode.setVisited(BacktrackingColors.GREY);
    35                 startNode.addReachableNode(startNode);
    36                 startNode.appendChannelToPath(startNode, startNode);
    37                 for (int i = 0; i < startNode.getLeadsTo().size(); i++) {
    38                         succNode = startNode.getLeadsTo().get(i).getToChannel();
    39                         if (succNode.isSubgraph()) {
    40                                 if (succNode.getVisited() == BacktrackingColors.WHITE) {
    41                                         digraph.setForwardEdge(startNode, succNode);
    42                                         trdfs(succNode);
    43                                 } else if (succNode.getVisited() == BacktrackingColors.GREY) {
    44                                         cycleEdges.add(digraph.getLeadsTo(startNode,
    45                                                         succNode));
    46                                 }
    47                                 for (int j = 0; j < succNode.getReachableNodes().size(); j++) {
     32    public void trdfs(Channel startNode) {
     33        Channel succNode;
     34        startNode.setVisited(BacktrackingColors.GREY);
     35        startNode.addReachableNode(startNode);
     36        startNode.appendChannelToPath(startNode, startNode);
     37        for (int i = 0; i < startNode.getLeadsTo().size(); i++) {
     38            succNode = startNode.getLeadsTo().get(i).getToChannel();
     39            if (succNode.isSubgraph()) {
     40                if (succNode.getVisited() == BacktrackingColors.WHITE) {
     41                    digraph.setForwardEdge(startNode, succNode);
     42                    trdfs(succNode);
     43                } else if (succNode.getVisited() == BacktrackingColors.GREY) {
     44                    cycleEdges.add(digraph.getLeadsTo(startNode,
     45                            succNode));
     46                }
     47                for (int j = 0; j < succNode.getReachableNodes().size(); j++) {
    4848
    49                                         startNode.addReachableNode(succNode.getReachableNodeAt(j));
    50                                         succNode.appendChannelToPath(succNode.getReachableNodeAt(j), succNode.getReachableNodeAt(j));
    51                                         succNode.appendChannelToPath(succNode.getReachableNodeAt(j), succNode);
    52                                         startNode.appendPath(succNode.getReachableNodeAt(j), succNode.getPathsAt(succNode.getReachableNodeAt(j)));
    53                                 }
    54                         }
     49                    startNode.addReachableNode(succNode.getReachableNodeAt(j));
     50                    succNode.appendChannelToPath(succNode.getReachableNodeAt(j), succNode.getReachableNodeAt(j));
     51                    succNode.appendChannelToPath(succNode.getReachableNodeAt(j), succNode);
     52                    startNode.appendPath(succNode.getReachableNodeAt(j), succNode.getPathsAt(succNode.getReachableNodeAt(j)));
     53                }
     54            }
    5555
    56                 }
    57                 startNode.setVisited(BacktrackingColors.BLACK);
    58         }
     56        }
     57        startNode.setVisited(BacktrackingColors.BLACK);
     58    }
    5959
    60         public void ereaseCycleEdges() {
    61                 cycleEdges.clear();
    62         }
     60    public void ereaseCycleEdges() {
     61        cycleEdges.clear();
     62    }
    6363
    64         public int getCycleedgesSize() {
    65                 return cycleEdges.size();
    66         }
     64    public int getCycleedgesSize() {
     65        return cycleEdges.size();
     66    }
    6767
    68         public LeadsTo getCycleEdgeAt(int i) {
    69                 return cycleEdges.get(i);
    70         }
     68    public LeadsTo getCycleEdgeAt(int i) {
     69        return cycleEdges.get(i);
     70    }
    7171
    72         public ArrayList<LeadsTo> getCycleEdges() {
    73                 return cycleEdges;
    74         }
     72    public ArrayList<LeadsTo> getCycleEdges() {
     73        return cycleEdges;
     74    }
    7575}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/reader/ColorSchemeXMLReader.java

    r25501 r30725  
    88public class ColorSchemeXMLReader extends XMLReader{
    99
    10         private HashMap<String, Color> colorScheme;
     10    private HashMap<String, Color> colorScheme;
    1111
    12         public ColorSchemeXMLReader(String filename) {
    13                 super(filename);
    14                 parseXML();
    15         }
     12    public ColorSchemeXMLReader(String filename) {
     13        super(filename);
     14        parseXML();
     15    }
    1616
    17         /**
    18         * gibt die zu dieser Objektklasse gespeicherte Farbe zurück
    19         * @param s Objektklasse
    20         * @return die passende Farbe, existiert keine wird grey zurückgegeben
    21         */
    22         public Color getColor(String s) {
    23                 if (colorScheme.containsKey(s)) {
    24                         return colorScheme.get(s);
    25                 }
    26                 else {
    27                         return Color.GRAY;
    28                 }
    29         }
     17    /**
     18    * gibt die zu dieser Objektklasse gespeicherte Farbe zurück
     19    * @param s Objektklasse
     20    * @return die passende Farbe, existiert keine wird grey zurückgegeben
     21    */
     22    public Color getColor(String s) {
     23        if (colorScheme.containsKey(s)) {
     24            return colorScheme.get(s);
     25        }
     26        else {
     27            return Color.GRAY;
     28        }
     29    }
    3030
    31         @Override
    32         public void parseXML() {
    33                 colorScheme = new HashMap<String, Color>();
    34                 String tempValue;
    35                 //String tempKeyValue ="";
    36                 try {
    37                         while (parser.hasNext()) {
    38                                 switch (parser.getEventType()) {
     31    @Override
     32    public void parseXML() {
     33        colorScheme = new HashMap<String, Color>();
     34        String tempValue;
     35        //String tempKeyValue ="";
     36        try {
     37            while (parser.hasNext()) {
     38                switch (parser.getEventType()) {
    3939
    40                                 case XMLStreamConstants.START_ELEMENT:
    41                                         tempValue = parser.getAttributeValue(null, "color");
    42                                         if (tempValue != null) {
    43                                                 String[] erg = tempValue.split(",");
    44                                                 Color c = new Color(Integer.parseInt(erg[0]), Integer.parseInt(erg[1]), Integer.parseInt(erg[2]));
    45                                                 colorScheme.put(parser.getLocalName(),c);
    46                                         }
    47                                         break;
    48                                 }
    49                                 parser.next();
    50                         }
    51                 } catch (XMLStreamException e) {
    52                         System.out.println(e);
    53                 }
    54         }
     40                case XMLStreamConstants.START_ELEMENT:
     41                    tempValue = parser.getAttributeValue(null, "color");
     42                    if (tempValue != null) {
     43                        String[] erg = tempValue.split(",");
     44                        Color c = new Color(Integer.parseInt(erg[0]), Integer.parseInt(erg[1]), Integer.parseInt(erg[2]));
     45                        colorScheme.put(parser.getLocalName(),c);
     46                    }
     47                    break;
     48                }
     49                parser.next();
     50            }
     51        } catch (XMLStreamException e) {
     52            System.out.println(e);
     53        }
     54    }
    5555}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/reader/OSMXMLReader.java

    r25501 r30725  
    1616public class OSMXMLReader extends XMLReader {
    1717
    18         private OSMGraph osmgraph = new OSMGraph();
     18    private OSMGraph osmgraph = new OSMGraph();
    1919
    20         public OSMXMLReader(String filename) {
    21                 super(filename);
    22         }
     20    public OSMXMLReader(String filename) {
     21        super(filename);
     22    }
    2323
    24         public OSMXMLReader(File file) {
    25                 super(file);
    26         }
     24    public OSMXMLReader(File file) {
     25        super(file);
     26    }
    2727
    28         private void readAttributes(OSMEntity entity) {
    29                 String temp = parser.getAttributeValue(null, "changeset");
    30                 if (temp != null) {
    31                         entity.setChangeset(Integer.parseInt(temp));
    32                 }
    33                 entity.setId(Long.parseLong(parser.getAttributeValue(null, "id")));
    34                 entity.setTimestamp(parser.getAttributeValue(null, "timestamp"));
     28    private void readAttributes(OSMEntity entity) {
     29        String temp = parser.getAttributeValue(null, "changeset");
     30        if (temp != null) {
     31            entity.setChangeset(Integer.parseInt(temp));
     32        }
     33        entity.setId(Long.parseLong(parser.getAttributeValue(null, "id")));
     34        entity.setTimestamp(parser.getAttributeValue(null, "timestamp"));
    3535
    36                 temp = parser.getAttributeValue(null, "uid");
    37                 if (temp != null)
    38                         entity.setUid(Integer.parseInt(temp));
     36        temp = parser.getAttributeValue(null, "uid");
     37        if (temp != null)
     38            entity.setUid(Integer.parseInt(temp));
    3939
    40                 temp = parser.getAttributeValue(null, "uid");
    41                 if (temp != null) {
    42                         entity.setUid(Integer.parseInt(temp));
    43                 }
    44                 entity.setUser(parser.getAttributeValue(null, "user"));
     40        temp = parser.getAttributeValue(null, "uid");
     41        if (temp != null) {
     42            entity.setUid(Integer.parseInt(temp));
     43        }
     44        entity.setUser(parser.getAttributeValue(null, "user"));
    4545
    46                 temp = parser.getAttributeValue(null, "visible");
    47                 if (temp != null) {
    48                         if (temp.equals("true") || temp.equals("1")) {
    49                                 entity.setVisible(true);
    50                         }
    51                 } else {
    52                         entity.setVisible(false);
    53                 }
    54                 temp = parser.getAttributeValue(null, "version");
    55                 if (temp != null) {
    56                         entity.setversion(Integer.parseInt(temp));
    57                 }
    58         }
     46        temp = parser.getAttributeValue(null, "visible");
     47        if (temp != null) {
     48            if (temp.equals("true") || temp.equals("1")) {
     49                entity.setVisible(true);
     50            }
     51        } else {
     52            entity.setVisible(false);
     53        }
     54        temp = parser.getAttributeValue(null, "version");
     55        if (temp != null) {
     56            entity.setversion(Integer.parseInt(temp));
     57        }
     58    }
    5959
    60         private void readMember(OSMRelation relation) {
    61                 if (parser.getAttributeValue(null, "type").equals("node")) {
    62                         relation.addMember(osmgraph.getNode(Integer.parseInt(parser
    63                                         .getAttributeValue(null, "ref"))), parser
    64                                         .getAttributeValue(null, "role"));
    65                 }
    66                 else if (parser.getAttributeValue(null, "type").equals("way")) {
    67                         relation.addMember(osmgraph.getWay(Long.parseLong(parser
    68                                         .getAttributeValue(null, "ref"))), parser
    69                                         .getAttributeValue(null, "role"));
    70                 }
    71                 else if (parser.getAttributeValue(null, "type").equals("relation")) {
    72                         relation.addMember(osmgraph.getRelation(Integer.parseInt(parser
    73                                         .getAttributeValue(null, "ref"))), parser
    74                                         .getAttributeValue(null, "role"));
    75                 }
    76         }
     60    private void readMember(OSMRelation relation) {
     61        if (parser.getAttributeValue(null, "type").equals("node")) {
     62            relation.addMember(osmgraph.getNode(Integer.parseInt(parser
     63                    .getAttributeValue(null, "ref"))), parser
     64                    .getAttributeValue(null, "role"));
     65        }
     66        else if (parser.getAttributeValue(null, "type").equals("way")) {
     67            relation.addMember(osmgraph.getWay(Long.parseLong(parser
     68                    .getAttributeValue(null, "ref"))), parser
     69                    .getAttributeValue(null, "role"));
     70        }
     71        else if (parser.getAttributeValue(null, "type").equals("relation")) {
     72            relation.addMember(osmgraph.getRelation(Integer.parseInt(parser
     73                    .getAttributeValue(null, "ref"))), parser
     74                    .getAttributeValue(null, "role"));
     75        }
     76    }
    7777
    78         @Override
    79         public void parseXML() {
    80                 String xmlelement;
    81                 OSMNode node = new OSMNode();
    82                 OSMWay way = new OSMWay();
    83                 OSMRelation relation = new OSMRelation();
    84                 HashMap<String, String> hashmap = new HashMap<String, String>();
    85                 try {
    86                         while (parser.hasNext()) {
    87                                 switch (parser.getEventType()) {
     78    @Override
     79    public void parseXML() {
     80        String xmlelement;
     81        OSMNode node = new OSMNode();
     82        OSMWay way = new OSMWay();
     83        OSMRelation relation = new OSMRelation();
     84        HashMap<String, String> hashmap = new HashMap<String, String>();
     85        try {
     86            while (parser.hasNext()) {
     87                switch (parser.getEventType()) {
    8888
    89                                 case XMLStreamConstants.START_ELEMENT:
    90                                         xmlelement = parser.getLocalName();
     89                case XMLStreamConstants.START_ELEMENT:
     90                    xmlelement = parser.getLocalName();
    9191
    92                                         if (xmlelement.equals("node")) {
    93                                                 node = new OSMNode();
    94                                                 hashmap = new HashMap<String, String>();
    95                                                 readAttributes(node);
    96                                                 node.setLatitude(Double.parseDouble(parser
    97                                                                 .getAttributeValue(null, "lat")));
    98                                                 node.setLongitude(Double.parseDouble(parser
    99                                                                 .getAttributeValue(null, "lon")));
    100                                         }
     92                    if (xmlelement.equals("node")) {
     93                        node = new OSMNode();
     94                        hashmap = new HashMap<String, String>();
     95                        readAttributes(node);
     96                        node.setLatitude(Double.parseDouble(parser
     97                                .getAttributeValue(null, "lat")));
     98                        node.setLongitude(Double.parseDouble(parser
     99                                .getAttributeValue(null, "lon")));
     100                    }
    101101
    102                                         if (xmlelement.equals("way")) {
    103                                                 way = new OSMWay();
    104                                                 hashmap = new HashMap<String, String>();
    105                                                 readAttributes(way);
    106                                         }
     102                    if (xmlelement.equals("way")) {
     103                        way = new OSMWay();
     104                        hashmap = new HashMap<String, String>();
     105                        readAttributes(way);
     106                    }
    107107
    108                                         if (xmlelement.equals("relation")) {
    109                                                 relation = new OSMRelation();
    110                                                 hashmap = new HashMap<String, String>();
    111                                                 readAttributes(relation);
    112                                         }
     108                    if (xmlelement.equals("relation")) {
     109                        relation = new OSMRelation();
     110                        hashmap = new HashMap<String, String>();
     111                        readAttributes(relation);
     112                    }
    113113
    114                                         if (xmlelement.equals("member")) {
    115                                                 readMember(relation);
    116                                         }
     114                    if (xmlelement.equals("member")) {
     115                        readMember(relation);
     116                    }
    117117
    118                                         if (xmlelement.equals("bounds")) {
    119                                                 osmgraph.setBbbottom(Double.parseDouble(parser
    120                                                                 .getAttributeValue(null, "minlat")));
    121                                                 osmgraph.setBbtop(Double.parseDouble(parser
    122                                                                 .getAttributeValue(null, "maxlat")));
    123                                                 osmgraph.setBbleft(Double.parseDouble(parser
    124                                                                 .getAttributeValue(null, "minlon")));
    125                                                 osmgraph.setBbright(Double.parseDouble(parser
    126                                                                 .getAttributeValue(null, "maxlon")));
    127                                         }
     118                    if (xmlelement.equals("bounds")) {
     119                        osmgraph.setBbbottom(Double.parseDouble(parser
     120                                .getAttributeValue(null, "minlat")));
     121                        osmgraph.setBbtop(Double.parseDouble(parser
     122                                .getAttributeValue(null, "maxlat")));
     123                        osmgraph.setBbleft(Double.parseDouble(parser
     124                                .getAttributeValue(null, "minlon")));
     125                        osmgraph.setBbright(Double.parseDouble(parser
     126                                .getAttributeValue(null, "maxlon")));
     127                    }
    128128
    129                                         if (xmlelement.equals("nd")) {
    130                                                 way.addNode(osmgraph.getNode(Integer.parseInt(parser
    131                                                                 .getAttributeValue(0))));
    132                                         }
     129                    if (xmlelement.equals("nd")) {
     130                        way.addNode(osmgraph.getNode(Integer.parseInt(parser
     131                                .getAttributeValue(0))));
     132                    }
    133133
    134                                         if (xmlelement.equals("tag")) {
    135                                                 hashmap.put(parser.getAttributeValue(null, "k"), parser
    136                                                                 .getAttributeValue(null, "v"));
    137                                         }
     134                    if (xmlelement.equals("tag")) {
     135                        hashmap.put(parser.getAttributeValue(null, "k"), parser
     136                                .getAttributeValue(null, "v"));
     137                    }
    138138
    139                                         if (xmlelement.equals("relation")) {
    140                                                 relation = new OSMRelation();
    141                                                 hashmap = new HashMap<String, String>();
    142                                                 readAttributes(relation);
    143                                         }
     139                    if (xmlelement.equals("relation")) {
     140                        relation = new OSMRelation();
     141                        hashmap = new HashMap<String, String>();
     142                        readAttributes(relation);
     143                    }
    144144
    145                                         //TODO: kann wohl wech!
    146                                         /*
    147                                         if (xmlelement.equals("member")) {
    148                                                 relation.addMember(parser.getAttributeValue(null,
    149                                                                 "type"), Integer.parseInt(parser
    150                                                                 .getAttributeValue(null, "ref")), parser
    151                                                                 .getAttributeValue(null, "role"));
    152                                         }
    153                                         */
    154                                         break;
     145                    //TODO: kann wohl wech!
     146                    /*
     147                    if (xmlelement.equals("member")) {
     148                        relation.addMember(parser.getAttributeValue(null,
     149                                "type"), Integer.parseInt(parser
     150                                .getAttributeValue(null, "ref")), parser
     151                                .getAttributeValue(null, "role"));
     152                    }
     153                    */
     154                    break;
    155155
    156                                 case XMLStreamConstants.END_ELEMENT:
    157                                         if (parser.getLocalName() == "node") {
    158                                                 node.setHashmap(hashmap);
    159                                                 osmgraph.addNode(node);
    160                                         }
     156                case XMLStreamConstants.END_ELEMENT:
     157                    if (parser.getLocalName() == "node") {
     158                        node.setHashmap(hashmap);
     159                        osmgraph.addNode(node);
     160                    }
    161161
    162                                         if (parser.getLocalName() == "way") {
    163                                                 way.setHashmap(hashmap);
    164                                                 osmgraph.addWay(way);
    165                                         }
     162                    if (parser.getLocalName() == "way") {
     163                        way.setHashmap(hashmap);
     164                        osmgraph.addWay(way);
     165                    }
    166166
    167                                         if (parser.getLocalName().equals("relation")) {
    168                                                 relation.setHashmap(hashmap);
    169                                                 osmgraph.addRelation(relation);
    170                                         }
    171                                         break;
    172                                 }
    173                                 parser.next();
    174                         }
    175                 } catch (XMLStreamException e) {
    176                         e.printStackTrace();
    177                 }
    178         }
     167                    if (parser.getLocalName().equals("relation")) {
     168                        relation.setHashmap(hashmap);
     169                        osmgraph.addRelation(relation);
     170                    }
     171                    break;
     172                }
     173                parser.next();
     174            }
     175        } catch (XMLStreamException e) {
     176            e.printStackTrace();
     177        }
     178    }
    179179
    180         public void setOSMGraph(OSMGraph osmgraph) {
    181                 this.osmgraph = osmgraph;
    182         }
     180    public void setOSMGraph(OSMGraph osmgraph) {
     181        this.osmgraph = osmgraph;
     182    }
    183183
    184         public OSMGraph getOSMGraph() {
    185                 return osmgraph;
    186         }
     184    public OSMGraph getOSMGraph() {
     185        return osmgraph;
     186    }
    187187}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/reader/XMLFilterReader.java

    r25501 r30725  
    1111public class XMLFilterReader extends XMLReader{
    1212
    13         Vector<Filter> filters;
    14         Filter filter;
     13    Vector<Filter> filters;
     14    Filter filter;
    1515
    16         public XMLFilterReader(String filename) {
    17                 super(filename);
    18                 filters = new Vector<Filter>();
    19         }
     16    public XMLFilterReader(String filename) {
     17        super(filename);
     18        filters = new Vector<Filter>();
     19    }
    2020
    21         @Override
    22         public void parseXML() {
    23                 String tempValue ="";
    24                 String tempKeyValue ="";
    25                 try {
    26                         while (parser.hasNext()) {
     21    @Override
     22    public void parseXML() {
     23        String tempValue ="";
     24        String tempKeyValue ="";
     25        try {
     26            while (parser.hasNext()) {
    2727
    28                                 switch (parser.getEventType()) {
    29                                 case XMLStreamConstants.START_ELEMENT:
    30                                         tempValue = parser.getAttributeValue(null, "entity");
    31                                         if (tempValue.equals("k")) {
    32                                                 filter = new Filter();
    33                                                 filter.setKeyValue(parser.getLocalName());
    34                                                 tempKeyValue = parser.getLocalName();
    35                                         }
    36                                         if (tempValue.equalsIgnoreCase("v")) {
    37                                                 filter.setTagValue(parser.getLocalName());
    38                                         }
    39                                         break;
     28                switch (parser.getEventType()) {
     29                case XMLStreamConstants.START_ELEMENT:
     30                    tempValue = parser.getAttributeValue(null, "entity");
     31                    if (tempValue.equals("k")) {
     32                        filter = new Filter();
     33                        filter.setKeyValue(parser.getLocalName());
     34                        tempKeyValue = parser.getLocalName();
     35                    }
     36                    if (tempValue.equalsIgnoreCase("v")) {
     37                        filter.setTagValue(parser.getLocalName());
     38                    }
     39                    break;
    4040
    41                                 case XMLStreamConstants.END_ELEMENT:
    42                                         if (tempKeyValue.equalsIgnoreCase(parser.getLocalName())) {
    43                                                 filters.add(filter);
    44                                         }
    45                                         break;
     41                case XMLStreamConstants.END_ELEMENT:
     42                    if (tempKeyValue.equalsIgnoreCase(parser.getLocalName())) {
     43                        filters.add(filter);
     44                    }
     45                    break;
    4646
    47                                 }
    48                                 parser.next();
    49                         }
    50                 } catch (XMLStreamException e) {
    51                         e.printStackTrace();
    52                 }
    53         }
     47                }
     48                parser.next();
     49            }
     50        } catch (XMLStreamException e) {
     51            e.printStackTrace();
     52        }
     53    }
    5454
    55         public Filter[] getFilters() {
    56                 Filter[] filterarray= new Filter[filters.size()];
    57                 return filters.toArray(filterarray);
    58         }
     55    public Filter[] getFilters() {
     56        Filter[] filterarray= new Filter[filters.size()];
     57        return filters.toArray(filterarray);
     58    }
    5959}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/reader/XMLReader.java

    r25501 r30725  
    99
    1010public  abstract class XMLReader {
    11        
    12         protected String filename;
    13         protected XMLInputFactory factory = XMLInputFactory.newInstance();
    14         protected XMLStreamReader parser;
    15        
    16         public XMLReader(String filename) {
    17                 try {
    18                         parser = factory
    19                                 .createXMLStreamReader(this.getClass().getResourceAsStream(filename));
    20                 } catch (XMLStreamException e) {
    21                         e.printStackTrace();
    22                 }
    23         }
    24        
    25         public XMLReader(File file) {
    26                 try {
    27                         parser = factory
    28                                         .createXMLStreamReader(new FileInputStream(file));
    29                 } catch (FileNotFoundException e) {
    30                         e.printStackTrace();
    31                 } catch (XMLStreamException e) {
    32                         e.printStackTrace();
    33                 }
    34         }
    35        
    36         public abstract void parseXML();
     11   
     12    protected String filename;
     13    protected XMLInputFactory factory = XMLInputFactory.newInstance();
     14    protected XMLStreamReader parser;
     15   
     16    public XMLReader(String filename) {
     17        try {
     18            parser = factory
     19                .createXMLStreamReader(this.getClass().getResourceAsStream(filename));
     20        } catch (XMLStreamException e) {
     21            e.printStackTrace();
     22        }
     23    }
     24   
     25    public XMLReader(File file) {
     26        try {
     27            parser = factory
     28                    .createXMLStreamReader(new FileInputStream(file));
     29        } catch (FileNotFoundException e) {
     30            e.printStackTrace();
     31        } catch (XMLStreamException e) {
     32            e.printStackTrace();
     33        }
     34    }
     35   
     36    public abstract void parseXML();
    3737}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/util/RelationProducer.java

    r25501 r30725  
    1919public class RelationProducer {
    2020
    21         private JunctionCheckerPlugin plugin;
    22         private HashSet<HashSet<Channel>> storedRelations;
     21    private JunctionCheckerPlugin plugin;
     22    private HashSet<HashSet<Channel>> storedRelations;
    2323
    24         public RelationProducer(JunctionCheckerPlugin plugin) {
    25                 this.plugin = plugin;
    26                 storedRelations = new HashSet<HashSet<Channel>>();
    27         }
     24    public RelationProducer(JunctionCheckerPlugin plugin) {
     25        this.plugin = plugin;
     26        storedRelations = new HashSet<HashSet<Channel>>();
     27    }
    2828
    29         public void produceRelation(HashSet<Channel> subset, int n) {
    30                 if (isProduced(subset)) {
    31                         return;
    32                 }
    33                 LinkedList<OsmPrimitive> ways = new LinkedList<OsmPrimitive>();
    34                 Iterator<Channel> cit = subset.iterator();
    35                 while (cit.hasNext()) {
    36                         Channel c = cit.next();
    37                         // System.out.println(c.getWay().getId());
    38                         if (!(ways.contains(plugin.getOsmlayer().data.getPrimitiveById(c
    39                                         .getWay().getId(), OsmPrimitiveType.WAY)))) {
    40                                 ways.add(plugin.getOsmlayer().data.getPrimitiveById(c.getWay()
    41                                                 .getId(), OsmPrimitiveType.WAY));
    42                         }
    43                 }
    44                 Main.map.mapView.setActiveLayer(plugin.getOsmlayer());
    45                 plugin.getOsmlayer().data.setSelected(ways);
     29    public void produceRelation(HashSet<Channel> subset, int n) {
     30        if (isProduced(subset)) {
     31            return;
     32        }
     33        LinkedList<OsmPrimitive> ways = new LinkedList<OsmPrimitive>();
     34        Iterator<Channel> cit = subset.iterator();
     35        while (cit.hasNext()) {
     36            Channel c = cit.next();
     37            // System.out.println(c.getWay().getId());
     38            if (!(ways.contains(plugin.getOsmlayer().data.getPrimitiveById(c
     39                    .getWay().getId(), OsmPrimitiveType.WAY)))) {
     40                ways.add(plugin.getOsmlayer().data.getPrimitiveById(c.getWay()
     41                        .getId(), OsmPrimitiveType.WAY));
     42            }
     43        }
     44        Main.map.mapView.setActiveLayer(plugin.getOsmlayer());
     45        plugin.getOsmlayer().data.setSelected(ways);
    4646
    47                 Relation jrelation = new Relation();
    48                 jrelation.put("type", "junction");
    49                 jrelation.put("n", Integer.toString(n));
    50                 for (int i = 0; i < ways.size(); i++) {
    51                         jrelation.addMember(new RelationMember("part of", ways.get(i)));
    52                 }
     47        Relation jrelation = new Relation();
     48        jrelation.put("type", "junction");
     49        jrelation.put("n", Integer.toString(n));
     50        for (int i = 0; i < ways.size(); i++) {
     51            jrelation.addMember(new RelationMember("part of", ways.get(i)));
     52        }
    5353
    54                 plugin.getOsmlayer().data.addPrimitive(jrelation);
    55         }
     54        plugin.getOsmlayer().data.addPrimitive(jrelation);
     55    }
    5656
    57         private boolean isProduced(HashSet<Channel> subset) {
    58                 if (storedRelations.contains(subset)) {
    59                         return true;
    60                 } else {
    61                         storedRelations.add(subset);
    62                 }
    63                 return false;
    64         }
     57    private boolean isProduced(HashSet<Channel> subset) {
     58        if (storedRelations.contains(subset)) {
     59            return true;
     60        } else {
     61            storedRelations.add(subset);
     62        }
     63        return false;
     64    }
    6565}
  • applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/writing/OSMXMLWriter.java

    r25501 r30725  
    2222public class OSMXMLWriter {
    2323
    24         String filename;
    25         ChannelDiGraph digraph;
    26         XMLStreamWriter writer;
     24    String filename;
     25    ChannelDiGraph digraph;
     26    XMLStreamWriter writer;
    2727
    28         public OSMXMLWriter(String filename, ChannelDiGraph digraph) {
    29                 this.filename = filename;
    30                 this.digraph = digraph;
    31         }
     28    public OSMXMLWriter(String filename, ChannelDiGraph digraph) {
     29        this.filename = filename;
     30        this.digraph = digraph;
     31    }
    3232
    33         public void writeXML() throws FileNotFoundException, XMLStreamException {
    34                 XMLOutputFactory factory = XMLOutputFactory.newInstance();
    35                 writer = factory.createXMLStreamWriter(
    36                                                    new FileOutputStream(  filename ) );
    37                 // Der XML-Header wird erzeugt
    38                 writer.writeStartDocument("utf-8", "1.0");
    39                 // Zuerst wird das Wurzelelement mit Attribut geschrieben
    40                   writer.writeStartElement( "osm" );
    41                     writer.writeAttribute( "version", "0.6" );
    42                     writer.writeAttribute("generator", "channelGenerator");
     33    public void writeXML() throws FileNotFoundException, XMLStreamException {
     34        XMLOutputFactory factory = XMLOutputFactory.newInstance();
     35        writer = factory.createXMLStreamWriter(
     36                                           new FileOutputStream(  filename ) );
     37        // Der XML-Header wird erzeugt
     38        writer.writeStartDocument("utf-8", "1.0");
     39        // Zuerst wird das Wurzelelement mit Attribut geschrieben
     40          writer.writeStartElement( "osm" );
     41            writer.writeAttribute( "version", "0.6" );
     42            writer.writeAttribute("generator", "channelGenerator");
    4343
    44                     writer.writeEmptyElement("bounds");
    45                     writer.writeAttribute("minlat", Double.toString(digraph.getBbbottom()));
    46                     writer.writeAttribute("minlon", Double.toString(digraph.getBbleft()));
    47                     writer.writeAttribute("maxlat", Double.toString(digraph.getBbtop()));
    48                     writer.writeAttribute("maxlon", Double.toString(digraph.getBbright()));
     44            writer.writeEmptyElement("bounds");
     45            writer.writeAttribute("minlat", Double.toString(digraph.getBbbottom()));
     46            writer.writeAttribute("minlon", Double.toString(digraph.getBbleft()));
     47            writer.writeAttribute("maxlat", Double.toString(digraph.getBbtop()));
     48            writer.writeAttribute("maxlon", Double.toString(digraph.getBbright()));
    4949
    5050
    51                     OSMNode[] nodes = digraph.getAllOSMNodes();
    52                     for (int i = 0; i < nodes.length; i++) {
    53                         //writer.writeStartElement("node");
    54                         writer.writeEmptyElement("node");
    55                         writeAttributes(nodes[i]);
    56                         }
     51            OSMNode[] nodes = digraph.getAllOSMNodes();
     52            for (int i = 0; i < nodes.length; i++) {
     53                //writer.writeStartElement("node");
     54                writer.writeEmptyElement("node");
     55                writeAttributes(nodes[i]);
     56            }
    5757
    58                     ArrayList<Channel> ways = digraph.getChannels();
    59                     for (int i = 0; i < ways.size(); i++) {
    60                                 writer.writeStartElement("way");
    61                                 writer.writeAttribute("id", Integer.toString(ways.get(i).getNewid()));
    62                                 writeAttributes(ways.get(i).getWay());
    63                                   writer.writeEmptyElement("nd");
    64                                   writer.writeAttribute("ref", Long.toString(ways.get(i).getFromNode().getId()));
    65                                   //writer.writeEndElement();
    66                                   writer.writeEmptyElement("nd");
    67                                   writer.writeAttribute("ref", Long.toString(ways.get(i).getToNode().getId()));
    68                                   //writer.writeEndElement();
     58            ArrayList<Channel> ways = digraph.getChannels();
     59            for (int i = 0; i < ways.size(); i++) {
     60                writer.writeStartElement("way");
     61                writer.writeAttribute("id", Integer.toString(ways.get(i).getNewid()));
     62                writeAttributes(ways.get(i).getWay());
     63                  writer.writeEmptyElement("nd");
     64                  writer.writeAttribute("ref", Long.toString(ways.get(i).getFromNode().getId()));
     65                  //writer.writeEndElement();
     66                  writer.writeEmptyElement("nd");
     67                  writer.writeAttribute("ref", Long.toString(ways.get(i).getToNode().getId()));
     68                  //writer.writeEndElement();
    6969
    70                                   HashMap<String, String> tags = ways.get(i).getWay().getHashmap();
    71                                   Set<String> keys = tags.keySet();
    72                                   String t;
    73                                   Iterator<String> iterator = keys.iterator();
    74                                   while (iterator.hasNext()) {
    75                                                 t = iterator.next();
    76                                                 writer.writeEmptyElement("tag");
    77                                                 writer.writeAttribute("k", t);
    78                                                 writer.writeAttribute("v", tags.get(t));
    79                                           }
    80                                   writer.writeEmptyElement("tag");
    81                                   writer.writeAttribute("k", "ID");
    82                                   writer.writeAttribute("v", Integer.toString(ways.get(i).getNewid()));
    83                                   writer.writeEmptyElement("tag");
     70                  HashMap<String, String> tags = ways.get(i).getWay().getHashmap();
     71                  Set<String> keys = tags.keySet();
     72                  String t;
     73                  Iterator<String> iterator = keys.iterator();
     74                  while (iterator.hasNext()) {
     75                        t = iterator.next();
     76                        writer.writeEmptyElement("tag");
     77                        writer.writeAttribute("k", t);
     78                        writer.writeAttribute("v", tags.get(t));
     79                      }
     80                  writer.writeEmptyElement("tag");
     81                  writer.writeAttribute("k", "ID");
     82                  writer.writeAttribute("v", Integer.toString(ways.get(i).getNewid()));
     83                  writer.writeEmptyElement("tag");
    8484                  writer.writeAttribute("k", "SCC");
    8585                  if (ways.get(i).isStrongConnected()) {
     
    9090                  }
    9191                  writer.writeEndElement();
    92                         }
     92            }
    9393
    94                   writer.writeEndElement();
    95                 writer.writeEndDocument();
    96                 writer.close();
    97         }
     94          writer.writeEndElement();
     95        writer.writeEndDocument();
     96        writer.close();
     97    }
    9898
    99         private void writeAttributes(OSMEntity ent) throws FileNotFoundException, XMLStreamException{
    100                 if (ent instanceof OSMNode) {
    101                         writer.writeAttribute("id", Long.toString(ent.getId()) );
    102                         writer.writeAttribute("lat", Double.toString(((OSMNode) ent).getLatitude()));
    103                         writer.writeAttribute("lon", Double.toString(((OSMNode) ent).getLongitude()));
    104                 }
     99    private void writeAttributes(OSMEntity ent) throws FileNotFoundException, XMLStreamException{
     100        if (ent instanceof OSMNode) {
     101            writer.writeAttribute("id", Long.toString(ent.getId()) );
     102            writer.writeAttribute("lat", Double.toString(((OSMNode) ent).getLatitude()));
     103            writer.writeAttribute("lon", Double.toString(((OSMNode) ent).getLongitude()));
     104        }
    105105
    106         if (ent.getTimestamp()!=null) {
    107                 writer.writeAttribute("timestamp", ent.getTimestamp());
    108         }
    109         if (ent.isVisible())
    110                 writer.writeAttribute("visible", "true");
    111         else writer.writeAttribute("visible", "false");
    112                 writer.writeAttribute("version", Integer.toString(ent.getVersion()));
    113         }
     106        if (ent.getTimestamp()!=null) {
     107            writer.writeAttribute("timestamp", ent.getTimestamp());
     108        }
     109        if (ent.isVisible())
     110            writer.writeAttribute("visible", "true");
     111        else writer.writeAttribute("visible", "false");
     112        writer.writeAttribute("version", Integer.toString(ent.getVersion()));
     113    }
    114114}
Note: See TracChangeset for help on using the changeset viewer.