/// <summary>
        /// Try to match the specified glyphs. Returns null if the match fails.
        /// </summary>
        /// <param name="src">Source.</param>
        /// <param name="tgt">Target.</param>
        public override GlyphMatch Match(Glyph src, Glyph tgt)
        {
//            Debug.Log("GetDifference: " + src.name + " ~ " + tgt.name);
            int[] indexMatch = MatchStrokes(src, tgt);

            if (indexMatch == null)
            {
                return(null);                   //failed
            }
            GlyphMatch.StrokeMatch[] matches = new GlyphMatch.StrokeMatch[indexMatch.Length];
            for (int i = 0; i < indexMatch.Length; i++)
            {
                int j = indexMatch[i];
                matches[i] = matchMatrix[i, j];
            }
            float costSum = 0, weight = 0;

            foreach (GlyphMatch.StrokeMatch sm in matches)
            {
                costSum += sm.cost; weight += sm.weight;
            }
            GlyphMatch result = new GlyphMatch(src, tgt, matches, Mathf.Sqrt(costSum / weight), threshold);

            src         = null; tgt = null; //matches = null;
            matchMatrix = null; error = null;
            return(result);
        }
Exemple #2
0
 /// <summary>
 /// Sets this stroke to a lerp state of a stroke match.
 /// </summary>
 /// <param name="strokeMatch">Stroke Match.</param>
 /// <param name="t">T.</param>
 public void SetToMatchLerp(GlyphMatch.StrokeMatch strokeMatch, float t)
 {
     if (points.Length != strokeMatch.Length)
     {
         points = new Vector2[strokeMatch.Length];                //Resize points array
     }
     for (int index = 0; index < Length; index++)
     {
         points[index] = strokeMatch[index, t];
     }
 }
Exemple #3
0
        protected virtual GlyphMatch FinalizeMatch(Glyph src, Glyph tgt, int[] indexMatch)
        {
            if (indexMatch == null)
            {
                return(null);                   //failed
            }
            GlyphMatch.StrokeMatch[] matches = new GlyphMatch.StrokeMatch[indexMatch.Length];
            for (int i = 0; i < indexMatch.Length; i++)
            {
                int j = indexMatch[i];
                srcStroke  = src[i]; tgtStroke = tgt[j];
                matches[i] = GetStrokeMatch(error[i, j], directMatch[i, j]);// matchMatrix[i, j];

                if (matches[i] == null)
                {
                    return(null);
                }
//				if (matches[i]==null){
//					Debug.Log ("Match "+i+"-"+j+" failed.");
//					return null;
//				}
//				else{
//	                float meanCost = (float)Math.Sqrt(matches[i].cost / matches[i].weight);
//	                Debug.Log("MeanCost(" + i + "," + j + "): " + matches[i].cost + " / " + matches[i].weight + " (" + meanCost + ")");
//				}
            }
            srcStroke = null; tgtStroke = null;

            float costSum = 0, weight = 0;

            foreach (GlyphMatch.StrokeMatch sm in matches)
            {
                costSum += sm.cost; weight += sm.weight;
            }
            GlyphMatch result = new GlyphMatch(src, tgt, matches, Mathf.Sqrt(costSum / weight), threshold);

            src         = null; tgt = null;
            directMatch = null; error = null;
            return(result);
        }