Open
Graph Drawing
Framework

 v.2012.05
 

SpringEmbedderFRExact.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  
00042 #ifdef _MSC_VER
00043 #pragma once
00044 #endif
00045 
00046 #ifndef OGDF_SPRING_EMBEDDER_FR_EXACT_H
00047 #define OGDF_SPRING_EMBEDDER_FR_EXACT_H
00048 
00049 
00050 #include <ogdf/module/ForceLayoutModule.h>
00051 #include <ogdf/basic/SList.h>
00052 
00053 
00054 namespace ogdf {
00055 
00056 
00057     class OGDF_EXPORT GraphCopyAttributes;
00058     class OGDF_EXPORT GraphCopy;
00059 
00060 
00061 class OGDF_EXPORT SpringEmbedderFRExact : public ForceLayoutModule
00062 {
00063 public:
00064     enum CoolingFunction { cfFactor, cfLogarithmic };
00065 
00067     SpringEmbedderFRExact();
00068 
00069     // destructor
00070     ~SpringEmbedderFRExact() { }
00071 
00072 
00074     void call(GraphAttributes &GA);
00075 
00076 
00078     int iterations() const {
00079         return m_iterations;
00080     }
00081 
00083     void iterations(int i) {
00084         OGDF_ASSERT(i > 0)
00085         m_iterations = i;
00086     }
00087 
00089     bool noise() const {
00090         return m_noise;
00091     }
00092 
00094     void noise(bool on) {
00095         m_noise = on;
00096     }
00097     
00099     void nodeWeights(bool on) {
00100         m_useNodeWeight = on;
00101     }
00103     CoolingFunction coolingFunction() const {
00104         return m_coolingFunction;
00105     }
00106 
00108     void coolingFunction(CoolingFunction f) {
00109         m_coolingFunction = f;
00110     }
00111     
00113     double idealEdgeLength() const { return m_idealEdgeLength; }
00114 
00116     void idealEdgeLength(double len) { m_idealEdgeLength = len; }
00117 
00119     double minDistCC() const { return m_minDistCC; }
00120 
00122     void minDistCC(double x) { m_minDistCC = x; }
00123 
00125     double pageRatio() { return m_pageRatio; }
00126 
00128     void pageRatio(double x) { m_pageRatio = x; }
00129     
00130     void checkConvergence(bool b) {m_checkConvergence = b;}
00131     bool checkConvergence() {return m_checkConvergence;}
00132 void convTolerance(double tol) {m_convTolerance = tol;}
00133 
00134 private:
00135     class ArrayGraph
00136     {
00137         int m_numNodes;
00138         int m_numEdges;
00139         int m_numCC;
00140 
00141         GraphAttributes *m_ga;
00142         node *m_orig;
00143         Array<SList<node> > m_nodesInCC;
00144         NodeArray<int>      m_mapNode;
00145 
00146     public:
00147         ArrayGraph(GraphAttributes &ga);
00148         ~ArrayGraph();
00149 
00150         void initCC(int i);
00151 
00152         int numberOfCCs() const { return m_numCC; }
00153         int numberOfNodes() const { return m_numNodes; }
00154         int numberOfEdges() const { return m_numEdges; }
00155 
00156         node original(int v) const { return m_orig[v]; }
00157         const SList<node> &nodesInCC(int i) const { return m_nodesInCC[i]; }
00158 
00159         int *m_src;
00160         int *m_tgt;
00161         double *m_x;
00162         double *m_y;
00163         double *m_nodeWeight;
00164         //this should be part of a multilevel layout interface class later on
00165         bool m_useNodeWeight; //should given nodeweights be used or all set to 1.0? 
00166     };
00167 
00168     double log2(double x) { return log(x) / log(2.0); }
00169     double mylog2(int x) {
00170         double l = 0.0;
00171         while(x > 0) {
00172             l++;
00173             x >>= 1;
00174         }
00175         return l/2;
00176     }
00177 
00178     void initialize(ArrayGraph &component);
00179     void mainStep(ArrayGraph &component);
00180     void mainStep_sse3(ArrayGraph &component);
00181 
00182     // Fruchterman, Reingold
00183     //double f_att(double d) { return d*d / m_idealEdgeLength; }
00184     //double f_rep(double d) { return m_idealEdgeLength*m_idealEdgeLength / d; }
00185 
00186     // eades
00187     //double f_att(double d) { return 5.0 * d * log2(d/m_idealEdgeLength); }
00188     //double f_rep(double d) { return 20.0 / d; }
00189 
00190     // cooling function
00191     void cool(double &tx, double &ty, int &cF);
00192 
00193     int    m_iterations; 
00194     bool   m_noise;      
00195     CoolingFunction m_coolingFunction; 
00196 
00197 
00198     //double m_tx;
00199     //double m_ty;
00200 
00201     double m_coolFactor_x;
00202     double m_coolFactor_y;
00203 
00204     double m_idealEdgeLength; 
00205     double m_minDistCC;       
00206     double m_pageRatio;       
00207 
00208     //int m_cF;
00209     double m_txNull;
00210     double m_tyNull;
00211     //see above at ArrayGraph
00212     bool m_useNodeWeight;
00213     bool m_checkConvergence; //<! If set to true, computation is stopped if movement falls below threshold
00214     double m_convTolerance; //<! Fraction of ideal edge length below which convergence is achieved
00215 };
00216 
00217 
00218 } // end namespace ogdf
00219 
00220 
00221 #endif