Search in sources :

Example 1 with LoopL

use of org.twak.utils.collections.LoopL in project chordatlas by twak.

the class GMLReader method readGML3d.

public static LoopL<Point3d> readGML3d(File in, DefaultGeocentricCRS targetCS, CoordinateReferenceSystem sourceCS) {
    LoopL<Point3d> out = new LoopL();
    try {
        InputSource input = new InputSource(new FileInputStream(in));
        new GMLReader(input, targetCS, sourceCS) {

            Loop<Point3d> parent, poly;

            public void newPoly(String name) {
                parent = poly = new SuperLoop<Point3d>(name);
                out.add(poly);
            }

            @Override
            public void hole(int n) {
                poly = new Loop<Point3d>();
                parent.holes.add(poly);
            }

            public void addLine(double[] s, double[] e) {
                poly.append(new Point3d(s[0], s[1], s[2]));
            }
        };
    } catch (Throwable e) {
        e.printStackTrace();
    }
    System.out.println("found " + out.size() + " polygons ");
    return out;
}
Also used : Loop(org.twak.utils.collections.Loop) SuperLoop(org.twak.utils.collections.SuperLoop) InputSource(org.xml.sax.InputSource) Point3d(javax.vecmath.Point3d) SuperLoop(org.twak.utils.collections.SuperLoop) LoopL(org.twak.utils.collections.LoopL) LineString(com.vividsolutions.jts.geom.LineString) FileInputStream(java.io.FileInputStream)

Example 2 with LoopL

use of org.twak.utils.collections.LoopL in project chordatlas by twak.

the class GreebleHelper method findPerimeter.

public static LoopL<LPoint3d> findPerimeter(Face f) {
    LoopL<LPoint3d> out = new LoopL<>();
    for (Loop<SharedEdge> loop : f.edges) {
        Loop<LPoint3d> lout = new Loop<>();
        out.add(lout);
        for (SharedEdge se : loop) {
            String label;
            Face other = se.getOther(f);
            if (other == null || se.start.z < 0.1 && se.end.z < 0.1)
                label = FLOOR_EDGE;
            else if (GreebleEdge.isWall(other))
                label = WALL_EDGE;
            else
                label = ROOF_EDGE;
            Point3d pt = se.getStart(f);
            if (pt != null)
                lout.append(new LPoint3d(pt, label));
        }
    }
    return out;
}
Also used : Loop(org.twak.utils.collections.Loop) SharedEdge(org.twak.camp.Output.SharedEdge) Point3d(javax.vecmath.Point3d) LoopL(org.twak.utils.collections.LoopL) Face(org.twak.camp.Output.Face)

Example 3 with LoopL

use of org.twak.utils.collections.LoopL in project chordatlas by twak.

the class SliceSolver method align.

private static double align(LoopL<Point2d> top, LoopL<Point2d> bottom) {
    if (top.isEmpty() || bottom.isEmpty())
        return Double.MAX_VALUE;
    if (top == bottom)
        return 0;
    LoopL bbackwards = new LoopL<>(bottom);
    bbackwards.reverseEachLoop();
    return Math.sqrt(Math.abs(Loopz.area(Loopz.insideOutside(top, bbackwards))));
}
Also used : LoopL(org.twak.utils.collections.LoopL)

Example 4 with LoopL

use of org.twak.utils.collections.LoopL 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 5 with LoopL

use of org.twak.utils.collections.LoopL in project chordatlas by twak.

the class GISGen method importMesh.

