<div dir="ltr">Some of the FilterProgressReporting example doesn't make sense to me. It shouldn't be necessary to access RCommand - it is used internally by AddCommand. We probably shouldn't make it directly accessible from R. The following works for me. A closure is necessary if you want the callback to access the filter, for example to print measures<div>contained in the filter that is making the callback. Also note that in the first message you were passing the function result, not the function.<br><div><br></div><div>## get an image</div><div><p style="margin:0px;font-size:10px;font-family:Monaco">p <- PhysicalPointImageSource()</p><p style="margin:0px;font-size:10px;font-family:Monaco">p$SetOrigin(c(-1, -1))</p><p style="margin:0px;font-size:10px;font-family:Monaco">p$SetSize(c(50,50))</p><p style="margin:0px;font-size:10px;font-family:Monaco">pim <- p$Execute()</p><p style="margin:0px;font-size:10px;font-family:Monaco"><br></p><p style="margin:0px;font-size:10px;font-family:Monaco">pimOneChannel <- pim[[1]]</p><p style="margin:0px;font-size:10px;font-family:Monaco"><br></p><p style="margin:0px;font-size:10px;font-family:Monaco">f1 <- function() {print("Start")}</p><p style="margin:0px;font-size:10px;font-family:Monaco">f2 <- function(){print("End")}</p><p style="margin:0px;font-size:10px;font-family:Monaco"><br></p><p style="margin:0px;font-size:10px;font-family:Monaco">gaussian <- DiscreteGaussianImageFilter()</p><p style="margin:0px;font-size:10px;font-family:Monaco">
</p><p style="margin:0px;font-size:10px;font-family:Monaco">gaussian$SetVariance( 2 )</p><p style="margin:0px;font-size:10px;font-family:Monaco">gaussian$AddCommand( 'sitkStartEvent',  f1 )</p><div><p style="margin:0px;font-size:10px;font-family:Monaco">gaussian$AddCommand( 'sitkEndEvent', f2 )</p></div><div><p style="margin:0px;font-size:10px;font-family:Monaco"><br></p><p style="margin:0px;font-size:10px;font-family:Monaco">filtered <- gaussian$Execute( pimOneChannel )</p></div><div><br></div><div><br></div><div><br></div><p style="margin:0px;font-size:10px;font-family:Monaco"><br></p></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 10, 2016 at 11:46 PM, Mathew Guilfoyle <span dir="ltr"><<a href="mailto:mrguilfoyle@gmail.com" target="_blank">mrguilfoyle@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Richard<br>
<br>
Thanks for the reply.  I hadn't appreciated that function being passed in the registration example was a closure.  However, in the FiterProgressReporting example it is not a closure.<br>
<br>
I have modified my code to be a closure but still get a crash/abort; I have also run the code in the examples themselves verbatim and get the same problem.<br>
<br>
Any further ideas on how to get this working?<br>
<br>
Cheers<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
> On 10 Apr 2016, at 02:10, Mathew Guilfoyle <<a href="mailto:mrguilfoyle@gmail.com">mrguilfoyle@gmail.com</a>> wrote:<br>
><br>
> There seems to be a problem with using the $AddCommand function to ImageRegistrationMethod objects in the R wrapping to SimpleITK.<br>
><br>
> Using R 3.2.4 on OS X 10.11<br>
><br>
> Example:<br>
><br>
> f <- function(x){print(x$GetMetricValue())}<br>
><br>
> registration = ImageRegistrationMethod()<br>
><br>
> registration$AddCommand(‘sitkIterationEvent’, f(registration))<br>
><br>
> 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’))<br>
><br>
> 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’.<br>
><br>
> 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.<br>
><br>
> 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. <a href="https://github.com/SimpleITK/SimpleITK/blob/master/Examples/FilterProgressReporting.R" rel="noreferrer" target="_blank">https://github.com/SimpleITK/SimpleITK/blob/master/Examples/FilterProgressReporting.R</a>) 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)<br>
><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div>