Search in sources :

Example 41 with Line

use of org.twak.utils.Line in project chordatlas by twak.

the class LineSoup method partition.

public List<Set<Line>> partition(double d) {
    List<Set<Line>> out = new ArrayList();
    for (Line l : all) {
        Set<Set<Line>> closeSets = new HashSet<>();
        part: for (Set<Line> part : out) for (Line pl : part) if (pl.distance(l) < d) {
            closeSets.add(part);
            continue part;
        }
        Set<Line> best = null;
        if (closeSets.isEmpty()) {
            best = new HashSet<>();
            out.add(best);
        } else {
            Iterator<Set<Line>> wtf = closeSets.iterator();
            best = wtf.next();
            while (wtf.hasNext()) {
                Set<Line> togo = wtf.next();
                best.addAll(togo);
                out.remove(togo);
            }
        }
        best.add(l);
    }
    return out;
}
Also used : Line(org.twak.utils.Line) QLine(org.twak.viewTrace.QuadTree.QLine) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 42 with Line

use of org.twak.utils.Line in project chordatlas by twak.

the class SkelGen method findRange.

private static double[] findRange(SuperEdge se, Point2d s, Point2d e, Line backup) {
    Line mf;
    if (se.mini.isEmpty() || se.mini.get(0).imageFeatures == null) {
        if (backup == null)
            return null;
        else
            mf = backup;
    } else
        // todo: bad place for this method.
        mf = se.mini.get(0).imageFeatures.mega.megafacade;
    double mfL = mf.length();
    return new double[] { mf.findPPram(s) * mfL, mf.findPPram(e) * mfL };
}
Also used : Line(org.twak.utils.Line)

Example 43 with Line

use of org.twak.utils.Line in project chordatlas by twak.

the class GreebleSkel method createMesh.

