Search in sources :

Example 1 with Line

use of org.twak.utils.Line in project chordatlas by twak.

the class FeatureCache method readFeatures.

public static ImageFeatures readFeatures(File fFolder, MegaFeatures megaFeatures) {
    Line mega = new Line(megaFeatures.megafacade);
    ImageFeatures out = new ImageFeatures();
    out.mega = megaFeatures;
    Line imageL = null;
    out.miniFacades = new ArrayList();
    {
        if (Tweed.DATA == null)
            out.ortho = new File(fFolder, RENDERED_IMAGE_PNG);
        else
            out.ortho = Paths.get(Tweed.DATA).relativize(new File(fFolder, RENDERED_IMAGE_PNG).toPath()).toFile();
        File rectFile = new File(fFolder, "rectified.png");
        if (rectFile.exists()) {
            if (Tweed.DATA == null)
                out.rectified = rectFile;
            else
                out.rectified = Paths.get(Tweed.DATA).relativize(rectFile.toPath()).toFile();
        } else
            out.rectified = out.ortho;
    }
    int imageWidth = out.getRectified().getWidth(), imageHeight = out.getRectified().getHeight();
    double rectifiedToOrtho = out.getRectified().getWidth() / (double) out.getOrtho().getWidth();
    {
        List<String> lines = null;
        try {
            lines = Files.readAllLines(new File(fFolder, "meta.txt").toPath());
        } catch (IOException e) {
            System.err.println("failed to read metafile");
        }
        if (lines == null) {
            System.out.println("warning, failed to read input files in " + fFolder);
            imageL = new Line(0, 0, out.getRectified().getWidth() / FacadeTool.pixelsPerMeter, 0);
        } else {
            String plane = lines.get(1);
            String[] pVals = plane.split(" ");
            Point2d a = new Point2d(Float.parseFloat(pVals[0]), Float.parseFloat(pVals[1]));
            Point2d b = new Point2d(Float.parseFloat(pVals[2]), Float.parseFloat(pVals[3]));
            imageL = new Line(a, b);
        }
    }
    out.start = mega.findPPram(imageL.start) * mega.length();
    out.end = mega.findPPram(imageL.end) * mega.length();
    try {
        File yFile = new File(fFolder, PARAMETERS_YML);
        if (yFile.exists()) {
            YamlReader fromVision = new YamlReader(new FileReader(yFile));
            Map m = (Map) fromVision.read();
            List yamlFac = (List) m.get("facades");
            double maxW = 0;
            if (yamlFac != null) {
                for (Object o : yamlFac) try {
                    MiniFacade mf = new MiniFacade(out, (Map) o, imageWidth / (rectifiedToOrtho * FacadeTool.pixelsPerMeter), imageHeight / FacadeTool.pixelsPerMeter, rectifiedToOrtho * FacadeTool.pixelsPerMeter, out.start);
                    if (!mf.invalid())
                        out.miniFacades.add(mf);
                    maxW = Math.max(maxW, (mf.left + mf.width - out.start));
                } catch (Throwable th) {
                    System.out.println("while reading " + yFile);
                    th.printStackTrace();
                }
            }
        } else
            System.out.println("no parameters in " + fFolder);
    } catch (Throwable e) {
        e.printStackTrace();
    }
    return out;
}
Also used : MiniFacade(org.twak.viewTrace.facades.MiniFacade) ArrayList(java.util.ArrayList) IOException(java.io.IOException) YamlReader(com.esotericsoftware.yamlbeans.YamlReader) ICanPaint(org.twak.utils.PaintThing.ICanPaint) Line(org.twak.utils.Line) Point2d(javax.vecmath.Point2d) ArrayList(java.util.ArrayList) List(java.util.List) FileReader(java.io.FileReader) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MultiMap(org.twak.utils.collections.MultiMap)

Example 2 with Line

use of org.twak.utils.Line in project chordatlas by twak.

the class MiniFacade method paint.

