<div dir="ltr"><font color="#000000" face="Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif">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?</font><br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 7, 2017 at 10:27 PM, Nick Cullen via Insight-users <span dir="ltr"><<a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="color:#000;background-color:#fff;font-family:Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:13px"><div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14483" dir="ltr">Hi Friends !!</div><div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14483" dir="ltr"><br></div><div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14483" dir="ltr">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:</div><div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14483" dir="ltr"><br></div><div id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14483" dir="ltr">```</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14514">    typedef typename ImageType::DirectionType ImageDirectionType;    </div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14515">    ImageDirectionType * direction = const_cast<ImageDirectionType *>( &image->GetDirection() );</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14516"><br id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14517"></div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14518">    typedef typename ImageDirectionType::<wbr>InternalMatrixType DirectionInternalMatrixType;</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14519">    DirectionInternalMatrixType * fixed_matrix = const_cast<<wbr>DirectionInternalMatrixType *>( &direction->GetVnlMatrix() );</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14520"><br id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14521"></div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14522">    const vnl_matrix<double> vnlmat1 = fixed_matrix->as_matrix();</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14523">    vnl_matrix<double> * vnlmat2 = const_cast<vnl_matrix<double> *>( &vnlmat1 );</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14524"><br id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14525"></div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14526">    typedef itk::PyVnl<double> PyVnlType;</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">    PyObject * mymatrix = PyVnlType::_<wbr>GetArrayViewFromVnlMatrix( vnlmat2 );</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">```</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527"><br></div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">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() ... -__-</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527"><br></div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527"><br></div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">I know that this works:</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527"><br></div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">```</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14561">    vnl_matrix<double> * vnlmat = new vnl_matrix<double>;</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14562">    vnlmat->set_size(2,3);</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14563">    vnlmat->fill(0);</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14564">    vnlmat->put(1,2,1.3);</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14565">    vnlmat->put(1,0,2);</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14566">    std::cout << vnlmat << std::endl;</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14567"><br id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14568"></div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14569">    typedef itk::PyVnl<double> PyVnlType;</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14570">    PyObject * mymatrix = PyVnlType::_<wbr>GetArrayViewFromVnlMatrix( vnlmat );</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14570">```</div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14570"><br></div><div dir="ltr" id="m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14570">Any help above is MUCH appreciated !!!!</div></div></div><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/<wbr>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" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>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" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_<wbr>FAQ</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/<wbr>mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><span style="font-size:12.8px;color:rgb(136,136,136)">Samuel Gerber</span><br style="font-size:12.8px;color:rgb(136,136,136)"><span style="font-size:12.8px;color:rgb(136,136,136)">R&D Engineer</span><br style="font-size:12.8px;color:rgb(136,136,136)"><span style="font-size:12.8px;color:rgb(136,136,136)">Kitware, Inc.</span><br></div></div>
</div>