Search in sources :

Example 26 with Line

use of org.twak.utils.Line in project chordatlas by twak.

the class Prof method distance.

public // union or just range of other
double distance(// union or just range of other
Prof other, // union or just range of other
boolean union, // do we extend or penalize when out of range?
boolean extendThis, // do we extend or penalize when out of range?
boolean extendOther) {
    double meanFit = 0;
    int norm = 0;
    int t = 0, o = 0;
    if (size() < 2 || other.size() < 2)
        throw new Error();
    double h = union ? Math.min(other.get(0).y, this.get(0).y) : other.get(0).y, delta = 0.1;
    h = Math.max(0, h);
    double penalty = 10 * 10;
    if (get(0).y > other.get(other.size() - 1).y || get(size() - 1).y < other.get(0).y)
        return penalty;
    boolean overT = false, overO = false;
    while (true) {
        while (h > get(t + 1).y) {
            t++;
            if (t >= size() - 1) {
                overT = true;
                t = size() - 2;
                break;
            }
        }
        while (h > other.get(o + 1).y) {
            o++;
            if (o >= other.size() - 1) {
                overO = true;
                o = other.size() - 2;
                break;
            }
        }
        if (!union && overO || overT && overO)
            break;
        if (!extendOther && overO || !extendThis && overT)
            meanFit += penalty;
        else {
            Line tl = new Line(get(t), get(t + 1)), ol = new Line(other.get(o), other.get(o + 1));
            double tx = tl.xAtY(h), ox = ol.xAtY(h);
            tx = Math.min(0, tx);
            ox = Math.min(0, ox);
            meanFit += (Math.pow(tl.absAngle(ol) * 2, 2) + Math.pow(tx - ox, 2)) * delta * (1 / tl.aTan2());
        }
        norm++;
        h += delta;
    }
    return norm == 0 ? penalty : meanFit / norm;
}
Also used : Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine)

Example 27 with Line

use of org.twak.utils.Line in project chordatlas by twak.

the class Prof method buildProfile.

public static Prof buildProfile(ObjRead mesh, Line3d oLine, Point3d cen, double minH, double maxH, double minD, double maxD, Tweed tweed, Node dbg) {
    Prof monotonic = buildProfile(oLine, cen);
    Vector3d dir = oLine.dir();
    dir.normalize();
    Vector3d sliceNormal = new Vector3d(dir.x, 0, dir.z);
    LinearForm3D lf = new LinearForm3D(sliceNormal, cen);
    List<Line3d> lines = ObjSlice.sliceTri(mesh, lf, 0.5, new Vector3d(-dir.z, 0, dir.x), Math.PI / 2 + 0.1);
    // dbg.attachChild( Jme3z.lines( tweed, lines, ColorRGBA.Blue, 2 ) );
    Line3d first = null;
    double closestStart = Double.MAX_VALUE;
    for (Line3d l : lines) {
        if (l.start.y > l.end.y)
            l.reverse();
        double dist = l.distanceSquared(cen);
        if (dist < closestStart) {
            closestStart = dist;
            first = l;
        }
    }
    if (first == null) {
        return null;
    // lines.clear();
    // monotonic.add( cen );
    // monotonic.add( new Point3d( cen.x, cen.y - 500, cen.z ) );
    } else {
        climb(lines, first, monotonic, maxH, true);
        climb(lines, first, monotonic, minH, false);
    }
    {
        double tol = 0.2;
        minD -= tol;
        maxD += tol;
        LinearForm min = new LinearForm(Mathz.UP).findC(new Point2d(minD, 0));
        LinearForm max = new LinearForm(Mathz.UP).findC(new Point2d(maxD, 0));
        for (int i = 0; i < monotonic.size() - 1; i++) {
            Point2d a = monotonic.get(i), b = monotonic.get(i + 1);
            if (a.x < minD && b.x < minD) {
                monotonic.remove(i);
                i--;
            } else if (a.x < minD) {
                monotonic.set(i, new LinearForm(new Line(a, b)).intersect(min));
            } else if (b.x < minD) {
                monotonic.set(i + 1, new LinearForm(new Line(a, b)).intersect(min));
                b.x = minD + Math.ulp(minD);
            }
            if (a.x > maxD && b.x > maxD) {
                monotonic.remove(i);
                i--;
            } else if (a.x > maxD) {
                monotonic.set(i, new LinearForm(new Line(a, b)).intersect(max));
            } else if (b.x > maxD) {
                monotonic.set(i + 1, new LinearForm(new Line(a, b)).intersect(max));
                b.x = maxD - Math.ulp(maxD);
            }
        }
    }
    return monotonic;
}
Also used : Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine) Vector3d(javax.vecmath.Vector3d) Point2d(javax.vecmath.Point2d) LinearForm(org.twak.utils.geom.LinearForm) LinearForm3D(org.twak.utils.geom.LinearForm3D) Line3d(org.twak.utils.geom.Line3d)

Example 28 with Line

use of org.twak.utils.Line in project chordatlas by twak.

the class Prof method verticalLength.

protected Double verticalLength(double tol) {
    double length = 0;
    for (Pair<Point2d, Point2d> pts : new ConsecutiveItPairs<>(this)) {
        Line line = new Line(pts.first(), pts.second());
        double angle = line.aTan2();
        if (angle > Mathz.PI2 - tol && angle < Mathz.PI2 + tol)
            length += line.length();
    }
    return length;
}
Also used : Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine) ConsecutiveItPairs(org.twak.utils.collections.ConsecutiveItPairs) Point2d(javax.vecmath.Point2d)

Example 29 with Line

use of org.twak.utils.Line in project chordatlas by twak.

the class Prof method clean.

// public static List<List<Prof>> partition( List<Prof> profiles, double threshold ) {
// 
// double[] ss = new double[profiles.size()];
// 
// for (int i = 0; i < profiles.size(); i++) { // suppress non-max
// 
// double wMax = -Double.MAX_VALUE;
// int winner = -1;
// 
// for (int k = -3; k <= 3; k++) {
// int ii = MUtils.clamp( i+k, 0, profiles.size() -1 );
// 
// if (profiles.get(ii).similarity > wMax) {
// winner = ii;
// wMax = profiles.get(ii).similarity;
// }
// }
// 
// ss[i] = profiles.get(i).similarity;
// 
// if ( winner == i )
// ss[i] *= 3;
// }
// 
// List<List<Prof>> out = new ArrayList();
// 
// List<Prof> lout = null;
// for (int i = 0; i < profiles.size(); i++) {
// if (lout == null || ss[i] > threshold  ) {
// lout = new ArrayList<>();
// out.add(lout);
// }
// lout.add(profiles.get( i ));
// profiles.get(i).similarity = ss[i];
// }
// 
// return out;
// }
public static Prof clean(List<Prof> partition) {
    int[] inds = new int[partition.size()];
    Prof loc3 = partition.get(partition.size() / 2);
    Prof out = new Prof(loc3.toFlat, loc3.dir);
    double delta = 0.1;
    double h = 0;
    // boolean halt;
    List<Double> xs = new ArrayList();
    do {
        // halt = true;
        xs.clear();
        int count = 0;
        for (int p = 0; p < partition.size(); p++) {
            Prof prof = partition.get(p);
            if (prof.size() < 2)
                continue;
            count++;
            if (prof.get(inds[p] + 1).y > h) {
                Line l = new Line(prof.get(inds[p]), prof.get(inds[p] + 1));
                if (Math.abs(l.start.x - l.end.x) < 0.01)
                    xs.add(l.start.x);
                else
                    xs.add(l.xAtY(h));
            }
            while (prof.get(inds[p] + 1).y < h + delta && inds[p] < prof.size() - 2) inds[p]++;
        // if ( prof.get ( inds[p] + 1).y > h+delta )
        // halt = false;
        }
        double sum = xs.stream().collect(Collectors.summingDouble(x -> x)).doubleValue();
        if (!Double.isNaN(sum / count))
            out.add(new Point2d(sum / count, h));
        h += delta;
    } while (xs.size() > partition.size() / 4);
    return out;
}
Also used : Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine) Point2d(javax.vecmath.Point2d) ArrayList(java.util.ArrayList)

