Search in sources :

Example 6 with ObjDump

use of org.twak.utils.geom.ObjDump in project chordatlas by twak.

the class SliceSolver method buildRunGurobi.

private void buildRunGurobi(Slice slice, double delta, List<State> states) {
    double[][] fit = new double[states.size()][states.size()];
    System.out.println("data fit");
    for (int i = 0; i < states.size(); i++) {
        for (int j = 0; j < states.size(); j++) {
            fit[i][j] = dataFit(states.get(i).filtered, states.get(j).con.out);
            System.out.print(fit[i][j] + " ");
        }
        System.out.println();
    }
    System.out.println("slice align");
    double[][] align = new double[states.size()][states.size()];
    for (int i = 0; i < states.size(); i++) {
        for (int j = 0; j < states.size(); j++) {
            align[j][i] = align(states.get(i).con.out, states.get(j).con.out);
            System.out.print(align[j][i] + " ");
        }
        System.out.println();
    }
    // for ( int j = 0; j < states.size(); j++ ) {
    // double t = 0;
    // for ( int i = 0; i < states.size(); i++ ) {
    // if (fit[i][j] != Double.MAX_VALUE)
    // t += fit[i][j];
    // }
    // System.out.println(" j " +j +" ++ "+t);
    // }
    int[] res = sliceOptimize(states.size(), fit, align);
    if (res == null) {
        System.err.println("no solution found");
        return;
    }
    ObjDump out = new ObjDump();
    states.stream().forEach(x -> CutHoles.cutHoles(x.con.out, P.CON_TOL / 5));
    double height = slice.min[slice.majorAxis];
    for (int i = 0; i < res.length; i++) {
        System.out.print(res[i] + ", ");
        State s = states.get(res[i]);
        Slice.extrude(out, s.con.out, height, height + delta);
        Slice.capAtHeight(out, s.con.out, false, height);
        Slice.capAtHeight(out, s.con.out, true, height + delta);
        height += delta;
    }
    out.dump(outfile);
}
Also used : ObjDump(org.twak.utils.geom.ObjDump)

Example 7 with ObjDump

use of org.twak.utils.geom.ObjDump in project chordatlas by twak.

the class SliceSolver method slicesByDataFit.

private void slicesByDataFit(Slice slice, double delta, List<State> states) {
    {
        Cache<State, Double> cache = new Cache<State, Double>() {

            @Override
            public Double create(State i) {
                double out = 0;
                for (State s : states) {
                    double d = dataFit(s.filtered, i.con.out);
                    if (d != Double.MAX_VALUE)
                        out += d;
                    else
                        out += 1e3;
                }
                if (out == 0)
                    out = Double.MAX_VALUE;
                return out;
            }
        };
        Collections.sort(states, new Comparator<State>() {

            public int compare(State o1, State o2) {
                return -Double.compare(cache.get(o1), cache.get(o2));
            }
        });
        states.stream().forEach(s -> CutHoles.cutHoles(s.con.out, P.CON_TOL / 5));
        ObjDump out = new ObjDump();
        double height = slice.min[slice.majorAxis];
        for (int i = 0; i < states.size(); i++) {
            State s = states.get(i);
            System.out.println(" >>>> " + cache.get(s));
            Slice.extrude(out, s.con.out, height, height + delta);
            Slice.capAtHeight(out, s.con.out, false, height);
            Slice.capAtHeight(out, s.con.out, true, height + delta);
            height += delta * 3;
        }
        out.dump(outfile);
    }
}
Also used : GRBQuadExpr(gurobi.GRBQuadExpr) LoopL(org.twak.utils.collections.LoopL) GRBException(gurobi.GRBException) GRBVar(gurobi.GRBVar) GRBLinExpr(gurobi.GRBLinExpr) Line(org.twak.utils.Line) DoubleAttr(gurobi.GRB.DoubleAttr) File(java.io.File) ArrayList(java.util.ArrayList) Loop(org.twak.utils.collections.Loop) Loopz(org.twak.utils.collections.Loopz) Point2d(javax.vecmath.Point2d) GRBModel(gurobi.GRBModel) List(java.util.List) Cache(org.twak.utils.Cache) Loopable(org.twak.utils.collections.Loopable) ObjDump(org.twak.utils.geom.ObjDump) Comparator(java.util.Comparator) Collections(java.util.Collections) GRBEnv(gurobi.GRBEnv) GRB(gurobi.GRB) ObjDump(org.twak.utils.geom.ObjDump) Cache(org.twak.utils.Cache) Comparator(java.util.Comparator)