public void createMesh(Output output) {
    float[] roofColor = new float[] { 0.3f, 0.3f, 0.3f, 1 }, wallColor = new float[] { 228 / 255f, 223 / 255f, 206 / 255f, 1.0f };
    if (output.faces == null)
        return;
    double bestWallArea = 0, bestRoofArea = 0;
    for (Face f : output.faces.values()) {
        double area = Loopz.area3(f.getLoopL());
        Tag t = getTag(f.profile, RoofTag.class);
        if (t != null && area > bestRoofArea && ((RoofTag) t).color != null) {
            roofColor = ((RoofTag) t).color;
            bestRoofArea = area;
        }
        t = getTag(f.profile, WallTag.class);
        if (t != null && area > bestWallArea && ((WallTag) t).color != null) {
            wallColor = ((WallTag) t).color;
            bestWallArea = area;
        }
    }
    greebleGrid = new GreebleGrid(tweed, mbs = new MMeshBuilderCache());
    output.addNonSkeletonSharedEdges(new RoofTag(roofColor));
    edges(output, roofColor);
    for (List<Face> chain : Campz.findChains(output)) {
        // for ( Face f : output.faces.values() )
        // mbs.get(roofColor).add3d( Loopz.insertInnerEdges( f.getLoopL() ), zToYup );
        Optional<Tag> opt = chain.stream().flatMap(f -> f.profile.stream()).filter(tag -> tag instanceof WallTag).findAny();
        WallTag wt = null;
        Set<QuadF> features = new HashSet<>();
        MiniFacade mf = null;
        if (opt.isPresent() && (wt = (WallTag) opt.get()).miniFacade != null) {
            MiniFacade mf2 = new MiniFacade(wt.miniFacade);
            Line facadeLine;
            {
                Edge e = chain.get(0).edge;
                // we might rotate the facade to apply a set of features to a different side of the building.
                facadeLine = new Line(e.end.x, e.end.y, e.start.x, e.start.y);
            }
            if (TweedSettings.settings.snapFacadeWidth) {
                // move/scale mf horizontally from mean-image-location to mesh-facade-location
                double[] meshSE = findSE(wt.miniFacade, facadeLine, chain);
                mf2.scaleX(meshSE[0], meshSE[1]);
            }
            // find window locations in 3 space
            mf2.rects.values().stream().flatMap(f -> f.stream()).map(r -> new QuadF(r, facadeLine)).forEach(q -> features.add(q));
            mf = mf2;
        }
        for (Face f : chain) {
            face(f, mf, features, roofColor, wallColor);
        }
        for (QuadF w : features) if ((w.original.f == Feature.WINDOW || w.original.f == Feature.SHOP) && w.foundAll()) {
            greebleGrid.createDormerWindow(w, mbs.WOOD, mbs.GLASS, (float) wt.sillDepth, (float) wt.sillHeight, (float) wt.corniceHeight, 0.6, 0.9);
        }
        // for ( String mName : mbs.cache.keySet() )
        // for (float[] mCol : mbs.cache.get( mName ).keySet() )
        // node.attachChild( mb2Geom( output, chain, mName, mCol ) );
        greebleGrid.attachAll(node, chain, output, new ClickMe() {

            @Override
            public void clicked(Object data) {
                try {
                    SwingUtilities.invokeAndWait(new Runnable() {

                        @Override
                        public void run() {
                            selected(output, node, findSuperEdge(output, chain));
                        }
                    });
                } catch (Throwable th) {
                    th.printStackTrace();
                }
            }
        });
    }
}
Also used : LinearForm3D(org.twak.utils.geom.LinearForm3D) PlanSkeleton(org.twak.siteplan.campskeleton.PlanSkeleton) Matrix4d(javax.vecmath.Matrix4d) ClickMe(org.twak.tweed.ClickMe) Tag(org.twak.camp.Tag) Vector3d(javax.vecmath.Vector3d) Bar(org.twak.camp.ui.Bar) Tweed(org.twak.tweed.Tweed) ArrayList(java.util.ArrayList) TweedSettings(org.twak.tweed.TweedSettings) HashSet(java.util.HashSet) SETag(org.twak.tweed.gen.skel.SETag) Loop(org.twak.utils.collections.Loop) Node(com.jme3.scene.Node) SwingUtilities(javax.swing.SwingUtilities) Pointz(org.twak.tweed.gen.Pointz) Mathz(org.twak.utils.Mathz) SuperEdge(org.twak.tweed.gen.SuperEdge) Point3d(javax.vecmath.Point3d) ColumnProperties(org.twak.siteplan.campskeleton.PlanSkeleton.ColumnProperties) LoopL(org.twak.utils.collections.LoopL) Iterator(java.util.Iterator) Output(org.twak.camp.Output) Edge(org.twak.camp.Edge) Line(org.twak.utils.Line) Set(java.util.Set) MeshBuilder(org.twak.siteplan.jme.MeshBuilder) LinearForm(org.twak.utils.geom.LinearForm) Collectors(java.util.stream.Collectors) LPoint2d(org.twak.viewTrace.facades.GreebleHelper.LPoint2d) Loopz(org.twak.utils.collections.Loopz) Point2d(javax.vecmath.Point2d) LPoint3d(org.twak.viewTrace.facades.GreebleHelper.LPoint3d) List(java.util.List) Loopable(org.twak.utils.collections.Loopable) DRectangle(org.twak.utils.geom.DRectangle) Optional(java.util.Optional) Face(org.twak.camp.Output.Face) Feature(org.twak.viewTrace.facades.MiniFacade.Feature) ClickMe(org.twak.tweed.ClickMe) Line(org.twak.utils.Line) Tag(org.twak.camp.Tag) SETag(org.twak.tweed.gen.skel.SETag) Face(org.twak.camp.Output.Face) SuperEdge(org.twak.tweed.gen.SuperEdge) Edge(org.twak.camp.Edge) HashSet(java.util.HashSet)

Example 44 with Line

use of org.twak.utils.Line in project chordatlas by twak.

the class GreebleSkel method setToHeight.

