Exemplo n.º 1
0
        /// <summary>
        /// Get normalized strokes. Call "ClearCache" function for recalculating
        /// </summary>
        /// <param name="height">Height of bounding box after the normalization</param>
        /// <param name="sortPos">Sort strokes in order of x coordinate of gravity point</param>
        /// <returns></returns>
        public List<AnalysisPenStroke> GetNormalizedStrokes(double height, bool sortPos)
        {
            if (this.normalizedStrokes == null)
            {
                List<AnalysisPenStroke> strokes = new List<AnalysisPenStroke>(this.Strokes);
                Rect gr = GetBounds();
                double scale = height / gr.Height;

                // position sort
                if (sortPos)
                {
                    strokes = AnalysisPenStroke.SortByCenterX(strokes);
                }

                // normalization
                List<AnalysisPenStroke> nstrokes = new List<AnalysisPenStroke>();
                foreach (AnalysisPenStroke s in strokes)
                {
                    AnalysisPenStroke ns = new AnalysisPenStroke();
                    Rect sr = s.BoundingBox;
                    foreach (AnalysisPenPoint p in s.Points)
                    {
                        AnalysisPenPoint np = new AnalysisPenPoint(p.Time, (p.X - sr.Left) * scale, (p.Y - sr.Top) * scale);
                        ns.Points.Add(np);
                        //Console.Write("(" + np.X + "," + np.Y + "),");
                    }
                    nstrokes.Add(ns);
                    //Console.WriteLine();
                }
                this.normalizedStrokes = nstrokes;
            }

            return this.normalizedStrokes;
        }
        /// <summary>
        /// Generate stroke object from serialized json string
        /// </summary>
        /// <param name="jsonStr"></param>
        public AnalysisPenStroke(String jsonStr)
        {
            var json = DynamicJson.Parse(jsonStr);

            this.Points = new List<AnalysisPenPoint>();
            foreach (var p in json.stroke)
            {
                AnalysisPenPoint ppoint = new AnalysisPenPoint((ulong)p.time, (int)p.x, (int)p.y);
                this.Points.Add(ppoint);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Join an answer step after the answer step
        /// </summary>
        /// <param name="step"></param>
        public void JoinStrokes(AnswerStep step)
        {
            // Calculate offset value for coordinate transformation
            Rect orgBounds = this.GetBounds();
            Rect addBounds = step.GetBounds();
            Point endPoint = new Point(orgBounds.Left, (orgBounds.Top + orgBounds.Bottom) / 2.0);
            Point startPoint = new Point(addBounds.Left, (addBounds.Top + addBounds.Bottom) / 2.0);
            Point offsetPoint = new Point(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y);

            // transform coordinates to join anter the origin strokes
            foreach (AnalysisPenStroke addStroke in step.Strokes)
            {
                AnalysisPenStroke s = new AnalysisPenStroke();
                foreach (AnalysisPenPoint addPoint in addStroke.Points)
                {
                    AnalysisPenPoint p = new AnalysisPenPoint(addPoint.Time, addPoint.X + offsetPoint.X, addPoint.Y + offsetPoint.Y);
                    s.Points.Add(p);
                }
                this.Strokes.Add(s);
            }
        }