Boost logo

Ublas :

Subject: Re: [ublas] Extended/overloading ublas
From: kayhman (kayhman_at_[hidden])
Date: 2009-06-04 03:36:27


Hi Kim,

Thanks for your answer :)

Concerning what I'm doing, I'd like to extend uBLAS with :
- an object representing an element of the Lie group SE(3), using a vector
of 7 doubles,
- and another object representing an element of the Lie algebra associated
se(3) using a vector of 6 doubles.

For these objects, I need to redefine the inner and outer product as well as
adding mapping operations log and exponential.

Besides, I want to be able to use proxies for these two objects, as
eventually I will maniupalte a cartesian product of Lie goup elements which
will be stored in a global vector. Using proxies, I'd like to map each lie
group element to the corresponding double sub array in the global vector.

And finally, for performances, I want to benefit from the template
expression mecanism to eliminates temporaries.

Could you explain me how to add a new function, let's say the exponential,
which convert an se(3) element into an SE(3) element ? (This can be seen as
converting a 6-d vector into a 4-4 matrix by applying the exp() on the 6-d
vector)

Thanks a lot,

kayhman

2009/6/3 Kim Kuen Tang <kuentang_at_[hidden]>

> Hi kayhman,
>
> below is the working code.
> To understand what you are doing, can you tell us more?
>
> //#include <vector>
> #include <iostream>
> #include <boost/numeric/ublas/vector.hpp>
>
> namespace boost { namespace numeric { namespace ublas {
>
> class twist : public vector<double, ublas::bounded_array<double,3> >
> {
> public:
> typedef vector<double, bounded_array<double,3> > Base_vector;
> // Default construction
> twist () : Base_vector(3)
> {}
> // Construction and assignment from a uBLAS vector expression or copy
> assignment
> template <class R> twist (const vector_expression<R>& r) : Base_vector(r)
> {}
> template <class R> void operator=(const vector_expression<R>& r)
> {
> Base_vector::operator=(r);
> }
> template <class R> void operator=(const Base_vector& r)
> {
> Base_vector::operator=(r);
> }
> };
>
>
> BOOST_UBLAS_INLINE
> vector_binary_traits<twist::Base_vector,
> twist::Base_vector,
> scalar_plus<double,double> >::result_type
> //operator + (const vector_expression<twist > &e1,
> // const vector_expression<twist > &e2)
> operator + (twist::Base_vector &e1, twist::Base_vector &e2)
> {
> typedef vector_binary_traits<twist::Base_vector,
> twist::Base_vector, scalar_plus<double,double> >::expression_type
> expression_type;
> std::cout << "twist sum !!!!" << std::endl;
> return expression_type (e1, e2);
> }
>
> }
> }
> }
>
> int main()
> {
> using namespace boost::numeric::ublas;
> twist T1;
> twist T2;
>
> std::cout << "sum Twist : " << std::endl;
> T2+T1;
> //std::cout << "Quat : " << T2+T1 << std::endl;
>
> }
>
>
> kayhman schrieb:
>
>> Hello !
>>
>>
>> I'd like to extend ublas, i.e. I want to create a new Twist class, and
>> overload some of the standard operation like addition, inner_prod, ...
>>
>> I've define the new class as follow :
>>
>> class twist : public vector<double, ublas::bounded_array<double,3> >
>> {
>> typedef vector<double, bounded_array<double,3> > Base_vector;
>> public:
>> // Default construction
>> twist () : Base_vector(3)
>> {}
>> // Construction and assignment from a uBLAS vector expression or copy
>> assignment
>> template <class R> twist (const vector_expression<R>& r) :
>> Base_vector(r)
>> {}
>> template <class R> void operator=(const vector_expression<R>& r)
>> {
>> Base_vector::operator=(r);
>> }
>> template <class R> void operator=(const Base_vector& r)
>> {
>> Base_vector::operator=(r);
>> }
>> };
>>
>> And I've overloaded the sum specializing the following templated function
>> :
>>
>> template<>
>> BOOST_UBLAS_INLINE
>> vector_binary_traits<twist,
>> twist,
>> scalar_plus<double,double> >::result_type
>> operator + (const vector_expression<twist > &e1,
>> const vector_expression<twist > &e2)
>> {
>> typedef vector_binary_traits<twist, twist, scalar_plus<double,double>
>> >::expression_type expression_type;
>> std::cout << "twist sum !!!!" << std::endl;
>> return expression_type (e1(), e2());
>> }
>>
>>
>>
>> And I get the following error (using gcc-4.2):
>>
>> ../../../boost/numeric/ublas/
>> expression_types.hpp: In member function ‘const E&
>> boost::numeric::ublas::vector_expression<E>::operator()() const [with E =
>> boost::numeric::ublas::twist]’:
>> twist.cpp:37: instantiated from here
>> ../../../boost/numeric/ublas/expression_types.hpp:184: error: invalid
>> static_cast from type ‘const
>> boost::numeric::ublas::vector_expression<boost::numeric::ublas::twist>*
>> const’ to type ‘const boost::numeric::ublas::twist*’
>>
>> Do you have any idea of where is my mistake ?
>>
>> Thanks,
>>
>> kayhman
>>
>> P.S. : a small example is enclosed.
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> ublas mailing list
>> ublas_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/ublas
>>
>>
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
>