Search in sources :

Example 6 with Timer

use of org.sunflow.system.Timer in project joons-renderer by joonhyublee.

the class SunflowGUI method buildMenuItemActionPerformed.

private void buildMenuItemActionPerformed(ActionEvent evt) {
    new Thread() {

        @Override
        public void run() {
            setEnableInterface(false);
            if (clearLogMenuItem.isSelected()) {
                clearConsole();
            }
            Timer t = new Timer();
            t.start();
            try {
                api = SunflowAPI.compile(editorTextArea.getText());
            } catch (NoClassDefFoundError e) {
                UI.printError(Module.GUI, "Janino library not found. Please check command line.");
                api = null;
            }
            if (api != null) {
                try {
                    if (currentFile != null) {
                        String dir = new File(currentFile).getAbsoluteFile().getParent();
                        api.searchpath("texture", dir);
                        api.searchpath("include", dir);
                    }
                    api.build();
                } catch (Exception e) {
                    UI.printError(Module.GUI, "Build terminated abnormally: %s", e.getMessage());
                    for (StackTraceElement elt : e.getStackTrace()) {
                        UI.printInfo(Module.GUI, "       at %s", elt.toString());
                    }
                    Logger.getLogger(SunflowGUI.class.getName()).log(Level.SEVERE, null, e);
                }
                t.end();
                UI.printInfo(Module.GUI, "Build time: %s", t.toString());
            }
            setEnableInterface(true);
        }
    }.start();
}
Also used : Timer(org.sunflow.system.Timer) File(java.io.File) PropertyVetoException(java.beans.PropertyVetoException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 7 with Timer

use of org.sunflow.system.Timer in project joons-renderer by joonhyublee.

the class SunflowAPI method compile.

/**
 * Compile the specified code string via Janino. The code must implement a
 * build method as described above. The build method is not called on the
 * output, it is up the caller to do so.
 *
 * @param code java code string
 * @return a valid SunflowAPI object upon succes, <code>null</code>
 * otherwise.
 */
public static SunflowAPI compile(String code) {
    try {
        Timer t = new Timer();
        t.start();
        SunflowAPI api = (SunflowAPI) ClassBodyEvaluator.createFastClassBodyEvaluator(new Scanner(null, new StringReader(code)), SunflowAPI.class, (ClassLoader) null);
        t.end();
        UI.printInfo(Module.API, "Compile time: %s", t.toString());
        return api;
    } catch (CompileException e) {
        UI.printError(Module.API, "%s", e.getMessage());
        return null;
    } catch (ParseException e) {
        UI.printError(Module.API, "%s", e.getMessage());
        return null;
    } catch (ScanException e) {
        UI.printError(Module.API, "%s", e.getMessage());
        return null;
    } catch (IOException e) {
        UI.printError(Module.API, "%s", e.getMessage());
        return null;
    }
}
Also used : Scanner(org.codehaus.janino.Scanner) Timer(org.sunflow.system.Timer) ScanException(org.codehaus.janino.Scanner.ScanException) StringReader(java.io.StringReader) CompileException(org.codehaus.janino.CompileException) ParseException(org.codehaus.janino.Parser.ParseException) IOException(java.io.IOException)

Example 8 with Timer

use of org.sunflow.system.Timer in project joons-renderer by joonhyublee.

the class SunflowAPI method create.

/**
 * Create an API object from the specified file. Java files are read by
 * Janino and are expected to implement a build method (they implement a
 * derived class of SunflowAPI. The build method is called if the code
 * compiles succesfully. Other files types are handled by the parse method.
 *
 * @param filename filename to load
 * @return a valid SunflowAPI object or <code>null</code> on failure
 */
public static SunflowAPI create(String filename, int frameNumber) {
    if (filename == null) {
        return new SunflowAPI();
    }
    SunflowAPI api = null;
    if (filename.endsWith(".java")) {
        Timer t = new Timer();
        UI.printInfo(Module.API, "Compiling \"" + filename + "\" ...");
        t.start();
        try {
            FileInputStream stream = new FileInputStream(filename);
            api = (SunflowAPI) ClassBodyEvaluator.createFastClassBodyEvaluator(new Scanner(filename, stream), SunflowAPI.class, ClassLoader.getSystemClassLoader());
            stream.close();
        } catch (CompileException e) {
            UI.printError(Module.API, COULDNT_MESSAGE_FORMAT, filename);
            UI.printError(Module.API, "%s", e.getMessage());
            return null;
        } catch (ParseException e) {
            UI.printError(Module.API, COULDNT_MESSAGE_FORMAT, filename);
            UI.printError(Module.API, "%s", e.getMessage());
            return null;
        } catch (ScanException e) {
            UI.printError(Module.API, COULDNT_MESSAGE_FORMAT, filename);
            UI.printError(Module.API, "%s", e.getMessage());
            return null;
        } catch (IOException e) {
            UI.printError(Module.API, COULDNT_MESSAGE_FORMAT, filename);
            UI.printError(Module.API, "%s", e.getMessage());
            return null;
        }
        t.end();
        UI.printInfo(Module.API, "Compile time: " + t.toString());
        // allow relative paths
        String currentFolder = new File(filename).getAbsoluteFile().getParentFile().getAbsolutePath();
        api.includeSearchPath.addSearchPath(currentFolder);
        api.textureSearchPath.addSearchPath(currentFolder);
        UI.printInfo(Module.API, "Build script running ...");
        t.start();
        api.currentFrame(frameNumber);
        api.build();
        t.end();
        UI.printInfo(Module.API, "Build script time: %s", t.toString());
    } else {
        api = new SunflowAPI();
        api = api.include(filename) ? api : null;
    }
    return api;
}
Also used : Scanner(org.codehaus.janino.Scanner) Timer(org.sunflow.system.Timer) ScanException(org.codehaus.janino.Scanner.ScanException) CompileException(org.codehaus.janino.CompileException) ParseException(org.codehaus.janino.Parser.ParseException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 9 with Timer

use of org.sunflow.system.Timer in project joons-renderer by joonhyublee.

the class GlobalPhotonMap method init.

@Override
public void init() {
    UI.printInfo(Module.LIGHT, "Balancing global photon map ...");
    UI.taskStart("Balancing global photon map", 0, 1);
    Timer t = new Timer();
    t.start();
    balance();
    t.end();
    UI.taskStop();
    UI.printInfo(Module.LIGHT, "Global photon map:");
    UI.printInfo(Module.LIGHT, "  * Photons stored:   %d", storedPhotons);
    UI.printInfo(Module.LIGHT, "  * Photons/estimate: %d", numGather);
    UI.printInfo(Module.LIGHT, "  * Estimate radius:  %.3f", gatherRadius);
    maxRadius = 1.4f * (float) Math.sqrt(maxPower * numGather);
    UI.printInfo(Module.LIGHT, "  * Maximum radius:   %.3f", maxRadius);
    UI.printInfo(Module.LIGHT, "  * Balancing time:   %s", t.toString());
    if (gatherRadius > maxRadius) {
        gatherRadius = maxRadius;
    }
    t.start();
    precomputeRadiance();
    t.end();
    UI.printInfo(Module.LIGHT, "  * Precompute time:  %s", t.toString());
    UI.printInfo(Module.LIGHT, "  * Radiance photons: %d", storedPhotons);
    UI.printInfo(Module.LIGHT, "  * Search radius:    %.3f", gatherRadius);
}
Also used : Timer(org.sunflow.system.Timer)

Example 10 with Timer

use of org.sunflow.system.Timer in project joons-renderer by joonhyublee.

the class MultipassRenderer method render.

public void render(Display display) {
    this.display = display;
    display.imageBegin(imageWidth, imageHeight, bucketSize);
    // set members variables
    bucketCounter = 0;
    // start task
    Timer timer = new Timer();
    timer.start();
    UI.taskStart("Rendering", 0, bucketCoords.length);
    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();
}
Also used : Timer(org.sunflow.system.Timer)

Aggregations

Timer (org.sunflow.system.Timer)17 IOException (java.io.IOException)6 File (java.io.File)4 IntArray (org.sunflow.util.IntArray)3 FileNotFoundException (java.io.FileNotFoundException)2 CompileException (org.codehaus.janino.CompileException)2 ParseException (org.codehaus.janino.Parser.ParseException)2 Scanner (org.codehaus.janino.Scanner)2 ScanException (org.codehaus.janino.Scanner.ScanException)2 Color (org.sunflow.image.Color)2 Vector3 (org.sunflow.math.Vector3)2 PropertyVetoException (java.beans.PropertyVetoException)1 EOFException (java.io.EOFException)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 StringReader (java.io.StringReader)1 SceneParser (org.sunflow.core.SceneParser)1 ColorSpecificationException (org.sunflow.image.ColorFactory.ColorSpecificationException)1 BoundingBox (org.sunflow.math.BoundingBox)1 Point3 (org.sunflow.math.Point3)1