We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProcessing DevelopmentLibraries,  Tool Development › Refreshing PApplet mid-draw
Page Index Toggle Pages: 1
Refreshing PApplet mid-draw (Read 3820 times)
Refreshing PApplet mid-draw
Oct 28th, 2007, 4:47am
 
Howdy.

I'm working on getting P5Sunflow up to speed, and was struggling with a little problem I was hoping Someone Much Smarter Than Me would be able to come up with an obvious solution to.  Have I just ended a sentence in a preposition  You don't know.  You have to look it up.  Or, at least I had to.

Anyway, the ray tracing stuff can be a pretty long running processes.  Throughout the process Sunflow is updating pixels, which I'm grabbing, and setting in PGraphics.pixels.  However, because the PApplet is (I think) in the middle of a thread locked draw, my squirrel-like brain is entirely unable to figure how to get PApplet's screen to update in the process.

I would love to be able to provide the user with a real-time-ish update beyond "Rendering [12%]," but I've clashed against A Wall Of Utter Confusion.

So, in short, I would like to tell the PApplet to draw the pixels while it is in the middle of drawing the pixels.

I am entirely unable to bake a cake in the likeness of a human head, but I promise to learn such a skill if anyone would be able to hack around this problem.  The first cake, of course, would be formed to the problem-solver's head, and be presented to said problem-solver.
Re: Refreshing PApplet mid-draw
Reply #1 - Oct 30th, 2007, 3:07pm
 
for the time consuming stuff, make a separate thread and run it there, drawing into a context made with createGraphics(). meanwhile, set the main sketch to run at a low framerate, and have it ask the other thread about its progress from time to time. it's fairly involved due to the threading issues, but this is how you'd go about it.
Re: Refreshing PApplet mid-draw
Reply #2 - Oct 31st, 2007, 2:52pm
 
Awesome.  I'll give this a shot.  I see many synchronized methods in my future.

Thanks.
Re: Refreshing PApplet mid-draw
Reply #3 - Oct 31st, 2007, 9:45pm
 
Hi mchadw
Good work on Sunflow.. lots of people have been playing with it, including my friends. A few of them have been getting java version mismatch errors, but that is another topic completely Smiley

I've recently had to write a bunch of "load in the background" methods lately and threads are definitely the best way to do it. You don't need any synchronized methods as far as I'm concerned... simply keep a float to track the progress of your render and in your main draw() do your display for % done. All your rendering code will simply called from a separate thread, and the biggest difference being that you're rendering to an offscreen buffer rather than the P5 main buffer.

Good luck! And remember: the cake is a lie!
Re: Refreshing PApplet mid-draw
Reply #4 - Oct 31st, 2007, 10:47pm
 
mflux,

Thanks, I like that percent-done idea.  My hope was to keep it 1:1 with Processing's frames, so things like MovieMaker worked out of the box.  But, I'm starting to think that may not be possible (with on-screen feedback).

Real quick, to further propagate the off-topicness, Sunflow is all Java 1.6, I've compiled it to 1.5 bytecode (same w/ my code).  I don't think it's possible to get <= 1.4- bytecode out of >= 1.5 Java.  Anyway, make sure 1.5+ is installed, and download processing *without Java*.  Processing will use its bundled VM regardless of what you have installed (right?).

And, thanks for letting my secret out about the cake, man!  I had a good thing going, there.  I'll never be respected again.  Maybe I can make it up with a picture of a cake I once bought my girlfriend?  Is that close?

http://www.ihearyoulikestories.com/images/pumacake.jpg
Re: Refreshing PApplet mid-draw
Reply #5 - Apr 11th, 2008, 12:22am
 
As an experiment, I tried using createGraphics() with p5Sunflow as the renderer:

----------------

Code:

import hipstersinc.sunflow.*;
import hipstersinc.sunflow.shader.*;
import hipstersinc.*;
import processing.opengl.*;

PGraphics sunflow;

void setup() {
 size(400, 300, P3D);
 frameRate(15);
}

void draw() {
 background(255);
 camera(300, -300, 300, 0, 0, 0, 0, -1, 0);
 perspective();
 fill(255, 150, 0);
 box(100, 100, 100);
}

void keyPressed() {
 if (key == 'r') {
   sunflowRender();
 }
}

void sunflowRender() {
 println("Beginning Sunflow render...");
 noLoop();
 sunflow = createGraphics(400, 300, "hipstersinc.P5Sunflow");
 sunflow.beginDraw();
 sunflow.background(255);
 sunflow.camera(300, -300, 300, 0, 0, 0, 0, -1, 0);
 sunflow.perspective();
 sunflow.fill(255, 150, 0);
 sunflow.box(100, 100, 100);
 sunflow.endDraw();
 sunflow.save("output.tif");
 println("Sunflow render complete.");
 loop();
}

--------------

Calling sunflowRender() throws the following exception:

----------------
Code:

java.lang.NullPointerException

at hipstersinc.P5Sunflow.<init>(P5Sunflow.java:59)

java.lang.NullPointerException

at hipstersinc.P5Sunflow.<init>(P5Sunflow.java:59)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

at java.lang.reflect.Constructor.newInstance(Constructor.java:494)

at processing.core.PApplet.createGraphics(PApplet.java:1218)

at processing.core.PApplet.createGraphics(PApplet.java:1124)

at Temporary_2874_7633.sunflowRender(Temporary_2874_7633.java:30)

at Temporary_2874_7633.keyPressed(Temporary_2874_7633.java:23)

at processing.core.PApplet.handleKeyEvent(PApplet.java:2016)

at processing.core.PApplet.dequeueKeyEvents(PApplet.java:1992)

at processing.core.PApplet.handleDisplay(PApplet.java:1495)

at processing.core.PGraphics.requestDisplay(PGraphics.java:690)

at processing.core.PApplet.run(PApplet.java:1562)

at java.lang.Thread.run(Thread.java:613)
java.lang.RuntimeException

at processing.core.PApplet.createGraphics(PApplet.java:1235)

at processing.core.PApplet.createGraphics(PApplet.java:1124)

at Temporary_2874_7633.sunflowRender(Temporary_2874_7633.java:30)

at Temporary_2874_7633.keyPressed(Temporary_2874_7633.java:23)

at processing.core.PApplet.handleKeyEvent(PApplet.java:2016)

at processing.core.PApplet.dequeueKeyEvents(PApplet.java:1992)

at processing.core.PApplet.handleDisplay(PApplet.java:1495)

at processing.core.PGraphics.requestDisplay(PGraphics.java:690)

at processing.core.PApplet.run(PApplet.java:1562)

at java.lang.Thread.run(Thread.java:613)

----------------

Right now I'm exporting geometry and rendering it with Sunflow in a separate sketch, which works fine... but it would be super cool to have Sunflow render in the background from a single sketch.
Re: Refreshing PApplet mid-draw
Reply #6 - May 22nd, 2009, 8:14am
 
What's the status of P5Sunflow?  Has it been successfully updated?
Page Index Toggle Pages: 1