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

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 ;)

*** 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
*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;
        tgt_range = src_range;


*** quaternion
* direct assignment to component 0..3 of the quaternion, i.e. quat.q0 =
* assignment from a vector / array of values
* quaternion to (3x3) rotation matrix (common orientation
* quaternion to euler angles (common aerospace orientation
* 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;
        /* 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> 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.

Boost list run by bdawes at, gregod at, cpdaniel at, john at