toon-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Toon-members] TooN Matrix--->Access to the data structure?


From: E. Rosten
Subject: Re: [Toon-members] TooN Matrix--->Access to the data structure?
Date: Mon, 28 Sep 2009 18:54:49 +0100 (BST)
User-agent: Alpine 2.00 (LSU 1167 2008-08-23)

On Mon, 28 Sep 2009, "Gabriel Nützi" wrote:

Hello

I really need quick help

How can I get the data pointer of a TooN Matrix or Vector like:
Matrix<> A(3,1)

I need a pointer to the stored data because I want to copy this to matlab in 
c++ by memcpy()...

&A(0,0) works only for the first element, its dynamic.....

Can anybody help me? Whats the correct Syntax?

Thanks alot!

If you declare:

Matrix<> A(3, 1);

Then the data is contiguous and &A(0,0) will give you the pointer to the first element, so you can to use memcpy. However, if your matrix is ColMajor, then you might not get the right answer.

However, if you use slices, the data is not contiguous, so:

Matrix<> A(3, 3);

&A.slice(2,2)(0,0) //You don't want to memcpy this pointer!


The best solution is to write a function which does a double for-loop over the matrix and copies the data. This will work slices, ColMajor, RowMajor and so on. Something like:

template<int R, int C, class P, class B>
void matrix_copy(const Matrix<R, C, P, B>& in, P* out)
{
   for(int r=0; r < in.num_rows(); r++)
    for(int c=0; c < in.num_cols(); c++)
     *out++ = in[r][c];
}

Swap the order of the loops if matlab stores things as column major.

-Ed


--
(You can't go wrong with psycho-rats.)(http://mi.eng.cam.ac.uk/~er258)

/d{def}def/f{/Times s selectfont}d/s{11}d/r{roll}d f 2/m{moveto}d -1
r 230 350 m 0 1 179{ 1 index show 88 rotate 4 mul 0 rmoveto}for/s 12
    d f pop 235 420 translate 0 0 moveto 1 2 scale show showpage

reply via email to

[Prev in Thread] Current Thread [Next in Thread]