#ifndef MARGINALIZATIONFACTOR_H_ #define MARGINALIZATIONFACTOR_H_ #include #include #include #include "utils/common.h" #include "utils/math_tools.h" const int NUM_THREADS = 4; struct ResidualBlockInfo { ResidualBlockInfo(ceres::CostFunction *_cost_function, ceres::LossFunction *_loss_function, std::vector _parameter_blocks, std::vector _drop_set) : cost_function(_cost_function), loss_function(_loss_function), parameter_blocks(_parameter_blocks), drop_set(_drop_set) {} void Evaluate(); ceres::CostFunction *cost_function; ceres::LossFunction *loss_function; std::vector parameter_blocks; std::vector drop_set; double **raw_jacobians; std::vector> jacobians; Eigen::VectorXd residuals; }; class MarginalizationInfo { public: ~MarginalizationInfo(); int LocalSize(int size) const; void AddResidualBlockInfo(ResidualBlockInfo *residual_block_info); void PreMarginalize(); void Marginalize(); std::vector GetParameterBlocks(std::unordered_map &addr_shift); std::vector factors; int m, n; std::unordered_map parameter_block_size; //global size int sum_block_size; std::unordered_map parameter_block_idx; //local size std::unordered_map parameter_block_data; std::vector keep_block_size; //global size std::vector keep_block_idx; //local size std::vector keep_block_data; Eigen::MatrixXd linearized_jacobians; Eigen::VectorXd linearized_residuals; const double eps = 1e-8; }; class MarginalizationFactor : public ceres::CostFunction { public: MarginalizationFactor(MarginalizationInfo* _marginalization_info); virtual bool Evaluate(double const *const *parameters, double *residuals, double **jacobians) const; MarginalizationInfo* marginalization_info; }; struct ThreadsStruct { std::vector sub_factors; Eigen::MatrixXd A; Eigen::VectorXd b; std::unordered_map parameter_block_size; //global size std::unordered_map parameter_block_idx; //local size }; #endif //MARGINALIZATIONFACTOR_H_