Search in sources :

Example 11 with SuperLine

use of org.twak.viewTrace.SuperLine in project chordatlas by twak.

the class SkelFootprint method buildFootprint.

public SolverState buildFootprint(List<Line> footprint, ProgressMonitor m, FeatureCache features, BlockGen blockGen) {
    MultiMap<MegaFeatures, MFPoint> minis = features == null ? null : features.createMinis(blockGen);
    Map<SuperEdge, double[]> profFit = new HashMap();
    HalfMesh2 mesh = boundMesh(footprint);
    globalProfs = null;
    Collections.sort(footprint, megaAreaComparator);
    for (Line l : footprint) {
        MegaFacade mf = ((SuperLine) l).getMega();
        if (mf.area < megaFacadeAreaThreshold)
            break;
        insert(mesh, l, 2, true, true);
        if (m.isCanceled())
            return null;
    }
    if (features != null)
        fractureOnFeatures(minis, footprint, mesh);
    m.setProgress(2);
    if (!TweedSettings.settings.useGreedyProfiles) {
        globalProfs = new ArrayList();
        findProfiles(footprint, globalProfs);
        calcProfFit(mesh, globalProfs, profFit, m);
    }
    if (FALSE && profMergeTol > 0)
        mergeOnProfiles(mesh, footprint);
    if (exitA)
        return new SolverState(mesh, minis, globalProfs, profFit, footprint);
    System.out.println("sampling...");
    for (HalfFace f : mesh) meanModeHeightColor(Loopz.from(f), (SuperFace) f, blockGen);
    pushHeightsToSmallFaces(mesh);
    for (HalfFace f : new ArrayList<>(mesh.faces)) {
        SuperFace sf = (SuperFace) f;
        if (sf.height < heightCutoff)
            sf.remove(mesh);
    }
    removeExposedFaces(mesh);
    return new SolverState(mesh, minis, globalProfs, profFit, footprint);
}
Also used : MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MegaFacade(org.twak.tweed.gen.ProfileGen.MegaFacade) ArrayList(java.util.ArrayList) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine) SuperLine(org.twak.viewTrace.SuperLine) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) HalfMesh2(org.twak.utils.geom.HalfMesh2)

Example 12 with SuperLine

use of org.twak.viewTrace.SuperLine in project chordatlas by twak.

the class SkelFootprint method meanDistance.

private Double meanDistance(Prof clean, SuperEdge he) {
    SuperLine sl = (SuperLine) he.profLine;
    if (sl == null)
        return null;
    MegaFacade mf = sl.getMega();
    int s = mf.getIndex(he.start), e = mf.getIndex(he.end);
    if (s > e) {
        int tmp = e;
        e = s;
        s = tmp;
    }
    int delta = e - s;
    if (delta >= 8) {
        delta *= 0.2;
        s += delta;
        e -= delta;
    }
    return meanDistance(mf, s, e, clean);
}
Also used : SuperLine(org.twak.viewTrace.SuperLine) MegaFacade(org.twak.tweed.gen.ProfileGen.MegaFacade) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint)

Example 13 with SuperLine

use of org.twak.viewTrace.SuperLine in project chordatlas by twak.

the class SkelFootprint method meanModeHeightColor.

