Je n'arrive pas à comprendre comment définir une matrice du type Eigen::MatrixXd comme attribut d'une classe.
Tout d'abord, je ne peux pas définir
Eigen::MatrixXd Y(4,1)
mais uniquement
Eigen::MatrixXd Y(int n = 4, int m = 1)
Déja je trouve çà louche, admettons. Maintenant, je souhaiterais initialiser cette matrice lors du constructeur, j'ai essayé plusieurs choses mais aucune ne fonctionne.
PREMIERE APPROCHE :
class OpticalFlow
{
public:
// CONSTRUCTEUR
OpticalFlow(){
Y(0,0) = 0.0;
Y(1,0) = 0.0;
Y(2,0) = 0.0;
Y(3,0) = 0.0;
cout<<"\n Y : "<<endl;
cout<<Y<<endl;
}
protected:
// ATTRIBUTS
Eigen::MatrixXd Y(int n = 4, int m = 1);
};
Dans ce cas, j'obtiens le message :
/home/matt/catkin_ws/src/optical_flow/src/optical_flow_range.cpp:117:16: error: no match for ‘operator=’ (operand types are ‘Eigen::MatrixXd {aka Eigen::Matrix<double, -1, -1>}’ and ‘double’)
Y(0,0) = 0.0;
DEUXIEME APPROCHE
class OpticalFlow
{
public:
// CONSTRUCTEUR
OpticalFlow(){
Y << 0.0 , 0.0 , 0.0 , 0.0;
cout<<"\n Y : "<<endl;
cout<<Y<<endl;
}
protected:
// ATTRIBUTS
Eigen::MatrixXd Y(int n = 4, int m = 1);
};
Pas mieux :
/home/matt/catkin_ws/src/optical_flow/src/optical_flow_range.cpp:117:14: error: invalid use of member function (did you forget the ‘()’ ?)
Y << 0.0 , 0.0 , 0.0 , 0.0;
TROISIEME APPROCHE
class OpticalFlow
{
public:
// CONSTRUCTEUR
OpticalFlow(){
Y.col(0) << 0.0 , 0.0 , 0.0 , 0.0;
cout<<"\n Y : "<<endl;
cout<<Y<<endl;
}
protected:
// ATTRIBUTS
Eigen::MatrixXd Y(int n = 4, int m = 1);
};
Toujours pas.
/home/matt/catkin_ws/src/optical_flow/src/optical_flow_range.cpp:117:9: error: ‘((OpticalFlow*)this)->OpticalFlow::Y’ does not have class typ
Comment initialise t-on un tel type comme attribut ?
Ça déclare une fonction Y qui reçoit 2 paramètres facultatifs et retourne une Eigen::MatrixXd, ça n'est pas ce que tu souhaites. D'où, tes approches n'ont aucun sens.
class OpticalFlow {
public:
OpticalFlow()
: Y(4,1) // création des membres
{
Y << 0.0 , 0.0 , 0.0 , 0.0;
}
protected:
Eigen::MatrixXd Y; // membre défini
};
En recherche d'emploi.
Eigen matrix comme attribut
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
En recherche d'emploi.