Search in sources :

Example 16 with Point2d

use of javax.vecmath.Point2d 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 17 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class SkelGen method moveToX0.

public static Prof moveToX0(Prof prof) {
    Prof out = new Prof(prof);
    double tol = 0.01;
    if (out.get(1).y == tol && out.get(2).y == tol && out.size() >= 4) {
        // post-process out steps :(
        out.remove(0);
        out.remove(0);
        out.set(0, new Point2d(out.get(0).x, 0));
        prof = out;
        out = new Prof(prof);
    }
    Point2d first = out.get(0);
    if (first.x > -100) {
        // always move to origin
        // if ( first.x > -1.5 ) { // move to origin
        double offset = first.x;
        out.clear();
        for (Point2d p : prof) out.add(new Point2d(p.x - offset, p.y));
    } else {
        // add "step" and keep it where it is
        first.y = tol;
        out.add(0, new Point2d(0.0, tol));
        out.add(0, new Point2d(0, 0));
    }
    return out;
}
Also used : Point2d(javax.vecmath.Point2d) Prof(org.twak.tweed.gen.Prof)

Example 18 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class SkelGen method toProf.

private Prof toProf(Profile profile) {
    List<Point2d> pts = profile.points.get(0).stream().map(b -> new Point2d(-b.end.x, -b.end.y)).collect(Collectors.toList());
    pts.add(0, new Point2d());
    Prof prof = new Prof();
    for (Point2d p : pts) prof.add(p);
    return prof;
}
Also used : Plan(org.twak.siteplan.campskeleton.Plan) PlanSkeleton(org.twak.siteplan.campskeleton.PlanSkeleton) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) Pix2Pix(org.twak.viewTrace.facades.Pix2Pix) Tag(org.twak.camp.Tag) Bar(org.twak.camp.ui.Bar) Loop(org.twak.utils.collections.Loop) Node(com.jme3.scene.Node) Profile(org.twak.siteplan.campskeleton.Profile) IDumpObjs(org.twak.tweed.IDumpObjs) Map(java.util.Map) Cache(org.twak.utils.Cache) Siteplan(org.twak.siteplan.campskeleton.Siteplan) Prof(org.twak.tweed.gen.Prof) LoopL(org.twak.utils.collections.LoopL) IdentityHashMap(java.util.IdentityHashMap) BlockGen(org.twak.tweed.gen.BlockGen) Output(org.twak.camp.Output) ListDownLayout(org.twak.utils.ui.ListDownLayout) Line(org.twak.utils.Line) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) Instance(org.twak.siteplan.anchors.Ship.Instance) HalfMesh2(org.twak.utils.geom.HalfMesh2) Regularizer(org.twak.viewTrace.facades.Regularizer) Collectors(java.util.stream.Collectors) List(java.util.List) Loopable(org.twak.utils.collections.Loopable) WallTag(org.twak.viewTrace.facades.WallTag) Optional(java.util.Optional) JPanel(javax.swing.JPanel) WindowConstants(javax.swing.WindowConstants) Gen(org.twak.tweed.gen.Gen) Ship(org.twak.siteplan.anchors.Ship) ActionListener(java.awt.event.ActionListener) ProfileAssignmentViewer(org.twak.tweed.gen.ProfileAssignmentViewer) HashMap(java.util.HashMap) MiniFacade(org.twak.viewTrace.facades.MiniFacade) Plot(org.twak.utils.ui.Plot) Tweed(org.twak.tweed.Tweed) SkelFootprint(org.twak.tweed.gen.SkelFootprint) ArrayList(java.util.ArrayList) TweedSettings(org.twak.tweed.TweedSettings) MiniViewer(org.twak.tweed.gen.MiniViewer) Spatial(com.jme3.scene.Spatial) Mathz(org.twak.utils.Mathz) PaintThing(org.twak.utils.PaintThing) ProgressMonitor(javax.swing.ProgressMonitor) SuperEdge(org.twak.tweed.gen.SuperEdge) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) Iterator(java.util.Iterator) GreebleSkel(org.twak.viewTrace.facades.GreebleSkel) Marker(org.twak.camp.ui.Marker) ActionEvent(java.awt.event.ActionEvent) JmeGen(org.twak.tweed.gen.JmeGen) OnClick(org.twak.viewTrace.facades.GreebleSkel.OnClick) Loopz(org.twak.utils.collections.Loopz) Point2d(javax.vecmath.Point2d) Changed(org.twak.utils.WeakListener.Changed) Jme3z(org.twak.siteplan.jme.Jme3z) JLabel(javax.swing.JLabel) RoofTag(org.twak.viewTrace.facades.RoofTag) Skeleton(org.twak.camp.Skeleton) ObjDump(org.twak.utils.geom.ObjDump) SuperFace(org.twak.tweed.gen.SuperFace) Collections(java.util.Collections) CGAMini(org.twak.viewTrace.facades.CGAMini) CompareGens(org.twak.tweed.CompareGens) Point2d(javax.vecmath.Point2d) Prof(org.twak.tweed.gen.Prof)

