Search in sources :

Example 1 with DRectangle

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

the class Regularizer method dimensionSpread.

private double dimensionSpread(List<FRect> found) {
    DRectangle tmp = new DRectangle(found.get(0));
    double width = 0, height = 0;
    for (DRectangle d : found) {
        width += d.width;
        height += d.height;
        tmp.setFrom(d.union(tmp));
    }
    width /= found.size();
    height /= found.size();
    return Math.min(Math.abs(width - tmp.width) / width, Math.abs(height - tmp.height) / height);
}
Also used : DRectangle(org.twak.utils.geom.DRectangle)

Example 2 with DRectangle

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

the class GreebleSkel method findRect.

protected DRectangle findRect(Loop<Point2d> rect) {
    double[] bounds = Loopz.minMax2d(rect);
    DRectangle all = new DRectangle(bounds[0], bounds[2], bounds[1] - bounds[0], bounds[3] - bounds[2]);
    return all;
}
Also used : DRectangle(org.twak.utils.geom.DRectangle)

Example 3 with DRectangle

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

the class Pix2Pix method pix2pix.

public static void pix2pix(MiniFacade toEdit, PlanSkeleton skel, Output output, SuperFace sf, Runnable update) {
    BufferedImage bi = new BufferedImage(512, 256, BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g = (Graphics2D) bi.getGraphics();
    DRectangle bounds = new DRectangle(256, 0, 256, 256);
    // g.setColor( new Color (0, 0, 255 ) );
    // g.fillRect( 255, 0, 255, 255 );
    g.setColor(new Color(0, 48, 255));
    g.fillRect(256, 0, 256, 255);
    DRectangle mini = toEdit.getAsRect();
    cmpRects(toEdit, g, bounds, mini, new Color(0, 207, 255), Feature.DOOR);
    cmpRects(toEdit, g, bounds, mini, new Color(0, 129, 250), Feature.WINDOW);
    cmpRects(toEdit, g, bounds, mini, new Color(255, 80, 0), Feature.MOULDING);
    cmpRects(toEdit, g, bounds, mini, new Color(32, 255, 224), Feature.CORNICE);
    cmpRects(toEdit, g, bounds, mini, new Color(109, 254, 149), Feature.SILL);
    cmpRects(toEdit, g, bounds, mini, new Color(175, 0, 0), Feature.SHOP);
    String name = System.nanoTime() + "";
    try {
        ImageIO.write(bi, "png", new File("/home/twak/code/pix2pix-interactive/input/test/" + name + ".png"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    long startTime = System.currentTimeMillis();
    do {
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        File[] fz = new File("/home/twak/code/pix2pix-interactive/output/").listFiles();
        if (fz.length > 0) {
            for (File f : fz) {
                String dest;
                try {
                    new File(Tweed.SCRATCH).mkdirs();
                    // File texture = new File (f, "images/"+name+"_real_A.png");
                    File texture = new File(f, "images/" + name + "_fake_B.png");
                    if (texture.exists() && texture.length() > 0) {
                        FileOutputStream fos = new FileOutputStream(Tweed.DATA + "/" + (dest = "scratch/" + name + ".png"));
                        Files.copy(texture.toPath(), fos);
                        fos.flush();
                        fos.close();
                        if (dest != null)
                            toEdit.texture = dest;
                        texture.delete();
                        break;
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        }
    } while (System.currentTimeMillis() - startTime < 1000);
    update.run();
}
Also used : DRectangle(org.twak.utils.geom.DRectangle) Color(java.awt.Color) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 4 with DRectangle

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

the class Pix2Pix method cmpRects.

public static void cmpRects(MiniFacade toEdit, Graphics2D g, DRectangle bounds, DRectangle mini, Color col, Feature... features) {
    for (FRect r : toEdit.getRects(features)) {
        DRectangle w = bounds.scale(mini.normalize(r));
        w.y = bounds.getMaxY() - w.y - w.height;
        g.setColor(col);
        g.fillRect((int) w.x, (int) w.y, (int) w.width, (int) w.height);
    }
}
Also used : DRectangle(org.twak.utils.geom.DRectangle)

Example 5 with DRectangle

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

the class Grid method paint.

@Override
public void paint(Graphics2D g, PanMouseAdaptor ma) {
    g.setColor(Color.green);
    for (Id c : x) {
        Line l = new Line(c.value, 0, c.value, 1);
        PaintThing.paint(l, g, ma);
    }
    g.setColor(Color.blue);
    for (Map.Entry<Griddable, DRectangle> e : findPositions().entrySet()) {
        // DRectangle d2 = new DRectangle( e.getValue() );
        // d2.y = d2.y - d2.height;
        PaintThing.paint(e.getValue(), g, ma);
    }
}
Also used : Line(org.twak.utils.Line) DRectangle(org.twak.utils.geom.DRectangle) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DRectangle (org.twak.utils.geom.DRectangle)21 Point2d (javax.vecmath.Point2d)7 ArrayList (java.util.ArrayList)6 List (java.util.List)4 MeshBuilder (org.twak.siteplan.jme.MeshBuilder)4 Feature (org.twak.viewTrace.facades.MiniFacade.Feature)4 Vector3f (com.jme3.math.Vector3f)3 File (java.io.File)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 Matrix4d (javax.vecmath.Matrix4d)3 Point3d (javax.vecmath.Point3d)3 Vector2d (javax.vecmath.Vector2d)3 Vector3d (javax.vecmath.Vector3d)3 Griddable (org.twak.viewTrace.facades.Grid.Griddable)3 Material (com.jme3.material.Material)2 Geometry (com.jme3.scene.Geometry)2 Map (java.util.Map)2 OptionalDouble (java.util.OptionalDouble)2 Window (org.twak.tweed.gen.WindowGen.Window)2