Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.1K Views
|
8 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Skipped instances using Dynamic

Posted 3 years ago

When I execute the following sample code using a large Map operation and many Graphics3D objects, the end result (i=20) is shown without showing the intermediate results (i=1,i=2,..., i=19). I want to show each and every step. Can someone help?

Dynamic[a]
For[i = 1, i <= 20, i++,
b = RandomReal[{-1, 1}, {10000, 3}];
TextStr = {Text["i=" <> ToString[i], {0, 0, 5}]};
b3g = Map[Sphere[#, 1] &, b];
a = Graphics3D[{TextStr, b3g}, 
PlotRange -> {{-5, 5}, {-5, 5}, {-5, 5}}];
]

As a comparison, the sample code below without a large Map operation and with little Graphics3D objects, each and every individual step is visible.

Dynamic[c]
For[i = 1, i <= 20, i++,
d = RandomReal[{-1, 1}, {10000000, 3}];
TextStr = {Text["i=" <> ToString[i], {0, 0, 5}]};
c = Graphics3D[{TextStr, Sphere[d[[1]], 1]}, 
PlotRange -> {{-5, 5}, {-5, 5}, {-5, 5}}];
]
POSTED BY: John Lee
8 Replies
Posted 3 years ago

Eric, thanks again for the comment.

but now you're happy with completely externalizing the results for offline inspection.

If you run the last code example I uploaded, you may be able to monitor the Graphics3D output in real time at every intermediate step (i=1,2,3,...,20) as they are evaluated. Yes they are saved to the SSD as png files also but the important point is that it enables real-time screen monitoring without skipping any of the results and I am happy with that. If I save all the steps' outputs (hundreds or thousands of them) to an array and use ListAnimate, it may take up too much memory for my computer to handle so I rather decided to use For loop to keep updating the vector array variable as the calculation goes on, rather than keep appending it to another giant array of arrays. I am not as fluent as most of the experts here including you in Mathematica and I learned a lot from your comments. I guess that the problem might be ultimately solved if Dynamic can have an option to increase its graphical rendering priority as you implied, or there is a Pause-like function that waits until Dynamic finishes updating all of its graphical output.

POSTED BY: John Lee
Posted 3 years ago

Eric, thanks for the suggestion again. I inserted a png file Export command in place of the Pause as shown below and it just works fine and shows each and every step now. Probably the png Export requires the output of the updated Graphics3D object a enforcing it to wait until the graphics update is finished internally, or it simply took just enough time :).

a = Graphics3D[{}];
Dynamic[a]
For[i = 1, i <= 20, i++, b = RandomReal[{-1, 1}, {10000, 3}];
 TextStr = {Text["i=" <> ToString[i], {0, 0, 5}]};
 b3g = Map[Sphere[#, 1] &, b];
 a = Graphics3D[{TextStr, b3g}, 
   PlotRange -> {{-5, 5}, {-5, 5}, {-5, 5}}];
 Export["D:\\Downloads\\a" <> ToString[i] <> ".png", a]
 ]
POSTED BY: John Lee
Posted 3 years ago
POSTED BY: Eric Rimbey
Posted 3 years ago
POSTED BY: Eric Rimbey
Posted 3 years ago
POSTED BY: John Lee
Posted 3 years ago

You could do something like this instead:

centers = RandomReal[{-1, 1}, {20, 3}];
spheres = MapIndexed[
   Graphics3D[{Text["i=" <> ToString[#2[[1]]], {0, 0, 5}], 
      Sphere[#1]}, PlotRange -> {{-5, 5}, {-5, 5}, {-5, 5}}] &, 
   centers];
ListAnimate[spheres]
POSTED BY: Eric Rimbey
Posted 3 years ago

Why are you generating 10 million random triples when you only need 20?

POSTED BY: Eric Rimbey
Posted 3 years ago

If you figured out something that DOES show each step, then what is your question? Sounds like you answered your own question.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard