Search in sources :

Example 16 with ImagePanel

use of org.jwildfire.swing.ImagePanel in project JWildfire by thargor6.

the class MeshGenController method getPreviewPanel.

private ImagePanel getPreviewPanel() {
    if (previewPanel == null) {
        int width = previewRootPanel.getWidth();
        int height = previewRootPanel.getHeight();
        SimpleImage img = new SimpleImage(width, height);
        img.fillBackground(0, 0, 0);
        previewPanel = new ImagePanel(img, 0, 0, previewRootPanel.getWidth());
        previewRootPanel.add(previewPanel, BorderLayout.CENTER);
        previewRootPanel.getParent().validate();
        previewRootPanel.repaint();
    }
    return previewPanel;
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) ImagePanel(org.jwildfire.swing.ImagePanel)

Example 17 with ImagePanel

use of org.jwildfire.swing.ImagePanel in project JWildfire by thargor6.

the class MutaGenController method mutate.

protected void mutate(int pRow, int pCol) {
    try {
        if (selectedGenerationIdx >= 0 && selectedGenerationIdx < mutationList.size()) {
            Dimension renderSize = calcImageSize();
            Dimension probeSize = new Dimension(50, 40);
            MutationSet selectedSet = mutationList.get(selectedGenerationIdx);
            final int rows = MUTA_ROWS;
            final int cols = MUTA_COLS;
            Flame baseFlame = selectedSet.getFlame(pRow, pCol);
            baseFlame = createWeightedFlame(selectedSet.getBaseFlame(), baseFlame);
            boolean doMorph = fabs((Double) amountREd.getValue() - 1.0) > EPSILON;
            List<Flame> mutations = new ArrayList<Flame>();
            initProgress(rows, cols);
            int centreX = rows / 2;
            int centreY = cols / 2;
            SimpleImage baseFlameImg = renderFlame(baseFlame.makeCopy(), probeSize, false);
            SimpleImage simplifiedBaseFlameImg = RandomFlameGeneratorSampler.createSimplifiedRefImage(baseFlameImg);
            int step = 0;
            for (int i = 0; i < rows; i++) {
                for (int j = 0; j < cols; j++) {
                    // Let centre flame untouched
                    SimpleImage renderedImg = null;
                    if ((i != centreX || j != centreY)) {
                        int x = (i - centreX);
                        int y = (j - centreY);
                        final int MAX_ITER = 10;
                        final double MIN_RENDER_COVERAGE = 0.32;
                        final double MIN_DIFF_COVERAGE = 0.18;
                        final double INVALID_COVERAGE = -1.0;
                        int iter = 0;
                        double bestCoverage = INVALID_COVERAGE;
                        Flame bestMutation = null;
                        while (true) {
                            Flame currMutation = baseFlame.makeCopy();
                            List<MutationType> mutationTypes = createMutationTypes(x, y);
                            modifyFlame(currMutation, x, y, mutationTypes);
                            renderedImg = renderFlame(currMutation.makeCopy(), probeSize, true);
                            double coverage = renderedImg != null ? RandomFlameGeneratorSampler.calculateCoverage(renderedImg, 0, 0, 0, true) : INVALID_COVERAGE;
                            if (coverage > MIN_RENDER_COVERAGE) {
                                coverage = RandomFlameGeneratorSampler.calculateDiffCoverage(renderedImg, simplifiedBaseFlameImg);
                            }
                            if (coverage > MIN_DIFF_COVERAGE) {
                                mutations.add(currMutation);
                                if (doMorph) {
                                    Flame morphed = createWeightedFlame(baseFlame, currMutation);
                                    renderedImg = renderFlame(morphed, renderSize, false);
                                } else {
                                    renderedImg = renderFlame(currMutation, renderSize, false);
                                }
                                break;
                            } else if (coverage > bestCoverage) {
                                bestCoverage = coverage;
                                bestMutation = currMutation;
                            }
                            // Don't count invalid mutations
                            if (renderedImg != null) {
                                iter++;
                            }
                            if (iter >= MAX_ITER) {
                                mutations.add(bestMutation);
                                if (doMorph) {
                                    Flame morphed = createWeightedFlame(baseFlame, bestMutation);
                                    renderedImg = renderFlame(morphed, renderSize, false);
                                } else {
                                    renderedImg = renderFlame(bestMutation, renderSize, false);
                                }
                                break;
                            }
                        }
                    } else {
                        mutations.add(baseFlame.makeCopy());
                        renderedImg = renderFlame(baseFlame.makeCopy(), renderSize, false);
                    }
                    ImagePanel pnl = imagePanels[i][j];
                    pnl.setImage(renderedImg);
                    showProgress(++step);
                    try {
                        pnl.invalidate();
                        Graphics g = pnl.getGraphics();
                        if (g != null) {
                            pnl.paint(g);
                        }
                    } catch (Throwable ex) {
                        ex.printStackTrace();
                    }
                }
            }
            MutationSet newSet = new MutationSet(rows, cols, baseFlame, mutations);
            mutationList.add(newSet);
            selectedGenerationIdx = mutationList.size() - 1;
            enableControls();
        }
    } catch (Throwable ex) {
        errorHandler.handleError(ex);
    }
}
Also used : ArrayList(java.util.ArrayList) Dimension(java.awt.Dimension) Graphics(java.awt.Graphics) SimpleImage(org.jwildfire.image.SimpleImage) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame) ImagePanel(org.jwildfire.swing.ImagePanel)

Example 18 with ImagePanel

use of org.jwildfire.swing.ImagePanel in project JWildfire by thargor6.

