Search in sources :

Example 11 with Line3d

use of org.twak.utils.geom.Line3d in project chordatlas by twak.

the class Prof method buildProfile.

public static Prof buildProfile(ObjRead mesh, Line3d oLine, Point3d cen, double minH, double maxH, double minD, double maxD, Tweed tweed, Node dbg) {
    Prof monotonic = buildProfile(oLine, cen);
    Vector3d dir = oLine.dir();
    dir.normalize();
    Vector3d sliceNormal = new Vector3d(dir.x, 0, dir.z);
    LinearForm3D lf = new LinearForm3D(sliceNormal, cen);
    List<Line3d> lines = ObjSlice.sliceTri(mesh, lf, 0.5, new Vector3d(-dir.z, 0, dir.x), Math.PI / 2 + 0.1);
    // dbg.attachChild( Jme3z.lines( tweed, lines, ColorRGBA.Blue, 2 ) );
    Line3d first = null;
    double closestStart = Double.MAX_VALUE;
    for (Line3d l : lines) {
        if (l.start.y > l.end.y)
            l.reverse();
        double dist = l.distanceSquared(cen);
        if (dist < closestStart) {
            closestStart = dist;
            first = l;
        }
    }
    if (first == null) {
        return null;
    // lines.clear();
    // monotonic.add( cen );
    // monotonic.add( new Point3d( cen.x, cen.y - 500, cen.z ) );
    } else {
        climb(lines, first, monotonic, maxH, true);
        climb(lines, first, monotonic, minH, false);
    }
    {
        double tol = 0.2;
        minD -= tol;
        maxD += tol;
        LinearForm min = new LinearForm(Mathz.UP).findC(new Point2d(minD, 0));
        LinearForm max = new LinearForm(Mathz.UP).findC(new Point2d(maxD, 0));
        for (int i = 0; i < monotonic.size() - 1; i++) {
            Point2d a = monotonic.get(i), b = monotonic.get(i + 1);
            if (a.x < minD && b.x < minD) {
                monotonic.remove(i);
                i--;
            } else if (a.x < minD) {
                monotonic.set(i, new LinearForm(new Line(a, b)).intersect(min));
            } else if (b.x < minD) {
                monotonic.set(i + 1, new LinearForm(new Line(a, b)).intersect(min));
                b.x = minD + Math.ulp(minD);
            }
            if (a.x > maxD && b.x > maxD) {
                monotonic.remove(i);
                i--;
            } else if (a.x > maxD) {
                monotonic.set(i, new LinearForm(new Line(a, b)).intersect(max));
            } else if (b.x > maxD) {
                monotonic.set(i + 1, new LinearForm(new Line(a, b)).intersect(max));
                b.x = maxD - Math.ulp(maxD);
            }
        }
    }
    return monotonic;
}
Also used : Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine) Vector3d(javax.vecmath.Vector3d) Point2d(javax.vecmath.Point2d) LinearForm(org.twak.utils.geom.LinearForm) LinearForm3D(org.twak.utils.geom.LinearForm3D) Line3d(org.twak.utils.geom.Line3d)

Example 12 with Line3d

use of org.twak.utils.geom.Line3d in project chordatlas by twak.

the class GreebleGrid method createDormerWindow.

