Boost logo

Ublas :

From: Manoj Rajagopalan (rmanoj_at_[hidden])
Date: 2008-05-08 22:14:14

Hi Troy,

> 1. Does Boost Matrix provide a simple way to convert between row major
> and column major formats? Or is it do it yourself.

==== AFAIK, this is DIY yet simple. Create a column major matrix of same
dimensions and use the = operator to assign the row major matrix. This
should work.

> 2. Is the a way to take an array of 16 floats in clomun major order and
> put them in a Boost 4x4 Matrix ? Or is it do it yourself.
> GLfloat lightModelview[16], lightProjection[16];
> glGetFloatv(GL_PROJECTION_MATRIX, lightProjection);
> glGetFloatv(GL_MODELVIEW_MATRIX, lightModelview);
==== If you mean that you want to be able to view say lightModelview[16]
as a 4x4 matrix then you can do the following:

matrix<GLfloat, column_major, shallow_array_adaptor<GLfloat> >
     lightModelview_asMatrix44(4, 4,

Now, lightModelview_asMatrix44 is a 4x4 column major matrix which,
because of shallow_array_adaptor, doesn't allocate any space but only
references the statically allocated lightModelView[16] array. The first
2 parameters in the constructor are the matrix dimensions. The third
parameter is a vector type that stores the matrix element data in a
linearized way. Here, shallow_array_adaptor tells uBLAS not to allocate
space but to reference the block beginning at the pointer lightModelview
and that this vector is 16 elements long.

You can find the definition of shallow_array_adaptor in storage.hpp

To provide access to the GLfloat array, say in a glLoadMatrixf() call,
just use which returns a
pointer the lightModelview pointer. Of course, you'd do this in a
different scope where lightModelview[16] may be accessible only through
this matrix.

> 3. Does Boost matrix handle multiplying Matrixes in different formats (
> row and column major) automatically ?

==== AFAIK uBLAS should. It is possible that uBLAS does not provide an
optimized kernel for every possible combination of storage layouts.
  Writing a small to answer this should be easy.