private void importMesh(int index) {
    LoopL<Point3d> polies = blocks.get(index);
    List<Vector2D> verts = polies.stream().flatMap(ll -> ll.streamAble()).map(x -> {
        Line3d l = new Line3d(x.get(), x.getNext().get());
        l.move(perp(l.dir(), EXPAND_MESH));
        return new Vector2D(l.start.x, l.start.z);
    }).collect(Collectors.toList());
    double tol = 0.0001;
    ConvexHull2D chull = null;
    while (tol < 10) {
        try {
            chull = new MonotoneChain(false, tol).generate(verts);
            tol = 1000;
        } catch (ConvergenceException e) {
            tol *= 10;
        }
    }
    if (chull == null) {
        System.out.println("unable to find hull");
        return;
    }
    Loop<Point3d> hull = new Loop<Point3d>((Arrays.stream(chull.getLineSegments()).map(x -> new Point3d(x.getStart().getX(), 0, x.getStart().getY())).collect(Collectors.toList())));
    File root = new File(Tweed.SCRATCH + "meshes" + File.separator);
    int i = 0;
    File l;
    while ((l = new File(root, "" + i)).exists()) i++;
    l.mkdirs();
    File croppedFile = new File(l, CROPPED_OBJ);
    boolean found = false;
    for (Gen gen : tweed.frame.gens(MiniGen.class)) {
        // minigen == optimised obj
        ((MiniGen) gen).clip(hull, croppedFile);
        found = true;
    }
    if (!found)
        for (Gen gen : tweed.frame.gens(MeshGen.class)) {
            // obj == just import whole obj
            ObjGen objg = (ObjGen) gen;
            try {
                Files.asByteSource(objg.getFile()).copyTo(Files.asByteSink(croppedFile));
                objg.setVisible(false);
                found = true;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    if (found) {
        Graph2D g2 = new Graph2D();
        polies.stream().flatMap(ll -> ll.streamAble()).forEach(x -> g2.add(new Point2d(x.get().x, x.get().z), new Point2d(x.getNext().get().x, x.getNext().get().z)));
        g2.removeInnerEdges();
        // new Plot (true, g2 );
        UnionWalker uw = new UnionWalker();
        for (Point2d p : g2.map.keySet()) for (Line line : g2.map.get(p)) uw.addEdge(line.end, line.start);
        // new Plot (true, new ArrayList( uw.map.keySet()) );
        Loopz.writeXZObj(uw.findAll(), new File(l, "gis.obj"), true);
        Loopz.writeXZObj(Loopz.to2dLoop(polies, 1, null), new File(l, "gis_footprints.obj"), false);
        BlockGen bg = new BlockGen(l, tweed, polies);
        lastMesh.put(index, bg);
        tweed.frame.addGen(bg, true);
        tweed.frame.setSelected(bg);
    } else
        JOptionPane.showMessageDialog(tweed.frame(), "Failed to find mesh from minimesh or gml layers");
}
Also used : FactoryException(org.opengis.referencing.FactoryException) Arrays(java.util.Arrays) CRS(org.geotools.referencing.CRS) NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) Matrix4d(javax.vecmath.Matrix4d) Closer(org.twak.viewTrace.Closer) ConvexHull2D(org.apache.commons.math3.geometry.euclidean.twod.hull.ConvexHull2D) Loop(org.twak.utils.collections.Loop) ObjRead(org.twak.utils.geom.ObjRead) Complete(org.twak.utils.Parallel.Complete) Map(java.util.Map) Point3d(javax.vecmath.Point3d) LoopL(org.twak.utils.collections.LoopL) SuperLoop(org.twak.utils.collections.SuperLoop) Parallel(org.twak.utils.Parallel) ListDownLayout(org.twak.utils.ui.ListDownLayout) Line(org.twak.utils.Line) Set(java.util.Set) ConvergenceException(org.apache.commons.math3.exception.ConvergenceException) DefaultGeocentricCRS(org.geotools.referencing.crs.DefaultGeocentricCRS) Collectors(java.util.stream.Collectors) SatUtils(org.twak.footprints.SatUtils) FacadeFinder(org.twak.viewTrace.FacadeFinder) List(java.util.List) Optional(java.util.Optional) GMLReader(org.twak.viewTrace.GMLReader) Line3d(org.twak.utils.geom.Line3d) JPanel(javax.swing.JPanel) GenHandlesSelect(org.twak.tweed.GenHandlesSelect) FacadeTool(org.twak.tweed.tools.FacadeTool) HashMap(java.util.HashMap) Graph2D(org.twak.utils.geom.Graph2D) Pair(org.twak.utils.Pair) Vector3d(javax.vecmath.Vector3d) Vector2D(org.apache.commons.math3.geometry.euclidean.twod.Vector2D) Tweed(org.twak.tweed.Tweed) ArrayList(java.util.ArrayList) TweedSettings(org.twak.tweed.TweedSettings) HashSet(java.util.HashSet) Files(com.google.common.io.Files) SelectTool(org.twak.tweed.tools.SelectTool) NoSuchElementException(java.util.NoSuchElementException) JComponent(javax.swing.JComponent) UnionWalker(org.twak.utils.geom.UnionWalker) Work(org.twak.utils.Parallel.Work) MonotoneChain(org.apache.commons.math3.geometry.euclidean.twod.hull.MonotoneChain) IOException(java.io.IOException) JOptionPane(javax.swing.JOptionPane) File(java.io.File) Loopz(org.twak.utils.collections.Loopz) Point2d(javax.vecmath.Point2d) ConvexHull2D(org.apache.commons.math3.geometry.euclidean.twod.hull.ConvexHull2D) Line3d(org.twak.utils.geom.Line3d) MonotoneChain(org.apache.commons.math3.geometry.euclidean.twod.hull.MonotoneChain) Point3d(javax.vecmath.Point3d) ConvergenceException(org.apache.commons.math3.exception.ConvergenceException) UnionWalker(org.twak.utils.geom.UnionWalker) Loop(org.twak.utils.collections.Loop) SuperLoop(org.twak.utils.collections.SuperLoop) IOException(java.io.IOException) Graph2D(org.twak.utils.geom.Graph2D) Line(org.twak.utils.Line) Vector2D(org.apache.commons.math3.geometry.euclidean.twod.Vector2D) Point2d(javax.vecmath.Point2d) File(java.io.File)

Aggregations

LoopL (org.twak.utils.collections.LoopL)6 Point3d (javax.vecmath.Point3d)4 ArrayList (java.util.ArrayList)3 Loop (org.twak.utils.collections.Loop)3 HashMap (java.util.HashMap)2 Point2d (javax.vecmath.Point2d)2 Line3d (org.twak.utils.geom.Line3d)2 ObjRead (org.twak.utils.geom.ObjRead)2 Closer (org.twak.viewTrace.Closer)2 Files (com.google.common.io.Files)1 LineString (com.vividsolutions.jts.geom.LineString)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 IdentityHashMap (java.util.IdentityHashMap)1 List (java.util.List)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1