use of org.sunflow.system.Timer in project JWildfire by thargor6.
the class EDENController method buildScene.
public void buildScene() {
try {
clearConsole();
Timer t = new Timer();
t.start();
switch(sceneType) {
case JAVA:
api = SunflowAPI.compile(editorTextArea.getText());
break;
case SC:
{
File tmpFile = File.createTempFile("jwf", ".sc");
try {
String filename = tmpFile.getAbsolutePath();
Tools.writeUTF8Textfile(filename, editorTextArea.getText());
String template = "import org.sunflow.core.*;\nimport org.sunflow.core.accel.*;\nimport org.sunflow.core.camera.*;\nimport org.sunflow.core.primitive.*;\nimport org.sunflow.core.shader.*;\nimport org.sunflow.image.Color;\nimport org.sunflow.math.*;\n\npublic void build() {\n include(\"" + filename.replace("\\", "\\\\") + "\");\n}\n";
api = SunflowAPI.compile(template);
} finally {
tmpFile.deleteOnExit();
}
}
break;
}
if (currentFile != null) {
String dir = new File(currentFile).getAbsoluteFile().getParent();
api.searchpath("texture", dir);
api.searchpath("include", dir);
}
api.build();
t.end();
UI.printInfo(Module.GUI, "Build time: %s", t.toString());
enableControls();
} catch (Throwable ex) {
api = null;
errorHandler.handleError(ex);
}
}
use of org.sunflow.system.Timer in project joons-renderer by joonhyublee.
the class CausticPhotonMap method init.
@Override
public void init() {
UI.printInfo(Module.LIGHT, "Balancing caustics photon map ...");
Timer t = new Timer();
t.start();
balance();
t.end();
UI.printInfo(Module.LIGHT, "Caustic photon map:");
UI.printInfo(Module.LIGHT, " * Photons stored: %d", storedPhotons);
UI.printInfo(Module.LIGHT, " * Photons/estimate: %d", gatherNum);
maxRadius = 1.4f * (float) Math.sqrt(maxPower * gatherNum);
UI.printInfo(Module.LIGHT, " * Estimate radius: %.3f", gatherRadius);
UI.printInfo(Module.LIGHT, " * Maximum radius: %.3f", maxRadius);
UI.printInfo(Module.LIGHT, " * Balancing time: %s", t.toString());
if (gatherRadius > maxRadius) {
gatherRadius = maxRadius;
}
}
use of org.sunflow.system.Timer in project joons-renderer by joonhyublee.
the class SCParser method parse.
@Override
public boolean parse(String filename, SunflowAPIInterface api) {
String localDir = new File(filename).getAbsoluteFile().getParentFile().getAbsolutePath();
numLightSamples = 1;
Timer timer = new Timer();
timer.start();
UI.printInfo(Module.API, "Parsing \"%s\" ...", filename);
try {
p = new Parser(filename);
while (true) {
String token = p.getNextToken();
if (token == null) {
break;
}
if (token.equals("image")) {
UI.printInfo(Module.API, "Reading image settings ...");
parseImageBlock(api);
} else if (token.equals(BACKGROUND)) {
UI.printInfo(Module.API, "Reading background ...");
parseBackgroundBlock(api);
} else if (token.equals("accel")) {
UI.printInfo(Module.API, "Reading accelerator type ...");
p.getNextToken();
UI.printWarning(Module.API, "Setting accelerator type is not recommended - ignoring");
} else if (token.equals(FILTER)) {
UI.printInfo(Module.API, "Reading image filter type ...");
parseFilter(api);
} else if (token.equals("bucket")) {
UI.printInfo(Module.API, "Reading bucket settings ...");
api.parameter("bucket.size", p.getNextInt());
api.parameter("bucket.order", p.getNextToken());
api.options(SunflowAPI.DEFAULT_OPTIONS);
} else if (token.equals("photons")) {
UI.printInfo(Module.API, "Reading photon settings ...");
parsePhotonBlock(api);
} else if (token.equals("gi")) {
UI.printInfo(Module.API, "Reading global illumination settings ...");
parseGIBlock(api);
} else if (token.equals("lightserver")) {
UI.printInfo(Module.API, "Reading light server settings ...");
parseLightserverBlock(api);
} else if (token.equals("trace-depths")) {
UI.printInfo(Module.API, "Reading trace depths ...");
parseTraceBlock(api);
} else if (token.equals("camera")) {
parseCamera(api);
} else if (token.equals(SHADER)) {
if (!parseShader(api)) {
return false;
}
} else if (token.equals(MODIFIER)) {
if (!parseModifier(api)) {
return false;
}
} else if (token.equals("override")) {
api.parameter("override.shader", p.getNextToken());
api.parameter("override.photons", p.getNextBoolean());
api.options(SunflowAPI.DEFAULT_OPTIONS);
} else if (token.equals("object")) {
parseObjectBlock(api);
} else if (token.equals("instance")) {
parseInstanceBlock(api);
} else if (token.equals("light")) {
parseLightBlock(api);
} else if (token.equals("texturepath")) {
String path = p.getNextToken();
if (!new File(path).isAbsolute()) {
path = localDir + File.separator + path;
}
api.searchpath(TEXTURE, path);
} else if (token.equals("includepath")) {
String path = p.getNextToken();
if (!new File(path).isAbsolute()) {
path = localDir + File.separator + path;
}
api.searchpath("include", path);
} else if (token.equals("include")) {
String file = p.getNextToken();
UI.printInfo(Module.API, "Including: \"%s\" ...", file);
api.include(file);
} else {
UI.printWarning(Module.API, "Unrecognized token %s", token);
}
}
p.close();
} catch (ParserException e) {
UI.printError(Module.API, "%s", e.getMessage());
Logger.getLogger(SCParser.class.getName()).log(Level.SEVERE, null, e);
return false;
} catch (FileNotFoundException e) {
UI.printError(Module.API, "%s", e.getMessage());
return false;
} catch (IOException e) {
UI.printError(Module.API, "%s", e.getMessage());
return false;
} catch (ColorSpecificationException e) {
UI.printError(Module.API, "%s", e.getMessage());
return false;
}
timer.end();
UI.printInfo(Module.API, "Done parsing.");
UI.printInfo(Module.API, "Parsing time: %s", timer.toString());
return true;
}
use of org.sunflow.system.Timer in project joons-renderer by joonhyublee.
the class LightServer method calculatePhotons.
boolean calculatePhotons(final PhotonStore map, String type, final int seed, Options options) {
if (map == null) {
return true;
}
if (lights.length == 0) {
UI.printError(Module.LIGHT, "Unable to trace %s photons, no lights in scene", type);
return false;
}
final float[] histogram = new float[lights.length];
histogram[0] = lights[0].getPower();
for (int i = 1; i < lights.length; i++) {
histogram[i] = histogram[i - 1] + lights[i].getPower();
}
UI.printInfo(Module.LIGHT, "Tracing %s photons ...", type);
map.prepare(options, scene.getBounds());
int numEmittedPhotons = map.numEmit();
if (numEmittedPhotons <= 0 || histogram[histogram.length - 1] <= 0) {
UI.printError(Module.LIGHT, "Photon mapping enabled, but no %s photons to emit", type);
return false;
}
UI.taskStart("Tracing " + type + " photons", 0, numEmittedPhotons);
Thread[] photonThreads = new Thread[scene.getThreads()];
final float scale = 1.0f / numEmittedPhotons;
int delta = numEmittedPhotons / photonThreads.length;
photonCounter = 0;
Timer photonTimer = new Timer();
photonTimer.start();
for (int i = 0; i < photonThreads.length; i++) {
final int threadID = i;
final int start = threadID * delta;
final int end = (threadID == (photonThreads.length - 1)) ? numEmittedPhotons : (threadID + 1) * delta;
photonThreads[i] = new Thread(new Runnable() {
public void run() {
IntersectionState istate = new IntersectionState();
for (int i = start; i < end; i++) {
synchronized (LightServer.this) {
UI.taskUpdate(photonCounter);
photonCounter++;
if (UI.taskCanceled()) {
return;
}
}
int qmcI = i + seed;
double rand = QMC.halton(0, qmcI) * histogram[histogram.length - 1];
int j = 0;
while (rand >= histogram[j] && j < histogram.length) {
j++;
}
// make sure we didn't pick a zero-probability light
if (j == histogram.length) {
continue;
}
double randX1 = (j == 0) ? rand / histogram[0] : (rand - histogram[j]) / (histogram[j] - histogram[j - 1]);
double randY1 = QMC.halton(1, qmcI);
double randX2 = QMC.halton(2, qmcI);
double randY2 = QMC.halton(3, qmcI);
Point3 pt = new Point3();
Vector3 dir = new Vector3();
Color power = new Color();
lights[j].getPhoton(randX1, randY1, randX2, randY2, pt, dir, power);
power.mul(scale);
Ray r = new Ray(pt, dir);
scene.trace(r, istate);
if (istate.hit()) {
shadePhoton(ShadingState.createPhotonState(r, istate, qmcI, map, LightServer.this), power);
}
}
}
});
photonThreads[i].setPriority(scene.getThreadPriority());
photonThreads[i].start();
}
for (int i = 0; i < photonThreads.length; i++) {
try {
photonThreads[i].join();
} catch (InterruptedException e) {
UI.printError(Module.LIGHT, "Photon thread %d of %d was interrupted", i + 1, photonThreads.length);
return false;
}
}
if (UI.taskCanceled()) {
// shut down task cleanly
UI.taskStop();
return false;
}
photonTimer.end();
UI.taskStop();
UI.printInfo(Module.LIGHT, "Tracing time for %s photons: %s", type, photonTimer.toString());
map.init();
return true;
}
use of org.sunflow.system.Timer in project joons-renderer by joonhyublee.
the class BucketRenderer method render.
public void render(Display display) {
this.display = display;
display.imageBegin(imageWidth, imageHeight, bucketSize);
// set members variables
bucketCounter = 0;
// start task
UI.taskStart("Rendering", 0, bucketCoords.length);
Timer timer = new Timer();
timer.start();
BucketThread[] renderThreads = new BucketThread[scene.getThreads()];
for (int i = 0; i < renderThreads.length; i++) {
renderThreads[i] = new BucketThread(i);
renderThreads[i].setPriority(scene.getThreadPriority());
renderThreads[i].start();
}
for (int i = 0; i < renderThreads.length; i++) {
try {
renderThreads[i].join();
} catch (InterruptedException e) {
UI.printError(Module.BCKT, "Bucket processing thread %d of %d was interrupted", i + 1, renderThreads.length);
} finally {
renderThreads[i].updateStats();
}
}
UI.taskStop();
timer.end();
UI.printInfo(Module.BCKT, "Render time: %s", timer.toString());
display.imageEnd();
}
Aggregations