2017-03-28 116 views
0

請幫助我轉換此函數,以便它可以接受MatrixXf,Matrix3f,Matrix4f,我閱讀推薦使用MatrixBase但沒有用的Eigen手冊,Eigen :: Ref類也沒有。謝謝。使用特徵矩陣作爲模板

void MatrixIO::FEigentoFile(const Eigen::MatrixXf& in_mat, 
          const std::string filename) 
{ 
    fmat fmat_pb; 
    fmat_pb.set_rows(in_mat.rows()); 
    fmat_pb.set_cols(in_mat.cols()); 
    fmat_pb.mutable_data()->Reserve(in_mat.rows() * in_mat.cols()); 
    for (int i = 0; i < in_mat.rows(); i++) 
    { 
    for (int j = 0; j < in_mat.cols(); j++) 
    { 
     float c = in_mat(i, j); 
     fmat_pb.add_data(c); 
    } 
    } 
    std::fstream output(filename, 
         std::ios::out | std::ios::trunc | std::ios::binary); 
    if (!fmat_pb.SerializeToOstream(&output)) 
    { 
    LOG(INFO) << "Failed to write to file." << std::endl; 
    } 
    return; 
} 

回答

0
template<typename Derived> 
void FEigentoFile(const Eigen::EigenBase<Derived> &in_mat, const std::string filename) 

這應該接受MATRIXX *作爲參數。