Search in sources :

Example 1 with PlanSkeleton

use of org.twak.siteplan.campskeleton.PlanSkeleton in project chordatlas by twak.

the class SkelGen method buildCamp.

private static PlanSkeleton buildCamp(SuperFace sf, Double cap) {
    Plan plan = new Plan();
    LoopL<Bar> loopl = new LoopL();
    Loop<Bar> loop = new Loop();
    loopl.add(loop);
    Cache<Point2d, Point2d> cache = new Cache<Point2d, Point2d>() {

        @Override
        public Point2d create(Point2d i) {
            return new Point2d(i.x, i.y);
        }
    };
    LoopL<HalfEdge> edges = sf.findHoles();
    LoopL<Point2d> lpd = new LoopL();
    for (Loop<HalfEdge> loopHE : edges) {
        Map<Point2d, SuperEdge> ses = new HashMap();
        Loop<Point2d> lp = new Loop();
        lpd.add(lp);
        for (HalfEdge he : loopHE) {
            SuperEdge se = (SuperEdge) he;
            lp.append(se.start);
            ses.put(se.start, se);
        }
        lp = Loopz.mergeAdjacentEdges2(lp, 0.001);
        for (Loopable<Point2d> lpb : lp.loopableIterator()) {
            Bar b = new Bar(cache.get(lpb.getNext().get()), cache.get(lpb.get()));
            SuperEdge se = ses.get(lpb.get());
            Profile profile = null;
            if (se.prof == null || se.prof.size() < 2) {
                List<Point2d> defpts = new ArrayList<>();
                defpts.add(new Point2d(0, 0));
                defpts.add(new Point2d(0, -sf.height * 1.2));
                profile = new Profile(defpts);
            } else {
                profile = toProfile(se.prof);
            }
            tagWalls(profile, ((SuperFace) se.face).roofColor, se, lpb.get(), lpb.getNext().get());
            plan.addLoop(profile.points.get(0), plan.root, profile);
            b.tags.add(new SETag(se));
            loop.prepend(b);
            plan.profiles.put(b, profile);
        }
    }
    plan.points = loopl;
    if (cap != null) {
        // skel.capAt( cap, a -> skel.capArea = a ); simple...but doesn't show in the siteplan ui
        Ship s = new FlatRoofShip(cap, plan);
        for (Profile prof : plan.profiles.values()) {
            for (Loop<Bar> lb : prof.points) {
                boolean addedMarker = false;
                for (Bar b : lb) {
                    if (-b.start.y < cap && -b.end.y > cap || (!addedMarker && b == lb.start.getPrev().get())) {
                        Marker m = new Marker();
                        m.set(b.toLine().xAtY(-cap), -cap);
                        m.bar = b;
                        m.bar.mould.create(m, null);
                        Instance i = s.newInstance();
                        i.anchors[0].setProfileGen(m.generator);
                        addedMarker = true;
                    }
                }
            }
        }
        plan.ships.add(s);
    }
    PlanSkeleton skel = new PlanSkeleton(plan);
    skel.skeleton();
    return skel;
}
Also used : PlanSkeleton(org.twak.siteplan.campskeleton.PlanSkeleton) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) Instance(org.twak.siteplan.anchors.Ship.Instance) ArrayList(java.util.ArrayList) Profile(org.twak.siteplan.campskeleton.Profile) Loop(org.twak.utils.collections.Loop) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) LoopL(org.twak.utils.collections.LoopL) Marker(org.twak.camp.ui.Marker) Plan(org.twak.siteplan.campskeleton.Plan) SuperEdge(org.twak.tweed.gen.SuperEdge) Bar(org.twak.camp.ui.Bar) Point2d(javax.vecmath.Point2d) Ship(org.twak.siteplan.anchors.Ship) Cache(org.twak.utils.Cache)

Example 2 with PlanSkeleton

use of org.twak.siteplan.campskeleton.PlanSkeleton in project chordatlas by twak.

the class SkelGen method selected.