@Override
public void paint(Graphics2D g, PanMouseAdaptor ma) {
    if (PAINT_IMAGE && imageFeatures != null) {
        Composite oldC = g.getComposite();
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
        paintImage(g, ma, left, -height, left + width, 0);
        g.setComposite(oldC);
    }
    g.setStroke(new BasicStroke(2f));
    if (width < 5)
        return;
    for (Feature f : Feature.values()) if (f != Feature.GRID)
        for (FRect w : rects.get(f)) {
            if (w.outer == null) {
                g.setColor(f.color);
                // if (w.width < 10)
                g.drawRect(ma.toX(w.x), ma.toY(-w.y - w.height), ma.toZoom(w.width), ma.toZoom(w.height));
                g.setColor(Color.black);
                if (w.id >= 0)
                    g.drawString(w.id + "", ma.toX(w.x) + 3, ma.toY(-w.y - w.height) + 13);
            // try {
            // g.drawString(
            // w.attachedHeight.get( Feature.CORNICE ).d +", " +
            // w.attachedHeight.get( Feature.BALCONY ).d +", "+
            // w.attachedHeight.get( Feature.SILL ).d + ", ",
            // ma.toX( w.x ) + 3, ma.toY( -w.y - w.height ) + 13  );
            // } catch (NullPointerException e) {}
            }
            for (Dir dir : Dir.values()) {
                FRect n = w.getAdj(dir);
                if (n != null) {
                    g.setColor(Rainbow.getColour(dir.ordinal()));
                    Point2d s = getRectPoint(w, dir), e = getRectPoint(n, dir.opposite);
                    s.y = -s.y;
                    e.y = -e.y;
                    Line l = new Line(s, e);
                    PaintThing.paint(l, g, ma);
                    PaintThing.drawArrow(g, ma, l, 3);
                // if ( dir == Dir.L || dir == Dir.U ) {
                // Point2d label = l.fromPPram( 0.5 );
                // g.drawString( w.distanceToAdjacent( dir ) + "", ma.toX( label.x ), ma.toY( label.y ) );
                // }
                }
            }
        }
    if (false && grid != null) {
        g.setColor(new Color(100, 100, 255, 200));
        // for ( DRectangle w : grid.dows )
        // g.fillRect( ma.toX( w.x ), ma.toY( -w.y - w.height ), ma.toZoom( w.width ), ma.toZoom( w.height ) );
        g.setColor(new Color(100, 255, 10, 200));
        if (false)
            for (int x = 0; x < grid.cols; x++) for (int y = 0; y < grid.rows; y++) {
                g.fillRect(ma.toX(x * grid.hspacing + grid.x), ma.toY(-y * grid.vspacing - grid.wHeight - grid.y), ma.toZoom(grid.wWidth), ma.toZoom(grid.wHeight));
            }
    }
    g.setColor(Color.black);
    g.drawLine(ma.toX(left), ma.toY(0), ma.toX(left + width), ma.toY(0));
    g.setColor(Color.green);
    g.setColor(new Color(0, 170, 255));
    g.setStroke(new BasicStroke(softLeft ? 1 : 3));
    g.drawLine(ma.toX(left), ma.toY(0), ma.toX(left), ma.toY(-height));
    g.setStroke(new BasicStroke(softRight ? 1 : 3));
    g.drawLine(ma.toX(left + width), ma.toY(0), ma.toX(left + width), ma.toY(-height));
    g.setColor(Color.black);
    g.setStroke(new BasicStroke(1));
    g.drawLine(ma.toX(left), ma.toY(-height), ma.toX(left + width), ma.toY(-height));
    g.drawLine(ma.toX(left), ma.toY(-groundFloorHeight), ma.toX(left + width), ma.toY(-groundFloorHeight));
}
Also used : BasicStroke(java.awt.BasicStroke) Line(org.twak.utils.Line) AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) Point2d(javax.vecmath.Point2d) Color(java.awt.Color) ICanPaint(org.twak.utils.PaintThing.ICanPaint)

Example 3 with Line

use of org.twak.utils.Line 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 4 with Line

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

use of org.twak.utils.Line in project chordatlas by twak.

the class SuperMeshPainter method paint.

@Override
public void paint(Object oa, Graphics2D g2, PanMouseAdaptor ma) {
    HalfMesh2 o = (HalfMesh2) oa;
    double scatterRadius = 0.0;
    if (o.faces.isEmpty())
        return;
    double maxHeight = o.faces.stream().mapToDouble(x -> ((SuperFace) x).height).max().getAsDouble();
    // (int) ( Math.random() * 100 );
    int fc = 0;
    for (HalfFace f : o.faces) {
        fc++;
        Polygon pwt = new Polygon();
        try {
            for (HalfEdge e : f.edges()) {
                pwt.addPoint(ma.toX(e.start.x + Math.random() * scatterRadius), ma.toY(e.start.y + Math.random() * scatterRadius));
            // PaintThing.paint(e.start, g2, ma);
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
        SuperFace sf = (SuperFace) f;
        Color c;
        if (false) {
            int h = (int) Mathz.clamp(((SuperFace) f).height * 5, 0, 255);
            if (((SuperFace) f).height == -Double.MAX_VALUE)
                c = Color.green;
            else if (((SuperFace) f).height < 0)
                c = Color.red;
            else
                c = new Color(h, h, h);
        } else if (sf.height == -Double.MAX_VALUE) {
            c = Color.yellow;
        } else if (sf.classification == -1 || sf.height < 0) {
            c = Color.red;
        } else {
            // c = Color.white;
            c = Rainbow.getColour(sf.classification + 1);
        // c = Rainbow.getColour( fc++ + 1 );
        }
        // c = Color.white;
        // new Color( c.getRed(), c.getGreen(), c.getBlue(), 50 ) );
        g2.setColor(c);
        g2.fill(pwt);
    // Loop<Point2d> pts = new Loop<>();
    // for ( HalfEdge e : f.edges() )
    // pts.append(e.end);
    // 
    // if ( ( Loopz.area( pts ) ) < 0.1 ) {
    // g2.setColor(Color.red);
    // g2.setStroke( new BasicStroke( 4f ) );
    // g2.draw( pwt );
    // }
    }
    for (HalfFace f : o.faces) {
        g2.setColor(Color.black);
        try {
            for (HalfEdge e : f) {
                SuperEdge se = (SuperEdge) e;
                g2.setColor(Color.black);
                if (se.proceduralFacade != null) {
                    g2.setStroke(new BasicStroke(3f));
                } else {
                    g2.setStroke(new BasicStroke(1f));
                }
            // if ( se.profLine != null || ( se.over != null && ((SuperEdge)se.over).profLine != null ) ) {
            // g2.setStroke( new BasicStroke( 2f ) );
            // g2.setColor( new Color (255, 0, 0 ) );
            // }
            // else
            // {
            // g2.setStroke( new BasicStroke( 1f ) );
            // g2.setColor( Color.black );
            // }
            // g2.setColor( ((SuperEdge)e).profLine == null? Color.green : Color.magenta);
            // PaintThing.paint ( e.line(), g2, ma );
            // }
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
        g2.setStroke(new BasicStroke(3));
        if (false)
            for (HalfEdge e : f.edges()) {
                SuperEdge se = (SuperEdge) e;
                if (se.profLine != null) {
                    // g2.setColor( Color.BLACK );
                    // new Line (new Point2d (e.start), new Point2d (e.end));
                    Line l = se.line();
                    // PaintThing.drawArrow( g2, ma, l, 5 );
                    g2.drawLine(ma.toX(l.start.x), ma.toY(l.start.y), ma.toX(l.end.x), ma.toY(l.end.y));
                }
            // if (e.over != null)
            // {
            // l.moveLeft( ma.fromZoom( 2 ) );
            // 
            // double delta = Math.abs (  ((SuperEdge)e).localHeight - ((SuperEdge)e.over).localHeight );
            // 
            // int h =  (int) Math.min(255, delta * 10 ) ;
            // g2.setColor ( new Color (0,h,h) );
            // g2.setStroke (new BasicStroke( 3f ));
            // 
            // }
            // if ( ( (SuperEdge) e ).debug ) {
            // if ( e.over == null || ((SuperFace)e.over.face).classification != ((SuperFace)f).classification ) {
            // g2.setColor( Color.black );
            // g2.setStroke( new BasicStroke( 2 ) );
            // PaintThing.paint( e.line(), g2, ma );
            // }
            }
    }
    fc = 0;
    if (false)
        for (HalfFace f : o.faces) {
            for (HalfEdge e : f.edges()) {
                // Point2d pt = new Point2d(e.start);
                // pt.add( off );
                // Point2d pt2 = new Point2d(e.end);
                // pt2.add( off );
                // 
                // PaintThing.paint( new Line (pt, pt2) , g2, ma );
                g2.setColor(new Color(255, 0, 0, 20));
                if (e.line().absAngle(e.next.line()) > Math.PI - 0.001) {
                    g2.setColor(new Color(0, 255, 0, 255));
                }
                PaintThing.paint(new Line(e.start, e.end), g2, ma);
                PaintThing.paint(new Line(e.next.start, e.next.end), g2, ma);
            }
        // for ( HalfEdge e : f.edges() ) {
        // PaintThing.drawArrow( g2, ma, e.line(), 5 );
        // }
        }
    if (false)
        for (HalfFace f : o.faces) for (HalfEdge e : f.edges()) {
            if (e.face != f || (e.over != null && (e.over.over != e || !o.faces.contains(e.over.face))) || e.face == null || e.start == null || e.end == null || e.next == null) {
                g2.setColor(Color.red);
                g2.setStroke(new BasicStroke(4));
                PaintThing.paint(e.line(), g2, ma);
            }
        }
}
Also used : BasicStroke(java.awt.BasicStroke) Line(org.twak.utils.Line) Color(java.awt.Color) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) Polygon(java.awt.Polygon) SuperFace(org.twak.tweed.gen.SuperFace) SuperEdge(org.twak.tweed.gen.SuperEdge) HalfMesh2(org.twak.utils.geom.HalfMesh2)

Aggregations

Line (org.twak.utils.Line)59 Point2d (javax.vecmath.Point2d)38 ArrayList (java.util.ArrayList)25 SuperLine (org.twak.viewTrace.SuperLine)22 List (java.util.List)16 Point3d (javax.vecmath.Point3d)14 HashSet (java.util.HashSet)13 LinearForm (org.twak.utils.geom.LinearForm)13 HashMap (java.util.HashMap)12 Map (java.util.Map)11 Set (java.util.Set)11 HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)11 HalfFace (org.twak.utils.geom.HalfMesh2.HalfFace)11 Collectors (java.util.stream.Collectors)10 Vector2d (javax.vecmath.Vector2d)10 Iterator (java.util.Iterator)9 Vector3d (javax.vecmath.Vector3d)9 Tweed (org.twak.tweed.Tweed)8 TweedSettings (org.twak.tweed.TweedSettings)8 MFPoint (org.twak.tweed.gen.FeatureCache.MFPoint)8