Open
Graph Drawing
Framework

 v.2012.05
 

RoutingChannel.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  
00044 #ifdef _MSC_VER
00045 #pragma once
00046 #endif
00047 
00048 
00049 #ifndef OGDF_ROUTING_CHANNEL_H
00050 #define OGDF_ROUTING_CHANNEL_H
00051 
00052 
00053 #include <ogdf/orthogonal/OrthoRep.h>
00054 
00055 
00056 namespace ogdf {
00057 
00058 //---------------------------------------------------------
00059 // RoutingChannel
00060 // maintains input sizes for constructive compaction (size
00061 // of routing channels, separation, cOverhang)
00062 //---------------------------------------------------------
00063 template<class ATYPE>
00064 class RoutingChannel
00065 {
00066 public:
00067     // constructor
00068     RoutingChannel(const Graph &G, ATYPE sep, double cOver) :
00069         m_channel(G), m_separation(sep), m_cOverhang(cOver) { }
00070 
00071     // size of routing channel of side dir of node v
00072     const ATYPE &operator()(node v, OrthoDir dir) const {
00073         return m_channel[v].rc[dir];
00074     }
00075 
00076     ATYPE &operator()(node v, OrthoDir dir) {
00077         return m_channel[v].rc[dir];
00078     }
00079 
00080     // returns separation (minimum distance between vertices/edges)
00081     ATYPE separation() const {
00082         return m_separation;
00083     }
00084 
00085     // returns cOverhang (such that overhang = separation * cOverhang)
00086     double cOverhang() const {
00087         return m_cOverhang;
00088     }
00089 
00090     // returns overhang (distance between vertex corners and edges)
00091     ATYPE overhang() const {
00092         return ATYPE(m_cOverhang * m_separation);
00093     }
00094 
00095     void computeRoutingChannels(const OrthoRep &OR, bool align = false)
00096     {
00097         const Graph &G = OR;
00098 
00099         node v;
00100         forall_nodes(v,G)
00101         {
00102             const OrthoRep::VertexInfoUML *pInfo = OR.cageInfo(v);
00103 
00104             if (pInfo) {
00105                 const OrthoRep::SideInfoUML &sNorth = pInfo->m_side[odNorth];
00106                 const OrthoRep::SideInfoUML &sSouth = pInfo->m_side[odSouth];
00107                 const OrthoRep::SideInfoUML &sWest  = pInfo->m_side[odWest];
00108                 const OrthoRep::SideInfoUML &sEast  = pInfo->m_side[odEast];
00109 
00110                 (*this)(v,odNorth) = computeRoutingChannel(sNorth,sSouth,align);
00111                 (*this)(v,odSouth) = computeRoutingChannel(sSouth,sNorth,align);
00112                 (*this)(v,odWest ) = computeRoutingChannel(sWest ,sEast ,align);
00113                 (*this)(v,odEast ) = computeRoutingChannel(sEast ,sWest ,align);
00114             }
00115         }
00116     }
00117 
00118 private:
00119     // computes required size of routing channel at side si with opposite side siOpp
00120     int computeRoutingChannel(
00121         const OrthoRep::SideInfoUML &si,
00122         const OrthoRep::SideInfoUML &siOpp,
00123         bool align = false)
00124     {
00125         if (si.m_adjGen == 0)
00126         {
00127             int k = si.m_nAttached[0];
00128             if (k == 0 || 
00129                 ((k == 1 && siOpp.totalAttached() == 0) && !align) )
00130                 return 0;
00131             else
00132                 return (k+1)*m_separation;
00133 
00134         } else {
00135             int m = max(si.m_nAttached[0],si.m_nAttached[1]);
00136             if (m == 0)
00137                 return 0;
00138             else
00139                 return (m+1)*m_separation;
00140         }
00141     }
00142 
00143     struct vInfo {
00144         ATYPE rc[4];
00145         vInfo() {
00146             rc[0] = rc[1] = rc[2] = rc[3];
00147         }
00148     };
00149 
00150     NodeArray<vInfo> m_channel;
00151     ATYPE m_separation;
00152     double m_cOverhang;
00153 };
00154 
00155 
00156 } // end namespace ogdf
00157 
00158 
00159 #endif