Package jjil.core

Examples of jjil.core.Vec2


        if (cliStart.getNext() == cliEnd.getPrevious()) {
            return 0;
        }
        // vecLine is the direction from the ending point to
        // the starting point
         Vec2 vecLine = cliEnd.getNext().getPos().diff(cliStart.getNext().getPos());
        // check for starting and ending points the same
        if (vecLine.getX() == 0 && vecLine.getY() == 0) {
          // measure from curve direction at start
            vecLine = cliStart.getPrevious().getVec();
        }
        // maxPerp is the max distance from the line to the current point
        int maxPerp = Integer.MIN_VALUE;
        CircListIter cli = cliStart.clone();
        cli.next();
        CircListIter cliMaxPoint = cli;
        this.mvSum.setXY(0, 0);
        // for each point from start to end
        while (cli.getNext() != cliEnd.getNext()) {
          // get the point
            this.mvSum.add(cli.next().getVec());
            // perp is the magnitude of the cross product
            // of vec (current position) x vecLine (line)
            // which is the distance of vec to the line
            // (times the length of vecLine which doesn't change)
            int perp = this.mvSum.crossMag(vecLine);
            perp *= perp;
            // if we're further from the line than we've
            // been before
            if (perp > maxPerp) {
                maxPerp = perp;
                cliMaxPoint = cli.clone();
                cliMaxPoint.previous();
            }
        };
        int vLen = 0;
        try {
          vLen = vecLine.length();
        } catch (jjil.core.Error er) {
         
        }
        // check to see if we should split again
        // remember maxPerp = | vLen | * (max perpendicular distance to vecLine)
View Full Code Here


        do {
            if (fixed_count <= 3) {
                break;                     //already too few

            }
            Vec2 d12vec = edgefix1.getPos().diff(edgefix2.getPos());
            int d12 = d12vec.lengthSqr();
            if (d12 <= gapmin) {
                Vec2 d01vec = edgefix0.getPos().diff(edgefix1.getPos());
                int d01 = d01vec.lengthSqr();
                Vec2 d23vec = edgefix2.getPos().diff(edgefix3.getPos());
                int d23 = d23vec.lengthSqr();
                if (d01 > d23) {
                    edgefix2.resetFixed();
                    fixed_count--;
                } else {
                    edgefix1.resetFixed();
View Full Code Here

     * @throws jjil.core.Error if some of the edges in t1 are of length zero
     */
    public TriangleMap(Triangle t1, Triangle t2) throws jjil.core.Error {
        this.p1 = t1.getP1();
        this.p2 = t2.getP1();
        Vec2 s12, s13, s22, s23;
        s12 = new Vec2(this.p1, t1.getP2());
        s13 = new Vec2(this.p1, t1.getP3());
        s22 = new Vec2(this.p2, t2.getP2());
        s23 = new Vec2(this.p2, t2.getP3());

        // The matrix transformation is
        // A vT = u
        // where vT is the original vector (s12 or s13), transposed,
        // and u is the transformed vector (s22 or s23).
        // The solution to the transformation is
        // A = [s22T s23T][s12T s13T]-1 = [s22T s23T] B-1
        // Where -1 indicates matrix inversion of the 2x2 matrix (denoted B) formed from
        // the transposed vectors s12T and s13T.
        // Matrix inversion of a 2x2 matrix is easy.
        // First calculate the determinant of B above
        this.detB = s12.getX() * s13.getY() - s13.getX() * s12.getY();
        if (this.detB == 0) {
            throw new Error(
                            Error.PACKAGE.ALGORITHM,
                            ErrorCodes.PARAMETER_OUT_OF_RANGE,
                            t1.toString(),
                            null,
                            null);
        }
        // Note: Binv is implicitly divided by detB. We delay the division
        // because we're doing everything in integer
        int Binv[][] = new int[2][2];
        Binv[0][0] = s13.getY();
        Binv[0][1] = -s13.getX();
        Binv[1][0] = -s12.getY();
        Binv[1][1] = s12.getX();
        // finally form A. Once again, A is divided by detB later.
        this.A = new int[2][2];
        this.A[0][0] = s22.getX() * Binv[0][0] + s23.getX() * Binv[1][0];
        this.A[0][1] = s22.getX() * Binv[0][1] + s23.getX() * Binv[1][1];
        this.A[1][0] = s22.getY() * Binv[0][0] + s23.getY() * Binv[1][0];
 
View Full Code Here

     * Map point in one triangle into the other triangle
     * @param p Point to map
     * @return mapped Point
     */
    public Point map(Point p) {
        Vec2 v = new Vec2(p1, p);
        // multiply by A
        return new Point(
                (this.A[0][0]*v.getX() + this.A[0][1]*v.getY()) / this.detB,
                (this.A[1][0]*v.getX() + this.A[1][1]*v.getY()) / this.detB);
    }
View Full Code Here

     * @param a 2x3 affine transformation, scaled by 2**16
     * @param p input vector
     * @return transformed vector
     */
    private Vec2 affineTrans(int a[][], Vec2 p) {
        return new Vec2(
                (a[0][0] * p.getX() + a[0][1] * p.getY() + a[0][2])>>16,
                (a[1][0] * p.getX() + a[1][1] * p.getY() + a[1][2])>>16);
    }
View Full Code Here

            image.toString(),
            null,
            null);
        }
        // first calculate bounds of output image
        Vec2 p00 = affineTrans(this.rnWarp, new Vec2(0, 0));
        Vec2 p01 = affineTrans(this.rnWarp, new Vec2(0, image.getHeight()));
        Vec2 p10 = affineTrans(this.rnWarp, new Vec2(image.getWidth(), 0));
        Vec2 p11 = affineTrans(this.rnWarp, new Vec2(image.getWidth(),
                 image.getHeight()));
        this.nMinX = (int) Math.min(p00.getX(),
                Math.min(p01.getX(), Math.min(p10.getX(), p11.getX())));
        this.nMaxX = (int) Math.max(p00.getX(),
                Math.max(p01.getX(), Math.max(p10.getX(), p11.getX())));
        this.nMinY = (int) Math.min(p00.getY(),
                Math.min(p01.getY(), Math.min(p10.getY(), p11.getY())));
        this.nMaxY = (int) Math.max(p00.getY(),
                Math.max(p01.getY(), Math.max(p10.getY(), p11.getY())));
        this.nXOffset = -this.nMinX;
        this.nYOffset = -this.nMinY;
        if (this.nWarpOrder == Gray8AffineWarp.WARP_X_FIRST) {
            Gray8Image grayX = warpX((Gray8Image) image);
            //super.setOutput(new Gray8OffsetImage(grayX, this.nXOffset, this.nYOffset));
View Full Code Here

    public Vec2 warpVec(Vec2 p) {
        int x = (p.getX() * this.rnWarp[0][0] + p.getY() * this.rnWarp[0][1] +
                this.rnWarp[0][2])>>16;
        int y = (p.getX() * this.rnWarp[1][0] + p.getY() * this.rnWarp[1][1] +
                this.rnWarp[1][2])>>16;
        return new Vec2(x,y);
    }
View Full Code Here

TOP

Related Classes of jjil.core.Vec2

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.