Search in sources :

Example 11 with Line

use of org.twak.utils.Line 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 12 with Line

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

the class ImagePlaneGen method rotateByAngle.

public ImagePlaneGen rotateByAngle(double deltaAngle, double distance) {
    Line nLine = new Line(new Point2d(a.x, a.z), new Point2d(b.x, b.z));
    Point2d cen = nLine.fromPPram(0.5);
    double angle = nLine.aTan2() + deltaAngle;
    double len = nLine.length() / 2;
    Vector2d dir = new Vector2d(-Math.cos(angle) * len, -Math.sin(angle) * len);
    Point2d start = new Point2d(cen), end = new Point2d(cen);
    start.add(dir);
    end.sub(dir);
    ImagePlaneGen out = new ImagePlaneGen(this);
    out.a.set((float) start.x, a.y, (float) start.y);
    out.b.set((float) end.x, b.y, (float) end.y);
    out.calcUV();
    return out;
}
Also used : Line(org.twak.utils.Line) Vector2d(javax.vecmath.Vector2d) Point2d(javax.vecmath.Point2d)

Example 13 with Line

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

the class ProfileGen method processMegaFaces.

private void processMegaFaces() {
    addOnJmeThread.clear();
    if (faces == null || faces.isEmpty()) {
        JOptionPane.showMessageDialog(tweed.frame(), "Failed to cluster facades");
        return;
    }
    Node mfNode = new Node();
    // Node cProfileNode = new Node();
    Random randy = new Random(2);
    dbgProfileLookup.clear();
    final boolean DBG = true;
    computeProfiles(faces);
    int i = 0;
    for (MegaFacade mf : faces) {
        // if (i == 4)
        {
            System.out.println("building profiles over megafacade " + i + "/" + faces.size());
            ColorRGBA dispCol = new ColorRGBA(color.getRed() * randy.nextFloat() / 255f, color.getGreen() * randy.nextFloat() / 255f, color.getBlue() * randy.nextFloat() / 255f, 1);
            if (DBG) {
                List<Line3d> dbg = new ArrayList();
                for (int d : mf.keySet()) {
                    for (Line l2 : mf.get(d)) {
                        Line3d oLine = new Line3d(l2.start.x, getHeight(d), l2.start.y, l2.end.x, getHeight(d), l2.end.y);
                        dbg.add(oLine);
                    }
                }
                mfNode.attachChild(Jme3z.lines(tweed.getAssetManager(), dbg, dispCol, 0.1f, true));
                Line l2 = mf.origin.line;
                Line3d oLine = new Line3d(l2.start.x, getHeight(mf.origin.height), l2.start.y, l2.end.x, getHeight(mf.origin.height), l2.end.y);
            // mfNode.attachChild( Jme3z.lines( tweed.getAssetManager(), Collections.singletonList( oLine ), dispCol, 0.5f, true ) );
            }
            {
                Line l3 = mf.origin.line;
                // if ( mf.profiles.values().stream().mapToDouble( p -> p.get( 0 ).y ).min().getAsDouble() > 8 )
                // continue;
                totalPlanLineLength += l3.length();
                Line3d oLine = new Line3d(l3.start.x, getHeight(mf.origin.height), l3.start.y, l3.end.x, getHeight(mf.origin.height), l3.end.y);
                List<SuperLine> pLines = Prof.findProfileLines(mf.profiles.values(), oLine);
                for (int pi = 0; pi < pLines.size(); pi++) {
                    SuperLine profileLine = pLines.get(pi);
                    // if ( distance ( gis, profileLine.start ) > 2 || distance ( gis, profileLine.end ) > 2 )
                    // continue;
                    Node profileNode = new Node();
                    // dispCol = new ColorRGBA( randy.nextFloat(), randy.nextFloat(), randy.nextFloat(), 1 );
                    MegaFacade pMF = mf.moveTo(profileLine);
                    if (pi >= 1) {
                        Line newOrigin = null;
                        double bestDist = Double.MAX_VALUE;
                        Point3d plCen = Pointz.to3(profileLine.fromPPram(0.5), getHeight(mf.hExtentMin));
                        for (int li = mf.hExtentMin; li <= mf.hExtentMax; li++) for (Line l : mf.get(li)) {
                            double dist = Pointz.to3(l.fromPPram(0.5), getHeight(li)).distance(plCen);
                            if (dist < bestDist) {
                                newOrigin = l;
                                bestDist = dist;
                            }
                        }
                        if (newOrigin != null) {
                            pMF.setOrigin(new LineAtHeight(pMF.hExtentMin, newOrigin));
                            pMF.computeProfiles(ProfileGen.this);
                        }
                    }
                    profileLine.setMega(pMF);
                    footprint.add(profileLine);
                    dbgProfileLookup.put(i++, pMF);
                    if (DBG) {
                        profileNode.attachChild(Jme3z.lines(tweed.getAssetManager(), Collections.singletonList(new Line3d(profileLine.start.x, 0, profileLine.start.y, profileLine.end.x, 0, profileLine.end.y)), dispCol, 0.3f, true));
                        render(new ArrayList<>(pMF.profiles.values()), tweed, dispCol, profileNode);
                        // List<Prof> cleans = new ArrayList<>();
                        // for ( Prof p : pMF.profiles.values() ) {
                        // p.render( tweed, profileNode, dispCol, 1f );
                        // cleans.add( new Prof( p ).parameterize() );
                        // .render( tweed, cProfileNode, dispCol.add( ColorRGBA.Gray ), 1f );
                        // 
                        // }
                        // render ( cleans, tweed, cProfileNode );
                        profileNode.attachChild(Jme3z.lines(tweed.getAssetManager(), Collections.singletonList(oLine), dispCol, 0.3f, true));
                        profileNode.setUserData(ProfileGen.class.getSimpleName(), i);
                        addOnJmeThread.add(profileNode);
                    }
                }
            }
        }
    }
    if (DBG)
        tweed.frame.addGen(new JmeGen("horizontal lines", tweed, mfNode), false);
    // tweed.frame.addGen( new JmeGen( "clean profiles", tweed, cProfileNode ), false );
    calculateOnJmeThread();
}
Also used : Node(com.jme3.scene.Node) ArrayList(java.util.ArrayList) CullHint(com.jme3.scene.Spatial.CullHint) Line3d(org.twak.utils.geom.Line3d) Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine) Random(java.util.Random) ColorRGBA(com.jme3.math.ColorRGBA) Point3d(javax.vecmath.Point3d) SuperLine(org.twak.viewTrace.SuperLine) List(java.util.List) ArrayList(java.util.ArrayList)

