base_unary_edge.hpp
Go to the documentation of this file.
00001 // g2o - General Graph Optimization
00002 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, H. Strasdat, W. Burgard
00003 // 
00004 // g2o is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU Lesser General Public License as published
00006 // by the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // g2o is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 template <int D, typename E, typename VertexXiType>
00018 void BaseUnaryEdge<D, E, VertexXiType>::constructQuadraticForm()
00019 {
00020   VertexXiType* from=static_cast<VertexXiType*>(_vertices[0]);
00021 
00022   // chain rule to get the Jacobian of the nodes in the manifold domain
00023   const JacobianXiOplusType& A = jacobianOplusXi();
00024   const InformationType& omega = _information;
00025 
00026   bool istatus = !from->fixed();
00027   if (istatus) {
00028 #ifdef G2O_OPENMP
00029     from->lockQuadraticForm();
00030 #endif
00031     from->b().noalias() -= A.transpose() * omega * _error;
00032     from->A().noalias() += A.transpose() * omega * A;
00033 #ifdef G2O_OPENMP
00034     from->unlockQuadraticForm();
00035 #endif
00036   }
00037 }
00038 
00039 template <int D, typename E, typename VertexXiType>
00040 void BaseUnaryEdge<D, E, VertexXiType>::linearizeOplus()
00041 {
00042   //Xi - estimate the jacobian numerically
00043   VertexXiType* vi = static_cast<VertexXiType*>(_vertices[0]);
00044 
00045   if (vi->fixed())
00046     return;
00047 
00048 #ifdef G2O_OPENMP
00049   vi->lockQuadraticForm();
00050 #endif
00051 
00052   const double delta = 1e-9;
00053   const double scalar = 1.0 / (2*delta);
00054   ErrorVector error1;
00055   ErrorVector errorBeforeNumeric = _error;
00056 
00057   double add_vi[VertexXiType::Dimension];
00058   std::fill(add_vi, add_vi + VertexXiType::Dimension, 0.0);
00059   // add small step along the unit vector in each dimension
00060   for (int d = 0; d < VertexXiType::Dimension; ++d) {
00061     vi->push();
00062     add_vi[d] = delta;
00063     vi->oplus(add_vi);
00064     computeError();
00065     error1 = _error;
00066     vi->pop();
00067     vi->push();
00068     add_vi[d] = -delta;
00069     vi->oplus(add_vi);
00070     computeError();
00071     vi->pop();
00072     add_vi[d] = 0.0;
00073 
00074     _jacobianOplusXi.col(d) = scalar * (error1 - _error);
00075   } // end dimension
00076 
00077   _error = errorBeforeNumeric;
00078 #ifdef G2O_OPENMP
00079   vi->unlockQuadraticForm();
00080 #endif
00081 }
00082 
00083 template <int D, typename E, typename VertexXiType>
00084 void BaseUnaryEdge<D, E, VertexXiType>::initialEstimate(const OptimizableGraph::VertexSet&, OptimizableGraph::Vertex*)
00085 {
00086   std::cerr << __PRETTY_FUNCTION__ << " is not implemented, please give implementation in your derived class" << std::endl;
00087 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:30:47