Proposals:Making MetaIO a configurable namespace: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
= STATUS =
This task has been partially completed
* A different method than what is given below was used.  The method below required a change in the include paths which isn't backward compatible (it required ITK_BINARY_DIR/Utilities/MetaIO to be included in applications' paths).  The solution adopted does not add namespace to ITK and instead requires the use of a namespace in vtk.
* Regretfully, files (CMakeLists.txt and localMetaConfiguration.h) differ between the distributions, so they still do not share a code base...this needs to be resolved.
=== Motive ===
=== Motive ===
MetaIO is a library that is intended used by multiple projects. Stephen recently added it to a branch in VTK. Since it is shared by multiple projects (TIK and VTK here) function definitions will collide in projects that use both ITK and VTK.  
MetaIO is a library that is intended used by multiple projects. Stephen recently added it to a branch in VTK. Since it is shared by multiple projects (TIK and VTK here) function definitions will collide in projects that use both ITK and VTK.  
Line 41: Line 48:


although both would work. The point being that if you did write code in VTK, your code would use the former convention.
although both would work. The point being that if you did write code in VTK, your code would use the former convention.
{{ITK/Template/Footer}}

Latest revision as of 01:21, 22 October 2007

STATUS

This task has been partially completed

  • A different method than what is given below was used. The method below required a change in the include paths which isn't backward compatible (it required ITK_BINARY_DIR/Utilities/MetaIO to be included in applications' paths). The solution adopted does not add namespace to ITK and instead requires the use of a namespace in vtk.
  • Regretfully, files (CMakeLists.txt and localMetaConfiguration.h) differ between the distributions, so they still do not share a code base...this needs to be resolved.

Motive

MetaIO is a library that is intended used by multiple projects. Stephen recently added it to a branch in VTK. Since it is shared by multiple projects (TIK and VTK here) function definitions will collide in projects that use both ITK and VTK.

Solution

Use a configurable namespace like KWsys (shared in ITK as itksys, vtksys, cmsys). The idea is that each project using MetaIO configures the MetaIO library namespace at compile time. The point is to share the same source tree for MetaIO in both ITK and VTK.

The CMake API to configure the namespace is simple. CMakeLists.txt provides the following options:

- USE_NAMESPACE_FOR_METAIO  (default off in ITK, on in VTK)
- METAIO_NAMESPACE = "itkmetaio" 
- METAIO_LIBRARY = "ITKMetaIO" # name of the library that will be built, defaults to the namespace name
- METAIO_BUILD_SHARED_LIBS = OFF/ON; Shared / static libs ?    

It is worth mentioning that the third option is redundant in ITK, which does not build any of the Utilities/ as shared libraries. The only shared library built is ITKCommon. In VTK, the Utilities are built as shared or static libraries depending on the BUILD_SHARED_LIBS flag.

Implementation

1. Download MetaIO.tar.gz and metaio.patch from ftp://www.itk.org/pub/itk/UsersITK/metaio

2. cd Insight/ && patch -p0 < /tmp/metaio.patch && cd Utilities/ && rm -rf MetaIO && tar xvzf /tmp/MetaIO.tar.gz

3. Configure, build as usual with CMake and you should be good to go.

The configurable namespace stuff has just been added to VTK (in a branch) and will most likely move to the HEAD soon.

Backward compatibility issues

Good news. Everything is 100% backward compatible.

MetaIO traditionally never had a namespace. A namespace has just been added and the default in ITK is to open the namespace using namespace itkmetaio; and in VTK, the default is not to do so. This has been done to maintain backward compatibility in ITK. This can be controlled by a CMake option in both ITK and VTK: USE_NAMESPACE_FOR_METAIO

Nevertheless, when you write code that uses the metaio library, you are encouraged to use the following convention,

 #include "itkmetaio/metaImage.h"
 ...
 itkmetaio::MetaImage myMetaImage;

instead of

 #include "metaImage.h"
 ...
 MetaImage myMetaImage;

although both would work. The point being that if you did write code in VTK, your code would use the former convention.



ITK: [Welcome | Site Map]