Open
Graph Drawing
Framework

 v.2012.05
 

ClusterPlanRep.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008  
00043 #ifdef _MSC_VER
00044 #pragma once
00045 #endif
00046 
00047 #ifndef OGDF_CLUSTER_PLAN_REP_H
00048 #define OGDF_CLUSTER_PLAN_REP_H
00049 
00050 
00051 
00052 #include <ogdf/planarity/PlanRepUML.h>
00053 #include <ogdf/cluster/ClusterGraphAttributes.h>
00054 #include <ogdf/cluster/ClusterGraph.h>
00055 #include <ogdf/cluster/ClusterArray.h>
00056 
00057 #include <ogdf/basic/HashArray.h>
00058 
00059 
00060 namespace ogdf {
00061 
00062 
00063 class OGDF_EXPORT ClusterPlanRep : public PlanRep
00064 {
00065 
00066 public:
00067 
00068     ClusterPlanRep(const ClusterGraphAttributes &acGraph, 
00069                    const ClusterGraph &clusterGraph);
00070 
00071     virtual ~ClusterPlanRep() {}
00072 
00073     void initCC(int i);
00074 
00075     //edge on the cluster boundary, adjSource
00076     void setClusterBoundary(edge e) {
00077         setEdgeTypeOf(e, edgeTypeOf(e) | clusterPattern());
00078     }
00079     bool isClusterBoundary(edge e) {
00080         return ((edgeTypeOf(e) & clusterPattern()) == clusterPattern());
00081     }
00082     const ClusterGraph &getClusterGraph() const {
00083         return *m_pClusterGraph;
00084     }
00094     void insertEdgePathEmbedded(edge eOrig,
00095                                 CombinatorialEmbedding &E,
00096                                 const SList<adjEntry> &crossedEdges);
00097 
00098     void ModelBoundaries();
00099 
00100     //rootadj is set by ModelBoundaries
00101     adjEntry externalAdj() {return m_rootAdj;};
00102 
00103 
00104     //*************************************************************************
00105     //structural alterations
00106 
00107     // Expands nodes with degree > 4 and merge nodes for generalizations
00108     virtual void expand(bool lowDegreeExpand = false);
00109 
00110     virtual void expandLowDegreeVertices(OrthoRep &OR);
00111 
00112     //splits edge e, updates clustercage lists if necessary and returns new edge
00113     virtual edge split(edge e)
00114     {
00115         edge eNew = PlanRep::split(e);
00116 
00117         //update edge to cluster info
00118         m_edgeClusterID[eNew] = m_edgeClusterID[e];
00119         m_nodeClusterID[eNew->source()] = m_edgeClusterID[e];
00120 
00121         return eNew;
00122     }//split
00123 
00124 
00125     //returns cluster of edge e
00126     //edges only have unique numbers if clusters are already modelled
00127     //we derive the edge cluster from the endnode cluster information
00128     cluster clusterOfEdge(edge e) 
00129     {
00130 
00131         OGDF_ASSERT(m_clusterOfIndex.isDefined(ClusterID(e->source())))
00132         OGDF_ASSERT(m_clusterOfIndex.isDefined(ClusterID(e->target())))
00133 
00134         OGDF_ASSERT( (ClusterID(e->source()) == ClusterID(e->target())) ||
00135                       (clusterOfIndex(ClusterID(e->source())) ==
00136                        clusterOfIndex(ClusterID(e->target()))->parent()) ||
00137                        (clusterOfIndex(ClusterID(e->target())) ==
00138                        clusterOfIndex(ClusterID(e->source()))->parent()) ||
00139                        (clusterOfIndex(ClusterID(e->target()))->parent() ==
00140                        clusterOfIndex(ClusterID(e->source()))->parent())
00141                        )
00142 
00143         if (ClusterID(e->source()) == ClusterID(e->target()))
00144             return clusterOfIndex(ClusterID(e->target()));
00145         if (clusterOfIndex(ClusterID(e->source())) ==
00146             clusterOfIndex(ClusterID(e->target()))->parent())
00147             return clusterOfIndex(ClusterID(e->source()));
00148         if (clusterOfIndex(ClusterID(e->target())) ==
00149             clusterOfIndex(ClusterID(e->source()))->parent())
00150             return clusterOfIndex(ClusterID(e->target()));
00151         if (clusterOfIndex(ClusterID(e->target()))->parent() ==
00152             clusterOfIndex(ClusterID(e->source()))->parent())
00153             return clusterOfIndex(ClusterID(e->source()))->parent();
00154 
00155         OGDF_THROW(AlgorithmFailureException);
00156         //return 0;
00157     }//clusterOfEdge
00158 
00159     inline int ClusterID(node v) const {return m_nodeClusterID[v];}
00160     inline int ClusterID(edge e) const {return m_edgeClusterID[e];}
00161     cluster clusterOfIndex(int i) {return m_clusterOfIndex[i];}
00162 
00163     inline cluster clusterOfDummy(node v) 
00164         {
00165             OGDF_ASSERT(!original(v))
00166             OGDF_ASSERT(ClusterID(v) != -1)
00167             return clusterOfIndex(ClusterID(v));
00168         }
00169 
00170     //output functions
00171     void writeGML(const char *fileName, const Layout &drawing);
00172     void writeGML(const char *fileName);
00173     void writeGML(ostream &os, const Layout &drawing);
00174 
00175 
00176 protected:
00177 
00178     //insert boundaries for all given clusters
00179     void convertClusterGraph(cluster act, 
00180                              AdjEntryArray<edge>& currentEdge,
00181                              AdjEntryArray<int>& outEdge);
00182 
00183     //insert edges to represent the cluster boundary
00184     void insertBoundary(cluster C, 
00185                         AdjEntryArray<edge>& currentEdge,
00186                         AdjEntryArray<int>& outEdge,
00187                         bool clusterIsLeaf);
00188 
00189     //reinsert edges to planarize the graph after convertClusterGraph
00190     void reinsertEdge(edge e);
00191 
00192 private:
00193 
00194     const ClusterGraph *m_pClusterGraph;
00195 
00196     edgeType clusterPattern()        {return etcSecCluster << etoSecondary;}
00197 
00198     adjEntry m_rootAdj; //connects cluster on highest level with non cluster or 
00199                      //same level
00200 
00201 
00202     //******************
00203     EdgeArray<int> m_edgeClusterID;
00204     NodeArray<int> m_nodeClusterID;
00205     //we maintain an array of index to cluster mappings (CG is const)
00206     //cluster numbers don't need to be consecutive
00207     HashArray<int, cluster> m_clusterOfIndex;
00208 };
00209 
00210 
00211 }//namespace
00212 
00213 #endif