Exemplo n.º 1
0
        private void DrawStrokePart(StrokePart part, Graphics graphics, Pen pen1, Pen pen2)
        {
            Vector2f topLeft = new Vector2f(10, 10);
            Vector2f scale   = new Vector2f(0.01f, 0.01f);

            if (allStrokes.Count > 0)
            {
                KanjiMatcher.CalcResize(allStrokes, matchedTemplate, out topLeft, out scale);
            }

            graphics.DrawLine(pen1,
                              new PointF(topLeft.X + part.StartPoint.X / scale.X, topLeft.Y + part.StartPoint.Y / scale.Y),
                              new PointF(topLeft.X + part.EndPoint.X / scale.X, topLeft.Y + part.EndPoint.Y / scale.Y));
            const int sections = 64;

            PointF[] roundPoints = new PointF[sections + 1];
            Vector2f delta       = part.EndPoint - part.StartPoint;
            Vector2f ortho       = new Vector2f(delta.Y, -delta.X);

            for (int i = 0; i <= sections; i++)
            {
                float    pos   = (float)i / sections;
                Vector2f point = part.GetGlobalFromProgress(pos);
                float    param = 1 - (2 * pos - 1) * (2 * pos - 1);
                point          = topLeft + new Vector2f(point.X / scale.X, point.Y / scale.Y);
                roundPoints[i] = new PointF(point.X, point.Y);
            }
            graphics.DrawLines(pen2, roundPoints);
        }
        StrokePartMatch MatchLine(int start, int end)
        {
            StrokePart line  = new StrokePart(Input[start], Input[end]);
            float      multi = line.Length * 0.5f;

            float a = 0, b = 0, c = 0;            //Parabel coefficients

            for (int i = start; i <= end; i++)
            {
                Vector2f point           = Input[i];
                float    weight          = Weight[i];
                float    scaledX         = line.GetParallelPositionScaled(point);
                float    unscaledY       = line.GetOrthoPositionUnscaled(point);
                float    unscaledOutside = (Math.Abs(scaledX) - 1) * multi;
                if (unscaledOutside > 0)
                {
                    c += weight * (unscaledOutside * unscaledOutside + unscaledY * unscaledY);
                }
                else
                {
                    float param = (1 - scaledX * scaledX) * multi;
                    a += weight * param * param;
                    b += weight * (-2) * param * unscaledY;
                    c += weight * unscaledY * unscaledY;
                }
            }
            float optimalCurve = -b / (2 * a);
            var   result       = new StrokePartMatch(line.StartPoint, line.EndPoint, optimalCurve);

            result.DeltaCurveCost = a;
            result.MinCost        = c - b * b / (4 * a);

            return(result);
        }
Exemplo n.º 3
0
        public static string StrokeToString(IEnumerable <StrokePart> parts)
        {
            List <StrokePart> partsList = parts.ToList();
            string            result    = "";

            for (int i = 0; i < partsList.Count; i++)
            {
                StrokePart part       = partsList[i];
                bool       includeEnd = i == partsList.Count - 1;
                result += part.ToString(includeEnd);
            }
            return(result);
        }
Exemplo n.º 4
0
        private void DrawStrokePart(StrokePart part, Graphics graphics, Pen pen1, Pen pen2)
        {
            Vector2f topLeft = new Vector2f(10, 10);
            Vector2f scale = new Vector2f(0.01f, 0.01f);
            if (allStrokes.Count > 0)
                KanjiMatcher.CalcResize(allStrokes, matchedTemplate, out topLeft, out scale);

            graphics.DrawLine(pen1,
                new PointF(topLeft.X + part.StartPoint.X / scale.X, topLeft.Y + part.StartPoint.Y / scale.Y),
                new PointF(topLeft.X + part.EndPoint.X / scale.X, topLeft.Y + part.EndPoint.Y / scale.Y));
            const int sections = 64;
            PointF[] roundPoints = new PointF[sections + 1];
            Vector2f delta = part.EndPoint - part.StartPoint;
            Vector2f ortho = new Vector2f(delta.Y, -delta.X);
            for (int i = 0; i <= sections; i++)
            {
                float pos = (float)i / sections;
                Vector2f point = part.GetGlobalFromProgress(pos);
                float param = 1 - (2 * pos - 1) * (2 * pos - 1);
                point = topLeft + new Vector2f(point.X / scale.X, point.Y / scale.Y);
                roundPoints[i] = new PointF(point.X, point.Y);
            }
            graphics.DrawLines(pen2, roundPoints);
        }
Exemplo n.º 5
0
 public override string ToString()
 {
     return(StrokePart.StrokeToString(Parts));
 }
        StrokePartMatch MatchLine(int start, int end)
        {
            StrokePart line = new StrokePart(Input[start], Input[end]);
            float multi = line.Length* 0.5f;

            float a = 0, b = 0, c = 0;//Parabel coefficients
            for (int i = start; i <= end; i++)
            {
                Vector2f point = Input[i];
                float weight = Weight[i];
                float scaledX = line.GetParallelPositionScaled(point);
                float unscaledY = line.GetOrthoPositionUnscaled(point);
                float unscaledOutside = (Math.Abs(scaledX) - 1) * multi;
                if (unscaledOutside > 0)
                {
                    c += weight * (unscaledOutside * unscaledOutside + unscaledY  *unscaledY  );
                }
                else
                {
                    float param = (1 - scaledX * scaledX) * multi;
                    a += weight * param * param;
                    b += weight * (-2) * param * unscaledY;
                    c += weight * unscaledY * unscaledY;
                }
            }
            float optimalCurve = -b / (2 * a);
            var result = new StrokePartMatch(line.StartPoint, line.EndPoint, optimalCurve);
            result.DeltaCurveCost = a;
            result.MinCost = c - b * b / (4 * a);

            return result;
        }