Ticket #363: lemonsikgraf2_2c0edf00dc8f.patch
File lemonsikgraf2_2c0edf00dc8f.patch, 46.1 KB (added by , 9 years ago) 


lemon/graph_to_eps.h
# HG changeset patch # User Peter Gyorok # Date 1285418159 7200 # Node ID 2c0edf00dc8ff8bdf85187c590b17d2a355b2d03 # Parent 10d57978f9003ad2839583e71265b72b30b884b1 PlanarGraph and PlaneGraph related fixes (#363) diff r 10d57978f900 r 2c0edf00dc8f lemon/graph_to_eps.h
a b 662 662 public: 663 663 ~GraphToEps() { } 664 664 665 private: 665 666 template<typename GR, typename D> 666 667 void edgeToEps(const GR &g, std::ostream &os, const typename GR::Arc e, 667 668 const Color &col, double width, D t) { … … 674 675 } 675 676 676 677 template<typename D> 677 void inner_run(D t) {678 void start(D t) { 678 679 const double EPSILON=1e9; 679 680 if(dontPrint) return; 680 681 … … 1076 1077 if(_pleaseRemoveOsStream) {delete &os;} 1077 1078 } 1078 1079 1080 public: 1079 1081 ///Draws the graph. 1080 1082 1081 1083 ///Like other functions using … … 1083 1085 ///this function calls the algorithm itself, i.e. in this case 1084 1086 ///it draws the graph. 1085 1087 void run(int i = 0) { 1086 this> inner_run(i); //for normal graphs1088 this>start(i); //for normal graphs 1087 1089 } 1088 1090 1089 1091 void run(bool b) { 1090 this> inner_run(b); //for plane graphs with custom edge shape support1092 this>start(b); //for plane graphs with custom edge shape support 1091 1093 } 1092 1094 1093 1095 ///\name Aliases 
lemon/planar_graph.h
diff r 10d57978f900 r 2c0edf00dc8f lemon/planar_graph.h
a b 21 21 22 22 ///\ingroup graphs 23 23 ///\file 24 ///\brief PlanarGraph classes. UNDER CONSTRUCTION.24 ///\brief PlanarGraph classes. 25 25 26 26 #include <lemon/core.h> 27 27 #include <lemon/error.h> … … 359 359 360 360 void firstCcwF(Arc &e, const Face &f) const { 361 361 e.id = faces[f.id].first_arc; 362 setToOpposite(e); 362 363 turnRight(e); 363 setToOpposite(e);364 364 } 365 365 void nextCcwF(Arc &e) const { 366 366 if (e.id == faces[arcs[e.id].left_face].first_arc) e = INVALID; 367 367 else { 368 setToOpposite(e); 368 369 turnRight(e); 369 setToOpposite(e);370 370 } 371 371 } 372 372 void firstCwF(Arc &e, const Face &f) const { … … 379 379 } 380 380 381 381 void firstInF(Arc &e, const Face &f) const { 382 e.id = faces[f.id].first_arc; 382 e.id = faces[f.id].first_arc ^ 1; 383 turnRight(e); 384 setToOpposite(e); 383 385 } 384 386 void nextInF(Arc &e) const { 385 setToOpposite(e); 386 turnRight(e); 387 if (e.id == faces[arcs[e.id].left_face].first_arc) e = INVALID; 388 } 389 void lastInF(Arc &e, const Face &f) const { 390 e.id = faces[f.id].first_arc; 391 setToOpposite(e); 392 turnRight(e); 393 } 394 void prevInF(Arc &e) const { 395 if (e.id == faces[arcs[e.id].left_face].first_arc) { 387 if (e.id == (faces[arcs[e.id ^ 1].left_face].first_arc ^ 1)) { 396 388 e = INVALID; 397 389 return; 398 390 } 391 turnRight(e); 399 392 setToOpposite(e); 400 turnRight(e); 393 } 394 void lastInF(Arc &e, const Face &f) const { 395 e.id = faces[f.id].first_arc ^ 1; 396 } 397 void prevInF(Arc &e) const { 398 setToOpposite(e); 399 turnLeft(e); 400 if (e.id == (faces[arcs[e.id ^ 1].left_face].first_arc ^ 1)) e = INVALID; 401 401 } 402 402 403 403 void firstOutF(Arc &e, const Face &f) const { … … 522 522 } 523 523 524 524 Node addNode() { 525 int n = link _node();525 int n = linkNode(); 526 526 527 527 nodes[n].component = addComponent(); 528 528 components[nodes[n].component].num_nodes = 1; … … 540 540 left_face && nodes[u.id].component == nodes[v.id].component) return 541 541 INVALID; 542 542 543 int n = link _edge();543 int n = linkEdge(); 544 544 545 545 arcs[n].target = u.id; 546 546 arcs[n  1].target = v.id; … … 585 585 faces[f.id].first_arc = n  1; 586 586 faces[oldf].first_arc = n; 587 587 Arc arc(n  1); 588 wall _paint(arc,f.id,arc);588 wallPaint(arc,f.id,arc); 589 589 if (nodes[v.id].component != nodes[u.id].component) { 590 590 erase(Face(oldf)); 591 591 erase(Face(oldfb)); 592 592 if (components[ca].num_nodes > components[cb].num_nodes) { 593 component _relabel(v,ca);593 componentRelabel(v,ca); 594 594 eraseComponent(cb); 595 595 } else { 596 component _relabel(u,cb);596 componentRelabel(u,cb); 597 597 eraseComponent(ca); 598 598 } 599 599 } … … 638 638 eraseComponent(nodes[n].component); 639 639 erase(Face(nodes[n].outer_face)); 640 640 641 unlink _node(n);641 unlinkNode(n); 642 642 } 643 643 644 644 void erase(const Edge& edge) { … … 658 658 bool comp_split = false; 659 659 if (fr != fl) { 660 660 Arc arc(faces[fr].first_arc); 661 wall _paint(arc,fl,arc);661 wallPaint(arc,fl,arc); 662 662 if ((faces[fl].first_arc  1) == (n  1)) 663 663 faces[fl].first_arc = faces[fr].first_arc; 664 664 erase(Face(fr)); … … 671 671 ed.id ^= 1; 672 672 turnRightF(arc); 673 673 Face f = addFace(); 674 wall _paint(arc,f.id,ed);674 wallPaint(arc,f.id,ed); 675 675 faces[f.id].first_arc = arc.id; 676 676 turnRightF(ed); 677 677 faces[fr].first_arc = ed.id; … … 681 681 if (arcs[n].next_out != 1) { 682 682 arcs[arcs[n].next_out].prev_out = arcs[n].prev_out; 683 683 } else { 684 nodes[arcs[n ].target].last_out = arcs[n].prev_out;684 nodes[arcs[n  1].target].last_out = arcs[n].prev_out; 685 685 } 686 686 687 687 if (arcs[n].prev_out != 1) { … … 693 693 if (arcs[n  1].next_out != 1) { 694 694 arcs[arcs[n  1].next_out].prev_out = arcs[n  1].prev_out; 695 695 } else { 696 nodes[arcs[n  1].target].last_out = arcs[n  1].prev_out;696 nodes[arcs[n].target].last_out = arcs[n  1].prev_out; 697 697 } 698 698 699 699 if (arcs[n  1].prev_out != 1) { … … 702 702 nodes[arcs[n].target].first_out = arcs[n  1].next_out; 703 703 } 704 704 705 unlink _edge(edge);705 unlinkEdge(edge); 706 706 707 if (comp_split) component _relabel(Node(arcs[n  1].target),707 if (comp_split) componentRelabel(Node(arcs[n  1].target), 708 708 addComponent()); 709 709 if (nodes[arcs[n].target].first_out == 1 && nodes[arcs[n  1].target]. 710 710 first_out == 1) { … … 736 736 Node split(Edge e) { 737 737 Node v; 738 738 Edge e2; 739 inner _split1(v,e2);740 return inner _split2(e,v,e2);739 innerSplit1(v,e2); 740 return innerSplit2(e,v,e2); 741 741 } 742 742 743 743 Node split(Node n1, Edge e1, Edge e2, bool b) { 744 744 Node n2; 745 inner _split1(n1,n2);745 innerSplit1(n1,n2); 746 746 Edge a3; 747 inner _split2(n1,n2,e1,e2,b,a3);747 innerSplit2(n1,n2,e1,e2,b,a3); 748 748 if (!b && a3 != INVALID) erase(a3); 749 749 return n2; 750 750 } … … 754 754 Node n2 = v(e); 755 755 Node nd; 756 756 bool simple; 757 inner _contract1(n1,n2,nd,simple);758 inner _contract2(e,n1,n2,nd,simple);757 innerContract1(n1,n2,nd,simple); 758 innerContract2(e,n1,n2,nd,simple); 759 759 } 760 760 761 761 protected: … … 763 763 //Adds a node to the linked list and sets default properties. Used by 764 764 //addNode and other functions that take care of the planar properties by 765 765 //themselves. 766 int link _node() {766 int linkNode() { 767 767 int n; 768 768 if (first_free_node==1) { 769 769 n = nodes.size(); … … 784 784 //Removes a node from the linked list. Used by 785 785 //erase(Node) and other functions that take care of the planar properties by 786 786 //themselves. 787 void unlink _node(int n) {787 void unlinkNode(int n) { 788 788 if (nodes[n].next != 1) { 789 789 nodes[nodes[n].next].prev = nodes[n].prev; 790 790 } … … 803 803 //Adds an edge to the linked list. Used by 804 804 //addEdge and other functions that take care of the planar properties by 805 805 //themselves. 806 int link _edge() {806 int linkEdge() { 807 807 int n; 808 808 if (first_free_arc == 1) { 809 809 n = arcs.size(); … … 819 819 //Removes an edge from the linked list. Used by 820 820 //erase(Edge) and other functions that take care of the planar properties by 821 821 //themselves. 822 void unlink _edge(Edge e) {822 void unlinkEdge(Edge e) { 823 823 int n = e.id*2; 824 824 arcs[n].next_out = first_free_arc; 825 825 first_free_arc = n; … … 828 828 } 829 829 830 830 //Primitives of split(Edge) 831 void inner _split1(Node &v, Edge &e2) {832 v = Node(link _node());833 e2 = Arc(link _edge());831 void innerSplit1(Node &v, Edge &e2) { 832 v = Node(linkNode()); 833 e2 = Arc(linkEdge()); 834 834 } 835 835 836 Node inner _split2(Edge e, Node v, Edge e2) {836 Node innerSplit2(Edge e, Node v, Edge e2) { 837 837 Arc a(e.id*2); 838 838 int b = e2.id*2; 839 839 nodes[v.id].component = nodes[arcs[a.id].target].component; … … 864 864 } 865 865 866 866 //Primitives of contract(Edge) 867 void inner _contract1(Node n1, Node n2, Node &to_delete, bool &simple) {867 void innerContract1(Node n1, Node n2, Node &to_delete, bool &simple) { 868 868 if (nodes[n1.id].first_out == nodes[n1.id].last_out) { 869 869 simple = true; 870 870 to_delete = n1; … … 877 877 } 878 878 } 879 879 880 void inner _contract2(Edge e, Node n1, Node n2, Node &to_delete, bool880 void innerContract2(Edge e, Node n1, Node n2, Node &to_delete, bool 881 881 &simple) { 882 882 if (simple) { 883 883 erase(e); … … 921 921 } 922 922 arcs[arcs[a.id].prev_out].next_out = arcs[a.id  1].next_out; 923 923 924 unlink _edge(e);924 unlinkEdge(e); 925 925 components[nodes[n2.id].component].num_nodes; 926 unlink _node(n2.id);926 unlinkNode(n2.id); 927 927 } 928 928 929 929 //Primitives of split(Node) 930 void inner _split1(Node n1, Node &n2) {931 n2 = Node(link _node());930 void innerSplit1(Node n1, Node &n2) { 931 n2 = Node(linkNode()); 932 932 } 933 933 934 void inner _split2(Node n1, Node n2, Edge e1, Edge e2, bool b, Edge &e3) {934 void innerSplit2(Node n1, Node n2, Edge e1, Edge e2, bool b, Edge &e3) { 935 935 e3 = INVALID; 936 936 if (nodes[n1.id].first_out == 1) { 937 937 if (b) e3 = addEdge(n1,n2,INVALID,INVALID); … … 945 945 if (arcs[a1.id].target != n1.id) a1.id = 1; 946 946 Arc a2(e2.id*2); 947 947 if (arcs[a2.id].target != n1.id) a2.id = 1; 948 Arc a3(link _edge());948 Arc a3(linkEdge()); 949 949 e3 = a3; 950 950 arcs[a3.id].target = n1.id; 951 951 arcs[a3.id  1].target = n2.id; … … 973 973 } 974 974 975 975 //Relabels the "wall" of a face with a new face ID. 976 void wall _paint(Arc arc, int f_id, Arc ed) {976 void wallPaint(Arc arc, int f_id, Arc ed) { 977 977 do { 978 978 arcs[arc.id].left_face = f_id; 979 979 turnRightF(arc); … … 981 981 } 982 982 983 983 //Relabels a component with a new component ID. 984 void component _relabel(Node node, int comp_id) {984 void componentRelabel(Node node, int comp_id) { 985 985 std::vector<int> ns(nodes.size()); 986 986 std::list<int> q; 987 987 q.push_back(node.id); … … 1137 1137 } 1138 1138 } 1139 1139 #endif 1140 1141 1140 }; 1142 1141 1143 1142 // Face counting: … … 1302 1301 }; 1303 1302 1304 1303 1305 1304 /// Iterator class for the faces. 1306 1305 1307 1308 1306 /// This iterator goes through the faces of a planar graph. 1307 class FaceIt : public Face { 1309 1308 const Graph* _graph; 1310 1309 public: 1311 1310 … … 1325 1324 return *this; 1326 1325 } 1327 1326 1328 1327 }; 1329 1328 1330 1329 1331 1330 /// Iterator class for the common faces of two nodes 1332 1331 1333 1334 1332 /// This iterator goes through the common faces of two nodes 1333 class CommonFacesIt : public Face { 1335 1334 const Graph* _graph; 1336 1335 const Node _n1, _n2; 1337 1336 std::set<Face> _f1, _f2; … … 1371 1370 return *this; 1372 1371 } 1373 1372 1374 1373 }; 1375 1374 1376 1375 /// Iterator class for the common nodes of two facess 1377 1376 1378 1379 1377 /// This iterator goes through the common nodes of two faces 1378 class CommonNodesIt : public Node { 1380 1379 const Graph* _graph; 1381 1380 const Face _f1, _f2; 1382 1381 std::set<Node> _ns1,_ns2; … … 1416 1415 return *this; 1417 1416 } 1418 1417 1419 1418 }; 1420 1419 1421 /// Iterator class for the arcs on the boundary of a face. 1420 /// This iterator goes through the arcs on the boundary of a face counter clockwise. 1421 class CcwBoundaryArcIt : public Arc { 1422 const Graph* _graph; 1423 Face _face; 1424 Arc f_arc; 1425 public: 1422 1426 1423 /// This iterator goes through the arcs on the boundary of a face clockwise. 1424 class CwBoundaryArcIt : public Arc { 1427 CcwBoundaryArcIt() { } 1428 1429 CcwBoundaryArcIt(Invalid i) : Arc(i) { } 1430 1431 CcwBoundaryArcIt(const Graph& graph, const Face& face) 1432 : _graph(&graph), _face(face) { 1433 _graph>firstCcwF(static_cast<Arc&>(*this),face); 1434 f_arc = *this; 1435 } 1436 1437 CcwBoundaryArcIt(const Graph& graph, const Arc& arc) 1438 : Arc(arc), _graph(&graph) {} 1439 1440 CcwBoundaryArcIt& operator++() { 1441 _graph>nextCcwF(*this); 1442 return *this; 1443 } 1444 1445 }; 1446 1447 /// Iterator class for the arcs on the boundary of a face. 1448 1449 /// This iterator goes through the arcs on the boundary of a face clockwise. 1450 class CwBoundaryArcIt : public Arc { 1425 1451 const Graph* _graph; 1426 1452 Face _face; 1427 1453 Arc f_arc; … … 1445 1471 return *this; 1446 1472 } 1447 1473 1448 1474 }; 1449 1475 1450 /// Iterator class for the arcs arounda node.1476 /// Iterator class for the outgoing arcs of a node. 1451 1477 1452 /// This iterator goes through the arcs around a node anticlockwise.1453 class CcwArcIt : public Arc {1478 /// This iterator goes through the outgoing arcs of a node counter clockwise. 1479 class CcwOutArcIt : public Arc { 1454 1480 const Graph* _graph; 1455 1481 const Node _node; 1456 1482 public: 1457 1483 1458 Ccw ArcIt() { }1484 CcwOutArcIt() { } 1459 1485 1460 Ccw ArcIt(Invalid i) : Arc(i) { }1486 CcwOutArcIt(Invalid i) : Arc(i) { } 1461 1487 1462 Ccw ArcIt(const Graph& graph, const Node& node)1488 CcwOutArcIt(const Graph& graph, const Node& node) 1463 1489 : _graph(&graph), _node(node) { 1464 _graph>first Ccw(*this, node);1490 _graph>firstOut(*this, node); 1465 1491 } 1466 1492 1467 Ccw ArcIt(const Graph& graph, const Arc& arc)1493 CcwOutArcIt(const Graph& graph, const Arc& arc) 1468 1494 : Arc(arc), _graph(&graph) {} 1469 1495 1470 Ccw ArcIt& operator++() {1471 _graph>next Ccw(*this, _node);1496 CcwOutArcIt& operator++() { 1497 _graph>nextOut(*this); 1472 1498 return *this; 1473 1499 } 1474 1500 1501 }; 1502 1503 /// Iterator class for the outgoing arcs of a node. 1504 1505 /// This iterator goes through the outgoing arcs of a node clockwise. 1506 class CwOutArcIt : public Arc { 1507 const Graph* _graph; 1508 const Node _node; 1509 public: 1510 1511 CwOutArcIt() { } 1512 1513 CwOutArcIt(Invalid i) : Arc(i) { } 1514 1515 CwOutArcIt(const Graph& graph, const Node& node) 1516 : _graph(&graph), _node(node) { 1517 _graph>lastOut(*this, node); 1518 } 1519 1520 CwOutArcIt(const Graph& graph, const Arc& arc) 1521 : Arc(arc), _graph(&graph) {} 1522 1523 CwOutArcIt& operator++() { 1524 _graph>prevOut(*this); 1525 return *this; 1526 } 1527 1528 }; 1529 1530 /// Iterator class for the incoming arcs of a node. 1531 1532 /// This iterator goes through the incoming arcs of a node counter clockwise. 1533 class CcwInArcIt : public Arc { 1534 const Graph* _graph; 1535 const Node _node; 1536 public: 1537 1538 CcwInArcIt() { } 1539 1540 CcwInArcIt(Invalid i) : Arc(i) { } 1541 1542 CcwInArcIt(const Graph& graph, const Node& node) 1543 : _graph(&graph), _node(node) { 1544 _graph>firstIn(*this, node); 1545 } 1546 1547 CcwInArcIt(const Graph& graph, const Arc& arc) 1548 : Arc(arc), _graph(&graph) {} 1549 1550 CcwInArcIt& operator++() { 1551 _graph>nextIn(*this); 1552 return *this; 1553 } 1554 1555 }; 1556 1557 /// Iterator class for the incoming arcs of a node. 1558 1559 /// This iterator goes through the incoming arcs of a node clockwise. 1560 class CwInArcIt : public Arc { 1561 const Graph* _graph; 1562 const Node _node; 1563 public: 1564 1565 CwInArcIt() { } 1566 1567 CwInArcIt(Invalid i) : Arc(i) { } 1568 1569 CwInArcIt(const Graph& graph, const Node& node) 1570 : _graph(&graph), _node(node) { 1571 _graph>lastIn(*this, node); 1572 } 1573 1574 CwInArcIt(const Graph& graph, const Arc& arc) 1575 : Arc(arc), _graph(&graph) {} 1576 1577 CwInArcIt& operator++() { 1578 _graph>prevIn(*this); 1579 return *this; 1580 } 1581 1475 1582 }; 1476 1583 1477 1584 void clear() { … … 1519 1626 ///This class provides only linear time counting for nodes, edges, arcs and 1520 1627 ///faces. 1521 1628 /// 1522 ///A disconnected planar graph has havean outer face for each of its1629 ///A disconnected planar graph has an outer face for each of its 1523 1630 ///components, effectively turning them into separate graphs. Each component 1524 1631 ///has a corresponding component in the dual. 1525 1632 ///\sa concepts::Graph … … 1537 1644 /// \brief Constructor 1538 1645 1539 1646 /// Constructor. 1540 /// 1647 /// Creates an empty planar graph. 1541 1648 PlanarGraph() {} 1542 1649 1543 1650 typedef True PlanarGraphTag; 1651 1544 1652 ///\brief Constructor that copies a planar embedding 1545 1653 1546 1654 ///Constructor that copies a planar embedding. … … 1551 1659 this>copyEmbedding(g,em,nm,am); 1552 1660 } 1553 1661 1662 ///\brief Constructor that copies a planar embedding 1663 1664 ///Constructor that copies a planar embedding. Places the mapping from the 1665 ///nodes and arcs of the old graph to the ones of the new graph into \c nm 1666 ///and \c am, respectively. 1554 1667 template<typename Graph> 1555 1668 PlanarGraph(const Graph &g, const lemon::PlanarEmbedding<Graph> &em, 1556 1669 typename Graph::template NodeMap<Node> &nm, … … 1592 1705 } 1593 1706 } 1594 1707 1595 void edge _add_notify(Edge edge) {1708 void edgeAddNotify(Edge edge) { 1596 1709 notifier(Edge()).add(edge); 1597 1710 std::vector<Arc> ev; 1598 1711 ev.push_back(Parent::direct(edge, true)); … … 1600 1713 notifier(Arc()).add(ev); 1601 1714 } 1602 1715 1603 void edge _erase_notify(Edge edge) {1716 void edgeEraseNotify(Edge edge) { 1604 1717 std::vector<Arc> av; 1605 1718 av.push_back(Parent::direct(edge, true)); 1606 1719 av.push_back(Parent::direct(edge, false)); … … 1626 1739 /// This function adds a new edge to the graph between nodes 1627 1740 /// \c u and \c v with inherent orientation from node \c u to 1628 1741 /// node \c v. \c p_u and \c p_v are the edges that directly precede the new 1629 /// edge in anticlockwise order at the nodes \c u and \c v, respectively.1742 /// edge in counter clockwise order at the nodes \c u and \c v, respectively. 1630 1743 /// INVALID should be passed as \c p_u or \c p_v if and only if the 1631 1744 /// respective node is isolated. 1632 1745 /// … … 1659 1772 if (!valid(f_v) && f_u != f_v) notifier(Face()).erase(f_v); 1660 1773 if (!valid(o_u)) notifier(Face()).erase(o_u); 1661 1774 if (!valid(o_v)) notifier(Face()).erase(o_v); 1662 edge _add_notify(edge);1775 edgeAddNotify(edge); 1663 1776 Face e_l = leftFace(direct(edge,u)); 1664 1777 Face e_r = rightFace(direct(edge,u)); 1665 1778 if (e_l != f_u && e_l != f_v && e_l != o_u && e_l != o_v) … … 1752 1865 return Parent::valid(f); 1753 1866 } 1754 1867 1755 /// \brief Change the first node of an edge.1756 ///1757 /// Planar graphs don't support changing the endpoints of edges.1758 void changeU(Edge e, Node n) = delete;1759 /// \brief Change the second node of an edge.1760 ///1761 /// Planar graphs don't support changing the endpoints of edges.1762 void changeV(Edge e, Node n) = delete;1763 1764 1868 /// \brief Contract two nodes. 1765 1869 /// 1766 1870 /// This function contracts the two ends of the given edge. … … 1786 1890 if (n1 == n2) return; 1787 1891 Node nd; 1788 1892 bool simple; 1789 inner _contract1(n1,n2,nd,simple);1893 innerContract1(n1,n2,nd,simple); 1790 1894 notifier(Node()).erase(nd); 1791 edge _erase_notify(e);1792 inner _contract2(e,n1,n2,nd,simple);1895 edgeEraseNotify(e); 1896 innerContract2(e,n1,n2,nd,simple); 1793 1897 } 1794 1898 1795 1899 /// \brief Split an edge. … … 1808 1912 Node split(Edge e) { 1809 1913 Node v; 1810 1914 Edge e2; 1811 inner _split1(v,e2);1915 innerSplit1(v,e2); 1812 1916 notifier(Node()).add(v); 1813 edge _add_notify(e2);1814 return inner _split2(e,v,e2);1917 edgeAddNotify(e2); 1918 return innerSplit2(e,v,e2); 1815 1919 } 1816 1920 1817 1921 ///Split a node. 1818 1922 1819 1923 ///This function splits the given node. First, a new node is added 1820 ///to the graph, then all edges in anticlockwise order from \c e1 until but1924 ///to the graph, then all edges in counter clockwise order from \c e1 until but 1821 1925 ///not including \c e2 1822 1926 ///are reanchored from \c n to the new node. 1823 1927 ///If the second parameter \c connect is \c true (this is the default … … 1835 1939 ///Snapshot feature. 1836 1940 Node split(Node n1, Edge e1, Edge e2, bool connect) { 1837 1941 Node n2; 1838 inner _split1(n1,n2);1942 innerSplit1(n1,n2); 1839 1943 notifier(Node()).add(n2); 1840 1944 Edge a3; 1841 inner _split2(n1,n2,e1,e2,connect,a3);1945 innerSplit2(n1,n2,e1,e2,connect,a3); 1842 1946 if (!connect) { 1843 1947 if (a3 != INVALID) 1844 1948 erase(a3); 1845 1949 } else { 1846 edge _add_notify(a3);1950 edgeAddNotify(a3); 1847 1951 } 1848 1952 return n2; 1849 1953 } … … 1866 1970 /// then it is worth reserving space for this amount before starting 1867 1971 /// to build the graph. 1868 1972 /// \sa reserveEdge() 1973 /// \sa reserveFace() 1869 1974 void reserveNode(int n) { 1870 1975 nodes.reserve(n); 1871 1976 }; … … 1878 1983 /// then it is worth reserving space for this amount before starting 1879 1984 /// to build the graph. 1880 1985 /// \sa reserveNode() 1986 /// \sa reserveFace() 1881 1987 void reserveEdge(int m) { 1882 1988 arcs.reserve(2 * m); 1883 1989 }; … … 1889 1995 /// be large (e.g. it will contain millions of nodes and/or edges), 1890 1996 /// then it is worth reserving space for this amount before starting 1891 1997 /// to build the graph. 1892 /// \sa reserveFace() 1998 /// \sa reserveNode() 1999 /// \sa reserveEdge() 1893 2000 void reserveFace(int n) { 1894 2001 faces.reserve(n); 1895 2002 }; 1896 2003 2004 private: 1897 2005 class DualBase { 1898 2006 const Graph *_graph; 1899 2007 protected: … … 1939 2047 void next(Node &i) const { 1940 2048 _graph>next(i); 1941 2049 } 2050 void first(Edge &i) const { 2051 _graph>first(i); 2052 } 2053 void next(Edge &i) const { 2054 _graph>next(i); 2055 } 1942 2056 void first(Arc &i) const { 1943 2057 _graph>first(i); 1944 2058 } 1945 2059 void next(Arc &i) const { 1946 2060 _graph>next(i); 1947 2061 } 2062 void firstInc(Edge& i, bool &dir, const Node& n) const { 2063 Arc e; 2064 _graph>lastInF(e, n); 2065 i = e; 2066 dir = _graph>direction(e); 2067 } 2068 void nextInc(Edge& i, bool &dir) const { 2069 Arc e = _graph>direct(i, dir); 2070 _graph>prevInF(e); 2071 i = e; 2072 dir = _graph>direction(e); 2073 } 1948 2074 void firstCcw(Arc& i, const Node& n) const { 1949 2075 _graph>lastInF(i, n); 1950 2076 } … … 1957 2083 void nextIn(Arc& i) const { 1958 2084 _graph>nextInF(i); 1959 2085 } 2086 void lastIn(Arc& i, const Node& n) const { 2087 _graph>lastInF(i, n); 2088 } 2089 void prevIn(Arc& i) const { 2090 _graph>prevInF(i); 2091 } 1960 2092 void firstCwF(Arc& i, const Face& n) const { 1961 _graph>last In(i, n);2093 _graph>lastOut(i, n); 1962 2094 } 1963 2095 void nextCwF(Arc& i) const { 1964 _graph>prevIn(i); 2096 _graph>prevOut(i); 2097 } 2098 void firstCcwF(Arc& i, const Face& n) const { 2099 _graph>firstOut(i, n); 2100 } 2101 void nextCcwF(Arc& i) const { 2102 _graph>nextOut(i); 1965 2103 } 1966 2104 void firstOut(Arc& i, const Node& n ) const { 1967 _graph>first OutF(i, n);2105 _graph>firstCcwF(i, n); 1968 2106 } 1969 2107 void nextOut(Arc& i) const { 1970 _graph>nextOutF(i); 2108 _graph>nextCcwF(i); 2109 } 2110 void lastOut(Arc& i, const Node& n ) const { 2111 _graph>firstCwF(i, n); 2112 } 2113 void prevOut(Arc& i) const { 2114 _graph>nextCwF(i); 1971 2115 } 1972 2116 void first(Face &i) const { 1973 2117 _graph>first(i); … … 2004 2148 bool valid(Face n) const { 2005 2149 return _graph>valid(n); 2006 2150 } 2007 2151 Node u(Edge e) const { 2152 return _graph>w1(e); 2153 } 2154 Node v(Edge e) const { 2155 return _graph>w2(e); 2156 } 2157 Face w1(Edge e) const { 2158 return _graph>u(e); 2159 } 2160 Face w2(Edge e) const { 2161 return _graph>v(e); 2162 } 2163 2008 2164 }; 2009 2165 2010 2166 typedef PlanarGraphExtender<GraphExtender<DualBase> > ExtendedDualBase; 2011 2167 2012 /// Adaptor class for the dual of a planar graph. 2168 public: 2013 2169 2014 /// This is an adaptor class for the dual of a planar graph. 2015 class Dual : public ExtendedDualBase { 2016 public: 2170 /// Adaptor class for the dual of a planar graph. 2171 2172 /// This is an adaptor class for the dual of a planar graph. 2173 /// Nodes in the dual graph correspond to the faces of the underlying planar 2174 /// graph and vice versa. For this reason, the type Node in Dual is the same 2175 /// as Face in PlanarGraph and vice versa. All the iterators, maps and 2176 /// inspector functions work the same way as with PlanarGraph. 2177 class Dual : public ExtendedDualBase { 2178 public: 2017 2179 Dual(const PlanarGraph &graph) { 2018 2180 initialize(&graph); 2019 2181 } 
lemon/plane_graph.h
diff r 10d57978f900 r 2c0edf00dc8f lemon/plane_graph.h
a b 21 21 22 22 ///\ingroup graphs 23 23 ///\file 24 ///\brief PlaneGraph class es. UNDER CONSTRUCTION.24 ///\brief PlaneGraph class. 25 25 26 26 #include <lemon/planarity.h> 27 27 #include <lemon/planar_graph.h> … … 457 457 ///\ref PlaneGraph adds geometry features to PlanarGraph. While PlanarGraph 458 458 ///must be built from the topology, PlaneGraph requires coordinates for nodes 459 459 ///and determines the topology that fits the coordinates. 460 ///This class takes an edge shape type as a template parameter. The following 461 ///classes can be used as an edge shape type: 462 ///  PlaneGraphStraightEdge 463 ///  PlaneGraphLineStripEdge 464 ///  PlaneGraphBezier2Edge 465 ///  PlaneGraphBezier3Edge 466 ///A custom edge shape must have the following: 467 ///  typedef Point;  a point type, such as dim2::Point 468 ///  typedef Shape;  type which stores the shape data 469 ///  static Shape create();  creates an "empty" shape 470 ///  static Shape create(...);  creates a shape with arbitrary data 471 ///  static Point source(Shape);  returns the source point of an edge 472 ///  static Point target(Shape);  returns the target point of an edge 473 ///  static Shape reverse(Shape);  reverses an edge 474 ///  static bool between(Shape c, Shape a, Shape b);  returns true if and 475 /// only if c should go between a and b in counter clockwise order 476 ///  static bool intersect(Shape, Shape);  checks if two edges intersect 477 ///  static bool degenerate(Shape);  checks if a shape is invalid 460 478 ///\sa PlanarGraph 461 479 template <typename EdgeType = PlaneGraphStraightEdge> 462 480 class PlaneGraph : public PlanarGraph { … … 522 540 } 523 541 } 524 542 543 ///\brief Constructor that copies a planar drawing 544 545 ///Constructor that copies a planar drawing. Places the mapping from the 546 ///nodes and arcs of the old graph to the ones of the new graph into \c nm 547 ///and \c em, respectively. 525 548 template<typename Graph> 526 549 PlaneGraph(const Graph &graph, const lemon::PlanarDrawing<Graph> &drawing, 527 550 typename Graph::template NodeMap<Node> &nm, … … 633 656 if (p_v != INVALID && (p_u == INVALID  leftFace(p_u) != leftFace(p_v)) 634 657 && checkIntersections(es,p_v)) return INVALID; 635 658 636 #ifdef REMOVE_BEFORE_RELEASE637 std::cout << "AddArc: " << id(n1) << ">" << id(n2) << ", p_u: "638 << id(p_u) << ", p_v: " << id(p_v) << std::endl;639 #endif640 659 Edge e = PlanarGraph::addEdge(n1,n2,p_u,p_v); 641 660 if (e != INVALID) { 642 661 if (n1 != n2  EdgeType::between(esr,edgeshapes[p_u],es)) { … … 667 686 } 668 687 669 688 ///Get a map of the node locations. 689 670 690 ///Get a map of the node locations. 691 /// 671 692 const NodeMap<EdgePoint> &nodePosMap() const { 672 693 return nodepos; 673 694 } 674 695 675 696 ///Tell the location of a node. 697 676 698 ///Tell the location of a node. 699 /// 677 700 const EdgePoint &locate(const Node &n) const { 678 701 return nodepos[n]; 679 702 } 680 703 681 704 ///Tell the location of an arc. 705 682 706 ///Tell the location of an arc. 707 /// 683 708 const EdgeShape &locate(const Arc &a) const { 684 709 return edgeshapes[a]; 685 710 } … … 693 718 694 719 /// Iterator class for the edge shapes around a node. 695 720 696 /// This iterator goes through the arcs around a node anticlockwise. 721 /// This iterator goes through the arcs around a node counter clockwise. 722 /// 697 723 class CcwIncIt : public Arc { 698 724 const PlaneGraph* _graph; 699 725 const Node _node; … … 725 751 /// Iterator class for the edge shapes around a node. 726 752 727 753 /// This iterator goes through the arcs around a node clockwise. 754 /// 728 755 class CwIncIt : public Arc { 729 756 const PlaneGraph* _graph; 730 757 const Node _node; … … 756 783 /// Iterator class for the edge shapes on the boundary of a face. 757 784 758 785 /// This iterator goes through the arcs on the boundary of a face clockwise. 786 /// 759 787 class CwBoundaryIt { 760 788 const PlaneGraph* _graph; 761 789 Face _face; … … 786 814 /// Iterator class for the edge shapes on the boundary of a face. 787 815 788 816 /// This iterator goes through the arcs on the boundary of a face 789 /// anticlockwise.817 /// counter clockwise. 790 818 class CcwBoundaryIt { 791 819 const PlaneGraph* _graph; 792 820 Face _face; 
test/planar_graph_test.cc
diff r 10d57978f900 r 2c0edf00dc8f test/planar_graph_test.cc
a b 91 91 } 92 92 93 93 template <class Graph> 94 void checkGraphDual() { 95 TEMPLATE_GRAPH_TYPEDEFS(Graph); 96 97 Graph G; 98 Node n1 = G.addNode(), 99 n2 = G.addNode(), 100 n3 = G.addNode(), 101 n4 = G.addNode(); 102 Edge e1 = G.addEdge(n1, n2, INVALID, INVALID), 103 e2 = G.addEdge(n1, n3, e1, INVALID), 104 e3 = G.addEdge(n1, n4, e2, INVALID), 105 e4 = G.addEdge(n2, n3, e1, e2), 106 e5 = G.addEdge(n4, n3, e3, e4); 107 108 typedef PlanarGraph::Dual PD; 109 PD D(G); 110 checkGraphNodeList(D, 3); 111 checkGraphEdgeList(D, 5); 112 checkGraphArcList(D, 10); 113 checkGraphFaceList(D, 4); 114 115 checkGraphIncEdgeArcLists(D, G.leftFace(G.direct(e3, false)), 3); 116 checkGraphIncEdgeArcLists(D, G.leftFace(G.direct(e3, true)), 4); 117 checkGraphIncEdgeArcLists(D, G.leftFace(G.direct(e2, false)), 3); 118 checkGraphBoundaryArcList(D, n1, 3); 119 checkGraphBoundaryArcList(D, n2, 2); 120 checkGraphBoundaryArcList(D, n3, 3); 121 checkGraphBoundaryArcList(D, n4, 2); 122 123 } 124 125 template <class Graph> 94 126 void checkPlaneGraphBuild() { 95 127 TEMPLATE_GRAPH_TYPEDEFS(Graph); 96 128 … … 154 186 checkGraphFaceMap(G); 155 187 } 156 188 189 PlaneGraphLineStripEdge::Shape p2e(dim2::Point<double> p1, 190 dim2::Point<double> p2) { 191 std::vector<dim2::Point<double> > v(2); 192 v[0] = p1; 193 v[1] = p2; 194 return PlaneGraphLineStripEdge::create(v); 195 } 196 197 template<class Graph> 198 void checkPlaneGraph2Build() { 199 TEMPLATE_GRAPH_TYPEDEFS(Graph); 200 201 Graph G; 202 typedef dim2::Point<double> Pt; 203 Node 204 n1 = G.addNode(Pt(0.0,1.0)), 205 n2 = G.addNode(Pt(0.0,0.0)), 206 n3 = G.addNode(Pt(1.0,0.0)), 207 n4 = G.addNode(Pt(1.0,1.0)), 208 n5 = G.addNode(Pt(2.0,0.5)); 209 Edge 210 e1 = G.addEdge(p2e(Pt(0.0,1.0), Pt(0.0,0.0))), 211 e2 = G.addEdge(p2e(Pt(0.0,1.0), Pt(1.0,0.0))), 212 e3 = G.addEdge(p2e(Pt(0.0,1.0), Pt(1.0,1.0))), 213 e4 = G.addEdge(p2e(Pt(0.0,0.0), Pt(1.0,0.0))), 214 e5 = G.addEdge(p2e(Pt(1.0,1.0), Pt(1.0,0.0))), 215 e6 = G.addEdge(p2e(Pt(0.0,1.0), Pt(1.0,1.0))), //invalid 216 e7 = G.addEdge(p2e(Pt(0.0,1.0), Pt(2.0,0.5))); //invalid 217 218 checkGraphNodeList(G, 5); 219 checkGraphEdgeList(G, 5); 220 checkGraphArcList(G, 10); 221 checkGraphFaceList(G, 4); 222 223 checkGraphIncEdgeArcLists(G, n1, 3); 224 checkGraphIncEdgeArcLists(G, n2, 2); 225 checkGraphIncEdgeArcLists(G, n3, 3); 226 checkGraphIncEdgeArcLists(G, n4, 2); 227 checkGraphIncEdgeArcLists(G, n5, 0); 228 229 } 230 231 PlaneGraphBezier2Edge::Shape p3e(dim2::Point<double> p1, 232 dim2::Point<double> p2, dim2::Point<double> p3) { 233 return PlaneGraphBezier2Edge::create(p1, p2, p3); 234 } 235 236 template<class Graph> 237 void checkPlaneGraph3Build() { 238 TEMPLATE_GRAPH_TYPEDEFS(Graph); 239 240 Graph G; 241 typedef dim2::Point<double> Pt; 242 Node 243 n1 = G.addNode(Pt(0.0,1.0)), 244 n2 = G.addNode(Pt(0.0,0.0)), 245 n3 = G.addNode(Pt(1.0,0.0)), 246 n4 = G.addNode(Pt(1.0,1.0)), 247 n5 = G.addNode(Pt(2.0,0.5)); 248 Edge 249 e1 = G.addEdge(p3e(Pt(0.0,1.0), Pt(1.0,0.5), Pt(0.0,0.0))), 250 e2 = G.addEdge(p3e(Pt(0.0,1.0), Pt(0.6,0.6), Pt(1.0,0.0))), 251 e3 = G.addEdge(p3e(Pt(0.0,1.0), Pt(0.5,1.1), Pt(1.0,1.0))), 252 e4 = G.addEdge(p3e(Pt(0.0,0.0), Pt(0.5,0.1), Pt(1.0,0.0))), 253 e5 = G.addEdge(p3e(Pt(1.0,1.0), Pt(1.1,0.5), Pt(1.0,0.0))), 254 e6 = G.addEdge(p3e(Pt(0.0,1.0), Pt(0.6,0.6), Pt(1.0,1.0))), //invalid 255 e7 = G.addEdge(p3e(Pt(0.0,1.0), Pt(1.6,0.75), Pt(2.0,0.5))); //invalid 256 257 checkGraphNodeList(G, 5); 258 checkGraphEdgeList(G, 5); 259 checkGraphArcList(G, 10); 260 checkGraphFaceList(G, 4); 261 262 checkGraphIncEdgeArcLists(G, n1, 3); 263 checkGraphIncEdgeArcLists(G, n2, 2); 264 checkGraphIncEdgeArcLists(G, n3, 3); 265 checkGraphIncEdgeArcLists(G, n4, 2); 266 checkGraphIncEdgeArcLists(G, n5, 0); 267 268 } 269 270 PlaneGraphBezier3Edge::Shape p4e(dim2::Point<double> p1, 271 dim2::Point<double> p2, dim2::Point<double> p3, dim2::Point<double> p4) { 272 return PlaneGraphBezier3Edge::create(p1, p2, p3, p4); 273 } 274 275 template<class Graph> 276 void checkPlaneGraph4Build() { 277 TEMPLATE_GRAPH_TYPEDEFS(Graph); 278 279 Graph G; 280 typedef dim2::Point<double> Pt; 281 Node 282 n1 = G.addNode(Pt(0.0,1.0)), 283 n2 = G.addNode(Pt(0.0,0.0)), 284 n3 = G.addNode(Pt(1.0,0.0)), 285 n4 = G.addNode(Pt(1.0,1.0)), 286 n5 = G.addNode(Pt(2.0,0.5)); 287 Edge 288 e1 = G.addEdge(p4e(Pt(0.0,1.0), Pt(0.1,0.66), Pt(0.1,0.33), Pt(0.0,0.0))), 289 e2 = G.addEdge(p4e(Pt(0.0,1.0), Pt(0.33,0.33), Pt(0.66,0.66), Pt(1.0,0.0))), 290 e3 = G.addEdge(p4e(Pt(0.0,1.0), Pt(0.33,1.1), Pt(0.66,1.1), Pt(1.0,1.0))), 291 e4 = G.addEdge(p4e(Pt(0.0,0.0), Pt(0.33,0.1), Pt(0.66,0.1), Pt(1.0,0.0))), 292 e5 = G.addEdge(p4e(Pt(1.0,1.0), Pt(1.1,0.66), Pt(1.1,0.33), Pt(1.0,0.0))), 293 e6 = G.addEdge(p4e(Pt(0.0,1.0), Pt(0.33,0.33), Pt(0.66,0.66), Pt(1.0,1.0))), 294 e7 = G.addEdge(p4e(Pt(0.0,1.0), Pt(1.0,0.75), Pt(1.5,0.66), Pt(2.0,0.5))); 295 296 checkGraphNodeList(G, 5); 297 checkGraphEdgeList(G, 5); 298 checkGraphArcList(G, 10); 299 checkGraphFaceList(G, 4); 300 301 checkGraphIncEdgeArcLists(G, n1, 3); 302 checkGraphIncEdgeArcLists(G, n2, 2); 303 checkGraphIncEdgeArcLists(G, n3, 3); 304 checkGraphIncEdgeArcLists(G, n4, 2); 305 checkGraphIncEdgeArcLists(G, n5, 0); 306 307 } 308 157 309 template <class Graph> 158 310 void checkGraphArcSplit() { 159 311 TEMPLATE_GRAPH_TYPEDEFS(Graph); … … 493 645 void checkGraphs() { 494 646 { // Checking PlanarGraph 495 647 checkGraphBuild<PlanarGraph>(); 648 checkGraphDual<PlanarGraph>(); 496 649 checkPlaneGraphBuild<PlaneGraph<> >(); 650 checkPlaneGraph2Build<PlaneGraph<PlaneGraphLineStripEdge> >(); 651 checkPlaneGraph3Build<PlaneGraph<PlaneGraphBezier2Edge> >(); 652 checkPlaneGraph4Build<PlaneGraph<PlaneGraphBezier3Edge> >(); 497 653 checkGraphArcSplit<PlanarGraph>(); 498 654 checkGraphNodeSplit<PlanarGraph>(); 499 655 checkGraphContract<PlanarGraph>(); 
test/planar_graph_test.h
diff r 10d57978f900 r 2c0edf00dc8f test/planar_graph_test.h
a b 16 16 * 17 17 */ 18 18 19 #ifndef LEMON_TEST_ GRAPH_TEST_H20 #define LEMON_TEST_ GRAPH_TEST_H19 #ifndef LEMON_TEST_PLANAR_GRAPH_TEST_H 20 #define LEMON_TEST_PLANAR_GRAPH_TEST_H 21 21 22 22 #include <set> 23 23 … … 25 25 #include <lemon/maps.h> 26 26 27 27 #include "test_tools.h" 28 #include "graph_test.h" 28 29 29 30 namespace lemon { 30 31 31 32 template<class Graph> 32 void checkGraphNodeList(const Graph &G, int cnt)33 {34 typename Graph::NodeIt n(G);35 for(int i=0;i<cnt;i++) {36 check(n!=INVALID,"Wrong Node list linking.");37 ++n;38 }39 check(n==INVALID,"Wrong Node list linking.");40 check(countNodes(G)==cnt,"Wrong Node number.");41 }42 43 template<class Graph>44 33 void checkGraphFaceList(const Graph &G, int cnt) 45 34 { 46 35 typename Graph::FaceIt n(G); … … 53 42 } 54 43 55 44 template<class Graph> 56 void checkGraphArcList(const Graph &G, int cnt)57 {58 typename Graph::ArcIt e(G);59 for(int i=0;i<cnt;i++) {60 check(e!=INVALID,"Wrong Arc list linking.");61 check(G.oppositeNode(G.source(e), e) == G.target(e),62 "Wrong opposite node");63 check(G.oppositeNode(G.target(e), e) == G.source(e),64 "Wrong opposite node");65 ++e;66 }67 check(e==INVALID,"Wrong Arc list linking.");68 check(countArcs(G)==cnt,"Wrong Arc number.");69 }70 71 template<class Graph>72 void checkGraphOutArcList(const Graph &G, typename Graph::Node n, int cnt)73 {74 typename Graph::OutArcIt e(G,n);75 for(int i=0;i<cnt;i++) {76 check(e!=INVALID,"Wrong OutArc list linking.");77 check(n==G.source(e),"Wrong OutArc list linking.");78 check(n==G.baseNode(e),"Wrong OutArc list linking.");79 check(G.target(e)==G.runningNode(e),"Wrong OutArc list linking.");80 ++e;81 }82 check(e==INVALID,"Wrong OutArc list linking.");83 check(countOutArcs(G,n)==cnt,"Wrong OutArc number.");84 }85 86 template<class Graph>87 void checkGraphInArcList(const Graph &G, typename Graph::Node n, int cnt)88 {89 typename Graph::InArcIt e(G,n);90 for(int i=0;i<cnt;i++) {91 check(e!=INVALID,"Wrong InArc list linking.");92 check(n==G.target(e),"Wrong InArc list linking.");93 check(n==G.baseNode(e),"Wrong OutArc list linking.");94 check(G.source(e)==G.runningNode(e),"Wrong OutArc list linking.");95 ++e;96 }97 check(e==INVALID,"Wrong InArc list linking.");98 check(countInArcs(G,n)==cnt,"Wrong InArc number.");99 }100 101 template<class Graph>102 void checkGraphEdgeList(const Graph &G, int cnt)103 {104 typename Graph::EdgeIt e(G);105 for(int i=0;i<cnt;i++) {106 check(e!=INVALID,"Wrong Edge list linking.");107 check(G.oppositeNode(G.u(e), e) == G.v(e), "Wrong opposite node");108 check(G.oppositeNode(G.v(e), e) == G.u(e), "Wrong opposite node");109 ++e;110 }111 check(e==INVALID,"Wrong Edge list linking.");112 check(countEdges(G)==cnt,"Wrong Edge number.");113 }114 115 template<class Graph>116 void checkGraphIncEdgeList(const Graph &G, typename Graph::Node n, int cnt)117 {118 typename Graph::IncEdgeIt e(G,n);119 for(int i=0;i<cnt;i++) {120 check(e!=INVALID,"Wrong IncEdge list linking.");121 check(n==G.u(e)  n==G.v(e),"Wrong IncEdge list linking.");122 check(n==G.baseNode(e),"Wrong OutArc list linking.");123 check(G.u(e)==G.runningNode(e)  G.v(e)==G.runningNode(e),124 "Wrong OutArc list linking.");125 ++e;126 }127 check(e==INVALID,"Wrong IncEdge list linking.");128 check(countIncEdges(G,n)==cnt,"Wrong IncEdge number.");129 }130 131 template <class Graph>132 void checkGraphIncEdgeArcLists(const Graph &G, typename Graph::Node n,133 int cnt)134 {135 checkGraphIncEdgeList(G, n, cnt);136 checkGraphOutArcList(G, n, cnt);137 checkGraphInArcList(G, n, cnt);138 }139 140 template<class Graph>141 45 void checkGraphBoundaryArcList(const Graph &G, typename Graph::Face n, int 142 46 cnt) 143 47 { 144 typename Graph::CwBoundaryArcIt e(G,n); 48 typename Graph::CwBoundaryArcIt e1(G,n); 49 typename Graph::CcwBoundaryArcIt e2(G,n); 50 std::vector<int> v(cnt); 145 51 for(int i=0;i<cnt;i++) { 146 check(e!=INVALID,"Wrong CwBoundaryArc list linking."); 147 check(n==G.w1(e)  n==G.w2(e),"Wrong CwBoundaryArc list linking."); 148 ++e; 52 check(e1!=INVALID,"Wrong CwBoundaryArc list linking."); 53 check(n==G.w1(e1)  n==G.w2(e1),"Wrong CwBoundaryArc list linking."); 54 v[i] = G.id(e1); 55 ++e1; 149 56 } 150 check(e==INVALID,"Wrong BoundaryArc list linking."); 151 check(countBoundaryArcs(G,n)==cnt,"Wrong IncEdge number."); 152 } 153 154 template <class Graph> 155 void checkGraphConArcList(const Graph &G, int cnt) { 156 int i = 0; 157 for (typename Graph::NodeIt u(G); u != INVALID; ++u) { 158 for (typename Graph::NodeIt v(G); v != INVALID; ++v) { 159 for (ConArcIt<Graph> a(G, u, v); a != INVALID; ++a) { 160 check(G.source(a) == u, "Wrong iterator."); 161 check(G.target(a) == v, "Wrong iterator."); 162 ++i; 163 } 164 } 57 check(e1==INVALID,"Wrong BoundaryArc list linking."); 58 for(int i=0;i<cnt;i++) { 59 check(e2!=INVALID,"Wrong CcwBoundaryArc list linking."); 60 check(n==G.w1(e2)  n==G.w2(e2),"Wrong CcwBoundaryArc list linking."); 61 check(v[cnt1i] == G.id(e2),"Conflicting Cw and Ccw iterators."); 62 ++e2; 165 63 } 166 check(cnt == i, "Wrong iterator."); 167 } 168 169 template <class Graph> 170 void checkGraphConEdgeList(const Graph &G, int cnt) { 171 int i = 0; 172 for (typename Graph::NodeIt u(G); u != INVALID; ++u) { 173 for (typename Graph::NodeIt v(G); v != INVALID; ++v) { 174 for (ConEdgeIt<Graph> e(G, u, v); e != INVALID; ++e) { 175 check((G.u(e) == u && G.v(e) == v)  176 (G.u(e) == v && G.v(e) == u), "Wrong iterator."); 177 i += u == v ? 2 : 1; 178 } 179 } 180 } 181 check(2 * cnt == i, "Wrong iterator."); 64 check(e2==INVALID,"Wrong BoundaryArc list linking."); 65 check(countBoundaryArcs(G,n)==cnt,"Wrong Boundary Arc number."); 182 66 } 183 67 184 68 template<class Graph> … … 206 90 } 207 91 208 92 template <typename Graph> 209 void checkArcDirections(const Graph& G) {210 for (typename Graph::ArcIt a(G); a != INVALID; ++a) {211 check(G.source(a) == G.target(G.oppositeArc(a)), "Wrong direction");212 check(G.target(a) == G.source(G.oppositeArc(a)), "Wrong direction");213 check(G.direct(a, G.direction(a)) == a, "Wrong direction");214 }215 }216 217 template <typename Graph>218 void checkNodeIds(const Graph& G) {219 std::set<int> values;220 for (typename Graph::NodeIt n(G); n != INVALID; ++n) {221 check(G.nodeFromId(G.id(n)) == n, "Wrong id");222 check(values.find(G.id(n)) == values.end(), "Wrong id");223 check(G.id(n) <= G.maxNodeId(), "Wrong maximum id");224 values.insert(G.id(n));225 }226 }227 228 template <typename Graph>229 void checkArcIds(const Graph& G) {230 std::set<int> values;231 for (typename Graph::ArcIt a(G); a != INVALID; ++a) {232 check(G.arcFromId(G.id(a)) == a, "Wrong id");233 check(values.find(G.id(a)) == values.end(), "Wrong id");234 check(G.id(a) <= G.maxArcId(), "Wrong maximum id");235 values.insert(G.id(a));236 }237 }238 239 template <typename Graph>240 void checkEdgeIds(const Graph& G) {241 std::set<int> values;242 for (typename Graph::EdgeIt e(G); e != INVALID; ++e) {243 check(G.edgeFromId(G.id(e)) == e, "Wrong id");244 check(values.find(G.id(e)) == values.end(), "Wrong id");245 check(G.id(e) <= G.maxEdgeId(), "Wrong maximum id");246 values.insert(G.id(e));247 }248 }249 250 template <typename Graph>251 93 void checkFaceIds(const Graph& G) { 252 94 std::set<int> values; 253 95 for (typename Graph::FaceIt n(G); n != INVALID; ++n) { … … 259 101 } 260 102 261 103 template <typename Graph> 262 void checkGraphNodeMap(const Graph& G) {263 typedef typename Graph::Node Node;264 typedef typename Graph::NodeIt NodeIt;265 266 typedef typename Graph::template NodeMap<int> IntNodeMap;267 IntNodeMap map(G, 42);268 for (NodeIt it(G); it != INVALID; ++it) {269 check(map[it] == 42, "Wrong map constructor.");270 }271 int s = 0;272 for (NodeIt it(G); it != INVALID; ++it) {273 map[it] = 0;274 check(map[it] == 0, "Wrong operator[].");275 map.set(it, s);276 check(map[it] == s, "Wrong set.");277 ++s;278 }279 s = s * (s  1) / 2;280 for (NodeIt it(G); it != INVALID; ++it) {281 s = map[it];282 }283 check(s == 0, "Wrong sum.");284 285 // map = constMap<Node>(12);286 // for (NodeIt it(G); it != INVALID; ++it) {287 // check(map[it] == 12, "Wrong operator[].");288 // }289 }290 291 template <typename Graph>292 void checkGraphArcMap(const Graph& G) {293 typedef typename Graph::Arc Arc;294 typedef typename Graph::ArcIt ArcIt;295 296 typedef typename Graph::template ArcMap<int> IntArcMap;297 IntArcMap map(G, 42);298 for (ArcIt it(G); it != INVALID; ++it) {299 check(map[it] == 42, "Wrong map constructor.");300 }301 int s = 0;302 for (ArcIt it(G); it != INVALID; ++it) {303 map[it] = 0;304 check(map[it] == 0, "Wrong operator[].");305 map.set(it, s);306 check(map[it] == s, "Wrong set.");307 ++s;308 }309 s = s * (s  1) / 2;310 for (ArcIt it(G); it != INVALID; ++it) {311 s = map[it];312 }313 check(s == 0, "Wrong sum.");314 315 // map = constMap<Arc>(12);316 // for (ArcIt it(G); it != INVALID; ++it) {317 // check(map[it] == 12, "Wrong operator[].");318 // }319 }320 321 template <typename Graph>322 void checkGraphEdgeMap(const Graph& G) {323 typedef typename Graph::Edge Edge;324 typedef typename Graph::EdgeIt EdgeIt;325 326 typedef typename Graph::template EdgeMap<int> IntEdgeMap;327 IntEdgeMap map(G, 42);328 for (EdgeIt it(G); it != INVALID; ++it) {329 check(map[it] == 42, "Wrong map constructor.");330 }331 int s = 0;332 for (EdgeIt it(G); it != INVALID; ++it) {333 map[it] = 0;334 check(map[it] == 0, "Wrong operator[].");335 map.set(it, s);336 check(map[it] == s, "Wrong set.");337 ++s;338 }339 s = s * (s  1) / 2;340 for (EdgeIt it(G); it != INVALID; ++it) {341 s = map[it];342 }343 check(s == 0, "Wrong sum.");344 345 // map = constMap<Edge>(12);346 // for (EdgeIt it(G); it != INVALID; ++it) {347 // check(map[it] == 12, "Wrong operator[].");348 // }349 }350 351 352 template <typename Graph>353 104 void checkGraphFaceMap(const Graph& G) { 354 105 typedef typename Graph::Face Face; 355 106 typedef typename Graph::FaceIt FaceIt;