Search in sources :

Example 66 with Point2d

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

the class GreebleSkel method mapTo2d.

protected void mapTo2d(Face f, Loop<LPoint3d> ll, MiniFacade mf, WallTag wallTag, Set<QuadF> features, MatMeshBuilder faceMaterial) {
    Matrix4d to2dXY = new Matrix4d();
    Vector3d up = f.edge.uphill, along = f.edge.direction(), out = f.edge.getPlaneNormal();
    along.normalize();
    to2dXY.setRow(2, up.x, up.y, up.z, 0);
    to2dXY.setRow(1, out.x, out.y, out.z, 0);
    to2dXY.setRow(0, -along.x, -along.y, -along.z, 0);
    Point3d bottomS = f.definingSE.iterator().next().getStart(f), bottomE = f.definingSE.iterator().next().getEnd(f);
    Point3d start = new Point3d(bottomS);
    Point3d end = new Point3d(bottomE);
    to2dXY.m33 = 1;
    to2dXY.transform(start);
    to2dXY.m03 = -start.x;
    to2dXY.m13 = -start.y;
    to2dXY.m23 = -start.z;
    start = new Point3d(bottomS);
    to2dXY.transform(start);
    to2dXY.transform(end);
    Loop<LPoint2d> flat = GreebleHelper.to2dLoop(GreebleHelper.transform(ll, to2dXY), 1);
    Matrix4d to3d = new Matrix4d(to2dXY);
    to3d.invert();
    {
        // face in z-up, we're in y-up
        double[] one = new double[4], two = new double[4];
        to3d.getRow(1, one);
        to3d.getRow(2, two);
        to3d.setRow(1, two);
        to3d.setRow(2, one);
    }
    // now in jme space
    Matrix4d to2d = new Matrix4d(to3d);
    to2d.invert();
    MiniFacade forFace = null;
    if (mf != null) {
        forFace = new MiniFacade(mf);
        forFace.rects.clear();
    }
    LinearForm3D facePlane = new LinearForm3D(new Vector3d(out.x, out.z, out.y), new Point3d(bottomS.x, bottomS.z, bottomS.y));
    LoopL<Point2d> sides = null;
    DRectangle facadeRect = null;
    if (wallTag != null) {
        sides = findRectagle(flat, Pointz.to2(start), Pointz.to2(end));
        if (sides != null)
            facadeRect = findRect(sides.remove(0));
    }
    List<DRectangle> floors = new ArrayList();
    List<MeshBuilder> materials = new ArrayList();
    if (wallTag != null && facadeRect != null && mf != null && wallTag.isGroundFloor && mf.groundFloorHeight > 0 && wallTag.groundFloorColor != null && facadeRect.x < mf.groundFloorHeight && facadeRect.getMaxX() > mf.groundFloorHeight) {
        floors.addAll(facadeRect.splitY(mf.groundFloorHeight));
        MatMeshBuilder gfm = greebleGrid.mbs.get("brick", wallTag.groundFloorColor);
        for (Loop<Point2d> loop : sides) {
            Loop<Point2d>[] cut = Loopz.cutConvex(loop, new LinearForm(0, 1, mf.groundFloorHeight));
            faceMaterial.add(cut[1].singleton(), to3d);
            gfm.add(cut[0].singleton(), to3d);
        }
        materials.add(gfm);
        materials.add(faceMaterial);
    } else {
        floors.add(facadeRect);
        materials.add(faceMaterial);
        if (sides != null)
            faceMaterial.add(sides, to3d);
    }
    for (int j = 0; j < floors.size(); j++) {
        DRectangle floorRect = floors.get(j);
        MeshBuilder m = materials.get(j);
        Iterator<QuadF> quit = features.iterator();
        while (quit.hasNext()) {
            QuadF n = quit.next();
            if (n.project(to2d, to3d, flat, facePlane, new Vector3d(along.y, 0, -along.x)) && wallTag != null && floorRect != null && forFace != null) {
                // set the vertical bounds, so we can just render in 2d
                FRect bounds = new FRect(n.original);
                n.setBounds(to2d, bounds);
                if (floorRect.contains(bounds)) {
                    forFace.rects.put(n.original.f, bounds);
                    quit.remove();
                }
            }
        }
        if (wallTag == null || forFace == null || floorRect == null) {
            m.add(flat.singleton(), to3d);
            return;
        }
        List<DRectangle> occlusions = new ArrayList<>();
        for (LineHeight lh : wallTag.occlusions) {
            Point3d s = new Point3d(lh.start.x, lh.start.y, lh.min), e = new Point3d(lh.end.x, lh.end.y, lh.max);
            to2dXY.transform(s);
            to2dXY.transform(e);
            occlusions.add(new DRectangle(Math.min(s.x, e.x), s.z, Math.abs(e.x - s.x), Math.abs(e.z - s.z)));
        }
        if (mf.texture == null)
            greebleGrid.buildGrid(floorRect, to3d, forFace, m, wallTag);
        else
            greebleGrid.textureGrid(floorRect, to3d, mf);
    }
}
Also used : Loop(org.twak.utils.collections.Loop) DRectangle(org.twak.utils.geom.DRectangle) LPoint2d(org.twak.viewTrace.facades.GreebleHelper.LPoint2d) ArrayList(java.util.ArrayList) LinearForm(org.twak.utils.geom.LinearForm) LinearForm3D(org.twak.utils.geom.LinearForm3D) Matrix4d(javax.vecmath.Matrix4d) Vector3d(javax.vecmath.Vector3d) LPoint2d(org.twak.viewTrace.facades.GreebleHelper.LPoint2d) Point2d(javax.vecmath.Point2d) Point3d(javax.vecmath.Point3d) LPoint3d(org.twak.viewTrace.facades.GreebleHelper.LPoint3d) MeshBuilder(org.twak.siteplan.jme.MeshBuilder)

