Search in sources :

Example 6 with Point2d

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

the class MiniFacade method getMenu.

@Override
public void getMenu(MouseEvent e, PanMouseAdaptor ma, ChangeListener cl) {
    mouseDown(e, ma);
    SimplePopup2 pop = new SimplePopup2(e);
    if (dragging != null)
        pop.add("delete", new Runnable() {

            @Override
            public void run() {
                if (dragging != null)
                    rects.remove(dragging.f, dragging);
                cl.stateChanged(null);
            }
        });
    if (dragging != null)
        pop.add("duplicate", new Runnable() {

            @Override
            public void run() {
                mouseDown(e, ma);
                if (dragging != null) {
                    FRect rec = new FRect(dragging);
                    // rec.x += 0.5;
                    rec.x += rec.width + 0.3;
                    rects.put(rec.f, rec);
                    cl.stateChanged(null);
                }
            }
        });
    for (Feature f : Feature.values()) {
        pop.add("add " + f.name().toLowerCase(), new Runnable() {

            @Override
            public void run() {
                Point2d pt = flip(ma.from(e));
                FRect rec = new FRect(pt.x, pt.y, pt.x + 0.5, pt.y + 0.5);
                rec.f = f;
                rects.put(f, rec);
                cl.stateChanged(null);
            }
        });
    }
    pop.add("color", new Runnable() {

        @Override
        public void run() {
            new ColourPicker(null, new Color((float) color[0], (float) color[1], (float) color[2])) {

                @Override
                public void picked(Color color) {
                    MiniFacade.this.color = new double[] { color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1 };
                    cl.stateChanged(null);
                }
            };
        }
    });
    pop.show();
}
Also used : ColourPicker(org.twak.utils.ui.ColourPicker) Point2d(javax.vecmath.Point2d) Color(java.awt.Color) SimplePopup2(org.twak.utils.ui.SimplePopup2)

Example 7 with Point2d

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

the class GreebleGrid method findWorldBox.

protected Vector3f[] findWorldBox(DRectangle door, Matrix4d to3d, double depth) {
    Point2d[] pts = door.points();
    Point3d[] ptt = new Point3d[4];
    for (int i = 0; i < 4; i++) {
        ptt[i] = Pointz.to3(pts[i]);
        to3d.transform(ptt[i]);
    }
    Vector3d along = new Vector3d(ptt[3]);
    along.sub(ptt[0]);
    along.normalize();
    Vector3d up = new Vector3d(ptt[1]);
    up.sub(ptt[0]);
    up.normalize();
    Vector3d out = new Vector3d();
    out.cross(along, up);
    out.normalize();
    Vector3d loc = new Vector3d();
    loc.cross(along, up);
    loc.scale(-depth / loc.length());
    loc.add(ptt[0]);
    Vector3f lo = Jme3z.to(loc), ou = Jme3z.to(out), al = Jme3z.to(along), u = Jme3z.to(up), p = Jme3z.to(ptt[0]);
    return new Vector3f[] { lo, ou, al, u, p };
}
Also used : Point2d(javax.vecmath.Point2d) Vector3d(javax.vecmath.Vector3d) Point3d(javax.vecmath.Point3d) Vector3f(com.jme3.math.Vector3f)

Example 8 with Point2d

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

the class GreebleSkel method toPoly.

private static Loop<Point2d> toPoly(List<Point2d> left, PtInChain xyL) {
    Loop<Point2d> lef = new Loop<>();
    for (int i = 0; i <= xyL.prevPt; i++) lef.append(left.get(i));
    if (xyL.frac > 0 && xyL.prevPt < left.size() - 1)
        lef.append(new Line(left.get(xyL.prevPt), left.get(xyL.prevPt + 1)).fromPPram(xyL.frac));
    lef.append(new Point2d(xyL.x, xyL.y));
    lef.append(new Point2d(xyL.x, 0));
    return lef;
}
Also used : Loop(org.twak.utils.collections.Loop) Line(org.twak.utils.Line) LPoint2d(org.twak.viewTrace.facades.GreebleHelper.LPoint2d) Point2d(javax.vecmath.Point2d)

