~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/removeoverlap/generate-constraints.h

  • Committer: tgdwyer
  • Date: 2006-07-12 00:55:58 UTC
  • Revision ID: tgdwyer@users.sourceforge.net-20060712005558-4pqys3ou7f5er3dm
Previously graph layout was done using the Kamada-Kawai layout algorithm 
implemented in Boost.  I am replacing this with a custom implementation of
a constrained stress-majorization algorithm.

The stress-majorization algorithm is more robust and has better convergence
characteristics than Kamada-Kawai, and also simple constraints can be placed
on node position (for example, to enforce downward-pointing edges, non-overlap constraints, or cluster constraints).

Another big advantage is that we no longer need Boost.

I've tested the basic functionality, but I have yet to properly handle
disconnected graphs or to properly scale the resulting layout.

This commit also includes significant refactoring... the quadratic program solver - libvpsc (Variable Placement with Separation Constraints) has been moved to src/libvpsc and the actual graph layout algorithm is in libcola.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * \brief Functions to automatically generate constraints for the
3
 
 * rectangular node overlap removal problem.
4
 
 *
5
 
 * Authors:
6
 
 *   Tim Dwyer <tgdwyer@gmail.com>
7
 
 *
8
 
 * Copyright (C) 2005 Authors
9
 
 *
10
 
 * Released under GNU LGPL.  Read the file 'COPYING' for more information.
11
 
 */
12
 
#ifndef SEEN_REMOVEOVERLAP_GENERATE_CONSTRAINTS_H
13
 
#define SEEN_REMOVEOVERLAP_GENERATE_CONSTRAINTS_H
14
 
#include <iostream>
15
 
 
16
 
class Rectangle {       
17
 
        friend std::ostream& operator <<(std::ostream &os, const Rectangle &r);
18
 
public:
19
 
        static double xBorder,yBorder;
20
 
        Rectangle(double x, double X, double y, double Y);
21
 
        double getMaxX() const { return maxX+xBorder; }
22
 
        double getMaxY() const { return maxY+yBorder; }
23
 
        double getMinX() const { return minX; }
24
 
        double getMinY() const { return minY; }
25
 
        double getMinD(unsigned const d) const {
26
 
                return ( d == 0 ? getMinX() : getMinY() );
27
 
        }
28
 
        double getMaxD(unsigned const d) const {
29
 
                return ( d == 0 ? getMaxX() : getMaxY() );
30
 
        }
31
 
        double getCentreX() const { return minX+width()/2.0; }
32
 
        double getCentreY() const { return minY+height()/2.0; }
33
 
        double width() const { return getMaxX()-minX; }
34
 
        double height() const { return getMaxY()-minY; }
35
 
        static void setXBorder(double x) {xBorder=x;}
36
 
        static void setYBorder(double y) {yBorder=y;}
37
 
        void moveCentreX(double x) {
38
 
                moveMinX(x-width()/2.0);
39
 
        }
40
 
        void moveCentreY(double y) {
41
 
                moveMinY(y-height()/2.0);
42
 
        }
43
 
        void moveMinX(double x) {
44
 
                maxX=x+width()-xBorder;
45
 
                minX=x;
46
 
        }
47
 
        void moveMinY(double y) {
48
 
                maxY=y+height()-yBorder;
49
 
                minY=y;
50
 
        }
51
 
        inline double overlapX(Rectangle *r) const {
52
 
                if (getCentreX() <= r->getCentreX() && r->minX < getMaxX())
53
 
                        return getMaxX() - r->minX;
54
 
                if (r->getCentreX() <= getCentreX() && minX < r->getMaxX())
55
 
                        return r->getMaxX() - minX;
56
 
                return 0;
57
 
        }
58
 
        inline double overlapY(Rectangle *r) const {
59
 
                if (getCentreY() <= r->getCentreY() && r->minY < getMaxY())
60
 
                        return getMaxY() - r->minY;
61
 
                if (r->getCentreY() <= getCentreY() && minY < r->getMaxY())
62
 
                        return r->getMaxY() - minY;
63
 
                return 0;
64
 
        }
65
 
private:
66
 
        double minX,maxX,minY,maxY;
67
 
};
68
 
 
69
 
 
70
 
class Variable;
71
 
class Constraint;
72
 
 
73
 
// returns number of constraints generated
74
 
int generateXConstraints(const int n, Rectangle** rs, Variable** vars, Constraint** &cs, const bool useNeighbourLists);
75
 
int generateYConstraints(const int n, Rectangle** rs, Variable** vars, Constraint** &cs);
76
 
 
77
 
 
78
 
#endif // SEEN_REMOVEOVERLAP_GENERATE_CONSTRAINTS_H