public static void meanModeHeightColor(Loop<Point2d> pts, SuperFace sf, BlockGen blockgen) {
    double[] minMax = Loopz.minMax2d(pts);
    double sample = 2;
    double missCost = 30;
    if (sf.colors != null)
        sf.colors.clear();
    sf.heights.clear();
    int insideGIS = 0, outsideGIS = 0;
    LoopL<Point2d> gis = blockgen.profileGen.gis;
    gis = Loopz.removeInnerEdges(gis);
    gis = Loopz.removeNegativeArea(gis, -1);
    gis = Loopz.mergeAdjacentEdges(gis, 1, 0.05);
    for (double x = minMax[0]; x < minMax[1]; x += sample) for (double y = minMax[2]; y < minMax[3]; y += sample) {
        x += Math.random() * sample - sample / 2;
        y += Math.random() * sample - sample / 2;
        Point2d p2d = new Point2d(x, y);
        if (Loopz.inside(p2d, pts)) {
            CollisionResults results = new CollisionResults();
            blockgen.gNode.collideWith(new Ray(Jme3z.toJmeV(x, 0, y), UP), results);
            CollisionResult cr = results.getFarthestCollision();
            double height;
            if (cr != null) {
                height = cr.getDistance();
                sf.heights.add(height);
                if (sf != null && sf.colors != null) {
                    ColorRGBA col = getColor(cr.getGeometry(), cr.getContactPoint(), cr.getTriangleIndex(), blockgen.tweed);
                    sf.colors.add(new float[] { col.r, col.g, col.b });
                }
            }
            if (Loopz.inside(p2d, gis)) {
                insideGIS++;
            // PaintThing.debug( Color.yellow, 1, p2d);
            } else {
                outsideGIS++;
            // PaintThing.debug( Color.green, 1, p2d);
            }
        }
    }
    if (sf.heights.size() < 2)
        sf.height = -Double.MAX_VALUE;
    else if (TweedSettings.settings.useGis && insideGIS < gisInterior * outsideGIS)
        sf.height = -missCost;
    else {
        sf.updateHeight();
    }
    sf.maxProfHeights = new ArrayList();
    for (HalfEdge e : sf) {
        SuperEdge se = ((SuperEdge) e);
        if (se.profLine != null)
            for (Prof p : ((SuperLine) se.profLine).getMega().getTween(e.start, e.end, 0.3)) sf.maxProfHeights.add(p.get(p.size() - 1).y);
    }
}
Also used : CollisionResult(com.jme3.collision.CollisionResult) ArrayList(java.util.ArrayList) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) Ray(com.jme3.math.Ray) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) ColorRGBA(com.jme3.math.ColorRGBA) Point2d(javax.vecmath.Point2d) CollisionResults(com.jme3.collision.CollisionResults) SuperLine(org.twak.viewTrace.SuperLine)

Example 14 with SuperLine

use of org.twak.viewTrace.SuperLine in project chordatlas by twak.

the class SkelFootprint method fracture.

private static void fracture(HalfMesh2 mesh, HalfEdge previous, Vector2d dir, double remainingHard, double remainingSoft, Line line, boolean setLine) {
    if (previous == null)
        // at edge of shape: done
        return;
    HalfEdge p2 = previous.face.fracture(previous.end, dir, previous, previous.next);
    if (p2 == null) {
        System.err.println("failed to find intersection from " + previous.end + " dir " + dir);
        return;
    }
    HalfEdge next = p2.next.over;
    HalfEdge dividing = previous.face.split(mesh, previous, p2);
    ((SuperEdge) dividing).profLine = setLine ? (SuperLine) line : null;
    double l = dividing.length();
    if (remainingHard != 0)
        if (remainingHard < l) {
            Point2d softStart = new Point2d(dir);
            softStart.scale(remainingHard / dir.length());
            softStart.add(previous.end);
            dividing.split(softStart);
            ((SuperEdge) dividing.next).profLine = null;
            ((SuperEdge) dividing.next.over).profLine = null;
            fracture(mesh, next, dir, 0, remainingSoft - l + remainingHard, null, setLine);
        } else
            fracture(mesh, next, dir, remainingHard - l, remainingSoft, line, setLine);
    else if (remainingSoft > l)
        fracture(mesh, next, dir, 0, remainingSoft - l, line, setLine);
}
Also used : Point2d(javax.vecmath.Point2d) SuperLine(org.twak.viewTrace.SuperLine) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge)

Aggregations

SuperLine (org.twak.viewTrace.SuperLine)14 ArrayList (java.util.ArrayList)9 Point2d (javax.vecmath.Point2d)8 Line (org.twak.utils.Line)8 List (java.util.List)6 Point3d (javax.vecmath.Point3d)6 MFPoint (org.twak.tweed.gen.FeatureCache.MFPoint)6 MegaFacade (org.twak.tweed.gen.ProfileGen.MegaFacade)6 HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)6 ColorRGBA (com.jme3.math.ColorRGBA)5 Material (com.jme3.material.Material)4 Geometry (com.jme3.scene.Geometry)4 Node (com.jme3.scene.Node)4 HashSet (java.util.HashSet)4 LinkedHashMap (java.util.LinkedHashMap)4 Vector2d (javax.vecmath.Vector2d)4 HalfFace (org.twak.utils.geom.HalfMesh2.HalfFace)4 Mesh (com.jme3.scene.Mesh)3 VertexBuffer (com.jme3.scene.VertexBuffer)3 Color (java.awt.Color)3