Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm attempting to display an image sequence of 40 images inside of a Manipulate that cycles through each frame with a slider. I would like the Manipulate to appear in a separate DialogBox. I see a significant performance difference if I try to encapsulate this functionality inside its own function. This code displays the dialog nearly instantaneously:

CreateDialog[
  Manipulate[
    imageSequence[[frame]], {frame, 1, Length[imageSequence], 1}]]

However the code below takes around 10 seconds for the dialog to appear:

showit[imageSequence_] := 
  CreateDialog[
    Manipulate[
      imageSequence[[frame]], {frame, 1, Length[imageSequence], 1}]]

showit[imageSequence]

It does not seem to matter if the function definition is surrounded by DynamicModule or not. Any ideas what is going on and what I can do to improve performance while maintaining encapsulation?

Thanks!

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Try

showit[imageSequence_] := 
  CreateDialog[
    Module[{i = imageSequence}, 
    Manipulate[i[[frame]], {frame, 1, Length[imageSequence], 1}]] ];
showit[imageSequence];

As to any insights what is going on here, I think you used the literal imagelist as Manipulate expression, thereby loading the whole of it into the front end and putting it into the manipulate cell. I used i$xxxx as nanipulate expression, which is just a link to the actual imagelist in the kernel, from which a single frame is loaded on demand. Note, that your version of the dialog is self-contained and may be saved and then reopened in another session, my version in that case will not work, since the image list is no longer there in the kernel. Also note, that using DynamicModule doesn't help because it also keeps its variables in the front end. You may also link directly to your image lists in the kernel just by adding SetAttributes[showit, HoldAll] to your code, or using showit[Unevaluated@imageSequence]

share|improve this answer
3  
It works! Any insight as to what exactly is going on behind the scenes? –  bridges2 Jul 21 '13 at 19:08
    
@bridges2, added some to the answer –  panda-34 Jul 22 '13 at 5:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.