0

Hi ,as you can see ,I seems have an issue with the code when I am compiling with cmake: I am using this code to chage the value type of Eigen values mag_models.cpp:

#include <iostream>
#include "Eigen/Core"
#include "Eigen/Geometry"


using namespace std;
using namespace Eigen;


template <typename T>
struct CoilCalibrationModel
{
    double global_gain;
    Eigen::Vector3<T> noise;
    Eigen::Vector3<T> bias;
    Eigen::Vector3<T> gain;
    Eigen::Vector3<T> per_channel_gain;
    Eigen::Vector3<T> sensor_offset;
    Eigen::Quaternion<T> sensor_rot_offset;
    Eigen::Vector3<T> ring_offset;
    Eigen::Quaternion<T> ring_rot_offset;
    Eigen::Quaternion<double> base_sensor_offset;
    Eigen::Quaternion<double> base_sensor_rot_offset;
    array<double, 3> crosstalk;

    template<typename U> CoilCalibrationModel<U> cast() const
    {
        CoilCalibrationModel<U> model;
        model.global_gain = U(global_gain);
        model.noise = noise.cast<U>();
        model.bias = bias.cast<U>();
        model.gain = gain.cast<U>();
        model.per_channel_gain = per_channel_gain.cast<U>();
        model.sensor_offset = sensor_offset.cast<U>();
        model.sensor_rot_offset = sensor_rot_offset.cast<U>();
        model.ring_offset = ring_offset.cast<U>();
        model.ring_rot_offset = ring_rot_offset.cast<U>();
        model.base_sensor_offset = base_sensor_offset.cast<U>();;
        model.base_sensor_rot_offset = base_sensor_rot_offset.cast<U>();;
        model.crosstalk = {T(crosstalk[0]), T(crosstalk[1]), T(crosstalk[2])};
        return model;
    }
};

int mian(){
    CoilCalibrationModel<double> fram;
    fram.global_gain= 0.5;
    fram.noise = Eigen::Vector3<double>(1,2,3);
    fram.bias = Eigen::Vector3<double>(1,2,3);
    fram.gain = Eigen::Vector3<double>(1,2,3);
    fram.per_channel_gain = Eigen::Vector3<double>(1,2,3);
    fram.sensor_offset = Eigen::Vector3<double>(1,2,3);
    fram.sensor_rot_offset = Eigen::Quaternion<double>(1,2,3,4);
    fram.ring_offset = Eigen::Vector3<double>(1,2,3);
    fram.ring_rot_offset = Eigen::Vector3<double>(1,2,3);
    fram.base_sensor_offset = Eigen::Quaternion<double>(1,2,3,4);
    fram.base_sensor_rot_offset = Eigen::Quaternion<double>(1,2,3,4);
    fram.crosstalk ={1.0,2.0,3.0};
    cout<<" before cast :"<<fram.global_gain<<endl;
    CoilCalibrationModel<int> framcast = fram.cast<int>();
    cout<<" after cast :"<<framcast.global_gain<<endl;
}

Here is the cmake file :

cmake_minimum_required (VERSION 3.8)

project ("mag-inverse")

set(CMAKE_BUILD_TYPE RelWithDebInfo)

Find_Package(Eigen3 REQUIRED)
Find_Package(Ceres REQUIRED COMPONENTS SuiteSparse EigenSparse Multithreading LAPACK)
include_directories(${CERES_INCLUDE_DIRS})
include_directories(${EIGEN3_INCLUDE_DIRS})


find_package(gflags REQUIRED)
include_directories(.)
add_executable(magtest mag_models.cpp)
target_link_libraries(magtest ${CERES_LIBRARIES})
target_link_libraries(magtest gflags)

and I get the error:your text

 error: expected primary-expression before ‘>’ token
   31 |   model.noise = noise.cast<U>();
      |                             ^
/home/xx/AuraTest/mag_models.cpp:31:31: error: expected primary-expression before ‘)’ token
   31 |   model.noise = noise.cast<U>();
      |                               ^
/home/xx/AuraTest/mag_models.cpp:32:27: error: expected primary-expression before ‘>’ token
   32 |   model.bias = bias.cast<U>();
      |                           ^
/home/xx/AuraTest/mag_models.cpp:32:29: error: expected primary-expression before ‘)’ token
   32 |   model.bias = bias.cast<U>();

Could you please help with me seem like that I am struggling in this issue :-(,thanks

gcc/g++ =9.4; eigen=3.4

Soar
  • 1
  • 1
    You have to write `noise.template cast()`, see here for an explanation: https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords. Also here: https://eigen.tuxfamily.org/dox/TopicTemplateKeyword.html – chtz Mar 08 '23 at 15:50
  • 2
    Does this answer your question? [Where and why do I have to put the "template" and "typename" keywords?](https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) – chtz Mar 08 '23 at 15:51

0 Answers0