private void selected(PlanSkeleton skel, Node house, SuperFace sf, SuperEdge se) {
    JPanel ui = new JPanel();
    ui.setLayout(new ListDownLayout());
    JButton fac = new JButton("edit facade");
    fac.addActionListener(e -> editFacade(skel, sf, se, false));
    ui.add(fac);
    // JButton tex = new JButton( "texture facade" );
    // tex.addActionListener( e -> editFacade( skel, sf, se, true ) );
    // ui.add( tex );
    JButton proc = new JButton("procedural facade");
    proc.addActionListener(e -> cgaFacade(skel, sf, se));
    ui.add(proc);
    JButton camp = new JButton("procedural extrusions");
    camp.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            closeSitePlan();
            siteplan = new Siteplan(skel.plan, false) {

                SuperFace workon = sf;

                public void show(Output output, Skeleton threadKey) {
                    super.show(output, threadKey);
                    Plot.closeLast();
                    tweed.enqueue(new Runnable() {

                        @Override
                        public void run() {
                            removeGeometryFor(workon);
                            // current selection is invalid
                            tweed.frame.setGenUI(null);
                            setSkel((PlanSkeleton) threadKey, output, workon);
                        }
                    });
                }
            };
            siteplan.setVisible(true);
            siteplan.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        }
    });
    ui.add(camp);
    JButton mini = new JButton("street-view");
    mini.addActionListener(e -> new MiniViewer(se));
    if (sf != null)
        ui.add(mini);
    JButton prof = new JButton("profiles");
    prof.addActionListener(e -> new ProfileAssignmentViewer(sf, skelFootprint == null ? null : skelFootprint.globalProfs));
    ui.add(prof);
    ui.add(new JLabel("height " + sf.heights.size()));
    JButton plan = new JButton("plan");
    plan.addActionListener(e -> new Plot(toRender, footprint));
    ui.add(plan);
    JButton remove = new JButton("remove");
    remove.addActionListener(e -> {
        visible = false;
        calculateOnJmeThread();
        tweed.frame.removeGen(SkelGen.this);
    });
    ui.add(plan);
    JButton b = new JButton("view clean profiles");
    b.addActionListener(e -> SkelFootprint.debugFindCleanProfiles(footprint, this, new ProgressMonitor(null, "", "", 0, 100), tweed));
    ui.add(b);
    JButton c = new JButton("compare profiles");
    c.addActionListener(e -> skelFootprint.debugCompareProfs(skelFootprint.globalProfs));
    ui.add(c);
    tweed.frame.setGenUI(ui);
}
Also used : JPanel(javax.swing.JPanel) ListDownLayout(org.twak.utils.ui.ListDownLayout) PlanSkeleton(org.twak.siteplan.campskeleton.PlanSkeleton) ActionEvent(java.awt.event.ActionEvent) Plot(org.twak.utils.ui.Plot) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) SuperFace(org.twak.tweed.gen.SuperFace) ProgressMonitor(javax.swing.ProgressMonitor) ActionListener(java.awt.event.ActionListener) Siteplan(org.twak.siteplan.campskeleton.Siteplan) Output(org.twak.camp.Output) MiniViewer(org.twak.tweed.gen.MiniViewer) PlanSkeleton(org.twak.siteplan.campskeleton.PlanSkeleton) Skeleton(org.twak.camp.Skeleton) ProfileAssignmentViewer(org.twak.tweed.gen.ProfileAssignmentViewer)

Example 3 with PlanSkeleton

use of org.twak.siteplan.campskeleton.PlanSkeleton in project chordatlas by twak.

the class SkelGen method calculate.

@Override
public void calculate() {
    for (Spatial s : gNode.getChildren()) s.removeFromParent();
    Node pNode = new Node();
    if (toRender != null)
        for (int i = 0; i < toRender.faces.size(); i++) try {
            HalfFace f = toRender.faces.get(i);
            SuperFace sf = (SuperFace) f;
            PlanSkeleton skel = calc(sf);
            if (skel != null)
                setSkel(skel, skel.output, sf);
        } catch (Throwable th) {
            th.printStackTrace();
        }
    if (!pNode.getChildren().isEmpty())
        tweed.frame.addGen(new JmeGen("sProfs", tweed, pNode), false);
    gNode.updateModelBound();
    gNode.updateGeometricState();
    super.calculate();
}
Also used : PlanSkeleton(org.twak.siteplan.campskeleton.PlanSkeleton) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) JmeGen(org.twak.tweed.gen.JmeGen) SuperFace(org.twak.tweed.gen.SuperFace)

Example 4 with PlanSkeleton

use of org.twak.siteplan.campskeleton.PlanSkeleton in project chordatlas by twak.

the class VizSkelGen method calculate.

@Override
public void calculate() {
    for (Spatial s : gNode.getChildren()) s.removeFromParent();
    SuperFace sf;
    if (mode == Mode.Extrude) {
        sf = toHalf(Loopz.to3d(Loopz.removeInnerEdges(Loopz.toXZLoop(blockGen.polies)).get(0), 0, 1));
        PlanSkeleton skel = calc(sf);
        setSkel(skel, skel.output, sf);
    } else
        for (Loop<Point3d> loop : blockGen.polies) {
            sf = toHalf(loop);
            PlanSkeleton skel = calc(sf);
            setSkel(skel, skel.output, sf);
        }
    gNode.updateModelBound();
    gNode.updateGeometricState();
    setVisible(visible);
}
Also used : Loop(org.twak.utils.collections.Loop) PlanSkeleton(org.twak.siteplan.campskeleton.PlanSkeleton) Spatial(com.jme3.scene.Spatial)

Example 5 with PlanSkeleton

use of org.twak.siteplan.campskeleton.PlanSkeleton in project chordatlas by twak.

the class SkelGen method calc.

protected static PlanSkeleton calc(SuperFace sf) {
    double pHeight = findHeightFromProfiles(sf);
    // good for pointy roofs
    PlanSkeleton skelP = buildCamp(sf, pHeight);
    // good for flat roofs
    PlanSkeleton skelS = buildCamp(sf, sf.height);
    PlanSkeleton skel;
    if (skelP == null && skelS == null)
        return null;
    if (skelP == null)
        skel = skelS;
    else if (skelS == null)
        skel = skelP;
    else {
        if (skelP.capArea < 0.5 * skelS.capArea)
            skel = skelP;
        else
            skel = skelS;
    }
    return skel;
}
Also used : PlanSkeleton(org.twak.siteplan.campskeleton.PlanSkeleton)

Aggregations

PlanSkeleton (org.twak.siteplan.campskeleton.PlanSkeleton)6 Spatial (com.jme3.scene.Spatial)2 Bar (org.twak.camp.ui.Bar)2 SuperFace (org.twak.tweed.gen.SuperFace)2 Loop (org.twak.utils.collections.Loop)2 Node (com.jme3.scene.Node)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 JButton (javax.swing.JButton)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 ProgressMonitor (javax.swing.ProgressMonitor)1 Point2d (javax.vecmath.Point2d)1 Output (org.twak.camp.Output)1 Skeleton (org.twak.camp.Skeleton)1 Marker (org.twak.camp.ui.Marker)1 Ship (org.twak.siteplan.anchors.Ship)1