[Insight-developers] SimpleITK TCON - Special Topic On R Wrapping

Richard Beare richard.beare at gmail.com
Wed Feb 1 18:46:12 EST 2012


I'll look into the ToString option.

I have a question - is there a method that provides mapping between
PixelValueID and the string that gets used in the accessor functions -
GetPixelValueAsUInt8 etc, or at least the UInt8 part?

I'm not quite sure what you mean by the second part. The code I've
added to deal with vectors currently does the following (note that
part is a replacement of the auto generated code that seems to be
incomplete):

1) Ties these types into the standard R display mechanisms (print and show)
2) Provides the standard R bracket operator for access and assignment.
The swig code did the latter, but wasn't quite complete.

Currently this means that the wrapped vectors act quite like R
objects. So you can do this sort of thing:

> testim <- ReadImage('cthead1.png')
>
> sp <- testim$GetSpacing()
# sp is a c++ object, which we can confirm by checking the class
> class(sp)
[1] "_p_std__vectorT_double_std__allocatorT_double_t_t"
# but we can display the contents
> sp
[1] 0.3527778 0.3527778
# we can also retrieve a single entry
sp[1]
[1] 0.3527778
# safely go out of bound?
> sp[3]
[[1]]
NULL
# use R style slicing (a bit meaningless for 2 elements)
> b<-sp[c(2,1,2,2)]
> b
[1] 0.3527778 0.3527778 0.3527778 0.3527778
# b is an R object
> class(b)
[1] "numeric"
# can directly copy sp to b
> b <- sp[]
> class(b)
[1] "numeric"

# assign to elements of sp, leaving sp as c++
> sp[] <- 5
> class(sp)
[1] "_p_std__vectorT_double_std__allocatorT_double_t_t"
> sp
[1] 5 5
# all the standard vector assignment rules apply sp[1] <- 6 etc



However, what you can't currently do is pass an R vector to one of the
swig functions and have it converted transparently

> testim$SetSpacing(testim, b)
ungraceful crash


I'm not sure how easy it is to get the binding layer to support R
objects directly. If it is hard then a lot of the pain of using the R
interface can be reduced by overloading the built in operators and
providing some helper functions to create the c++ objects when new
ones are needed.




On Thu, Feb 2, 2012 at 1:14 AM, Bradley Lowekamp <blowekamp at mail.nih.gov> wrote:
> Hello Richard,
>
> Looks like this is a nice step.
>
> I am forwarding this to the insight developers list as other may be
> interested in your work. It will be also best to share the discussions of
> SimpleITK design for posterity's sake.
>
> My couple of comments:
>
> The image print method should use sitk::Image::ToString. A very similar
> method exits is java and python and they all just use this method to print
> the object.
>
> It looks like you spent a little effort adding methods to the wrapped
> stl::vector class.The design of SimpleITK is to use the std::vector types
> for the small variable length vector and vectors that are the length of the
> image dimension. So they are used alot. I think the goal of wrapping them
> should be that this type gets mapped to the wrapped languages native
> array/vector type.
>
> I think we are going to need to spend a bit of time in this section of the
> SWIG documentation to get the R wrapping the way it should be:
>
> http://www.swig.org/Doc2.0/Extending.html#Extending
>
> Brad
>
> Begin forwarded message:
>
> From: Richard Beare <richard.beare at gmail.com>
> Date: January 31, 2012 11:21:55 PM EST
> To: "Lowekamp, Bradley (NIH/NLM/LHC) [C]" <blowekamp at mail.nih.gov>
> Subject: Re: SimpleITK TCON - Special Topic On R Wrapping
> Reply-To: "Richard.Beare at ieee.org" <Richard.Beare at ieee.org>
>
> Hi,
> I won't be able to attend the teleconference. I'm sending two files
> that implement some syntactic sugar - show and print methods for
> vectors/images and access/assignment using [ operators
>
>
>
> On Wed, Feb 1, 2012 at 1:12 PM, Bradley Lowekamp <blowekamp at mail.nih.gov>
> wrote:
>
> Hello,
>
>
> We will be having the SimpleITK TCON on Wednesday morning at 9:30am EST.
>
>
> There is a special topic on Wrapping for R based on significant interest by
>
> a variety of parties.
>
>
> Here is a rough agenda:
>
>
> http://www.itk.org/Wiki/ITK_Release_4/SimpleITK/Tcon_2012_2_1
>
>
> Please feel free to provide details, and add important issues.
>
>
> Brad
>
>
>
> ========================================================
>
>
> Bradley Lowekamp
>
>
> Medical Science and Computing for
>
>
> Office of High Performance Computing and Communications
>
>
> National Library of Medicine
>
>
> blowekamp at mail.nih.gov
>
>
>
>
>
>
> ========================================================
>
> Bradley Lowekamp
>
> Medical Science and Computing for
>
> Office of High Performance Computing and Communications
>
> National Library of Medicine
>
> blowekamp at mail.nih.gov
>
>
>
>
>


More information about the Insight-developers mailing list