Search in sources :

Example 1 with Cluster

use of org.twak.utils.DumbCluster1D.Cluster in project chordatlas by twak.

the class SolverState method miniPainter.

public ICanPaint miniPainter() {
    return new ICanPaint() {

        @Override
        public void paint(Graphics2D g, PanMouseAdaptor ma) {
            // for ( MegaFeatures f : SS.minis.keySet() ) {
            // 
            // for ( MFPoint mfp : SS.minis.get( f ) ) {
            // Line l = mfp.image.mega.megafacade;
            // 
            // spreadImages( g, ma, l, mfp,  Listz.from( mfp.left, mfp.right ) );
            // 
            // }
            // }
            // if (SS.minis == null)
            int brake = 100;
            for (HalfFace f : mesh) {
                for (HalfEdge e : f) {
                    if (e.over != null)
                        continue;
                    if (brake-- < 0)
                        break;
                    SuperEdge se = (SuperEdge) e;
                    if (se.mini == null)
                        continue;
                    List<MiniFacade> mfs = new ArrayList(se.mini);
                    // while (mfs .size() < 2)
                    // mfs.add(null);
                    spreadImages(g, ma, se.line(), se.line().fromPPram(0.5), mfs);
                }
            }
            int i = 0;
            if (minis != null)
                for (MegaFeatures f : minis.keySet()) {
                    // PaintThing.paint (f.megafacade, g, ma);
                    DumbCluster1D<MFPoint> res = GurobiSkelSolver.clusterMinis(f, minis);
                    Vector2d dir = f.megafacade.dir();
                    Vector2d out = new Vector2d(dir);
                    out.set(-out.y, out.x);
                    out.scale(ma.toZoom(2) / out.length());
                    for (Cluster<MFPoint> c : res) {
                        g.setColor(Rainbow.getColour(i++));
                        for (MFPoint mfp : c.things) {
                            Point2d pt = new Point2d(mfp);
                            pt.add(out);
                            g.setStroke(new BasicStroke(0.2f));
                            PaintThing.paint(pt, g, ma);
                            g.setStroke(new BasicStroke(0.2f));
                            for (HalfEdge e : GurobiSkelSolver.findNear(f.megafacade, mfp, mesh)) g.drawLine(ma.toX(pt.x), ma.toY(pt.y), ma.toX(e.end.x), ma.toY(e.end.y));
                            if (mfp.selectedEdge != null) {
                                g.setStroke(new BasicStroke(2f));
                                g.drawLine(ma.toX(pt.x), ma.toY(pt.y), ma.toX(mfp.selectedEdge.end.x), ma.toY(mfp.selectedEdge.end.y));
                            }
                        }
                    }
                }
            g.setStroke(new BasicStroke(1));
        }

        private void spreadImages(Graphics2D g, PanMouseAdaptor ma, Line sel, Point2d cen, List<MiniFacade> mfs) {
            Vector2d perp = sel.dir();
            perp.set(-perp.y, perp.x);
            perp.normalize();
            for (int i = 0; i < mfs.size(); i++) {
                MiniFacade mf = mfs.get(i);
                Vector2d p2 = new Vector2d(perp);
                p2.scale((i + 1) * 10);
                p2.add(cen);
                if (mf == null) {
                    g.setColor(Color.black);
                    g.fillRect(ma.toX(p2.x - 1), ma.toY(p2.y - 3), ma.toZoom(2), ma.toZoom(6));
                    continue;
                }
                double w = mf.width * 0.1;
                double h = mf.height * 0.1;
                mf.paintImage(g, ma, p2.x - w, p2.y - h, p2.x + w, p2.y + h);
            }
        }
    };
}
Also used : BasicStroke(java.awt.BasicStroke) MiniFacade(org.twak.viewTrace.facades.MiniFacade) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) ArrayList(java.util.ArrayList) Cluster(org.twak.utils.DumbCluster1D.Cluster) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) HalfFace(org.twak.utils.geom.HalfMesh2.HalfFace) DumbCluster1D(org.twak.utils.DumbCluster1D) ICanPaint(org.twak.utils.PaintThing.ICanPaint) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) ICanPaint(org.twak.utils.PaintThing.ICanPaint) Graphics2D(java.awt.Graphics2D) Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine) Vector2d(javax.vecmath.Vector2d) Point2d(javax.vecmath.Point2d) PanMouseAdaptor(org.twak.utils.PanMouseAdaptor) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

BasicStroke (java.awt.BasicStroke)1 Graphics2D (java.awt.Graphics2D)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Point2d (javax.vecmath.Point2d)1 Vector2d (javax.vecmath.Vector2d)1 MFPoint (org.twak.tweed.gen.FeatureCache.MFPoint)1 MegaFeatures (org.twak.tweed.gen.FeatureCache.MegaFeatures)1 DumbCluster1D (org.twak.utils.DumbCluster1D)1 Cluster (org.twak.utils.DumbCluster1D.Cluster)1 Line (org.twak.utils.Line)1 ICanPaint (org.twak.utils.PaintThing.ICanPaint)1 PanMouseAdaptor (org.twak.utils.PanMouseAdaptor)1 HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)1 HalfFace (org.twak.utils.geom.HalfMesh2.HalfFace)1 SuperLine (org.twak.viewTrace.SuperLine)1 MiniFacade (org.twak.viewTrace.facades.MiniFacade)1