예제 #1
0
 public Node split(EmbeddedGraph embeddedGraph, Edge edge) {
   Graph originalGraph = embeddedGraph.getGraph();
   Node newNode = originalGraph.createDummyNode();
   originalGraph.removeEdge(edge);
   List<Edge> newEdges = ListSequence.fromList(new ArrayList<Edge>());
   ListSequence.fromList(newEdges).addElement(originalGraph.connect(edge.getSource(), newNode));
   ListSequence.fromList(newEdges).addElement(originalGraph.connect(newNode, edge.getTarget()));
   MapSequence.fromMap(mySplittedEdges).put(edge, newEdges);
   List<Face> facesToProcess = ListSequence.fromList(new ArrayList<Face>());
   ListSequence.fromList(facesToProcess)
       .addSequence(ListSequence.fromList(embeddedGraph.getAdjacentFaces(edge)));
   for (Face face : ListSequence.fromList(facesToProcess)) {
     List<Dart> darts = face.getDarts();
     int pos = 0;
     while (ListSequence.fromList(darts).getElement(pos).getEdge() != edge) {
       pos++;
     }
     Dart dartToReplace = ListSequence.fromList(darts).getElement(pos);
     for (Edge newEdge : ListSequence.fromList(newEdges)) {
       if (ListSequence.fromList(newEdge.getAdjacentNodes()).contains(dartToReplace.getSource())) {
         embeddedGraph.setDart(face, pos, new Dart(newEdge, dartToReplace.getSource()));
       }
     }
     for (Edge newEdge : ListSequence.fromList(newEdges)) {
       if (ListSequence.fromList(newEdge.getAdjacentNodes()).contains(dartToReplace.getTarget())) {
         embeddedGraph.insertDart(face, pos + 1, new Dart(newEdge, newNode));
       }
     }
   }
   return newNode;
 }
예제 #2
0
 private void restoreEdge(EmbeddedGraph embeddedGraph, Edge removedEdge) {
   MapSequence.fromMap(mySplittedEdges)
       .put(removedEdge, ListSequence.fromList(new ArrayList<Edge>()));
   Graph graph = embeddedGraph.getGraph();
   DualGraph dualGraph = new DualGraph(embeddedGraph);
   List<Node> newNodes = ListSequence.fromList(new ArrayList<Node>());
   for (Node node : ListSequence.fromList(removedEdge.getAdjacentNodes())) {
     Node newNode = dualGraph.createDummyNode();
     for (Edge nodeEdge : ListSequence.fromList(node.getEdges(Edge.Direction.BOTH))) {
       for (Face face : ListSequence.fromList(embeddedGraph.getAdjacentFaces(nodeEdge))) {
         dualGraph.connect(newNode, MapSequence.fromMap(dualGraph.getNodesMap()).get(face));
       }
     }
     ListSequence.fromList(newNodes).addElement(newNode);
   }
   List<Edge> path =
       ShortestPath.getPath(
           dualGraph,
           ListSequence.fromList(newNodes).getElement(0),
           ListSequence.fromList(newNodes).getElement(1),
           Edge.Direction.BOTH);
   List<Node> nodePath = ListSequence.fromList(new ArrayList<Node>());
   List<Face> facePath = ListSequence.fromList(new ArrayList<Face>());
   ListSequence.fromList(nodePath)
       .addElement(ListSequence.fromList(removedEdge.getAdjacentNodes()).getElement(0));
   Node cur = ListSequence.fromList(newNodes).getElement(0);
   for (Edge edge : ListSequence.fromList(path)) {
     Edge realEdge = MapSequence.fromMap(dualGraph.getEdgesMap()).get(edge);
     if (embeddedGraph.getAdjacentFaces(realEdge) != null) {
       ListSequence.fromList(nodePath)
           .addElement(
               split(embeddedGraph, MapSequence.fromMap(dualGraph.getEdgesMap()).get(edge)));
     }
     cur = edge.getOpposite(cur);
     Face curFace = MapSequence.fromMap(dualGraph.getFacesMap()).get(cur);
     if (curFace != null) {
       ListSequence.fromList(facePath).addElement(curFace);
     }
   }
   ListSequence.fromList(nodePath)
       .addElement(ListSequence.fromList(removedEdge.getAdjacentNodes()).getElement(1));
   for (int i = 0; i < ListSequence.fromList(nodePath).count() - 1; i++) {
     Edge newEdge =
         graph.connect(
             ListSequence.fromList(nodePath).getElement(i),
             ListSequence.fromList(nodePath).getElement(i + 1));
     ListSequence.fromList(MapSequence.fromMap(mySplittedEdges).get(removedEdge))
         .addElement(newEdge);
     splitFace(embeddedGraph, ListSequence.fromList(facePath).getElement(i), newEdge);
   }
 }
예제 #3
0
 public void splitFace(EmbeddedGraph embeddedGraph, Face face, Edge newEdge) {
   List<Node> nodes = newEdge.getAdjacentNodes();
   Graph originalGraph = embeddedGraph.getGraph();
   List<Face> newFaces = ListSequence.fromList(new ArrayList<Face>());
   ListSequence.fromList(newFaces).addElement(new Face(originalGraph));
   ListSequence.fromList(newFaces).addElement(new Face(originalGraph));
   Iterator<Dart> dartItr = ListSequence.fromList(face.getDarts()).iterator();
   Dart cur;
   do {
     cur = dartItr.next();
   } while (!(ListSequence.fromList(nodes).contains(cur.getSource())));
   Dart first = cur;
   Node found = cur.getSource();
   Node toFind = ListSequence.fromList(nodes).getElement(0);
   if (toFind == found) {
     toFind = ListSequence.fromList(nodes).getElement(1);
   }
   do {
     ListSequence.fromList(newFaces).getElement(0).addLast(cur);
     cur = dartItr.next();
   } while (cur.getSource() != toFind);
   ListSequence.fromList(newFaces).getElement(0).addLast(new Dart(newEdge, cur.getSource()));
   ListSequence.fromList(newFaces).getElement(1).addLast(new Dart(newEdge, first.getSource()));
   ListSequence.fromList(newFaces).getElement(1).addLast(cur);
   while (dartItr.hasNext()) {
     cur = dartItr.next();
     ListSequence.fromList(newFaces).getElement(1).addLast(cur);
   }
   dartItr = ListSequence.fromList(face.getDarts()).iterator();
   cur = dartItr.next();
   while (cur != first) {
     ListSequence.fromList(newFaces).getElement(1).addLast(cur);
     cur = dartItr.next();
   }
   embeddedGraph.removeFace(face);
   for (Face newFace : ListSequence.fromList(newFaces)) {
     embeddedGraph.addFace(newFace);
   }
   if (embeddedGraph.isOuterFace(face)) {
     embeddedGraph.setOuterFace(ListSequence.fromList(newFaces).getElement(1));
   }
 }