56 TreeOptimizer3::TreeOptimizer3(){
57 restartOnDivergence=
false;
64 TreeOptimizer3::~TreeOptimizer3(){
67 void TreeOptimizer3::initializeTreeParameters(){
69 treeDepthVisit(pp,
root);
80 propagateErrors(
false);
83 computePreconditioner();
84 propagateErrors(
true);
89 if (restartOnDivergence){
92 error(&mre, &mte, &are, &ate);
93 maxTranslationalErrors.push_back(mte);
94 maxRotationalErrors.push_back(mre);
96 if ((
int)maxRotationalErrors.size()>=interval){
97 uint s=(
uint)maxRotationalErrors.size();
98 double re0 = maxRotationalErrors[s-interval];
99 double re1 = maxRotationalErrors[s-1];
101 if ((re1-re0)>are ||
sqrt(re1)>0.99*
M_PI){
104 cerr <<
"RESTART!!!!! : Angular wraparound may be occourring" << endl;
105 cerr <<
" err=" << re0 <<
" -> " << re1 << endl;
106 cerr <<
"Restarting optimization and reducing the rotation factor" << endl;
107 cerr << rg <<
" -> ";
109 initializeTreeParameters();
110 initializeOptimization();
112 maxTranslationalErrors.push_back(mte);
113 maxRotationalErrors.push_back(mre);
116 cerr << rotGain << endl;
119 cerr <<
"decreasing angular gain" << rotGain*0.1 << endl;
129 void TreeOptimizer3::recomputeTransformations(Vertex*v, Vertex* top){
132 recomputeTransformations(v->parent, top);
133 v->transformation=v->parent->transformation*v->parameters;
137 void TreeOptimizer3::recomputeParameters(Vertex*v, Vertex* top){
139 v->parameters=v->parent->transformation.inv()*v->transformation;
148 return v->transformation;
153 return top->transformation*t;
159 return v->transformation.rotation();
161 r=v->parameters.rotation()*r;
164 return top->transformation.rotation()*r;
169 double TreeOptimizer3::error(
const Edge*
e)
const{
170 const Vertex* v1=e->v1;
171 const Vertex* v2=e->v2;
180 Pose ps=e->informationMatrix*p12;
187 double TreeOptimizer3::traslationalError(
const Edge*
e)
const{
188 const Vertex* v1=e->v1;
189 const Vertex* v2=e->v2;
200 double TreeOptimizer3::rotationalError(
const Edge*
e)
const{
201 const Vertex* v1=e->v1;
202 const Vertex* v2=e->v2;
204 Rotation er=e->transformation.rotation();
205 Rotation r1=v1->transformation.rotation();
206 Rotation r2=v2->transformation.rotation();
209 double r=r12.
angle();
214 double TreeOptimizer3::loopError(
const Edge*
e)
const{
216 const Vertex* v=e->v1;
218 err+=error(v->parentEdge);
223 err+=error(v->parentEdge);
226 if (e->v2->parentEdge!=e && e->v1->parentEdge!=e)
231 double TreeOptimizer3::loopRotationalError(
const Edge*
e)
const{
233 const Vertex* v=e->v1;
235 err+=rotationalError(v->parentEdge);
240 err+=rotationalError(v->parentEdge);
243 if (e->v2->parentEdge!=e && e->v1->parentEdge!=e)
244 err+=rotationalError(e);
250 double globalRotError=0.;
251 double maxRotError=0;
252 double globalTrasError=0.;
253 double maxTrasError=0;
257 for (TreePoseGraph3::EdgeMap::const_iterator it=edges.begin(); it!=edges.end(); it++){
258 double re=rotationalError(it->second);
260 maxRotError=maxRotError>re?maxRotError:re;
261 double te=traslationalError(it->second);
263 maxTrasError=maxTrasError>te?maxTrasError:te;
267 for (TreePoseGraph3::EdgeSet::const_iterator it=eset->begin(); it!=eset->end(); it++){
268 const TreePoseGraph3::Edge* edge=*it;
269 double re=rotationalError(edge);
271 maxRotError=maxRotError>re?maxRotError:re;
272 double te=traslationalError(edge);
274 maxTrasError=maxTrasError>te?maxTrasError:te;
284 *ate=globalTrasError/c;
286 *are=globalRotError/c;
287 return globalRotError+globalTrasError;
293 edgeCompareMode=mode;
307 sortedEdges=sortEdges();
313 void TreeOptimizer3::initializeOnlineIterations(){
319 maxRotationalErrors.clear();
320 maxTranslationalErrors.clear();
326 edgeCompareMode=mode;
329 Vertex* v0=addVertex(0,
Pose(0,0,0,0,0,0));
338 void TreeOptimizer3::onStepStart(Edge*
e){
341 void TreeOptimizer3::onStepFinished(Edge*
e){
345 void TreeOptimizer3::onIterationStart(
int iteration){
349 void TreeOptimizer3::onIterationFinished(
int iteration){
353 void TreeOptimizer3::onRestartBegin(){}
354 void TreeOptimizer3::onRestartDone(){}
355 bool TreeOptimizer3::isDone(){
GLM_FUNC_DECL vecType< T, P > sqrt(vecType< T, P > const &x)
GLM_FUNC_DECL genType e()
A comparator class (struct) that compares the level of two vertices if edges.
Defines the core optimizer class for 3D graphs which is a subclass of TreePoseGraph3.
EVComparator< Edge * >::CompareMode EdgeCompareMode
Quaternion< T > inverse() const
A class (struct) to compute the parameterization of the vertex v.
std::multiset< Edge *, EVComparator< Edge * > > EdgeSet