Search in sources :

Example 6 with ListDownLayout

use of org.twak.utils.ui.ListDownLayout in project chordatlas by twak.

the class PlanesGen method selected.

private void selected(Plane p) {
    JPanel ui = new JPanel(new ListDownLayout());
    JButton delete = new JButton("delete");
    delete.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            planes.remove(p);
            PlanesGen.this.calculateOnJmeThread();
        }
    });
    ui.add(delete);
    tweed.frame.setGenUI(ui);
}
Also used : JPanel(javax.swing.JPanel) ListDownLayout(org.twak.utils.ui.ListDownLayout) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton)

Example 7 with ListDownLayout

use of org.twak.utils.ui.ListDownLayout in project chordatlas by twak.

the class ProfileGen method getUI.

@Override
public JComponent getUI() {
    JSlider slider = new JSlider(JSlider.HORIZONTAL, -1, gNode.getChildren().size(), -1);
    slider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            tweed.enqueue(new Runnable() {

                @Override
                public void run() {
                    int value = slider.getValue();
                    for (Spatial s : gNode.getChildren()) {
                        if (s instanceof Node) {
                            Integer i = s.getUserData(ProfileGen.class.getSimpleName());
                            if (i != null && s instanceof Node)
                                if (value == -1 || i == value)
                                    s.setCullHint(CullHint.Inherit);
                                else
                                    s.setCullHint(CullHint.Always);
                        }
                    }
                    tweed.gainFocus();
                }
            });
        }
    });
    JButton skel = new JButton("optimize");
    skel.addActionListener(ae -> doSkel());
    JComboBox<Mode> vizMode = new JComboBox<>(Mode.values());
    vizMode.addActionListener(e -> doViz((Mode) vizMode.getSelectedItem()));
    // JButton writeProfiles = new JButton("dump profs");
    // writeProfiles.addActionListener( ae -> writeProfiles() );
    JButton stateBuilder = new JButton("segmenter ui");
    stateBuilder.addActionListener(ae -> new SSBuilder(this, tweed.features));
    JButton profs = new JButton("2d profiles");
    profs.addActionListener(ae -> new ProfileAssignmentViewer(faces));
    JPanel out = new JPanel(new ListDownLayout());
    out.add(skel);
    out.add(new JLabel("profiles rendered:"));
    out.add(slider);
    out.add(new JLabel("viz:"));
    out.add(vizMode);
    // out.add( writeProfiles );
    out.add(stateBuilder);
    out.add(profs);
    return out;
}
Also used : JPanel(javax.swing.JPanel) ListDownLayout(org.twak.utils.ui.ListDownLayout) JComboBox(javax.swing.JComboBox) Node(com.jme3.scene.Node) Mode(org.twak.tweed.gen.VizSkelGen.Mode) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) CullHint(com.jme3.scene.Spatial.CullHint) ChangeEvent(javax.swing.event.ChangeEvent) Spatial(com.jme3.scene.Spatial) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener)

Example 8 with ListDownLayout

use of org.twak.utils.ui.ListDownLayout in project chordatlas by twak.

the class ResultsGen method getUI.

@Override
public JComponent getUI() {
    JPanel out = new JPanel();
    out.setLayout(new ListDownLayout());
    JButton all = new JButton("load all");
    all.addActionListener(e -> new Thread(() -> load(root, false)).start());
    out.add(all);
    JButton clear = new JButton("clear");
    clear.addActionListener(e -> clear());
    out.add(clear);
    return out;
}
Also used : JPanel(javax.swing.JPanel) ListDownLayout(org.twak.utils.ui.ListDownLayout) JButton(javax.swing.JButton)

Example 9 with ListDownLayout

use of org.twak.utils.ui.ListDownLayout in project chordatlas by twak.

the class FacadeTool method getUI.