Example 9 with Point2d

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

the class GreebleSkel method findSE.

private static double[] findSE(MiniFacade mf, Line l, List<Face> chain) {
    double mlen = l.length();
    double lowest = Double.MAX_VALUE;
    Face bestFace = null;
    for (Face f : chain) {
        double[] bounds = Loopz.minMax(f.getLoopL());
        if (bounds[5] - bounds[4] > 1 && bounds[4] < lowest) {
            bestFace = f;
            lowest = bounds[4];
        }
    }
    if (bestFace == null)
        // !
        return new double[] { mf.left, mf.left + mf.width };
    List<Double> params = bestFace.getLoopL().streamE().map(p3 -> l.findPPram(new Point2d(p3.x, p3.y))).collect(Collectors.toList());
    double[] out = new double[] { params.stream().mapToDouble(x -> x).min().getAsDouble() * mlen, params.stream().mapToDouble(x -> x).max().getAsDouble() * mlen };
    // if good, stretch whole minifacade to mesh
    if (Mathz.inRange((out[1] - out[0]) / (mf.width), 0.66, 1.4))
        return out;
    // else snap to the closest of start/end
    if (l.fromPPram(out[0] / mlen).distance(l.fromPPram(mf.left / mlen)) > l.fromPPram(out[1] / mlen).distance(l.fromPPram((mf.left + mf.width) / mlen)))
        return new double[] { out[1] - mf.width, out[1] };
    else
        return new double[] { out[0], out[0] + mf.width };
}
Also used : LinearForm3D(org.twak.utils.geom.LinearForm3D) PlanSkeleton(org.twak.siteplan.campskeleton.PlanSkeleton) Matrix4d(javax.vecmath.Matrix4d) ClickMe(org.twak.tweed.ClickMe) Tag(org.twak.camp.Tag) Vector3d(javax.vecmath.Vector3d) Bar(org.twak.camp.ui.Bar) Tweed(org.twak.tweed.Tweed) ArrayList(java.util.ArrayList) TweedSettings(org.twak.tweed.TweedSettings) HashSet(java.util.HashSet) SETag(org.twak.tweed.gen.skel.SETag) Loop(org.twak.utils.collections.Loop) Node(com.jme3.scene.Node) SwingUtilities(javax.swing.SwingUtilities) Pointz(org.twak.tweed.gen.Pointz) Mathz(org.twak.utils.Mathz) SuperEdge(org.twak.tweed.gen.SuperEdge) Point3d(javax.vecmath.Point3d) ColumnProperties(org.twak.siteplan.campskeleton.PlanSkeleton.ColumnProperties) LoopL(org.twak.utils.collections.LoopL) Iterator(java.util.Iterator) Output(org.twak.camp.Output) Edge(org.twak.camp.Edge) Line(org.twak.utils.Line) Set(java.util.Set) MeshBuilder(org.twak.siteplan.jme.MeshBuilder) LinearForm(org.twak.utils.geom.LinearForm) Collectors(java.util.stream.Collectors) LPoint2d(org.twak.viewTrace.facades.GreebleHelper.LPoint2d) Loopz(org.twak.utils.collections.Loopz) Point2d(javax.vecmath.Point2d) LPoint3d(org.twak.viewTrace.facades.GreebleHelper.LPoint3d) List(java.util.List) Loopable(org.twak.utils.collections.Loopable) DRectangle(org.twak.utils.geom.DRectangle) Optional(java.util.Optional) Face(org.twak.camp.Output.Face) Feature(org.twak.viewTrace.facades.MiniFacade.Feature) LPoint2d(org.twak.viewTrace.facades.GreebleHelper.LPoint2d) Point2d(javax.vecmath.Point2d) Face(org.twak.camp.Output.Face)

Example 10 with Point2d

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

the class GreebleEdge method roofGreeble.

