57 TreeOptimizer3::TreeOptimizer3(){
58 restartOnDivergence=
false;
65 TreeOptimizer3::~TreeOptimizer3(){
68 void TreeOptimizer3::initializeTreeParameters(){
70 treeDepthVisit(pp,
root);
74 void TreeOptimizer3::iterate(TreePoseGraph3::EdgeSet* eset,
bool noPreconditioner){
75 TreePoseGraph3::EdgeSet* temp=sortedEdges;
81 propagateErrors(
false);
84 computePreconditioner();
85 propagateErrors(
true);
90 if (restartOnDivergence){
93 error(&mre, &mte, &are, &ate);
94 maxTranslationalErrors.push_back(mte);
95 maxRotationalErrors.push_back(mre);
97 if ((
int)maxRotationalErrors.size()>=interval){
99 double re0 = maxRotationalErrors[
s-interval];
100 double re1 = maxRotationalErrors[
s-1];
102 if ((re1-re0)>are ||
sqrt(re1)>0.99*
M_PI){
105 cerr <<
"RESTART!!!!! : Angular wraparound may be occourring" << endl;
106 cerr <<
" err=" << re0 <<
" -> " << re1 << endl;
107 cerr <<
"Restarting optimization and reducing the rotation factor" << endl;
108 cerr << rg <<
" -> ";
110 initializeTreeParameters();
111 initializeOptimization();
113 maxTranslationalErrors.push_back(mte);
114 maxRotationalErrors.push_back(mre);
117 cerr << rotGain << endl;
120 cerr <<
"decreasing angular gain" << rotGain*0.1 << endl;
130 void TreeOptimizer3::recomputeTransformations(Vertex*v, Vertex* top){
133 recomputeTransformations(
v->parent, top);
134 v->transformation=
v->parent->transformation*
v->parameters;
138 void TreeOptimizer3::recomputeParameters(Vertex*v, Vertex* top){
140 v->parameters=
v->parent->transformation.inv()*
v->transformation;
149 return v->transformation;
154 return top->transformation*
t;
160 return v->transformation.rotation();
162 r=
v->parameters.rotation()*r;
165 return top->transformation.rotation()*r;
170 double TreeOptimizer3::error(
const Edge*
e)
const{
171 const Vertex*
v1=
e->v1;
172 const Vertex*
v2=
e->v2;
181 Pose ps=
e->informationMatrix*p12;
188 double TreeOptimizer3::traslationalError(
const Edge*
e)
const{
189 const Vertex*
v1=
e->v1;
190 const Vertex*
v2=
e->v2;
201 double TreeOptimizer3::rotationalError(
const Edge*
e)
const{
202 const Vertex*
v1=
e->v1;
203 const Vertex*
v2=
e->v2;
205 Rotation er=
e->transformation.rotation();
210 double r=r12.
angle();
215 double TreeOptimizer3::loopError(
const Edge*
e)
const{
217 const Vertex*
v=
e->v1;
219 err+=
error(
v->parentEdge);
224 err+=
error(
v->parentEdge);
227 if (
e->v2->parentEdge!=
e &&
e->v1->parentEdge!=
e)
232 double TreeOptimizer3::loopRotationalError(
const Edge*
e)
const{
234 const Vertex*
v=
e->v1;
236 err+=rotationalError(
v->parentEdge);
241 err+=rotationalError(
v->parentEdge);
244 if (
e->v2->parentEdge!=
e &&
e->v1->parentEdge!=
e)
245 err+=rotationalError(
e);
250 double TreeOptimizer3::error(
double* mre,
double* mte,
double* are,
double* ate, TreePoseGraph3::EdgeSet* eset)
const{
251 double globalRotError=0.;
252 double maxRotError=0;
253 double globalTrasError=0.;
254 double maxTrasError=0;
258 for (TreePoseGraph3::EdgeMap::const_iterator it=
edges.begin(); it!=
edges.end(); it++){
259 double re=rotationalError(it->second);
261 maxRotError=maxRotError>re?maxRotError:re;
262 double te=traslationalError(it->second);
264 maxTrasError=maxTrasError>te?maxTrasError:te;
268 for (TreePoseGraph3::EdgeSet::const_iterator it=eset->begin(); it!=eset->end(); it++){
269 const TreePoseGraph3::Edge* edge=*it;
270 double re=rotationalError(edge);
272 maxRotError=maxRotError>re?maxRotError:re;
273 double te=traslationalError(edge);
275 maxTrasError=maxTrasError>te?maxTrasError:te;
285 *ate=globalTrasError/
c;
287 *are=globalRotError/
c;
288 return globalRotError+globalTrasError;
293 void TreeOptimizer3::initializeOptimization(EdgeCompareMode mode){
294 edgeCompareMode=
mode;
308 sortedEdges=sortEdges();
314 void TreeOptimizer3::initializeOnlineIterations(){
320 maxRotationalErrors.clear();
321 maxTranslationalErrors.clear();
326 void TreeOptimizer3::initializeOnlineOptimization(EdgeCompareMode mode){
327 edgeCompareMode=
mode;
330 Vertex* v0=addVertex(0,
Pose(0,0,0,0,0,0));
339 void TreeOptimizer3::onStepStart(Edge*
e){
342 void TreeOptimizer3::onStepFinished(Edge*
e){
346 void TreeOptimizer3::onIterationStart(
int iteration){
350 void TreeOptimizer3::onIterationFinished(
int iteration){
354 void TreeOptimizer3::onRestartBegin(){}
355 void TreeOptimizer3::onRestartDone(){}
356 bool TreeOptimizer3::isDone(){