protected void createDormerWindow(QuadF l, MeshBuilder window, MeshBuilder glass, float sillDepth, float sillHeight, float corniceHeight, double panelWidth, double panelHeight) {
    Vector3d along = new Vector3d(l.corners[3]);
    along.sub(l.corners[0]);
    along.normalize();
    Vector3d up = new Vector3d(0, 1, 0);
    Vector3d out = new Vector3d();
    out.cross(along, up);
    out.scale(1 / out.length());
    Line3d lout;
    {
        Point3d away = new Point3d(l.corners[0]);
        away.add(out);
        lout = new Line3d(new Point3d(l.corners[0]), away);
    }
    Vector3d loc = new Vector3d(l.found[0]);
    if (lout.findPPram(l.found[0]) < lout.findPPram(l.found[1])) {
        // outwards going wall...
        loc = new Vector3d(up);
        loc.scale(-l.original.height);
        loc.add(l.found[1]);
    }
    {
        Vector3d avoidRoof = new Vector3d(out);
        avoidRoof.scale(0.09);
        ;
        loc.add(avoidRoof);
    }
    Point3d deepest = Arrays.stream(l.found).map(p -> new Pair<Point3d, Double>(p, lout.findPPram(p))).max((a, b) -> b.second().compareTo(a.second())).get().first();
    double depth = lout.closestPointOn(deepest, false).distance(lout.closestPointOn(new Point3d(loc), false));
    // MUtils.max(
    // Math.abs (l.corners[0].distance( l.found[0] )),
    // Math.abs (l.corners[1].distance( l.found[1] )),
    // Math.abs (l.corners[2].distance( l.found[2] )),
    // Math.abs (l.corners[3].distance( l.found[3] ))
    // ) ;
    WindowGen.createWindow(window, glass, new Window(Jme3z.to(loc), Jme3z.to(along), Jme3z.to(up), l.original.width, l.original.height, depth, panelWidth, panelHeight));
// Vector3f u = Jme3z.to(up), o = Jme3z.to( out );
// if (sillDepth > 0)
// window.addCube( Jme3z.to ( ptt[0] ).add( u.mult( -sillHeight + 0.01f ) ).add( o.mult( -sillDepth) ),
// Jme3z.to(out), Jme3z.to(along), Jme3z.to(up),
// (float)depth + sillDepth, (float)winPanel.width,(float) sillHeight  );
// 
// if (corniceHeight > 0)
// moulding( to3d, new DRectangle(winPanel.x, winPanel.getMaxY(), winPanel.width, corniceHeight), wall );
}
Also used : Arrays(java.util.Arrays) Cach2(org.twak.utils.Cach2) Cache2(org.twak.utils.Cache2) Griddable(org.twak.viewTrace.facades.Grid.Griddable) WindowGen(org.twak.tweed.gen.WindowGen) LinearForm3D(org.twak.utils.geom.LinearForm3D) Matrix4d(javax.vecmath.Matrix4d) ClickMe(org.twak.tweed.ClickMe) Pair(org.twak.utils.Pair) Vector3d(javax.vecmath.Vector3d) QuadF(org.twak.viewTrace.facades.GreebleSkel.QuadF) Tweed(org.twak.tweed.Tweed) ArrayList(java.util.ArrayList) Node(com.jme3.scene.Node) Pointz(org.twak.tweed.gen.Pointz) Material(com.jme3.material.Material) Point3d(javax.vecmath.Point3d) Output(org.twak.camp.Output) Vector3f(com.jme3.math.Vector3f) MeshBuilder(org.twak.siteplan.jme.MeshBuilder) Vector2d(javax.vecmath.Vector2d) File(java.io.File) CrossGen(org.twak.viewTrace.facades.Tube.CrossGen) Point2d(javax.vecmath.Point2d) List(java.util.List) Jme3z(org.twak.siteplan.jme.Jme3z) DRectangle(org.twak.utils.geom.DRectangle) ColorRGBA(com.jme3.math.ColorRGBA) Face(org.twak.camp.Output.Face) Window(org.twak.tweed.gen.WindowGen.Window) Line3d(org.twak.utils.geom.Line3d) Collections(java.util.Collections) Feature(org.twak.viewTrace.facades.MiniFacade.Feature) Geometry(com.jme3.scene.Geometry) Window(org.twak.tweed.gen.WindowGen.Window) Vector3d(javax.vecmath.Vector3d) Point3d(javax.vecmath.Point3d) Line3d(org.twak.utils.geom.Line3d) Pair(org.twak.utils.Pair)

