Search in sources :

Example 16 with HalfEdge

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

the class SkelFootprint method removeExposedFaces.

public static void removeExposedFaces(HalfMesh2 mesh) {
    System.out.println("removing exposed faces....");
    Set<HalfFace> togo = new HashSet<>(mesh.faces);
    while (!togo.isEmpty()) {
        // for ( HalfFace hf : new ArrayList<HalfFace>( mesh.faces ) ) {
        HalfFace hf = togo.iterator().next();
        togo.remove(hf);
        double exposed = 0, safe = 0;
        for (HalfEdge e : hf.edges()) {
            if (e.over == null && ((SuperEdge) e).profLine == null)
                exposed += e.length();
            else
                safe += e.length();
        }
        if (exposed > exposedFaceFrac * safe) {
            togo.addAll(hf.getNeighbours());
            hf.remove(mesh);
        }
    }
}
Also used : HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 17 with HalfEdge

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

the class SkelFootprint method calcProfFit.

// private static Prof boringProf( double h ) {
// Prof prof = Prof.buildProfile( new Line3d( new Point3d( 0, 0, 0 ), new Point3d( 1, 0, 0 ) ), new Point3d( 0, 0, 0 ) );
// prof.add(new Point2d (0,0));
// prof.add(new Point2d (0,h));
// return prof;
// }
private void calcProfFit(HalfMesh2 mesh, List<Prof> globalProfs, Map<SuperEdge, double[]> out, ProgressMonitor m) {
    System.out.println("Building F...");
    boolean[] used = new boolean[globalProfs.size()];
    Map<SuperEdge, double[]> tmp = new HashMap();
    double[] noData = new double[globalProfs.size()];
    Arrays.fill(noData, 0);
    noData[0] = -1;
    used[0] = true;
    for (int i = 0; i < mesh.faces.size(); i++) {
        // System.out.println( "calculating profile fit for face " + i + "/" + mesh.faces.size() );
        HalfFace f = mesh.faces.get(i);
        for (HalfEdge e : f) {
            double[] fits = new double[globalProfs.size()];
            for (int g = 0; g < fits.length; g++) {
                Double d = meanDistance(globalProfs.get(g), (SuperEdge) e);
                if (d == null || Double.isNaN(d)) {
                    fits = noData;
                    break;
                } else
                    fits[g] = d;
            }
            tmp.put((SuperEdge) e, fits);
            used[Arrayz.min(fits)] = true;
        }
        if (m.isCanceled())
            return;
    }
    Arrays.fill(used, true);
    int count = 0;
    for (boolean u : used) if (u)
        count++;
    for (Map.Entry<SuperEdge, double[]> e : tmp.entrySet()) {
        double[] fits = new double[count];
        int c = 0;
        for (int i = 0; i < e.getValue().length; i++) if (used[i])
            fits[c++] = e.getValue()[i];
        out.put(e.getKey(), fits);
    }
    for (int g = globalProfs.size() - 1; g >= 0; g--) if (!used[g])
        globalProfs.remove(g);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) MutableDouble(org.twak.utils.MutableDouble) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MultiMap(org.twak.utils.collections.MultiMap) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint)

Example 18 with HalfEdge

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

the class SkelFootprint method dbgShowProfiles.

private void dbgShowProfiles(HalfMesh2 mesh, List<Prof> globalProfs, Map<SuperEdge, double[]> profFit, String name) {
    Node n = new Node();
    Jme3z.removeAllChildren(n);
    int colI = 0;
    for (HalfFace f : mesh) {
        ColorRGBA col = Jme3z.toJme(Rainbow.getColour(colI++));
        colI = colI % 6;
        Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
        mat.setColor("Diffuse", col);
        mat.setColor("Ambient", col);
        mat.setBoolean("UseMaterialColors", true);
        if (true) {
            Loop<Point3d> loop = new Loop<>();
            for (HalfEdge e : f) loop.append(new Point3d(e.start.x, 0, e.start.y));
            MeshBuilder mb = new MeshBuilder();
            mb.add(loop.singleton(), null, false);
            Geometry g = new Geometry("floorplan", mb.getMesh());
            g.setMaterial(mat);
            n.attachChild(g);
        }
        for (HalfEdge e : f) {
            SuperEdge se = (SuperEdge) e;
            Prof bestProf = null;
            if (globalProfs == null)
                bestProf = se.prof;
            else {
                // if (se.profLine != null) {
                // 
                // SuperLine sl = ((SuperLine)se.profLine);
                // MegaFacade mf = (MegaFacade) sl.properties.get( MegaFacade.class.getName() );
                // 
                // List<Prof> pfs = mf.getTween( se.start, se.end, 0.3 );
                // 
                // if (!pfs.isEmpty())
                // bestProf = Prof.parameterize( sl, pfs );
                // else {
                // bestProf = clean.get( 0 );
                // double bestScore = Double.MAX_VALUE;
                // 
                // for ( Prof c : clean ) {
                // 
                // double score = 0;
                // boolean good = false;
                // for ( Prof r : mf.getTween( se.start, se.end, 0.3 ) ) {
                // score += c.distance( r, true, false, true );
                // good = true;
                // }
                // if ( good && score < bestScore ) {
                // bestScore = score;
                // bestProf = c;
                // }
                // 
                // }
                // }
                // 
                // 
                // }
                // if (bestProf)
                // ((SuperLine))
                // 
                double[] fitV = profFit.get(se);
                if (fitV == null)
                    continue;
                double bestScore = Double.MAX_VALUE;
                for (int ii = 0; ii < fitV.length; ii++) {
                    double d = fitV[ii];
                    if (d < bestScore) {
                        bestScore = d;
                        bestProf = globalProfs.get(ii);
                    }
                }
            // 
            // double bestScore = Double.MAX_VALUE;
            // 
            // for ( int ii = 0; ii < fitV.length; ii++ ) {
            // double d = fitV[ ii ];
            // if ( d < bestScore ) {
            // bestScore = d;
            // bestProf = globalProfs.get( ii );
            // }
            // }
            // if (false)
            // se.prof = bestProf;
            }
            if (bestProf != null) {
                Geometry g = new Geometry();
                Point3d cen = Pointz.to3(se.line().fromPPram(0.5));
                Prof goodOrientation = Prof.buildProfile(Pointz.to3(se.line()), cen);
                for (Point2d p : bestProf) goodOrientation.add(p);
                g.setMesh(goodOrientation.renderStrip(1.5, cen));
                g.setMaterial(mat);
                n.attachChild(g);
                g.updateGeometricState();
                g.updateModelBound();
            }
        }
    }
    skelGen.tweed.frame.addGen(new JmeGen(name, tweed, n), false);
}
Also used : Loop(org.twak.utils.collections.Loop) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) Geometry(com.jme3.scene.Geometry) ColorRGBA(com.jme3.math.ColorRGBA) Point2d(javax.vecmath.Point2d) Point3d(javax.vecmath.Point3d) MeshBuilder(org.twak.siteplan.jme.MeshBuilder)

