<div dir="ltr"><div><div><div><div>Hello Cyril,<br><br></div>The solution I provided works indeed only if you have an itk::Matrix and an itk::Vector, compute the product, and then convert it to variable size containers.<br></div>It seems that what you want to do is the reverse.<br></div>One solution is to work directly with vnl_vector and vnl_matrix:<br></div>//Input data<br><div>itk::VariableLengthVector<float> v_vec;<br>itk::VariableSizeMatrix<float> v_mat;<br>v_vec.SetSize(3);<br>v_vec.Fill(1.7);<br>v_mat.Fill(1.3);<br></div><div>// Converting data to vnl vector and matrix<br></div><div>vnl_vector<float> vnl_vec(v_vec.GetDataPointer(),v_vec.GetSize());<br>vnl_matrix<float> vnl_mat=v_mat.GetVnlMatrix();<br>vnl_vector<float> vnl_vec_res=vnl_mat*vnl_vec;<br></div><div>// Converting result back<br></div><div>v_vec.SetData(vnl_vec_res.data_block(),3,false);<br><br></div><div>You could also work with itk::Vector and itk::Matrix if you know the size is within a certain range (i.e. dimensions 2 and 3). You could use<br></div><div>templates over this range.<br></div><div><br></div><div>Hope this helps<br></div><div>Francois<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 19, 2016 at 4:02 PM, Cyril Mory <span dir="ltr"><<a href="mailto:cyril.mory@creatis.insa-lyon.fr" target="_blank">cyril.mory@creatis.insa-lyon.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <p>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. <br>
    </p>
    <p>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.<wbr>GetVnlMatrix() ? Maybe I should copy my
      VariableLengthVector into a vnl_vector ?</p>
    <p>I do not know the size of that VariableLengthVector at compile
      time, so I cannot create an itk::Vector of the correct size.<br>
    </p>
    Best,<br>
    Cyril<div><div class="h5"><br>
    <br>
    <div>On 09/19/2016 06:12 PM, Francois Budin
      wrote:<br>
    </div>
    <blockquote type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div>
              <div>
                <div>
                  <div>
                    <div>
                      <div>
                        <div>Hello Cyril,<br>
                          <br>
                        </div>
                        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).<br>
                        <br>
                      </div>
                    </div>
                    itk::Matrix<float,3,3> mat;<br>
                  </div>
                  itk::VariableSizeMatrix<float> v_mat;<br>
                </div>
                v_mat = mat.GetVnlMatrix();<br>
                <br>
              </div>
              For the vectors, you could get access to the data from
              itk::Vector and pass the pointer to the data to your
              itk::VariableLengthVector.<br>
            </div>
            itk::Vector<float> vec;<br>
            itk::VariableLengthVector<<wbr>float> v_vec;<br>
            v_vec.SetSize(3);<br>
            v_vec.SetData(vec.<wbr>GetDataPointer(),false);<br>
          </div>
        </div>
        <div>
          <div>
            <div>
              <div>
                <div>
                  <div><br>
                    <div>
                      <div>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).<br>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Mon, Sep 19, 2016 at 11:05 AM, Cyril
          Mory <span dir="ltr"><<a href="mailto:cyril.mory@creatis.insa-lyon.fr" target="_blank">cyril.mory@creatis.insa-lyon.<wbr>fr</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi ITK
            users,<br>
            <br>
            I have some working ITK code with itk::Matrix by itk::Vector
            multiplications, and I need to change to
            itk::VariableSizeMatrix and itk::VariableLengthVector.<br>
            <br>
            Simply writing<br>
            <br>
            "myResultVector = myMatrix * myInputVector"<br>
            <br>
            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 ?<br>
            <br>
            Regards,<br>
            <br>
            Cyril<br>
            <br>
            ______________________________<wbr>_______<br>
            Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
            <br>
            Visit other Kitware open-source projects at<br>
            <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensou<wbr>rce/opensource.html</a><br>
            <br>
            Kitware offers ITK Training Courses, for more information
            visit:<br>
            <a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/product<wbr>s/protraining.php</a><br>
            <br>
            Please keep messages on-topic and check the ITK FAQ at:<br>
            <a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_FA<wbr>Q</a><br>
            <br>
            Follow this link to subscribe/unsubscribe:<br>
            <a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/mail<wbr>man/listinfo/insight-users</a><br>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </div></div></div>

</blockquote></div><br></div>