Open
Graph Drawing
Framework

 v.2012.05
 

ELabelInterface.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  
00041 #ifdef _MSC_VER
00042 #pragma once 
00043 #endif
00044 
00045 #ifndef OGDF_E_LABEL_INTERFACE_H
00046 #define OGDF_E_LABEL_INTERFACE_H
00047 
00048 #include <ogdf/orthogonal/OrthoLayout.h>
00049 #include <ogdf/basic/GridLayout.h>
00050 #include <ogdf/basic/GridLayoutMapped.h>
00051 #include <ogdf/planarity/PlanRepUML.h>
00052 
00053 
00054 namespace ogdf {
00055 
00056 //********************************************************
00057 //global defs
00058 //the available labels
00059 //the five basic labels are not allowed to be changed,
00060 //cause the have a special meaning/position, insert
00061 //other labels between mult1/End2
00062 const int labelNum = 5;
00063 //Note: eLabelTyp is used for index computation (increment +1) in arrays
00064 //of type 0..labelNum, whereas eUsedLabels can be used as bitfield
00065 //for matching, setting and comparison (|-op)
00066 enum eLabelTyp {elEnd1, elMult1, elName, elEnd2, elMult2};
00067 enum eUsedLabels {lName = 4, lEnd1 = 1, lMult1 = 2, lEnd2 = 8, lMult2 = 16, lAll = 31};
00068 
00069 
00070 //*************************************
00071 //the basic single label defining class
00072 //holds info about all labels for one edge
00073 template <class coordType>
00074 class OGDF_EXPORT EdgeLabel {
00075 
00076 public:
00077 
00078     //construction and destruction
00079     EdgeLabel() {m_edge = 0; m_usedLabels = 0;}
00080     //bit pattern 2^labelenumpos bitwise
00081     EdgeLabel(edge e, int usedLabels = lAll) : m_usedLabels(usedLabels) 
00082     {
00083       m_edge = e;
00084       for(int i = 0; i < labelNum; i++)
00085       {
00086         //zu testzwecken randoms
00087         m_xSize[i] = double(randomNumber(5,13))/50.0; //1
00088         m_ySize[i] = double(randomNumber(3,7))/50.0;  //1
00089 
00090         m_xPos[i] = 0;
00091         m_yPos[i] = 0;
00092       }//for
00093     
00094     }//constructor
00095     // Construction with specification of label sizes in arrays of length labelnum
00096     EdgeLabel(edge e, coordType w[], coordType h[], int usedLabels = lAll) : m_usedLabels(usedLabels) 
00097     {
00098       m_edge = e;
00099       for(int i = 0; i < labelNum; i++)
00100       {
00101         m_xSize[i] = w[i];
00102         m_ySize[i] = h[i];
00103         m_xPos[i] = 0;
00104         m_yPos[i] = 0;
00105       }//for
00106     
00107     }//constructor
00108 
00109     EdgeLabel(edge e, coordType w, coordType h, int usedLabels) : m_usedLabels(usedLabels)
00110     {
00111         m_edge = e;
00112         for (int i = 0; i < labelNum; i++)
00113             if (m_usedLabels & (1 << i)) {
00114                 m_xPos[i] = 0.0;
00115                 m_yPos[i] = 0.0;
00116                 m_xSize[i] = w;
00117                 m_ySize[i] = h;
00118             }
00119     }
00120 
00121     ~EdgeLabel() {}
00122 
00123     //copy constructor
00124     inline EdgeLabel(const EdgeLabel& rhs)
00125     {
00126       m_usedLabels = rhs.m_usedLabels;
00127       m_edge = rhs.m_edge;
00128       int i;
00129       for(i = 0; i < labelNum; i++)
00130       {
00131         m_xPos[i] = rhs.m_xPos[i];
00132         m_yPos[i] = rhs.m_yPos[i];
00133         m_xSize[i] = rhs.m_xSize[i];
00134         m_ySize[i] = rhs.m_ySize[i];
00135       }
00136     }//copy con
00137     //assignment
00138     inline EdgeLabel& operator=(const EdgeLabel& rhs)
00139     {
00140       if ( this != &rhs)
00141       {
00142          m_usedLabels = rhs.m_usedLabels;
00143          m_edge = rhs.m_edge;
00144         int i;
00145         for(i = 0; i < labelNum; i++)
00146         {
00147           m_xPos[i] = rhs.m_xPos[i];
00148           m_yPos[i] = rhs.m_yPos[i];
00149           m_xSize[i] = rhs.m_xSize[i];
00150           m_ySize[i] = rhs.m_ySize[i];
00151         }
00152       }
00153       return *this;
00154     }//assignment
00155 
00156     inline EdgeLabel& operator|=(const EdgeLabel& rhs)
00157     {
00158         if (m_edge) {
00159             OGDF_ASSERT(m_edge == rhs.m_edge);
00160         }
00161         else
00162             m_edge = rhs.m_edge;
00163         if (this != &rhs)
00164         {
00165             m_usedLabels |= rhs.m_usedLabels;
00166             for (int i = 0; i < labelNum; i++)
00167                 if (rhs.m_usedLabels & (1 << i)) {
00168                     m_xPos[i] = rhs.m_xPos[i];
00169                     m_yPos[i] = rhs.m_yPos[i];
00170                     m_xSize[i] = rhs.m_xSize[i];
00171                     m_ySize[i] = rhs.m_ySize[i];
00172                 }
00173         }
00174         return *this;
00175     }
00176 
00177 
00178     //set
00179     void setX(eLabelTyp elt, coordType x) {m_xPos[elt] = x;}
00180     void setY(eLabelTyp elt, coordType y) {m_yPos[elt] = y;}
00181     void setHeight(eLabelTyp elt, coordType h) {m_ySize[elt] = h;}
00182     void setWidth(eLabelTyp elt, coordType w) {m_xSize[elt] = w;}
00183     void setEdge(edge e) {m_edge = e;}
00184     void addType(eLabelTyp elt) { m_usedLabels |= (1<<elt); }
00185 
00186     //get
00187     coordType getX(eLabelTyp elt) {return m_xPos[elt];}
00188     coordType getY(eLabelTyp elt) {return m_yPos[elt];}
00189     coordType getWidth(eLabelTyp elt) {return m_xSize[elt];}
00190     coordType getHeight(eLabelTyp elt) {return m_ySize[elt];}
00191     edge theEdge() {return m_edge;}
00192     bool usedLabel(eLabelTyp elt) 
00193         {return ( ( m_usedLabels & (1<<elt) )>0 );}
00194 
00195     int &usedLabel()
00196     { return m_usedLabels; }
00197 
00198 
00199 
00200 private:
00201      
00202 
00203     //the positions of the labels
00204     coordType m_xPos[labelNum];
00205     coordType m_yPos[labelNum];
00206 
00207     //the input label sizes
00208     coordType m_xSize[labelNum];
00209     coordType m_ySize[labelNum];
00210 
00211     //which labels have to be placed bit pattern 2^labelenumpos bitwise
00212     int m_usedLabels; //1 = only name, 5 = name and end2, ...
00213 
00214     //the edge of heaven
00215     edge m_edge;
00216 
00217     //the label text
00218     //String m_string;
00219 
00220 
00221 };//edgelabel
00222 
00223 
00224 //*********************
00225 //Interface to algorithm
00226 template <class coordType>
00227 class ELabelInterface {
00228 
00229 public:
00230     //constructor
00231     ELabelInterface(PlanRepUML& pru) 
00232     {
00233         //the PRU should not work with real world data but with 
00234         //normalized integer values
00235         m_distDefault = 2; 
00236         m_minFeatDist = 1;
00237         m_labels.init(pru.original());
00238         m_ug = 0;
00239 
00240         //temporary
00241         edge e;
00242         forall_edges(e, pru.original())
00243             setLabel(e, EdgeLabel<coordType>(e, 0));
00244     }
00245     //constructor on GraphAttributes
00246     ELabelInterface(GraphAttributes& uml) : m_ug(&uml)
00247     {
00248         //the GraphAttributes should work on real world data,
00249         //which can be floats or ints
00250         m_distDefault = 0.002; 
00251         m_minFeatDist = 0.003;
00252         m_labels.init(uml.constGraph());
00253 
00254         //temporary
00255         edge e;
00256         forall_edges(e, uml.constGraph())
00257             setLabel(e, EdgeLabel<coordType>(e, 0));
00258     }
00259 
00260     GraphAttributes& graph() {return *m_ug;}
00261 
00262     //set new EdgeLabel 
00263     void setLabel(const edge &e, const EdgeLabel<coordType>& el)
00264         {m_labels[e] = el;}
00265 
00266     void addLabel(const edge &e, const EdgeLabel<coordType>& el)
00267     { m_labels[e] |= el; }
00268 
00269     //get info about current EdgeLabel
00270     EdgeLabel<coordType>& getLabel(edge e) {return m_labels[e];}
00271 
00272     coordType getWidth(edge e, eLabelTyp elt)
00273         {return m_labels[e].getWidth(elt);}
00274     coordType getHeight(edge e, eLabelTyp elt)
00275         {return m_labels[e].getHeight(elt);}
00276 
00277     //get general information
00278     coordType& minFeatDist() {return m_minFeatDist;}
00279     coordType& distDefault() {return m_distDefault;}
00280 
00281 private:
00282 
00283     EdgeArray<EdgeLabel<coordType> > m_labels; //holds all labels for original edges
00284     //the base graph
00285     GraphAttributes* m_ug;
00286 
00287     coordType m_distDefault; //default distance label/edge for positioner
00288     coordType m_minFeatDist; //min Distance label/feature in candidate posit.
00289 };//ELabelInterface
00290 
00291 
00292 }//end namespace
00293 
00294 #endif