use of org.twak.viewTrace.facades.MiniFacade 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;
}
use of org.twak.viewTrace.facades.MiniFacade in project chordatlas by twak.
the class HouseTool method clickedOn.
@Override
public void clickedOn(Spatial target, Vector3f loc, Vector2f cursorPosition) {
// (Line) new XStream().fromXML( new File( "/home/twak/data/regent/March_30/congo/1/line.xml" ) ));
MegaFeatures mf = new MegaFeatures(new Line(0, 0, 10, 0));
// FeatureCache.readFeatures( new File( "/home/twak/data/regent/March_30/congo/1/0" ), mf );
ImageFeatures imf = new ImageFeatures();
imf.mega = mf;
double[] minMax = new double[] { 0, 15, 0, 25 };
HalfMesh2.Builder builder = new HalfMesh2.Builder(SuperEdge.class, SuperFace.class);
builder.newPoint(new Point2d(minMax[0] + loc.x, minMax[3] + loc.z));
builder.newPoint(new Point2d(minMax[1] + loc.x, minMax[3] + loc.z));
builder.newPoint(new Point2d(minMax[1] + loc.x, minMax[2] + loc.z));
builder.newPoint(new Point2d(minMax[0] + loc.x, minMax[2] + loc.z));
builder.newFace();
HalfMesh2 mesh = builder.done();
Prof p = new Prof();
p.add(new Point2d(0, 0));
p.add(new Point2d(0, 20));
p.add(new Point2d(-5, 25));
boolean first = true;
for (HalfFace f : mesh) {
for (HalfEdge e : f) {
SuperEdge se = (SuperEdge) e;
se.prof = p;
MiniFacade mini = newMini(imf, se.length());
if (true) {
se.addMini(mini);
se.proceduralFacade = mf;
se.toEdit = mini;
if (first)
se.addMini(mini);
}
first = false;
}
SuperFace sf = (SuperFace) f;
sf.maxProfHeights = new ArrayList();
sf.maxProfHeights.add(Double.valueOf(100));
sf.height = 100;
}
SkelGen sg = new SkelGen(mesh, tweed, null);
tweed.frame.addGen(sg, true);
}
use of org.twak.viewTrace.facades.MiniFacade in project chordatlas by twak.
the class WindowGen method calculate.
@Override
public void calculate() {
for (Spatial s : gNode.getChildren()) s.removeFromParent();
FeatureCache fg = tweed.features;
int i = 0;
if (fg != null) {
for (MegaFeatures mf : fg.getBlock(block.center).features) {
Vector3f along, up, in;
{
Vector2d mfl = mf.megafacade.dir();
mfl.normalize();
along = new Vector3f((float) mfl.x, 0, (float) mfl.y);
up = new Vector3f(0, 1, 0);
in = along.cross(up);
}
Vector3f mfStart = Jme3z.to(Pointz.to3(mf.megafacade.start));
for (ImageFeatures im : mf.features) {
MeshBuilder mb = new MeshBuilder();
float offset = (float) Math.random() * 5;
for (MiniFacade mini : im.miniFacades) {
for (DRectangle r : mini.rects.get(Feature.WINDOW)) {
Vector3f loc = new Vector3f(mfStart);
loc.addLocal(along.mult((float) r.x));
loc.addLocal(up.mult((float) r.y));
createWindow(mb, mb, new Window(loc.add(in.mult(offset + 0.4f)), along, up, r.width, r.height, 0.3, 0.4, 0.6));
}
if (!mini.rects.get(Feature.WINDOW).isEmpty()) {
Vector3f loc = new Vector3f(mfStart);
loc.addLocal(along.mult((float) mini.left)).addLocal(in.mult(offset));
mb.addCube(loc, up, along, in, (float) mini.height, (float) mini.width, 0.1f);
}
}
Geometry g = new Geometry(this.getClass().getSimpleName());
g.setMesh(mb.getMesh());
Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
mat.setColor("Diffuse", Jme3z.toJme(Rainbow.getColour(i)));
mat.setColor("Ambient", Jme3z.toJme(Rainbow.getColour(i)));
mat.setBoolean("UseMaterialColors", true);
g.setMaterial(mat);
i++;
gNode.attachChild(g);
}
}
}
super.calculate();
}
use of org.twak.viewTrace.facades.MiniFacade in project chordatlas by twak.
the class SolverState method miniPainter.
public ICanPaint miniPainter() {
return new ICanPaint() {
@Override
public void paint(Graphics2D g, PanMouseAdaptor ma) {
// for ( MegaFeatures f : SS.minis.keySet() ) {
//
// for ( MFPoint mfp : SS.minis.get( f ) ) {
// Line l = mfp.image.mega.megafacade;
//
// spreadImages( g, ma, l, mfp, Listz.from( mfp.left, mfp.right ) );
//
// }
// }
// if (SS.minis == null)
int brake = 100;
for (HalfFace f : mesh) {
for (HalfEdge e : f) {
if (e.over != null)
continue;
if (brake-- < 0)
break;
SuperEdge se = (SuperEdge) e;
if (se.mini == null)
continue;
List<MiniFacade> mfs = new ArrayList(se.mini);
// while (mfs .size() < 2)
// mfs.add(null);
spreadImages(g, ma, se.line(), se.line().fromPPram(0.5), mfs);
}
}
int i = 0;
if (minis != null)
for (MegaFeatures f : minis.keySet()) {
// PaintThing.paint (f.megafacade, g, ma);
DumbCluster1D<MFPoint> res = GurobiSkelSolver.clusterMinis(f, minis);
Vector2d dir = f.megafacade.dir();
Vector2d out = new Vector2d(dir);
out.set(-out.y, out.x);
out.scale(ma.toZoom(2) / out.length());
for (Cluster<MFPoint> c : res) {
g.setColor(Rainbow.getColour(i++));
for (MFPoint mfp : c.things) {
Point2d pt = new Point2d(mfp);
pt.add(out);
g.setStroke(new BasicStroke(0.2f));
PaintThing.paint(pt, g, ma);
g.setStroke(new BasicStroke(0.2f));
for (HalfEdge e : GurobiSkelSolver.findNear(f.megafacade, mfp, mesh)) g.drawLine(ma.toX(pt.x), ma.toY(pt.y), ma.toX(e.end.x), ma.toY(e.end.y));
if (mfp.selectedEdge != null) {
g.setStroke(new BasicStroke(2f));
g.drawLine(ma.toX(pt.x), ma.toY(pt.y), ma.toX(mfp.selectedEdge.end.x), ma.toY(mfp.selectedEdge.end.y));
}
}
}
}
g.setStroke(new BasicStroke(1));
}
private void spreadImages(Graphics2D g, PanMouseAdaptor ma, Line sel, Point2d cen, List<MiniFacade> mfs) {
Vector2d perp = sel.dir();
perp.set(-perp.y, perp.x);
perp.normalize();
for (int i = 0; i < mfs.size(); i++) {
MiniFacade mf = mfs.get(i);
Vector2d p2 = new Vector2d(perp);
p2.scale((i + 1) * 10);
p2.add(cen);
if (mf == null) {
g.setColor(Color.black);
g.fillRect(ma.toX(p2.x - 1), ma.toY(p2.y - 3), ma.toZoom(2), ma.toZoom(6));
continue;
}
double w = mf.width * 0.1;
double h = mf.height * 0.1;
mf.paintImage(g, ma, p2.x - w, p2.y - h, p2.x + w, p2.y + h);
}
}
};
}
use of org.twak.viewTrace.facades.MiniFacade in project chordatlas by twak.
the class HouseTool method newMini.
private MiniFacade newMini(ImageFeatures imf, double length) {
MiniFacade mini = new MiniFacade();
mini = new MiniFacade();
mini.width = length;
mini.height = 20;
mini.rects.put(Feature.WINDOW, new FRect(Feature.WINDOW, Math.random() * mini.width - 3, 5, 3, 3));
mini.color = new double[] { 0.8, 0.8, 0.3, 1 };
mini.imageFeatures = imf;
// "tex.jpg";
mini.texture = null;
// mini.spec = "spec.jpg";
return mini;
}
Aggregations