Comments (9)
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.
Hi, thanks for your answer.
I will check it out.
from simpleitk.
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.
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.
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.
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.
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.
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.
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)
- After registration, is the order of transforms composition specified in the documentation correct? HOT 4
- `MetaData dictionary key must be str`? HOT 2
- simpleITK python acts differently while reading metadata with upper or lower case hexadecimal label HOT 5
- Figure illustrating image concepts doesn't have clear text HOT 5
- ThresholdImage filter in Python HOT 2
- Add way to search docs
- Add docs on how to set/get the mask on an image HOT 1
- Provide reference documentation for transform parameters HOT 1
- Groupwise registration of 4D objects. Bad direction, determinant is 0. Direction is 1 0 0 HOT 1
- How to convert DisplacementFieldTransform to Image format and save it? HOT 1
- There was a problem merging two.NIIs into one
- There was a problem merging two.NIIs into one HOT 6
- Some special characters in metadata are truncated HOT 2
- Changing number of iterations per level of registration HOT 1
- Race condition in ErodeObjectMorphologyImageFilter HOT 2
- Incorrect resampling result with SimpleITK.sitkLinear Interpolator option HOT 4
- Update Elastix SuperBuild version HOT 2
- Linux availability of native library for java HOT 2
- Dicom series loaded with incorrect origin and spacing HOT 11
- elastix error when applying tranformparameters HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simpleitk.