Search in sources :

Example 6 with HalfEdge

use of org.twak.utils.geom.HalfMesh2.HalfEdge in project chordatlas by twak.

the class HouseTool method clickedOn.

@Override
public void clickedOn(Spatial target, Vector3f loc, Vector2f cursorPosition) {
    // (Line) new XStream().fromXML( new File( "/home/twak/data/regent/March_30/congo/1/line.xml" ) ));
    MegaFeatures mf = new MegaFeatures(new Line(0, 0, 10, 0));
    // FeatureCache.readFeatures( new File( "/home/twak/data/regent/March_30/congo/1/0" ), mf );
    ImageFeatures imf = new ImageFeatures();
    imf.mega = mf;
    double[] minMax = new double[] { 0, 15, 0, 25 };
    HalfMesh2.Builder builder = new HalfMesh2.Builder(SuperEdge.class, SuperFace.class);
    builder.newPoint(new Point2d(minMax[0] + loc.x, minMax[3] + loc.z));
    builder.newPoint(new Point2d(minMax[1] + loc.x, minMax[3] + loc.z));
    builder.newPoint(new Point2d(minMax[1] + loc.x, minMax[2] + loc.z));
    builder.newPoint(new Point2d(minMax[0] + loc.x, minMax[2] + loc.z));
    builder.newFace();
    HalfMesh2 mesh = builder.done();
    Prof p = new Prof();
    p.add(new Point2d(0, 0));
    p.add(new Point2d(0, 20));
    p.add(new Point2d(-5, 25));
    boolean first = true;
    for (HalfFace f : mesh) {
        for (HalfEdge e : f) {
            SuperEdge se = (SuperEdge) e;
            se.prof = p;
            MiniFacade mini = newMini(imf, se.length());
            if (true) {
                se.addMini(mini);
                se.proceduralFacade = mf;
                se.toEdit = mini;
                if (first)
                    se.addMini(mini);
            }
            first = false;
        }
        SuperFace sf = (SuperFace) f;
        sf.maxProfHeights = new ArrayList();
        sf.maxProfHeights.add(Double.valueOf(100));
        sf.height = 100;
    }
    SkelGen sg = new SkelGen(mesh, tweed, null);
    tweed.frame.addGen(sg, true);
}
Also used : MiniFacade(org.twak.viewTrace.facades.MiniFacade) ImageFeatures(org.twak.tweed.gen.FeatureCache.ImageFeatures) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) ArrayList(java.util.ArrayList) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) SuperEdge(org.twak.tweed.gen.SuperEdge) SuperFace(org.twak.tweed.gen.SuperFace) SkelGen(org.twak.tweed.gen.skel.SkelGen) Line(org.twak.utils.Line) Point2d(javax.vecmath.Point2d) HalfMesh2(org.twak.utils.geom.HalfMesh2) Prof(org.twak.tweed.gen.Prof)

Example 7 with HalfEdge

use of org.twak.utils.geom.HalfMesh2.HalfEdge 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 8 with HalfEdge

use of org.twak.utils.geom.HalfMesh2.HalfEdge in project chordatlas by twak.

the class SolverState method miniPainter.

