示例#1
0
        private void afficherTraitsClassique()
        {
            strokes = ((DrawingWindowViewModel)(DataContext)).Traits;
            var tasks = new List <Task <(int Index, bool IsDone)> >();


            foreach (Stroke stroke in strokes)
            {
                StylusPointCollection points = new StylusPointCollection();
                Timer timer = new Timer();
                timer.Interval = 10;
                timer.Start();

                int index = 0;

                timer.Tick += (s, a) =>
                {
                    StylusPoint point = stroke.StylusPoints[index];
                    var         x     = (float)point.X;
                    var         y     = (float)point.Y;

                    points.Add(new StylusPoint(x, y));

                    inkPresenter.Strokes.Add(new Stroke(points));

                    index++;
                    if (index >= stroke.StylusPoints.Count)
                    {
                        timer.Stop();
                    }
                };
            }
        }
示例#2
0
 private void ExpertInkCanvas_ExpertStrokeLoadedEvent(object sender, ExpertInkCanvas.ExpertStrokeLoadedEventEventArgs e)
 {
     IsExpertStrokeLoaded   = e.state;
     ExpertStrokeCollection = e.strokes;
     ExpertStroke           = ExpertStrokeCollection[StudentStrokeCount];
     ExpertStylusPoint      = ExpertStroke.StylusPoints.First();
 }
示例#3
0
        /// <summary>
        /// 返回起始点和结束点中间的所有中间点的坐标
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        private StylusPoint[] getMidPoints(StylusPoint start, StylusPoint end)
        {
            StylusPoint[] results  = { start, end };
            double        distance = MathTool.getInstance().distanceP2P(start, end);

            int numofmidpoints = (int)(distance / DIS_SEP) - 1;

            if (numofmidpoints <= 0)
            {
                return(results);
            }
            StylusPoint[] midpoints = new StylusPoint[numofmidpoints];
            int           offx      = (int)(end.X - start.X);
            int           offy      = (int)(end.Y - start.Y);

            for (int i = 0; i < numofmidpoints; i++)
            {
                midpoints[i]   = new StylusPoint();
                midpoints[i].X = start.X + offx * (i + 1) / (numofmidpoints + 1);
                midpoints[i].Y = start.Y + offy * (i + 1) / (numofmidpoints + 1);
            }
            results    = new StylusPoint[2 + numofmidpoints];
            results[0] = start;
            for (int i = 1; i < numofmidpoints + 1; i++)
            {
                results[i] = midpoints[i - 1];
            }
            results[1 + numofmidpoints] = end;
            return(results);
        }
        public static Rect getBoundBox(StrokeCollection strokes)
        {
            double minX = strokes[0].StylusPoints[0].X;
            double minY = strokes[0].StylusPoints[0].Y;

            double maxX = strokes[0].StylusPoints[0].X;
            double maxY = strokes[0].StylusPoints[0].Y;

            for (int j = 0; j < strokes.Count; j++)
            {
                Stroke stroke = strokes[j];
                for (int i = 0; i < stroke.StylusPoints.Count; i++)
                {
                    StylusPoint p = stroke.StylusPoints[i];
                    if (p.X > maxX)
                    {
                        maxX = p.X;
                    }
                    if (p.X < minX)
                    {
                        minX = p.X;
                    }
                    if (p.Y > maxY)
                    {
                        maxY = p.Y;
                    }
                    if (p.Y < minY)
                    {
                        minY = p.Y;
                    }
                }
            }
            return(new Rect(new Point(minX, minY), new Point(maxX, maxY)));
        }
