Boost logo

Boost :

From: Job Mulder (Job_at_[hidden])
Date: 2005-12-07 09:04:25


I have some requests for the uBlas and quaternion libraries, call it my
christmas wish-list ;) These are perhaps different topics, but in my
current project, they're sort of interwoven. Feel free to pick my mail
apart.

background:
I'm writing a Kalman filter with uBlas, based on Matlab code written by
my colleagues. I encountered a few points of improvement (IMO). Maybe
these points are not really supposed to be part of uBlas, in which case
I would like to see them in some other component ;)

wish-list:
*** ublas
* a solution to the error at the bottom of the mail...
*assign an array of values to a vector (of known length)
*assign an array of values to a dense matrix (of known size, serialized
input)
*reverse of these operations

*assign a single value to all elements of a vector (of known length)
*assign a single value to all elements of a matrix (of known size,
serialized input)

*assignment of a part of a matrix to a same-size part of another matrix.
currently, this has to be done with a number of range-operators. I've
written a small wrapper for this, but I think there is a better /
cleaner way.

template <typename value_type>
void assignSubMatrix(boost::numeric::ublas::matrix<value_type>& target,
int target_row, int target_col, const
boost::numeric::ublas::matrix<value_type>& source, int source_row, int
source_col, int cols, int rows)
{
        using namespace boost::numeric::ublas;
        matrix_range<Matrix>
src_range(source,range(source_row,source_col),
range(source_row+rows-1,source_col+cols-1));
        matrix_range<Matrix>
tgt_range(target,range(target_row,target_col),
range(target_row+rows-1,target_col+cols-1));
        tgt_range = src_range;
}

------------------------------------------------------------------------
----------------------------------------------------------------------

*** quaternion
* direct assignment to component 0..3 of the quaternion, i.e. quat.q0 =
1.0
* assignment from a vector / array of values
* quaternion to (3x3) rotation matrix (common orientation
representation)
* quaternion to euler angles (common aerospace orientation
representation)
* reverse of these operations

PS: I have the code for transforming a quaternion to rotation matrix or
euler angles if anyone wants to pick this up.

------------------------------------------------------------------------
----------------------------------------------------------------------
I encountered this error with the ublas library when compiled with
Visual C++ 2005 Express. It's probably my own fault, but I can't figure
it out.
Please explain:

// fixed size vector definition
#define VECTOR(N,T) class Vector ## N : public blas::vector<T,
blas::bounded_array<T,N> > { \
        typedef blas::vector<T, blas::bounded_array<T,N> > Base_vector;
\
public:
\
        /* Default construction */
\
        Vector ## N () : Base_vector(N) {}
\
        /* Construction and assignment from an array of values */
\
        Vector ## N (const T& value) : Base_vector(N)
\
        { for (int i=0;i<N;++i) data()[i] = value; }
\
        /* Construction and assignment from a uBLAS vector expression or
copy assignment */ \
        template <class R> Vector ## N (const
blas::vector_expression<R>& r) : Base_vector(r) {} \
        template <class R> void operator=(const
blas::vector_expression<R>& r)
\
        { Base_vector::operator=(r); }
\
        template <class R> void operator=(const Base_vector& r)
\
        { Base_vector::operator=(r); }
\
        void operator=(const T* values)
\
        { for (int i=0;i<N;++i) data()[i] = values[i]; }
\
}

VECTOR(3,double); // this defines Vector3, a 3-element vector
typedef boost::math::quaternion<double> Quaternion;

void determineOrientation(Vector3 acc, Vector3 mag, Quaternion& q_gs)
{
        Vector3 tmp = boost::numeric::ublas::outer_prod(acc,mag);
}

This gives the following error:
>z:\kalman\src\kalmanfiltermt.cpp(129) : error C2440: 'initializing' :
cannot convert from
'boost::numeric::ublas::vector_matrix_binary<E1,E2,F>' to 'Vector3'
1> with
1> [
1>
E1=boost::numeric::ublas::vector<double,boost::numeric::ublas::bounded_a
rray<double,3>>,
1>
E2=boost::numeric::ublas::vector<double,boost::numeric::ublas::bounded_a
rray<double,3>>,
1> F=boost::numeric::ublas::scalar_multiplies<double,double>
1> ]
1> No constructor could take the source type, or constructor
overload resolution was ambiguous

I've tried many different explicit template instantiations for
outer_prod, but I don't know which to use, since none of them worked.

-----------------------------------------------------------------------
Job P. Mulder
Software Engineer
Xsens Motion Technologies B.V.
http://www.xsens.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk