[ITK] [ITK-users] (R wrapping/SimpleITK) AddCommand to ImageRegistrationMethod bug

Richard Beare richard.beare at gmail.com
Sat Apr 9 23:38:26 EDT 2016


There are still issues with garbage collection that we have partial
solutions for, but haven't put into master yet that may be causing issues,
but you'd be pretty unlucky. Usually such failures are rare until the
garbage collection torture is enabled.

I don't think your observer function is quite right - the image
registration one

commandIteration <- function(method)
{
res <- function() {
msg <- paste("Optimizer iteration number ", method$GetOptimizerIteration(),
" = ", method$GetMetricValue(), " : ", method$GetOptimizerPosition(),
"\n" )
cat(msg)
}
return(res)
}
Note that it is returning a function created internally. This is a
"closure" in R (I think) and the trick is that it retains a copy of the
environment, which includes the input argument.

Yours example is passing the result of print, which isn't a function. This
kind of error is meant to raise an exception, rather than crash
ungracefully, so there may be some more work to do there.



On Sun, Apr 10, 2016 at 11:10 AM, Mathew Guilfoyle <mrguilfoyle at gmail.com>
wrote:

> There seems to be a problem with using the $AddCommand function to
> ImageRegistrationMethod objects in the R wrapping to SimpleITK.
>
> Using R 3.2.4 on OS X 10.11
>
> Example:
>
> f <- function(x){print(x$GetMetricValue())}
>
> registration = ImageRegistrationMethod()
>
> registration$AddCommand(‘sitkIterationEvent’, f(registration))
>
> This last line causes R to abort/hard crash (no error message).  This
> behaviour is irrespective of which event type I use or the function passed
> as the second argument (e.g. even something simple like print(‘Hello’))
>
> The AddCommand method is inherited from the SimpleITK ProcessObject type.
> Digging around in the SimpleITK.R file I can see that the
> ProcessObject$AddCommand method expects a second argument of type
> ‘_p_itk__simple__Command’.
>
> There is a ‘Command’ method that generates a new object of type
> ‘_p_itk__simple__Command’.  If I pass this resulting object as the second
> argument to registration$AddCommand then I do not get an error.  However,
> there doesn’t seem to be any way to point the ‘_p_itk__simple__Command’
> object to my function or otherwise convert my function to a
> ‘_p_itk__simple__Command’ type.
>
> The $AddCommand method is used in a couple of example scripts on the
> SimpleITK site (using it for monitoring a registration and a filter e.g.
> https://github.com/SimpleITK/SimpleITK/blob/master/Examples/FilterProgressReporting.R)
> so I don’t know if it was working previously and a bug has been introduced
> more recently? (the example scripts cause the same error when I run them
> now)
>
>
>
> _____________________________________
> 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/community/attachments/20160410/79e3fbb7/attachment.html>
-------------- next part --------------
_____________________________________
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


More information about the Community mailing list