<html><head></head><body><div style="color:#000; background-color:#fff; font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px"><div id="yui_3_16_0_ym19_1_1502159025493_24590" dir="ltr"><span id="yui_3_16_0_ym19_1_1502159025493_26306">Oh and to be clear, it gives me random numbers <i>after</i> I hit the numpy view and such (i.e.g </span>ndarrview = numpy.asarray(memview).view(dtype = numpydatatype).reshape(shape).view(numpy.ndarray))</div> <div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" style="display: block;"> <div style="font-family: Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 13px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div dir="ltr"><font size="2" face="Arial"> On Monday, August 7, 2017 10:27 PM, Nick Cullen <nickmarch31@yahoo.com> wrote:<br></font></div> <br><br> <div class="y_msg_container"><div id="yiv1576732323"><div><div style="color:#000;background-color:#fff;font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px;"><div id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14483" dir="ltr">Hi Friends !!</div><div id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14483" dir="ltr"><br></div><div id="yiv1576732323yui_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="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14483" dir="ltr"><br></div><div id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14483" dir="ltr">```</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14514"> typedef typename ImageType::DirectionType ImageDirectionType; </div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14515"> ImageDirectionType * direction = const_cast<ImageDirectionType *>( &image->GetDirection() );</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14516"><br id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14517"></div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14518"> typedef typename ImageDirectionType::InternalMatrixType DirectionInternalMatrixType;</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14519"> DirectionInternalMatrixType * fixed_matrix = const_cast<DirectionInternalMatrixType *>( &direction->GetVnlMatrix() );</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14520"><br id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14521"></div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14522"> const vnl_matrix<double> vnlmat1 = fixed_matrix->as_matrix();</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14523"> vnl_matrix<double> * vnlmat2 = const_cast<vnl_matrix<double> *>( &vnlmat1 );</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14524"><br id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14525"></div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14526"> typedef itk::PyVnl<double> PyVnlType;</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14527"> PyObject * mymatrix = PyVnlType::_GetArrayViewFromVnlMatrix( vnlmat2 );</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14527">```</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14527"><br></div><div dir="ltr" id="yiv1576732323yui_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="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14527"><br></div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14527"><br></div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14527">I know that this works:</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14527"><br></div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14527">```</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14561"> vnl_matrix<double> * vnlmat = new vnl_matrix<double>;</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14562"> vnlmat->set_size(2,3);</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14563"> vnlmat->fill(0);</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14564"> vnlmat->put(1,2,1.3);</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14565"> vnlmat->put(1,0,2);</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14566"> std::cout << vnlmat << std::endl;</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14567"><br id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14568"></div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14569"> typedef itk::PyVnl<double> PyVnlType;</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14570"> PyObject * mymatrix = PyVnlType::_GetArrayViewFromVnlMatrix( vnlmat );</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14570">```</div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14570"><br></div><div dir="ltr" id="yiv1576732323yui_3_16_0_ym19_1_1502159025493_14570">Any help above is MUCH appreciated !!!!</div></div></div></div><br><br></div> </div> </div> </div></div></body></html>