Difference between revisions of "User:Mseeland"

From NAMIC Wiki
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 49: Line 49:
  
 
===Prerequisites for Two-Tensor Tractography module===
 
===Prerequisites for Two-Tensor Tractography module===
====Teem Python wrapping====
+
====Check out Two-Tensor Tractography====
 
+
* Check out Two-Tensor Tractography from http://svn.na-mic.org/NAMICSandBox/trunk/TwoTensorTractography.
=====BACKGROUND=====
+
* Copy the Two-Tensor Tractography folder into the directory /Slicer3-build/lib/Slicer3/Modules.
* Teem Python wrapping is needed to make use of existing Two-Tensor tractography functions in Teem in Python
 
* The Python wrappings are based on ctypes, as well as a ctypes code generator (called "ctypeslib")
 
** http://python.net/crew/theller/ctypes
 
** http://starship.python.net/crew/theller/wiki/CodeGenerator
 
** http://starship.python.net/crew/theller/ctypes/old/codegen.html
 
* Ctypes is a standard part of python, by which C functions in a shared library can be called from Python
 
* The ctypes code generator converts declarations in C header files into executable Python code: enums, structs, unions, function declarations, com interfaces, and preprocessor definitions.
 
* Creating wrappers for C header file(s) is a two step process.
 
** First, the ``h2xml.py`` script runs GCC-XML_ over the include file(s), creating a XML file containing declarations and definitions. 
 
** Second, the ``xml2py.py`` script parses the XML files and creates Python code containing all or a subset of these definitions.
 
* Python code is generated for C enums, structure, unions, typedefs and function declarations.
 
 
 
=====REQUIREMENTS=====
 
* Ctypeslib: ctypeslib is an extension package for ctypes. It contains a ctypes code generator.
 
