Proposals:Making MetaIO a configurable namespace

From KitwarePublic
Revision as of 16:14, 20 March 2006 by Andy (talk | contribs)
Jump to navigationJump to search


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.


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.


1. Download MetaIO.tar.gz and metaio.patch from

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]