public static string Classify(bool useRubine, float duration, bool righthandedness, List<float> SpeakerAngles, PointCollection pointHist, StylusPointCollection S, List<List<int>> hist, List<List<int>> ihist) { // Convert all parameters to format used in GestureTests List<Vector2> InterpretedPoints = new List<Vector2>(); List<Vector2> StylusPoints = new List<Vector2>(); List<Vector2> VelocityHistory = new List<Vector2>(); List<Vector2> InverseVelocityHistory = new List<Vector2>(); foreach(Point P in pointHist) InterpretedPoints.Add(new Vector2((float)P.X,(float)P.Y)); foreach(StylusPoint P in S) StylusPoints.Add(new Vector2((float)P.X,(float)P.Y)); for (int i = 0; i < hist[0].Count; i++) { VelocityHistory.Add(new Vector2(hist[0][i], hist[1][i])); InverseVelocityHistory.Add(new Vector2(ihist[0][i], ihist[1][i])); } // Create a new Sample, compute the features, and classify GS = new GestureSample(GestureTests.Types.GestureType.unknown, righthandedness,duration,SpeakerAngles,InterpretedPoints,StylusPoints,VelocityHistory,InverseVelocityHistory); GS.ComputeFeatures(GestureFeatures.PointsStroke); if (useRubine) return EC.Recognizer.Classify(GS).ToString(); WriteARFF(); Instances test = new Instances(new java.io.FileReader("outfile.arff")); test.setClassIndex(0); double clsLabel = cls.classifyInstance(test.instance(0)); test.instance(0).setClassValue(clsLabel); // Return the appropriate label return ((GestureType2D)((int)clsLabel+1)).ToString(); }
//считаем площадь полигона public double square(PointCollection pol) { double s = 0; double res = 0; double sq = 0; int n = pol.Count;//кол-во вершин for (int i = 0; i < n; i++) { if (i == 0) { s = pol[i].X * (pol[n - 1].Y - pol[i + 1].Y); //если i == 0, то y[i-1] заменяем на y[n-1] res += s; } else if (i == n - 1) { s = pol[i].X * (pol[i - 1].Y - pol[0].Y); // если i == n-1, то y[i+1] заменяем на y[0] res += s; } else { s = pol[i].X * (pol[i - 1].Y - pol[i + 1].Y); res += s; } } sq = Math.Abs(res / 2); return sq; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var rc = value as IEnumerable<RegisterTransaction>; if (rc == null || rc.Count() == 0) return null; // Cheat a little here and get the min/max ranges for scaling double minValue = rc.Min(rt => rt.TotalBalance); double maxValue = rc.Max(rt => rt.TotalBalance); double increment = 100.0 / rc.Count(); maxValue = Math.Max(Math.Abs(minValue), Math.Abs(maxValue)); minValue = -maxValue; var pc = new PointCollection(); double x = 0; foreach (var reg in rc) { double yPos = ((-minValue + reg.TotalBalance)/(maxValue - minValue)) * 100; pc.Add(new Point(x, yPos)); x += increment; } return pc; }
/// <summary> /// Calculates the points for back face /// </summary> public void CalculateBackFacePoints() { _backFacePoints = new PointCollection(); foreach(Point point in _frontFacePoints) _backFacePoints.Add(new Point(point.X + _depth3D, point.Y - _depth3D)); }
private void generatePentagon(double R, double x, double y) { try { PointCollection pointCollection = new PointCollection(); int R2 = (int)(R / Math.Sqrt(2)); Point[] pt = new Point[6]; pt[0].X = x; pt[0].Y = y - R; pt[1].X = x + R2; pt[1].Y = y - R2; pt[2].X = x + R; pt[2].Y = y; pt[3].X = x + R2; pt[3].Y = y + R2; pt[4].X = x; pt[4].Y = y + R; pt[5].X = pt[0].X; pt[5].Y = pt[0].Y; //m_halfOctagon = new List<DataPoint>(); for (int idx = 0; idx < pt.Length; idx++) { m_halfOctagon.Add(new DataPoint(pt[idx], idx)); } } catch (Exception) { } }
public Computing() { Result = new Moment(0); //Tmr = new Timer(3000); //Tmr.AutoReset = true; //Tmr.Elapsed += Tmr_Elapsed; InpFileName = @"D:\ballistics\ballisticwpf\config.txt"; OutFileName = @"D:\ballistics\ballisticwpf\result.txt"; //string InpFileName = @"C:\Users\Andrey\Documents\Visual Studio 2015\Projects\ballistics\ballisticwpf\config.txt"; //string OutFileName = @"C:\Users\Andrey\Documents\Visual Studio 2015\Projects\ballistics\ballisticwpf\result.txt"; Config = new Configuration(0); Config.ReadConfugurationFromFile(InpFileName); bool ExistFlag = File.Exists(OutFileName); if (ExistFlag) { File.Delete(OutFileName); } Positions = new PointCollection(); Positions.Add(new Point(0, 0)); Chart = new Polyline(); Chart.Points = Positions; //BgrWork = ((BackgroundWorker)this.FindResource("bgrWork")); //ComplexArg = new ComplexForAsyns(Config); }
private void goButton_Click(object sender, RoutedEventArgs e) { Parser.Parser.Variable variableI; Parser.Parser parser = new Parser.Parser(); parser = new Parser.Parser(); parser.InputString = functionTextBox.Text; variableI = parser.GetVariable("x"); PointCollection p = new PointCollection(); Random r = new Random(); for (float i = 0; i <= 10; i += 0.5f) { points.pointX.Add(i); variableI.value = i; clearSignal.Add(variableI.value); //variableI.value = (i % 3 == 0) ? i * (float)r.NextDouble() : i; //noiseSignal.Add(variableI.value); points.pointY.Add(parser.Calculate()); p.Add(new Point(parser.Calculate(), i)); } chart.DataContext = p; }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { var polygonPoints = new PointCollection(); if (values.Length == 3 && values[2] is Thickness) { var width = System.Convert.ToDouble(values[0]); var height = System.Convert.ToDouble(values[1]); var margin = (Thickness)values[2]; if (System.Convert.ToInt32(parameter) == 0) { polygonPoints.Add(new Point(0 + margin.Left, height - margin.Bottom)); polygonPoints.Add(new Point(0, height)); polygonPoints.Add(new Point(0, 0)); polygonPoints.Add(new Point(width, 0)); polygonPoints.Add(new Point(width - margin.Right, 0 + margin.Top)); } else { polygonPoints.Add(new Point(0 + margin.Left, height - margin.Bottom)); polygonPoints.Add(new Point(0, height)); polygonPoints.Add(new Point(width, height)); polygonPoints.Add(new Point(width, 0)); polygonPoints.Add(new Point(width - margin.Right, 0 + margin.Top)); } } return polygonPoints; }
public override Rect GetRectangle() { if (Points == null) Points = new PointCollection(); if (Points.Count == 0) return new Rect(0, 0, 0, 0); double minLeft = double.MaxValue; double minTop = double.MaxValue; double maxLeft = 0; double maxTop = 0; foreach (var point in Points) { if (point.X < minLeft) minLeft = point.X; if (point.Y < minTop) minTop = point.Y; if (point.X > maxLeft) maxLeft = point.X; if (point.Y > maxTop) maxTop = point.Y; } if (maxTop < minTop) minTop = maxTop; if (maxLeft < minLeft) minLeft = maxLeft; return new Rect(minLeft, minTop, maxLeft - minLeft, maxTop - minTop); }
private void drawShape(bool success, List<DataPoint> points) { lnPoints.Points.Clear(); if (success) { PointCollection pointCollection = new PointCollection(); for (int x = 0; x < points.Count; x++) { DataPoint point = points[x]; pointCollection.Add(point.UiPoint); } lnPoints.Points = pointCollection; message.Text = "Success"; message.Foreground = Brushes.LightGreen; message.FontWeight = FontWeights.Normal; } else { message.Text = "Failure"; message.Foreground = Brushes.Red; message.FontWeight = FontWeights.Bold; } }
protected override void Resize(ResizeDirection direction, Vector vector) { ElementBaseShape element = DesignerItem.Element as ElementBaseShape; if (element != null) { var rect = element.GetRectangle(); var placeholder = new Rect(rect.TopLeft, rect.Size); if ((direction & ResizeDirection.Top) == ResizeDirection.Top) { placeholder.Y += vector.Y; placeholder.Height -= vector.Y; } else if ((direction & ResizeDirection.Bottom) == ResizeDirection.Bottom) placeholder.Height += vector.Y; if ((direction & ResizeDirection.Left) == ResizeDirection.Left) { placeholder.X += vector.X; placeholder.Width -= vector.X; } else if ((direction & ResizeDirection.Right) == ResizeDirection.Right) placeholder.Width += vector.X; double kx = rect.Width == 0 ? 0 : placeholder.Width / rect.Width; double ky = rect.Height == 0 ? 0 : placeholder.Height / rect.Height; _points = new PointCollection(); foreach (var point in element.Points) _points.Add(new Point(placeholder.X + kx * (point.X - rect.X), placeholder.Y + ky * (point.Y - rect.Y))); element.Points = _points; DesignerItem.RefreshPainter(); DesignerCanvas.DesignerChanged(); } }
static bool Snip(PointCollection contour, int u, int v, int w, int n, int[] V) { int p; double Ax, Ay, Bx, By, Cx, Cy, Px, Py; Ax = contour[V[u]].X; Ay = contour[V[u]].Y; Bx = contour[V[v]].X; By = contour[V[v]].Y; Cx = contour[V[w]].X; Cy = contour[V[w]].Y; if (Epsilon > (((Bx - Ax) * (Cy - Ay)) - ((By - Ay) * (Cx - Ax)))) return false; for (p = 0; p < n; p++) { if ((p == u) || (p == v) || (p == w)) continue; Px = contour[V[p]].X; Py = contour[V[p]].Y; if (InsideTriangle(Ax, Ay, Bx, By, Cx, Cy, Px, Py)) return false; } return true; }
static Terrain3D() { { SX = new double[17]; SZ = new double[17]; int i = 0; for (double d = 0; d < 2; d += 0.125) { i++; SX[i] = Math.Cos(Math.PI * d); SZ[i] = Math.Sin(Math.PI * d); } } { TEXTURE_COORDINATES = new PointCollection(17); TEXTURE_COORDINATES.Add(new Point(0, 0)); Point p = new Point(1, 0); int i = -1; while (++i < 16) TEXTURE_COORDINATES.Add(p); TEXTURE_COORDINATES.Freeze(); } { TRIANGLE_INDICES = new Int32Collection(48); for (int i = 1; i < 16; i++) { TRIANGLE_INDICES.Add(0); TRIANGLE_INDICES.Add(i + 1); TRIANGLE_INDICES.Add(i); } TRIANGLE_INDICES.Add(0); TRIANGLE_INDICES.Add(1); TRIANGLE_INDICES.Add(16); TRIANGLE_INDICES.Freeze(); } }
public static PointCollection GetSelectionPolygon(Rect topRect, Rect bottomRect, double width, double offsetX, double lineInterval) { double lineIntervalCompensation = 0; if(lineInterval < 1) { lineIntervalCompensation = 1 - lineInterval; } double topRectCompensation = topRect.Height * lineIntervalCompensation; double bottmRectCompensation = bottomRect.Height * lineIntervalCompensation; var pointCollection = new PointCollection(); if (topRect.Top < bottomRect.Top) { pointCollection.Add(new Point(offsetX, topRect.Bottom)); pointCollection.Add(new Point(topRect.Left, topRect.Bottom)); pointCollection.Add(new Point(topRect.Left, topRect.Top + topRectCompensation)); pointCollection.Add(new Point(width - offsetX, topRect.Top + topRectCompensation)); pointCollection.Add(new Point(width - offsetX, bottomRect.Top + bottmRectCompensation)); pointCollection.Add(new Point(bottomRect.Right, bottomRect.Top + bottmRectCompensation)); pointCollection.Add(new Point(bottomRect.Right, bottomRect.Bottom)); pointCollection.Add(new Point(offsetX, bottomRect.Bottom)); } else { pointCollection.Add(new Point(topRect.Left, topRect.Bottom)); pointCollection.Add(new Point(topRect.Left, topRect.Top + topRectCompensation)); pointCollection.Add(new Point(bottomRect.Right, bottomRect.Top + bottmRectCompensation)); pointCollection.Add(new Point(bottomRect.Right, bottomRect.Bottom)); } return pointCollection; }
protected override void Triangulate(DependencyPropertyChangedEventArgs args, Point3DCollection vertices, Vector3DCollection normals, Int32Collection indices, PointCollection textures) { vertices.Clear(); normals.Clear(); indices.Clear(); textures.Clear(); MeshGeometry3D mesh = MeshGenerator.Geometry; foreach (Point3D vertex in mesh.Positions) vertices.Add(vertex); foreach (Vector3D normal in mesh.Normals) normals.Add(normal); foreach (int index in mesh.TriangleIndices) indices.Add(index); foreach (Point texture in mesh.TextureCoordinates) textures.Add(texture); }
static ArrowOrientation GetArrowOrientation(PointCollection points) { Debug.Assert(points.Count > 1, "Invalid connector"); ArrowOrientation orientation; Point srcPoint = points[points.Count - 2]; Point destPoint = points[points.Count - 1]; if (srcPoint.X == destPoint.X) { orientation = ArrowOrientation.Top; if (destPoint.Y > srcPoint.Y) { orientation = ArrowOrientation.Bottom; } } else { orientation = ArrowOrientation.Left; if (destPoint.X > srcPoint.X) { orientation = ArrowOrientation.Right; } } return orientation; }
protected PointCollection GetPoints(Rect bounds) { // Inscribe the shape inside a circle double angle = -(Math.PI / 2.0f); double deltaAngle = (Math.PI * 2) / Sides; double halfWidth = bounds.Width / 2; double halfHeight = bounds.Height / 2; PointCollection points = new PointCollection(Sides); for (int i = 0; i < this.Sides; i++) { // Convert from polar to cartesian coordinates. double x = halfWidth * Math.Cos(angle); double y = halfHeight * Math.Sin(angle); points.Add(new Point( x + halfWidth + bounds.Left, y + halfHeight + bounds.Top)); angle += deltaAngle; } return points; }
protected override void ProcessFigure(CircularList<Point> list, Point3DCollection vertices, Vector3DCollection normals, Int32Collection indices, PointCollection textures) { int offset = vertices.Count; for (int i = 0; i <= list.Count; i++) { Point pt = list[i]; // Set vertices. vertices.Add(new Point3D(pt.X, pt.Y, 0)); vertices.Add(new Point3D(pt.X, pt.Y, -Depth)); // Set texture coordinates. textures.Add(new Point((double)i / list.Count, 0)); textures.Add(new Point((double)i / list.Count, 1)); // Set triangle indices. if (i < list.Count) { indices.Add(offset + i * 2 + 0); indices.Add(offset + i * 2 + 2); indices.Add(offset + i * 2 + 1); indices.Add(offset + i * 2 + 1); indices.Add(offset + i * 2 + 2); indices.Add(offset + i * 2 + 3); } } }
static void Segment(PointCollection points, Point pt0, Point pt1, Point pt2, Point pt3, double T1, double T2, double tolerance) { // See Petzold, "Programming Microsoft Windows with C#", pages 645-646 or // Petzold, "Programming Microsoft Windows with Microsoft Visual Basic .NET", pages 638-639 // for derivation of the following formulas: double SX1 = T1 * (pt2.X - pt0.X); double SY1 = T1 * (pt2.Y - pt0.Y); double SX2 = T2 * (pt3.X - pt1.X); double SY2 = T2 * (pt3.Y - pt1.Y); double AX = SX1 + SX2 + 2 * pt1.X - 2 * pt2.X; double AY = SY1 + SY2 + 2 * pt1.Y - 2 * pt2.Y; double BX = -2 * SX1 - SX2 - 3 * pt1.X + 3 * pt2.X; double BY = -2 * SY1 - SY2 - 3 * pt1.Y + 3 * pt2.Y; double CX = SX1; double CY = SY1; double DX = pt1.X; double DY = pt1.Y; int num = (int)((Math.Abs(pt1.X - pt2.X) + Math.Abs(pt1.Y - pt2.Y)) / tolerance); // Notice begins at 1 so excludes the first point (which is just pt1) for (int i = 1; i < num; i++) { double t = (double)i / (num - 1); Point pt = new Point(AX * t * t * t + BX * t * t + CX * t + DX, AY * t * t * t + BY * t * t + CY * t + DY); points.Add(pt); } }
protected override void Triangulate( DependencyPropertyChangedEventArgs args, Point3DCollection vertices, Vector3DCollection normals, Int32Collection indices, PointCollection textures) { // Clear all four collections. vertices.Clear(); normals.Clear(); indices.Clear(); textures.Clear(); // Convert TextGeometry to series of closed polylines. PathGeometry path = TextGeometry.GetFlattenedPathGeometry(0.001, ToleranceType.Relative); foreach (PathFigure fig in path.Figures) { list.Clear(); list.Add(fig.StartPoint); foreach (PathSegment seg in fig.Segments) { if (seg is LineSegment) { LineSegment lineseg = seg as LineSegment; list.Add(lineseg.Point); } else if (seg is PolyLineSegment) { PolyLineSegment polyline = seg as PolyLineSegment; for (int i = 0; i < polyline.Points.Count; i++) list.Add(polyline.Points[i]); } } // Figure is complete. Post-processing follows. if (list.Count > 0) { // Remove last point if it's the same as the first. if (list[0] == list[list.Count - 1]) list.RemoveAt(list.Count - 1); // Convert points to Y increasing up. for (int i = 0; i < list.Count; i++) { Point pt = list[i]; pt.Y = 2 * Origin.Y - pt.Y; list[i] = pt; } // For each figure, process the points. ProcessFigure(list, vertices, normals, indices, textures); } } }
/// <summary> /// Initializes a new instance of the <see cref="HiLoOpenCloseSeries"/> class. /// </summary> public HiLoOpenCloseSeries() { HighPoints = new PointCollection(); LowPoints = new PointCollection(); OpenPoints = new PointCollection(); ClosePoints = new PointCollection(); }
/// <summary> /// Calculates the texture for the specified model. /// </summary> /// <param name="model"> /// The model. /// </param> /// <param name="mesh"> /// The mesh. /// </param> public override void Calculate(TerrainModel model, MeshGeometry3D mesh) { var normals = MeshGeometryHelper.CalculateNormals(mesh); var texcoords = new PointCollection(); var up = new Vector3D(0, 0, 1); for (int i = 0; i < normals.Count; i++) { double slope = Math.Acos(Vector3D.DotProduct(normals[i], up)) * 180 / Math.PI; double u = slope / 40; if (u > 1) { u = 1; } if (u < 0) { u = 0; } texcoords.Add(new Point(u, u)); } this.TextureCoordinates = texcoords; this.Material = MaterialHelper.CreateMaterial(this.Brush); }
public void AddFunction(IEnumerable<Point> points, Color color, string description) { if(!squaresFunctions.ContainsKey(description) && !functions.ContainsKey(description)) { Polyline polyline = new Polyline(); polyline.Stroke = new SolidColorBrush(color); polyline.StrokeThickness = CalculateThickness(0.005, R2.Width, R2.Height); PointCollection pColl = new PointCollection(points); polyline.Points = pColl; var nwFour = new Four(polyline.Points.Min(p => p.X), polyline.Points.Max(p => p.Y), polyline.Points.Min(p => p.Y), polyline.Points.Max(p => p.Y)); squaresFunctions.Add(description, nwFour); RecalculateSquare(); GoToCenter(); DrowCoordinates(); R2.Children.Add(polyline); Label lbl = new Label(); lbl.Content = description; lbl.Foreground = new SolidColorBrush(color); Descriptions.Children.Add(lbl); functions.Add(description, new Tuple<Polyline, Label>(polyline, lbl)); } }
private static void AddCircleInZCross(MeshBuilder mb, Point3D centre, double radius, int div) { var points = MeshBuilder.GetCircle(div); var vectors = new Point3DCollection(); var normals = new Vector3DCollection(); var textures = new PointCollection(); vectors.Add(new Point3D(centre.X, centre.Y, 0)); normals.Add(new Vector3D(0, 0, 1)); textures.Add(new Point(0.5, 0.5)); for (int i = 0; i < points.Count - 1; i++) { vectors.Add(new Point3D(points[i].X * radius + centre.X, points[i].Y * radius + centre.Y, centre.Z)); normals.Add(new Vector3D(0, 0, -1)); textures.Add(new Point(points[i].X * 0.5 + 0.5, points[i].Y * 0.5 + 0.5)); vectors.Add(new Point3D(points[i + 1].X * radius + centre.X, points[i + 1].Y * radius + centre.Y, centre.Z)); normals.Add(new Vector3D(0, 0, 01)); textures.Add(new Point(points[i + 1].X * 0.5 + 0.5, points[i + 1].Y * 0.5 + 0.5)); } mb.AddTriangleFan(vectors, normals, textures); }
public override void Draw(Canvas c) { base.Draw(c); Polygon polygon = new Polygon(); polygon.Fill = Brushes.Red; polygon.Stroke = Brushes.Black; polygon.StrokeThickness = 1; PointCollection pointCollection = new PointCollection(); pointCollection.Add(new Point(130, 162)); pointCollection.Add(new Point(145, 158)); pointCollection.Add(new Point(155, 155)); pointCollection.Add(new Point(160, 160)); pointCollection.Add(new Point(160, 165)); pointCollection.Add(new Point(155, 170)); pointCollection.Add(new Point(140, 177)); pointCollection.Add(new Point(120, 177)); pointCollection.Add(new Point(105, 170)); pointCollection.Add(new Point(100, 165)); pointCollection.Add(new Point(100, 160)); pointCollection.Add(new Point(105, 155)); pointCollection.Add(new Point(115, 158)); polygon.Points = pointCollection; c.Children.Add(polygon); }
private void AppearanceChanged() { var builder = new MeshBuilder(false, true); // hard code a kerb section var section = new PointCollection(); int m = 41; double n = 4; double a = this.Width / 2; double b = this.Height; for (int i = 0; i < m; i++) { double t = Math.PI * i / (m - 1); section.Add(new Point( a * Math.Sign(Math.Cos(t)) * Math.Pow(Math.Abs(Math.Cos(t)), 2 / n), -b * Math.Sign(Math.Sin(t)) * Math.Pow(Math.Abs(Math.Sin(t)), 2 / n))); } // calculate the texture coordinates var values = new List<double> { 0 }; for (int i = 1; i < this.Positions.Count; i++) { var d = this.Positions[i - 1].DistanceTo(this.Positions[i]); values.Add(values[values.Count - 1] + (d / this.Length)); } // create the extruded geometry builder.AddTube(this.Positions, null, values, null, section, new Vector3D(1, 0, 0), false, false); this.kerbModel.Geometry = builder.ToMesh(); }
private void LayoutRoot_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { PointCollection points = new PointCollection(); foreach (Point p in poly.Points) points.Add(p); Point newPoint = e.GetPosition(poly); points.Add(newPoint); poly.Points = points; // placeholder Ellipse ph = new Ellipse { Fill = new SolidColorBrush(Colors.Black), Width = 4D, Height = 4D }; TranslateTransform t = new TranslateTransform { X = newPoint.X - 2D, Y = newPoint.Y - 2D }; ph.RenderTransform = t; cnv.Children.Add(ph); // TextBlock tb = new TextBlock { Foreground = new SolidColorBrush(Colors.Gray), FontSize = 8 }; tb.Text = newPoint.ToString(); tb.RenderTransform = t; cnv.Children.Add(tb); }
void CreateGeometry() { double r = Diameter / 2; double l = HeadLength * Diameter; // arrowhead var pc = new PointCollection(); pc.Add(new Point(-l, r)); pc.Add(new Point(-l, r * 2)); pc.Add(new Point(0, 0)); var headBuilder = new MeshBuilder(); headBuilder.AddRevolvedGeometry(pc, new Point3D(0, 0, 0), new Vector3D(0, 0, 1), ThetaDiv); _head = headBuilder.ToMesh(); _head.Freeze(); // body pc = new PointCollection(); pc.Add(new Point(0, 0)); pc.Add(new Point(0, r)); pc.Add(new Point(1, r)); var bodyBuilder = new MeshBuilder(); bodyBuilder.AddRevolvedGeometry(pc, new Point3D(0, 0, 0), new Vector3D(0, 0, 1), ThetaDiv); _body = bodyBuilder.ToMesh(); _body.Freeze(); }
public OrganismVisual(Organism source, Ellipse organism, Polygon sight, PointCollection boundaries, TextBlock energy) { this.source = source; source.OnDeath += source_OnDeath; this.organism = organism; this.boundaries = boundaries; this.energy = energy; organism.Dispatcher.Invoke(new Action(() => organism.Fill = new SolidColorBrush(Colors.Red))); organism.Dispatcher.Invoke(new Action(() => organism.Height = source.getSize())); organism.Dispatcher.Invoke(new Action(() => organism.Width = source.getSize())); this.sight = sight; sight.Dispatcher.Invoke(new Action(() => sight.Fill = new SolidColorBrush(Color.FromArgb(50, 200, 200, 200)))); sight.Dispatcher.Invoke(new Action(() => sight.Points = boundaries)); energy.Dispatcher.Invoke(new Action(() => energy.Foreground = new SolidColorBrush(Colors.White))); energy.Dispatcher.Invoke(new Action(() => energy.HorizontalAlignment = HorizontalAlignment.Center)); energy.Dispatcher.Invoke(new Action(() => energy.VerticalAlignment = VerticalAlignment.Center)); energy.Dispatcher.Invoke(new Action(() => energy.TextAlignment = TextAlignment.Center)); energy.Dispatcher.Invoke(new Action(() => energy.Height = 15)); energy.Dispatcher.Invoke(new Action(() => energy.Width = 40)); constructPointCollection(); }
protected override void OnRender(DrawingContext dc) { BitmapSource bit = null; if (opacity_value != 0) { var reduced = OriginalImage.Clone(); Core.ImageExtensions.OpacityReduction(reduced, opacity_value); bit = BitmapSourceConvert.ToBitmapSource(reduced); } base.OnRender(dc); if (!above && bit != null) { dc.DrawImage(bit, new Rect(0, 0, Width, Height)); } foreach (DominoInCanvas dic in Stones) { Point point1 = dic.canvasPoints[0]; Point point2 = dic.canvasPoints[1]; Point point3 = dic.canvasPoints[2]; Point point4 = dic.canvasPoints[3]; StreamGeometry streamGeometry = new StreamGeometry(); using (StreamGeometryContext geometryContext = streamGeometry.Open()) { geometryContext.BeginFigure(point1, true, true); var points = new System.Windows.Media.PointCollection { point2, point3, point4 }; geometryContext.PolyLineTo(points, true, true); } Pen pen = new Pen(); if (dic.isSelected) { pen.Brush = new SolidColorBrush(SelectedBorderColor); pen.Thickness = BorderSize; } else if (dic.PossibleToPaste) { pen.Brush = Brushes.Plum; pen.Thickness = BorderSize; } else { pen.Brush = new SolidColorBrush(UnselectedBorderColor); pen.Thickness = BorderSize / 2; } dc.DrawGeometry(new SolidColorBrush(dic.StoneColor), pen, streamGeometry); } if (above && bit != null) { dc.DrawImage(bit, new Rect(0, 0, Width, Height)); } }
public static void UserDrawRoutesWPF(Route Route, DrawingContext dc, System.Windows.Media.Color color) { System.Windows.Point[] m_ScreenPnts = null; int PixelX = 0; int PixelY = 0; if (Route == null) { return; } if (Route.Points.Count() == 0) { return; } System.Windows.Media.SolidColorBrush curBrush = new System.Windows.Media.SolidColorBrush(); curBrush.Color = color;// System.Windows.Media.Colors.Gold; System.Windows.Media.Pen pen = new System.Windows.Media.Pen(curBrush, 3); // m_ScreenPnts = new System.Windows.Point[Route.arr_legs.Length + 1]; m_ScreenPnts = new System.Windows.Point[Route.Points.Count()]; //VMMainViewModel.Instance.ConvertCoordGroundToPixel(Route.arr_legs[0].FromLongn, Route.arr_legs[0].FromLatn, ref PixelX, ref PixelY); //m_ScreenPnts[0].X = PixelX; //m_ScreenPnts[0].Y = PixelY; for (int i = 0; i < Route.Points.Count(); i++) { //VMMainViewModel.Instance.ConvertCoordGroundToPixel(Route.arr_legs[i].ToLongn, Route.arr_legs[i].ToLatn, ref PixelX, ref PixelY); //m_ScreenPnts[i + 1].X = PixelX; //m_ScreenPnts[i + 1].Y = PixelY; VMMainViewModel.Instance.ConvertCoordGroundToPixel(Route.Points[i].X, Route.Points[i].Y, ref PixelX, ref PixelY); m_ScreenPnts[i].X = PixelX; m_ScreenPnts[i].Y = PixelY; } System.Windows.Media.PathGeometry PathGmtr = new System.Windows.Media.PathGeometry(); System.Windows.Media.PathFigure pathFigure = new System.Windows.Media.PathFigure(); System.Windows.Media.PolyLineSegment myPolyLineSegment = new System.Windows.Media.PolyLineSegment(); System.Windows.Media.PointCollection pc = new System.Windows.Media.PointCollection(m_ScreenPnts); myPolyLineSegment.Points = pc; pathFigure.StartPoint = m_ScreenPnts[0]; pathFigure.Segments.Add(myPolyLineSegment); PathGmtr.Figures.Add(pathFigure); dc.DrawGeometry(null, pen, PathGmtr); }
protected override System.Windows.Shapes.Shape createShape() { var pc = new media.PointCollection(); pc.Add(bases[0]); pc.Add(bases[1]); pc.Add(bases[2]); return(new wpf2d.Polyline() { Name = MakeCtrlId(), HorizontalAlignment = wpf.HorizontalAlignment.Left, VerticalAlignment = wpf.VerticalAlignment.Top, Stroke = media.Brushes.Black, StrokeThickness = 5, Points = pc }); }
///<summary> /// Callback method, used for adding a figure to the list ///</summary> ///<param name="isFilled"> /// The figure is filled ///</param> ///<param name="isClosed"> /// The figure is closed ///</param> ///<param name="pPoints"> /// The array of the figure's defining points ///</param> ///<param name="pointCount"> /// The size of the points array ///</param> ///<param name="pSegTypes"> /// The array of the figure's defining segment types ///</param> ///<param name="segmentCount"> /// The size of the types array ///</param> internal unsafe void AddFigureToList(bool isFilled, bool isClosed, MilPoint2F *pPoints, UInt32 pointCount, byte *pSegTypes, UInt32 segmentCount) { if (pointCount >= 1 && segmentCount >= 1) { PathFigure figure = new PathFigure(); figure.IsFilled = isFilled; figure.StartPoint = new Point(pPoints->X, pPoints->Y); int pointIndex = 1; int sameSegCount = 0; for (int segIndex = 0; segIndex < segmentCount; segIndex += sameSegCount) { byte segType = (byte)(pSegTypes[segIndex] & (byte)MILCoreSegFlags.SegTypeMask); sameSegCount = 1; // Look for a run of same-type segments for a PolyXXXSegment. while (((segIndex + sameSegCount) < segmentCount) && (pSegTypes[segIndex] == pSegTypes[segIndex + sameSegCount])) { sameSegCount++; } bool fStroked = (pSegTypes[segIndex] & (byte)MILCoreSegFlags.SegIsAGap) == (byte)0; bool fSmooth = (pSegTypes[segIndex] & (byte)MILCoreSegFlags.SegSmoothJoin) != (byte)0; if (segType == (byte)MILCoreSegFlags.SegTypeLine) { if (pointIndex + sameSegCount > pointCount) { throw new System.InvalidOperationException(SR.Get(SRID.PathGeometry_InternalReadBackError)); } if (sameSegCount > 1) { PointCollection ptCollection = new PointCollection(); for (int i = 0; i < sameSegCount; i++) { ptCollection.Add(new Point(pPoints[pointIndex + i].X, pPoints[pointIndex + i].Y)); } ptCollection.Freeze(); PolyLineSegment polySeg = new PolyLineSegment(ptCollection, fStroked, fSmooth); polySeg.Freeze(); figure.Segments.Add(polySeg); } else { Debug.Assert(sameSegCount == 1); figure.Segments.Add(new LineSegment(new Point(pPoints[pointIndex].X, pPoints[pointIndex].Y), fStroked, fSmooth)); } pointIndex += sameSegCount; } else if (segType == (byte)MILCoreSegFlags.SegTypeBezier) { int pointBezierCount = sameSegCount * 3; if (pointIndex + pointBezierCount > pointCount) { throw new System.InvalidOperationException(SR.Get(SRID.PathGeometry_InternalReadBackError)); } if (sameSegCount > 1) { PointCollection ptCollection = new PointCollection(); for (int i = 0; i < pointBezierCount; i++) { ptCollection.Add(new Point(pPoints[pointIndex + i].X, pPoints[pointIndex + i].Y)); } ptCollection.Freeze(); PolyBezierSegment polySeg = new PolyBezierSegment(ptCollection, fStroked, fSmooth); polySeg.Freeze(); figure.Segments.Add(polySeg); } else { Debug.Assert(sameSegCount == 1); figure.Segments.Add(new BezierSegment( new Point(pPoints[pointIndex].X, pPoints[pointIndex].Y), new Point(pPoints[pointIndex + 1].X, pPoints[pointIndex + 1].Y), new Point(pPoints[pointIndex + 2].X, pPoints[pointIndex + 2].Y), fStroked, fSmooth)); } pointIndex += pointBezierCount; } else { throw new System.InvalidOperationException(SR.Get(SRID.PathGeometry_InternalReadBackError)); } } if (isClosed) { figure.IsClosed = true; } figure.Freeze(); Figures.Add(figure); // Do not bother adding empty figures. } }
private void UserDrawWPF(DrawingContext dc) { System.Windows.Media.Color m_LineColor = System.Windows.Media.Colors.Gold; System.Windows.Media.SolidColorBrush m_LineColorBrush = System.Windows.Media.Brushes.Gold; int m_LineWidth = 4; try { int PixelX = 0; int PixelY = 0; if (pntSource.X != 0.0 && pntSource.Y != 0.0) { VMMainViewModel.Instance.ConvertCoordGroundToPixel(pntSource.X, pntSource.Y, ref PixelX, ref PixelY); ImageSource ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/Images/" + "flag_blue.png")); Utilites.UserDrawRasterWPFScreenCoordinate(dc, ImageSource, PixelX, PixelY, 22, 22); } if (pntTarget.X != 0.0 && pntTarget.Y != 0.0) { VMMainViewModel.Instance.ConvertCoordGroundToPixel(pntTarget.X, pntTarget.Y, ref PixelX, ref PixelY); ImageSource ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/Images/" + "flag_red.png")); Utilites.UserDrawRasterWPFScreenCoordinate(dc, ImageSource, PixelX, PixelY, 22, 22); } if (m_PolygonPnts == null) { return; } // if (m_PolygonPnts.Count == 0) return; // m_LineColor = System.Windows.Media.Colors.Gold; // m_LineColorBrush.Color = System.Windows.Media.Colors.Gold; System.Windows.Media.Pen pen = new System.Windows.Media.Pen(m_LineColorBrush, m_LineWidth); pen.Thickness = m_LineWidth; pen.LineJoin = PenLineJoin.Round; System.Windows.Point[] m_ScreenPnts = new System.Windows.Point[m_PolygonPnts.Count]; for (int i = 0; i < m_PolygonPnts.Count; i++) { // int PixelX = 0; // int PixelY = 0; VMMainViewModel.Instance.ConvertCoordGroundToPixel(m_PolygonPnts[i].X, m_PolygonPnts[i].Y, ref PixelX, ref PixelY); m_ScreenPnts[i].X = PixelX; m_ScreenPnts[i].Y = PixelY; } if (m_ScreenPnts.Length > 1) { System.Windows.Media.PathGeometry PathGmtr = new System.Windows.Media.PathGeometry(); System.Windows.Media.PathFigure pathFigure = new System.Windows.Media.PathFigure(); System.Windows.Media.PolyLineSegment myPolyLineSegment = new System.Windows.Media.PolyLineSegment(); System.Windows.Media.PointCollection pc = new System.Windows.Media.PointCollection(m_ScreenPnts); myPolyLineSegment.Points = pc; pathFigure.StartPoint = m_ScreenPnts[0]; pathFigure.Segments.Add(myPolyLineSegment); PathGmtr.Figures.Add(pathFigure); pathFigure.IsClosed = false; dc.DrawGeometry(null, pen, PathGmtr); } if (dtGridRoute != null) { FormattedText frm = new FormattedText("o", System.Globalization.CultureInfo.GetCultureInfo("en-us"), System.Windows.FlowDirection.RightToLeft, new System.Windows.Media.Typeface("Arial"), 18, System.Windows.Media.Brushes.Red); for (int i = 0; i < dtGridRoute.Items.Count; i++) { if (dtGridRoute.SelectedIndex == i) { frm.SetFontSize(24); } else { frm.SetFontSize(18); } OsmRouteData DetailData = ((List <OsmRouteData>)dtGridRoute.ItemsSource)[i]; VMMainViewModel.Instance.ConvertCoordGroundToPixel(DetailData.X, DetailData.Y, ref PixelX, ref PixelY); frm.SetFontWeight(System.Windows.FontWeights.Bold); frm.TextAlignment = TextAlignment.Center; dc.DrawText(frm, new System.Windows.Point(PixelX - frm.Width / 2, PixelY - frm.Height / 2)); FormattedText frmNum = new FormattedText((i + 1).ToString(), System.Globalization.CultureInfo.GetCultureInfo("en-us"), System.Windows.FlowDirection.LeftToRight, new System.Windows.Media.Typeface("Arial"), 14, System.Windows.Media.Brushes.Red); frmNum.SetFontWeight(System.Windows.FontWeights.Bold); dc.DrawText(frmNum, new System.Windows.Point(PixelX, PixelY)); } } } catch (Exception ex) { } }
public void SetAnimDash(PointCollection pc, ShapeLayer layer) { MapPolyline animDashLine = new MapPolyline() { MapStrokeThickness = 20, Points = pc, ScaleFactor = 0.2 }; animDashLine.Stroke = new SolidColorBrush(System.Windows.Media.Color.FromArgb(128, 255, 255, 255)); animDashLine.StrokeLineJoin = PenLineJoin.Round; animDashLine.StrokeStartLineCap = PenLineCap.Flat; animDashLine.StrokeEndLineCap = PenLineCap.Triangle; animDashLine.StrokeDashCap = PenLineCap.Triangle; var dc = new DoubleCollection { 2, 2 }; animDashLine.IsHitTestVisible = false; animDashLine.StrokeDashArray = dc; DoubleAnimation animation = new DoubleAnimation { From = 4, To = 0, FillBehavior = System.Windows.Media.Animation.FillBehavior.HoldEnd, RepeatBehavior = RepeatBehavior.Forever }; var strokeStoryboard = new Storyboard(); strokeStoryboard.Children.Add(animation); Storyboard.SetTargetProperty(animation, new PropertyPath("(Line.StrokeDashOffset)")); Storyboard.SetTarget(animation, animDashLine); strokeStoryboard.Begin(); layer.Shapes.Add(animDashLine); }