[ITK-users] SimpleITK and R wrapping problems (bugs?)

Richard Beare richard.beare at gmail.com
Sun Apr 3 21:30:09 EDT 2016


OK, it turns out there are a couple of issues. The first one is that static
member functions aren't being included in the list of functions accessible
via '$' operator. Not sure if yet whether this is an option we can turn on
via swig configuration. The second error is caused by incomplete support
for character vectors. The C layer is turning the c++ vectors into R
vectors, but I forgot to include the typemap that stops the R part of the
swig binding thinking that it is still a c++ vector pointer. You can
include a temporary fix at the R level be rewriting the function as follows:

ImageSeriesReader_GetGDCMSeriesFileNames__SWIG_0 <- function (directory,
useSeriesDetails, recursive, loadSequences,
    loadPrivateTags, .copy = FALSE)
{
    directory = as(directory, "character")
    useSeriesDetails = as.logical(useSeriesDetails)
    recursive = as.logical(recursive)
    loadSequences = as.logical(loadSequences)
    loadPrivateTags = as.logical(loadPrivateTags)
    ans = .Call("R_swig_ImageSeriesReader_GetGDCMSeriesFileNames__SWIG_0",
        directory, useSeriesDetails, recursive, loadSequences,
        loadPrivateTags, as.logical(.copy), PACKAGE = "SimpleITK")
    # comment out the following two lines
    #ans <-
new("_p_std__vectorT_std__string_std__allocatorT_std__string_t_t",
    #    ref = ans)
    ans
}

and repeat for the other __SWIG_? functions that use a .Call

I'm not yet certain whether the fix needs to happen in the simpleITK side
or in swig.


On Mon, Apr 4, 2016 at 1:18 AM, Mathew Guilfoyle <mrguilfoyle at gmail.com>
wrote:

> Hi
>
> I’ve been trying to get to grips with using the R wrapping to SimpleITK.
> On OS X 10.11 I’ve successfully built/compiled SimpleITK from source with
> Python and R wrapping turned on in Cmake.  I can import the SimpleITK
> package into R 3.2.4 within Studio without any error reports.
>
> The main difficulties I’m finding are around importing CT image volumes
> which are stored as a series of image slices within a single directory.
> Following the usual workflow I’ve tried in Python I start with:
>
> reader = ImageSeriesReader()
>
> this works ok but the ‘GetGDCMSeriesFileNames’ function is not exposed for
> the reader object via the $ operator.   This is in contrast to the Python
> wrapping where this function is available as
> 'reader.GetGDCMSeriesFilenames()'
>
> In R the ImageSeriesReader_GetGDCMSeriesFileNames() static function is
> available but does not work when supplied with a directory either as a R
> character vector or as a SimpleITK ‘VectorString’ object.
>
> For the moment I have resorted to getting a list of the files with native
> R code. Passing this list as an argument to reader$SetFileNames() causes
> the R session to crash.  Instead I’ve created a (SimpleITK) VectorString of
> appropriate length and then transfer the individual filenames from the R
> list within a loop, before finally using the
> reader$SetFileNames(VectorString) method.  When I then run reader$Execute
> the DICOM image series is correctly read to an image object.
>
> Next I need to do some initial image transformation based on certain
> fields of DICOM metadata.  However, I’ve not been able to access this at
> all.  The image$GetMetaDataKeys() function does not work, reporting the
> error:
>
> *Error in validObject(.Object) : *
> *  invalid class
> “_p_std__vectorT_std__string_std__allocatorT_std__string_t_t” object:
> invalid object for slot "ref" in class
> "_p_std__vectorT_std__string_std__allocatorT_std__string_t_t": got class
> "character", should be or extend class "externalptr"*
>
> Image$GetMetaData(key) also returns an error whatever key value I use
> (including DICOM keys that I know are included in the series), whether
> these are passed as as an R character string or SimpleITK VectorString.
>
> I know that the metadata is being read, at least to a certain extent,
> because  basic info like pixel spacing, image direction, origin etc are all
> present and correct, and accessible via their dedicated Get.. methods.
>
> If I’m using these functions with incorrect arguments or committing some
> other error I would be grateful for any pointers.
>
> Cheers
> Mat
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20160404/9e78f6f4/attachment.html>


More information about the Insight-users mailing list