edge_se3Switchable.cpp
Go to the documentation of this file.
00001 /*
00002  * edge_se3Switchable.cpp
00003  *
00004  *  Created on: 17.10.2011
00005  *      Author: niko
00006  *
00007  *  Updated on: 14.01.2013
00008  *      Author: Christian Kerl <christian.kerl@in.tum.de>
00009  */
00010 
00011 #include "vertigo/g2o/edge_se3Switchable.h"
00012 #include "vertigo/g2o/vertex_switchLinear.h"
00013 #include "g2o/types/slam3d/vertex_se3.h"
00014 #include "g2o/types/slam3d/isometry3d_gradients.h"
00015 
00016 
00017 using namespace std;
00018 using namespace Eigen;
00019 
00020 
00021 // ================================================
00022 EdgeSE3Switchable::EdgeSE3Switchable() : g2o::BaseMultiEdge<6, Eigen::Isometry3d>()
00023 {
00024   resize(3);
00025   _jacobianOplus[0].resize(6,6); 
00026   _jacobianOplus[1].resize(6,6);
00027   _jacobianOplus[2].resize(6,1);
00028 
00029 }
00030 // ================================================
00031 bool EdgeSE3Switchable::read(std::istream& is)
00032   {    
00033     g2o::Vector7d meas;
00034     for (int i=0; i<7; i++) 
00035       is >> meas[i];
00036     // normalize the quaternion to recover numerical precision lost by storing as human readable text
00037     Vector4d::MapType(meas.data()+3).normalize();
00038     setMeasurement(g2o::internal::fromVectorQT(meas));
00039 
00040     for (int i=0; i<6; i++)
00041       for (int j=i; j<6; j++) {
00042         is >> information()(i,j);
00043         if (i!=j)
00044           information()(j,i) = information()(i,j);
00045       }
00046     return true;
00047 
00048   }
00049 // ================================================
00050 bool EdgeSE3Switchable::write(std::ostream& os) const
00051 {
00052     g2o::Vector7d meas = g2o::internal::toVectorQT(measurement());
00053     for (int i=0; i<7; i++) os  << meas[i] << " ";
00054     for (int i = 0; i < 6; ++i)
00055       for (int j = i; j < 6; ++j)
00056         os << " " << information()(i, j);
00057     return os.good();
00058 }
00059 
00060 // ================================================
00061 void EdgeSE3Switchable::linearizeOplus()
00062 {
00063 
00064     g2o::VertexSE3* from = static_cast<g2o::VertexSE3*>(_vertices[0]);
00065     g2o::VertexSE3* to = static_cast<g2o::VertexSE3*>(_vertices[1]);
00066     const VertexSwitchLinear* vSwitch = static_cast<const VertexSwitchLinear*>(_vertices[2]);
00067 
00068     Eigen::Isometry3d E;
00069     const Eigen::Isometry3d& Xi=from->estimate();
00070     const Eigen::Isometry3d& Xj=to->estimate();
00071     const Eigen::Isometry3d& Z=_measurement;
00072     g2o::internal::computeEdgeSE3Gradient(E, _jacobianOplus[0], _jacobianOplus[1], Z, Xi, Xj);
00073 
00074     _jacobianOplus[0]*=vSwitch->estimate();
00075     _jacobianOplus[1]*=vSwitch->estimate();
00076 
00077     // derivative w.r.t switch vertex
00078     _jacobianOplus[2].setZero();
00079     _jacobianOplus[2] = g2o::internal::toVectorMQT(E) * vSwitch->gradient();
00080 }
00081 
00082 
00083 // ================================================
00084 void EdgeSE3Switchable::computeError()
00085 {
00086     const g2o::VertexSE3* v1 = dynamic_cast<const g2o::VertexSE3*>(_vertices[0]);
00087     const g2o::VertexSE3* v2 = dynamic_cast<const g2o::VertexSE3*>(_vertices[1]);
00088     const VertexSwitchLinear* v3 = static_cast<const VertexSwitchLinear*>(_vertices[2]);
00089 
00090     Eigen::Isometry3d delta = _inverseMeasurement * (v1->estimate().inverse()*v2->estimate());
00091     _error = g2o::internal::toVectorMQT(delta) * v3->estimate();
00092 }
00093 
00094 /*
00095 #include <GL/gl.h>
00096 #ifdef G2O_HAVE_OPENGL
00097   EdgeSE3SwitchableDrawAction::EdgeSE3SwitchableDrawAction(): DrawAction(typeid(EdgeSE3Switchable).name()){}
00098 
00099   g2o::HyperGraphElementAction* EdgeSE3SwitchableDrawAction::operator()(g2o::HyperGraph::HyperGraphElement* element,
00100                g2o::HyperGraphElementAction::Parameters* ){
00101     if (typeid(*element).name()!=_typeName)
00102       return 0;
00103     EdgeSE3Switchable* e =  static_cast<EdgeSE3Switchable*>(element);
00104 
00105 
00106     g2o::VertexSE3* fromEdge = static_cast<g2o::VertexSE3*>(e->vertices()[0]);
00107     g2o::VertexSE3* toEdge   = static_cast<g2o::VertexSE3*>(e->vertices()[1]);
00108     VertexSwitchLinear* s   = static_cast<VertexSwitchLinear*>(e->vertices()[2]);
00109 
00110     glColor3f(s->estimate()*1.0,s->estimate()*0.1,s->estimate()*0.1);
00111     glPushAttrib(GL_ENABLE_BIT);
00112     glDisable(GL_LIGHTING);
00113     glBegin(GL_LINES);
00114     glVertex3f(fromEdge->estimate().translation().x(),fromEdge->estimate().translation().y(),fromEdge->estimate().translation().z());
00115     glVertex3f(toEdge->estimate().translation().x(),toEdge->estimate().translation().y(),toEdge->estimate().translation().z());
00116     glEnd();
00117     glPopAttrib();
00118     return this;
00119   }
00120 #endif
00121 */


rtabmap
Author(s): Mathieu Labbe
autogenerated on Sat Jul 23 2016 11:44:16