summaryrefslogtreecommitdiffstats
path: root/src/libcola
diff options
context:
space:
mode:
authorTim Dwyer <tgdwyer@gmail.com>2006-07-14 04:09:40 +0000
committertgdwyer <tgdwyer@users.sourceforge.net>2006-07-14 04:09:40 +0000
commitd18b8150ba16f4a930b213dae1f4fb369cb3d0bf (patch)
tree72afddfbcafd6b51e6797a7674c963886cce75b0 /src/libcola
parent* src/libavoid/router.cpp: Fixed a bug in the libavoid function (diff)
downloadinkscape-d18b8150ba16f4a930b213dae1f4fb369cb3d0bf.tar.gz
inkscape-d18b8150ba16f4a930b213dae1f4fb369cb3d0bf.zip
- Connectors with end-markers now constrained to point downwards in graph layout
- vpsc namespace added to libvpsc (bzr r1408)
Diffstat (limited to 'src/libcola')
-rw-r--r--src/libcola/cola.cpp2
-rw-r--r--src/libcola/cola.h6
-rw-r--r--src/libcola/gradient_projection.cpp31
-rw-r--r--src/libcola/gradient_projection.h48
-rw-r--r--src/libcola/straightener.h2
5 files changed, 45 insertions, 44 deletions
diff --git a/src/libcola/cola.cpp b/src/libcola/cola.cpp
index 74663f501..3499d729a 100644
--- a/src/libcola/cola.cpp
+++ b/src/libcola/cola.cpp
@@ -253,7 +253,7 @@ void ConstrainedMajorizationLayout::straighten(vector<straightener::Edge*>& sedg
}
}
GradientProjection gp(dim,n,Q,coords,tol,100,
- (AlignmentConstraints*)NULL,false,(Rectangle**)NULL,(PageBoundaryConstraints*)NULL,&cs);
+ (AlignmentConstraints*)NULL,false,(vpsc::Rectangle**)NULL,(PageBoundaryConstraints*)NULL,&cs);
constrainedLayout = true;
majlayout(Dij,&gp,coords,b);
for(unsigned i=0;i<sedges.size();i++) {
diff --git a/src/libcola/cola.h b/src/libcola/cola.h
index d4b0d1421..cc99515bf 100644
--- a/src/libcola/cola.h
+++ b/src/libcola/cola.h
@@ -121,7 +121,7 @@ namespace cola {
class ConstrainedMajorizationLayout {
public:
ConstrainedMajorizationLayout(
- vector<Rectangle*>& rs,
+ vector<vpsc::Rectangle*>& rs,
vector<Edge>& es,
double* eweights,
double idealLength,
@@ -141,7 +141,7 @@ namespace cola {
straightenEdges(NULL)
{
assert(rs.size()==n);
- boundingBoxes = new Rectangle*[rs.size()];
+ boundingBoxes = new vpsc::Rectangle*[rs.size()];
copy(rs.begin(),rs.end(),boundingBoxes);
double** D=new double*[n];
@@ -229,7 +229,7 @@ namespace cola {
double** Dij;
double tol;
TestConvergence& done;
- Rectangle** boundingBoxes;
+ vpsc::Rectangle** boundingBoxes;
double *X, *Y;
Clusters* clusters;
double edge_length;
diff --git a/src/libcola/gradient_projection.cpp b/src/libcola/gradient_projection.cpp
index 061ba0f1a..cec59c57a 100644
--- a/src/libcola/gradient_projection.cpp
+++ b/src/libcola/gradient_projection.cpp
@@ -19,12 +19,13 @@
#include <iostream>
using namespace std;
+using namespace vpsc;
//#define CONMAJ_LOGGING 1
-static void dumpVPSCException(char const *str, IncVPSC* vpsc) {
+static void dumpVPSCException(char const *str, IncSolver* solver) {
cerr<<str<<endl;
unsigned m;
- Constraint** cs = vpsc->getConstraints(m);
+ Constraint** cs = solver->getConstraints(m);
for(unsigned i=0;i<m;i++) {
cerr << *cs[i] << endl;
}
@@ -41,9 +42,9 @@ unsigned GradientProjection::solve(double * b) {
bool converged=false;
- IncVPSC* vpsc=NULL;
+ IncSolver* solver=NULL;
- vpsc = setupVPSC();
+ solver = setupVPSC();
//cerr << "in gradient projection: n=" << n << endl;
for (i=0;i<n;i++) {
assert(!isnan(place[i]));
@@ -51,9 +52,9 @@ unsigned GradientProjection::solve(double * b) {
vars[i]->desiredPosition=place[i];
}
try {
- vpsc->satisfy();
+ solver->satisfy();
} catch (char const *str) {
- dumpVPSCException(str,vpsc);
+ dumpVPSCException(str,solver);
}
for (i=0;i<n;i++) {
@@ -104,9 +105,9 @@ unsigned GradientProjection::solve(double * b) {
//project to constraint boundary
try {
- vpsc->satisfy();
+ solver->satisfy();
} catch (char const *str) {
- dumpVPSCException(str,vpsc);
+ dumpVPSCException(str,solver);
}
for (i=0;i<n;i++) {
place[i]=vars[i]->position();
@@ -155,7 +156,7 @@ unsigned GradientProjection::solve(double * b) {
converged=false;
}
}
- destroyVPSC(vpsc);
+ destroyVPSC(solver);
return counter;
}
// Setup an instance of the Variable Placement with Separation Constraints
@@ -164,7 +165,7 @@ unsigned GradientProjection::solve(double * b) {
// --- that are only relevant to one iteration, and merge these with the
// global constraint list (including alignment constraints,
// dir-edge constraints, containment constraints, etc).
-IncVPSC* GradientProjection::setupVPSC() {
+IncSolver* GradientProjection::setupVPSC() {
Constraint **cs;
//assert(lcs.size()==0);
@@ -192,13 +193,13 @@ IncVPSC* GradientProjection::setupVPSC() {
}
cs = new Constraint*[lcs.size() + gcs.size()];
unsigned m = 0 ;
- for(Constraints::iterator ci = lcs.begin();ci!=lcs.end();++ci) {
+ for(vector<Constraint*>::iterator ci = lcs.begin();ci!=lcs.end();++ci) {
cs[m++] = *ci;
}
- for(Constraints::iterator ci = gcs.begin();ci!=gcs.end();++ci) {
+ for(vector<Constraint*>::iterator ci = gcs.begin();ci!=gcs.end();++ci) {
cs[m++] = *ci;
}
- return new IncVPSC(vars.size(),vs,m,cs);
+ return new IncSolver(vars.size(),vs,m,cs);
}
void GradientProjection::clearDummyVars() {
for(DummyVars::iterator i=dummy_vars.begin();i!=dummy_vars.end();++i) {
@@ -206,7 +207,7 @@ void GradientProjection::clearDummyVars() {
}
dummy_vars.clear();
}
-void GradientProjection::destroyVPSC(IncVPSC *vpsc) {
+void GradientProjection::destroyVPSC(IncSolver *vpsc) {
if(acs) {
for(AlignmentConstraints::iterator ac=acs->begin(); ac!=acs->end();++ac) {
(*ac)->updatePosition();
@@ -218,7 +219,7 @@ void GradientProjection::destroyVPSC(IncVPSC *vpsc) {
delete vpsc;
delete [] cs;
delete [] vs;
- for(Constraints::iterator i=lcs.begin();i!=lcs.end();i++) {
+ for(vector<Constraint*>::iterator i=lcs.begin();i!=lcs.end();i++) {
delete *i;
}
lcs.clear();
diff --git a/src/libcola/gradient_projection.h b/src/libcola/gradient_projection.h
index e8b72180b..9ee3ff5c5 100644
--- a/src/libcola/gradient_projection.h
+++ b/src/libcola/gradient_projection.h
@@ -11,8 +11,8 @@
using namespace std;
-typedef vector<Constraint*> Constraints;
-typedef vector<Variable*> Variables;
+typedef vector<vpsc::Constraint*> Constraints;
+typedef vector<vpsc::Variable*> Variables;
typedef vector<pair<unsigned,double> > OffsetList;
class SimpleConstraint {
@@ -35,7 +35,7 @@ public:
void* guide;
double position;
private:
- Variable* variable;
+ vpsc::Variable* variable;
};
typedef vector<AlignmentConstraint*> AlignmentConstraints;
@@ -44,16 +44,16 @@ public:
PageBoundaryConstraints(double lm, double rm, double w)
: leftMargin(lm), rightMargin(rm), weight(w) { }
void createVarsAndConstraints(Variables &vs, Constraints &cs) {
- Variable* vl, * vr;
+ vpsc::Variable* vl, * vr;
// create 2 dummy vars, based on the dimension we are in
- vs.push_back(vl=new Variable(vs.size(), leftMargin, weight));
- vs.push_back(vr=new Variable(vs.size(), rightMargin, weight));
+ vs.push_back(vl=new vpsc::Variable(vs.size(), leftMargin, weight));
+ vs.push_back(vr=new vpsc::Variable(vs.size(), rightMargin, weight));
// for each of the "real" variables, create a constraint that puts that var
// between our two new dummy vars, depending on the dimension.
for(OffsetList::iterator o=offsets.begin(); o!=offsets.end(); ++o) {
- cs.push_back(new Constraint(vl, vs[o->first], o->second));
- cs.push_back(new Constraint(vs[o->first], vr, o->second));
+ cs.push_back(new vpsc::Constraint(vl, vs[o->first], o->second));
+ cs.push_back(new vpsc::Constraint(vs[o->first], vr, o->second));
}
}
OffsetList offsets;
@@ -99,19 +99,19 @@ friend class GradientProjection;
*/
void setupVPSC(Variables &vars, Constraints &cs) {
double weight=1;
- left = new Variable(vars.size(),place_l,weight);
+ left = new vpsc::Variable(vars.size(),place_l,weight);
vars.push_back(left);
- right = new Variable(vars.size(),place_r,weight);
+ right = new vpsc::Variable(vars.size(),place_r,weight);
vars.push_back(right);
for(CList::iterator cit=leftof.begin();
cit!=leftof.end(); ++cit) {
- Variable* v = vars[(*cit).first];
- cs.push_back(new Constraint(left,v,(*cit).second));
+ vpsc::Variable* v = vars[(*cit).first];
+ cs.push_back(new vpsc::Constraint(left,v,(*cit).second));
}
for(CList::iterator cit=rightof.begin();
cit!=rightof.end(); ++cit) {
- Variable* v = vars[(*cit).first];
- cs.push_back(new Constraint(v,right,(*cit).second));
+ vpsc::Variable* v = vars[(*cit).first];
+ cs.push_back(new vpsc::Constraint(v,right,(*cit).second));
}
}
/**
@@ -163,8 +163,8 @@ friend class GradientProjection;
}
double dist; // ideal distance between vars
double b; // linear coefficient in quad form for left (b_right = -b)
- Variable* left; // Variables used in constraints
- Variable* right;
+ vpsc::Variable* left; // Variables used in constraints
+ vpsc::Variable* right;
double lap2; // laplacian entry
double g; // descent vec for quad form for left (g_right = -g)
double old_place_l; // old_place is where the descent vec g was computed
@@ -185,7 +185,7 @@ public:
unsigned max_iterations,
AlignmentConstraints* acs=NULL,
bool nonOverlapConstraints=false,
- Rectangle** rs=NULL,
+ vpsc::Rectangle** rs=NULL,
PageBoundaryConstraints *pbc = NULL,
SimpleConstraints *sc = NULL)
: k(k), n(n), A(A), place(x), rs(rs),
@@ -195,18 +195,18 @@ public:
constrained(false)
{
for(unsigned i=0;i<n;i++) {
- vars.push_back(new Variable(i,1,1));
+ vars.push_back(new vpsc::Variable(i,1,1));
}
if(acs) {
for(AlignmentConstraints::iterator iac=acs->begin();
iac!=acs->end();++iac) {
AlignmentConstraint* ac=*iac;
- Variable *v=ac->variable=new Variable(vars.size(),ac->position,0.0001);
+ vpsc::Variable *v=ac->variable=new vpsc::Variable(vars.size(),ac->position,0.0001);
vars.push_back(v);
for(OffsetList::iterator o=ac->offsets.begin();
o!=ac->offsets.end();
o++) {
- gcs.push_back(new Constraint(v,vars[o->first],o->second,true));
+ gcs.push_back(new vpsc::Constraint(v,vars[o->first],o->second,true));
}
}
}
@@ -215,7 +215,7 @@ public:
}
if (sc) {
for(SimpleConstraints::iterator c=sc->begin(); c!=sc->end();++c) {
- gcs.push_back(new Constraint(
+ gcs.push_back(new vpsc::Constraint(
vars[(*c)->left],vars[(*c)->right],(*c)->gap));
}
}
@@ -239,8 +239,8 @@ public:
unsigned solve(double* b);
DummyVars dummy_vars; // special vars that must be considered in Lapl.
private:
- IncVPSC* setupVPSC();
- void destroyVPSC(IncVPSC *vpsc);
+ vpsc::IncSolver* setupVPSC();
+ void destroyVPSC(vpsc::IncSolver *vpsc);
Dim k;
unsigned n; // number of actual vars
double** A; // Graph laplacian matrix
@@ -250,7 +250,7 @@ private:
Constraints gcs; /* global constraints - persist throughout all
iterations */
Constraints lcs; /* local constraints - only for current iteration */
- Rectangle** rs;
+ vpsc::Rectangle** rs;
bool nonOverlapConstraints;
double tolerance;
AlignmentConstraints* acs;
diff --git a/src/libcola/straightener.h b/src/libcola/straightener.h
index 33af0c697..e2c50a3a6 100644
--- a/src/libcola/straightener.h
+++ b/src/libcola/straightener.h
@@ -97,7 +97,7 @@ namespace straightener {
bool dummy;
double weight;
bool open;
- Node(unsigned id, Rectangle* r) :
+ Node(unsigned id, vpsc::Rectangle* r) :
id(id),x(r->getCentreX()),y(r->getCentreY()), width(r->width()), height(r->height()),
xmin(x-width/2),xmax(x+width/2),
ymin(y-height/2),ymax(y+height/2),