Example 14 with Line

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

the class CutHoles method find.

public static Point3d find(Point2d pt, Map<Point2d, Point3d> root, Map<Point2d, Line> created) {
    if (root.containsKey(pt))
        return root.get(pt);
    else {
        Line l = created.get(pt);
        Point3d a = find(l.start, root, created), b = find(l.end, root, created);
        return new Line3d(a, b).fromPPram(l.findPPram(pt));
    }
}
Also used : Line(org.twak.utils.Line) Point3d(javax.vecmath.Point3d) Line3d(org.twak.utils.geom.Line3d)

Example 15 with Line

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

the class GBias method getAngle.

/**
 * local bias
 */
public Double getAngle(Line line, Point2d cen) {
    final double PI8 = Math.PI / 8;
    DRectangle r = new DRectangle(line);
    r.grow(expand);
    Collection<Longer> res = tree.queryRange(r);
    double bestScore = -Double.MAX_VALUE;
    Double bestAngle = null;
    for (AxisAlignedBoundingBox aabb : res) {
        Line gis = ((Longer) aabb).line;
        double len = gis.length();
        // gis.distance( line );
        double dist = gis.fromPPram(0.5).distance(line.fromPPram(0.5));
        if (dist < len * expand) {
            double angle = line.absAngle(gis);
            if (angle < PI8) {
                double score = (PI8 - angle) / dist;
                if (score > bestScore) {
                    bestAngle = gis.aTan2();
                    bestScore = score;
                }
            } else if (Mathz.inRangeTol(angle, Mathz.PI2, PI8)) {
                double score = 0.2 * (PI8 - angle) / dist;
                if (score > bestScore) {
                    gis = new Line(new Point2d(gis.start.y, -gis.start.x), new Point2d(gis.end.y, -gis.end.x));
                    if (gis.absAngle(line) > PI8)
                        gis = gis.reverse();
                    bestAngle = gis.aTan2();
                    bestScore = score;
                }
            }
        }
    }
    if (bestAngle != null)
        return bestAngle;
    else
        return null;
}
Also used : Line(org.twak.utils.Line) QLine(org.twak.viewTrace.QuadTree.QLine) AxisAlignedBoundingBox(org.twak.viewTrace.QuadTree.AxisAlignedBoundingBox) DRectangle(org.twak.utils.geom.DRectangle) Point2d(javax.vecmath.Point2d)

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