blocks.cpp revision 6b15695578f07a3f72c4c9475c1a261a3021472a
/**
* \brief A block structure defined over the variables
*
* A block structure defined over the variables such that each block contains
* 1 or more variables, with the invariant that all constraints inside a block
* are satisfied by keeping the variables fixed relative to one another
*
* Authors:
* Tim Dwyer <tgdwyer@gmail.com>
*
* Copyright (C) 2005 Authors
*
* Released under GNU GPL. Read the file 'COPYING' for more information.
*/
#include "blocks.h"
#include "block.h"
#include "constraint.h"
#ifdef RECTANGLE_OVERLAP_LOGGING
#endif
long blockTimeCtr;
blockTimeCtr=0;
for(int i=0;i<nvs;i++) {
}
}
{
delete *i;
}
clear();
}
/**
* returns a list of variables with total ordering determined by the constraint
* DAG
*/
for(int i=0;i<nvs;i++) {
}
for(int i=0;i<nvs;i++) {
}
}
return order;
}
// Recursive depth first search giving total order by pushing nodes in the DAG
// onto the front of the list when we finish searching them
v->visited=true;
Constraint *c=*it;
}
}
order->push_front(v);
}
/**
* Processes incoming constraints, most violated to least, merging with the
* neighbouring (left) block until no more violated constraints are found
*/
#ifdef RECTANGLE_OVERLAP_LOGGING
f<<"mergeLeft called on "<<*r<<endl;
#endif
r->timeStamp=++blockTimeCtr;
r->setUpInConstraints();
Constraint *c=r->findMinInConstraint();
#ifdef RECTANGLE_OVERLAP_LOGGING
f<<"mergeLeft on constraint: "<<*c<<endl;
#endif
r->deleteMinInConstraint();
}
r->mergeIn(l);
r->timeStamp=++blockTimeCtr;
removeBlock(l);
c=r->findMinInConstraint();
}
#ifdef RECTANGLE_OVERLAP_LOGGING
f<<"merged "<<*r<<endl;
#endif
}
/**
* Symmetrical to mergeLeft
*/
#ifdef RECTANGLE_OVERLAP_LOGGING
f<<"mergeRight called on "<<*l<<endl;
#endif
l->setUpOutConstraints();
Constraint *c = l->findMinOutConstraint();
#ifdef RECTANGLE_OVERLAP_LOGGING
f<<"mergeRight on constraint: "<<*c<<endl;
#endif
l->deleteMinOutConstraint();
r->setUpOutConstraints();
}
l->mergeOut(r);
removeBlock(r);
c=l->findMinOutConstraint();
}
#ifdef RECTANGLE_OVERLAP_LOGGING
f<<"merged "<<*l<<endl;
#endif
}
//erase(doomed);
}
Block *b=*i;
if(b->deleted) {
erase(b);
delete b;
}
}
}
/**
* Splits block b across constraint c into two new blocks, l and r (c's left
* and right sides respectively)
*/
b->split(l,r,c);
#ifdef RECTANGLE_OVERLAP_LOGGING
f<<"Split left: "<<*l<<endl;
f<<"Split right: "<<*r<<endl;
#endif
mergeLeft(l);
// r may have been merged!
r->wposn = r->desiredWeightedPosition();
mergeRight(r);
removeBlock(b);
insert(l);
insert(r);
}
/**
* returns the cost total squared distance of variables from their desired
* positions
*/
double c = 0;
c += (*i)->cost();
}
return c;
}