Search in sources :

Example 1 with RenderPointCloudThread

use of org.jwildfire.create.tina.meshgen.render.RenderPointCloudThread in project JWildfire by thargor6.

the class MeshGenController method generateButton_clicked.

public void generateButton_clicked() {
    if (renderSlicesThread != null) {
        renderSlicesThread.setForceAbort();
        while (renderSlicesThread.isFinished()) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        renderSlicesThread = null;
        enableControls();
    } else if (currBaseFlame != null) {
        try {
            JFileChooser chooser;
            if (isPointCloudMode()) {
                chooser = new PointCloudOutputFileChooser(Tools.FILEEXT_PLY);
                if (prefs.getTinaMeshPath() != null) {
                    try {
                        chooser.setCurrentDirectory(new File(prefs.getTinaMeshPath()));
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            } else {
                chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
                if (prefs.getOutputImagePath() != null) {
                    try {
                        chooser.setCurrentDirectory(new File(prefs.getOutputImagePath()));
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
            if (chooser.showSaveDialog(rootPanel) == JFileChooser.APPROVE_OPTION) {
                final File file = chooser.getSelectedFile();
                prefs.setLastOutputImageFile(file);
                MeshGenGenerateThreadFinishEvent finishEvent = new MeshGenGenerateThreadFinishEvent() {

                    @Override
                    public void succeeded(double pElapsedTime) {
                        try {
                            tinaController.getMessageHelper().showStatusMessage(currBaseFlame, "render time: " + Tools.doubleToString(pElapsedTime) + "s");
                        } catch (Throwable ex) {
                            errorHandler.handleError(ex);
                        }
                        renderSlicesThread = null;
                        enableControls();
                    }

                    @Override
                    public void failed(Throwable exception) {
                        errorHandler.handleError(exception);
                        renderSlicesThread = null;
                        enableControls();
                    }
                };
                Flame flame = currBaseFlame.makeCopy();
                switch(getOutputType()) {
                    case VOXELSTACK:
                        {
                            String outfilenamePattern = SequenceFilenameGen.createFilenamePattern(file);
                            Flame grayFlame = flame.makeCopy();
                            RGBPalette gradient = new RGBPalette();
                            for (int i = 0; i < RGBPalette.PALETTE_SIZE; i++) {
                                gradient.setColor(i, 225, 225, 225);
                            }
                            grayFlame.getFirstLayer().setPalette(gradient);
                            renderSlicesThread = new RenderSlicesThread(prefs, grayFlame, outfilenamePattern, finishEvent, renderSequenceProgressUpdater, renderWidthREd.getIntValue(), renderHeightREd.getIntValue(), sliceCountREd.getIntValue(), slicesPerRenderREd.getIntValue(), renderQualityREd.getIntValue(), zminREd.getDoubleValue(), zmaxREd.getDoubleValue());
                            lastRenderedSequenceOutFilePattern = outfilenamePattern;
                            break;
                        }
                    case POINTCLOUD:
                        {
                            renderSlicesThread = new RenderPointCloudThread(prefs, flame, file.getAbsolutePath(), finishEvent, renderSequenceProgressUpdater, renderWidthREd.getIntValue(), renderHeightREd.getIntValue(), renderQualityREd.getIntValue(), zminREd.getDoubleValue(), zmaxREd.getDoubleValue(), meshGenCellSizeREd.getDoubleValue());
                            break;
                        }
                }
                enableControls();
                new Thread(renderSlicesThread).start();
            }
        } catch (Throwable ex) {
            errorHandler.handleError(ex);
        }
    }
}
Also used : RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) ImageFileChooser(org.jwildfire.swing.ImageFileChooser) RenderSlicesThread(org.jwildfire.create.tina.meshgen.render.RenderSlicesThread) RenderPointCloudThread(org.jwildfire.create.tina.meshgen.render.RenderPointCloudThread) MeshGenRenderThread(org.jwildfire.create.tina.meshgen.render.MeshGenRenderThread) RenderSlicesThread(org.jwildfire.create.tina.meshgen.render.RenderSlicesThread) RenderPointCloudThread(org.jwildfire.create.tina.meshgen.render.RenderPointCloudThread) JFileChooser(javax.swing.JFileChooser) PointCloudOutputFileChooser(org.jwildfire.swing.PointCloudOutputFileChooser) File(java.io.File) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Aggregations

File (java.io.File)1 JFileChooser (javax.swing.JFileChooser)1 Flame (org.jwildfire.create.tina.base.Flame)1 MeshGenRenderThread (org.jwildfire.create.tina.meshgen.render.MeshGenRenderThread)1 RenderPointCloudThread (org.jwildfire.create.tina.meshgen.render.RenderPointCloudThread)1 RenderSlicesThread (org.jwildfire.create.tina.meshgen.render.RenderSlicesThread)1 RGBPalette (org.jwildfire.create.tina.palette.RGBPalette)1 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)1 ImageFileChooser (org.jwildfire.swing.ImageFileChooser)1 PointCloudOutputFileChooser (org.jwildfire.swing.PointCloudOutputFileChooser)1