#ifndef COLA_H #define COLA_H #include #include #include #include #include #include #include #include "gradient_projection.h" #include "straightener.h" typedef vector Cluster; typedef vector Clusters; namespace vpsc { class Rectangle; } namespace cola { using vpsc::Rectangle; typedef pair Edge; // 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 class Component { public: vector node_ids; vector rects; vector edges; SimpleConstraints scx, scy; virtual ~Component(); void moveRectangles(double x, double y); Rectangle* getBoundingBox(); }; // for a graph of n nodes, return connected components void connectedComponents( const vector &rs, const vector &es, const SimpleConstraints &scx, const SimpleConstraints &scy, vector &components); // move the contents of each component so that the components do not // overlap. void separateComponents(const vector &components); // 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 frac_ub, double frac_bv, double* X, double* Y) : u(u),v(v),b(b),w(w),frac_ub(frac_ub),frac_bv(frac_bv), tAtProjection(true) { assert(frac_ub<=1.0); assert(frac_bv<=1.0); assert(frac_ub>=0); assert(frac_bv>=0); if(tAtProjection) { double uvx = X[v] - X[u], uvy = Y[v] - Y[u], vbx = X[b] - X[u], vby = Y[b] - Y[u]; t = uvx * vbx + uvy * vby; t/= uvx * uvx + uvy * uvy; // 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(fabs(denominator)<0.001) { // if line is close to vertical then use Y coords to compute T numerator=Y[b]-Y[u]; denominator=Y[v]-Y[u]; } if(fabs(denominator)<0.0001) { denominator=1; } t=numerator/denominator; } duu=(1-t)*(1-t); 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; }; typedef vector LinearConstraints; class TestConvergence { public: double old_stress; TestConvergence(const double& tolerance = 0.001, const unsigned maxiterations = 1000) : tolerance(tolerance), maxiterations(maxiterations) { reset(); } virtual ~TestConvergence() {} virtual bool operator()(double new_stress, double* X, double* Y) { //std::cout<<"iteration="<