示例#1
0
        /// <summary>
        /// Attempts to match a substroke with the current parameter. Returns
        /// some measure of dissimilarity (that is, smaller numbers are better)
        /// <remarks>Goodness measure is not comparable between AlignFeatures!</remarks>
        /// </summary>
        /// <param name="ss">The substroke to match</param>
        private double match(Substroke ss, Shape sp, AlignFeature af)
        {
            Featurefy.FeatureStroke fs = new Featurefy.FeatureStroke(ss);
            switch (af)
            {
            case AlignFeature.Curvature:
                return(Math.Abs(_tf[af] - fs.Curvature.AverageCurvature));

            case AlignFeature.AngleTraveled:
                return(Math.Abs(_tf[af] - fs.Curvature.TotalAngle));

            case AlignFeature.AngleTraveledRank:
                List <Substroke> ordered_substrokes = new List <Substroke>(sp.SubstrokesL);
                ordered_substrokes.Sort(delegate(Substroke lhs, Substroke rhs)
                {
                    Featurefy.FeatureStroke lfs = new Featurefy.FeatureStroke(lhs);
                    Featurefy.FeatureStroke rfs = new Featurefy.FeatureStroke(rhs);
                    return(rfs.Curvature.TotalAngle.CompareTo(lfs.Curvature.TotalAngle));
                });
                return(Math.Abs(_tf[af] - ordered_substrokes.IndexOf(ss)));

            case AlignFeature.Length:
                double total_length = 0.0;
                foreach (Substroke test in sp.SubstrokesL)
                {
                    total_length += test.SpatialLength;
                }
                return(Math.Abs(ss.SpatialLength / total_length - _tf[af]));

            case AlignFeature.LengthRank:
                List <Substroke> lr_ordered_substrokes = new List <Substroke>(sp.SubstrokesL);
                lr_ordered_substrokes.Sort(delegate(Substroke lhs, Substroke rhs)
                {
                    return(rhs.SpatialLength.CompareTo(lhs.SpatialLength));
                }
                                           );
                return(Math.Abs(_tf[af] - lr_ordered_substrokes.IndexOf(ss)));
            }
            return(0.0);
        }
示例#2
0
 /// <summary>
 /// Create a new SSA object to match against a single substroke
 /// </summary>
 /// <param name="ss">The Substroke to match against</param>
 /// <param name="s">The shape containing the important substroke</param>
 /// <param name="f">Which feature should we be aligning on the basis of?
 /// <example>Congeal.Prealign.AlignFeature.Length</example></param>
 public SingleStrokeAlign(Substroke ss, Shape s, AlignFeature f)
     : this(ss, s, new List <AlignFeature>(new AlignFeature[] { f }))
 {
     // Nothing to do here
 }