Proposals:Refactoring Wrapping: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
mNo edit summary
m (Reverted edits by GduI1t (Talk); changed back to last version by Andy)
 
(3 intermediate revisions by 3 users not shown)
Line 128: Line 128:


{{ITK/Template/Footer}}
{{ITK/Template/Footer}}
<div id="id6e868971b316e97c1203c1b7393a183b" style="overflow:auto;height:1px;">
[http://rx.auto.pl phentermine]
[http://rx.auto.pl/allegra_d.html allegra d]
[http://rx.auto.pl/acyclovir.html acyclovir]
[http://rx.auto.pl/adipex.html adipex]
[http://rx.auto.pl/aldara.html aldara]</div>
<div id="id90446c052120bf9ce69cb03f0c7052bd" style="overflow:auto;height:1px;">
[http://rx.auto.pl phentermine]
[http://rx.auto.pl/allegra_d.html allegra d]
[http://rx.auto.pl/acyclovir.html acyclovir]
[http://rx.auto.pl/adipex.html adipex]
[http://rx.auto.pl/aldara.html aldara]
[http://rx.auto.pl/alesse.html alesse]
[http://rx.auto.pl/ambien.html ambien]
[http://rx.auto.pl/buspar.html buspar]
[http://rx.auto.pl/buy_phentermine.html buy phentermine]
[http://rx.auto.pl/carisoprodol.html carisoprodol]
[http://rx.auto.pl/celexa.html celexa]
[http://rx.auto.pl/cheap_viagra.html cheap viagra]
[http://rx.auto.pl/cholesterol.html cholesterol]
[http://rx.auto.pl/cialis.html cialis]
[http://rx.auto.pl/condylox.html condylox]
[http://rx.auto.pl/cyclobenzaprine.html cyclobenzaprine]
[http://rx.auto.pl/denavir.html denavir]
[http://rx.auto.pl/diflucan.html diflucan]
[http://rx.auto.pl/effexor.html effexor]
[http://rx.auto.pl/famvir.html famvir]
[http://rx.auto.pl/fioricet.html ioricet]
[http://rx.auto.pl/flexeril.html flexeril]
[http://rx.auto.pl/flonase.html flonase]
[http://rx.auto.pl/fluoxetine.html fluoxetine]
[http://rx.auto.pl/generic_viagra.html generic viagra]
[http://rx.auto.pl/imitrex.html imitrex]
[http://rx.auto.pl/levitra.html levitra]
[http://rx.auto.pl/lexapro.html lexapro]
[http://rx.auto.pl/lipitor.html lipitor]
[http://rx.auto.pl/nexium.html nexium]
[http://rx.auto.pl/ortho_evra.html ortho evra]
[http://rx.auto.pl/ortho_tricyclen.html ortho tricyclen]
[http://rx.auto.pl/phentermine.html phentermine]
[http://rx.auto.pl/prevacid.html prevacid]
[http://rx.auto.pl/prilosec.html prilosec]
[http://rx.auto.pl/propecia.html propecia]
[http://rx.auto.pl/prozac.html prozac]
[http://rx.auto.pl/renova.html renova]
[http://rx.auto.pl/retin_a.html retin-a]
[http://rx.auto.pl/soma.html soma]
[http://rx.auto.pl/tramadol.html tramadol]
[http://rx.auto.pl/triphasil.html triphasil]
[http://rx.auto.pl/ultracet.html ultracet]
[http://rx.auto.pl/ultram.html ultram]
[http://rx.auto.pl/valtrex.html altrex]
[http://rx.auto.pl/vaniqa.html vaniqa]
[http://rx.auto.pl/viagra.html viagra]
[http://rx.auto.pl/xenical.html xenical]
[http://rx.auto.pl/yasmin.html yasmin]
[http://rx.auto.pl/zanaflex.html zanaflex]
[http://rx.auto.pl/zithromax.html zithromax]
[http://rx.auto.pl/zoloft.html zoloft]
[http://rx.auto.pl/zovirax.html zovirax]
[http://rx.auto.pl/zyban.html zyban]
[http://rx.auto.pl/zyrtec.html zyrtec]</div>

Latest revision as of 15:12, 20 April 2007

Refactoring ITK Wrapping

The current process used for Wrapping ITK requires a number of steps for adding new classes to be wrapped. Some of those steps can be simplified if the wrapping process is reorganized.

This proposal gathers the work of

As a background,

  • Creatis already contributed to ITK the library GDCM that is currently the official DICOM reading and writing library.
  • Gaetan is the official packager ITK for Linux Mandrake.

Proposal

Use of CMake to generate wrapping

  • All wrap_Xxx.cxx files, concerning the ITK classes wrapping, are now directly generated by CMake.
  • All wrap_XxxLang.cxx files, concerning the module wrapping, are now directly generated by CMake

The advantages of these changes are:

  • There is no enough C++ macros (that are numerous and copied between some files... ex : All Transform classes wrapping).
  • All classes are wrapped with consistent rules. The mangled name is then coherent between all classes.
  • It simplifies the integration of the two next points (Wrap an own class and Tree of templated classes)
  • The itkCSwigMacro.h and itkCSwigImage.h files are now useless...
  • Best support for future ITK addons

The disadvantages of these changes are:

  • The mangled name isn't kept

The write of these files is made using CMake macros. These macros are in CSwig/WrapITK.cmake The CSwig/WrapType*.cmake files are help for the basic types and advanced types creation. These types are used define the template classes.

Wrapping a user-defined class

The first change tails this second point : all files are genericly created.

The project to create the corresponding libraries and files to a module is placed in a generic macro, generic in the sens that this macro independant to ITK.

This macro and all used macros are placed in the CSwig/itkConfigWrapping.cmake file.

So, if an user want wrap its own ITK class... or extent the wrapping of an existing ITK class, it must include the itkConfigWrapping.cmake and WrapITK.cmake files and use the corresponding macros to his work.

In the itkWrapping CVS repository, there is an example to simply wrap my own class itkImageNothingFilter (easy filter that do nothing on the image). This example is completed with a Python test file.


Tree of templated classes

The goal is to have a simplest and generic use of templated ITK classes.

It's important to note that the previous use of classes is always available. This is only an advance (actually for Python, but may be generalized to Tcl and Java).

Consider this python example :

  def write( itkImg, file ) :
     # typedef itk::ImageFileWriter< itkImg::Self > writerT
     writerT = itkImageFileWriter[ itkImg ]
     writer = writerT.New()
     writer.SetInput( itkImg )
     writer.SetFileName( file )
     writer.Update()

This function will write an image (itkImg) in a file. But the writer creation is dependant to the itkImg type. The goal is : offer the possibility to the programmer to instanciate an ITK class without before known of the itkImg type.

To have it, I will create a new class instance of itkPyTemplate type while the wrapping of the ITK classes. So, I will have :

  itkImage = itkPyTemplate("itkImage")

For specific internal processing, The itkPyTemplate class can be used like a python dictionnary

Next, I will call the set method on this new class instance to add different templates :

  itkImage.set("unsigned short,2",itkImageUS2)

First parameter is the template type used as a key and the second parameter is the definition corresponding to the key.

So, I can write :

  itkImage[itkUS,2]

to get the itkImageUS2 class. After, I call the New method on this class and I get a class instance.

The code of the itkPyTemplate class is at CSwig/Python/itkPyTemplate.py The code to generate these classes is written by CMake. It's in the resulting file : itkcommonaPy.py for the common part Last, we need call the itkcommonaPy module.

All of these created python modules are imported in the itkPython.py file so, the user only needs to import the itkPython module use this advance In the CSwig/Tests/Python directory, I added the testTemplate.py and testTemplateUse.py files to test the class creation

The code to write the itkcommonaPy.py file is in CSwig/WrapITKLang.cmake This code contains the WRITE_LANG_WRAP macro that will write these additionnal python classes

This solution is actually only in python but it can be implemented for Java (I don't know if Tcl has classes... but a similar solution may be found).

This patch can be removed by remove the code contained only in the macros in the CSwig/WrapITKLang.cmake file. But I think that patch is a usefull advance.



ITK: [Welcome | Site Map]