[Insight-developers] [ITK + Python] Wrapping classes proposal

Gaetan Lehmann gaetan.lehmann at jouy.inra.fr
Wed Jun 15 09:35:35 EDT 2005


On Wed, 15 Jun 2005 14:12:37 +0200, Benoit Regrain  
<benoit.regrain at creatis.insa-lyon.fr> wrote:

>>> I have finished to mix our 2 codes. The result is very good and offers  
>>> a simple use
>>> But with a first parse of the itk classes :-(
>>> I have used my parsing and adapted it to your classes. I have added  
>>> some usefull
>>> methods in classes to have facilities.
>>
>> Great:-), but sadely you took an old version of my module, and lots of  
>> things are better now, without talking of New method facilities (dict  
>> interface for types, no names with _ prefix in itk module, better  
>> management of __call__ to be consistent with vtk, ...)
>> I'm modifying it to integrate changes.
> Where could I get the last version of your module ?

http://voxel.jouy.inra.fr/darcs/pitk
it's a darcs repository, but you can get last version without darcs

I attach changes I made to your module (in fact, I import your changes in  
mine).

Some comments :
I import import itkClassParser instead of import everything in it to be  
able to keep only interesting attributes (for user) in itk module
I use True and False instead of 1 and 0
I haven't imported ItkBase because the unique method it contains is used  
only in one class. But it may be nice to have one common class for all itk  
classes
I have used ''.join([]) instead of string.join([], '') because string.join  
should be deprecated in future python
I remove ITK_ prefix of types (itk.ITK_US -> itk.US). itk.US seems enough  
to me :-)


>
>
>> Also, I don't really understand the can_instanciate method : some  
>> classes can be instanciated without New method, just with () (Ex:  
>> itk.Index[2]())
> But some classes found like ImageToImageFilter aren't instanciable  
> because
> they haven't the ::New method (in the C++ code). The can_instanciate  
> method
> is to differenciate super classes and instanciable classes

ok
To be consistent with VTK, I have made classes callable (it delegates to  
New if New exists). Doing that unify classes with New method and classes  
without New method.
As there is no way to know in a class is really callable, I'm not sure  
this method is really useful, or it should return True (when New method is  
avaible) or Perhaps if New is not avaible ;-)

>
>
>>
>>>
>>> In your solution, you have kept the _New, _Pointer, _SuperClass, etc.  
>>> extentions
>>> to create corresponding methods New, Pointer, SuperClass. What is the  
>>> interest
>>> to keep Pointer, Superclas, etc. ? Have the New method seems to me the  
>>> only
>>> usefull method.
>>
>> I don't know if other methods are useful. In doubt, I kept them. The  
>> goal was to make everything in InsightToolkit module avaible in itk  
>> module.
> But in your solution, you don't make difference between
>  - classes : _Pointer, _SuperClass
>  - methods : _New

you're right, but is it really a problem ? Everything is object in python  
;-)
I don't care to remove them : I don't use them, and I don't know if they  
are useful.

But there is a problem with your module : static methods such as  
InsightToolkit.itkVersion_GetITKVersion() are not avaible :-/

> Having methods is usefull but I don't see the interest to have the  
> _SuperClass.
> Concerning _Pointer, it may be usefull, but I'm not sure.
>
>
>
>>>> Can we get your code somewhere ?
>>> Yes, I have made a CVS repository on our server :
>>>    CVSROOT :  
>>> :pserver:anonymous at cvs.creatis.insa-lyon.fr:2402/cvs/public
>>>    password  : anonymous Module name : itkWrapping
>>>
>>> All is in the python directory :
>>>  itkParser.py : the parser of the itk classes
>>>  itk.py : creation of classes
>>>  itkTestX.py : 3 tests presenting the use and limitations
>
> Benoit Regrain



-- 
Gaetan Lehmann <gaetan.lehmann at jouy.inra.fr>
Tel: +33 1 34 65 29 66
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
Web: http://voxel.jouy.inra.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: itk2.py
Type: application/octet-stream
Size: 10048 bytes
Desc: not available
Url : http://www.itk.org/mailman/private/insight-developers/attachments/20050615/a9c59e75/itk2.obj


More information about the Insight-developers mailing list