示例#5
0
        void ClonePoints()
        {
            //<Snippet18>
            Point[] rawPoints = new Point[]
            {
                new Point(100, 100),
                new Point(100, 200),
                new Point(200, 250),
                new Point(300, 300)
            };

            StylusPointCollection points1 = new StylusPointCollection(rawPoints);

            // Create a copy of points1 and change the second StylusPoint.
            StylusPointCollection points2 = points1.Clone();

            points2[1] = new StylusPoint(200, 100);

            // Create a stroke from each StylusPointCollection and add them to
            // inkCanvas1. Note that changing a StylusPoint in point2 did not
            // affect points1.
            Stroke stroke1 = new Stroke(points1);

            inkCanvas1.Strokes.Add(stroke1);

            Stroke stroke2 = new Stroke(points2);

            stroke2.DrawingAttributes.Color = Colors.Red;
            inkCanvas1.Strokes.Add(stroke2);
            //</Snippet18>
        }
        public static Stroke LineToSingleArrow(Stroke originalStroke)
        {
            StylusPoint pB1 = originalStroke.StylusPoints[originalStroke.StylusPoints.Count - 1];
            StylusPoint pB2 = originalStroke.StylusPoints[0];

            double slopy, cosy, siny;
            double Par = 20.0;              //length of Arrow (>)

            slopy = Math.Atan2((pB1.Y - pB2.Y), (pB1.X - pB2.X));
            cosy  = Math.Cos(slopy);
            siny  = Math.Sin(slopy);

            //side 1
            originalStroke.StylusPoints.Add(new StylusPoint(
                                                pB1.X + (-Par * cosy - (Par / 2.0 * siny)),
                                                pB1.Y + (-Par * siny + (Par / 2.0 * cosy))));

            originalStroke.StylusPoints.Add(pB1);

            //side 2
            originalStroke.StylusPoints.Add(new StylusPoint(
                                                pB1.X + (-Par * cosy + (Par / 2.0 * siny)),
                                                pB1.Y - (Par / 2.0 * cosy + Par * siny)));

            originalStroke.StylusPoints.Add(pB1);

            return(originalStroke);
        }
        public static Stroke LineToOctagon(Stroke originalStroke)
        {
            StylusPoint           start = originalStroke.StylusPoints[0];
            double                r     = originalStroke.GetBounds().Width * 0.5;
            double                y     = originalStroke.GetBounds().Top;
            double                x     = start.X;
            StylusPointCollection s     = new StylusPointCollection();

            s.Add(new StylusPoint(x + r, y));
            s.Add(new StylusPoint(r + x, -0.4142 * r + y));
            s.Add(new StylusPoint(0.7071 * r + x, -0.7071 * r + y));
            s.Add(new StylusPoint(0.4142 * r + x, -r + y));
            s.Add(new StylusPoint(x, -r + y));

            s.Add(new StylusPoint(-0.4142 * r + x, -r + y));
            s.Add(new StylusPoint(-0.7071 * r + x, -0.7071 * r + y));
            s.Add(new StylusPoint(-r + x, -0.4142 * r + y));
            s.Add(new StylusPoint(-r + x, y));
            s.Add(new StylusPoint(-r + x, 0.4142 * r + y));
            s.Add(new StylusPoint(-0.7071 * r + x, 0.7071 * r + y));
            s.Add(new StylusPoint(-0.4142 * r + x, r + y));
            s.Add(new StylusPoint(x, r + y));
            s.Add(new StylusPoint(0.4142 * r + x, r + y));
            s.Add(new StylusPoint(0.7071 * r + x, 0.7071 * r + y));
            s.Add(new StylusPoint(r + x, 0.4142 * r + y));
            s.Add(new StylusPoint(r + x, y));

            Stroke st = new Stroke(s);

            return(st);
        }
        /// <summary>
        /// 获取关键点
        /// </summary>
        /// <param name="intervalLength"></param>
        private void getKeyPoints(int intervalLength)
        {
            StylusPointCollection spc = trackStroke.StylusPoints;
            int firstIndex            = 0;

            keyPoints.Add(spc[firstIndex]);
            double distance = 0;

            for (int i = firstIndex; i < spc.Count - 1; i++)
            {
                double distanc2P = MathTool.getInstance().distanceP2P(spc[i + 1], spc[i]);
                distance += distanc2P;
                int offsetDistance = (int)distance - intervalLength;
                if (offsetDistance > 3)//处理两点间隔距离过大的情况,向中间添加点
                {
                    StylusPoint addPoint = MathTool.getInstance().getPointInLine(spc[i + 1], spc[i], distanc2P - offsetDistance);
                    spc.Add(new StylusPoint(0, 0));
                    for (int j = spc.Count - 2; j > i; j--)
                    {
                        spc[j + 1] = new StylusPoint(spc[j].X, spc[j].Y);
                    }
                    spc[i + 1] = new StylusPoint(addPoint.X, addPoint.Y);
                    //drawPoint(spc[i+1].X, spc[i+1].Y,Colors.Green);
                    keyPoints.Add(spc[i + 1]);
                    distance = 0;
                }
                else if (Math.Abs(offsetDistance) <= 3)
                {
                    //drawPoint(spc[i + 1].X, spc[i + 1].Y, Colors.Blue);
                    keyPoints.Add(spc[i + 1]);
                    distance = 0;
                }
            }
        }
        public void Update()
        {
            double Mass1X = X0 + L1 * Math.Sin(Phi1);
            double Mass1Y = Y0 + L1 * Math.Cos(Phi1);
            double Mass2X = Mass1X + L2 * Math.Sin(Phi2);
            double Mass2Y = Mass1Y + L2 * Math.Cos(Phi2);

            SetSize(mass1, 2 * M1);
            SetSize(mass2, 2 * M2);
            SetPosition(mass1, Mass1X - M1, Mass1Y - M1);
            SetPosition(mass2, Mass2X - M2, Mass2Y - M2);
            SetPosition(Arm1, X0, Y0, Mass1X, Mass1Y);
            SetPosition(Arm2, Mass1X, Mass1Y, Mass2X, Mass2Y);

            var sp = new StylusPoint(Mass2X, Mass2Y);

            if (col == null || col.Count >= 1000)
            {
                var ncol = new StylusPointCollection();
                if (col != null)
                {
                    ncol.Add(col.Last());
                }
                ncol.Add(sp);
                stroke = new Stroke(ncol);
                stroke.DrawingAttributes.Color = Colors.Blue;
                _ink.Strokes.Add(stroke);
                col = ncol;
            }
            else
            {
                col.Add(sp);
            }
        }
