cdef class CvArr:
   def c_CvArr* handle(self):
       raise NotImplementedError

cdef class IplImage(CvArr):
    cdef c_IplImage* image
    def c_CvArr* handle(self):
       return <c_CvArr*>self.image

cdef class CvMat(CvArr):
    cdef c_CvMat *cvmat
    def c_CvArr* handle(self):
       return <c_CvArr*>self.cvmat


Mmm... just a use case for "cdef properties" managed by calling
get/setters in the vtable?


On Thu, May 21, 2009 at 9:16 PM, Chris Colbert <[email protected]> wrote:
> the problem is that the C library has several functions that will accept one
> of many types of arrays.
>
> The function parameter type is CvArr whose definition is (in C):
>
> typedef void CvArr;
>
> and the functions are declared as accepting CvArr* types as arguments.
>
> two of the types I am wrapping are IplImage and CvMat both of which can be
> passed as CvArr*.
>
> I would like to make python callable functions that accept either instance
> of IplImage or CvMat (which I have created as extension types).
>
> Unfortunately, i haven't yet been able to figure it out through various
> tinkering with subclassing, casting, or void pointers....
>
>
> I would greatly appreciate any insight one could give..
>
> Thanks and Cheers!
>
> Chris
>
> On Thu, May 21, 2009 at 7:05 PM, Chris Colbert <[email protected]> wrote:
>>
>> I have certain functions that should accept types of IplImage or CvMat
>>
>> I have the two types declared as inheriting from a generic CvArr as such
>>
>> cdef class CvArr:
>>        cdef void* thisptr
>>
>> cdef class IplImage(CvArr):
>>       .....
>>
>> cdef class CvMat(CvArr):
>>       ....
>>
>>
>> and a function declared like this:
>>
>> def cvSmooth(CvArr src, .....):
>>       c_lib.cvSmooth(src.thisptr, ....)
>>
>> when compiling and calling that function with instances of IplImage, the
>> Cython compiler complains that src is not a CvArr.
>>
>> Is there a way around this?
>>
>> Chris
>
>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>
>



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to