private static PtInChain setToHeight(List<Point2d> chain, boolean left, double x2, double y2) {
    double bestX = chain.get(0).x;
    for (int i = 1; i < chain.size(); i++) {
        Point2d p = chain.get(i - 1), n = chain.get(i);
        bestX = left ? Math.max(p.x, bestX) : Math.min(p.x, bestX);
        PtInChain first = new PtInChain(new Point2d(n), i, 0);
        first.x = bestX;
        if (Math.abs(n.y - y2) < 0.001) {
            first.x = left ? Math.max(n.x, first.x) : Math.min(n.x, first.x);
            return first;
        }
        Line pn = new Line(p, n);
        if (n.y > y2) {
            Point2d sec = new LinearForm(pn).intersect(new LinearForm(0, 1, y2));
            if (sec == null)
                return first;
            sec.x = left ? Math.max(bestX, sec.x) : Math.min(bestX, sec.x);
            return new PtInChain(sec, i - 1, pn.findPPram(sec));
        }
    }
    return null;
}
Also used : Line(org.twak.utils.Line) LPoint2d(org.twak.viewTrace.facades.GreebleHelper.LPoint2d) Point2d(javax.vecmath.Point2d) LinearForm(org.twak.utils.geom.LinearForm)

Example 45 with Line

use of org.twak.utils.Line in project chordatlas by twak.

the class GMLReader method main1.

public static void main1(String[] args) {
    Graph2D g2 = readGMLToGraph(new File("/home/twak/data/langham/langham.gml"));
    g2.removeInnerEdges();
    Point2d offset = new Point2d();
    int count = 0;
    for (Point2d p : g2.map.keySet()) for (Line l : g2.get(p)) {
        count++;
        offset.add(l.start);
        System.out.println(l);
    }
    offset.scale(1. / count);
    System.out.println("offset is " + offset);
    AffineTransform at = AffineTransform.getScaleInstance(-1, 1);
    at.concatenate(AffineTransform.getTranslateInstance(-offset.x, -offset.y));
    g2 = g2.apply(at);
    UnionWalker uw = new UnionWalker();
    for (Point2d a : g2.map.keySet()) {
        for (Line l : g2.get(a)) {
            uw.addEdge(l.start, l.end);
        }
    }
    LoopL<Point2d> out = uw.findAll();
    ObjDump obj = new ObjDump();
    for (Loop<Point2d> loop : out) {
        List<Point3d> pts = new ArrayList();
        for (Point2d pt : loop) pts.add(new Point3d(pt.x, 0, pt.y));
        obj.addFace(pts);
    }
    obj.dump(new File(Tweed.SCRATCH + "langham.obj"));
}
Also used : ArrayList(java.util.ArrayList) Graph2D(org.twak.utils.geom.Graph2D) Line(org.twak.utils.Line) Point2d(javax.vecmath.Point2d) ObjDump(org.twak.utils.geom.ObjDump) Point3d(javax.vecmath.Point3d) AffineTransform(java.awt.geom.AffineTransform) UnionWalker(org.twak.utils.geom.UnionWalker) File(java.io.File)

Aggregations

Line (org.twak.utils.Line)59 Point2d (javax.vecmath.Point2d)38 ArrayList (java.util.ArrayList)25 SuperLine (org.twak.viewTrace.SuperLine)22 List (java.util.List)16 Point3d (javax.vecmath.Point3d)14 HashSet (java.util.HashSet)13 LinearForm (org.twak.utils.geom.LinearForm)13 HashMap (java.util.HashMap)12 Map (java.util.Map)11 Set (java.util.Set)11 HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)11 HalfFace (org.twak.utils.geom.HalfMesh2.HalfFace)11 Collectors (java.util.stream.Collectors)10 Vector2d (javax.vecmath.Vector2d)10 Iterator (java.util.Iterator)9 Vector3d (javax.vecmath.Vector3d)9 Tweed (org.twak.tweed.Tweed)8 TweedSettings (org.twak.tweed.TweedSettings)8 MFPoint (org.twak.tweed.gen.FeatureCache.MFPoint)8