ok I found out that actual multiplication is no problem, my problem lies with storing the end result.<br><br>This works:<br><br> typedef itk::Matrix<double,3,4> Matrix3by4Type;<br> typedef itk::Vector<double,4> Vector4Type;<br>
<br> Matrix3by4Type Translation;<br> Vector4Type FinalOrigin;<br><br> Translation[0][0] = 1; Translation[0][1] = 0; Translation[0][2] = 0; Translation[0][3] = 2;<br> Translation[1][0] = 0; Translation[1][1] = 1; Translation[1][2] = 0; Translation[1][3] = 3;<br>
Translation[2][0] = 0; Translation[2][1] = 0; Translation[2][2] = 1; Translation[2][3] = 4;<br><br> FinalOrigin[0] = 0; FinalOrigin[1] = 0; FinalOrigin[2] = 0; FinalOrigin[3] = 1;<br><br> std::cout << "finalorigin: " << std::endl << FinalOrigin << std::endl;<br>
std::cout << "translation: " << std::endl << Translation << std::endl;<br><br> std::cout << "p : " << FinalOrigin << std::endl ;<br> std::cout << "A∗p : " << Translation*FinalOrigin << std::endl ;<br>
<br><br>// but this doesn't work:<br> <br> FinalOrigin = A*p<br><br><br>When I make the vector a 1by4 Matrix instead:<br><br>FinalOrigin *= Translation;<br> compile error: no match for ‘operator*=’ in ‘FinalOrigin *= Translation’<br>
<br> FinalOrigin *= Translation.GetTranspose();<br><br>runtime error:<br>vnl_matrix_fixed<T, num_rows, num_cols>::vnl_matrix_fixed(const vnl_matrix<T>&) [with T = double, unsigned int num_rows = 4u, unsigned int num_cols = 4u]: Assertion `rhs.rows() == num_rows && rhs.columns() == num_cols' failed.<br>
(which makes sense because the the number of rows and colums of both the vector and matrix are not the same)<br><br>So vector still seems to be the right way to go, I just can't figure out how to save it in a vector...<br>
<br><br>Does anybody know how I save my result?<br><br>cheers, Michael<br><br><br><br><br><div class="gmail_quote">On Wed, Mar 31, 2010 at 10:21 AM, michiel mentink <span dir="ltr"><<a href="mailto:michael.mentink@st-hughs.ox.ac.uk">michael.mentink@st-hughs.ox.ac.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>I'd like to do the following calculation, a translate:<br><br>A =<br>[ 1 0 0 2 ]<br>
[ 0 1 0 3 ]<br>[ 0 0 1 4 ]<br><br>B = [ x y z 1 ]<br><br>FinalOrigin = A * B' = [x+2 y+3 z+4 ]<br><br>For that, I have got the following code:<br>
<br><br><br><span style="font-family: times new roman,serif;"> typedef itk::Matrix<double,3,4> Matrix3by4Type;</span><br style="font-family: times new roman,serif;"><span style="font-family: times new roman,serif;"> typedef itk::Vector<double,4> Vector4Type;</span><br style="font-family: times new roman,serif;">
<br style="font-family: times new roman,serif;"><span style="font-family: times new roman,serif;"> Matrix3by4Type Translation;</span><br style="font-family: times new roman,serif;"><span style="font-family: times new roman,serif;"> Vector4Type FinalOrigin;</span><br>
<br><span style="font-family: times new roman,serif;">FinalOrigin[0] = origin[0]; FinalOrigin[1] = origin[1]; FinalOrigin[2] = origin[2]; FinalOrigin[3] = 1;</span><br style="font-family: times new roman,serif;"><span style="font-family: times new roman,serif;">FinalOrigin = Translation * FinalOrigin;</span><br style="font-family: times new roman,serif;">
<br><br><br>1)<br>Is it possible to multiply an itk::vector with an itk::matrix in ITK?<br><br>2)<br>There is no transpose available for the vnl_vector type, that is implemented in ITK. <br>Or is there?<br><br><br>I know that there are other methods in ITK to do translation, but for my understanding, I'd like<br>
to figure this out.<br><br>cheers, <br><br>Michael<br><br><br><br>
</blockquote></div><br>