Git Product home page Git Product logo

Comments (9)

blowekamp avatar blowekamp commented on June 3, 2024

Hello,

I experimented with something similar to what you request in Python. Please find the topic here [1].

Basically, Something like the following code would be added to the R library:
%wrapper %{
SWIGEXPORT itk::simple::Image * convertSwigSimpleITKImage( SEXP obj )
{
itk::simple::Image img;
if (SWIG_ConvertPtr(obj, (void *
) &img, SWIGTYPE_p_itk__simple__Image, ??) == -1)
return NULL;
return img;
}
%}

You can look at the generated SimpleITKR_wrap.cxx file for more information.

I'd expect with this interface you should be able to work the Rcpp, but I haven't used it.

If you are able to give it a try, please share the results!

[1] master...blowekamp:AddCXXConvertInterfaceToPythonLibrary

from simpleitk.

zarquon42b avatar zarquon42b commented on June 3, 2024

Hi, thanks for your answer.
I will check it out.

from simpleitk.

zarquon42b avatar zarquon42b commented on June 3, 2024

Hi,
It is actually quite easy. The extern declaration of the SimpleITK function does the trick. I started a package and added a simple function that calls the SimpleITK code on C++ level (getting the image dimensions; see: https://github.com/zarquon42b/RcppSimpleITK/blob/master/src/test.cpp). I will try to pass indices and values as matrices and run the image filling on C++ too. Theoretically, this should work.

from simpleitk.

blowekamp avatar blowekamp commented on June 3, 2024

That was quick! Looks like some great progress.

The problem with your approach is that you are dependent on the swig generated interface, which is not a public interface that is define and is subject to change.

Explicitly declaring a Public method, as I suggest, to get a C++ sitk object from a R Swigged object is better for the long term as it ensure compatibility. This would require just one method as oppose each member function in yours.

Is there an advantage to your approach that I am missing?

from simpleitk.

zarquon42b avatar zarquon42b commented on June 3, 2024

OK, now I got what you meant (I have no experience with SWIG yet). I tested it and it works on my local machine (I have not pushed it yet). To make things portable, this approach requires a more tedious setup for a dependent R-package, involving configure scripts and cmake and a complete install of SimpleITK (not only the created R-package)
My naive lazy man's approach would have worked with the self-contained SimpleITK R-package without the need of the rest of SimpleITK and as all functions are targeting SEXP objects, passing data would be fairly easy.

from simpleitk.

blowekamp avatar blowekamp commented on June 3, 2024

I suppose I have a longer run view of being lazy. Your approach would work for one project, but maintaining it when something changes, or re-using it for multiple projects would be very difficult.

Yes, you will need to include the SimpleITK headers, and link against SimpleITK libraries. Fortunately, if you just use SimpleITK, you don't need ITK directly as it's not exposed as a public dependency. This should make things much easier.

CMake would take care of a lot of this, but integrating it in with the R packaging system you are using would be difficult.

from simpleitk.

zarquon42b avatar zarquon42b commented on June 3, 2024

OK, let's call it short-sightedly lazy ;)
Integrating cmake and R-package installation can actually work: I am already doing it in my package RvtkStatismo
After some further testing, I will issue a pull request regarding the necessary changes in R.i (in SimpleITK)

from simpleitk.

zarquon42b avatar zarquon42b commented on June 3, 2024

I got it up and running, including cmake and configure scripts. The example function (called 'test' successfully updates an sitk::Image's origin via the C++ interface and Rcpp.

from simpleitk.

zarquon42b avatar zarquon42b commented on June 3, 2024

FYI: the wrapping works brilliantly. In the new R-package, I added functionality to fill vector images using a matrices containing indices and vectors, and it is very fast now and allows any kind of image operations on C++ level.

from simpleitk.

Related Issues (20)

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.