[PyQt] SIP PyList of SIP Wrapped Objects

Jay L. jlaura at asu.edu
Wed Oct 5 22:13:13 BST 2016


I have a struct with an associated SIP specification file:

class SiftPoint{

    %TypeHeaderCode
      #include "cudaSift.h"
      #include "numpy/arrayobject.h"
    %End

    %TypeCode
      PyObject *makearray(float array[], size_t size)
      {
      import_array();
      npy_intp dim = size;
      return PyArray_SimpleNewFromData(1, &dim, NPY_FLOAT32, (void *)array);
      }
    %End

    public:
      float xpos;
      float ypos;
      float scale;

      //float data[128];
      float get_descriptor();
      %MethodCode
        return makearray(sipCpp->data, 128);
      %End

I have been able to work with the array data by using method code and
passing out to a numpy array (which is working well).

I then have a second struct also exposed as a class that contains a pointer
to some number of SiftPoint instances.

  //SiftData
  class SiftData{

  %TypeHeaderCode
    #include "cudaSift.h"
  %End

  public:
    int numPts;
    int maxPts;

    //SiftPoint *h_data;
    SIP_PYLIST host_data();
    %MethodCode
      size_t size = sipCpp->numPts;
      PyObject *l = PyList_New(sipCpp->numPts);
      for (size_t i = 0; i != size; i++){

        SiftPoint sp = sipCpp->h_data[i];
        printf("%f, %f\n", sp.xpos, sp.ypos);
        PyObject *p = sipConvertFromType((void*)(&sp),sipType_SiftPoint,
NULL);
        PyList_SetItem(l, i, p);
      }
      return l;
    %End
    //Not exposed via Python
    //SiftPoint *d_data;
  };

Here, I am trying to expose a PyList of SiftPoint instances.  My
understanding is that I need to use sipConvertFromType to convert the
already mapped type to a python type before entry into a PyList.  The above
code is compiling without issue, and I can see all of the SiftPoint class
attributes.  Unfortunately, all of the attributes are returning NaN (as
opposed to some float value).

Am I missing something in the conversion of an already mapped type?

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20161005/b96e2ff8/attachment.html>


More information about the PyQt mailing list