Exemple #1
0
 public unsafe void Copy(DisplacementMesh srcMesh, Point dstOffset, Rectangle srcRect)
 {
     for (int y = 0; y < srcRect.Height; ++y)
     {
         DisplacementVector *
             src = srcMesh.GetPointAddressUnchecked(srcRect.X, y + srcRect.Y),
             dst = this.GetPointAddressUnchecked(dstOffset.X, y + dstOffset.Y);
         for (int x = 0; x < srcRect.Width; ++x)
         {
             *dst = *src;
             ++src;
             ++dst;
         }
     }
 }
Exemple #2
0
        public unsafe DisplacementMesh Resize(Size size)
        {
            DisplacementMesh ret = new DisplacementMesh(size);

            float xfactor = (float)width / size.Width;
            float yfactor = (float)height / size.Height;

            for (int y = 0; y < size.Height; ++y)
            {
                DisplacementVector *ptr = ret.GetPointAddressUnchecked(0, y);
                float srcy = y * yfactor;;
                for (int x = 0; x < size.Width; ++x)
                {
                    float srcx           = x * xfactor;
                    DisplacementVector v = GetBilinearSample(srcx, srcy);
                    ptr->X = v.X / xfactor;
                    ptr->Y = v.Y / yfactor;
                    ++ptr;
                }
            }
            return(ret);
        }
        unsafe private void UpdatePointHorizontal(int px, int istart, int ystart, int yend)
        {
            CosineInterpolator left  = new CosineInterpolator();
            CosineInterpolator right = new CosineInterpolator();

            for (int j = 0; j < handlesy; ++j)
            {
                left.Add((j + points[istart, j].Y) * yspacing, points[istart, j].X * xspacing);
                right.Add((j + points[istart, j].Y) * yspacing, points[istart, j].X * xspacing);
            }

            for (int i = px - 1; i < px + 1; ++i)
            {
                if (i >= -1 && i < width)
                {
                    right = new CosineInterpolator();
                    for (int j = 0; j < handlesy; ++j)
                    {
                        right.Add((j + points[i + 1, j].Y) * yspacing, points[i + 1, j].X * xspacing);
                    }
                }

                float itoxleft  = i * xspacing;
                float itoxright = (i + 1) * xspacing;

                for (int y = ystart; y < yend; ++y)
                {
                    float
                        leftval  = -(float)(left.Interpolate(y)),
                        rightval = -(float)(right.Interpolate(y));

                    int x1 = (int)(itoxleft - leftval);
                    int x2 = (int)(itoxright - rightval) + 1;

                    float xdif = x2 - x1;

                    if (x1 < 0)
                    {
                        x1 = 0;
                    }
                    if (x2 > mesh.Width)
                    {
                        x2 = mesh.Width;
                    }

                    DisplacementVector *ptr = mesh.GetPointAddressUnchecked(x1, y);

                    for (int x = x1; x < x2; ++x)
                    {
                        float
                            lerp = (x - x1) / xdif,
                            val  = lerp * rightval + (1 - lerp) * leftval;

                        ptr->X = val;
                        ++ptr;
                    }
                }

                left = right;
            }
        }