Example 19 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class SatUtils method render.

public static void render(Tweed tweed, LoopL<Point3d> loopL) {
    double[] range = Loopz.minMax(loopL);
    double jump = 30;
    int xMin = -1, xMax = 1, yMin = -1, yMax = 1;
    BufferedImage out = new BufferedImage(640 * (xMax - xMin + 1), 640 * (yMax - yMin + 1), BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g = out.createGraphics();
    int cenX = out.getWidth() / 2, cenY = out.getHeight() / 2;
    int removeBottom = 30;
    try {
        for (int x = xMin; x <= xMax; x++) for (int y = yMax; y >= yMin; y--) {
            Point3d cen = new Point3d((range[0] + range[1]) * 0.5 + x * jump, 0, (range[4] + range[5]) * 0.5 + y * jump);
            Point2d ll = worldToLLong(tweed, cen);
            System.out.println("in EPSG:27700 " + cen);
            System.out.println("lat long " + ll.x + " " + ll.y);
            URL url = new URL("https://maps.googleapis.com/maps/api/staticmap?center=" + ll.x + "," + ll.y + "&zoom=20&size=640x640&maptype=satellite&format=png32&key=go_get_your_own");
            URLConnection connection = url.openConnection();
            InputStream is = connection.getInputStream();
            BufferedImage image = ImageIO.read(is);
            g.drawImage(image, cenX - image.getWidth() / 2 - x * 323 + y * 8, cenY - image.getHeight() / 2 - x * 8 - y * 323, cenX + image.getWidth() / 2 - x * 323 + y * 8, cenY + image.getHeight() / 2 - x * 8 - y * 323 - removeBottom, 0, 0, image.getWidth(), image.getHeight() - removeBottom, null);
        }
        g.dispose();
        ImageIO.write(out, "png", new File(Tweed.SCRATCH + "ssat.png"));
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : Point2d(javax.vecmath.Point2d) Point3d(javax.vecmath.Point3d) InputStream(java.io.InputStream) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) URL(java.net.URL) URLConnection(java.net.URLConnection) Graphics2D(java.awt.Graphics2D)

Example 20 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class SatUtils method worldToLLong.

public static Point2d worldToLLong(Tweed tweed, Point3d cen) {
    Point3d out = new Point3d(cen);
    TweedSettings.settings.fromOrigin.transform(out);
    try {
        double[] latLong = new double[3];
        toLatLong.transform(new double[] { out.x, out.y, out.z }, 0, latLong, 0, 1);
        return new Point2d(latLong[0], latLong[1]);
    } catch (TransformException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Point2d(javax.vecmath.Point2d) Point3d(javax.vecmath.Point3d) TransformException(org.opengis.referencing.operation.TransformException)

Aggregations

Point2d (javax.vecmath.Point2d)84 Line (org.twak.utils.Line)37 ArrayList (java.util.ArrayList)29 Point3d (javax.vecmath.Point3d)27 List (java.util.List)18 Vector2d (javax.vecmath.Vector2d)17 SuperLine (org.twak.viewTrace.SuperLine)17 File (java.io.File)15 Vector3d (javax.vecmath.Vector3d)15 Map (java.util.Map)14 HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)14 HashMap (java.util.HashMap)13 Loop (org.twak.utils.collections.Loop)13 Collectors (java.util.stream.Collectors)12 IOException (java.io.IOException)11 HashSet (java.util.HashSet)11 Set (java.util.Set)11 Tweed (org.twak.tweed.Tweed)11 Matrix4d (javax.vecmath.Matrix4d)10 LinearForm (org.twak.utils.geom.LinearForm)10