示例#10
0
        private void MoveDotAndRobotToStylusPoint(StylusPoint stylusPt)
        {
            var pt = stylusPt.ToPoint();

            if (dot.Visibility == Visibility.Visible)
            {
                dotTranslateTransform.X = pt.X - (inkCanvas.ActualWidth / 2);
                dotTranslateTransform.Y = pt.Y - (inkCanvas.ActualHeight / 2);
            }

            //TODO :: handle case where drawDimensionSize is less than the inkCanvas.Strokes size
            // Apply the scalingFactor to the point that the robot will draw.
            // FOR TESTING
            if (!isShowingDrawZone)
            {
                // get the scaleFactor between the (inkSize + (drawDimensionSize - inkSize))
                // and  the actual inkSize.

                // TODO :: establish a new origin to be the Top Left of the Draw Rectangle
                double scaleFactorX = (drawZoneRect.Width / (inkCanvas.ActualWidth));
                double scaleFactorY = (drawZoneRect.Height / (inkCanvas.ActualHeight));

                pt.X = (pt.X * scaleFactorX) + drawZoneRect.Left;
                pt.Y = (pt.Y * scaleFactorY) + drawZoneRect.Top;
            }

            // Send the point to the robot too.
            // Leave the arm in its current down state.
            RobotArm.Move(pt);
        }
        private double PerpendicularDistance(StylusPoint pt, StylusPoint lineStart, StylusPoint lineEnd)
        {
            double dx = lineEnd.X - lineStart.X;
            double dy = lineEnd.Y - lineStart.Y;

            // Normalize
            double mag = Math.Sqrt(dx * dx + dy * dy);

            if (mag > 0.0)
            {
                dx /= mag;
                dy /= mag;
            }
            double pvx = pt.X - lineStart.X;
            double pvy = pt.Y - lineStart.Y;

            // Get dot product (project pv onto normalized direction)
            double pvdot = dx * pvx + dy * pvy;

            // Scale line direction vector and subtract it from pv
            double ax = pvx - pvdot * dx;
            double ay = pvy - pvdot * dy;

            return(Math.Sqrt(ax * ax + ay * ay));
        }
示例#12
0
        private void DrawAreaButton_Click(object sender, RoutedEventArgs e)
        {
            StylusPoint[] edgePoints = new StylusPoint[4];

            // Set index 0 as the starting top-left corner
            edgePoints[0].Y = drawZoneRect.Top;
            edgePoints[0].X = drawZoneRect.Left;

            // Set index 1 as the starting bottom-left corner
            edgePoints[1].Y = drawZoneRect.Bottom;
            edgePoints[1].X = targetArea == 0   // the code below is added adjust the bottom left dot
                ? drawZoneRect.Left + 30
                : targetArea == -1
                ? drawZoneRect.Left + 15
                : targetArea == -2
                ? drawZoneRect.Left + 10
                : drawZoneRect.Left;

            // Set index 2 as the starting bottom-right corner
            edgePoints[2].Y = drawZoneRect.Bottom;
            edgePoints[2].X = drawZoneRect.Right;

            // Set index 3 as the starting top-right corner
            edgePoints[3].Y = drawZoneRect.Top;
            edgePoints[3].X = drawZoneRect.Right;

            // flag is true so we dont apply scaling factor
            isShowingDrawZone = true;
            MoveRobotToShowDrawZone(edgePoints);
            isShowingDrawZone = false;
        }
