Difference between revisions of "ITK/Release 4/Wrapping/BuildProcess"

From KitwarePublic
< ITK‎ | Release 4‎ | Wrapping
Jump to navigationJump to search
Line 90: Line 90:
==Example==
==Example==


Here is an example to wrap a new dummy class.
Here is an example to wrap a new dummy class. All the files are in the same directory.


CMakeLists.txt:
CMakeLists.txt:
Line 105: Line 105:
     AUTO_INCLUDE_MODULES()
     AUTO_INCLUDE_MODULES()
   END_WRAP_LIBRARY()
   END_WRAP_LIBRARY()
itkDummy.wrap:
  WRAP_CLASS(itk::Dummy POINTER)
    foreach(t ${WRAP_ITK_SCALAR} ${WRAP_ITK_COLOR} ${WRAP_ITK_COMPLEX_REAL})
      WRAP_TEMPLATE("${ITKM_${t}}" "${ITKT_${t}}")
    endforeach(t)
  END_WRAP_CLASS()


itkDummy.h:
itkDummy.h:
Line 150: Line 158:
    
    
   #endif
   #endif
itkDummy.wrap:
  WRAP_CLASS(itk::Dummy POINTER)
    foreach(t ${WRAP_ITK_SCALAR} ${WRAP_ITK_COLOR} ${WRAP_ITK_COMPLEX_REAL})
      WRAP_TEMPLATE("${ITKM_${t}}" "${ITKT_${t}}")
    endforeach(t)
  END_WRAP_CLASS()


Then, after building and installing the external project, you can run that code in a python interpreter:
Then, after building and installing the external project, you can run that code in a python interpreter:

Revision as of 19:56, 31 May 2011

Wrapping build is done in several steps.

Configuration

The configuration is done with with the tool used to build ITK: CMake. All the files cited in this section are located in the ITK/Wrapping/WrapITK directory.

During this step, the template instantiations are generated with a several CMake macros. For each macro call of the template instantiation process, some callback macros specific of each language generator are called to generate the files and the commands needed to build the wrappers. The template instantiation and the code generation are completely separated.

Template instantiation

Everything is done in the `Libraries` directory. The instantiations are separated in two levels:

  • the libraries, which are grouping several modules. Generally, one binary for a target language contains all the instantiations from one library;
  • the modules, inside those libraries. Each module groups several template instantiations. The swig interface generator generates one '.i' file per module.

Even if it is usually a good idea to follow this structure, the generators are not forced to respect this structure. They are free to generate what they wan how they want.

Several macros are available to simplify the template instantiations.

Macros

The macros are defined in TypedefMacros.cmake.

WRAP_LIBRARIES and END_WRAP_LIBRARIES

WRAP_LIBRARIES is called before generating any library. The generator should use the call back on this macro if they need to perform some initialization step. END_WRAP_LIBRARIES is called after the last instantiation in the last library is done. The generators should use the callback on this macro to create some extra step — for example to build the tests.

WRAP_LIBRARY and END_WRAP_LIBRARY

Formely BEGIN_WRAPPER_LIBRARY and WRAPPER_LIBRARY_CREATE_LIBRARY.

INCLUDE_LIBRARY

AUTO_INCLUDE_MODULES

Formely WRAPPER_LIBRARY_CREATE_WRAP_FILES.

INCLUDE_MODULE

Formely INCLUDE_WRAP_CMAKE.

WRAP_MODULE and END_WRAP_MODULE

WRAP_CLASS

WRAP_NAMED_CLASS

WRAP_NON_TEMPLATE_CLASS

WRAP_NAMED_NON_TEMPLATE_CLASS

WRAP_INCLUDE

END_WRAP_CLASS

ADD_SIMPLE_TYPEDEF

ADD_ONE_TYPEDEF

WRAP_TEMPLATE

WRAP_IMAGE_FILTER_ALL_TYPES

WRAP_IMAGE_FILTER_SCALAR

WRAP_IMAGE_FILTER_VECTOR

WRAP_IMAGE_FILTER_USIGN_INT

WRAP_IMAGE_FILTER_SIGN_INT

WRAP_IMAGE_FILTER_INT

WRAP_IMAGE_FILTER_REAL

WRAP_IMAGE_FILTER_RGB

WRAP_IMAGE_FILTER_RGBA

WRAP_IMAGE_FILTER_VECTOR_REAL

WRAP_IMAGE_FILTER_COV_VECTOR_REAL

WRAP_IMAGE_FILTER_COMPLEX_REAL

WRAP_IMAGE_FILTER

WRAP_IMAGE_FILTER_COMBINATIONS

WRAP_IMAGE_FILTER_TYPES

FILTER_DIMS

Code generator

Everything is done in the 'Languages' directory.

Code generation

Build

Generation XML descriptions of instantiations

Generation of XML documentation

Generation of swig interfaces

Generation of Language specific C++ code

Compilation of C++ code

Linking of libraries

Compilation of tests

External Project

With WrapITK, an external project is a way to extend the wrapping with custom classes outside ITK. The exact same macros are reused, but a single library is generally produced. External projects can be built using ITK from its build tree or from its installed tree.

Example

Here is an example to wrap a new dummy class. All the files are in the same directory.

CMakeLists.txt:

 project(dummy)
 
 cmake_minimum_required(VERSION 2.8)
 
 find_package(ITK REQUIRED)
 find_package(WrapITK REQUIRED)
 
 WRAP_LIBRARY("${PROJECT_NAME}")
   set(WRAPPER_LIBRARY_DEPENDS Base)
   AUTO_INCLUDE_MODULES()
 END_WRAP_LIBRARY()

itkDummy.wrap:

 WRAP_CLASS(itk::Dummy POINTER)
   foreach(t ${WRAP_ITK_SCALAR} ${WRAP_ITK_COLOR} ${WRAP_ITK_COMPLEX_REAL})
     WRAP_TEMPLATE("${ITKM_${t}}" "${ITKT_${t}}")
   endforeach(t)
 END_WRAP_CLASS()

itkDummy.h:

 #ifndef __itkDummy_h
 #define __itkDummy_h
 
 #include "itkProcessObject.h"
 #include "itkImage.h"
 
 namespace itk
 {
 /** \class Dummy
  * \brief a dummy class to return a dummy value
  */
 template< class TValue >
 class ITK_EXPORT Dummy: public Object
 {
 public:
   /** Standard class typedefs. */
   typedef Dummy                      Self;
   typedef Object                     Superclass;
   typedef SmartPointer< Self >       Pointer;
   typedef SmartPointer< const Self > ConstPointer;
 
   /** Method for creation through the object factory. */
   itkNewMacro(Self);
 
   /** Run-time type information (and related methods). */
   itkTypeMacro(Dummy, Object);
 
   TValue GetValue() const
   {
     return NumericTraits<TValue>::OneValue();
   }
  protected:
   Dummy() {};
   virtual ~Dummy() {};
 
 private:
   Dummy(const Self &);    //purposely not implemented
   void operator=(const Self &); //purposely not implemented
 };
 } // end namespace itk
 
 #endif

Then, after building and installing the external project, you can run that code in a python interpreter:

 >>> import itk
 
 >>> df = itk.Dummy.F.New()
 
 >>> df.GetValue()
 1.0
 
 >>> drgb = itk.Dummy.RGBUC.New()
 
 >>> drgb.GetValue()
 itkRGBPixel(1  1  1)