6 * $Date: 2012-07-02 20:59:27 +0200 (Mon, 02 Jul 2012) $
7 ***************************************************************/
10 * \brief Declaration of Spring-Embedder (Fruchterman,Reingold)
13 * \author Carsten Gutwenger
16 * This file is part of the Open Graph Drawing Framework (OGDF).
20 * See README.txt in the root directory of the OGDF installation for details.
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
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.
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 ***************************************************************/
49 #ifndef OGDF_SPRING_EMBEDDER_FR_H
50 #define OGDF_SPRING_EMBEDDER_FR_H
53 #include <ogdf/module/LayoutModule.h>
54 #include <ogdf/basic/Array2D.h>
60 class OGDF_EXPORT GraphCopyAttributes
;
61 class OGDF_EXPORT GraphCopy
;
64 //! The spring-embedder layout algorithm by Fruchterman and Reingold.
66 * The implementation used in SpringEmbedderFR is based on
67 * the following publication:
69 * Thomas M. J. Fruchterman, Edward M. Reingold: <i>%Graph Drawing by Force-directed
70 * Placement</i>. Software - Practice and Experience 21(11), pp. 1129-1164, 1991.
72 * <H3>Optional parameters</H3>
73 * Fruchterman/Reingold layout provides the following optional parameters.
77 * <th><i>Option</i><th><i>Type</i><th><i>Default</i><th><i>Description</i>
79 * <td><i>iterations</i><td>int<td>400
80 * <td>The number of iterations performed in the optimization.
82 * <td><i>noise</i><td>bool<td>true
83 * <td>If set to true, (small) random perturbations are performed.
85 * <td><i>minDistCC</i><td>double<td>20.0
86 * <td>The minimum distance between connected components.
88 * <td><i>pageRatio</i><td>double<td>1.0
91 * <td><i>scaling</i><td> #Scaling <td> #scScaleFunction
92 * <td>The scaling method for scaling the inital layout.
94 * <td><i>scaleFunctionFactor</i><td>double<td>8.0
95 * <td>The scale function factor (used if scaling = scScaleFunction).
97 * <td><i>userBoundingBox</i><td>rectangle<td>(0.0,100.0,0.0,100.0)
98 * <td>The user bounding box for scaling (used if scaling = scUserBoundingBox).
102 class OGDF_EXPORT SpringEmbedderFR
: public LayoutModule
105 //! The scaling method used by the algorithm.
107 scInput
, //!< bounding box of input is used.
108 scUserBoundingBox
, //!< bounding box set by userBoundingBox() is used.
109 scScaleFunction
//!< automatic scaling is used with parameter set by scaleFunctionFactor() (larger factor, larger b-box).
113 //! Creates an instance of Fruchterman/Reingold layout.
117 ~SpringEmbedderFR() { }
120 //! Calls the layout algorithm for graph attributes \a GA.
121 void call(GraphAttributes
&GA
);
124 //! Returns the current setting of iterations.
125 int iterations() const {
129 //! Sets the number of iterations to \a i.
130 void iterations(int i
) {
135 double fineness() const {
139 void fineness(double f
) {
143 //! Returns the current setting of nodes.
148 //! Sets the parameter noise to \a on.
149 void noise(bool on
) {
153 //! Returns the minimum distance between connected components.
154 double minDistCC() const { return m_minDistCC
; }
156 //! Sets the minimum distance between connected components to \a x.
157 void minDistCC(double x
) { m_minDistCC
= x
; }
159 //! Returns the page ratio.
160 double pageRatio() { return m_pageRatio
; }
162 //! Sets the page ration to \a x.
163 void pageRatio(double x
) { m_pageRatio
= x
; }
165 //! Returns the current scaling method.
166 Scaling
scaling() const {
170 //! Sets the method for scaling the inital layout to \a sc.
171 void scaling(Scaling sc
) {
175 //! Returns the current scale function factor.
176 double scaleFunctionFactor() const {
177 return m_scaleFactor
;
180 //! Sets the scale function factor to \a f.
181 void scaleFunctionFactor(double f
) {
185 //! Sets the user bounding box (used if scaling method is scUserBoundingBox).
186 void userBoundingBox(double xmin
, double ymin
, double xmax
, double ymax
) {
194 bool initialize(GraphCopy
&G
, GraphCopyAttributes
&AG
);
196 void mainStep(GraphCopy
&G
, GraphCopyAttributes
&AG
);
202 NodeArray
<ListIterator
<node
> > m_lit
;
222 Array2D
<List
<node
> > *m_A
;
225 double mylog2(int x
) {
234 int m_iterations
; //!< The number of iterations.
235 double m_fineness
; //!< The fineness of the grid.
238 double m_xleft
; //!< Bounding box (minimal x-coordinate).
239 double m_xright
; //!< Bounding box (maximal x-coordinate).
240 double m_ysmall
; //!< Bounding box (minimal y-coordinate).
241 double m_ybig
; //!< Bounding box (maximal y-coordinate).
243 bool m_noise
; //!< Perform random perturbations?
245 Scaling m_scaling
; //!< The scaling method.
246 double m_scaleFactor
; //!< The factor used if scaling type is scScaleFunction.
248 double m_bbXmin
; //!< User bounding box (minimal x-coordinate).
249 double m_bbYmin
; //!< User bounding box (maximal x-coordinate).
250 double m_bbXmax
; //!< User bounding box (minimal y-coordinate).
251 double m_bbYmax
; //!< User bounding box (maximal y-coordinate).
253 double m_minDistCC
; //!< The minimal distance between connected components.
254 double m_pageRatio
; //!< The page ratio.
258 } // end namespace ogdf