* GCC-XML (from http://www.gccxml.org/) is required to parse C header files into an XML description.
 
 
 
=====GETTING THE SOFTWARE=====
 
* Python 2.6 can be got here (anything after 2.5 should work): http://www.python.org/download/
 
* Get gccxml (I used version 0.9.0), which can be got by CVS as described here: http://www.gccxml.org/HTML/Download.html
 
** follow the installation as described here: http://www.gccxml.org/HTML/Install.html
 
* use a version of ctypeslib which work with the version of gccxml:
 
  http://svn.python.org/projects/ctypes/branches/ctypeslib-gccxml-0.9
 
* But this requires some patches to work; the content of the "fixes.patch" file can be found here: [[http://wiki.na-mic.org/Wiki/images/3/3b/Fixes.patch.txt]]:
 
  svn co http://svn.python.org/projects/ctypes/branches/ctypeslib-gccxml-0.9
 
  cd ctypeslib-gccxml-0.9
 
  patch -p0 < ../fixes.patch
 
  cd ..
 
* ctypeslib is written in python => there's nothing new to compile at this point
 
 
 
=====CREATING PYTHON/TEEM=====
 
* First get Teem (starting from whatever directory should contain the "teem" source dir):
 
  svn co https://teem.svn.sourceforge.net/svnroot/teem/teem/trunk teem
 
and compile it as a shared library.  Directions for doing this with cmake are here:
 
  http://teem.sourceforge.net/build.html
 
* create the wrappings in a new directory (e.g. "teem-wrap"), where the XML and Python output will be
 
* Set the environment variables that identify where Teem and ctypeslib are:
 
** TEEM is where Teem's "make install" put subdirectories "bin", "lib", and "include" (e.g. ~/teem-build)
 
** CTYPES is the full path of ctypeslib-gccxml-0.9
 
* First create (in, for example, "teem-wrap") a meta-header for all the Teem header files (in tcsh):
 
  mkdir teemincl
 
  cp -r ${TEEM}/include/teem teemincl
 
  cd teemincl
 
  ls -1 teem/*.h | awk '{print "#include <"$1">"}' > all.h
 
  cd ..
 
* Then create teem.xml:
 
  setenv PYTHONPATH $CTYPES
 
  python $CTYPES/scripts/h2xml.py `pwd`/teemincl/all.h -I teemincl -o teem.xml
 
* Then create teem.py (use DYLD_LIBRARY_PATH in a mac):
 
  setenv LD_LIBRARY_PATH ${TEEM}/lib
 
  python $CTYPES/scripts/xml2py.py teem.xml -llibteem.so -o teem.py \
 
        -r "(air|hest|biff|nrrd|ell|unrrdu|moss|gage|bane|limn|seek|hoover|echo|ten|dye|mite).*"
 
  
 
====LEVMAR====
 
====LEVMAR====
Line 108: Line 57:
 
* The 2-tensor tractography depends on Levenberg-Marquardt nonlinear optimization of Sharon Peled's constrained two-tensor model. I used the following implementation for it: http://www.ics.forth.gr/~lourakis/levmar/
 
* The 2-tensor tractography depends on Levenberg-Marquardt nonlinear optimization of Sharon Peled's constrained two-tensor model. I used the following implementation for it: http://www.ics.forth.gr/~lourakis/levmar/
 
* First, in lm.h you need to uncomment the line that says: #undef HAVE_LAPACK (around line 30)
 
* First, in lm.h you need to uncomment the line that says: #undef HAVE_LAPACK (around line 30)
 +
* Change CMakeLists.txt in the teem folder. Below the required changes can be found.
 
* The levmar code is enabled by compiling Teem with TEEM_LEVMAR defined (turn LEVMAR ON while doing ccmake). The include paths and library link paths also need to be defined for everything to work.
 
* The levmar code is enabled by compiling Teem with TEEM_LEVMAR defined (turn LEVMAR ON while doing ccmake). The include paths and library link paths also need to be defined for everything to work.
 
* Here are the changes in the teem/CMakeLists.txt file that work for me:
 
* Here are the changes in the teem/CMakeLists.txt file that work for me:
Line 144: Line 94:
 
====Python processing package====
 
====Python processing package====
  
* This package needs to be downloaded here:
+
* This package can be downloaded here:
 
http://pypi.python.org/pypi/processing
 
http://pypi.python.org/pypi/processing
 
* Install the package in Slicer3-lib/python-build/lib/python2.5/site-packages/
 
* Install the package in Slicer3-lib/python-build/lib/python2.5/site-packages/

Latest revision as of 13:46, 14 September 2009

Wiki of Madeleine Seeland

General Information

About myself

I am a grad student of Management Information Systems at the University of Mannheim, Germany. I'm involved in the Diffusion Tensor Imaging (DTI) project in the Laboratory of Mathematics in Imaging. Currently I'm working on two-tensor tractograohy for Neurosurgery. I will document my research experience as a diploma thesis, which I need for completing my studies in Germany.

Contact information

E-mail: mseeland (at sign) bwh.harvard.edu

Collaborators & Contacts

  • Supervisors: C-F Westin, Nobuhiko Hata
  • Gordon Kindlmann (Teem)
  • Sharon Peled
  • Alireza Radmanesh
  • Isaiah Norton
  • Regarding Python: Steve Pieper, Julien de Siebenthal, Sylvain Bouix, Demian Wassermann, Luca Antiga

Project: Two-Tensor Tractography integration into Slicer

Project Description

  • Integration of Two-Tensor Tractography into Slicer using Python and the novel Python wrapping for Teem
  • Use of existing tractography methods in Teem (http://teem.sourceforge.net/)
  • My part: Interface between Slicer->Python->Teem and Teem->Python->Slicer
    • pass data from VTK through Python to Teem
    • make use of Teem tractography function calls
    • pass resulting fiber data from Teem to Python to VTK and display fiber tracts in Slicer

How to enable Python in Slicer 3.3

  • The current version of Slicer, Slicer 3.2, does not support Python. In order to use Python you need to install Slicer 3.3.
  • To build Slicer Version 3.3, just do the following two commands:
 svn co http://svn.slicer.org/Slicer3/trunk Slicer3
 ./Slicer3/Scripts/getbuildtest.tcl
  • In Slicer 3.3, Python support is disabled by default. In order to enable Python, just follow the next steps:
  1. Edit slicer_variables.tcl
    1. Change "set ::USE_PYTHON "off"" to "on"
  2. Optional: If you prefer to use your system Python installation, see here: [1]
  3. Optional: installing SciPy, see here: [2]. However, there are still problems adding scipy in Slicer, whcih are not fixed yet.
  • Rebuild Slicer3 using "getbuildtest.tcl":
./Slicer3/Scripts/getbuildtest.tcl

A new menu command Python Interpreter should appear on the Window menu in Slicer. This command should bring up the Python Console window.


Prerequisites for Two-Tensor Tractography module

Check out Two-Tensor Tractography

LEVMAR

  • The 2-tensor tractography depends on Levenberg-Marquardt nonlinear optimization of Sharon Peled's constrained two-tensor model. I used the following implementation for it: http://www.ics.forth.gr/~lourakis/levmar/
  • First, in lm.h you need to uncomment the line that says: #undef HAVE_LAPACK (around line 30)
  • Change CMakeLists.txt in the teem folder. Below the required changes can be found.
  • The levmar code is enabled by compiling Teem with TEEM_LEVMAR defined (turn LEVMAR ON while doing ccmake). The include paths and library link paths also need to be defined for everything to work.
  • Here are the changes in the teem/CMakeLists.txt file that work for me:

Replace the following line

 # Look for "levmar" library <http://www.ics.forth.gr/~lourakis/levmar/>
 OPTION(Teem_LEVMAR "Build Teem with levmar library support." OFF)
 SET(Teem_LEVMAR_LIB "")
 IF(Teem_LEVMAR)
   FIND_PACKAGE(LEVMAR)
   IF(LEVMAR_FOUND)
     ADD_DEFINITIONS(-DTEEM_LEVMAR)
     SET(Teem_LEVMAR_LIB ${LEVMAR_LIBRARIES})
     SET(Teem_LEVMAR_IPATH ${LEVMAR_INCLUDE_DIR})
   ELSE(LEVMAR_FOUND)
     # We need to set this as a cache variable, so that it will show up as
     # being turned off in the cache.
     MESSAGE(SEND_ERROR "Turning off Teem_LEVMAR, because it wasn't found.")
     SET(Teem_LEVMAR OFF CACHE BOOL "Build Teem with levmar library support." FORCE)
   ENDIF(LEVMAR_FOUND)
 ENDIF(Teem_LEVMAR)

with:

 # Look for "levmar" library <http://www.ics.forth.gr/~lourakis/levmar/>
 OPTION(Teem_LEVMAR "Build Teem with levmar library support." OFF)
 IF(Teem_LEVMAR)
     ADD_DEFINITIONS(-DTEEM_LEVMAR)
     SET(Teem_LEVMAR_PATH "/media/sda7/Programming/levmar")
     SET(Teem_LEVMAR_LIB "${LEVMAR_LEVMAR_PATH}/levmar-build/liblevmar.a" CACHE STRING "library path")
     SET(Teem_LEVMAR_IPATH "${LEVMAR_LEVMAR_PATH}/levmar-2.3" CACHE STRING "ipath")
 ENDIF(Teem_LEVMAR)

and replace the pathes with your pathes.

Python processing package

  • This package can be downloaded here:

http://pypi.python.org/pypi/processing

  • Install the package in Slicer3-lib/python-build/lib/python2.5/site-packages/
  • In the top directory of the package (containing setup.py and also this INSTALL file), type
 python setup.py install

Status/Progress

Month Week # Start Date - End Date Done Date Done
Find optimal parameter setting of the Two-Tensor Tractography method
Extend Two-Tensor Tractography module by fiducial seeding x
NA-MIC Project Week in Salt Lake City ([3],[4]) x
January Week 2 05.01 - 11.01
IGT Project Week x
Week 50 08.12 - 14.12
x
December Week 49 01.12 - 07.12
Try to compile teem with levmar (= Levenberg-Marquardt nonlinear least squares algorithm) x Mon Dec, 1st
Week 48 24.11 - 30.11
document the results of the two-tensor tractography given a tensor volume x
Try to do mutli trace tractography given a DWI volume x Mon Nov, 17th
Week 47 17.11 - 23.11
Working on Python tractography module for multi fiber tracing given a tensor volume x Mon Nov, 17th
Week 46 10.11 - 16.11
Get vertex data out of the nvert nrrd filled by the tractography back to Slicer x
Try to pass image data from Python to Teem through nrrdWrap_nva function x
Try to generate a list of point locations that were used as tractography seedpoints in the VTK tractography x Thu Nov, 13th
Implement Python tractography module for single fiber tracing given a seeding starting point and a tensor volume x Fri, Nov, 7th
Week 45 03.11 - 09.11
Try to get image data from numpy (= Python package) to Teem nrrd struct x
November Week 44 27.10 - 02.11
Try to get image data from numpy (= Python package) to Teem nrrd struct x
Week 43 20.10 - 26.10
Try to access DWI volumes through Python x Fri Oct, 17th
Get Teem wrapped in Python x Fri Oct, 19th
Week 42 13.10 - 19.10
Try to implement the seeding part of the (VTK) one-tensor tractography module in Python x Tue Oct, 14th
Week 41 06.10 - 12.10
Try to implement the seeding part of the (VTK) one-tensor tractography module in Python x Tue Oct, 14th
October Week 40 29.09 - 5.10
Totally understand existing Python modules in Slicer x
understand existing one-tensor streamline tractography in Slicer (VTK) x Tue Sep, 23rd
Totally understand existing Python modules in Slicer x Tue Sep, 23rd
Week 39 22.09 - 28.09
Slicer & Python Tutorials x
Enable Python in Slicer x Mon Sep, 22nd
September Week 38 14.09 - 21.09

Information

Python: