Search in sources :

Example 1 with LineSoup

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

the class ProfileGen method findMegaFaces.

private List<MegaFacade> findMegaFaces(double delta) {
    SliceParameters P = new SliceParameters(SLICE_SCALE);
    List<LineAtHeight> lines = new ArrayList();
    Map<Integer, LineSoup> slices = new HashMap<>();
    for (int hi = 0; getHeight(hi) < extent[3]; hi++) {
        int _i = hi;
        boolean error;
        int count = 0;
        do {
            error = false;
            try {
                LineSoup soup = new LineSoup(ObjSlice.sliceTri(blockGen.getCroppedMesh(), getHeight(hi), majorAxis));
                FindLines foundLines = new FindLines(soup, TweedSettings.settings.useGis ? gisBias : null, -1, null, P);
                foundLines.result.all.stream().forEach(x -> lines.add(new LineAtHeight(_i, delta, x, foundLines.result.all)));
                slices.put(hi, foundLines.result);
            } catch (Throwable th) {
                th.printStackTrace();
                error = true;
            }
        } while (error && count++ < 10);
    }
    Collections.sort(lines, new LAHComparator());
    // new Plot(lines.stream().map (lah -> lah.line).collect(Collectors.toList() ), gis);
    faces = new ArrayList<>();
    while (!lines.isEmpty()) {
        System.out.println("clustering megafacdes " + lines.size());
        // longest line
        LineAtHeight start = lines.get(0);
        lines.remove(start);
        MegaFacade face = new MegaFacade(start);
        Set<LineAtHeight> toProcess = new HashSet<>();
        toProcess.add(start);
        while (!toProcess.isEmpty()) {
            LineAtHeight lah = toProcess.iterator().next();
            toProcess.remove(lah);
            for (int _pmDelta : new int[] { -2, -1, 1, 2 }) {
                int hi = lah.height + _pmDelta;
                LineSoup ls = slices.get(hi);
                if (ls != null) {
                    for (Line l : ls.all) {
                        double lps = start.line.findPPram(l.start), lpe = start.line.findPPram(l.end);
                        double overlap = 0;
                        if (lpe < lps)
                            overlap = 0;
                        else if (lps > face.minP && lpe < face.maxP || lps < face.minP && lpe > face.maxP)
                            overlap = 1;
                        else if (lps < face.minP && lpe > face.minP)
                            overlap = (lpe - face.minP) / (lpe - lps);
                        else if (lps < face.maxP && lpe > face.maxP)
                            overlap = (face.maxP - lps) / (lpe - lps);
                        double angle = l.absAngle(start.line);
                        if (overlap > 0.8 && angle < 0.3 || overlap > 0.5 && /* 0.1 for aggressive clustering */
                        angle < 0.1) {
                            // if (overlap > 0.1 && angle < 0.5 ) {
                            if (l.distance(lah.line) < delta * TweedSettings.settings.megafacacadeClusterGradient) {
                                LineAtHeight toProc = new LineAtHeight(hi, l);
                                if (lines.contains(toProc)) {
                                    toProcess.add(toProc);
                                    face.put(hi, l);
                                    lines.remove(toProc);
                                    // bit strange: depends on the processing order of the set
                                    face.minP = Mathz.min(face.minP, lps);
                                    face.maxP = Mathz.max(face.maxP, lpe);
                                }
                            }
                        }
                    }
                }
            }
        }
        if (face.values().stream().flatMap(x -> x.stream()).count() > 5)
            faces.add(face);
        else
            System.out.println("skipping small megafacade");
    }
    Collections.sort(faces);
    processMegaFaces();
    return faces;
}
Also used : FindLines(org.twak.viewTrace.FindLines) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CullHint(com.jme3.scene.Spatial.CullHint) Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine) SliceParameters(org.twak.viewTrace.SliceParameters) LineSoup(org.twak.viewTrace.LineSoup) HashSet(java.util.HashSet)

Aggregations

CullHint (com.jme3.scene.Spatial.CullHint)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Line (org.twak.utils.Line)1 FindLines (org.twak.viewTrace.FindLines)1 LineSoup (org.twak.viewTrace.LineSoup)1 SliceParameters (org.twak.viewTrace.SliceParameters)1 SuperLine (org.twak.viewTrace.SuperLine)1