[Insight-developers] itk and ipython interaction enhancement

Gaetan Lehmann gaetan.lehmann at jouy.inra.fr
Thu Apr 7 10:24:40 EDT 2005


Hi,

I wrote a small module for python which give an easier access to itk  
classes (file in attachement).
all classes are in itk module and are not prefixed with itk, template  
types are attributes of the filter class, and methods of a filter is  
avaible as attribute of the type.
For example itkRescaleIntensityImageFilterF2F2_New() is called with  
itk.RescaleIntensityImageFilter.F2F2.New().
The main difference with InsightToolkit module is for completion with  
ipython. When I heat <tab>, I can easily find the class I need. With  
InsightToolkit module, it's really hard, because there is so much  
attributes in the module.


Another interesting feature with this module, is to easily change filter  
type in all the script. As we do in C++, we can "declare" types which will  
be used by several filters :

	inType = 'F2'
	outType = 'F2'

and use the filters

	rescale = itk.RescaleIntensityImageFilter[inType+outType].New()
	...

Please tell me if you think that this module can be interesting. I can  
make it really cleaner and faster :-)




One strange thing with ITK python wrapper is the presence of a class  
object in the list returned by dir fucntion :

3> f = itk.RescaleIntensityImageFilter['F2F2'].New()

4> dir(f)
4>
['AbortGenerateDataOff',
  'AbortGenerateDataOn',
  'AddObserver',
  'BeforeThreadedGenerateData',
  'CanRunInPlace',
  'CreateAnother',
  'DebugOff',
  'DebugOn',
  'Delete',
  'EnlargeOutputRequestedRegion',
  'GetAbortGenerateData',
  'GetCommand',
  'GetDebug',
  'GetFunctor',
  'GetInPlace',
  'GetInput',
  'GetInputMaximum',
  'GetInputMinimum',
  'GetInputs',
  'GetMTime',
  'GetMetaDataDictionary',
  'GetMultiThreader',
  'GetNameOfClass',
  'GetNumberOfInputs',
  'GetNumberOfOutputs',
  'GetNumberOfThreads',
  'GetNumberOfValidRequiredInputs',
  'GetOutput',
  'GetOutputMaximum',
  'GetOutputMinimum',
  'GetOutputs',
  'GetPointer',
  'GetProgress',
  'GetReferenceCount',
  'GetReleaseDataBeforeUpdateFlag',
  'GetReleaseDataFlag',
  'GetScale',
  'GetShift',
  'GraftNthOutput',
  'GraftOutput',
  'HasObserver',
  'InPlaceOff',
  'InPlaceOn',
  'InvokeEvent',
  'IsNotNull',
  'IsNull',
  'MakeOutput',
  'Modified',
  'PrepareOutputs',
  'Print',
  'PrintSelf',
  'PropagateRequestedRegion',
  'Register',
  'ReleaseDataBeforeUpdateFlagOff',
  'ReleaseDataBeforeUpdateFlagOn',
  'ReleaseDataFlagOff',
  'ReleaseDataFlagOn',
  'RemoveAllObservers',
  'RemoveObserver',
  'ResetPipeline',
  'SetAbortGenerateData',
  'SetDebug',
  'SetFunctor',
  'SetInPlace',
  'SetInput',
  'SetMetaDataDictionary',
  'SetNumberOfThreads',
  'SetOutputMaximum',
  'SetOutputMinimum',
  'SetProgress',
  'SetReferenceCount',
  'SetReleaseDataBeforeUpdateFlag',
  'SetReleaseDataFlag',
  'UnRegister',
  'Update',
  'UpdateLargestPossibleRegion',
  'UpdateOutputData',
  'UpdateOutputInformation',
  'UpdateProgress',
  '__class__',
  '__del__',
  '__delattr__',
  '__dict__',
  '__doc__',
  '__getattr__',
  '__getattribute__',
  '__hash__',
  '__init__',
  '__module__',
  '__new__',
  '__reduce__',
  '__reduce_ex__',
  '__repr__',
  '__setattr__',
  '__str__',
  '__swig_getmethods__',
  '__swig_setmethods__',
  '__weakref__',
  'this',
  'thisown',
  <class  
'itkRescaleIntensityImageFilter.itkRescaleIntensityImageFilterF2F2_PointerPtr'>]


This class object make ipython fail to complete attribute when <tab> is  
heat. It can be fixed in ipython by replacing

	words = dir(object)

by

	words = [w for w in dir(object) if isinstance(w, str)]

in FlexCompleter.py, but I think it should be fixed in ITK.

Regards

Gaetan.

-- 
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)
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: itk.py
Type: application/octet-stream
Size: 1666 bytes
Desc: not available
Url : http://www.itk.org/mailman/private/insight-developers/attachments/20050407/27ac5775/itk.obj


More information about the Insight-developers mailing list