Search in sources :

Example 36 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class Prof method to2d.

public Point2d to2d(Point3d pt) {
    Point3d tmp = new Point3d();
    toFlat.transform(pt, tmp);
    return new Point2d(tmp.x, tmp.y);
}
Also used : Point2d(javax.vecmath.Point2d) Point3d(javax.vecmath.Point3d)

Example 37 with Point2d

use of javax.vecmath.Point2d 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 38 with Point2d

use of javax.vecmath.Point2d 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 39 with Point2d

use of javax.vecmath.Point2d 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 40 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class ResultsGen method blockSelected.

@Override
public void blockSelected(LoopL<Point3d> polies, BlockGen blockGen) {
    Point2d cen = Loopz.average(Loopz.to2dLoop(polies, 1, null));
    for (File f : new File(tweed.DATA + File.separator + "solutions").listFiles()) {
        try {
            Point2d fp = FeatureCache.fileToCenter(f.getName());
            if (fp.distanceSquared(cen) < 1) {
                new Thread(() -> load(f, true)).start();
                return;
            }
        } catch (Throwable th) {
            System.out.println("unable to read solution " + f.getName());
        }
    }
    JOptionPane.showMessageDialog(tweed.frame(), "Can't find solution for center " + cen);
}
Also used : Point2d(javax.vecmath.Point2d) File(java.io.File)

Aggregations

Point2d (javax.vecmath.Point2d)84 Line (org.twak.utils.Line)37 ArrayList (java.util.ArrayList)29 Point3d (javax.vecmath.Point3d)27 List (java.util.List)18 Vector2d (javax.vecmath.Vector2d)17 SuperLine (org.twak.viewTrace.SuperLine)17 File (java.io.File)15 Vector3d (javax.vecmath.Vector3d)15 Map (java.util.Map)14 HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)14 HashMap (java.util.HashMap)13 Loop (org.twak.utils.collections.Loop)13 Collectors (java.util.stream.Collectors)12 IOException (java.io.IOException)11 HashSet (java.util.HashSet)11 Set (java.util.Set)11 Tweed (org.twak.tweed.Tweed)11 Matrix4d (javax.vecmath.Matrix4d)10 LinearForm (org.twak.utils.geom.LinearForm)10