public ICanPaint miniPainter() {
    return new ICanPaint() {

        @Override
        public void paint(Graphics2D g, PanMouseAdaptor ma) {
            // for ( MegaFeatures f : SS.minis.keySet() ) {
            // 
            // for ( MFPoint mfp : SS.minis.get( f ) ) {
            // Line l = mfp.image.mega.megafacade;
            // 
            // spreadImages( g, ma, l, mfp,  Listz.from( mfp.left, mfp.right ) );
            // 
            // }
            // }
            // if (SS.minis == null)
            int brake = 100;
            for (HalfFace f : mesh) {
                for (HalfEdge e : f) {
                    if (e.over != null)
                        continue;
                    if (brake-- < 0)
                        break;
                    SuperEdge se = (SuperEdge) e;
                    if (se.mini == null)
                        continue;
                    List<MiniFacade> mfs = new ArrayList(se.mini);
                    // while (mfs .size() < 2)
                    // mfs.add(null);
                    spreadImages(g, ma, se.line(), se.line().fromPPram(0.5), mfs);
                }
            }
            int i = 0;
            if (minis != null)
                for (MegaFeatures f : minis.keySet()) {
                    // PaintThing.paint (f.megafacade, g, ma);
                    DumbCluster1D<MFPoint> res = GurobiSkelSolver.clusterMinis(f, minis);
                    Vector2d dir = f.megafacade.dir();
                    Vector2d out = new Vector2d(dir);
                    out.set(-out.y, out.x);
                    out.scale(ma.toZoom(2) / out.length());
                    for (Cluster<MFPoint> c : res) {
                        g.setColor(Rainbow.getColour(i++));
                        for (MFPoint mfp : c.things) {
                            Point2d pt = new Point2d(mfp);
                            pt.add(out);
                            g.setStroke(new BasicStroke(0.2f));
                            PaintThing.paint(pt, g, ma);
                            g.setStroke(new BasicStroke(0.2f));
                            for (HalfEdge e : GurobiSkelSolver.findNear(f.megafacade, mfp, mesh)) g.drawLine(ma.toX(pt.x), ma.toY(pt.y), ma.toX(e.end.x), ma.toY(e.end.y));
                            if (mfp.selectedEdge != null) {
                                g.setStroke(new BasicStroke(2f));
                                g.drawLine(ma.toX(pt.x), ma.toY(pt.y), ma.toX(mfp.selectedEdge.end.x), ma.toY(mfp.selectedEdge.end.y));
                            }
                        }
                    }
                }
            g.setStroke(new BasicStroke(1));
        }

        private void spreadImages(Graphics2D g, PanMouseAdaptor ma, Line sel, Point2d cen, List<MiniFacade> mfs) {
            Vector2d perp = sel.dir();
            perp.set(-perp.y, perp.x);
            perp.normalize();
            for (int i = 0; i < mfs.size(); i++) {
                MiniFacade mf = mfs.get(i);
                Vector2d p2 = new Vector2d(perp);
                p2.scale((i + 1) * 10);
                p2.add(cen);
                if (mf == null) {
                    g.setColor(Color.black);
                    g.fillRect(ma.toX(p2.x - 1), ma.toY(p2.y - 3), ma.toZoom(2), ma.toZoom(6));
                    continue;
                }
                double w = mf.width * 0.1;
                double h = mf.height * 0.1;
                mf.paintImage(g, ma, p2.x - w, p2.y - h, p2.x + w, p2.y + h);
            }
        }
    };
}
Also used : BasicStroke(java.awt.BasicStroke) MiniFacade(org.twak.viewTrace.facades.MiniFacade) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) ArrayList(java.util.ArrayList) Cluster(org.twak.utils.DumbCluster1D.Cluster) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) DumbCluster1D(org.twak.utils.DumbCluster1D) ICanPaint(org.twak.utils.PaintThing.ICanPaint) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) ICanPaint(org.twak.utils.PaintThing.ICanPaint) Graphics2D(java.awt.Graphics2D) Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine) Vector2d(javax.vecmath.Vector2d) Point2d(javax.vecmath.Point2d) PanMouseAdaptor(org.twak.utils.PanMouseAdaptor) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with HalfEdge

use of org.twak.utils.geom.HalfMesh2.HalfEdge in project chordatlas by twak.

the class SkelFootprint method killDoubleEdges.

public static void killDoubleEdges(HalfMesh2 mesh) {
    for (HalfFace f : mesh) {
        boolean iDidSomething;
        do {
            iDidSomething = false;
            for (HalfEdge e : f) {
                if (e.next.over == e) {
                    e.dissolve(mesh);
                    iDidSomething = true;
                }
            }
        } while (iDidSomething);
    }
}
Also used : HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace)

Example 10 with HalfEdge

use of org.twak.utils.geom.HalfMesh2.HalfEdge in project chordatlas by twak.

the class SkelFootprint method pushHeightsToSmallFaces.

private static void pushHeightsToSmallFaces(HalfMesh2 mesh) {
    for (HalfFace f : mesh.faces) {
        SuperFace sf = (SuperFace) f;
        if (sf.height == -Double.MAX_VALUE) {
            // || sf.area() < 1  ) {
            double bestLength = -Double.MAX_VALUE;
            SuperFace bestFace = null;
            overProfile: for (boolean overProfiles : new boolean[] { false, true }) {
                for (HalfEdge e2 : f.edges()) {
                    double len = e2.length();
                    if (len > bestLength && e2.over != null)
                        if (overProfiles || ((SuperEdge) e2).profLine == null && ((SuperEdge) e2.over).profLine == null) {
                            SuperFace sf2 = (SuperFace) e2.over.face;
                            if (sf2.height != -Double.MAX_VALUE) {
                                bestFace = sf2;
                                bestLength = len;
                            }
                        }
                }
                if (bestFace != null) {
                    sf.height = bestFace.height;
                    break overProfile;
                }
            }
        }
    }
}
Also used : HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace)

Aggregations

HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)31 HalfFace (org.twak.utils.geom.HalfMesh2.HalfFace)25 Point2d (javax.vecmath.Point2d)15 MFPoint (org.twak.tweed.gen.FeatureCache.MFPoint)13 Line (org.twak.utils.Line)13 SuperLine (org.twak.viewTrace.SuperLine)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 MegaFeatures (org.twak.tweed.gen.FeatureCache.MegaFeatures)8 HalfMesh2 (org.twak.utils.geom.HalfMesh2)7 Color (java.awt.Color)6 LinkedHashSet (java.util.LinkedHashSet)6 List (java.util.List)6 Map (java.util.Map)6 MultiMap (org.twak.utils.collections.MultiMap)6 File (java.io.File)5 Set (java.util.Set)5 Vector2d (javax.vecmath.Vector2d)5 Cach (org.twak.utils.Cach)5