Example 8 with ObjDump

use of org.twak.utils.geom.ObjDump in project chordatlas by twak.

the class GMLReader method main1.

public static void main1(String[] args) {
    Graph2D g2 = readGMLToGraph(new File("/home/twak/data/langham/langham.gml"));
    g2.removeInnerEdges();
    Point2d offset = new Point2d();
    int count = 0;
    for (Point2d p : g2.map.keySet()) for (Line l : g2.get(p)) {
        count++;
        offset.add(l.start);
        System.out.println(l);
    }
    offset.scale(1. / count);
    System.out.println("offset is " + offset);
    AffineTransform at = AffineTransform.getScaleInstance(-1, 1);
    at.concatenate(AffineTransform.getTranslateInstance(-offset.x, -offset.y));
    g2 = g2.apply(at);
    UnionWalker uw = new UnionWalker();
    for (Point2d a : g2.map.keySet()) {
        for (Line l : g2.get(a)) {
            uw.addEdge(l.start, l.end);
        }
    }
    LoopL<Point2d> out = uw.findAll();
    ObjDump obj = new ObjDump();
    for (Loop<Point2d> loop : out) {
        List<Point3d> pts = new ArrayList();
        for (Point2d pt : loop) pts.add(new Point3d(pt.x, 0, pt.y));
        obj.addFace(pts);
    }
    obj.dump(new File(Tweed.SCRATCH + "langham.obj"));
}
Also used : ArrayList(java.util.ArrayList) Graph2D(org.twak.utils.geom.Graph2D) Line(org.twak.utils.Line) Point2d(javax.vecmath.Point2d) ObjDump(org.twak.utils.geom.ObjDump) Point3d(javax.vecmath.Point3d) AffineTransform(java.awt.geom.AffineTransform) UnionWalker(org.twak.utils.geom.UnionWalker) File(java.io.File)

Example 9 with ObjDump

use of org.twak.utils.geom.ObjDump in project chordatlas by twak.

the class TweedFrame method buildUI.

