This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Conversion needed. Huh?

Tags: None
(comma "," separated)
arennuit
Registered Member
Posts
28
Karma
0

Conversion needed. Huh?

Mon Feb 29, 2016 9:05 am
Hello,

I have inherited from class Matrix to add a project() method (to handle projection of homogeneous points into normal space):

Code: Select all
////////////////////////////////////////////////////////////////////////////////
/// \brief This class represents a point in a HOMOGENEOUS space.
///
/// This class is used together with class Point.
template<typename _Scalar, int _Size>
class HPoint : public Matrix<_Scalar, _Size + 1, 1>
{
public:
    HPoint() {}
};

////////////////////////////////////////////////////////////////////////////////
/// \brief Template specialization for HPoint of size 2.
template<typename _Scalar>
class HPoint<_Scalar, 2> : public Matrix<_Scalar, 3, 1>
{
public:
    HPoint() : Matrix<_Scalar, 3, 1>()  {}
    HPoint(_Scalar x, _Scalar y, _Scalar w) : Matrix<_Scalar, 3, 1>(x, y, w) {}
    HPoint(HPoint const& hPoint) : Matrix<_Scalar, 3, 1>(hPoint.x(), hPoint.y(), hPoint.z())  {}
    HPoint(Matrix<_Scalar, 3, 1> const& mat) : Matrix<_Scalar, 3, 1>(mat)  {}

    virtual HPoint<_Scalar, 2>& operator=(HPoint<_Scalar, 2> const& hPoint)
    {
        this->x() = hPoint.x();
        this->y() = hPoint.y();
        this->z() = hPoint.z();
    }

    _Scalar w() {return this->z();}

    /// Project the homogeneous space into its associated normal space.
    Matrix<_Scalar, 2, 1> project() const {return Matrix<_Scalar, 2, 1>(this->x() / this->w(), this->y() / this->w());}
};


Now with this code I cannot get this to work:

Code: Select all
HPoint p = HPoint::Zero();


I need to do

Code: Select all
HPoint p(HPoint::Zero());


or

Code: Select all
HPoint p = (HPoint)HPoint::Zero();


to get things working... which is not what I am looking for.

I am not sure I understand what I am doing wrong. Anyone has an idea?

Thanks,

Antoine.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Conversion needed. Huh?

Mon Feb 29, 2016 10:06 am
This is because you have to reproduce all ctor of Matrix which is a pain! Better use the plugins mechanism to add methods: http://eigen.tuxfamily.org/dox/TopicCus ... Eigen.html

This way you can even make your new method available to expressions, like (a+b).project().

Another approach is to add free-functions: res = project(a); instead of res = a.project();
arennuit
Registered Member
Posts
28
Karma
0

Re: Conversion needed. Huh?

Mon Feb 29, 2016 2:47 pm
This does work, thank you!


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft