Beispiel #1
0
        /// <summary>
        /// Handles the Double click event extension on Graphic and deletes the vertex.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
        private void vertex_doubleClick(object sender, MouseButtonEventArgs e)
        {
            Graphic g      = sender as Graphic;
            Graphic parent = g.Attributes["Feature"] as Graphic;

            if (parent.Geometry is Envelope)
            {
                return;                              //Cannot delete
            }
            PointCollection p = g.Attributes["PointCollection"] as PointCollection;

            if (parent.Geometry is Polygon && p.Count < 5)
            {
                return;                                                        //Cannot delete
            }
            if (parent.Geometry is Polyline && p.Count < 3)
            {
                return;                                                         //Cannot delete
            }
            int index = p.IndexOf(g.Geometry as MapPoint);

            if (parent.Geometry is Polygon && index == 0) //Maintain closing point
            {
                p.RemoveAt(p.Count - 1);                  //remove last point
                p.Add(new MapPoint(p[1].X, p[1].Y));      //close poly
            }
            MapPoint removeItem = p[index];

            p.RemoveAt(index);
            //Restart edit to rebuild vertices and hover lines
            StopEdit(true);
            StartEdit(parent, true);
            OnGeometryEdit(g, null, removeItem, Action.VertexRemoved);
        }
Beispiel #2
0
 protected void RemovePointsAfterFirst()
 {
     while (PointCollection.Count > 1)
     {
         PointCollection.RemoveAt(1);
     }
 }
 private void btnUndo_Click(object sender, RoutedEventArgs e)
 {
     if (polylinePoints.Any())
     {
         polylinePoints.RemoveAt(polylinePoints.Count - 1);
     }
 }
Beispiel #4
0
        private void Page_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Delete) // Removing dragging point
            {
                if (activeDraggingPoint != null)
                {
                    int index = activeDraggingPoints.IndexOf(activeDraggingPoint);
                    if (index != 0 && index != activeDraggingPoints.Count - 1)
                    {
                        // Remove UI element
                        FilterFunctionGraph.Children.Remove(activeDraggingPoint);

                        // Remove UI element - active point
                        activeDraggingPoints.RemoveAt(index);
                        activeDraggingPoint = null;

                        // Remove point from function graph
                        (((SelectedFilterEntry.Filter as FunctionFilter).Function as FunctionFormula).otherFunctionParams[0] as Graph).points.RemoveAt(index);

                        // Update line
                        functionGraphPoints.RemoveAt(index);
                        functionGraph.Points = functionGraphPoints;
                    }
                }
            }
        }
 /// <summary>
 /// Deletes last point
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Undo(object sender, RoutedEventArgs e)
 {
     if (points.Count > 0)
     {
         points.RemoveAt(points.Count - 1);
         DrawEverything();
     }
 }
Beispiel #6
0
 protected void RemoveFirstPoint()
 {
     if (PointCollection.Count <= 0)
     {
         return;
     }
     PointCollection.RemoveAt(0);
 }
        private void Source_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            IEnumerable <Point> enumerable = sender as IEnumerable <Point>;
            PointCollection     points     = this.collectionAssociations[enumerable];

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                for (int i = 0; i < e.NewItems.Count; i++)
                {
                    points.Insert(e.NewStartingIndex + i, (Point)e.NewItems[i]);
                }
                break;

            case NotifyCollectionChangedAction.Move:
                for (int i = 0; i < e.NewItems.Count; i++)
                {
                    points.RemoveAt(e.OldStartingIndex);
                    points.Insert(e.NewStartingIndex + i, (Point)e.NewItems[i]);
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                for (int i = 0; i < e.OldItems.Count; i++)
                {
                    points.RemoveAt(e.OldStartingIndex);
                }
                break;

            case NotifyCollectionChangedAction.Replace:
                for (int i = 0; i < e.NewItems.Count; i++)
                {
                    points[e.NewStartingIndex + i] = (Point)e.NewItems[i];
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                points.Clear();
                break;
            }
        }
Beispiel #8
0
        private void DoAdaptiveDownsampling(PointCollection points)
        {
            points.Add(RawPathPoints[0]);

            DownsampledPathPoints = RawPathPoints.Clone(); //don't use assign!!!


            //check every three pixels A, B, C. If the angle between AB and BC is larger than a threshold (ex., 178 degree)
            //then we drop pixel B.
            for (int i = 0; i < DownsampledPathPoints.Count - 2; i++)
            {
                Point A = DownsampledPathPoints[i];
                Point B = DownsampledPathPoints[i + 1];
                Point C = DownsampledPathPoints[i + 2];

                double c = Math.Sqrt((A.X - B.X) * (A.X - B.X) + (A.Y - B.Y) * (A.Y - B.Y));
                double a = Math.Sqrt((B.X - C.X) * (B.X - C.X) + (B.Y - C.Y) * (B.Y - C.Y));
                double b = Math.Sqrt((A.X - C.X) * (A.X - C.X) + (A.Y - C.Y) * (A.Y - C.Y));

                double ang;
                if (a * c != 0)
                {
                    ang = Math.Acos((a * a + c * c - b * b) / (2 * a * c));
                }
                else
                {
                    ang = Math.PI;
                }

                double s_tri = (a + b + c) / 2.0;
                double area  = Math.Sqrt(s_tri * (s_tri - a) * (s_tri - b) * (s_tri - c));


                //If the angle is small that means the curvature is large, we keep the point B
                if (ang < 175.0 / 180.0 * Math.PI && area > 10)
                {
                    points.Add(DownsampledPathPoints[i + 1]);
                }
                else
                {
                    DownsampledPathPoints.RemoveAt(i + 1);
                    if (i > 0) //roll back i
                    {
                        i--;
                    }
                }
            }
            //add rest points not checked
            points.Add(RawPathPoints[RawPathPoints.Count - 2]);
            points.Add(RawPathPoints[RawPathPoints.Count - 1]);
        }
        private void CommandUndo(object sender, RoutedEventArgs e)
        {
            Polygon poly = new Polygon();

            poly.Stroke          = System.Windows.Media.Brushes.Red;
            poly.StrokeThickness = 1;
            poly.FillRule        = FillRule.EvenOdd;
            if (myPointCollection2.Count > 0)
            {
                myPointCollection2.RemoveAt(myPointCollection2.Count - 1);
                poly.Points = myPointCollection2;
                Session.ZonePointList.RemoveAt(Session.ZonePointList.Count - 1);
            }
            Cnv.Children.Add(poly);
        }
Beispiel #10
0
        private static Geometry CreatePolyLineGeometry(PointCollection points)
        {
            Point point = points[0];

            points.RemoveAt(0);
            PathGeometry    pathGeometry    = new PathGeometry();
            PathFigure      pathFigure      = new PathFigure();
            PolyLineSegment polyLineSegment = new PolyLineSegment();

            pathFigure.IsClosed    = true;
            pathFigure.StartPoint  = point;
            polyLineSegment.Points = points;
            pathFigure.Segments.Add((PathSegment)polyLineSegment);
            pathGeometry.Figures.Add(pathFigure);
            return((Geometry)pathGeometry);
        }
Beispiel #11
0
 public void EndLines()
 {
     if (polyline != null)
     {
         var n = polylinePoints.Count;
         while (n > polylineLength)
         {
             polylinePoints.RemoveAt(n - 1);
             n--;
         }
         polylineShape  = null;
         polyline       = null;
         polylinePoints = null;
         polylineLength = 0;
     }
 }
Beispiel #12
0
        private void ResizeThumbOnMouseLeftButtonUp(object sender, MouseButtonEventArgs mouseButtonEventArgs)
        {
            //get current thumb
            MultiPointThumb mprt = sender as MultiPointThumb;

            if (mprt != null)
            {
                //shift+ctrl will remove selected point
                if ((Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) &&
                    (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
                {
                    //unselect all points
                    ResetThumbs();
                    PointCollection points = GetPointCollection();

                    //iterate thumbs to lower index of remaining thumbs
                    foreach (MultiPointThumb m in adornerPanel.Children)
                    {
                        if (m.Index > mprt.Index)
                        {
                            m.Index--;
                        }
                    }

                    //remove point and thumb
                    points.RemoveAt(mprt.Index);
                    adornerPanel.Children.Remove(mprt);

                    Invalidate();
                }
                else
                {
                    //if not keyboard ctrl is pressed and selected point is not previously selected, clear selection
                    if (!_selectedPoints.ContainsKey(mprt.Index) & !Keyboard.IsKeyDown(Key.LeftCtrl) &
                        !Keyboard.IsKeyDown(Key.RightCtrl))
                    {
                        ResetThumbs();
                    }
                    //add selected thumb, if ctrl pressed this could be all points in poly
                    if (!_selectedPoints.ContainsKey(mprt.Index))
                    {
                        SelectThumb(mprt);
                    }
                    _isDragging = false;
                }
            }
        }
Beispiel #13
0
        public void DeleteVertex()
        {
            PointCollection points = (Figure.Segments[0] as PolyLineSegment).Points;

            if (points.Count > 2)
            {
                int index = GetIndex();
                points.RemoveAt(index);
                ThumbList.RemoveAt(index);

                if (index == 0)
                {
                    Figure.StartPoint = points[0];
                }

                //MapCanvas parent = ((MapCanvas)Parent);

                if (PrevThumb == null)
                {
                    NextThumb.PrevThumb       = null;
                    NextThumb.PrevInsertThumb = null;
                }
                else if (NextThumb == null)
                {
                    PrevThumb.NextThumb       = null;
                    PrevThumb.NextInsertThumb = null;
                }
                else
                {
                    PrevThumb.NextThumb = NextThumb;
                    NextThumb.PrevThumb = PrevThumb;

                    InsertThumb newInsertThumb = new InsertThumb(ParentCanvas, Figure, PrevThumb.GetIndex(), NextThumb.GetIndex(), Scale, ThumbList);
                    newInsertThumb.PrevThumb  = PrevThumb;
                    newInsertThumb.NextThumb  = NextThumb;
                    PrevThumb.NextInsertThumb = newInsertThumb;
                    NextThumb.PrevInsertThumb = newInsertThumb;
                    ParentCanvas.Children.Add(newInsertThumb);
                }

                ParentCanvas.Children.Remove(this);

                ParentCanvas.Children.Remove(PrevInsertThumb);
                ParentCanvas.Children.Remove(NextInsertThumb);
            }
        }
Beispiel #14
0
        protected override void Init()
        {
            var layout = new StackLayout();

            var instructions = new Label
            {
                Padding         = 12,
                BackgroundColor = Color.Black,
                TextColor       = Color.White,
                Text            = "Tap the button, if the Polygon is updated, the test has passed."
            };

            var button = new Button
            {
                Text = "Update Polygon points"
            };

            var points = new PointCollection()
            {
                new Point(10, 10), new Point(100, 50), new Point(100, 95), new Point(10, 95)
            };

            var polygon = new Polygon
            {
                HeightRequest   = 100,
                WidthRequest    = 100,
                StrokeThickness = 2,
                Stroke          = Brush.Red,
                Points          = points
            };

            layout.Children.Add(instructions);
            layout.Children.Add(button);
            layout.Children.Add(polygon);

            Content = layout;

            button.Clicked += (sender, args) =>
            {
                if (points.Count > 1)
                {
                    points.RemoveAt(1);
                }
            };
        }
Beispiel #15
0
        private void UpdateNNErrorVis(FFNeuralNetwork nn)
        {
            _error.Add(new Point(_error.Count, nn.Error));
            if (_error.Count > NNVisSettings.MaxErrorPoints)
            {
                _error.RemoveAt(0);
                var pc = new PointCollection();
                for (var x = 0; x < _error.Count; x++)
                {
                    pc.Add(new Point(x, _error[x].Y));
                }
                _error = pc;
            }

            Plot.Add("Error", _error, Colors.White);

            IterationLabel.Content = $"I: {nn.Iteration}";
            ErrorLabel.Content     = $"E: {nn.Error:0.#######}";
        }
Beispiel #16
0
        private static void CreatePolygon(VectorTileFeature feature, Pallete pallete, Model3DGroup model3DGroup, Vector2 <int> shiftCoords)
        {
            PointCollection points             = new PointCollection();
            List <List <Vector2 <int> > > list = feature.Geometry <int>();

            foreach (List <Vector2 <int> > item in list)
            {
                points.Clear();

                foreach (Vector2 <int> point in item)
                {
                    points.Add(new Point(point.X + shiftCoords.X, point.Y + shiftCoords.Y));
                }

                points.RemoveAt(points.Count - 1);

                var model       = new GeometryModel3D();
                var meshbuilder = new MeshBuilder(true, true);

                var result = CuttingEarsTriangulator.Triangulate(points);

                List <int> tri = new List <int>();
                for (int i = 0; i < result.Count; i++)
                {
                    tri.Add(result[i]);
                    if (tri.Count == 3)
                    {
                        //Console.WriteLine("Triangle " + (i / 3).ToString() + " : " + tri[0].ToString() + ", " + tri[1].ToString() + ", " + tri[2].ToString());
                        meshbuilder.AddTriangle(new Point3D(points[tri[0]].X, points[tri[0]].Y, 1),
                                                new Point3D(points[tri[1]].X, points[tri[1]].Y, 1),
                                                new Point3D(points[tri[2]].X, points[tri[2]].Y, 1));
                        tri.Clear();
                    }
                }

                model.Geometry = meshbuilder.ToMesh();
                model.Material = MaterialHelper.CreateMaterial(pallete.MainFillColor.ToMediaColor());

                model3DGroup.Children.Add(model);
            }
        }
Beispiel #17
0
 public void CamKeyDown(object sender, KeyEventArgs e)
 {
     if (e.OriginalSource.GetType() != typeof(TextBox))
     {
         switch (e.Key)
         {
         case Key.Escape:
             if (_annoShapeModel != null & _annoShapeModel.shapetype == ShapeType.polygon)
             {
                 if (polygonCollection.Count > 1)
                 {
                     polygonCollection.RemoveAt(polygonCollection.Count - 1);
                     mDrawTempLine(polygonCollection[polygonCollection.Count - 1]);
                     _annoShapeModel.row.RemoveAt(_annoShapeModel.row.Count - 1);
                     _annoShapeModel.col.RemoveAt(_annoShapeModel.col.Count - 1);
                 }
             }
             break;
         }
     }
 }
Beispiel #18
0
        //指定間隔で選んだアンカー点を返す
        private PointCollection ChoiceAnchorPoint(PointCollection points, int interval)
        {
            var selectedPoints = new PointCollection();

            for (int i = 0; i < points.Count - 1; i += interval)
            {
                selectedPoints.Add(points[i]);
            }
            selectedPoints.Add(points[points.Count - 1]);//最後の一個は必ず入れる

            //選んだ頂点が3個以上あって、最後の頂点と最後から2番めが近いときは2番めを除去
            if (selectedPoints.Count >= 3)
            {
                int mod = (points.Count - 2) % interval;
                if (interval / 2 > mod)
                {
                    selectedPoints.RemoveAt(selectedPoints.Count - 2);//除去
                }
            }
            return(selectedPoints);
        }
        // Specify what you want to happen when the Elapsed event is raised.
        private void OnMainLoopSequenceEvent(object source, System.Timers.ElapsedEventArgs e)
        {
            if (Application.Current != null)                                // pour éviter l'exception null...
            {
                Application.Current.Dispatcher.BeginInvoke(new Action(() => // on UI Thread
                {
                    _positionRobotLive.Add(new Point(_positionUiBuffer.PositionX, _positionUiBuffer.PositionY));
                }), DispatcherPriority.Normal);

                Application.Current.Dispatcher.BeginInvoke(new Action(() => // on UI Thread
                {
                    if (PositionRobotLive.Count >= 100)
                    {
                        _positionRobotLive.RemoveAt(0);
                    }
                }), DispatcherPriority.Normal);
            }

            RaisePropertyChanged("PositionRobotLive");

            if (Application.Current != null)                                // pour éviter l'exception null...
            {
                Application.Current.Dispatcher.BeginInvoke(new Action(() => // on UI Thread
                {
                    _position2RobotLive.Add(new Point(_position2UiBuffer.PositionX, _position2UiBuffer.PositionY));
                }), DispatcherPriority.Normal);

                Application.Current.Dispatcher.BeginInvoke(new Action(() => // on UI Thread
                {
                    if (Position2RobotLive.Count >= 100)
                    {
                        _position2RobotLive.RemoveAt(0);
                    }
                }), DispatcherPriority.Normal);
            }

            RaisePropertyChanged("Position2RobotLive");
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="vertices"></param>
        /// <param name="normals"></param>
        /// <param name="indices"></param>
        /// <param name="textures"></param>
        protected void TriangleSubdivide(Point3DCollection vertices,
                                         Vector3DCollection normals,
                                         Int32Collection indices,
                                         PointCollection textures)
        {
            for (int i = 0; i < 3; i++)
            {
                verticesBase[2 - i] = vertices[vertices.Count - 1];
                normalsBase[2 - i]  = normals[vertices.Count - 1];
                texturesBase[2 - i] = textures[vertices.Count - 1];

                vertices.RemoveAt(vertices.Count - 1);
                normals.RemoveAt(normals.Count - 1);
                indices.RemoveAt(indices.Count - 1);
                textures.RemoveAt(textures.Count - 1);
            }

            int indexStart = vertices.Count;

            for (int slice = 0; slice <= Slices; slice++)
            {
                double weight = (double)slice / Slices;

                Point3D vertex1 = Point3DWeight(verticesBase[0], verticesBase[1], weight);
                Point3D vertex2 = Point3DWeight(verticesBase[0], verticesBase[2], weight);

                Vector3D normal1 = Vector3DWeight(normalsBase[0], normalsBase[1], weight);
                Vector3D normal2 = Vector3DWeight(normalsBase[0], normalsBase[2], weight);

                Point texture1 = PointWeight(texturesBase[0], texturesBase[1], weight);
                Point texture2 = PointWeight(texturesBase[0], texturesBase[2], weight);

                for (int i = 0; i <= slice; i++)
                {
                    weight = (double)i / slice;

                    if (Double.IsNaN(weight))
                    {
                        weight = 0;
                    }

                    vertices.Add(Point3DWeight(vertex1, vertex2, weight));
                    normals.Add(Vector3DWeight(normal1, normal2, weight));
                    textures.Add(PointWeight(texture1, texture2, weight));
                }
            }

            for (int slice = 0; slice < Slices; slice++)
            {
                int base1 = (slice + 1) * slice / 2;
                int base2 = base1 + slice + 1;

                for (int i = 0; i <= 2 * slice; i++)
                {
                    int half = i / 2;

                    if ((i & 1) == 0)         // even
                    {
                        indices.Add(indexStart + base1 + half);
                        indices.Add(indexStart + base2 + half);
                        indices.Add(indexStart + base2 + half + 1);
                    }
                    else                    // odd
                    {
                        indices.Add(indexStart + base1 + half);
                        indices.Add(indexStart + base2 + half + 1);
                        indices.Add(indexStart + base1 + half + 1);
                    }
                }
            }
        }
        private static PointCollection OptimizeLinePoints(PointCollection linePoints, Rect[] rectangles, ConnectorOrientation sourceOrientation, ConnectorOrientation sinkOrientation)
        {
            var points = new PointCollection();
            int cut    = 0;

            for (int i = 0; i < linePoints.Count; i++)
            {
                if (i >= cut)
                {
                    for (int k = linePoints.Count - 1; k > i; k--)
                    {
                        if (IsPointVisible(linePoints[i], linePoints[k], rectangles))
                        {
                            cut = k;
                            break;
                        }
                    }
                    points.Add(linePoints[i]);
                }
            }

            #region Line
            for (int j = 0; j < points.Count - 1; j++)
            {
                if (points[j].X != points[j + 1].X && points[j].Y != points[j + 1].Y)
                {
                    ConnectorOrientation orientationFrom;
                    ConnectorOrientation orientationTo;

                    // orientation from point
                    if (j == 0)
                    {
                        orientationFrom = sourceOrientation;
                    }
                    else
                    {
                        orientationFrom = GetOrientation(points[j], points[j - 1]);
                    }

                    // orientation to pint
                    if (j == points.Count - 2)
                    {
                        orientationTo = sinkOrientation;
                    }
                    else
                    {
                        orientationTo = GetOrientation(points[j + 1], points[j + 2]);
                    }


                    if ((orientationFrom == ConnectorOrientation.Left || orientationFrom == ConnectorOrientation.Right) &&
                        (orientationTo == ConnectorOrientation.Left || orientationTo == ConnectorOrientation.Right))
                    {
                        double centerX = Math.Min(points[j].X, points[j + 1].X) + Math.Abs(points[j].X - points[j + 1].X) / 2;
                        points.Insert(j + 1, new Point(centerX, points[j].Y));
                        points.Insert(j + 2, new Point(centerX, points[j + 2].Y));
                        if (points.Count - 1 > j + 3)
                        {
                            points.RemoveAt(j + 3);
                        }
                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Top || orientationFrom == ConnectorOrientation.Bottom) &&
                        (orientationTo == ConnectorOrientation.Top || orientationTo == ConnectorOrientation.Bottom))
                    {
                        double centerY = Math.Min(points[j].Y, points[j + 1].Y) + Math.Abs(points[j].Y - points[j + 1].Y) / 2;
                        points.Insert(j + 1, new Point(points[j].X, centerY));
                        points.Insert(j + 2, new Point(points[j + 2].X, centerY));
                        if (points.Count - 1 > j + 3)
                        {
                            points.RemoveAt(j + 3);
                        }
                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Left || orientationFrom == ConnectorOrientation.Right) &&
                        (orientationTo == ConnectorOrientation.Top || orientationTo == ConnectorOrientation.Bottom))
                    {
                        points.Insert(j + 1, new Point(points[j + 1].X, points[j].Y));
                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Top || orientationFrom == ConnectorOrientation.Bottom) &&
                        (orientationTo == ConnectorOrientation.Left || orientationTo == ConnectorOrientation.Right))
                    {
                        points.Insert(j + 1, new Point(points[j].X, points[j + 1].Y));
                        return(points);
                    }
                }
            }
            #endregion

            return(points);
        }
        private void detectGestures()
        {
            if (selectedChannels == 1)
            {
                foreach (List <int> subList in history)
                {
                    int signChanges = 0, bandwidth = 0, step = 0, lastSig = 0;
                    for (int i = 1; i < subList.Count; i++)
                    {
                        step++;
                        if (subList[i - 1] != 0)
                        {
                            lastSig = subList[i - 1];
                        }
                        if (subList[i] * lastSig < 0)
                        {
                            signChanges++;
                            bandwidth += step;
                            step       = 0;
                        }
                    }

                    if (KF[0].isBoth && KF[0].inverse_state > 5)
                    {
                        gestureDetected.Text = "Two Handed ";
                    }
                    else if (signChanges == 0 && (lastSig != 0))
                    {
                        gestureDetected.Text = "Scrolling ";
                    }
                    else if (signChanges == 2 || signChanges == 1)
                    {
                        gestureDetected.Text = "SingleTap ";
                    }
                    else if (signChanges >= 3)
                    {
                        gestureDetected.Text = "DoubleTap ";
                    }
                }
            }
            else if (selectedChannels == 2)
            {
                double tot_X = 0, tot_Y = 0;
                foreach (KeyFrequency now in KF)
                {
                    tot_X += now.x;
                    tot_Y += now.y;
                }

                pointHist.Add(new Point(tot_X, tot_Y));
                if (pointHist.Count > maxHistoryLength)
                {
                    pointHist.RemoveAt(0);
                }

                generateStroke(pointHist);
            }
            else if (selectedChannels >= 3)
            {
                double tot_X = 0, tot_Y = 0, tot_Z = 0;
                foreach (KeyFrequency now in KF)
                {
                    tot_X += now.x;
                    tot_Y += now.y;
                    tot_Z += now.z;
                }

                pointHist.Add(new Point(tot_X, tot_Y));
                point3DHist.Add(new Point3D(tot_X, tot_Y, tot_Z));
                if (pointHist.Count > maxHistoryLength)
                {
                    pointHist.RemoveAt(0);
                }
                if (point3DHist.Count > maxHistoryLength)
                {
                    point3DHist.RemoveAt(0);
                }

                generateStroke(pointHist);
            }


            gestureCompleted();
        }
Beispiel #23
0
        /// <summary>
        /// Generate the shapes geometry.
        /// </summary>
        protected Geometry GenerateGeometry()
        {
            PathGeometry pathGeometry = new PathGeometry();

            if (Points.Count == 2 || Points.Count == 3)
            {
                // Make a straight line.
                PathFigure fig = new PathFigure();
                fig.IsClosed   = false;
                fig.IsFilled   = false;
                fig.StartPoint = Points[0];

                for (int i = 1; i < Points.Count; ++i)
                {
                    fig.Segments.Add(new LineSegment(Points[i], true));
                }

                pathGeometry.Figures.Add(fig);
            }
            else
            {
                PointCollection adjustedPoints = new PointCollection();
                adjustedPoints.Add(Points[0]);
                for (int i = 1; i < Points.Count; ++i)
                {
                    adjustedPoints.Add(Points[i]);
                }

                if (adjustedPoints.Count == 4)
                {
                    // Make a curved line.
                    PathFigure fig = new PathFigure();
                    fig.IsClosed   = false;
                    fig.IsFilled   = false;
                    fig.StartPoint = adjustedPoints[0];
                    fig.Segments.Add(new BezierSegment(adjustedPoints[1], adjustedPoints[2], adjustedPoints[3], true));

                    pathGeometry.Figures.Add(fig);
                }
                else if (adjustedPoints.Count >= 5)
                {
                    // Make a curved line.
                    PathFigure fig = new PathFigure();
                    fig.IsClosed   = false;
                    fig.IsFilled   = false;
                    fig.StartPoint = adjustedPoints[0];

                    adjustedPoints.RemoveAt(0);

                    while (adjustedPoints.Count > 3)
                    {
                        Point generatedPoint = adjustedPoints[1] + ((adjustedPoints[2] - adjustedPoints[1]) / 2);

                        fig.Segments.Add(new BezierSegment(adjustedPoints[0], adjustedPoints[1], generatedPoint, true));

                        adjustedPoints.RemoveAt(0);
                        adjustedPoints.RemoveAt(0);
                    }

                    if (adjustedPoints.Count == 2)
                    {
                        fig.Segments.Add(new BezierSegment(adjustedPoints[0], adjustedPoints[0], adjustedPoints[1], true));
                    }
                    else
                    {
                        Trace.Assert(adjustedPoints.Count == 2);

                        fig.Segments.Add(new BezierSegment(adjustedPoints[0], adjustedPoints[1], adjustedPoints[2], true));
                    }

                    pathGeometry.Figures.Add(fig);
                }
            }

            return(pathGeometry);
        }
Beispiel #24
0
 protected void RemovePointBeforeLastPoint()
 {
     PointCollection.RemoveAt(PointCollection.Count - 2);
 }
Beispiel #25
0
        private void PointCollectionOperations(object sender, SelectionChangedEventArgs e)
        {
            RadioButton li = (sender as RadioButton);

            // Strings used to display the results
            String syntaxString, resultType, operationString;

            // The local variables point1, point2, vector2, etc are defined in each
            // case block for readability reasons. Each variable is contained within
            // the scope of each case statement.
            switch (li.Name)
            {   //begin switch
            case "rb1":
            {
                //<SnippetPointCollectionAdd>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);
                Point point4 = new Point(40, 40);

                // Instantiating an array of Points to the points
                Point[] pointArray = new Point[3];

                // Adding points to array
                pointArray[0] = point1;
                pointArray[1] = point2;
                pointArray[2] = point3;

                // Instantiating a PointCollection and initializing with an array
                PointCollection pointCollection1 = new PointCollection(pointArray);

                //  Adding a point to the PointCollection
                pointCollection1.Add(point4);

                // pointCollection1 is equal to (10,10 20,20 30,30 40,40)

                //</SnippetPointCollectionAdd>



                break;
            }

            case "rb2":
            {
                //<SnippetPointCollectionClear>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to the PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // clearing the PointCollection
                pointCollection1.Clear();

                // pointCollection1 is now empty

                //</SnippetPointCollectionClear>

                break;
            }

            case "rb3":
            {
                //<SnippetPointCollectionContains>

                Boolean inCollection;

                // Instantiating and Initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);
                Point point4 = new Point(40, 40);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                inCollection = pointCollection1.Contains(point4);

                // inCollection is equal to False

                //</SnippetPointCollectionContains>

                break;
            }

            case "rb4":
            {
                //<SnippetPointCollectionIndexOf>

                int pIndex;

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);
                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Getting the index of a Point
                pIndex = pointCollection1.IndexOf(point2);

                // pointIndex is equal to 1

                //</SnippetPointCollectionIndexOf>

                break;
            }

            case "rb5":
            {
                //<SnippetPointCollectionInsert>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);
                Point point4 = new Point(40, 40);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to the PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Inserting a Point into the PointCollection
                pointCollection1.Insert(1, point4);

                // pointCollection1 is now equal to (10,10 40,40 20,20 30,30

                //</SnippetPointCollectionInsert>

                break;
            }

            case "rb6":
            {
                //<SnippetPointCollectionRemove>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Removing a Point from the PointCollection
                pointCollection1.Remove(point2);

                // pointCollection1 is equal to 10,10 30,30

                //</SnippetPointCollectionRemove>

                break;
            }

            case "rb7":
            {
                //<SnippetPointCollectionRemoveAt>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to the PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Removing a range of Points
                pointCollection1.RemoveAt(1);

                // pointCollection1 is equal to (10,10 30,30)

                //</SnippetPointCollectionRemoveAt>

                break;
            }

            case "rb8":
            {
                //<SnippetPointCollectionToString>
                string pcString;

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Getting a string representation of the PointCollection
                pcString = pointCollection1.ToString();


                // pcString is equal to "10,10 20,20 30,30"

                //</SnippetPointCollectionToString>


                break;
            }

            case "rb9":
            {
                break;
            }

            case "rb10":
            {
                break;
            }

            case "rb11":
            {
                break;
            }

            case "rb12":
            {
                break;
            }
            } //end switch
        }
Beispiel #26
0
        private async void GetInputThreadFunction()
        {
            int    count = 0;
            double accXVal, accYVal, accZVal;
            double velXVal = 0, velYVal = 0, velZVal = 0;
            Vector x_shift = new Vector(-1, 0);
            //int time = 0;
            Action onReadTimeoutAction = OnReadTimeout; // Create a delegate to execute on a timeout.
            var    cts = new CancellationTokenSource(); // The CancellationTokenSource specifies the timeout value and the action to take on a timeout.

            cts.Token.Register(onReadTimeoutAction);    // Specify the function to call on a timeout.
            PointCollection points   = new PointCollection();
            bool            zcDetect = true;
            int             oldCount = 0;
            int             packetCounterVal;
            int             lostPacketCount    = 0;
            int             prevPacketCounter  = 0;
            double          lossPercentage     = 0;
            double          prevLossPercentage = 0;;

            while (true)
            {
                try
                {
                    if (_deviceHandleObtained && (inputReportBuf != null))
                    {
                        cts.CancelAfter(60 * 1000);  // Cancel the read if it hasn't completed after a timeout.

                        // Stops waiting when data is available or on timeout:
                        Int32 bytesRead = await _myHid.GetInputReportViaInterruptTransfer(_deviceData, inputReportBuf, cts);

                        if (bytesRead > 0)
                        {
                            ErrorBox.Dispatcher.Invoke(() => { ErrorBox.Text = "bytes read (includes report ID) = " + Convert.ToString(bytesRead); });
                            //for (int i = 0; i < inputReportBuffer.Length; i++)
                            //   InfoBox.Text += inputReportBuffer[i].ToString() + " ";
                            packetCounterVal = inputReportBuf[1] + inputReportBuf[2] * 256;
                            if (0 != prevPacketCounter)
                            {
                                if (packetCounterVal != (prevPacketCounter + 1))
                                {
                                    lostPacketCount += (packetCounterVal - (prevPacketCounter + 1));
                                }
                            }
                            prevPacketCounter = packetCounterVal;


                            //ValueTextBlock.Dispatcher.Invoke(() => { ValueTextBlock.Text = ((sbyte)inputReportBuf[3]).ToString(); });
                            //AccValProgressBar.Dispatcher.Invoke(() => { AccValProgressBar.Value = (double)((sbyte)inputReportBuf[3]); });
                            totalInputReports++;
                            accXVal  = (double)((sbyte)inputReportBuf[3]);
                            accYVal  = (double)((sbyte)inputReportBuf[4]);
                            accZVal  = (double)((sbyte)(inputReportBuf[5] - 64));
                            velXVal += accXVal * 0.0327 * 15.31 / 2.0;
                            velYVal += accYVal * 0.0327 * 15.31 / 2.0;
                            velZVal += accZVal * 0.0327 * 15.31 / 2.0;
                            if (accXVal > accXMax)
                            {
                                accXMax = accXVal;
                            }
                            if (accXVal < accXMin)
                            {
                                accXMin = accXVal;
                            }
                            if (accXVal > 0)
                            {
                                zcDetect = true;
                            }
                            if ((accXVal < 0) && (zcDetect == true))
                            {
                                if ((oldCount > 0) && (inputReportFrequency > 0))
                                {
                                    accXCount++;
                                    accXFreq = (double)inputReportFrequency / (double)(totalInputReports - oldCount);
                                    AccXFreqText.Dispatcher.Invoke(() =>
                                    {
                                        AccXFreqText.Text  = string.Format("{0}", (int)(accXFreq * 60));
                                        AccXCountText.Text = string.Format("{0}", accXCount);
                                    });
                                }
                                oldCount = totalInputReports;
                                zcDetect = false;
                            }
                            count++;
                            AccXPolyline.Dispatcher.Invoke(() =>
                            {
                                if (count >= 200)
                                {
                                    accXPoints.RemoveAt(0);
                                    //velXPoints.RemoveAt(0);
                                    accYPoints.RemoveAt(0);
                                    //velYPoints.RemoveAt(0);
                                    accZPoints.RemoveAt(0);
                                    //velZPoints.RemoveAt(0);
                                    for (int i = 0; i < accXPoints.Count; i++)
                                    {
                                        accXPoints[i] += x_shift;
                                        // velXPoints[i] += x_shift;
                                        accYPoints[i] += x_shift;
                                        // velYPoints[i] += x_shift;
                                        accZPoints[i] += x_shift;
                                        // velZPoints[i] += x_shift;
                                    }
                                    accXPoints.Add(new Point(200, 150 + accXVal));
                                    //  velXPoints.Add(new Point(200, 150 + velXVal));
                                    accYPoints.Add(new Point(200, 150 + accYVal));
                                    //  velYPoints.Add(new Point(200, 150 + velYVal));
                                    accZPoints.Add(new Point(200, 150 + accZVal));
                                    //  velZPoints.Add(new Point(200, 150 + velZVal));
                                }
                                else
                                {
                                    accXPoints.Add(new Point(count, 150 + accXVal));
                                    // velXPoints.Add(new Point(count * 4, 150 + velXVal));
                                    accYPoints.Add(new Point(count, 150 + accYVal));
                                    // velYPoints.Add(new Point(count * 4, 150 + velYVal));
                                    accZPoints.Add(new Point(count, 150 + accZVal));
                                    //  velZPoints.Add(new Point(count * 4, 150 + velZVal));
                                }
                            });

                            CountTextBlock.Dispatcher.Invoke(() =>
                            {
                                if (totalInputReports > 0)
                                {
                                    lossPercentage = (double)(lostPacketCount) * 100 / totalInputReports;
                                }
                                CountTextBlock.Text      = totalInputReports.ToString();
                                LossTextBlock.Text       = string.Format("{0:0.0}%", lossPercentage);
                                LossTextBlock.Foreground = (lossPercentage > prevLossPercentage) ? Brushes.Red : Brushes.Green;
                                prevLossPercentage       = lossPercentage;
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                    DisplayException(Name, ex);
                }
            }
        }