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

Benoit Regrain benoit.regrain at creatis.insa-lyon.fr
Thu Jun 16 10:14:01 EDT 2005



----- Original Message ----- 
From: "Gaetan Lehmann" <gaetan.lehmann at jouy.inra.fr>
To: "Benoit Regrain" <benoit.regrain at creatis.insa-lyon.fr>; 
<insight-developers at itk.org>
Sent: Wednesday, June 15, 2005 3:37 PM
Subject: Re: [Insight-developers] [ITK + Python] Wrapping classes proposal


>> 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 :-)
It's a very good idea


> ho, and I forgot : items() is now called keys() to be consistent with dict 
> interface :-)
Good. It's better to have the same use than a dict like you have made (by
adding some others methods too).



>>>> 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 ;-)
I think that can_instanciable isn't working in all cases. So I have removed 
it :-(




I have simplified our solution :
 - Consider the itkVersion that is not a template class.
    We were using a liaison class (ItkClassWithoutType) that
    will offer all static methods accessible in itkVersion, like 
GetITKVersion.
    The wrapping creates the itkVersion_GetITKVersion method too.
    So, I have removed this liaison class.
    Thus, now, when I write itk.Version, I directly have the itkVersion 
class
 - Consider the itkImage that is a template class.
    I'm using the same deduction to remove the ItkClassType and direcly
    call the itk wrapped class.
    For example : itk.Image["US2"] returns the class 
'itkImage_2D.itkImageUS2'
 - I keep the first level for template classe (ItkClass).

Removing the ItkClassType class removes :
 - all addons that you have made (while the call of the New method).
   But it's always possible to add them directly to the wrapped itk class 
:-)
 - the __name__ and __type__ variables added.
   But it's always possible to add or change them directly to the wrapped 
itk class :-)
   But I'm not sure that's a good idea to change the class name of wrapped 
itk classes.
   Moreover, not all itk classes will be changed (I think of itkXxxPtr or 
itkXxx_Pointer
   classes)

But in an other hand, now, the ITK wrappers must generate the python code 
for the
only python class ItkClass. That will simplify the realisation of our 
solution.

Now, the last problem is always the mangled name of wrapped itk classes. If 
we had
some consistent rules concerning the mangled name, our solution may work in 
all cases
(by adding a variable on wrapped itk classes) :-)
It will be nice that an ITK worker answers us on this point...




>>>>>> 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



More information about the Insight-developers mailing list