Git Product home page Git Product logo

sirfproject's Introduction

Automatic Generation of Python Interfaces to the C++ Synergistic Image Reconstruction Framework

This is a course project module used as part of the UCL MSc Scientific and Data Intensive Computing.

Installation

To get thisalamodule (an automatic generated Python interface to SIRF) running, you might need to install SIRF from https://github.com/SyneRBI/SIRF-SuperBuild first. You may also need to install SWIG, boost and CMake to perform SIRF-SuperBuild installation.

Usage

Firstly, please downloadmainfolder; Then please use CMake and a C++ compiler like VS2019's MSVC to install this SWIG project and obtain the auto-generated python module files ala.py & _ala.pyd. Please open PowerShell and input these lines before the next step:

$install="...\SIRFbuild\INSTALL" (your SIRF location)
 $Env:Path = "${install}\bin" + ";" + $Env:Path
 $Env:Path += ";${install}\FFTW"
 $Env:Path += ";.../boost_1_76_0/lib64-msvc-14.1/" (your boost location)
 $Env:SIRF_PATH = "...\SIRFbuild\sources\SIRF"
 $Env:PYTHONPATH = "${install}\python"
 $Env:MATLABPATH = "${install}\matlab"
 $Env:MATLABPATH+='; ...\SIRFbuild\sources\SPM'
 $Env:Path += ";...\MATLAB\extern\bin\win64; ...\MATLAB\bin\win64" (your MATLAB location)

Then please download & runtest_functionality.pyin Python to test thealamodule's functionalities.

sirfproject's People

Contributors

lerocci avatar kristhielemans avatar

Watchers

 avatar

sirfproject's Issues

allow using SIRF files in different places

you should be able to use SIRF include files that are located elsewhere. At present you specify include_directories as being in the current directory (where the source is).

include_directories(${CMAKE_SOURCE_DIR})

You can add other directories as well. You could do something like

set(SIRF_SOURCE "${CMAKE_SOURCE_DIR}" CACHE PATH "Location of the SIRF source")
include_directories(${SIRF_SOURCE}/src/common/include/)

and whatever you need.

At some point, you will be using an installed SIRF, in which case all SIRF include files will be in one location, but you can then just modify the above accordingly.

pass -doxygen flag

SWIG 4.0 can parse doxygen comments in the C++ file and pass them on to Python. It even handles LaTex formulas as far as I can see.

Something like this in the CMakeLists.txt (but I didn't check the if statement)

  if (SWIG_VERSION VERSION_GREATER_OR_EQUAL 4.0.0)
      SET(CMAKE_SWIG_FLAGS -doxygen)
  endif()

add lines to CMake to install Python files

we need to be able to copy the files after building to a particular location. You can probably just copy the following lines from STIR
https://github.com/UCL/STIR/blob/40545147179fbe2b1131679672375cc91a39ab55/src/swig/CMakeLists.txt#L116-L118
obviously adjusting the name (stir) to your project.

After inserting those, if you run CMake, you should have a PYTHON_DEST variable in the list of things that you can set. You can then set it to where you want it. As it's a CACHED variable, it will remember what you set for next time, such that you have to do this only once.

handle clone()

As clone() returns a std::unique_ptr, which SWIG cannot handle yet, we have to work-around it.

A first step could be like

%ignore *::clone()
%extend sirf::DataContainer
{
  DataContainer * my_clone() const
  { 
    return clone().get();
  }
}

%newobject *::my_clone();

FBP2D reconstruction

Lines 57 to 66 from ...\sources\SIRF\examples\Python\PET\fbp2d_reconstruction.py can be used as a starting point with FBP2D reconstruction script.

make interface more python-like

The wrapping works at the moment, but people will expect the objects to act Python-like. For instance

a.items()
# vs Python-style:
len(a)

This can be achieved in 2 ways I believe

Next step would be to do some arithmetic operations:

 a.multiply(b,c)
 #vs Python-style:
 a = b*c

Similarly, you can try something like

  • using %rename to rename multiply to operator*
  • using %extend to add operator*.

Some (not so easy) doc on this is http://swig.sourceforge.net/Doc4.0/Python.html#Python_builtin_overloads

I think the %rename options are probably best.

duplication?

would you be able to clarify the (almost?) duplication between the files in the main folder and the swigtest folder? I didn't check yet, but they same virtually the same.

try some renaming to be closer to existing SIRF interface

There are a few functions/classes that are currently called differently after SWIG compared to SIRF. Examples are

  • my_clone -> clone (can probably just be called like that in the .i)
  • from_array -> fill. Of course, there's a fill(float) already, but it looks like SWIG will take care of checking the argument types. You should show this by making your test script call both fill(1.1) and fill(some_ndarray). You could even check the generated wrapper if you feel like it. If this works, it would be worth commenting on in the report
  • xSTIR_FBP2DReconstruction -> FBP2DReconstructor I believe (this would need a %rename)

adjust wrapping for std:: classes

Like the std_string.i, you probably will need to add a few others, maybe only std_vector.i and std_shared_ptr.i, see
http://www.swig.org/Doc4.0/Library.html#Library_stl_cpp_library

In particular, the shared_ptr will be important. This is a bit more work than just including that file, see
http://www.swig.org/Doc4.0/Library.html#Library_std_shared_ptr
essentially

%include <std_shared_ptr.i>
%shared_ptr(sirf::DataContainer)
%shared_ptr(sirf::ImageData)
Etc
%include "sirf/common/DataContainer.h"
Etc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.