Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
containment.cpp
Go to the documentation of this file.
1/*
2 * vim: ts=4 sw=4 et tw=0 wm=0
3 *
4 * libcola - A library providing force-directed network layout using the
5 * stress-majorization method subject to separation constraints.
6 *
7 * Copyright (C) 2006-2008 Monash University
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library in the file LICENSE; if not,
21 * write to the Free Software Foundation, Inc., 59 Temple Place,
22 * Suite 330, Boston, MA 02111-1307 USA
23 *
24*/
25
33#include <iostream>
34
35#include <map>
36#include <vector>
37#include <algorithm>
38#include <float.h>
39#include <iomanip>
40#include <libcola/cola.h>
41#include <libcola/output_svg.h>
42#include "graphlayouttest.h"
43
44using namespace cola;
45using namespace std;
46
47vector<vpsc::Rectangle*> rs;
48vector<Edge> es;
51unsigned iteration=0;
52
53int main() {
54
55 const unsigned V = 5;
56 typedef pair < unsigned, unsigned >Edge;
57 Edge edge_array[] = { Edge(0, 1), Edge(1, 2), Edge(2, 3), Edge(3, 4) };
58 const std::size_t E = sizeof(edge_array) / sizeof(Edge);
59 es.resize(E);
60 copy(edge_array,edge_array+E,es.begin());
61 double width=100;
62 double height=100;
63 for(unsigned i=0;i<V;i++) {
64 double x=getRand(width), y=getRand(height);
65 rs.push_back(new vpsc::Rectangle(x,x+20,y,y+15));
66 }
67
68 const unsigned c[]={0,4}, d[]={1,2,3};
69 unsigned nc=sizeof(c)/sizeof(unsigned), nd=sizeof(d)/sizeof(unsigned);
70 CheckProgress test(0.0001,100);
72 alg.setScaling(true);
73 rc.nodes.resize(nc);
74 copy(c,c+nc,rc.nodes.begin());
75 rd.nodes.resize(nd);
76 copy(d,d+nd,rd.nodes.begin());
77 root.clusters.push_back(&rc);
78 root.clusters.push_back(&rd);
79 alg.run();
80 alg.setAvoidOverlaps();
81 alg.run();
82 OutputFile of(rs,es,&root,"containment.svg",false,true);
83 of.generate();
84 for(unsigned i=0;i<V;i++) {
85 delete rs[i];
86 }
87 return 0;
88}
89// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4:textwidth=99 :
int test()
Definition 2junctions.cpp:5
void generate()
std::vector< Cluster * > clusters
Definition cluster.h:116
std::set< unsigned > nodes
Definition cluster.h:115
Implements the Constrained Majorization graph layout algorithm (deprecated).
Definition cola.h:270
void setAvoidOverlaps(bool horizontal=false)
At each iteration of layout, generate constraints to avoid overlaps.
Definition cola.h:368
void setScaling(bool scaling)
Scaling speeds up the solver by conditioning the quadratic terms matrix.
Definition cola.h:352
void run(bool x=true, bool y=true)
Implements the main layout loop, taking descent steps until stress is no-longer significantly reduced...
Definition cola.cpp:319
Defines a rectangular cluster, either variable-sized with floating sides or a fixed size based on a p...
Definition cluster.h:219
Holds the cluster hierarchy specification for a diagram.
Definition cluster.h:173
A rectangle represents a fixed-size shape in the diagram that may be moved to prevent overlaps and sa...
Definition rectangle.h:78
double getRand(double range)
vector< Edge > es
vector< vpsc::Rectangle * > rs
RectangularCluster rd
RootCluster root
RectangularCluster rc
unsigned iteration
int main()
double c[8][4]
libcola: Force-directed network layout subject to separation constraints library.
Definition box.cpp:25
std::pair< unsigned, unsigned > Edge
Edges are simply a pair of indices to entries in the Node vector.
Definition cola.h:68
STL namespace.
double height
double width