public static boolean roofGreeble(Face f, MeshBuilder roof) {
    boolean isWall = isWall(f);
    for (Loop<SharedEdge> sl : f.edges) {
        for (Loopable<SharedEdge> sel : sl.loopableIterator()) {
            SharedEdge se = sel.get();
            boolean otherIsWall = isWall(se.getOther(f));
            if (!isWall && !otherIsWall) {
                Face oF = se.getOther(f);
                if (oF == null || order(f, oF) || f.edge.getPlaneNormal().angle(oF.edge.getPlaneNormal()) < 0.4)
                    continue;
                List<LinearForm3D> start = new ArrayList(), end = new ArrayList<>();
                {
                    SharedEdge fPrev = se.getAdjEdge(f, false), fNext = se.getAdjEdge(f, true), ofPrev = se.getAdjEdge(oF, false), ofNext = se.getAdjEdge(oF, true);
                    if (fNext == null || fPrev == null || ofNext == null || ofPrev == null)
                        continue;
                    double overHang = -0.03;
                    if (isWall(fNext.getOther(f)))
                        end.add(toLF(fNext.getOther(f), overHang));
                    else
                        end.add(roofTween(fNext, se, f));
                    if (isWall(ofPrev.getOther(oF)))
                        end.add(toLF(ofPrev.getOther(oF), overHang));
                    else
                        end.add(roofTween(se, ofPrev, oF));
                    if (isWall(fPrev.getOther(f)))
                        start.add(toLF(fPrev.getOther(f), overHang));
                    else
                        start.add(roofTween(se, fPrev, f));
                    if (isWall(ofNext.getOther(oF)))
                        start.add(toLF(ofNext.getOther(oF), overHang));
                    else
                        start.add(roofTween(ofNext, se, oF));
                }
                Point3d s = se.getStart(f), e = se.getEnd(f);
                if (end.contains(null) || start.contains(null))
                    continue;
                Tube.tube(roof, end, start, new Line3d(new Point3d(s.x, s.z, s.y), new Point3d(e.x, e.z, e.y)), toLF(f, 0), toLF(oF, 0), new CrossGen() {

                    @Override
                    public List<Point2d> gen(Vector2d left, Vector2d right) {
                        Vector2d l = new Vector2d(left);
                        l.normalize();
                        Vector2d lP = new Vector2d(l.y, -l.x);
                        Vector2d r = new Vector2d(right);
                        r.normalize();
                        Vector2d rP = new Vector2d(-r.y, r.x);
                        List<Point2d> out = new ArrayList();
                        double width = 0.15, height = 0.03;
                        Vector2d rn = new Vector2d(r);
                        rn.negate();
                        // height / Math.sin ( ( Math.PI - l.angle( rn ) ) /2 );
                        double cenOffset = 0.02;
                        Vector2d cen = new Vector2d(lP);
                        cen.add(rP);
                        cen.normalize();
                        for (double[] coords : new double[][] { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, -width }, { 0, 0, 0, height, -width }, { 0, 0, cenOffset, 0, 0 }, { -width, height, 0, 0, 0 }, { -width, 0, 0, 0, 0 } }) {
                            Point2d tmp = new Point2d(l), tmp2;
                            tmp.scale(coords[0]);
                            tmp2 = new Point2d(lP);
                            tmp2.scale(coords[1]);
                            tmp.add(tmp2);
                            tmp2 = new Point2d(cen);
                            tmp2.scale(coords[2]);
                            tmp.add(tmp2);
                            tmp2 = new Point2d(rP);
                            tmp2.scale(coords[3]);
                            tmp.add(tmp2);
                            tmp2 = new Point2d(r);
                            tmp2.scale(coords[4]);
                            tmp.add(tmp2);
                            out.add(tmp);
                        }
                        return out;
                    }
                });
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) LinearForm3D(org.twak.utils.geom.LinearForm3D) Line3d(org.twak.utils.geom.Line3d) SharedEdge(org.twak.camp.Output.SharedEdge) Vector2d(javax.vecmath.Vector2d) Point2d(javax.vecmath.Point2d) Point3d(javax.vecmath.Point3d) CrossGen(org.twak.viewTrace.facades.Tube.CrossGen) ArrayList(java.util.ArrayList) List(java.util.List) Face(org.twak.camp.Output.Face)

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