Search in sources :

Example 1 with ImageFeatures

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;
}
Also used : DumbCluster1D(org.twak.utils.DumbCluster1D) Cache2(org.twak.utils.Cache2) OptionalDouble(java.util.OptionalDouble) HashMap(java.util.HashMap) CountThings(org.twak.utils.collections.CountThings) Pair(org.twak.utils.Pair) TreeSet(java.util.TreeSet) MapMapList(org.twak.utils.collections.MapMapList) ArrayList(java.util.ArrayList) Arrayz(org.twak.utils.collections.Arrayz) HashSet(java.util.HashSet) Map(java.util.Map) Mathz(org.twak.utils.Mathz) Streamz(org.twak.utils.collections.Streamz) LinkedHashSet(java.util.LinkedHashSet) InAxDouble(org.twak.utils.streams.InAxDouble) Iterator(java.util.Iterator) ImageFeatures(org.twak.tweed.gen.FeatureCache.ImageFeatures) MultiMap(org.twak.utils.collections.MultiMap) Set(java.util.Set) Vector2d(javax.vecmath.Vector2d) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) Collectors(java.util.stream.Collectors) File(java.io.File) Cluster(org.twak.utils.DumbCluster1D.Cluster) Point2d(javax.vecmath.Point2d) List(java.util.List) DumbCluster1DImpl(org.twak.utils.DumbCluster1DImpl) Bounds(org.twak.utils.geom.DRectangle.Bounds) DRectangle(org.twak.utils.geom.DRectangle) Comparator(java.util.Comparator) Collections(java.util.Collections) Feature(org.twak.viewTrace.facades.MiniFacade.Feature) InAxDouble(org.twak.utils.streams.InAxDouble) ImageFeatures(org.twak.tweed.gen.FeatureCache.ImageFeatures) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) ArrayList(java.util.ArrayList)

Example 2 with ImageFeatures

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();
}
Also used : ImageFeatures(org.twak.tweed.gen.FeatureCache.ImageFeatures) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) XStream(com.thoughtworks.xstream.XStream) File(java.io.File)

Example 3 with ImageFeatures

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);
}
Also used : MiniFacade(org.twak.viewTrace.facades.MiniFacade) ImageFeatures(org.twak.tweed.gen.FeatureCache.ImageFeatures) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) ArrayList(java.util.ArrayList) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) SuperEdge(org.twak.tweed.gen.SuperEdge) SuperFace(org.twak.tweed.gen.SuperFace) SkelGen(org.twak.tweed.gen.skel.SkelGen) Line(org.twak.utils.Line) Point2d(javax.vecmath.Point2d) HalfMesh2(org.twak.utils.geom.HalfMesh2) Prof(org.twak.tweed.gen.Prof)

Example 4 with ImageFeatures

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();
}
Also used : MiniFacade(org.twak.viewTrace.facades.MiniFacade) DRectangle(org.twak.utils.geom.DRectangle) ImageFeatures(org.twak.tweed.gen.FeatureCache.ImageFeatures) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) Material(com.jme3.material.Material) Geometry(com.jme3.scene.Geometry) Vector2d(javax.vecmath.Vector2d) Spatial(com.jme3.scene.Spatial) MeshBuilder(org.twak.siteplan.jme.MeshBuilder) Vector3f(com.jme3.math.Vector3f)

Example 5 with ImageFeatures

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;
}
Also used : DumbCluster1D(org.twak.utils.DumbCluster1D) Cache2(org.twak.utils.Cache2) OptionalDouble(java.util.OptionalDouble) HashMap(java.util.HashMap) CountThings(org.twak.utils.collections.CountThings) Pair(org.twak.utils.Pair) TreeSet(java.util.TreeSet) MapMapList(org.twak.utils.collections.MapMapList) ArrayList(java.util.ArrayList) Arrayz(org.twak.utils.collections.Arrayz) HashSet(java.util.HashSet) Map(java.util.Map) Mathz(org.twak.utils.Mathz) Streamz(org.twak.utils.collections.Streamz) LinkedHashSet(java.util.LinkedHashSet) InAxDouble(org.twak.utils.streams.InAxDouble) Iterator(java.util.Iterator) ImageFeatures(org.twak.tweed.gen.FeatureCache.ImageFeatures) MultiMap(org.twak.utils.collections.MultiMap) Set(java.util.Set) Vector2d(javax.vecmath.Vector2d) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) Collectors(java.util.stream.Collectors) File(java.io.File) Cluster(org.twak.utils.DumbCluster1D.Cluster) Point2d(javax.vecmath.Point2d) List(java.util.List) DumbCluster1DImpl(org.twak.utils.DumbCluster1DImpl) Bounds(org.twak.utils.geom.DRectangle.Bounds) DRectangle(org.twak.utils.geom.DRectangle) Comparator(java.util.Comparator) Collections(java.util.Collections) Feature(org.twak.viewTrace.facades.MiniFacade.Feature) DRectangle(org.twak.utils.geom.DRectangle) Feature(org.twak.viewTrace.facades.MiniFacade.Feature) OptionalDouble(java.util.OptionalDouble) InAxDouble(org.twak.utils.streams.InAxDouble) Point2d(javax.vecmath.Point2d) MapMapList(org.twak.utils.collections.MapMapList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ImageFeatures (org.twak.tweed.gen.FeatureCache.ImageFeatures)6 MegaFeatures (org.twak.tweed.gen.FeatureCache.MegaFeatures)5 File (java.io.File)4 ArrayList (java.util.ArrayList)3 Point2d (javax.vecmath.Point2d)3 Vector2d (javax.vecmath.Vector2d)3 DRectangle (org.twak.utils.geom.DRectangle)3 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Map (java.util.Map)2 OptionalDouble (java.util.OptionalDouble)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2 Collectors (java.util.stream.Collectors)2 Cache2 (org.twak.utils.Cache2)2