Beispiel #1
0
 static void so_stitching_points_append(so_stitching_points_t points, so_stitching_points_t other)
 {
     so_stitching_point_t[] newPoints = new so_stitching_point_t[points.capacity + other.capacity];
     for (int i = 0; i < points.count; i++)
     {
         newPoints[i] = points.points[i];
     }
     for (int i = 0; i < other.count; i++)
     {
         newPoints[i + points.count] = other.points[i];
     }
     points.points   = newPoints;
     points.capacity = points.capacity + other.capacity;
     points.count    = points.count + other.count;
 }
Beispiel #2
0
    static void so_seam_add(so_seam_t seam, so_stitching_point_t point)
    {
        for (int side = 0; side < 2; side++)
        {
            for (int texel = 0; texel < 4; texel++)
            {
                so_texel_t t = point.sides[side].texels[texel];
                seam.x_min = Mathf.Min(t.x, seam.x_min);
                seam.y_min = Mathf.Min(t.y, seam.y_min);
                seam.x_max = Mathf.Max(t.x, seam.x_min);
                seam.y_max = Mathf.Max(t.y, seam.y_min);
            }
            so_texel_set_add(seam.texels, point.sides[side].texels, 4);
        }

        so_stitching_points_add(seam.stitchingPoints, point);
    }
Beispiel #3
0
    static void so_seams_add_seam(List <so_seam_t> seams, Vector2 a0, Vector2 a1, Vector2 b0, Vector2 b1, Color[] data, int w, int h, int c)
    {
        Vector2 s = new Vector2(w - 1, h - 1);

        a0 = Extensions.Multiply(a0, s);
        a1 = Extensions.Multiply(a1, s);
        b0 = Extensions.Multiply(b0, s);
        b1 = Extensions.Multiply(b1, s);
        Vector2 ad         = a1 - a0;
        Vector2 bd         = b1 - b0;
        float   l          = Mathf.Max(ad.magnitude, bd.magnitude);
        int     iterations = (int)(l * 5.0f);     // TODO: is this the best value?
        float   step       = 1.0f / iterations;

        so_seam_t currentSeam = new so_seam_t();

        currentSeam.x_min = w; currentSeam.y_min = h;
        currentSeam.x_max = 0; currentSeam.y_max = 0;

        // so_seam_alloc
        currentSeam.stitchingPoints = new so_stitching_points_t(iterations + 1);
        currentSeam.texels          = new so_texel_set_t();

        for (int i = 0; i <= iterations; i++)
        {
            float   t = i * step;
            Vector2 a = a0 + ad * t;
            Vector2 b = b0 + bd * t;
            // Kanglai: shouldn't be Round here
            int   ax = Mathf.FloorToInt(a.x), ay = Mathf.FloorToInt(a.y);
            int   bx = Mathf.FloorToInt(b.x), by = Mathf.FloorToInt(b.y);
            float au = a.x - ax, av = a.y - ay, nau = 1.0f - au, nav = 1.0f - av;
            float bu = b.x - bx, bv = b.y - by, nbu = 1.0f - bu, nbv = 1.0f - bv;

            so_texel_t ta0 = new so_texel_t(ax, ay);
            so_texel_t ta1 = new so_texel_t(Mathf.Min(ax + 1, w - 1), ay);
            so_texel_t ta2 = new so_texel_t(ax, Mathf.Min(ay + 1, h - 1));
            so_texel_t ta3 = new so_texel_t(Mathf.Min(ax + 1, w - 1), Mathf.Min(ay + 1, h - 1));

            so_texel_t tb0 = new so_texel_t(bx, by);
            so_texel_t tb1 = new so_texel_t(Mathf.Min(bx + 1, w - 1), by);
            so_texel_t tb2 = new so_texel_t(bx, Mathf.Min(by + 1, h - 1));
            so_texel_t tb3 = new so_texel_t(Mathf.Min(bx + 1, w - 1), Mathf.Min(by + 1, h - 1));

            /*
             * so_fill_with_closest(ta0.x, ta0.y, data, w, h, c);
             * so_fill_with_closest(ta1.x, ta1.y, data, w, h, c);
             * so_fill_with_closest(ta2.x, ta2.y, data, w, h, c);
             * so_fill_with_closest(ta3.x, ta3.y, data, w, h, c);
             *
             * so_fill_with_closest(tb0.x, tb0.y, data, w, h, c);
             * so_fill_with_closest(tb1.x, tb1.y, data, w, h, c);
             * so_fill_with_closest(tb2.x, tb2.y, data, w, h, c);
             * so_fill_with_closest(tb3.x, tb3.y, data, w, h, c);
             */
            so_stitching_point_t sp = new so_stitching_point_t();
            sp.sides[0].texels[0] = ta0;
            sp.sides[0].texels[1] = ta1;
            sp.sides[0].texels[2] = ta2;
            sp.sides[0].texels[3] = ta3;

            sp.sides[0].weights[0] = nau * nav;
            sp.sides[0].weights[1] = au * nav;
            sp.sides[0].weights[2] = nau * av;
            sp.sides[0].weights[3] = au * av;

            sp.sides[1].texels[0] = tb0;
            sp.sides[1].texels[1] = tb1;
            sp.sides[1].texels[2] = tb2;
            sp.sides[1].texels[3] = tb3;

            sp.sides[1].weights[0] = nbu * nbv;
            sp.sides[1].weights[1] = bu * nbv;
            sp.sides[1].weights[2] = nbu * bv;
            sp.sides[1].weights[3] = bu * bv;

            so_seam_add(currentSeam, sp);
        }
        so_seam_t dstSeam = null;

        for (int i = 0; i < seams.Count; i++)
        {
            so_seam_t seam = seams[i];
            // Kanglai: we put seams that intersects together
            if (so_seams_intersect(currentSeam, seam))
            {
                if (dstSeam == null)                 // found a seam that the edge is connected to . add current edge to that seam
                {
                    so_seams_in_place_merge(seam, currentSeam);
                    dstSeam = seam;
                }
                else                 // found another seam that the edge is connected to . merge those seams
                {
                    so_seams_in_place_merge(dstSeam, seam);

                    // remove current seam from seams
                    seams.Remove(seam);
                    i--;
                }
            }
        }
        if (dstSeam == null)         // did not find a seam that the edge is connected to . make a new one
        {
            seams.Add(currentSeam);
        }
    }
Beispiel #4
0
 static void so_stitching_points_add(so_stitching_points_t points, so_stitching_point_t point)
 {
     Debug.Assert(points.count < points.capacity);
     points.points[points.count++] = point;
 }