Example 30 with Line

use of org.twak.utils.Line in project chordatlas by twak.

the class SkelFootprint method debugFindCleanProfiles.

public static void debugFindCleanProfiles(List<Line> footprint, SkelGen skelGen, ProgressMonitor m, Tweed tweed) {
    MultiMap<SuperLine, List<Prof>> profSets = new MultiMap<>();
    for (Line l : footprint) profileRuns((SuperLine) l, profSets);
    List<List<Prof>> ordered = new ArrayList<>();
    Map<List<Prof>, SuperLine> pairs = new LinkedHashMap<>();
    for (SuperLine l : profSets.keySet()) for (List<Prof> lp : profSets.get(l)) {
        pairs.put(lp, l);
        ordered.add(lp);
    }
    JSlider bunch = new JSlider(0, ordered.size() - 1);
    JButton button = new JButton("go");
    Plot plot = new Plot(bunch, button);
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            PaintThing.debug.clear();
            plot.toPaint.clear();
            List<Prof> ps = ordered.get(bunch.getValue());
            SuperLine sl = pairs.get(ps);
            if (sl != null && ps != null) {
                PaintThing.debug(new Color(0, 0, 0, 50), 1, ps);
                Prof clean = Prof.parameterize(ps);
                Prof c2 = new Prof(clean);
                for (Point2d p : c2) p.x += 10;
                // plot.toPaint.add( clean ) );
                PaintThing.debug(new Color(0, 170, 255), 3f, c2);
                Prof mid = ps.get(ps.size() / 2);
                tweed.enqueue(new Runnable() {

                    @Override
                    public void run() {
                        Jme3z.removeAllChildren(tweed.debug);
                        for (Prof p : ps) {
                            // p = p.moveToX0();
                            p.render(tweed, tweed.debug, ColorRGBA.Blue, (float) TweedSettings.settings.profileHSampleDist);
                        }
                        Point3d pt = mid.to3d(mid.get(0));
                        pt.y = 0;
                        Geometry geom = new Geometry("material_", clean.renderStrip(1, null));
                        Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
                        mat.setColor("Diffuse", ColorRGBA.Blue);
                        mat.setColor("Ambient", ColorRGBA.Red);
                        geom.setMaterial(mat);
                        // tweed.debug.attachChild( geom );
                        tweed.debug.updateGeometricState();
                        tweed.debug.updateModelBound();
                        tweed.gainFocus();
                    }
                });
            }
            plot.repaint();
        }
    });
    bunch.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            button.doClick();
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) Plot(org.twak.utils.ui.Plot) Color(java.awt.Color) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) Material(com.jme3.material.Material) LinkedHashMap(java.util.LinkedHashMap) Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine) Geometry(com.jme3.scene.Geometry) MultiMap(org.twak.utils.collections.MultiMap) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) Point2d(javax.vecmath.Point2d) Point3d(javax.vecmath.Point3d) SuperLine(org.twak.viewTrace.SuperLine) JSlider(javax.swing.JSlider) List(java.util.List) ArrayList(java.util.ArrayList) ChangeListener(javax.swing.event.ChangeListener)

Aggregations

Line (org.twak.utils.Line)59 Point2d (javax.vecmath.Point2d)38 ArrayList (java.util.ArrayList)25 SuperLine (org.twak.viewTrace.SuperLine)22 List (java.util.List)16 Point3d (javax.vecmath.Point3d)14 HashSet (java.util.HashSet)13 LinearForm (org.twak.utils.geom.LinearForm)13 HashMap (java.util.HashMap)12 Map (java.util.Map)11 Set (java.util.Set)11 HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)11 HalfFace (org.twak.utils.geom.HalfMesh2.HalfFace)11 Collectors (java.util.stream.Collectors)10 Vector2d (javax.vecmath.Vector2d)10 Iterator (java.util.Iterator)9 Vector3d (javax.vecmath.Vector3d)9 Tweed (org.twak.tweed.Tweed)8 TweedSettings (org.twak.tweed.TweedSettings)8 MFPoint (org.twak.tweed.gen.FeatureCache.MFPoint)8