use of org.twak.tweed.gen.FeatureCache.ImageFeatures in project chordatlas by twak.
the class Regularizer method augmentWithTween.
private List<MiniFacade> augmentWithTween(List<MiniFacade> in, MegaFeatures megaFeatures) {
List<MiniFacade> out = new ArrayList<>(in);
if (megaFeatures == null)
return out;
if (in.isEmpty()) {
for (ImageFeatures iff : megaFeatures.features) for (MiniFacade mf : iff.miniFacades) if (lt - 3 < mf.left && mf.right() < rt + 3)
out.add(mf);
return out;
}
MegaFeatures mf = in.get(0).imageFeatures.mega;
double[] range = in.stream().flatMap(m -> Streamz.stream(m.left, m.left + m.width)).collect(new InAxDouble());
for (ImageFeatures imf : mf.features) for (MiniFacade mf2 : imf.miniFacades) if (mf2.left > range[0] && mf2.left + mf2.width < range[1] && !out.contains(mf2))
out.add(mf2);
return out;
}
use of org.twak.tweed.gen.FeatureCache.ImageFeatures in project chordatlas by twak.
the class AlignStandalone2d method setFolder.
private void setFolder(File folder) {
if (!folder.exists())
return;
MegaFeatures mf = new MegaFeatures((Line) new XStream().fromXML(new File(folder, "line.xml")));
features = new ArrayList<>();
File[] files = folder.listFiles();
Arrays.sort(files, FILE_COMPARATOR);
for (File f : files) if (f.isDirectory()) {
System.out.println(features.size() + " :: " + f.getName());
ImageFeatures imf = FeatureCache.readFeatures(f, mf);
if (imf != null)
features.add(imf);
}
imageSlide.setMaximum(features.size() - 1);
imageSlide.setValue(0);
plot();
}
use of org.twak.tweed.gen.FeatureCache.ImageFeatures 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.tweed.gen.FeatureCache.ImageFeatures 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.tweed.gen.FeatureCache.ImageFeatures in project chordatlas by twak.
the class Regularizer method combine.
private MiniFacade combine(List<MiniFacade> in) {
MiniFacade out = new MiniFacade();
out.left = lp;
out.width = rp - lp;
out.imageFeatures = in.get(0).imageFeatures;
out.color = new double[] { 0, 0, 0, 1 };
out.groundColor = new double[] { 0, 0, 0, 1 };
int gcc = 0;
for (MiniFacade mf : in) for (int i = 0; i < 3; i++) {
out.color[i] += mf.color[i];
if (mf.groundColor != null) {
out.groundColor[i] += mf.groundColor[i];
gcc++;
}
}
for (int i = 0; i < 3; i++) {
out.color[i] /= in.size();
if (gcc > 0)
out.groundColor[i] /= gcc;
}
Cache2<Outer, Integer, List<FRect>> corniceX = new ArrayCache2();
Cache2<Outer, Integer, List<FRect>> sillX = new ArrayCache2();
Cache2<Outer, Integer, List<FRect>> balX = new ArrayCache2();
out.height = in.stream().mapToDouble(mf -> mf.height).average().getAsDouble();
out.groundFloorHeight = in.stream().mapToDouble(mf -> mf.groundFloorHeight).average().getAsDouble();
for (int i = 0; i < ids; i++) {
int yay = 0, nay = 0;
int ii = i;
List<FRect> found = in.stream().map(mf -> m2i2r.get(mf, ii)).filter(x -> x != null).flatMap(l -> l.stream()).collect(Collectors.toList());
Point2d avg = found.stream().map(r -> r.getCenter()).collect(new Point2DMeanCollector());
for (MiniFacade mf : in) {
List<FRect> r = m2i2r.get(mf, i);
if (mf.contains(avg)) {
if (r.isEmpty()) {
if (mf.left + 3 < avg.x && mf.left + mf.width - 3 > avg.x)
nay++;
} else
yay++;
}
}
if (yay >= nay) {
// if we believe it exists add it as average of observed sizes
FRect o;
if (dimensionSpread(found) > 1.4) {
// scattered -> union (typically shop windows)
o = new FRect(found.get(0));
for (FRect n : found) o.setFrom(o.union(n));
} else
// about same size: average position: windows on a grid
o = new FRect(average(found.toArray(new FRect[found.size()])));
{
FRect t = found.get(0);
o.f = t.f;
o.id = i;
o.outer = null;
o.attachedHeight.get(Feature.SILL).d = averageAttached(o, Feature.SILL, found);
o.attachedHeight.get(Feature.CORNICE).d = averageAttached(o, Feature.CORNICE, found);
o.attachedHeight.get(Feature.BALCONY).d = averageAttached(o, Feature.BALCONY, found);
if (t.f == Feature.WINDOW || t.f == Feature.SHOP) {
for (FRect r : found) {
corniceX.get(r.outer, r.yi).add(o);
sillX.get(r.outer, r.yi).add(o);
balX.get(r.outer, r.yi).add(o);
}
}
}
out.rects.put(o.f, o);
}
}
spreadAttachedOverGrid(Feature.SILL, sillX);
spreadAttachedOverGrid(Feature.CORNICE, corniceX);
spreadAttachedOverGrid(Feature.BALCONY, balX);
fixOverlaps(out);
mergeRemoveSmall(out);
DRectangle mr = out.getAsRect();
// ensure everything is comfortably within the bounds
mr.width -= 0.2;
mr.x += 0.1;
for (Feature f : Feature.values()) {
// clip to all
Iterator<FRect> rit = out.rects.get(f).iterator();
while (rit.hasNext()) {
FRect r = rit.next();
DRectangle section = r.intersect(mr);
if (section == null || section.area() < 0.5)
rit.remove();
else
r.setFrom(section);
}
}
{
// door height
Double hf = Double.valueOf(0);
while (out.groundFloorHeight < 6 && ((hf = horizontalEmpty(out, out.groundFloorHeight)) != null)) out.groundFloorHeight = hf + 0.3;
if (out.groundFloorHeight >= 6)
// no ground floor!
out.groundFloorHeight = 0;
}
return out;
}
Aggregations