<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi everyone,<br>
<br>
this used to work with ITK 3.20 but does not work with ITK 4.2. <br>
<br>
The itkLandmarkBasedTransformInitializer is not properly wrapped by
WrapITK because it uses std::vectors. Therefore, we created our own
class itkPythonEnabledLandmarkBasedTransformInitializer. This is
wrapped using the following CMakeLists.txt:<br>
<br>
<blockquote><tt>PROJECT(itkExtensions)</tt><tt><br>
</tt><tt>FIND_PACKAGE(WrapITK REQUIRED)</tt><tt><br>
</tt><tt>cmake_minimum_required(VERSION 2.8) </tt><tt><br>
</tt><tt><br>
</tt><tt>SET(PROJECT_SOURCE_DIR "../../src")</tt><tt><br>
</tt><tt>include_directories( ${PROJECT_SOURCE_DIR})</tt><tt><br>
</tt><tt><br>
</tt><tt>itk_wrap_module("itkLandmarkAlignment")</tt><tt><br>
</tt><tt><br>
</tt><tt>set(WRAPPER_LIBRARY_DEPENDS ITKCommon ITKTransform) </tt><tt><br>
</tt><tt>SET(WRAPPER_LIBRARY_LINK_LIBRARIES ${ITK_LIBRARIES})</tt><tt><br>
</tt><tt><br>
</tt><tt>itk_auto_load_submodules() # includes all *.wrap custom
files</tt><tt><br>
</tt><tt>itk_end_wrap_module()</tt><br>
</blockquote>
The included .wrap file looks like this:<br>
<tt><br>
</tt>
<blockquote><tt>ITK_WRAP_INCLUDE("itkSimilarity3DTransform.h")</tt><br>
<tt>ITK_WRAP_CLASS("itk::PythonEnabledLandmarkBasedTransformInitializer"
POINTER_WITH_SUPERCLASS)</tt><br>
<tt> ITK_WRAP_TEMPLATE("VTIF3IF3"
"itk::VersorRigid3DTransform<double>, itk::Image<
float, 3>, itk::Image<float, 3>")</tt><br>
<tt> ITK_WRAP_TEMPLATE("STIF3IF3"
"itk::Similarity3DTransform<double>, itk::Image< float,
3>, itk::Image<float, 3>") </tt><br>
<tt>ITK_END_WRAP_CLASS()</tt><br>
</blockquote>
<br>
<br>
This compiles and can be imported into python. However, when I
import both itk and this module itkLandmarkAlignment, the regular
itk modules don't load properly anymore. I get this error:<br>
<br>
<blockquote><tt> File
"/home/tom/workspace/imageToImageRegistration/scripts/landmark_alignement.py",
line 166, in <module></tt><br>
<tt> main(*args[1:]), </tt><br>
<tt> File
"/home/tom/workspace/imageToImageRegistration/scripts/landmark_alignement.py",
line 46, in main</tt><br>
<tt> fixed_image = ImageReader(fixed_image_name).get_image() </tt><br>
<tt> File
"/home/tom/workspace/tools/scripts/common/ImageReaderITK.py",
line 51, in __init__</tt><br>
<tt> self.__itk_img_type = eval("itk.Image." + self.__datatype
+ str(self.__dimension))</tt><br>
<tt> File "<string>", line 1, in <module></tt><br>
<tt> File
"/export/contrib/InsightToolkit-4.20/linux64/u12_04_release/lib/ITK-4.2/Python/itkLazy.py",
line 37, in __getattribute__</tt><br>
<tt> itkBase.LoadModule(module, namespace)</tt><br>
<tt> File
"/export/contrib/InsightToolkit-4.20/linux64/u12_04_release/lib/ITK-4.2/Python/itkBase.py",
line 95, in LoadModule</tt><br>
<tt> LoadModule(dep, namespace)</tt><br>
<tt> File
"/export/contrib/InsightToolkit-4.20/linux64/u12_04_release/lib/ITK-4.2/Python/itkBase.py",
line 95, in LoadModule</tt><br>
<tt> LoadModule(dep, namespace)</tt><br>
<tt> File
"/export/contrib/InsightToolkit-4.20/linux64/u12_04_release/lib/ITK-4.2/Python/itkBase.py",
line 95, in LoadModule</tt><br>
<tt> LoadModule(dep, namespace)</tt><br>
<tt> File
"/export/contrib/InsightToolkit-4.20/linux64/u12_04_release/lib/ITK-4.2/Python/itkBase.py",
line 95, in LoadModule</tt><br>
<tt> LoadModule(dep, namespace)</tt><br>
<tt> File
"/export/contrib/InsightToolkit-4.20/linux64/u12_04_release/lib/ITK-4.2/Python/itkBase.py",
line 95, in LoadModule</tt><br>
<tt> LoadModule(dep, namespace)</tt><br>
<tt> File
"/export/contrib/InsightToolkit-4.20/linux64/u12_04_release/lib/ITK-4.2/Python/itkBase.py",
line 118, in LoadModule</tt><br>
<tt> for k, v in module.__dict__.items():</tt><br>
<tt>UnboundLocalError: local variable 'module' referenced before
assignment</tt><br>
</blockquote>
It seems that itkBase cannot load the reader module anymore. This
can be reproduced by hand in ipython. If and only if I have my own
wrapped module imported before trying to use an ImageFileReader, I
get the error messages:<br>
<br>
<blockquote><tt>UnboundLocalError Traceback
(most recent call last)</tt><br>
<tt>/local/tom/data/tibia/Anatomie/right/ct/<ipython-input-3-e158c938807a>
in <module>()</tt><br>
<tt>----> 1 reader = itk.ImageFileReader.ISS3.New()</tt><br>
<br>
<tt>/export/contrib/InsightToolkit-4.20/linux64/u12_04_release/lib/ITK-4.2/Python/itkLazy.pyc
in __getattribute__(self, attr)</tt><br>
<tt> 35 module = self.__lazy_attributes[attr]</tt><br>
<tt> 36 namespace = {}</tt><br>
<tt>---> 37 itkBase.LoadModule(module, namespace)</tt><br>
<tt> 38 # Load into 'namespace' first, then
self.__dict__ (via setattr) to</tt><br>
<br>
<tt> 39 # prevent the warnings about overwriting the
'NotLoaded' values already</tt><br>
<br>
<br>
<tt>/export/contrib/InsightToolkit-4.20/linux64/u12_04_release/lib/ITK-4.2/Python/itkBase.pyc
in LoadModule(name, namespace)</tt><br>
<tt> 93 deps.sort()</tt><br>
<tt> 94 for dep in deps:</tt><br>
<tt>---> 95 LoadModule(dep, namespace)</tt><br>
<tt> 96 </tt><br>
<tt> 97 if itkConfig.ImportCallback:
itkConfig.ImportCallback(name, 0)</tt><br>
<br>
<tt>/export/contrib/InsightToolkit-4.20/linux64/u12_04_release/lib/ITK-4.2/Python/itkBase.pyc
in LoadModule(name, namespace)</tt><br>
<tt> 93 deps.sort()</tt><br>
<tt> 94 for dep in deps:</tt><br>
<tt>---> 95 LoadModule(dep, namespace)</tt><br>
<tt> 96 </tt><br>
<tt> 97 if itkConfig.ImportCallback:
itkConfig.ImportCallback(name, 0)</tt><br>
<br>
<tt>/export/contrib/InsightToolkit-4.20/linux64/u12_04_release/lib/ITK-4.2/Python/itkBase.pyc
in LoadModule(name, namespace)</tt><br>
<tt> 116 this_module.swig = imp.new_module('swig')</tt><br>
<tt> 117 if namespace is not None: swig =
namespace.setdefault('swig', imp.new_module('swig'))</tt><br>
<tt>--> 118 for k, v in module.__dict__.items():</tt><br>
<tt> 119 if not k.startswith('__'):
setattr(this_module.swig, k, v)</tt><br>
<tt> 120 if namespace is not None and not
k.startswith('__'): setattr(swig, k, v)</tt><br>
<br>
<tt>UnboundLocalError: local variable 'module' referenced before
assignment</tt><br>
</blockquote>
<br>
Any help would be greatly appreciated.<br>
<br>
Tom<br>
</body>
</html>