@Override
public void getUI(JPanel panel) {
    panel.setLayout(new ListDownLayout());
    JComboBox<GISGen.Mode> allOne = new JComboBox<>();
    allOne.addItem(GISGen.Mode.RENDER_ALL_BLOCKS);
    allOne.addItem(GISGen.Mode.RENDER_SELECTED_BLOCK);
    // allOne.addItem( GISGen.Mode.RENDER_SAT );
    allOne.setSelectedItem(GISGen.mode);
    allOne.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            GISGen.mode = (Mode) allOne.getSelectedItem();
        }
    });
    JComboBox<FacadeFinder.FacadeMode> granularity = new JComboBox<>();
    granularity.addItem(FacadeMode.PER_GIS);
    granularity.addItem(FacadeMode.PER_MEGA);
    granularity.addItem(FacadeMode.PER_CAMERA);
    granularity.addItem(FacadeMode.PER_CAMERA_CROPPED);
    granularity.setSelectedItem(FacadeFinder.facadeMode);
    granularity.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            FacadeFinder.facadeMode = (FacadeMode) granularity.getSelectedItem();
        }
    });
    // JButton render = new JButton( "render" );
    // render.addActionListener( new ActionListener() {
    // @Override
    // public void actionPerformed( ActionEvent e ) {
    // renderFacades(null);
    // }
    // } );
    // panel.add( render );
    panel.add(allOne);
    panel.add(granularity);
    panel.add(new JLabel("click on any block to start"));
}
Also used : ListDownLayout(org.twak.utils.ui.ListDownLayout) FacadeMode(org.twak.viewTrace.FacadeFinder.FacadeMode) JComboBox(javax.swing.JComboBox) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) FacadeMode(org.twak.viewTrace.FacadeFinder.FacadeMode) Mode(org.twak.tweed.gen.GISGen.Mode) JLabel(javax.swing.JLabel)

Example 10 with ListDownLayout

use of org.twak.utils.ui.ListDownLayout in project chordatlas by twak.

the class Slice method buildUI.

