6 * $Date: 2012-07-07 17:14:54 +0200 (Sa, 07. Jul 2012) $
7 ***************************************************************/
10 * \brief Implementation of dual graph
12 * \author Michael Schulz
15 * This file is part of the Open Graph Drawing Framework (OGDF).
19 * See README.txt in the root directory of the OGDF installation for details.
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * Version 2 or 3 as published by the Free Software Foundation;
25 * see the file LICENSE.txt included in the packaging of this file
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public
36 * License along with this program; if not, write to the Free
37 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 * Boston, MA 02110-1301, USA.
40 * \see http://www.gnu.org/copyleft/gpl.html
41 ***************************************************************/
43 #include <ogdf/basic/DualGraph.h>
47 // Computes combinatorial embedding of dual graph
48 // Precondition: CE must be combinatorial embedding of connected planar graph
49 DualGraph::DualGraph(CombinatorialEmbedding
&CE
)
51 m_primalEmbedding
= &CE
;
52 Graph
&primalGraph
= CE
.getGraph();
54 Graph
&dualGraph
= getGraph();
57 m_dualEdge
.init(primalGraph
);
58 m_dualFace
.init(primalGraph
);
59 m_primalNode
.init(*this);
60 m_primalFace
.init(dualGraph
);
61 m_primalEdge
.init(dualGraph
);
67 node vDual
= dualGraph
.newNode();
68 m_dualNode
[f
] = vDual
;
69 m_primalFace
[vDual
] = f
;
74 forall_edges(e
, primalGraph
)
76 adjEntry aE
= e
->adjSource();
77 node vDualSource
= m_dualNode
[CE
.rightFace(aE
)];
78 node vDualTarget
= m_dualNode
[CE
.leftFace(aE
)];
79 edge eDual
= dualGraph
.newEdge(vDualSource
, vDualTarget
);
80 m_primalEdge
[eDual
] = e
;
81 m_dualEdge
[e
] = eDual
;
84 // sort adjElements of every dual node corresponding to dual embedding
85 EdgeArray
<bool> visited(dualGraph
, false); // needed for self-loops
88 node vDual
= m_dualNode
[f
];
89 adjEntry aePrimal
= f
->firstAdj();
90 List
<adjEntry
> aeList
;
93 edge eDual
= m_dualEdge
[aePrimal
->theEdge()];
94 adjEntry aeDual
= eDual
->adjSource();
95 if((aeDual
->theNode()!=vDual
) || (eDual
->isSelfLoop() && visited
[eDual
]))
96 aeDual
= eDual
->adjTarget();
97 aeList
.pushBack( aeDual
);
98 visited
[eDual
] = true; // only needed for self-loops
99 aePrimal
= aePrimal
->faceCycleSucc();
101 while(aePrimal
!= f
->firstAdj());
102 dualGraph
.sort(vDual
, aeList
);
105 // calculate dual faces and links to corresponding primal nodes
108 forall_nodes(v
, primalGraph
)
110 edge ePrimal
= v
->firstAdj()->theEdge();
111 edge eDual
= m_dualEdge
[ePrimal
];
112 face fDual
= rightFace(eDual
->adjSource());
113 if(ePrimal
->source()==v
)
114 fDual
= leftFace(eDual
->adjSource());
115 m_dualFace
[v
] = fDual
;
116 m_primalNode
[fDual
] = v
;
121 DualGraph::~DualGraph()