index 061ba0f1a10b6176bea1be7abaddcfc5bfe77f2f..78b141b3e788ffb003cb01e3894df288da984cc6 100644 (file)
#include <libvpsc/constraint.h>
#include "gradient_projection.h"
#include <iostream>
#include <libvpsc/constraint.h>
#include "gradient_projection.h"
#include <iostream>
+#include "isnan.h"
+#include "isinf.h"
+
using namespace std;
using namespace std;
+using namespace vpsc;
//#define CONMAJ_LOGGING 1
//#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;
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;
}
for(unsigned i=0;i<m;i++) {
cerr << *cs[i] << endl;
}
bool converged=false;
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++) {
//cerr << "in gradient projection: n=" << n << endl;
for (i=0;i<n;i++) {
- assert(!isnan(place[i]));
+ assert(!isNaN(place[i]));
assert(!isinf(place[i]));
vars[i]->desiredPosition=place[i];
}
try {
assert(!isinf(place[i]));
vars[i]->desiredPosition=place[i];
}
try {
- vpsc->satisfy();
+ solver->satisfy();
} catch (char const *str) {
} catch (char const *str) {
- dumpVPSCException(str,vpsc);
+ dumpVPSCException(str,solver);
}
for (i=0;i<n;i++) {
}
for (i=0;i<n;i++) {
// move to new unconstrained position
for (i=0; i<n; i++) {
place[i]-=alpha*g[i];
// move to new unconstrained position
for (i=0; i<n; i++) {
place[i]-=alpha*g[i];
- assert(!isnan(place[i]));
+ assert(!isNaN(place[i]));
assert(!isinf(place[i]));
vars[i]->desiredPosition=place[i];
}
assert(!isinf(place[i]));
vars[i]->desiredPosition=place[i];
}
//project to constraint boundary
try {
//project to constraint boundary
try {
- vpsc->satisfy();
+ solver->satisfy();
} catch (char const *str) {
} catch (char const *str) {
- dumpVPSCException(str,vpsc);
+ dumpVPSCException(str,solver);
}
for (i=0;i<n;i++) {
place[i]=vars[i]->position();
}
for (i=0;i<n;i++) {
place[i]=vars[i]->position();
converged=false;
}
}
converged=false;
}
}
- destroyVPSC(vpsc);
+ destroyVPSC(solver);
return counter;
}
// Setup an instance of the Variable Placement with Separation Constraints
return counter;
}
// Setup an instance of the Variable Placement with Separation Constraints
// --- that are only relevant to one iteration, and merge these with the
// global constraint list (including alignment constraints,
// dir-edge constraints, containment constraints, etc).
// --- 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);
Constraint **cs;
//assert(lcs.size()==0);
}
cs = new Constraint*[lcs.size() + gcs.size()];
unsigned m = 0 ;
}
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;
}
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;
}
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) {
}
void GradientProjection::clearDummyVars() {
for(DummyVars::iterator i=dummy_vars.begin();i!=dummy_vars.end();++i) {
}
dummy_vars.clear();
}
}
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();
if(acs) {
for(AlignmentConstraints::iterator ac=acs->begin(); ac!=acs->end();++ac) {
(*ac)->updatePosition();
delete vpsc;
delete [] cs;
delete [] vs;
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();
delete *i;
}
lcs.clear();