示例#13
0
        public override void _presenter_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            _inkCanvas.CaptureMouse();
            selectedStrokes = _inkCollector.SelectedStrokes;
            selectImages    = _inkCollector.SelectedImages;
            selectedButtons = _inkCollector.SelectButtons;

            if (selectedStrokes.Count > 0 || selectImages.Count > 0 || selectedButtons.Count > 0)
            {
                _center = _inkCollector.CenterSelect;
                Point start = e.GetPosition(_inkCanvas);
                _startPoint = new StylusPoint(start.X, start.Y);
                _prepoint   = _startPoint;
                if (selectImages.Count > 0)
                {
                    foreach (MyImage myimage in selectImages)
                    {
                        preImageAngleList.Add(myimage.Angle);
                    }
                }
                if (selectedButtons.Count > 0)
                {
                    foreach (MyButton myButton in selectedButtons)
                    {
                        preButtonAngleList.Add(myButton.Angle);
                    }
                }
            }
            pressedMouseLeftButtonDown = true;
        }
示例#14
0
        private void StrokeArrowConvert(System.Windows.Ink.Stroke stroke)
        {
            //Console.WriteLine("Stroke Completed");
            double toRadians = Math.PI / 180.0;
            StylusPointCollection ptsRect = new StylusPointCollection();
            StylusPointCollection pts     = stroke.StylusPoints;

            StylusPoint pt1 = pts[pts.Count - 1];
            StylusPoint pt2 = pts[0];

            ptsRect.Add(pt1);
            ptsRect.Add(pt2);
            //compute arrow head
            double arrowAngle = 30.0 * toRadians;
            double deltaX     = pt2.X - pt1.X;
            double deltaY     = pt2.Y - pt1.Y;
            double theta      = Math.Atan2(deltaY, deltaX); //radians
            double x1         = Math.Cos(theta + arrowAngle);
            double x2         = Math.Cos(theta - arrowAngle);
            double y1         = Math.Sin(theta + arrowAngle);
            double y2         = Math.Sin(theta - arrowAngle);
            double mag        = 10.0; //arrorhead line length

            ptsRect.Add(new StylusPoint(pt2.X - mag * x1, pt2.Y - mag * y1));
            ptsRect.Add(new StylusPoint(pt2.X, pt2.Y));
            ptsRect.Add(new StylusPoint(pt2.X - mag * x2, pt2.Y - mag * y2));
            stroke.StylusPoints = ptsRect;
            stroke.DrawingAttributes.FitToCurve = false;
        }
示例#15
0
        /// <summary>
        /// Gets a StrokeNode at the specified index that connects to a stroke at the previousIndex
        /// previousIndex can be -1 to signify it should be empty (first strokeNode)
        /// </summary>
        /// <returns></returns>
        internal StrokeNode this[int index, int previousIndex]
        {
            get
            {
                if (_stylusPoints == null || index < 0 || index >= _stylusPoints.Count || previousIndex < -1 || previousIndex >= index)
                {
                    throw new IndexOutOfRangeException();
                }

                StylusPoint stylusPoint            = _stylusPoints[index];
                StylusPoint previousStylusPoint    = (previousIndex == -1 ? new StylusPoint() : _stylusPoints[previousIndex]);
                float       pressureFactor         = 1.0f;
                float       previousPressureFactor = 1.0f;
                if (_usePressure)
                {
                    pressureFactor         = StrokeNodeIterator.GetNormalizedPressureFactor(stylusPoint.PressureFactor);
                    previousPressureFactor = StrokeNodeIterator.GetNormalizedPressureFactor(previousStylusPoint.PressureFactor);
                }

                StrokeNodeData nodeData     = new StrokeNodeData((Point)stylusPoint, pressureFactor);
                StrokeNodeData lastNodeData = StrokeNodeData.Empty;
                if (previousIndex != -1)
                {
                    lastNodeData = new StrokeNodeData((Point)previousStylusPoint, previousPressureFactor);
                }

                //we use previousIndex+1 because index can skip ahead
                return(new StrokeNode(_operations, previousIndex + 1, nodeData, lastNodeData, index == _stylusPoints.Count - 1 /*Is this the last node?*/));
            }
        }