Example 13 with Line3d

use of org.twak.utils.geom.Line3d in project chordatlas by twak.

the class Tube method angle.

private static double angle(Collection<LinearForm3D> lfs, Line3d line) {
    double min = Double.MAX_VALUE;
    for (LinearForm3D lf : lfs) {
        Point3d s = lf.project(line.start), e = lf.project(line.end);
        min = Math.min(min, line.angle(new Line3d(s, e).dir()));
    }
    return min;
}
Also used : Point3d(javax.vecmath.Point3d) LinearForm3D(org.twak.utils.geom.LinearForm3D) Line3d(org.twak.utils.geom.Line3d)

Example 14 with Line3d

use of org.twak.utils.geom.Line3d in project chordatlas by twak.

the class GreebleGrid method moulding.

protected void moulding(Matrix4d to3d, DRectangle rect, MeshBuilder mb) {
    double hh = rect.height / 2;
    Point3d start = new Point3d(rect.x, 0, rect.y + hh), end = new Point3d(rect.getMaxX(), 0, rect.y + hh);
    to3d.transform(start);
    to3d.transform(end);
    Line3d line = new Line3d(start, end);
    Vector3d dir = line.dir();
    dir.normalize();
    Vector3d nDir = new Vector3d(dir);
    nDir.scale(-1);
    LinearForm3D left = new LinearForm3D(nDir, start), right = new LinearForm3D(dir, end);
    LinearForm3D wall = new LinearForm3D(to3d.m01, to3d.m11, to3d.m21);
    wall.findD(start);
    Tube.tube(mb, Collections.singleton(left), Collections.singleton(right), line, wall, wall, new CrossGen() {

        @Override
        public List<Point2d> gen(Vector2d down, Vector2d up) {
            Vector2d d = new Vector2d(down);
            d.normalize();
            Vector2d dP = new Vector2d(d.y, -d.x);
            List<Point2d> out = new ArrayList();
            for (double[] coords : new double[][] { { 1.00, 0.00 }, { 1.00, 0.05 }, { 0.66, 0.05 }, { 0.66, 0.10 }, { 0.33, 0.10 }, { 0.33, 0.17 }, { 0.00, 0.17 }, { 0.00, 0.00 } }) {
                Point2d tmp = new Point2d(d);
                tmp.scale(coords[0] * rect.height - hh);
                Point2d tmp2 = new Point2d(dP);
                tmp2.scale(coords[1]);
                tmp.add(tmp2);
                out.add(tmp);
            }
            return out;
        }
    });
}
Also used : Vector2d(javax.vecmath.Vector2d) Vector3d(javax.vecmath.Vector3d) Point2d(javax.vecmath.Point2d) Point3d(javax.vecmath.Point3d) CrossGen(org.twak.viewTrace.facades.Tube.CrossGen) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinearForm3D(org.twak.utils.geom.LinearForm3D) Line3d(org.twak.utils.geom.Line3d)

Example 15 with Line3d

use of org.twak.utils.geom.Line3d 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

Line3d (org.twak.utils.geom.Line3d)17 Point3d (javax.vecmath.Point3d)15 ArrayList (java.util.ArrayList)10 LinearForm3D (org.twak.utils.geom.LinearForm3D)10 List (java.util.List)8 Point2d (javax.vecmath.Point2d)8 Vector3d (javax.vecmath.Vector3d)7 Vector2d (javax.vecmath.Vector2d)5 Loop (org.twak.utils.collections.Loop)5 ColorRGBA (com.jme3.math.ColorRGBA)4 Line (org.twak.utils.Line)4 Pair (org.twak.utils.Pair)4 Material (com.jme3.material.Material)3 Geometry (com.jme3.scene.Geometry)3 Node (com.jme3.scene.Node)3 File (java.io.File)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 Matrix4d (javax.vecmath.Matrix4d)3