public JComponent buildUI() {
    JPanel out = new JPanel(new BorderLayout());
    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);
    // Build the first menu.
    JMenu menu = new JMenu("File");
    menuBar.add(menu);
    JMenuItem save = new JMenuItem("save", KeyEvent.VK_S);
    save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
    menu.add(save);
    save.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (TweedSettings.folder == null) {
                new SimpleFileChooser(frame) {

                    @Override
                    public void heresTheFile(File f) throws Throwable {
                        TweedSettings.folder = f;
                        TweedSettings.save(false);
                    }
                };
            } else
                TweedSettings.save(false);
        }
    });
    JMenuItem load = new JMenuItem("open...", KeyEvent.VK_O);
    load.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
    menu.add(load);
    load.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            new SimpleFileChooser(frame, false, "select a tweed.xml", Tweed.DATA == null ? null : new File(Tweed.DATA), TWEED_XML) {

                @Override
                public void heresTheFile(File f) throws Throwable {
                    TweedSettings.load(f);
                }
            };
        }
    });
    JMenuItem recent = new JLazyMenu("open recent") {

        @Override
        public List<Runnable> getEntries() {
            List<Runnable> out = new ArrayList();
            for (File r : TweedSettings.recentFiles.f) {
                out.add(new Runnable() {

                    @Override
                    public void run() {
                        if (!r.exists())
                            JOptionPane.showMessageDialog(frame, "Location " + r.getName() + "not found (is it still there?)");
                        else
                            TweedSettings.load(r);
                    }

                    @Override
                    public String toString() {
                        return r.getName();
                    }
                });
            }
            return out;
        }
    };
    menu.add(recent);
    JMenuItem neu = new JMenuItem("new...", KeyEvent.VK_N);
    neu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
    menu.add(neu);
    neu.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            new SimpleFileChooser(frame, false, "select a file in the root of the workspace") {

                @Override
                public void heresTheFile(File f) throws Throwable {
                    TweedSettings.folder = f.getParentFile();
                    if (new File(TweedSettings.folder, TWEED_XML).exists()) {
                        JOptionPane.showMessageDialog(frame, TWEED_XML + " already exists at this location, pick another (or delete...)");
                        return;
                    }
                    TweedSettings.load(TweedSettings.folder);
                }
            };
        }
    });
    // JMenuItem remove = new JMenuItem( "delete layer", KeyEvent.VK_MINUS );
    // remove.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_MINUS, ActionEvent.CTRL_MASK ) );
    // menu.add( remove );
    // remove.addActionListener( new java.awt.event.ActionListener() {
    // @Override
    // public void actionPerformed( ActionEvent e ) {
    // if ( selectedGen != null )
    // removeGen( selectedGen );
    // };
    // } );
    JMenuItem resetCam = new JMenuItem("reset view", KeyEvent.VK_R);
    resetCam.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK));
    menu.add(resetCam);
    resetCam.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            tweed.resetCamera();
        }
    });
    JMenuItem settings = new JMenuItem("settings...", KeyEvent.VK_R);
    settings.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));
    menu.add(settings);
    settings.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            new Auto(TweedSettings.settings).frame();
        }
    });
    JMenuItem resetBG = new JMenuItem("reset background", KeyEvent.VK_MINUS);
    resetBG.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, ActionEvent.CTRL_MASK));
    menu.add(resetBG);
    resetBG.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            tweed.enqueue(new Runnable() {

                @Override
                public void run() {
                    TweedFrame.this.tweed.clearBackground();
                }
            });
        }
    });
    JMenuItem obj = new JMenuItem("export obj...", KeyEvent.VK_E);
    obj.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));
    menu.add(obj);
    obj.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ObjDump dump = new ObjDump();
            for (Gen g : genList) if (g.visible && g instanceof IDumpObjs)
                ((IDumpObjs) g).dumpObj(dump);
            new SimpleFileChooser(frame, true, "save all as obj", new File(Tweed.SCRATCH, "all.obj"), "obj") {

                @Override
                public void heresTheFile(File f) throws Throwable {
                    dump.dump(f);
                }
            };
        }
    });
    layerList = new JPanel(new ListDownLayout());
    JPanel layers = new JPanel();
    layers.setLayout(new BorderLayout());
    layers.add(new JLabel("layers:"), BorderLayout.NORTH);
    JScrollPane listScroll = new JScrollPane(layerList);
    listScroll.getVerticalScrollBar().setUnitIncrement(50);
    listScroll.setPreferredSize(new Dimension(200, 300));
    layers.add(listScroll, BorderLayout.CENTER);
    JPanel addRemoveLayer = new JPanel();
    {
        addRemoveLayer.setLayout(new GridLayout(1, 2));
        layers.add(addRemoveLayer, BorderLayout.SOUTH);
        JButton addLayer = new JButton("+");
        addLayer.addMouseListener(new MouseAdapter() {

            @Override
            public void mousePressed(MouseEvent e) {
                addLayer(e);
            }
        });
        JButton removeLayer = new JButton("-");
        removeLayer.addActionListener(e -> removeGen(selectedGen));
        addRemoveLayer.add(addLayer);
        addRemoveLayer.add(removeLayer);
    }
    JPanel options = new JPanel(new BorderLayout());
    {
        options.add(new JLabel("options:"), BorderLayout.NORTH);
        options.add(genUI, BorderLayout.CENTER);
    }
    JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, layers, options);
    out.add(pane, BorderLayout.CENTER);
    JPanel toolPanel = new JPanel(new ListRightLayout());
    tweed.addUI(toolPanel);
    coordLabel = new JLabel("");
    coordLabel.setHorizontalAlignment(SwingConstants.CENTER);
    worldLabel = new JLabel("");
    worldLabel.setHorizontalAlignment(SwingConstants.CENTER);
    crsLabel = new JLabel("none");
    crsLabel.setHorizontalAlignment(SwingConstants.CENTER);
    out.add(toolPanel, BorderLayout.NORTH);
    JPanel coords = new JPanel(new ListDownLayout());
    coords.add(worldLabel);
    coords.add(coordLabel);
    coords.add(crsLabel);
    out.add(coords, BorderLayout.SOUTH);
    out.setPreferredSize(new Dimension(300, frame.getHeight()));
    return out;
}
Also used : UIManager(javax.swing.UIManager) MiniGen(org.twak.tweed.gen.MiniGen) JLazyMenu(org.twak.utils.ui.JLazyMenu) ListRightLayout(org.twak.utils.ui.ListRightLayout) MiniTransform(org.twak.readTrace.MiniTransform) Node(com.jme3.scene.Node) MouseAdapter(java.awt.event.MouseAdapter) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) JMenuBar(javax.swing.JMenuBar) KeyStroke(javax.swing.KeyStroke) AppSettings(com.jme3.system.AppSettings) ToolTipManager(javax.swing.ToolTipManager) ListDownLayout(org.twak.utils.ui.ListDownLayout) Auto(org.twak.utils.ui.auto.Auto) JMenu(javax.swing.JMenu) HalfMesh2(org.twak.utils.geom.HalfMesh2) KeyEvent(java.awt.event.KeyEvent) WindowAdapter(java.awt.event.WindowAdapter) Canvas(java.awt.Canvas) Component(java.awt.Component) Collectors(java.util.stream.Collectors) WindowEvent(java.awt.event.WindowEvent) Executors(java.util.concurrent.Executors) Dimension(java.awt.Dimension) List(java.util.List) PlanesGen(org.twak.tweed.gen.PlanesGen) GISGen(org.twak.tweed.gen.GISGen) JPanel(javax.swing.JPanel) Gen(org.twak.tweed.gen.Gen) JSplitPane(javax.swing.JSplitPane) JmeCanvasContext(com.jme3.system.JmeCanvasContext) MeshGen(org.twak.tweed.gen.MeshGen) SwingConstants(javax.swing.SwingConstants) Vector3d(javax.vecmath.Vector3d) WindowManager(org.twak.utils.ui.WindowManager) ArrayList(java.util.ArrayList) GridLayout(java.awt.GridLayout) JMenuItem(javax.swing.JMenuItem) ObjGen(org.twak.tweed.gen.ObjGen) SimpleFileChooser(org.twak.utils.ui.SimpleFileChooser) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PaintThing(org.twak.utils.PaintThing) JComponent(javax.swing.JComponent) FlowLayout(java.awt.FlowLayout) JButton(javax.swing.JButton) JPopupMenu(javax.swing.JPopupMenu) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) JScrollPane(javax.swing.JScrollPane) WeakListener(org.twak.utils.WeakListener) JLabel(javax.swing.JLabel) ObjDump(org.twak.utils.geom.ObjDump) SuperMeshPainter(org.twak.viewTrace.SuperMeshPainter) SimplePopup2(org.twak.utils.ui.SimplePopup2) PanoGen(org.twak.tweed.gen.PanoGen) JPanel(javax.swing.JPanel) ListDownLayout(org.twak.utils.ui.ListDownLayout) ActionEvent(java.awt.event.ActionEvent) JLazyMenu(org.twak.utils.ui.JLazyMenu) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) SimpleFileChooser(org.twak.utils.ui.SimpleFileChooser) Auto(org.twak.utils.ui.auto.Auto) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) ObjDump(org.twak.utils.geom.ObjDump) JMenuItem(javax.swing.JMenuItem) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) ListRightLayout(org.twak.utils.ui.ListRightLayout) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) MiniGen(org.twak.tweed.gen.MiniGen) PlanesGen(org.twak.tweed.gen.PlanesGen) GISGen(org.twak.tweed.gen.GISGen) Gen(org.twak.tweed.gen.Gen) MeshGen(org.twak.tweed.gen.MeshGen) ObjGen(org.twak.tweed.gen.ObjGen) PanoGen(org.twak.tweed.gen.PanoGen) JSplitPane(javax.swing.JSplitPane) File(java.io.File) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Aggregations

ObjDump (org.twak.utils.geom.ObjDump)9 File (java.io.File)8 ArrayList (java.util.ArrayList)5 Point2d (javax.vecmath.Point2d)4 XStream (com.thoughtworks.xstream.XStream)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Matrix4d (javax.vecmath.Matrix4d)3 BorderLayout (java.awt.BorderLayout)2 Dimension (java.awt.Dimension)2 ActionEvent (java.awt.event.ActionEvent)2 WindowAdapter (java.awt.event.WindowAdapter)2 WindowEvent (java.awt.event.WindowEvent)2 FileOutputStream (java.io.FileOutputStream)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 JButton (javax.swing.JButton)2 JFrame (javax.swing.JFrame)2 JPanel (javax.swing.JPanel)2