the class MutaGenController method calcImageSize.

private Dimension calcImageSize() {
    createImagePanels();
    ImagePanel pnl = imagePanels[0][0];
    Dimension size = pnl.getSize();
    int imageWidth = Tools.FTOI(size.getWidth());
    int imageHeight = Tools.FTOI(size.getHeight());
    return new Dimension(imageWidth, imageHeight);
}
Also used : Dimension(java.awt.Dimension) ImagePanel(org.jwildfire.swing.ImagePanel)

Example 19 with ImagePanel

use of org.jwildfire.swing.ImagePanel in project JWildfire by thargor6.

the class MutaGenController method createImagePanels.

private void createImagePanels() {
    if (imagePanels == null) {
        try {
            final int rows = MUTA_ROWS;
            final int cols = MUTA_COLS;
            final int BORDER_SIZE = 0;
            ((JPanel) flamePanels[0].getParent()).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(37, 0), "selectLeftCellAction");
            ((JPanel) flamePanels[0].getParent()).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(39, 0), "selectRightCellAction");
            ((JPanel) flamePanels[0].getParent()).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(38, 0), "selectTopCellAction");
            ((JPanel) flamePanels[0].getParent()).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(40, 0), "selectBottomCellAction");
            ((JPanel) flamePanels[0].getParent()).getActionMap().put("selectLeftCellAction", new AbstractAction() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    selectLeftCell();
                }
            });
            ((JPanel) flamePanels[0].getParent()).getActionMap().put("selectRightCellAction", new AbstractAction() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    selectRightCell();
                }
            });
            ((JPanel) flamePanels[0].getParent()).getActionMap().put("selectTopCellAction", new AbstractAction() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    selectUpperCell();
                }
            });
            ((JPanel) flamePanels[0].getParent()).getActionMap().put("selectBottomCellAction", new AbstractAction() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    selectLowerCell();
                }
            });
            imagePanels = new ImagePanel[rows][cols];
            int idx = 0;
            for (int i = 0; i < rows; i++) {
                for (int j = 0; j < cols; j++) {
                    JPanel panel = flamePanels[idx++];
                    Dimension size = panel.getSize();
                    SimpleImage img = new SimpleImage(Tools.FTOI(size.getWidth()), Tools.FTOI(size.getHeight()));
                    final ImagePanel imgPanel = new ImagePanel(img, 0, 0, img.getImageWidth());
                    imagePanels[i][j] = imgPanel;
                    imgPanel.setImage(img);
                    imgPanel.setLocation(BORDER_SIZE, BORDER_SIZE);
                    final int row = i;
                    final int col = j;
                    imgPanel.addMouseListener(new java.awt.event.MouseAdapter() {

                        @Override
                        public void mouseClicked(java.awt.event.MouseEvent e) {
                            if (e.getClickCount() == 2 || e.getButton() == MouseEvent.BUTTON3) {
                                mutate(row, col);
                            } else if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON2) {
                                export(row, col);
                            }
                        }

                        @Override
                        public void mousePressed(MouseEvent e) {
                            selectCell(row, col);
                        }
                    });
                    panel.add(imgPanel);
                }
            }
        } catch (Throwable ex) {
            imagePanels = null;
            errorHandler.handleError(ex);
        }
    }
}
Also used : JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) Dimension(java.awt.Dimension) MouseEvent(java.awt.event.MouseEvent) SimpleImage(org.jwildfire.image.SimpleImage) AbstractAction(javax.swing.AbstractAction) ImagePanel(org.jwildfire.swing.ImagePanel)

Example 20 with ImagePanel

use of org.jwildfire.swing.ImagePanel in project JWildfire by thargor6.

the class DetachedPreviewController method refreshImagePanel.

private void refreshImagePanel() {
    if (imagePanel != null) {
        imageRootPanel.remove(imagePanel);
    }
    ImgSize size = getImgSize();
    image = new SimpleImage(size.getWidth(), size.getHeight());
    image.fillBackground(prefs.getTinaRandomBatchBGColorRed(), prefs.getTinaRandomBatchBGColorGreen(), prefs.getTinaRandomBatchBGColorBlue());
    imagePanel = new ImagePanel(image, 0, 0, image.getImageWidth());
    imagePanel.setSize(image.getImageWidth(), image.getImageHeight());
    imagePanel.setPreferredSize(new Dimension(image.getImageWidth(), image.getImageHeight()));
    imageRootPanel.add(imagePanel, BorderLayout.CENTER);
    imageRootPanel.getParent().validate();
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Dimension(java.awt.Dimension) ImagePanel(org.jwildfire.swing.ImagePanel)

Aggregations

ImagePanel (org.jwildfire.swing.ImagePanel)30 SimpleImage (org.jwildfire.image.SimpleImage)24 Dimension (java.awt.Dimension)15 JPanel (javax.swing.JPanel)9 JScrollPane (javax.swing.JScrollPane)8 MouseEvent (java.awt.event.MouseEvent)6 Flame (org.jwildfire.create.tina.base.Flame)4 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)4 LineBorder (javax.swing.border.LineBorder)3 ResolutionProfile (org.jwildfire.base.ResolutionProfile)3 Font (java.awt.Font)2 Graphics (java.awt.Graphics)2 Point (java.awt.Point)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 JLabel (javax.swing.JLabel)2 XYZProjectedPoint (org.jwildfire.create.tina.base.XYZProjectedPoint)2 TextTransformer (org.jwildfire.transform.TextTransformer)2 Color (java.awt.Color)1 Component (java.awt.Component)1