示例#16
0
 internal StrokeNode this[int index, int previousIndex]
 {
     get
     {
         if (_stylusPoints == null || index < 0 || index >= _stylusPoints.Count || previousIndex < -1 || previousIndex >= index)
         {
             throw new IndexOutOfRangeException();
         }
         StylusPoint stylusPoint  = _stylusPoints[index];
         StylusPoint stylusPoint2 = (previousIndex == -1) ? default(StylusPoint) : _stylusPoints[previousIndex];
         float       pressure     = 1f;
         float       pressure2    = 1f;
         if (_usePressure)
         {
             pressure  = GetNormalizedPressureFactor(stylusPoint.PressureFactor);
             pressure2 = GetNormalizedPressureFactor(stylusPoint2.PressureFactor);
         }
         StrokeNodeData nodeData     = new StrokeNodeData((System.Windows.Point)stylusPoint, pressure);
         StrokeNodeData lastNodeData = StrokeNodeData.Empty;
         if (previousIndex != -1)
         {
             lastNodeData = new StrokeNodeData((System.Windows.Point)stylusPoint2, pressure2);
         }
         return(new StrokeNode(_operations, previousIndex + 1, nodeData, lastNodeData, index == _stylusPoints.Count - 1));
     }
 }
示例#17
0
        public void ChangeStylusPoints()
        {
            if (strokes != null)
            {
                return;
            }

            wpf.Point[] points = new wpf.Point[] { new wpf.Point(0, 100), new wpf.Point(200, 200) };

            StylusPointCollection stylusPoints = new StylusPointCollection(points);

            wpf.Ink.Stroke stroke1 = new System.Windows.Ink.Stroke(stylusPoints);
            wpf.Ink.Stroke stroke2 = new System.Windows.Ink.Stroke(stylusPoints);

            strokes = new StrokeCollection();
            strokes.Add(stroke1);
            strokes.Add(stroke2);

            ReportStrokes();

            StylusPoint point = stroke2.StylusPoints[1];

            point.Y = 300;
            stroke2.StylusPoints[1] = point;

            ReportStrokes();
        }
示例#18
0
        protected void DrawLeapTouch(Leap.Frame frame)
        {
            InteractionBox interactionBox = frame.InteractionBox;

            if (frame.Pointables.Extended().Count != 1)
            {
                return;
            }

            Pointable pointable = frame.Pointables.Extended()[0];

            // InteractionBox を利用した座標変換
            Leap.Vector normalizedPosition = interactionBox.NormalizePoint(pointable.StabilizedTipPosition);

            double                tx         = normalizedPosition.x * windowWidth;
            double                ty         = windowHeight - normalizedPosition.y * windowHeight;
            StylusPoint           touchPoint = new StylusPoint(tx, ty);
            StylusPointCollection tips       = new StylusPointCollection(new StylusPoint[] { touchPoint });

            // タッチ状態
            if (normalizedPosition.z <= TouchBorder)
            {
                Stroke touchStroke = new Stroke(tips, touchIndicator);
                this.InkCanvas_LeapPaintLine.Strokes.Add(touchStroke.Clone());
            }
        }
        public static Stroke StrokeToCircle(Stroke originalStroke)
        {
            //Fix the center.
            StylusPoint start   = originalStroke.StylusPoints[0];
            double      radiusX = originalStroke.GetGeometry().Bounds.Width * 0.5;
            double      radiusY = originalStroke.GetGeometry().Bounds.Height * 0.5;
            double      ycenter = originalStroke.GetGeometry().Bounds.Top + radiusY;
            double      xcenter = originalStroke.GetGeometry().Bounds.Left + radiusX;

            StylusPointCollection s = new StylusPointCollection();
            double angle            = 0.0f;

            for (int i = 0; i < 360; i++)
            {
                angle = Math.PI * i / 180.0;
                s.Add(new StylusPoint(xcenter + (radiusX * Math.Cos(angle)), ycenter + (radiusY * Math.Sin(angle))));
            }

            //make sure to close the loop
            s.Add(new StylusPoint(s[0].X, s[0].Y));

            Stroke st = new Stroke(s);

            return(st);
        }
