// // Created by root on 4/13/21. // #ifndef SVO_SVOVISIONFACTOR_H #define SVO_SVOVISIONFACTOR_H #pragma once #include #include #include #include #include #include #include namespace svo { class VisionFactor: public gtsam::NoiseModelFactor1 { private: // measurement information gtsam::Pose3 pose; /// shared_ptr; /** * Constructor * @param pose Camera pose. * @param pointKey is the index of the landmark */ VisionFactor(const gtsam::Pose3& pose, const gtsam::SharedNoiseModel& H, gtsam::Key poseKey) : gtsam::NoiseModelFactor1(H, poseKey), pose(pose){} virtual ~VisionFactor(){} /// error function /// @param p the Estimated pose in Pose3 /// @param H the optional Jacobian matrix, which use boost optional and has default null pointer gtsam::Vector evaluateError(const gtsam::Pose3& p ,boost::optional H1 = boost::none) const { // note that use boost optional like a pointer // only calculate jacobian matrix when non-null pointer exists Eigen::Matrix E_r=0.5*(p.rotation().matrix().transpose()*pose.rotation().matrix()-pose.rotation().matrix().transpose()*p.rotation().matrix()); Vector3d e_t=p.translation()-pose.translation(); if(H1)(*H1) = (gtsam::Matrix(3,6)<< 1,0,0,0,0,0, 0,0,1,0,0,0, 0,0,0,0,1,0).finished(); return (gtsam::Matrix(3,1)<( gtsam::NonlinearFactor::shared_ptr(new VisionFactor(*this))); } }; } // namespace gtsamexamples #endif //SVO_SVOVISIONFACTOR_H