<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Title" content="">
<meta name="Keywords" content="">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Helvetica Neue";
        panose-1:2 0 5 3 0 0 0 2 0 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.msoIns
        {mso-style-type:export-only;
        mso-style-name:"";
        text-decoration:underline;
        color:teal;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body bgcolor="white" lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hello,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Is there a method named something like “_GetArrayFromVnlMatrix”? This should perform a copy of the data, as opposed to just a “view”.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Brad<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-left:.5in"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">Samuel Gerber <samuel.gerber@kitware.com><br>
<b>Date: </b>Tuesday, August 8, 2017 at 7:57 AM<br>
<b>To: </b>Nick Cullen <nickmarch31@yahoo.com><br>
<b>Cc: </b>"insight-users@itk.org" <insight-users@itk.org><br>
<b>Subject: </b>Re: [ITK] [ITK-users] vnl matrix to numpy array gives random numbers<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:.5in">
<span style="font-family:"Helvetica Neue",sans-serif;color:black">I'd guess there is something funky going with vnl_matrix_fixed. From the docs (
<a href="https://github.com/vxl/vxl/blob/master/core/vnl/vnl_matrix_fixed.h">https://github.com/vxl/vxl/blob/master/core/vnl/vnl_matrix_fixed.h</a> ) it says that the data resides on the stack. From your code snippet it is not exactly clear to me who owns the
 data in fixed_matrix, probably image. Might it be that image gets removed before you use the array view?</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="margin-left:.5in">On Mon, Aug 7, 2017 at 10:27 PM, Nick Cullen via Insight-users <<a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14483">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">Hi Friends !!<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14483">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14483">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">I'm trying to use itkPyVnl directly in ITK, but I must be getting something wrong with pointers... The following
 just gives me random numbers:<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14483">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14483">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">```<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14514">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    typedef typename ImageType::DirectionType ImageDirectionType;    <o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14515">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    ImageDirectionType * direction = const_cast<ImageDirectionType *>( &image->GetDirection() );<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14516">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14518">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    typedef typename ImageDirectionType::InternalMatrixType DirectionInternalMatrixType;<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14519">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    DirectionInternalMatrixType * fixed_matrix = const_cast<DirectionInternalMatrixType *>( &direction->GetVnlMatrix()
 );<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14520">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14522">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    const vnl_matrix<double> vnlmat1 = fixed_matrix->as_matrix();<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14523">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    vnl_matrix<double> * vnlmat2 = const_cast<vnl_matrix<double> *>( &vnlmat1 );<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14524">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14526">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    typedef itk::PyVnl<double> PyVnlType;<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    PyObject * mymatrix = PyVnlType::_GetArrayViewFromVnlMatrix( vnlmat2 );<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">```<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">I've tried a million different things and have problems either 1) due to the constness of ->as_matrix() and others
 or 2) due to "taking the address of a temporary object" with ->as_matrix() ... -__-<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">I know that this works:<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">```<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14561">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    vnl_matrix<double> * vnlmat = new vnl_matrix<double>;<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14562">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    vnlmat->set_size(2,3);<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14563">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    vnlmat->fill(0);<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14564">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    vnlmat->put(1,2,1.3);<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14565">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    vnlmat->put(1,0,2);<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14566">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    std::cout << vnlmat << std::endl;<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14567">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14569">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    typedef itk::PyVnl<double> PyVnlType;<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14570">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">    PyObject * mymatrix = PyVnlType::_GetArrayViewFromVnlMatrix( vnlmat );<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14570">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">```<o:p></o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14570">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14570">
<p class="MsoNormal" style="margin-left:.5in;background:white"><span style="font-size:10.0pt;font-family:"Helvetica Neue",sans-serif;color:black">Any help above is MUCH appreciated !!!!<o:p></o:p></span></p>
</div>
</div>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:.5in">
<br>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" 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" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/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" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/insight-users" target="_blank">http://public.kitware.com/mailman/listinfo/insight-users</a><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal" style="margin-left:.5in"><br>
<br clear="all">
<o:p></o:p></p>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<p class="MsoNormal" style="margin-left:.5in">-- <o:p></o:p></p>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:9.5pt;color:#888888">Samuel Gerber<br>
R&D Engineer<br>
Kitware, Inc.</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>