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);
}
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;
}
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();
}
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);
}
}
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);
}
}
Aggregations