cola.h revision aaacc83e3fab3c943e5d3b59646109b6b92c08dd
#ifndef COLA_H
#define COLA_H
#include <utility>
#include <iterator>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cassert>
#include "gradient_projection.h"
#include "straightener.h"
// a graph component with a list of node_ids giving indices for some larger list of nodes
// for the nodes in this component, and a list of edges - node indices relative to this component
~Component();
void moveRectangles(double x, double y);
};
// for a graph of n nodes, return connected components
void connectedComponents(
const SimpleConstraints &scx,
const SimpleConstraints &scy,
// move the contents of each component so that the components do not
// overlap.
// defines references to three variables for which the goal function
// will be altered to prefer points u-b-v are in a linear arrangement
// such that b is placed at u+t(v-u).
struct LinearConstraint {
LinearConstraint(unsigned u, unsigned v, unsigned b, double w,
double* X, double* Y)
tAtProjection(true)
{
if(tAtProjection) {
double uvx = X[v] - X[u],
uvy = Y[v] - Y[u],
vbx = X[b] - X[u],
vby = Y[b] - Y[u];
// p is the projection point of b on line uv
//double px = scalarProj * uvx + X[u];
//double py = scalarProj * uvy + Y[u];
// take t=|up|/|uv|
} else {
double numerator=X[b]-X[u];
double denominator=X[v]-X[u];
// if line is close to vertical then use Y coords to compute T
numerator=Y[b]-Y[u];
denominator=Y[v]-Y[u];
}
denominator=1;
}
}
duv=t*(1-t);
dub=t-1;
dvv=t*t;
dvb=-t;
dbb=1;
//printf("New LC: t=%f\n",t);
}
unsigned u;
unsigned v;
unsigned b;
double w; // weight
double t;
// 2nd partial derivatives of the goal function
// (X[b] - (1-t) X[u] - t X[v])^2
double duu;
double duv;
double dub;
double dvv;
double dvb;
double dbb;
// Length of each segment as a fraction of the total edge length
double frac_ub;
double frac_bv;
bool tAtProjection;
};
double old_stress;
virtual ~TestConvergence() {}
//std::cout<<"iteration="<<iterations<<", new_stress="<<new_stress<<std::endl;
if (old_stress == DBL_MAX) {
if(++iterations>=maxiterations) {;
return true;
} else {
return false;
}
}
bool converged =
|| ++iterations > maxiterations;
return converged;
}
void reset() {
iterations = 0;
}
const double tolerance;
const unsigned maxiterations;
unsigned iterations;
};
double* eweights,
double idealLength,
void moveBoundingBoxes() {
for(unsigned i=0;i<lapSize;i++) {
boundingBoxes[i]->moveCentreX(X[i]);
boundingBoxes[i]->moveCentreY(Y[i]);
}
}
void setupConstraints(
bool avoidOverlaps,
void setupDummyVars();
if(boundingBoxes) {
delete [] boundingBoxes;
}
if(constrainedLayout) {
}
for(unsigned i=0;i<lapSize;i++) {
}
delete [] X;
delete [] Y;
}
bool run();
bool avoidOverlaps;
bool constrainedLayout;
double euclidean_distance(unsigned i, unsigned j) {
return sqrt(
(X[i] - X[j]) * (X[i] - X[j]) +
(Y[i] - Y[j]) * (Y[i] - Y[j]));
}
double compute_stress(double **Dij);
double* b);
unsigned n; // is lapSize + dummyVars
unsigned lapSize; // lapSize is the number of variables for actual nodes
double** lap2; // graph laplacian
double** Q; // quadratic terms matrix used in computations
double** Dij;
double tol;
double *X, *Y;
double edge_length;
};
}
#endif // COLA_H
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4