Search in sources :

Example 1 with MegaFeatures

use of org.twak.tweed.gen.FeatureCache.MegaFeatures 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 MegaFeatures

use of org.twak.tweed.gen.FeatureCache.MegaFeatures 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 MegaFeatures

use of org.twak.tweed.gen.FeatureCache.MegaFeatures in project chordatlas by twak.

the class GurobiSkelSolver method buildMini.

private void buildMini() throws GRBException {
    Cache<HalfEdge, GRBLinExpr> isMiniExpr = new Cach<HalfMesh2.HalfEdge, GRBLinExpr>(he -> new GRBLinExpr());
    if (minis == null)
        return;
    for (MegaFeatures mf : minis.keySet()) {
        List<MiniPtCluster> clusterVars = new ArrayList<>();
        mega2clusters.put(mf, clusterVars);
        double mLen = mf.megafacade.length();
        DumbCluster1D<MFPoint> clusters = clusterMinis(mf, minis);
        for (DumbCluster1D.Cluster<MFPoint> d : clusters) {
            // for each cluster, we pick a single MFPoint as the boundary
            MiniPtCluster miniPtVar = new MiniPtCluster();
            Cache<HalfEdge, GRBLinExpr> isEdgeBind = new Cach<HalfMesh2.HalfEdge, GRBLinExpr>(he -> new GRBLinExpr());
            GRBLinExpr selectHE = new GRBLinExpr();
            boolean one = false;
            for (MFPoint pt : d.things) {
                MiniSelectEdge miniSelectEdge = new MiniSelectEdge();
                miniPtVar.put(pt, miniSelectEdge);
                List<HalfEdge> nearCorners = findNear(mf.megafacade, pt, mesh);
                try {
                    for (HalfEdge he : nearCorners) {
                        GRBVar heVar = model.addVar(0.0, 1.0, 0, GRB.BINARY, MINI_TO_EDGE);
                        miniSelectEdge.edge.put(he, heVar);
                        selectHE.addTerm(1, heVar);
                        double cost = he.end.distance(pt);
                        if (he.over != null) {
                            if (pt.right != null)
                                cost += Math.abs(pt.right.height - ((SuperFace) he.face).height);
                            if (pt.left != null)
                                cost += Math.abs(pt.left.height - ((SuperFace) he.over.face).height);
                            isEdgeBind.get(he).addTerm(1, heVar);
                        } else
                            // bonus for being on a corner;
                            cost -= totalEdgeLength * 0.1;
                        target.addTerm(cost, heVar);
                        isMiniExpr.get(he).addTerm(1, heVar);
                        one = true;
                    }
                } catch (Throwable th) {
                    th.printStackTrace();
                }
            }
            if (one) {
                clusterVars.add(miniPtVar);
                model.addConstr(selectHE, GRB.EQUAL, 1, "pick one near " + d.things.iterator().next());
            } else
                print("warning skipping minifacade loction " + d.things.size());
            for (HalfEdge he : isEdgeBind.cache.keySet()) model.addConstr(isEdgeBind.get(he), GRB.EQUAL, edgeInfo.get(he).isEdge, "minifacade boundary must terminate on edge " + he);
            miniPtVar.mean = mf.megafacade.fromPPram(d.mean / mLen);
        }
    }
    double penalty = totalEdgeLength * 0.1;
    for (HalfEdge he : edges) {
        if (he.over != null && he.next.over == null) {
            // edge comes to boundary without minifacade --> penalty
            OptionalDouble miniDist = minis.keySet().stream().map(mf -> mf.megafacade).mapToDouble(line -> line.distance(he.end, true)).min();
            if (!miniDist.isPresent() || miniDist.getAsDouble() > 4)
                continue;
            EdgeVars ei = edgeInfo.get(he);
            ei.edgeNoMini = model.addVar(0.0, 1.0, 0, GRB.BINARY, EDGE_NO_MINI);
            if (isMiniExpr.cache.containsKey(he)) {
                ei.isMini = model.addVar(0.0, 1.0, 0, GRB.BINARY, IS_MINI);
                GRBLinExpr is = isMiniExpr.get(he);
                /* ei.isMini might take 0 or positive integer... assume it's below 10 (0.1 = 1/10) */
                model.addConstr(ei.isMini, GRB.LESS_EQUAL, is, "is minifacade on edge " + he);
                model.addConstr(scale(0.1, is), GRB.LESS_EQUAL, ei.isMini, "is minifacade on edge " + he);
                GRBLinExpr expr = new GRBLinExpr();
                expr.addTerm(1, ei.isEdge);
                expr.addTerm(1, ei.isMini);
                model.addConstr(ei.edgeNoMini, GRB.LESS_EQUAL, expr, null);
                expr = new GRBLinExpr();
                expr.addTerm(1, ei.edgeNoMini);
                expr.addTerm(1, ei.isMini);
                model.addConstr(expr, GRB.LESS_EQUAL, 1, null);
                expr = new GRBLinExpr();
                expr.addTerm(1, ei.isEdge);
                expr.addTerm(-1, ei.isMini);
                model.addConstr(ei.edgeNoMini, GRB.GREATER_EQUAL, expr, null);
            } else {
                // no mini, but easier debug
                model.addConstr(ei.edgeNoMini, GRB.EQUAL, ei.isEdge, null);
            }
            target.addTerm(penalty, ei.edgeNoMini);
        }
    }
}
Also used : Color(java.awt.Color) GRBQuadExpr(gurobi.GRBQuadExpr) DumbCluster1D(org.twak.utils.DumbCluster1D) GRBException(gurobi.GRBException) Cache2(org.twak.utils.Cache2) StringAttr(gurobi.GRB.StringAttr) OptionalDouble(java.util.OptionalDouble) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) HashMap(java.util.HashMap) Random(java.util.Random) Cach(org.twak.utils.Cach) Tweed(org.twak.tweed.Tweed) ArrayList(java.util.ArrayList) TweedSettings(org.twak.tweed.TweedSettings) HashSet(java.util.HashSet) GRBModel(gurobi.GRBModel) Map(java.util.Map) Cache(org.twak.utils.Cache) Mathz(org.twak.utils.Mathz) PaintThing(org.twak.utils.PaintThing) ProgressMonitor(javax.swing.ProgressMonitor) GRBVar(gurobi.GRBVar) Iterator(java.util.Iterator) ImageFeatures(org.twak.tweed.gen.FeatureCache.ImageFeatures) GRBLinExpr(gurobi.GRBLinExpr) MultiMap(org.twak.utils.collections.MultiMap) Line(org.twak.utils.Line) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) Set(java.util.Set) HalfMesh2(org.twak.utils.geom.HalfMesh2) DoubleAttr(gurobi.GRB.DoubleAttr) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) LinearForm(org.twak.utils.geom.LinearForm) Collectors(java.util.stream.Collectors) File(java.io.File) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) Point2d(javax.vecmath.Point2d) List(java.util.List) Collections(java.util.Collections) GRBEnv(gurobi.GRBEnv) GRB(gurobi.GRB) GRBLinExpr(gurobi.GRBLinExpr) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) ArrayList(java.util.ArrayList) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) DumbCluster1D(org.twak.utils.DumbCluster1D) OptionalDouble(java.util.OptionalDouble) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) GRBVar(gurobi.GRBVar) Cach(org.twak.utils.Cach) HalfMesh2(org.twak.utils.geom.HalfMesh2)

Example 4 with MegaFeatures

use of org.twak.tweed.gen.FeatureCache.MegaFeatures 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 5 with MegaFeatures

use of org.twak.tweed.gen.FeatureCache.MegaFeatures 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)

Aggregations

MegaFeatures (org.twak.tweed.gen.FeatureCache.MegaFeatures)11 Point2d (javax.vecmath.Point2d)7 ImageFeatures (org.twak.tweed.gen.FeatureCache.ImageFeatures)7 File (java.io.File)6 ArrayList (java.util.ArrayList)6 Line (org.twak.utils.Line)6 HalfFace (org.twak.utils.geom.HalfMesh2.HalfFace)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Vector2d (javax.vecmath.Vector2d)5 MFPoint (org.twak.tweed.gen.FeatureCache.MFPoint)5 HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)5 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 MultiMap (org.twak.utils.collections.MultiMap)4 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 OptionalDouble (java.util.OptionalDouble)3 Set (java.util.Set)3