Search in sources :

Example 16 with HalfMesh2

use of org.twak.utils.geom.HalfMesh2 in project chordatlas by twak.

the class SkelFootprint method insert.

public static void insert(HalfMesh2 mesh, Line line, double softDist, boolean backwardsToo, boolean setLine) {
    Vector2d dir = line.dir(), nDir = new Vector2d(dir);
    nDir.negate();
    double remaining = line.length();
    for (HalfFace f : mesh.faces) {
        if (f.contains(line.start)) {
            HalfEdge n = f.fracture(line.start, nDir), p = f.fracture(line.start, dir);
            if (n == null || p == null) {
                System.err.println("geometry failure");
                return;
            }
            HalfEdge next = p.next.over, prev = n.next.over;
            HalfEdge dividing = f.split(mesh, n, p);
            dividing.split(line.start);
            ((SuperEdge) dividing.next).profLine = setLine ? (SuperLine) line : null;
            double l = dividing.next.length();
            if (remaining < l) {
                Point2d softStart = new Point2d(dir);
                softStart.scale(remaining / dir.length());
                softStart.add(line.start);
                dividing.next.split(softStart);
                ((SuperEdge) dividing.next.next).profLine = null;
                ((SuperEdge) dividing.next.next.over).profLine = null;
                double remSoftDist = softDist - dividing.next.next.line().length();
                if (remSoftDist > 0)
                    fracture(mesh, next, dir, 0, remSoftDist, null, setLine);
            } else if (next != null)
                fracture(mesh, next, dir, remaining - l, softDist, line, setLine);
            double softDistN = softDist - dividing.start.distance(line.start);
            if (backwardsToo && softDistN > 0 && prev != null) {
                fracture(mesh, prev, nDir, 0, softDistN, null, setLine);
            }
            return;
        }
    }
}
Also used : Vector2d(javax.vecmath.Vector2d) Point2d(javax.vecmath.Point2d) SuperLine(org.twak.viewTrace.SuperLine) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace)

Example 17 with HalfMesh2

use of org.twak.utils.geom.HalfMesh2 in project chordatlas by twak.

the class SkelFootprint method findOcclusions.

private static void findOcclusions(HalfMesh2 mesh) {
    int count = 0;
    for (HalfFace hf : mesh.faces) for (HalfEdge e1 : hf.edges()) {
        Line el1 = e1.line();
        for (HalfFace hf2 : mesh.faces) {
            for (HalfEdge e2 : hf2.edges()) if (e1 != e2) {
                Line e2l = e2.line();
                if (el1.distance(e2l) < 1 && e2l.absAngle(el1) > Math.PI * 0.7) // !el1.isOnLeft(  e2l.fromPPram( 0.5 ) )
                {
                    ((SuperEdge) e1).occlusions.add(new LineHeight(el1.project(e2l.start, true), el1.project(e2l.end, true), 0, ((SuperFace) hf2).height));
                    count++;
                }
            }
        }
    }
    System.out.println("found " + count + " occluding surfaces");
}
Also used : Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine) LineHeight(org.twak.viewTrace.facades.LineHeight) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint)

Example 18 with HalfMesh2

use of org.twak.utils.geom.HalfMesh2 in project chordatlas by twak.

the class SkelFootprint method findRoofColor.

private static void findRoofColor(HalfMesh2 mesh) {
    class Wrapper implements Clusterable {

        double[] col;

        public Wrapper(float[] col) {
            this.col = new double[] { col[0], col[1], col[2] };
        }

        @Override
        public double[] getPoint() {
            return col;
        }
    }
    for (HalfFace hf : mesh.faces) {
        List<Wrapper> toCluster = new ArrayList();
        SuperFace sf = (SuperFace) hf;
        if (sf.colors == null || sf.colors.isEmpty()) {
            float grey = (float) (Math.random() * 0.3 + 0.2);
            sf.roofColor = new float[] { grey, grey, grey };
            continue;
        }
        for (float[] v : sf.colors) toCluster.add(new Wrapper(v));
        sf.colors = null;
        DBSCANClusterer<Wrapper> cr = new DBSCANClusterer<>(0.2, 5);
        List<Cluster<Wrapper>> results = cr.cluster(toCluster);
        float[] col = new float[] { 0.3f, 0.3f, 0.3f };
        try {
            Cluster<Wrapper> biggest = results.stream().max((a, b) -> Double.compare(a.getPoints().size(), b.getPoints().size())).get();
            col = new float[3];
            for (Wrapper w : biggest.getPoints()) for (int i = 0; i < 3; i++) col[i] += (float) w.col[i];
            int size = biggest.getPoints().size();
            for (int i = 0; i < 3; i++) col[i] /= size;
        } catch (NoSuchElementException e) {
        }
        sf.roofColor = col;
    }
}
Also used : Color(java.awt.Color) XStream(com.thoughtworks.xstream.XStream) Arrays(java.util.Arrays) FloatBuffer(java.nio.FloatBuffer) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) Type(com.jme3.scene.VertexBuffer.Type) Arrayz(org.twak.utils.collections.Arrayz) Loop(org.twak.utils.collections.Loop) Node(com.jme3.scene.Node) SkelGen(org.twak.tweed.gen.skel.SkelGen) MutableDouble(org.twak.utils.MutableDouble) ColorRGBAPainter(org.twak.viewTrace.ColorRGBAPainter) Map(java.util.Map) Cache(org.twak.utils.Cache) Material(com.jme3.material.Material) ChangeListener(javax.swing.event.ChangeListener) Streamz(org.twak.utils.collections.Streamz) Point3d(javax.vecmath.Point3d) ChangeEvent(javax.swing.event.ChangeEvent) VertexBuffer(com.jme3.scene.VertexBuffer) LoopL(org.twak.utils.collections.LoopL) Predicate(java.util.function.Predicate) Line(org.twak.utils.Line) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) Set(java.util.Set) HalfMesh2(org.twak.utils.geom.HalfMesh2) CollisionResult(com.jme3.collision.CollisionResult) Vector2d(javax.vecmath.Vector2d) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) List(java.util.List) JSlider(javax.swing.JSlider) Optional(java.util.Optional) Rainbow(org.twak.utils.ui.Rainbow) CollisionResults(com.jme3.collision.CollisionResults) Mesh(com.jme3.scene.Mesh) Geometry(com.jme3.scene.Geometry) IntStream(java.util.stream.IntStream) ActionListener(java.awt.event.ActionListener) DBSCANClusterer(org.apache.commons.math3.ml.clustering.DBSCANClusterer) Vector2f(com.jme3.math.Vector2f) HashMap(java.util.HashMap) MiniFacade(org.twak.viewTrace.facades.MiniFacade) Cach(org.twak.utils.Cach) Plot(org.twak.utils.ui.Plot) SwingConstants(javax.swing.SwingConstants) TreeSet(java.util.TreeSet) Clusterable(org.apache.commons.math3.ml.clustering.Clusterable) Tweed(org.twak.tweed.Tweed) IndexBuffer(com.jme3.scene.mesh.IndexBuffer) ArrayList(java.util.ArrayList) TweedSettings(org.twak.tweed.TweedSettings) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Mathz(org.twak.utils.Mathz) PaintThing(org.twak.utils.PaintThing) NoSuchElementException(java.util.NoSuchElementException) ProgressMonitor(javax.swing.ProgressMonitor) LinkedHashSet(java.util.LinkedHashSet) MatParam(com.jme3.material.MatParam) JButton(javax.swing.JButton) Texture2D(com.jme3.texture.Texture2D) Iterator(java.util.Iterator) MultiMap(org.twak.utils.collections.MultiMap) BufferUtils(com.jme3.util.BufferUtils) Vector3f(com.jme3.math.Vector3f) MeshBuilder(org.twak.siteplan.jme.MeshBuilder) MegaFacade(org.twak.tweed.gen.ProfileGen.MegaFacade) ModeCollector(org.twak.viewTrace.ModeCollector) JOptionPane(javax.swing.JOptionPane) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) Loopz(org.twak.utils.collections.Loopz) Point2d(javax.vecmath.Point2d) Jme3z(org.twak.siteplan.jme.Jme3z) Ray(com.jme3.math.Ray) SuperLine(org.twak.viewTrace.SuperLine) LineHeight(org.twak.viewTrace.facades.LineHeight) Format(com.jme3.scene.VertexBuffer.Format) Cluster(org.apache.commons.math3.ml.clustering.Cluster) ColorRGBA(com.jme3.math.ColorRGBA) FileReader(java.io.FileReader) ImageRaster(com.jme3.texture.image.ImageRaster) Comparator(java.util.Comparator) Collections(java.util.Collections) ArrayList(java.util.ArrayList) Cluster(org.apache.commons.math3.ml.clustering.Cluster) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) Clusterable(org.apache.commons.math3.ml.clustering.Clusterable) DBSCANClusterer(org.apache.commons.math3.ml.clustering.DBSCANClusterer) NoSuchElementException(java.util.NoSuchElementException)

