[ITK-users] Multiply VariableSizeMatrix by VariableLengthVector

Cyril Mory cyril.mory at creatis.insa-lyon.fr
Mon Sep 19 16:02:47 EDT 2016


Thanks for this reply, but part of it is not what I was looking for. In 
my understanding, the solution you suggested allows to multiply a 
VariableSizeMatrix with a Vector, and then store the result into a 
VariableLenghtVector. But my input is also a VariableLengthVector, not a 
Vector.

So let me be clearer: I want to multiply a VariableSizeMatrix with a 
VariableLengthVector. Is there a way to extract from this 
VariableLengthVector something that can be multiplied with 
VariableSizeMatrix.GetVnlMatrix() ? Maybe I should copy my 
VariableLengthVector into a vnl_vector ?

I do not know the size of that VariableLengthVector at compile time, so 
I cannot create an itk::Vector of the correct size.

Best,
Cyril

On 09/19/2016 06:12 PM, Francois Budin wrote:
> Hello Cyril,
>
> For the matrix conversion, you can use itk::Matrix::GetVnlMatrix() to 
> extract the matrix from the itk::Matrix object, and use assign that 
> vnl matrix to your itk::VariableLengthVector using operator=(const 
> vnl_matrix< T > &matrix).
>
> itk::Matrix<float,3,3> mat;
> itk::VariableSizeMatrix<float> v_mat;
> v_mat = mat.GetVnlMatrix();
>
> For the vectors, you could get access to the data from itk::Vector and 
> pass the pointer to the data to your itk::VariableLengthVector.
> itk::Vector<float> vec;
> itk::VariableLengthVector<float> v_vec;
> v_vec.SetSize(3);
> v_vec.SetData(vec.GetDataPointer(),false);
>
> Be careful with the memory management for the vector as the data is 
> still managed by the itk::Vector in this example, so the data will be 
> destroyed if the vector is destroyed (if you go out of scope).
>
> On Mon, Sep 19, 2016 at 11:05 AM, Cyril Mory 
> <cyril.mory at creatis.insa-lyon.fr 
> <mailto:cyril.mory at creatis.insa-lyon.fr>> wrote:
>
>     Hi ITK users,
>
>     I have some working ITK code with itk::Matrix by itk::Vector
>     multiplications, and I need to change to itk::VariableSizeMatrix
>     and itk::VariableLengthVector.
>
>     Simply writing
>
>     "myResultVector = myMatrix * myInputVector"
>
>     works with itk::Matrix and itk::Vector objects, but not with their
>     VariableSize/Length counterparts. Is there a way to do it, other
>     than writing the matrix by vector multiplication for-loops myself ?
>
>     Regards,
>
>     Cyril
>
>     _____________________________________
>     Powered by www.kitware.com <http://www.kitware.com>
>
>     Visit other Kitware open-source projects at
>     http://www.kitware.com/opensource/opensource.html
>     <http://www.kitware.com/opensource/opensource.html>
>
>     Kitware offers ITK Training Courses, for more information visit:
>     http://www.kitware.com/products/protraining.php
>     <http://www.kitware.com/products/protraining.php>
>
>     Please keep messages on-topic and check the ITK FAQ at:
>     http://www.itk.org/Wiki/ITK_FAQ <http://www.itk.org/Wiki/ITK_FAQ>
>
>     Follow this link to subscribe/unsubscribe:
>     http://public.kitware.com/mailman/listinfo/insight-users
>     <http://public.kitware.com/mailman/listinfo/insight-users>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20160919/edc9a65c/attachment.html>


More information about the Insight-users mailing list