Example 19 with HalfEdge

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

the class SolverState method debugSolverResult.

public void debugSolverResult() {
    new Plot(mesh).add(miniPainter()).add(new ICanPaint() {

        @Override
        public void paint(Graphics2D g, PanMouseAdaptor ma) {
            Set<HalfEdge> seen = new HashSet<>();
            Color tWhite = new Color(255, 255, 255, 150);
            if (!seen.isEmpty())
                for (HalfFace f : mesh) {
                    for (HalfEdge e : f) {
                        int i = ((SuperEdge) e).profI;
                        // if (i == -1)
                        // continue;
                        Point2d loc = e.line().fromPPram(0.5);
                        String s = "" + i;
                        int offset = e.start.x < e.end.x ? -10 : 10;
                        seen.add(e);
                        Rectangle2D b = g.getFontMetrics().getStringBounds(s, g);
                        b = new Rectangle2D.Double(0, 0, b.getWidth() + 4, b.getHeight());
                        g.setColor(tWhite);
                        g.fillRect(ma.toX(loc.x) - (int) (b.getWidth() / 2), offset + ma.toY(loc.y) - (int) (b.getHeight() / 2), (int) (b.getWidth()), (int) (b.getHeight()));
                        g.setColor(Color.gray);
                        g.drawString(s, ma.toX(loc.x) - (int) (b.getWidth() / 2) + 2, offset + ma.toY(loc.y) + (int) (b.getHeight() / 2) - 3);
                    }
                }
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Plot(org.twak.utils.ui.Plot) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) ICanPaint(org.twak.utils.PaintThing.ICanPaint) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) ICanPaint(org.twak.utils.PaintThing.ICanPaint) Graphics2D(java.awt.Graphics2D) Point2d(javax.vecmath.Point2d) PanMouseAdaptor(org.twak.utils.PanMouseAdaptor)

Example 20 with HalfEdge

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

the class SolverState method save.

public void save(File location, boolean clean) {
    try {
        if (clean)
            for (HalfFace f : mesh) {
                for (HalfEdge e : f) {
                    SuperEdge se = (SuperEdge) e;
                    if (se.profLine != null)
                        ((SuperLine) se.profLine).mega = null;
                }
            }
        System.out.print("writing state to " + location + " ...");
        location.getAbsoluteFile().getParentFile().mkdirs();
        new XStream().toXML(this, new FileOutputStream(location));
        System.out.println("done!");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}
Also used : XStream(com.thoughtworks.xstream.XStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace)

Aggregations

HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)31 HalfFace (org.twak.utils.geom.HalfMesh2.HalfFace)25 Point2d (javax.vecmath.Point2d)15 MFPoint (org.twak.tweed.gen.FeatureCache.MFPoint)13 Line (org.twak.utils.Line)13 SuperLine (org.twak.viewTrace.SuperLine)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 MegaFeatures (org.twak.tweed.gen.FeatureCache.MegaFeatures)8 HalfMesh2 (org.twak.utils.geom.HalfMesh2)7 Color (java.awt.Color)6 LinkedHashSet (java.util.LinkedHashSet)6 List (java.util.List)6 Map (java.util.Map)6 MultiMap (org.twak.utils.collections.MultiMap)6 File (java.io.File)5 Set (java.util.Set)5 Vector2d (javax.vecmath.Vector2d)5 Cach (org.twak.utils.Cach)5