示例#20
0
        protected void DrawLeapPoint(Leap.Frame frame)
        {
            this.InkCanvas_LeapPaint.Strokes.Clear();
            windowHeight = (float)this.MainWindow1.Height;
            windowWidth  = (float)this.MainWindow1.Width;

            InteractionBox interactionBox = frame.InteractionBox;

            foreach (Pointable pointable in frame.Pointables.Extended())
            {
                // InteractionBox を利用した座標変換
                Leap.Vector normalizedPosition = interactionBox.NormalizePoint(pointable.StabilizedTipPosition);

                double                tx         = normalizedPosition.x * windowWidth;
                double                ty         = windowHeight - normalizedPosition.y * windowHeight;
                StylusPoint           touchPoint = new StylusPoint(tx, ty);
                StylusPointCollection tips       = new StylusPointCollection(new StylusPoint[] { touchPoint });

                // ホバー状態
                if (normalizedPosition.z > TouchBorder)
                {
                    Stroke touchStroke = new Stroke(tips, pointIndicator);
                    this.InkCanvas_LeapPaint.Strokes.Add(touchStroke);
                }
            }
        }
示例#21
0
        private void Filter(RawStylusInput rawStylusInput)
        {
            StylusPointCollection stylusPoints = rawStylusInput.GetStylusPoints();

            for (int i = 0; i < stylusPoints.Count; i++)
            {
                StylusPoint sp = stylusPoints[i];
                if (sp.X < 100)
                {
                    sp.X = 100;
                }
                if (sp.X > 400)
                {
                    sp.X = 400;
                }
                if (sp.Y < 100)
                {
                    sp.Y = 100;
                }
                if (sp.Y > 400)
                {
                    sp.Y = 400;
                }
                stylusPoints[i] = sp;
            }
            rawStylusInput.SetStylusPoints(stylusPoints);
        }
        /// <summary>
        /// 每条注释笔迹完成以后的操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InkCanvasAnnotation_StrokeCollected(object sender, System.Windows.Controls.InkCanvasStrokeCollectedEventArgs e)
        {
            if (null != _keyFramesAnnotation)
            {
                if (_keyFramesAnnotation.Strokes.Count == 0)
                {
                    if (_inkCollector.DefaultSummarizationNum == 0)
                    {
                        //关键帧索引
                        int index = _inkCollector.VideoSummarization.ShowKeyFrames.IndexOf(_inkCollector.SelectKeyFrames[0]);
                        ((SpiralSummarization)_inkCollector.VideoSummarization).AddPoints2ShowSpiral(index, Colors.Red, 0);
                    }
                    else if (_inkCollector.DefaultSummarizationNum == 1)
                    {
                        int         index   = _inkCollector.VideoSummarization.KeyFrames.IndexOf(_inkCollector.SelectKeyFrames[0]);
                        StylusPoint slPoint = _inkCollector.VideoSummarization.KeyPoints[index];

                        StylusPointCollection spc        = new StylusPointCollection();
                        StylusPoint           currPoint1 = new StylusPoint(slPoint.X - _inkCollector.VideoSummarization.ShowWidth / 2, slPoint.Y + _inkCollector.VideoSummarization.ShowHeight / 2 + 2);
                        StylusPoint           currPoint2 = new StylusPoint(slPoint.X + _inkCollector.VideoSummarization.ShowWidth / 2, slPoint.Y + _inkCollector.VideoSummarization.ShowHeight / 2 + 2);
                        spc.Add(currPoint1);
                        spc.Add(currPoint2);
                        Stroke s = new Stroke(spc);
                        s.DrawingAttributes.Color  = Colors.Red;
                        s.DrawingAttributes.Width  = 3;
                        s.DrawingAttributes.Height = 3;
                        ((InkCanvas)(_inkCollector._mainPage._inkCanvas.Children[1])).Strokes.Add(s);
                    }
                }
                Stroke lastStroke = InkCanvasAnnotation.Strokes[InkCanvasAnnotation.Strokes.Count - 1].Clone();
                _keyFramesAnnotation.Strokes.Add(lastStroke);
            }
        }
示例#23
0
        private void AddStrokeAsPoints(Stroke stroke)
        {
            int count = 0;

            StylusPointCollection spc = new StylusPointCollection();

            foreach (StylusPoint sp in stroke.StylusPoints)
            {
                double x = sp.X - (sp.X % 1) + (inkDA.Width / 2);
                double y = sp.Y - (sp.Y % 1) + (inkDA.Height / 2);

                StylusPoint point = new StylusPoint(x, y);

                if (!spc.Contains(point))
                {
                    spc.Add(point);
                }

                Stroke st = new Stroke(spc);
                st.DrawingAttributes = inkDA;

                if (!canvas.Strokes.Contains(st))
                {
                    canvas.Strokes.Add(st);
                    count++;
                }
                spc = new StylusPointCollection();
            }
            ActionHistory.Add(Actions.AddStroke);
            UndoPoints.Add(count);
            dirty = true;
        }
