据我所知,Ceres的接口需要将每个残差定义为函数器,其中operator()是const的成员函数。下面是我感兴趣的一个例子:
class some_residual
{
public:
template<typename type>
bool operator()(const type* const some_params, type* residual) const;
Eigen::MatrixXd m_M;/*The explanation follows. Nevermind its type, all
that matters is that it is not a raw buffer*/
};现在,在一个特殊的情况下,我需要“助手”矩阵m_M,我想在operator()中使用它。例如,我可以将其声明为mutable Eigen::MatrixXd m_M;,或者将其更改为std::shared_ptr<Eigen::MatrixXd> m_pM;,然后从operator()内部更新*mP (或者类似地,我可以使用引用)。作为另一种选择,我可以将这个矩阵的数据作为原始C指针传递给operator(),并在Ceres优化中修复它们。
我更喜欢尽可能避免使用原始指针,并且我倾向于认为使用mutable是最好的解决方案。一般来说,这是好的还是坏的实践,特别是在Ceres中使用它是安全的吗?我还有其他选择吗?
发布于 2018-04-23 05:26:32
可变不是一个好主意。
https://stackoverflow.com/questions/49938818
复制相似问题