Exemplo n.º 1
0
        public static SketchStroke ResampleStroke(SketchStroke stroke, int n)
        {
            SketchStroke resampledStroke = new SketchStroke();

            List <SketchPoint> points    = new List <SketchPoint>();
            List <long>        timeStamp = new List <long>();

            // Copies the points and timeStamps list of the initial stroke
            foreach (SketchPoint p in stroke.Points)
            {
                points.Add(p);
            }
            foreach (long t in stroke.TimeStamp)
            {
                timeStamp.Add(t);
            }

            double totalLength = SketchStrokeFeatureExtraction.PathLength(stroke);
            double increment   = totalLength / (n - 1);
            double dist        = 0;

            resampledStroke.AppendPoint(points[0]);

            for (int i = 1; i < points.Count; i++)
            {
                SketchPoint cur = points[i];
                SketchPoint pre = points[i - 1];

                double d = MathHelpers.EuclideanDistance(cur, pre);

                if (dist + d >= increment)
                {
                    double qx = pre.X + ((increment - dist) / d) * (cur.X - pre.X);
                    double qy = pre.Y + ((increment - dist) / d) * (cur.Y - pre.Y);

                    SketchPoint q = new SketchPoint(qx, qy);

                    resampledStroke.AppendPoint(q);
                    points.Insert(i, q);

                    dist = 0.0;
                }
                else
                {
                    dist = dist + d;
                }
            }

            int oldTimeCount = timeStamp.Count;
            int newTimeCount = resampledStroke.Points.Count;

            for (int j = 0; j < newTimeCount; ++j)
            {
                int index = (int)((double)j / newTimeCount * oldTimeCount);
                resampledStroke.AppendTime(timeStamp[index]);
            }

            return(resampledStroke);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Concatenate two strokes s1, s2
 /// </summary>
 /// <param name="s1"></param>
 /// <param name="s2"></param>
 /// <returns>s1 + s2</returns>
 public static SketchStroke ConcatenateStrokes(SketchStroke s1, SketchStroke s2)
 {
     SketchStroke result = new SketchStroke();
     for (int i = 0; i < s1.PointsCount; i++)
     {
         result.AppendPoint(s1.Points[i]);
         result.AppendTime(s1.TimeStamp[i]);
     }
     for (int i = 0; i < s2.PointsCount; i++)
     {
         result.AppendPoint(s2.Points[i]);
         result.AppendTime(s2.TimeStamp[i]);
     }
     return result;
 }
Exemplo n.º 3
0
        public static SketchStroke ConcatenateStrokes(List<SketchStroke> strokes)
        {
            SketchStroke result = new SketchStroke();

            foreach (SketchStroke stroke in strokes)
            {
                for (int i = 0; i < stroke.PointsCount; i++)
                {
                    result.AppendPoint(stroke.Points[i]);
                    result.AppendTime(stroke.TimeStamp[i]);
                }
            }

            return result;
        }
Exemplo n.º 4
0
        public static async Task <Sketch> XMLToSketch(StorageFile file)
        {
            string text = await FileIO.ReadTextAsync(file);

            XDocument document = XDocument.Parse(text);

            int    minX  = Int32.Parse(document.Root.Attribute("frameMinX").Value);
            int    maxX  = Int32.Parse(document.Root.Attribute("frameMaxX").Value);
            int    minY  = Int32.Parse(document.Root.Attribute("frameMinY").Value);
            int    maxY  = Int32.Parse(document.Root.Attribute("frameMaxY").Value);
            string label = document.Root.Attribute("label").Value;
            List <SketchStroke> strokes = new List <SketchStroke>();

            // Itereates through each stroke element
            foreach (XElement element in document.Root.Elements())
            {
                // Initializes the stroke
                SketchStroke stroke = new SketchStroke();

                // Iterates through each point element
                double x, y;
                long   t;

                foreach (XElement pointElement in element.Elements())
                {
                    x = Double.Parse(pointElement.Attribute("x").Value);
                    y = Double.Parse(pointElement.Attribute("y").Value);
                    t = Int64.Parse(pointElement.Attribute("time").Value);

                    SketchPoint point = new SketchPoint(x, y);

                    stroke.AppendPoint(point);
                    stroke.AppendTime(t);
                }

                strokes.Add(stroke);
            }

            return(new Sketch(minX, maxX, minY, maxY, label, strokes));
        }