示例#24
0
        public static double distance(StylusPoint p1, StylusPoint p2)
        {
            double Xdist = p1.X - p2.X;
            double Ydist = p1.Y - p2.Y;

            return(Math.Sqrt(Xdist * Xdist + Ydist * Ydist));
        }
示例#25
0
        // Resampling all the strokes with the same distance intervals

        /*
         * public static void Resampling(Stroke myStroke, double scaleFactor, Rect myBounds)
         * {
         *  double diagonalLength = GeometryRelation.Distance(myBounds.BottomLeft, myBounds.TopRight);
         *  double S = diagonalLength / scaleFactor;
         *  //MessageBox.Show("S = "+S);
         *  //
         *  double D = 0;
         *  StylusPointCollection resampledStylusPointsCollection = new StylusPointCollection();
         *
         *
         *  // Add the first point to resampled stylus points
         *  resampledStylusPointsCollection.Add(myStroke.StylusPoints[0]);
         *  for (int i = 1; i < myStroke.StylusPoints.Count; i++)
         *  {
         *      StylusPoint p1, p2;
         *      p1 = myStroke.StylusPoints[i - 1];
         *      p2 = myStroke.StylusPoints[i];
         *      double d = GeometryRelation.Distance(p1, p2);
         *      if ((D + d) >= S)
         *      {
         *          StylusPoint newPoint = new StylusPoint(p1.X + ((S - D) / d) * (p2.X - p1.X), p1.Y + ((S - D) / d) * (p2.Y - p1.Y));
         *          resampledStylusPointsCollection.Add(newPoint);
         *          myStroke.StylusPoints[i] = newPoint;
         *          D = 0;
         *      }
         *      else
         *      {
         *          D = D + d;
         *      }
         *  }
         *  myStroke.StylusPoints = resampledStylusPointsCollection;
         * }
         */
        public static void Resampling(Stroke myStroke, int n)
        {
            double S = Length(myStroke) / (n - 1);
            double D = 0;
            StylusPointCollection resampledStylusPointsCollection = new StylusPointCollection();


            // Add the first point to resampled stylus points
            resampledStylusPointsCollection.Add(myStroke.StylusPoints[0]);
            for (int i = 1; i < myStroke.StylusPoints.Count; i++)
            {
                StylusPoint p1, p2;
                p1 = myStroke.StylusPoints[i - 1];
                p2 = myStroke.StylusPoints[i];
                double d = Distance(p1, p2);
                if ((D + d) >= S)
                {
                    StylusPoint newPoint = new StylusPoint(p1.X + ((S - D) / d) * (p2.X - p1.X), p1.Y + ((S - D) / d) * (p2.Y - p1.Y));
                    resampledStylusPointsCollection.Add(newPoint);
                    myStroke.StylusPoints.Insert(i, newPoint);
                    //myStroke.StylusPoints[i] = newPoint;
                    D = 0;
                }
                else
                {
                    D = D + d;
                }
            }
            myStroke.StylusPoints = resampledStylusPointsCollection;
            if (myStroke.StylusPoints.Count == n - 1)
            {
                myStroke.StylusPoints.Add(new StylusPoint(myStroke.StylusPoints[myStroke.StylusPoints.Count - 1].X, myStroke.StylusPoints[myStroke.StylusPoints.Count - 1].Y));
            }
        }
示例#26
0
        private static double Distance(StylusPoint p1, Point2D p2)
        {
            double Xdist = p1.X - p2.X;
            double Ydist = p1.Y - p2.Y;

            return(Math.Sqrt(Xdist * Xdist + Ydist * Ydist));
        }