private void buildUI() {
    ma = new PanMouseAdaptor(this);
    ma.center(new Point2d((max[flatAxis[0]] - min[flatAxis[0]]) / 2 + min[flatAxis[0]], (max[flatAxis[1]] - min[flatAxis[1]]) / 2 + min[flatAxis[1]]));
    ma.setZoom(16);
    JFrame jf = new JFrame("slice");
    WindowManager.register(jf);
    jf.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
        // System.exit(0);
        }
    });
    jf.setLayout(new BorderLayout());
    this.setPreferredSize(new Dimension(600, 600));
    jf.add(this, BorderLayout.CENTER);
    final JSlider heightSlider = new JSlider(SwingConstants.VERTICAL, (int) (min[majorAxis] * sliderScale), (int) (max[majorAxis] * sliderScale), (int) ((max[majorAxis] - min[majorAxis]) * 0.5 + min[majorAxis]) * sliderScale);
    final JSlider lineSlider = new JSlider(SwingConstants.VERTICAL, -1, 50, -1);
    heightSlider.setPaintLabels(false);
    final ChangeListener cl;
    heightSlider.addChangeListener(cl = new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent arg0) {
            sliceHeight = heightSlider.getValue() / (double) sliderScale;
            LineSoup rawSoup = sliceMesh(rawMesh, sliceHeight);
            slice = sliceMesh(filteredMesh, sliceHeight);
            foundLines = new FindLines(slice, gisBias, lineSlider.getValue(), rawSoup.clique(P.CL_HIGH, P.CL_LOW), P);
            Concarnie cc = new Concarnie(foundLines.result, foundLines.cliques, P);
            // Concarnie cc = new Concarnie(slice, rawSoup.clique() );
            carnieSoup = cc.graph;
            carnie = cc.out;
            Slice.this.repaint();
        }
    });
    cl.stateChanged(null);
    lineSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            cl.stateChanged(null);
        }
    });
    final JSlider parameterScaleSlider = new JSlider(SwingConstants.VERTICAL, 0, 2000, (int) (P.getScale() * 100));
    parameterScaleSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            P.setScale(parameterScaleSlider.getValue() / 100.);
        }
    });
    JButton go = new JButton("support");
    go.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            setupObj(new ObjRead(toSlice));
        // supportPoints.clear();
        // Slice.this.repaint();
        // SwingUtilities.invokeLater(new Runnable() {
        // @Override
        // public void run() {
        // PerpSupport ps = new PerpSupport(slice, gis);
        // Slice.this.supportMax = ps.supportMax;
        // Slice.this.supportPoints = ps.supportPoints;
        // Slice.this.repaint();
        // }
        // });
        }
    });
    JButton fs = new JButton("full support");
    fs.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            Set<Point2d> points = new HashSet();
            for (double v = min[majorAxis]; v < max[majorAxis]; v += 0.01) {
                System.out.println("processing slice " + v + " / " + max[majorAxis]);
                slice = sliceMesh(filteredMesh, sliceHeight);
                for (SupportPoint sp : new PerpSupport(slice, gis).supportPoints) points.add(new Point2d(sp.support, max[majorAxis] - v));
            }
            System.out.println("found " + points.size() + " pts");
            new Plot(points);
        }
    });
    JButton ge = new JButton("lines");
    ge.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            foundLines = new FindLines(slice, gisBias, lineSlider.getValue(), slice.clique(P.CL_HIGH, P.CL_LOW), P);
            Slice.this.repaint();
        }
    });
    JButton cc = new JButton("carnie");
    cc.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            LineSoup rawSoup = sliceMesh(rawMesh, sliceHeight);
            foundLines = new FindLines(slice, gisBias, lineSlider.getValue(), rawSoup.clique(P.CL_HIGH, P.CL_LOW), P);
            Concarnie cc = new Concarnie(foundLines.result, foundLines.cliques, P);
            carnieSoup = cc.graph;
            carnie = cc.out;
            Slice.this.repaint();
        }
    });
    JButton ob = new JButton("dump");
    ob.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            ObjDump out = new ObjDump();
            double delta = 2.5;
            for (double d = min[majorAxis]; d <= max[majorAxis]; d += delta) {
                System.out.println(d + " / " + max[majorAxis]);
                boolean error;
                int count = 0;
                do {
                    error = false;
                    try {
                        LineSoup rawSoup = sliceMesh(rawMesh, d);
                        slice = sliceMesh(filteredMesh, d);
                        foundLines = new FindLines(slice, null, lineSlider.getValue(), rawSoup.clique(P.CL_HIGH, P.CL_LOW), P);
                        // foundLines = new FindLines(slice, gisBias, lineSlider.getValue(), rawSoup.clique(P.CL_HIGH, P.CL_LOW), P);
                        Concarnie c = new Concarnie(foundLines.result, foundLines.cliques, P);
                        // 
                        extrude(out, c.out, d, d + delta);
                        // capAtHeight (out, c.out, false, d );
                        capAtHeight(out, c.out, true, d + delta);
                    } catch (Throwable th) {
                        error = true;
                    }
                } while (error && count++ < 10);
            }
            out.dump(new File(Tweed.SCRATCH + "test2.obj"));
        }
    });
    JButton an = new JButton("anim");
    an.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            BufferedImage bi = new BufferedImage(Slice.this.getWidth(), Slice.this.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
            for (File f : new File(Tweed.SCRATCH + "vid").listFiles()) f.delete();
            int c = 0;
            for (int i = heightSlider.getMinimum(); i < heightSlider.getMaximum(); i += 100) {
                heightSlider.setValue(i);
                Slice.this.paintComponent(bi.getGraphics());
                try {
                    ImageIO.write(bi, "png", new File(String.format(Tweed.SCRATCH + "vid/%05d.png", c++)));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    JButton sl = new JButton("global");
    sl.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            new SliceSolver(new File(Tweed.SCRATCH + "test2.obj"), Slice.this, P);
        }
    });
    JButton pr = new JButton("profiles");
    pr.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            double delta = 0.5;
            BufferedImage out = new BufferedImage(Slice.this.getWidth(), Slice.this.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
            Graphics2D g2 = (Graphics2D) out.getGraphics();
            g2.setColor(Color.white);
            g2.fillRect(0, 0, getWidth(), getHeight());
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setColor(new Color(0, 0, 0, 50));
            for (double d = min[majorAxis]; d <= max[majorAxis]; d += delta) {
                System.out.println(d + " / " + max[majorAxis]);
                boolean error;
                int count = 0;
                do {
                    error = false;
                    try {
                        LineSoup rawSoup = sliceMesh(rawMesh, d);
                        slice = sliceMesh(filteredMesh, d);
                        FindLines fl = new FindLines(slice, gisBias, lineSlider.getValue(), rawSoup.clique(P.CL_HIGH, P.CL_LOW), P);
                        PaintThing.paint(fl.result, g2, ma);
                    // Concarnie c = new Concarnie(foundLines.result, foundLines.cliques, P);
                    } catch (Throwable th) {
                        error = true;
                    }
                } while (error && count++ < 10);
            }
            g2.dispose();
            try {
                ImageIO.write(out, "png", new File(Tweed.SCRATCH + "lines"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    final JCheckBox sg = new JCheckBox("gis", true);
    sg.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            showGis = sg.isSelected();
            Slice.this.repaint();
        }
    });
    final JCheckBox sf = new JCheckBox("fit", true);
    sf.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            showFit = sf.isSelected();
            Slice.this.repaint();
        }
    });
    final JCheckBox sc = new JCheckBox("poly-out", true);
    sc.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            showCarnie = sc.isSelected();
            Slice.this.repaint();
        }
    });
    final JCheckBox ss = new JCheckBox("slice", true);
    ss.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            showSlice = ss.isSelected();
            Slice.this.repaint();
        }
    });
    JPanel buttons = new JPanel(new ListDownLayout());
    buttons.add(go);
    buttons.add(fs);
    buttons.add(ge);
    buttons.add(cc);
    buttons.add(an);
    buttons.add(ob);
    buttons.add(sl);
    buttons.add(pr);
    buttons.add(sg);
    buttons.add(sf);
    buttons.add(sc);
    buttons.add(ss);
    buttons.add(lineSlider);
    JPanel controls = new JPanel(new BorderLayout());
    controls.add(heightSlider, BorderLayout.CENTER);
    controls.add(parameterScaleSlider, BorderLayout.WEST);
    controls.add(buttons, BorderLayout.EAST);
    jf.add(controls, BorderLayout.EAST);
    jf.pack();
    jf.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) ListDownLayout(org.twak.utils.ui.ListDownLayout) Set(java.util.Set) HashSet(java.util.HashSet) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) ObjRead(org.twak.utils.geom.ObjRead) BufferedImage(java.awt.image.BufferedImage) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) ObjDump(org.twak.utils.geom.ObjDump) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener) HashSet(java.util.HashSet) Plot(org.twak.utils.ui.Plot) Color(java.awt.Color) Dimension(java.awt.Dimension) IOException(java.io.IOException) Graphics2D(java.awt.Graphics2D) JCheckBox(javax.swing.JCheckBox) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) Point2d(javax.vecmath.Point2d) PanMouseAdaptor(org.twak.utils.PanMouseAdaptor) WindowEvent(java.awt.event.WindowEvent) File(java.io.File)

Aggregations

ListDownLayout (org.twak.utils.ui.ListDownLayout)15 JButton (javax.swing.JButton)12 ActionEvent (java.awt.event.ActionEvent)11 ActionListener (java.awt.event.ActionListener)10 JPanel (javax.swing.JPanel)10 JLabel (javax.swing.JLabel)7 File (java.io.File)4 JSlider (javax.swing.JSlider)4 ChangeEvent (javax.swing.event.ChangeEvent)4 ChangeListener (javax.swing.event.ChangeListener)4 Dimension (java.awt.Dimension)3 JCheckBox (javax.swing.JCheckBox)3 Vector3f (com.jme3.math.Vector3f)2 Node (com.jme3.scene.Node)2 BorderLayout (java.awt.BorderLayout)2 Color (java.awt.Color)2 WindowAdapter (java.awt.event.WindowAdapter)2 WindowEvent (java.awt.event.WindowEvent)2 BufferedImage (java.awt.image.BufferedImage)2 ArrayList (java.util.ArrayList)2