[ITK-users] Multiply VariableSizeMatrix by VariableLengthVector

Francois Budin francois.budin at kitware.com
Mon Sep 19 12:12:07 EDT 2016


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> 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
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> 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
>
> Follow this link to subscribe/unsubscribe:
> 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/98519a95/attachment.html>


More information about the Insight-users mailing list