Search in sources :

Example 1 with Instance

use of org.twak.siteplan.anchors.Ship.Instance 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)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Point2d (javax.vecmath.Point2d)1 Bar (org.twak.camp.ui.Bar)1 Marker (org.twak.camp.ui.Marker)1 Ship (org.twak.siteplan.anchors.Ship)1 Instance (org.twak.siteplan.anchors.Ship.Instance)1 Plan (org.twak.siteplan.campskeleton.Plan)1 PlanSkeleton (org.twak.siteplan.campskeleton.PlanSkeleton)1 Profile (org.twak.siteplan.campskeleton.Profile)1 SuperEdge (org.twak.tweed.gen.SuperEdge)1 Cache (org.twak.utils.Cache)1 Loop (org.twak.utils.collections.Loop)1 LoopL (org.twak.utils.collections.LoopL)1 HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)1