https://public.kitware.com/Wiki/api.php?action=feedcontributions&user=Sprevrha&feedformat=atomKitwarePublic - User contributions [en]2024-03-29T05:11:05ZUser contributionsMediaWiki 1.38.6https://public.kitware.com/Wiki/index.php?title=ITK/Python_Wrapping&diff=9638ITK/Python Wrapping2007-06-18T16:36:07Z<p>Sprevrha: /* Microsoft Windows */</p>
<hr />
<div>== Python Wrapping ==<br />
<br />
This section describes how to wrap ITK classes for being used from Python.<br />
<br />
Since slight differences exist depending on the platform where the wrapping is done, this section will describe those platforms independently.<br />
<br />
=== Microsoft Windows ===<br />
<br />
In order to wrap ITK for Python under Microsoft Windows you must start by gathering the following materials - at least this is the configuration with which I succeeded<br />
<br />
# Python 2.4<br />
# ITK CVS version posterior to July 10 2004 - I used 3.2.0<br />
# CableSwig- I used 2.2<br />
<br />
It is convenient to use CSwig from CVS and to check it out inside the source tree of ITK. However this is not necessary as the path to CableSwig can be set in the CMake configuration for ITK.<br />
<br />
CMake configuration:<br />
<br />
# Compiler: I tried MS Visual Studio Express which failed. However, I think this because VS Express does not include the MS Windows SDK. I believe that installing that (free download from MS) and adding it to the "VC directories" paths correctly in VS Express will make it work. I have MS VC 2003 .NET as well, and both CableSwig and ITK compiled without errors. <br />
<br />
# Shared Libs ON<br />
# ITK_CSWIG_PYTHON ON<br />
# Set the python paths (Advanced Values), don't worry about PYTHON_DEBUG_LIBRARY<br />
# TK_INTERNAL_PATH is the path to tkWinInt.h - this file is found in the source distro of Tcl/Tk.<br />
# ITK_EXPLICIT_INSTANTATION must be off.<br />
<br />
Open ALL_BUILD in MSVC, select the configuration you want (Release, RelWithDebugInfo etc) and build for a long time.<br />
<br />
Compiling with NumArray:<br />
<br />
It seems the CMake configuration for this combination needs some manual fine-tuning: If you see an error that import_libnumarray() is needed in itkPyBuffer.txx and cannot be found it is because this macro is defined in libnumarray.h (part of numarray) which is nowhere included. I added #include <libnumarray.h> in itkPyBuffer.h and the path to it in the MSVC directories (Tools->Options) and it compiled fine. <br />
<br />
Installation:<br />
<br />
Build the INSTALL target. This will install the binaries and the Python wrapper modules. If you receive a CMake error like "C:/packages/InsightToolkit-3.2.0/Wrapping/CSwig/cmake_install.cmake:31:<br />
FILE INSTALL cannot find file "C:/packages/InsightToolkit-3.2.0/Wrapping/CSwig/Python/InsightToolkit.py" to install." that's because the compilation configuration subdir (e.g. Release) is not being included, so CMake can’t find the file. Edit the paths in the .cmake file, and (re-)installation moves along fine.<br />
<br />
The next same issue is pythonfiles_install.cmake - the FILE(GLOB command on the first line also needs to read bin/Release/*.py ( or replace "Release" with your configuration).<br />
<br />
This is still true as of CVS version 6/17/07. <br />
<br />
Once everything is installed correctly, go to the Lib\site-packages of your Python installation and create a text file named "InsightToolkit.pth". Add four lines like these -<br> <br><br />
C:\\Program Files\\ITK\\bin<br><br />
C:\\Program Files\\ITK\\lib\\InsightToolkit<br><br />
C:\\Program Files\\ITK\\lib\\InsightToolkit\\python<br><br />
C:\\Program Files\\ITK\\lib\\InsightToolkit\\python\\Release<br><br><br />
(or replace C:\Program Files with the root of your ITK installation. Then add C:\Program Files\ITK\bin to the %PATH% global variable (and the path to python.exe)<br />
<br />
To test, start a cmd shell, type "python" and at the >>> prompt, "from InsightToolkit import *". You should see no errors.<br />
<br />
=== Linux ===<br />
<br />
{{ITK/Template/Footer}}</div>Sprevrhahttps://public.kitware.com/Wiki/index.php?title=ITK/Python_Wrapping&diff=9194ITK/Python Wrapping2007-05-31T23:39:51Z<p>Sprevrha: /* Microsoft Windows */</p>
<hr />
<div>== Python Wrapping ==<br />
<br />
This section describes how to wrap ITK classes for being used from Python.<br />
<br />
Since slight differences exist depending on the platform where the wrapping is done, this section will describe those platforms independently.<br />
<br />
=== Microsoft Windows ===<br />
<br />
In order to wrap ITK for Python under Microsoft Windows you must start by gathering the following materials - at least this is the configuration with which I succeeded<br />
<br />
# Python 2.4<br />
# ITK CVS version posterior to July 10 2004 - I used 3.2.0<br />
# CableSwig- I used 2.2<br />
<br />
It is convenient to use CSwig from CVS and to check it out inside the source tree of ITK. However this is not necessary as the path to CableSwig can be set in the CMake configuration for ITK.<br />
<br />
CMake configuration:<br />
<br />
# Compiler: I tried MS Visual Studio Express which failed. However, I think this because VS Express does not include the MS Windows SDK. I believe that installing that (free download from MS) and adding it to the "VC directories" paths correctly in VS Express will make it work. I have MS VC 2003 .NET as well, and both CableSwig and ITK compiled without errors. <br />
<br />
# Shared Libs ON<br />
# ITK_CSWIG_PYTHON ON<br />
# Set the python paths (Advanced Values), don't worry about PYTHON_DEBUG_LIBRARY<br />
# TK_INTERNAL_PATH is the path to tkWinInt.h - this file is found in the source distro of Tcl/Tk.<br />
# ITK_EXPLICIT_INSTANTATION must be off.<br />
<br />
Open ALL_BUILD in MSVC, select the configuration you want (Release, RelWithDebugInfo etc) and build for a long time.<br />
<br />
Compiling with NumArray:<br />
<br />
It seems the CMake configuration for this combination needs some manual fine-tuning: If you see an error that import_libnumarray() is needed in itkPyBuffer.txx and cannot be found it is because this macro is defined in libnumarray.h (part of numarray) which is nowhere included. I added #include <libnumarray.h> in itkPyBuffer.h and the path to it in the MSVC directories (Tools->Options) and it compiled fine. <br />
<br />
Installation:<br />
<br />
Build the INSTALL target. This will install the binaries and the Python wrapper modules. If you receive a CMake error like "C:/packages/InsightToolkit-3.2.0/Wrapping/CSwig/cmake_install.cmake:31:<br />
FILE INSTALL cannot find file "C:/packages/InsightToolkit-3.2.0/Wrapping/CSwig/Python/InsightToolkit.py" to install." that's because the compilation configuration subdir (e.g. Release) is not being included, so CMake can’t find the file. Edit the paths in the .cmake file, and (re-)installation moves along fine.<br />
<br />
Once everything is installed correctly, go to the Lib\site-packages of your Python installation and create a text file named "InsightToolkit.pth". Add four lines like these -<br> <br><br />
C:\\Program Files\\ITK\\bin<br><br />
C:\\Program Files\\ITK\\lib\\InsightToolkit<br><br />
C:\\Program Files\\ITK\\lib\\InsightToolkit\\python<br><br />
C:\\Program Files\\ITK\\lib\\InsightToolkit\\python\\Release<br><br><br />
(or replace C:\Program Files with the root of your ITK installation. Then add C:\Program Files\ITK\bin to the %PATH% global variable (and the path to python.exe)<br />
<br />
To test, start a cmd shell, type "python" and at the >>> prompt, "from InsightToolkit import *". You should see no errors.<br />
<br />
=== Linux ===<br />
<br />
{{ITK/Template/Footer}}</div>Sprevrhahttps://public.kitware.com/Wiki/index.php?title=ITK/Python_Wrapping&diff=9186ITK/Python Wrapping2007-05-30T17:33:36Z<p>Sprevrha: /* Microsoft Windows */</p>
<hr />
<div>== Python Wrapping ==<br />
<br />
This section describes how to wrap ITK classes for being used from Python.<br />
<br />
Since slight differences exist depending on the platform where the wrapping is done, this section will describe those platforms independently.<br />
<br />
=== Microsoft Windows ===<br />
<br />
In order to wrap ITK for Python under Microsoft Windows you must start by gathering the following materials - at least this is the configuration with which I succeeded<br />
<br />
# Python 2.4<br />
# ITK CVS version posterior to July 10 2004 - I used 3.2.0<br />
# CableSwig- I used 2.2<br />
<br />
It is convenient to use CSwig from CVS and to check it out inside the source tree of ITK. However this is not necessary as the path to CableSwig can be set in the CMake configuration for ITK.<br />
<br />
CMake configuration:<br />
<br />
# Compiler: I tried MS Visual Studio Express which failed. However, I think this because VS Express does not include the MS Windows SDK. I believe that installing that (free download from MS) and adding it to the "VC directories" paths correctly in VS Express will make it work. I have MS VC 2003 .NET as well, and both CableSwig and ITK compiled without errors. <br />
<br />
# Shared Libs ON<br />
# ITK_CSWIG_PYTHON ON<br />
# Set the python paths (Advanced Values), don't worry about PYTHON_DEBUG_LIBRARY<br />
# TK_INTERNAL_PATH is the path to tkWinInt.h - this file is found in the source distro of Tcl/Tk.<br />
# ITK_EXPLICIT_INSTANTATION must be off.<br />
<br />
Open ALL_BUILD in MSVC, select the configuration you want (Release, RelWithDebugInfo etc) and build for a long time.<br />
<br />
=== Linux ===<br />
<br />
{{ITK/Template/Footer}}</div>Sprevrhahttps://public.kitware.com/Wiki/index.php?title=ITK/Python_Wrapping&diff=9185ITK/Python Wrapping2007-05-30T17:14:58Z<p>Sprevrha: Started the page</p>
<hr />
<div>== Python Wrapping ==<br />
<br />
This section describes how to wrap ITK classes for being used from Python.<br />
<br />
Since slight differences exist depending on the platform where the wrapping is done, this section will describe those platforms independently.<br />
<br />
=== Microsoft Windows ===<br />
<br />
In order to wrap ITK for Python under Microsoft Windows you must start by gathering the following materials - at least this is the configuration with which I succeeded<br />
<br />
# Python 2.4<br />
# ITK CVS version posterior to July 10 2004 - I used 3.2.0<br />
# CableSwig- I used 2.2<br />
<br />
It is convenient to use CSwig from CVS and to check it out inside the source tree of ITK. However this is not necessary as the path to CableSwig can be set in the CMake configuration for ITK.<br />
<br />
CMake configuration:<br />
<br />
# Compiler: I tried MS Visual Studio Express which failed. However, I think this because VS Express does not include the MS Windows SDK. I believe that installing that (free download from MS) and adding it to the "VC directories" paths correctly in VS Express will make it work. I have MS VC 2003 .NET as well, and both CableSwig and ITK compiled without errors. <br />
<br />
# Shared Libs ON<br />
# ITK_CSWIG_PYTHON ON<br />
# Set the python paths (Advanced Values), don't worry about PYTHON_DEBUG_LIBRARY<br />
# ITK_EXPLICIT_INSTANTATION must be off.<br />
<br />
Open ALL_BUILD in MSVC, select the configuration you want (Release, RelWithDebugInfo etc) and build for a long time.<br />
<br />
<br />
<br />
=== Linux ===<br />
<br />
{{ITK/Template/Footer}}</div>Sprevrhahttps://public.kitware.com/Wiki/index.php?title=ITK/Configuring_and_Building&diff=9184ITK/Configuring and Building2007-05-30T17:03:07Z<p>Sprevrha: /* Wrapping ITK */</p>
<hr />
<div>== Configuring And Building ==<br />
<br />
This page describes the various ways of configuring and building ITK in common configurations. Recommended configurations are incldued for:<br />
<br />
* Linux<br />
* Mac OS X<br />
* Solaris<br />
* AIX<br />
* Windows<br />
<br />
It is strongly recommended that you build ITK in a separate tree. This is described elsewhere (?).<br />
<br />
=== CMake Configuration for Linux ===<br />
<br />
This configuration is the one used to build the packages for Debian GNU/Linux, but should work for any distribution just fine. It assumes that you already have certain libraries installed (which will almost always be the case), specifically:<br />
<br />
* libzlib<br />
* libjpg<br />
* libtiff<br />
* libpng<br />
<br />
The <tt>rpath</tt> option is disabled, as it is only really needed if you install the libraries into someplace other than a standard directory that is on your <tt>LD_LIBRARY_PATH</tt>.<br />
<br />
You can either paste this into a <tt>CMakeCache.txt</tt> or change the settings manually by running <tt>ccmake</tt>.<br />
<br />
# This is the Kickstart CMakeCache file for the Debian build of ITK.<br />
# Only those settings that are changed from the default are specified.<br />
&nbsp;<br />
// For some reason it defaults to c++<br />
CMAKE_CXX_COMPILER:STRING=g++<br />
&nbsp;<br />
// Don't build examples now (let the user later)<br />
BUILD_EXAMPLES:BOOL=OFF<br />
&nbsp;<br />
// Build ITK with shared libraries<br />
BUILD_SHARED_LIBS:BOOL=ON<br />
&nbsp;<br />
// Don't bother building the testing tree<br />
BUILD_TESTING:BOOL=OFF<br />
&nbsp;<br />
// Give us an optimised release build<br />
CMAKE_BUILD_TYPE:STRING=RELWITHDEBINFO<br />
&nbsp;<br />
// Install path prefix, prepended onto install directories<br />
CMAKE_INSTALL_PREFIX:PATH=/usr<br />
&nbsp;<br />
// The code still uses the older #include <iostream.h> style<br />
CMAKE_CXX_FLAGS:STRING=-Wno-deprecated <br />
&nbsp;<br />
// We do not want rpath enabled<br />
CMAKE_SKIP_RPATH:BOOL=ON<br />
&nbsp;<br />
// We haven't packaged this (yet)<br />
ITK_DATA_ROOT:PATH=ITK_DATA_ROOT_NOTFOUND<br />
&nbsp;<br />
// Use the system libraries for these<br />
ITK_USE_SYSTEM_JPEG:BOOL=ON<br />
ITK_USE_SYSTEM_PNG:BOOL=ON<br />
ITK_USE_SYSTEM_TIFF:BOOL=ON<br />
ITK_USE_SYSTEM_ZLIB:BOOL=ON<br />
&nbsp;<br />
//Build cswig Python wrapper support<br />
ITK_CSWIG_PYTHON:BOOL=ON<br />
&nbsp;<br />
//Build cswig Tcl wrapper support<br />
ITK_CSWIG_TCL:BOOL=ON<br />
<br />
==== Ebuild for Gentoo Linux ====<br />
<br />
For Gentoo Linux you can use the ebuild shown below, or alternatively download it [http://www.elreki.net/gentoo/itk-2.4.1.ebuild here]. This ebuild will pull in all required dependencies. Please notice that this ebuild does not build the Python/TCL wrapper support.<br />
<br />
# Copyright 1999-2006 Gentoo Foundation<br />
# Distributed under the terms of the GNU General Public License v2<br />
# $Header: $<br />
<br />
inherit distutils eutils flag-o-matic toolchain-funcs versionator<br />
<br />
DESCRIPTION="NLM Insight Segmentation and Registration Toolkit"<br />
HOMEPAGE="http://www.itk.org"<br />
SRC_URI="mirror://sourceforge/${PN}/InsightToolkit-${PV}.tar.gz"<br />
<br />
LICENSE="BSD"<br />
KEYWORD="~x86"<br />
SLOT="0"<br />
KEYWORDS="~x86"<br />
IUSE="patented"<br />
<br />
DEPEND="sys-libs/zlib<br />
media-libs/jpeg<br />
media-libs/libpng<br />
media-libs/tiff"<br />
RDEPEND="${RDEPEND}<br />
>=dev-util/cmake-1.8"<br />
<br />
MY_PV=$(replace_all_version_separators '-')<br />
S=${WORKDIR}/InsightToolkit-${MY_PV}<br />
<br />
src_compile() {<br />
<br />
# Out of source build<br />
mkdir my_build && cd my_build<br />
<br />
# Install path prefix, prepended onto install directories<br />
CMAKE_VARIABLES="${CMAKE_VARIABLES} -DCMAKE_INSTALL_PREFIX:PATH=/usr"<br />
# Build ITK with shared libraries<br />
CMAKE_VARIABLES="${CMAKE_VARIABLES} -DBUILD_SHARED_LIBS:BOOL=ON"<br />
# Don't bother building the testing tree<br />
CMAKE_VARIABLES="${CMAKE_VARIABLES} -DBUILD_TESTING:BOOL=OFF"<br />
# Don't build examples now (let the user later)<br />
CMAKE_VARIABLES="${CMAKE_VARIABLES} -DBUILD_EXAMPLES:BOOL=OFF"<br />
# Give us an optimised release build<br />
CMAKE_VARIABLES="${CMAKE_VARIABLES} -DCMAKE_BUILD_TYPE:STRING=RELWITHDEBINFO"<br />
# We do not want rpath enabled<br />
CMAKE_VARIABLES="${CMAKE_VARIABLES} -DCMAKE_SKIP_RPATH:BOOL=ON"<br />
# Use the system libraries for these<br />
CMAKE_VARIABLES="${CMAKE_VARIABLES} -DITK_USE_SYSTEM_JPEG:BOOL=ON"<br />
CMAKE_VARIABLES="${CMAKE_VARIABLES} -DITK_USE_SYSTEM_PNG:BOOL=ON"<br />
CMAKE_VARIABLES="${CMAKE_VARIABLES} -DITK_USE_SYSTEM_TIFF:BOOL=ON"<br />
CMAKE_VARIABLES="${CMAKE_VARIABLES} -DITK_USE_SYSTEM_ZLIB:BOOL=ON"<br />
<br />
use patented && CMAKE_VARIABLES="${CMAKE_VARIABLES} -DITK_USE_PATENTED:BOOL=ON"<br />
<br />
# Run CMake twice to configure properly with CMake 2.2.x<br />
cmake ${CMAKE_VARIABLES} .. && cmake ${CMAKE_VARIABLES} .. \<br />
|| die "CMake configuration failed"<br />
<br />
emake || die "emake failed"<br />
}<br />
<br />
src_install() {<br />
# Return to our build directory<br />
cd my_build<br />
<br />
# Do install<br />
make DESTDIR=${D} install || die "make install failed"<br />
<br />
# Fix configuration file<br />
sed -i -e "s:${D}:/:g" ${D}/usr/lib/${PN}/ITKConfig.cmake<br />
<br />
LDPATH="/usr/lib/InsightToolkit"<br />
echo "LDPATH=${LDPATH}" > ${T}/40${PN}<br />
echo "ITK_DATA_ROOT=/usr/share/${PN}/data" >> ${T}/40${PN}<br />
doenvd ${T}/40${PN}<br />
}<br />
<br />
pkg_postinst() {<br />
if use patented; then<br />
ewarn "Using patented code in ITK may require a license."<br />
ewarn "For more information, please read:"<br />
ewarn "http://www.vtk.org/Wiki/ITK_Patent_Bazaar"<br />
fi<br />
}<br />
<br />
=== CMake Configuration for Mac OS X ===<br />
<br />
This configuration has been tested on Mac OS X Panther 10.3, with XCode 1.1 and 1.2. It presumes that [http://fink.sourceforge.net/ Fink] has been installed, with the following libraries in the default location under <tt>/sw</tt>:<br />
<br />
* libjpeg<br />
* libtiff<br />
* libpng<br />
* libzilb<br />
<br />
//Name of build on the dashboard<br />
BUILDNAME:STRING=Darwin-g++<br />
&nbsp;<br />
//Build source documentation using doxygen<br />
BUILD_DOXYGEN:BOOL=OFF<br />
&nbsp;<br />
//Build the Examples directory.<br />
BUILD_EXAMPLES:BOOL=OFF<br />
&nbsp;<br />
//Build ITK with shared libraries.<br />
BUILD_SHARED_LIBS:BOOL=ON<br />
&nbsp;<br />
//Build the testing tree.<br />
BUILD_TESTING:BOOL=OFF<br />
&nbsp;<br />
//Choose the type of build, options are: None(CMAKE_CXX_FLAGS or<br />
// CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.<br />
//<br />
CMAKE_BUILD_TYPE:STRING=RelWithDebInfo<br />
&nbsp;<br />
//C++ compiler<br />
CMAKE_CXX_COMPILER:STRING=g++<br />
&nbsp;<br />
//Use the system's jpeg library.<br />
ITK_USE_SYSTEM_JPEG:BOOL=ON<br />
&nbsp;<br />
//Use the system's png library.<br />
ITK_USE_SYSTEM_PNG:BOOL=ON<br />
&nbsp;<br />
//Use the system's tiff library.<br />
ITK_USE_SYSTEM_TIFF:BOOL=ON<br />
&nbsp;<br />
//Use an outside build of VXL.<br />
ITK_USE_SYSTEM_VXL:BOOL=OFF<br />
&nbsp;<br />
//Use the system's zlib library.<br />
ITK_USE_SYSTEM_ZLIB:BOOL=ON<br />
&nbsp;<br />
//What is the path where the file jpeglib.h can be found<br />
JPEG_INCLUDE_DIR:PATH=/sw/include<br />
&nbsp;<br />
//Where can the jpeg library be found<br />
JPEG_LIBRARY:FILEPATH=/sw/lib/libjpeg.dylib<br />
&nbsp;<br />
//Where can the png library be found<br />
PNG_LIBRARY:FILEPATH=/sw/lib/libpng.dylib<br />
&nbsp;<br />
//What is the path where the file png.h can be found<br />
PNG_PNG_INCLUDE_DIR:PATH=/sw/include<br />
&nbsp;<br />
//What is the path where the file tiff.h can be found<br />
TIFF_INCLUDE_DIR:PATH=/sw/include<br />
&nbsp;<br />
//Where can the tiff library be found<br />
TIFF_LIBRARY:FILEPATH=/sw/lib/libtiff.dylib<br />
&nbsp;<br />
//What is the path where the file zlib.h can be found<br />
ZLIB_INCLUDE_DIR:PATH=/usr/include<br />
&nbsp;<br />
//Where can the z library be found<br />
ZLIB_LIBRARY:FILEPATH=/usr/lib/libz.dylib<br />
<br />
=== CMake Configuration for Solaris ===<br />
<br />
=== CMake Configuration for AIX ===<br />
<br />
=== CMake Configuration for Windows ===<br />
<br />
== Using a predefined Configuration ==<br />
<br />
CMake can be run interactively to configure a build, in which case all settings begin with system defaults (as determined by <tt>CMakeLists.txt</tt>) and the user customises them.<br />
<br />
Alternatively, a predefined configuration (such as those shown above) can be provided, which will provide initial settings for the build (also known as ''priming''). By creating a file called <tt>CMakeCache.txt</tt> in the top level of the build directory, the settings defined therein will be used to override the default settings for the build.<br />
<br />
== Wrapping ITK ==<br />
<br />
ITK can be wrapped for several different languages such as Python, Tcl and Java. <br />
<br />
* [[ITK Java Wrapping|Java wrapping]] guide<br />
* [[ITK Python Wrapping|Python wrapping]] guide<br />
<br />
{{ITK/Template/Footer}}</div>Sprevrha