Don't import ogdf namespace
[TortoiseGit.git] / ext / OGDF / src / planarlayout / IOPoints.h
blob66b6bd6fbfece1e2a7b62ffdf65f7109ef107cfa
1 /*
2 * $Revision: 2571 $
4 * last checkin:
5 * $Author: gutwenger $
6 * $Date: 2012-07-10 17:25:20 +0200 (Di, 10. Jul 2012) $
7 ***************************************************************/
9 /** \file
10 * \brief Declaration of classes InOutPoint and IOPoints which
11 * implement the management of in-/out-points
13 * \author Carsten Gutwenger
15 * \par License:
16 * This file is part of the Open Graph Drawing Framework (OGDF).
18 * \par
19 * Copyright (C)<br>
20 * See README.txt in the root directory of the OGDF installation for details.
22 * \par
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License
25 * Version 2 or 3 as published by the Free Software Foundation;
26 * see the file LICENSE.txt included in the packaging of this file
27 * for details.
29 * \par
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * \par
36 * You should have received a copy of the GNU General Public
37 * License along with this program; if not, write to the Free
38 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
39 * Boston, MA 02110-1301, USA.
41 * \see http://www.gnu.org/copyleft/gpl.html
42 ***************************************************************/
44 #ifdef _MSC_VER
45 #pragma once
46 #endif
48 #ifndef OGDF_IO_POINTS_H
49 #define OGDF_IO_POINTS_H
52 #include <ogdf/planarity/PlanRep.h>
55 namespace ogdf {
58 /********************************************************************
59 representation of an in- or outpoint
60 ********************************************************************/
62 struct InOutPoint
64 int m_dx, m_dy;
65 adjEntry m_adj;
67 InOutPoint() {
68 m_dx = m_dy = 0; m_adj = 0;
70 InOutPoint(adjEntry adj) {
71 m_adj = adj; m_dx = m_dy = 0;
76 /********************************************************************
77 representation of in- and outpoint lists
78 ********************************************************************/
80 class IOPoints {
81 public:
82 IOPoints() { }
83 IOPoints(const Graph &G) : m_depth(G,0), m_height(G,0), m_in(G), m_out(G),
84 m_mark(G,false), m_pointOf(G,0) { }
86 ~IOPoints () { }
89 // length of in- or outpoint list
90 int out(node v) const {
91 return m_out[v].size();
93 int in(node v) const {
94 return m_in[v].size();
97 // getting a const-reference to in- or outpoint list
98 const List<InOutPoint> &inpoints(node v) const {
99 return m_in [v];
101 List<InOutPoint> &inpoints(node v) {
102 return m_in [v];
105 const List<InOutPoint> &outpoints(node v) const {
106 return m_out [v];
108 List<InOutPoint> &outpoints(node v) {
109 return m_out [v];
112 // getting the in-/outpoint belonging to an adjacency entry
113 const InOutPoint *pointOf(adjEntry adj) const {
114 return m_pointOf[adj];
117 // marking adjacency entries
118 bool marked(adjEntry adj) const {
119 return m_mark[adj];
122 bool marked(node v) {
123 return (v->outdeg() == 1 && marked(v->firstAdj()));
126 // finding outpoints belonging to non-marked edges
127 ListConstIterator<InOutPoint> firstRealOut(node v) const {
128 return searchRealForward(m_out[v].begin());
131 ListConstIterator<InOutPoint> lastRealOut(node v) const {
132 return searchRealBackward(m_out[v].rbegin());
135 ListConstIterator<InOutPoint> nextRealOut(ListConstIterator<InOutPoint> it) const {
136 return searchRealForward(it.succ());
139 ListConstIterator<InOutPoint> prevRealOut(ListConstIterator<InOutPoint> it) const {
140 return searchRealBackward(it.pred());
143 // building in-/outpoint lists
144 void appendInpoint(adjEntry adj) {
145 node v = adj->theNode();
146 m_pointOf[adj] = &(*m_in[v].pushBack(InOutPoint(adj)));
148 void appendOutpoint(adjEntry adj) {
149 node v = adj->theNode();
150 m_pointOf[adj] = &(*m_out[v].pushBack(InOutPoint(adj)));
152 void pushInpoint(adjEntry adj) {
153 node v = adj->theNode();
154 m_pointOf[adj] = &(*m_in[v].pushFront(InOutPoint(adj)));
157 // setting relative coordinates
158 void setOutCoord (ListIterator<InOutPoint> it, int dx, int dy) {
159 (*it).m_dx = dx;
160 (*it).m_dy = dy;
162 void setInCoord (ListIterator<InOutPoint> it, int dx, int dy) {
163 (*it).m_dx = dx;
164 (*it).m_dy = dy;
167 void setOutDx(ListIterator<InOutPoint> it, int dx) {
168 (*it).m_dx = dx;
171 void restoreDeg1Nodes(PlanRep &PG, Stack<PlanRep::Deg1RestoreInfo> &S);
173 void changeEdge(node v, adjEntry adj_new) {
174 m_out[v].popBack();
175 appendInpoint(adj_new);
178 // belongs v to a chain (= at most to non-marked incoming edges
179 bool isChain(node v) const {
180 int i = 0;
181 ListConstIterator<InOutPoint> it;
182 for(it = m_in[v].begin(); it.valid(); ++it)
183 if (!marked((*it).m_adj)) ++i;
184 return (i <= 2);
187 // width of the left-/right side of an in-/outpoint list
188 int outLeft(node v) const {
189 return (m_out[v].empty()) ? 0 : (-m_out[v].front().m_dx);
192 int outRight(node v) const {
193 return (m_out[v].empty()) ? 0 : (m_out[v].back().m_dx);
196 int inLeft(node v) const {
197 return (m_in[v].empty()) ? 0 : (-m_in[v].front().m_dx);
200 int inRight(node v) const {
201 return (m_in[v].empty()) ? 0 : (m_in[v].back().m_dx);
204 int maxLeft(node v) const {
205 return max(inLeft(v), outLeft(v));
208 int maxRight(node v) const {
209 return max(inRight(v), outRight(v));
212 int maxPlusLeft(node v) const {
213 return (in(v) >= 3) ?
214 max(inLeft(v)+1, outLeft(v)) : maxLeft(v);
217 int maxPlusRight(node v) const {
218 return (in(v) >= 3) ?
219 max(inRight(v)+1, outRight(v)) : maxRight(v);
222 InOutPoint middleNeighbor(node z1) const;
224 void numDeg1(node v, int &xl, int &xr,
225 bool doubleCount) const;
227 adjEntry switchBeginIn(node v);
228 adjEntry switchEndIn (node v);
230 void switchBeginOut(node v);
231 void switchEndOut (node v);
234 NodeArray<int> m_depth, m_height;
237 private:
238 NodeArray<List<InOutPoint> > m_in, m_out;
239 AdjEntryArray<bool> m_mark;
240 AdjEntryArray<InOutPoint *> m_pointOf;
242 ListConstIterator<InOutPoint> searchRealForward (ListConstIterator<InOutPoint> it) const;
243 ListConstIterator<InOutPoint> searchRealBackward(ListConstIterator<InOutPoint> it) const;
248 } // end namespace ogdf
251 #endif