Example 19 with HalfMesh2

use of org.twak.utils.geom.HalfMesh2 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 20 with HalfMesh2

use of org.twak.utils.geom.HalfMesh2 in project chordatlas by twak.

the class SkelFootprint method fractureOnFeatures.

private void fractureOnFeatures(MultiMap<MegaFeatures, MFPoint> minis, List<Line> footprint, HalfMesh2 mesh) {
    for (MegaFeatures mf : minis.keySet()) pt: for (MFPoint pt : minis.get(mf)) {
        if (!Mathz.inRange(mf.megafacade.findPPram(pt), 0, 1))
            continue;
        Vector2d dir = pt.mega.megafacade.dir();
        dir.set(dir.y, -dir.x);
        Point2d probe = new Point2d(dir);
        probe.scale(2 / dir.length());
        probe.add(pt);
        for (// don't fracture near minifacade boundaries...we can't distinguish nice block bondaries
        Point2d avoid : // don't fracture near minifacade boundaries...we can't distinguish nice block bondaries
        pt.mega.megafacade.points()) if (avoid.distanceSquared(pt) < 4)
            continue pt;
        double bestDist = Double.MAX_VALUE;
        for (HalfFace f : mesh.faces) for (HalfEdge e : f) if (e.line().dir().angle(dir) < 0.4) {
            double dist = e.line().distance(probe);
            if (dist < bestDist)
                bestDist = dist;
        }
        if (bestDist > 0.3) {
            Vector2d end = new Vector2d(dir);
            end.scale(3 / end.length());
            end.add(probe);
            Vector2d start = new Vector2d(dir);
            start.scale(0.5 / start.length());
            start.add(pt);
            Line extra = new Line(new Point2d(start), new Point2d(end));
            SkelFootprint.insert(mesh, extra, 2, false, false);
        }
    }
}
Also used : Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) Vector2d(javax.vecmath.Vector2d) Point2d(javax.vecmath.Point2d) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace)

Aggregations

HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)18 HalfFace (org.twak.utils.geom.HalfMesh2.HalfFace)18 Point2d (javax.vecmath.Point2d)10 MFPoint (org.twak.tweed.gen.FeatureCache.MFPoint)10 Line (org.twak.utils.Line)10 HalfMesh2 (org.twak.utils.geom.HalfMesh2)9 ArrayList (java.util.ArrayList)7 MegaFeatures (org.twak.tweed.gen.FeatureCache.MegaFeatures)7 HashMap (java.util.HashMap)6 SuperLine (org.twak.viewTrace.SuperLine)6 Color (java.awt.Color)5 LinkedHashMap (java.util.LinkedHashMap)5 Material (com.jme3.material.Material)4 ColorRGBA (com.jme3.math.ColorRGBA)4 Geometry (com.jme3.scene.Geometry)4 Node (com.jme3.scene.Node)4 File (java.io.File)4 HashSet (java.util.HashSet)4 LinkedHashSet (java.util.LinkedHashSet)4 Map (java.util.Map)4