示例#27
0
        //private void StudentInkCanvas_SpeedCheckedEvent(object sender, StudentInkCanvas.SpeedCheckedEventArgs e)
        //{
        //    IsSpeedChecked = e.state;
        //}

        #endregion

        #region overrides

        protected override void OnStylusDown(RawStylusInput rawStylusInput)
        {
            base.OnStylusDown(rawStylusInput);
            Stroke tempStroke = new Stroke(rawStylusInput.GetStylusPoints());

            //if the styluspoints is not empty
            if (tempStroke.StylusPoints.Count >= 0)
            {
                //get the stroke thats the animation is running on
                ExpertStroke = ExpertStrokeCollection[StudentStrokeCount];
                //set the first point of the stroke as the expert reference point
                ExpertStylusPoint = ExpertStroke.StylusPoints.First();

                if (tempStroke.HitTest(ExpertStylusPoint.ToPoint(), HitThreshold))
                {
                    foreach (StylusPoint sp in tempStroke.StylusPoints)
                    {
                        hitChangedPoints.Add(sp.ToPoint());
                    }
                    StrokeColor = Color.FromArgb(255, 0, 255, 0);
                }
                else
                {
                    StrokeColor = Color.FromArgb(255, 255, 0, 0);
                }
            }
        }
示例#28
0
        /// <summary>
        /// We create a stroke with points close and then add the stroke to the canvas.
        /// If the points are far apart, we create a new stroke for those points.
        /// </summary>
        /// <param name="inkCanvas"></param>
        /// <param name="strokeInfo"></param>
        public static void AddStrokePreview(this InkCanvas inkCanvas, StrokeInfo strokeInfo)
        {
            StylusPoint           firstPoint = strokeInfo.PointCollection[0];
            StylusPointCollection tmpPoints  = new StylusPointCollection();

            tmpPoints.Add(firstPoint);

            for (int i = 0; i < strokeInfo.PointCollection.Count - 1; i++)
            {
                if (CalculateDistance(strokeInfo.PointCollection[i], strokeInfo.PointCollection[i + 1]) < 5)
                {
                    tmpPoints.Add(strokeInfo.PointCollection[i + 1]);
                }
                else
                {
                    inkCanvas.Strokes.Add(CreateStroke(strokeInfo, tmpPoints.Clone()));
                    tmpPoints.Clear();
                    tmpPoints.Add(strokeInfo.PointCollection[i + 1]);
                }
            }

            if (tmpPoints.Count > 0)
            {
                inkCanvas.Strokes.Add(CreateStroke(strokeInfo, tmpPoints));
            }
        }
示例#29
0
        private void Filter(RawStylusInput rawStylusInput)
        {
            // Get the StylusPoints that have come in.
            StylusPointCollection stylusPoints = rawStylusInput.GetStylusPoints();

            // Modify the (X,Y) data to move the points
            // inside the acceptable input area, if necessary.
            for (int i = 0; i < stylusPoints.Count; i++)
            {
                StylusPoint sp = stylusPoints[i];
                if (sp.X < 50)
                {
                    sp.X = 50;
                }
                if (sp.X > 250)
                {
                    sp.X = 250;
                }
                if (sp.Y < 50)
                {
                    sp.Y = 50;
                }
                if (sp.Y > 250)
                {
                    sp.Y = 250;
                }
                stylusPoints[i] = sp;
            }

            // Copy the modified StylusPoints back to the RawStylusInput.
            rawStylusInput.SetStylusPoints(stylusPoints);
        }
示例#30
0
 private void AddSingleStrokeBasedNote(IdeationUnit strokeBasedIdea)
 {
     try
     {
         StrokeData ideaData = (StrokeData)(strokeBasedIdea.Content);
         List <System.Windows.Point> strokePoints = ideaData.StrokePoints;
         StylusPointCollection       stylusPoints = new StylusPointCollection();
         foreach (System.Windows.Point p in strokePoints)
         {
             StylusPoint stylusP = new StylusPoint(p.X, p.Y);
             stylusPoints.Add(stylusP);
         }
         Stroke newStroke = new Stroke(stylusPoints);
         if (!ideaData.IsErasingStroke)
         {
             newStroke.DrawingAttributes       = DrawingCanvasModeSwitcher.normalDrawingAttribute.Clone();
             newStroke.DrawingAttributes.Color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(ideaData.StrokeColorCode);
         }
         else
         {
             newStroke.DrawingAttributes       = new DrawingAttributes();
             newStroke.DrawingAttributes.Color = System.Windows.Media.Color.FromRgb(0, 0, 0);
             newStroke.DrawingAttributes.Width = newStroke.DrawingAttributes.Height = 30;
         }
         drawingCanvas.Strokes.Add(newStroke);
     }
     catch (Exception ex)
     {
         Utilities.UtilitiesLib.LogError(ex);
     }
 }