types_seven_dof_expmap.cpp
Go to the documentation of this file.
00001 // g2o - General Graph Optimization
00002 // Copyright (C) 2011 H. Strasdat
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 #include "types_seven_dof_expmap.h"
00018 
00019 #include "g2o/core/factory.h"
00020 
00021 namespace g2o {
00022 
00023   void __attribute__ ((constructor)) init_seven_dof_types(void)
00024   {
00025     //cerr << "Calling " << __FILE__ << " " << __PRETTY_FUNCTION__ << endl;
00026     Factory* factory = Factory::instance();
00027     factory->registerType("VERTEX_SIM3:EXPMAP", new HyperGraphElementCreator<VertexSim3Expmap>);
00028 
00029     factory->registerType("EDGE_SIM3:EXPMAP", new HyperGraphElementCreator<EdgeSim3>);
00030     factory->registerType("EDGE_PROJECT_SIM3_XYZ:EXPMAP", new HyperGraphElementCreator<EdgeSim3ProjectXYZ>);
00031   }
00032 
00033   VertexSim3Expmap::VertexSim3Expmap() : BaseVertex<7, Sim3>()
00034   {
00035     _marginalized=false;
00036     _fix_scale = false;
00037     _principle_point[0] = 0;
00038     _principle_point[1] = 0;
00039     _focal_length[0] = 1;
00040     _focal_length[1] = 1;
00041   }
00042 
00043 
00044   EdgeSim3::EdgeSim3() :
00045       BaseBinaryEdge<7, Sim3, VertexSim3Expmap, VertexSim3Expmap>()
00046   {
00047   }
00048 
00049 
00050   bool VertexSim3Expmap::read(std::istream& is)
00051   {
00052     Vector7d cam2world;
00053     for (int i=0; i<6; i++){
00054       is >> cam2world[i];
00055     }
00056     is >> cam2world[6];
00057 //    if (! is) {
00058 //      // if the scale is not specified we set it to 1;
00059 //      std::cerr << "!s";
00060 //      cam2world[6]=0.;
00061 //    }
00062 
00063     for (int i=0; i<2; i++)
00064     {
00065       is >> _focal_length[i];
00066     }
00067     for (int i=0; i<2; i++)
00068     {
00069       is >> _principle_point[i];
00070     }
00071 
00072     estimate() = Sim3(cam2world).inverse();
00073     return true;
00074   }
00075 
00076   bool VertexSim3Expmap::write(std::ostream& os) const
00077   {
00078     Sim3 cam2world(estimate().inverse());
00079     Vector7d lv=cam2world.log();
00080     for (int i=0; i<7; i++){
00081       os << lv[i] << " ";
00082     }
00083     for (int i=0; i<2; i++)
00084     {
00085       os << _focal_length[i] << " ";
00086     }
00087     for (int i=0; i<2; i++)
00088     {
00089       os << _principle_point[i] << " ";
00090     }
00091     return os.good();
00092   }
00093 
00094   bool EdgeSim3::read(std::istream& is)
00095   {
00096     Vector7d v7;
00097     for (int i=0; i<7; i++){
00098       is >> v7[i];
00099     }
00100 
00101     Sim3 cam2world(v7);
00102     measurement() = cam2world.inverse();
00103 
00104     inverseMeasurement() = cam2world;
00105 
00106     for (int i=0; i<7; i++)
00107       for (int j=i; j<7; j++)
00108       {
00109         is >> information()(i,j);
00110         if (i!=j)
00111           information()(j,i)=information()(i,j);
00112       }
00113     return true;
00114   }
00115 
00116   bool EdgeSim3::write(std::ostream& os) const
00117   {
00118     Sim3 cam2world(measurement().inverse());
00119     Vector7d v7 = cam2world.log();
00120     for (int i=0; i<7; i++)
00121     {
00122       os  << v7[i] << " ";
00123     }
00124     for (int i=0; i<7; i++)
00125       for (int j=i; j<7; j++){
00126         os << " " <<  information()(i,j);
00127     }
00128     return os.good();
00129   }
00130 
00133   EdgeSim3ProjectXYZ::EdgeSim3ProjectXYZ() :
00134   BaseBinaryEdge<2, Vector2d, VertexPointXYZ, VertexSim3Expmap>()
00135   {
00136   }
00137 
00138   bool EdgeSim3ProjectXYZ::read(std::istream& is)
00139   {
00140     for (int i=0; i<2; i++)
00141     {
00142       is >> measurement()[i];
00143     }
00144 
00145     inverseMeasurement() = -measurement();
00146     for (int i=0; i<2; i++)
00147       for (int j=i; j<2; j++) {
00148         is >> information()(i,j);
00149       if (i!=j)
00150         information()(j,i)=information()(i,j);
00151     }
00152     return true;
00153   }
00154 
00155   bool EdgeSim3ProjectXYZ::write(std::ostream& os) const
00156   {
00157     for (int i=0; i<2; i++){
00158       os  << measurement()[i] << " ";
00159     }
00160 
00161     for (int i=0; i<2; i++)
00162       for (int j=i; j<2; j++){
00163         os << " " <<  information()(i,j);
00164     }
00165     return os.good();
00166   }
00167 
00168 //  void EdgeSim3ProjectXYZ::linearizeOplus()
00169 //  {
00170 //    VertexSim3Expmap * vj = static_cast<VertexSim3Expmap *>(_vertices[1]);
00171 //    Sim3 T = vj->estimate();
00172 
00173 //    VertexPointXYZ* vi = static_cast<VertexPointXYZ*>(_vertices[0]);
00174 //    Vector3d xyz = vi->estimate();
00175 //    Vector3d xyz_trans = T.map(xyz);
00176 
00177 //    double x = xyz_trans[0];
00178 //    double y = xyz_trans[1];
00179 //    double z = xyz_trans[2];
00180 //    double z_2 = z*z;
00181 
00182 //    Matrix<double,2,3> tmp;
00183 //    tmp(0,0) = _focal_length(0);
00184 //    tmp(0,1) = 0;
00185 //    tmp(0,2) = -x/z*_focal_length(0);
00186 
00187 //    tmp(1,0) = 0;
00188 //    tmp(1,1) = _focal_length(1);
00189 //    tmp(1,2) = -y/z*_focal_length(1);
00190 
00191 //    _jacobianOplusXi =  -1./z * tmp * T.rotation().toRotationMatrix();
00192 
00193 //    _jacobianOplusXj(0,0) =  x*y/z_2 * _focal_length(0);
00194 //    _jacobianOplusXj(0,1) = -(1+(x*x/z_2)) *_focal_length(0);
00195 //    _jacobianOplusXj(0,2) = y/z *_focal_length(0);
00196 //    _jacobianOplusXj(0,3) = -1./z *_focal_length(0);
00197 //    _jacobianOplusXj(0,4) = 0;
00198 //    _jacobianOplusXj(0,5) = x/z_2 *_focal_length(0);
00199 //    _jacobianOplusXj(0,6) = 0; // scale is ignored
00200 
00201 
00202 //    _jacobianOplusXj(1,0) = (1+y*y/z_2) *_focal_length(1);
00203 //    _jacobianOplusXj(1,1) = -x*y/z_2 *_focal_length(1);
00204 //    _jacobianOplusXj(1,2) = -x/z *_focal_length(1);
00205 //    _jacobianOplusXj(1,3) = 0;
00206 //    _jacobianOplusXj(1,4) = -1./z *_focal_length(1);
00207 //    _jacobianOplusXj(1,5) = y/z_2 *_focal_length(1);
00208 //    _jacobianOplusXj(1,6) = 0; // scale is ignored
00209 //  }
00210 
00211 } // end namespace


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