Example 67 with Point2d

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

the class GreebleSkel method findValid.

private static PtInChain findValid(List<Point2d> chain, double startingX, boolean left) {
    double bestArea = -Double.MAX_VALUE;
    PtInChain bestPt = new PtInChain(chain.get(0), 0, 0);
    double bestX = chain.get(0).x;
    Point2d pt;
    for (int i = 0; i < chain.size(); i++) {
        pt = chain.get(i);
        bestX = left ? Math.max(pt.x, bestX) : Math.min(pt.x, bestX);
        double area = Math.abs(startingX - bestX) * pt.y;
        if (area > bestArea || area == 0 && bestArea == 0 && pt.y > bestPt.y) {
            bestPt = new PtInChain(new Point2d(bestX, pt.y), i, 0);
            bestArea = area;
        }
    }
    return bestPt;
}
Also used : LPoint2d(org.twak.viewTrace.facades.GreebleHelper.LPoint2d) Point2d(javax.vecmath.Point2d)

Example 68 with Point2d

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

the class GreebleSkel method setToHeight.

private static PtInChain setToHeight(List<Point2d> chain, boolean left, double x2, double y2) {
    double bestX = chain.get(0).x;
    for (int i = 1; i < chain.size(); i++) {
        Point2d p = chain.get(i - 1), n = chain.get(i);
        bestX = left ? Math.max(p.x, bestX) : Math.min(p.x, bestX);
        PtInChain first = new PtInChain(new Point2d(n), i, 0);
        first.x = bestX;
        if (Math.abs(n.y - y2) < 0.001) {
            first.x = left ? Math.max(n.x, first.x) : Math.min(n.x, first.x);
            return first;
        }
        Line pn = new Line(p, n);
        if (n.y > y2) {
            Point2d sec = new LinearForm(pn).intersect(new LinearForm(0, 1, y2));
            if (sec == null)
                return first;
            sec.x = left ? Math.max(bestX, sec.x) : Math.min(bestX, sec.x);
            return new PtInChain(sec, i - 1, pn.findPPram(sec));
        }
    }
    return null;
}
Also used : Line(org.twak.utils.Line) LPoint2d(org.twak.viewTrace.facades.GreebleHelper.LPoint2d) Point2d(javax.vecmath.Point2d) LinearForm(org.twak.utils.geom.LinearForm)

Example 69 with Point2d

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

the class GMLReader method main1.

public static void main1(String[] args) {
    Graph2D g2 = readGMLToGraph(new File("/home/twak/data/langham/langham.gml"));
    g2.removeInnerEdges();
    Point2d offset = new Point2d();
    int count = 0;
    for (Point2d p : g2.map.keySet()) for (Line l : g2.get(p)) {
        count++;
        offset.add(l.start);
        System.out.println(l);
    }
    offset.scale(1. / count);
    System.out.println("offset is " + offset);
    AffineTransform at = AffineTransform.getScaleInstance(-1, 1);
    at.concatenate(AffineTransform.getTranslateInstance(-offset.x, -offset.y));
    g2 = g2.apply(at);
    UnionWalker uw = new UnionWalker();
    for (Point2d a : g2.map.keySet()) {
        for (Line l : g2.get(a)) {
            uw.addEdge(l.start, l.end);
        }
    }
    LoopL<Point2d> out = uw.findAll();
    ObjDump obj = new ObjDump();
    for (Loop<Point2d> loop : out) {
        List<Point3d> pts = new ArrayList();
        for (Point2d pt : loop) pts.add(new Point3d(pt.x, 0, pt.y));
        obj.addFace(pts);
    }
    obj.dump(new File(Tweed.SCRATCH + "langham.obj"));
}
Also used : ArrayList(java.util.ArrayList) Graph2D(org.twak.utils.geom.Graph2D) Line(org.twak.utils.Line) Point2d(javax.vecmath.Point2d) ObjDump(org.twak.utils.geom.ObjDump) Point3d(javax.vecmath.Point3d) AffineTransform(java.awt.geom.AffineTransform) UnionWalker(org.twak.utils.geom.UnionWalker) File(java.io.File)

Example 70 with Point2d

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

the class GMLReader method readGMLToGraph.

public static Graph2D readGMLToGraph(File in) {
    try {
        InputSource input = new InputSource(new FileInputStream(in));
        Graph2D out = new Graph2D();
        new GMLReader(input) {

            public void newPoly(String name) {
            }

            @Override
            public void hole(int n) {
                newPoly("hoel");
            }

            public void addLine(double[] s, double[] e) {
                out.add(new Point2d(e), new Point2d(s));
            }
        };
        return out;
    } catch (Throwable e) {
        e.printStackTrace();
        return null;
    }
}
Also used : InputSource(org.xml.sax.InputSource) Point2d(javax.vecmath.Point2d) LineString(com.vividsolutions.jts.geom.LineString) FileInputStream(java.io.FileInputStream) Graph2D(org.twak.utils.geom.Graph2D)

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