Search in sources :

Example 1 with SunflowAPI

use of org.sunflow.SunflowAPI in project JWildfire by thargor6.

the class FilterKernelVisualisation3dRenderer method createKernelVisualisation.

public SimpleImage createKernelVisualisation(int pWidth, int pHeight) {
    String key = makeKey(pWidth, pHeight);
    SimpleImage img = cache.get(key);
    if (img == null) {
        img = new SimpleImage(pWidth, pHeight);
        if (noiseFilterSize > 0) {
            Scene scene = createScene(pWidth, pHeight);
            double sunflowScale = 10.0;
            double sunflowZScale = 0.6;
            int rectCount = noiseFilterSize;
            double dx = (double) pWidth / (double) rectCount;
            double dy = (double) pHeight / (double) rectCount;
            double w2 = (double) pWidth / 2.0;
            double h2 = (double) pHeight / 2.0;
            double xOff = 0.0, yOff = 0.0;
            for (int i = 0; i < noiseFilterSize; i++) {
                xOff = 0;
                for (int j = 0; j < noiseFilterSize; j++) {
                    double fValue = filter[i][j];
                    Color rectColor;
                    if (fValue >= 0) {
                        int fValueClr = Tools.FTOI(255.0 * fValue);
                        if (fValueClr > 255) {
                            fValueClr = 255;
                        }
                        rectColor = new Color(fValueClr, fValueClr, fValueClr);
                    } else {
                        int fValueClr = Tools.FTOI(-255.0 * (fValue - 0.5));
                        if (fValueClr > 255) {
                            fValueClr = 255;
                        }
                        rectColor = new Color(fValueClr, 0, 0);
                    }
                    addCube(scene, sunflowScale * (xOff - w2) / (double) pWidth, sunflowScale * (yOff - h2) / (double) pHeight, sunflowScale * dx / (double) pWidth, sunflowScale * dy / (double) pHeight, sunflowScale * fValue * sunflowZScale, rectColor);
                    xOff += dx;
                }
                yOff += dy;
            }
            try {
                SunflowAPI api = createSunflowRenderer(scene);
                SunFlowImagePanel imagePanel = new SunFlowImagePanel();
                imagePanel.setBounds(0, 0, pWidth, pHeight);
                api.render(SunflowAPI.DEFAULT_OPTIONS, imagePanel);
                img.setBufferedImage(imagePanel.getImage(), imagePanel.getWidth(), imagePanel.getHeight());
            } catch (Exception e) {
                e.printStackTrace();
                img.fillBackground(emptyFilterColor.getRed(), emptyFilterColor.getGreen(), emptyFilterColor.getBlue());
            }
        } else {
            img.fillBackground(emptyFilterColor.getRed(), emptyFilterColor.getGreen(), emptyFilterColor.getBlue());
        }
        cache.put(key, img);
    }
    return img;
}
Also used : SunflowAPI(org.sunflow.SunflowAPI) SimpleImage(org.jwildfire.image.SimpleImage) Color(java.awt.Color) Scene(org.jwildfire.create.eden.scene.Scene) IOException(java.io.IOException)

Example 2 with SunflowAPI

use of org.sunflow.SunflowAPI in project JWildfire by thargor6.

the class FilterKernelVisualisation3dRenderer method createSunflowRenderer.

private SunflowAPI createSunflowRenderer(Scene scene) throws IOException, Exception {
    String sceneTxt = new SunflowExporter().exportScene(scene);
    String filename = createTmpFilename();
    Tools.writeUTF8Textfile(filename, sceneTxt);
    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";
    SunflowAPI api = SunflowAPI.compile(template);
    api.build();
    api.parameter("sampler", "ipr");
    api.parameter("accel", "kdtree");
    api.options(SunflowAPI.DEFAULT_OPTIONS);
    return api;
}
Also used : SunflowAPI(org.sunflow.SunflowAPI) SunflowExporter(org.jwildfire.create.eden.export.SunflowExporter)

Aggregations

SunflowAPI (org.sunflow.SunflowAPI)2 Color (java.awt.Color)1 IOException (java.io.IOException)1 SunflowExporter (org.jwildfire.create.eden.export.SunflowExporter)1 Scene (org.jwildfire.create.eden.scene.Scene)1 SimpleImage (org.jwildfire.image.SimpleImage)1