private void showWireframe_Checked(object sender, RoutedEventArgs e) { foreach (List<int> pts in this.faces) { if (pts != null) { int index = 0; for (index = 0; index < pts.Count - 1; index++) { LinesVisual3D line = new LinesVisual3D(); line.Color = Colors.Gold; line.Thickness = 1; line.Points.Add(this.points[pts[index]]); line.Points.Add(this.points[pts[index + 1]]); viewport.Children.Add(line); } LinesVisual3D line2 = new LinesVisual3D(); line2.Color = Colors.Gold; line2.Thickness = 1; line2.Points.Add(this.points[pts[index++]]); line2.Points.Add(this.points[pts[0]]); viewport.Children.Add(line2); } } }
void OnCompositionTargetRendering(object sender, EventArgs e) { if (ShowLinesVisual3D && lines==null) { lines = new LinesVisual3D { Color = Colors.Blue }; view1.Children.Add(lines); } if (!ShowLinesVisual3D && lines!=null) { lines.IsRendering = false; view1.Children.Remove(lines); lines = null; } if (ShowPointsVisual3D && points == null) { points = new PointsVisual3D { Color = Colors.Red, Size=6 }; view1.Children.Add(points); } if (!ShowPointsVisual3D && points != null) { points.IsRendering = false; view1.Children.Remove(points); points = null; } if (ShowScreenSpaceLines3D && screenSpaceLines == null) { screenSpaceLines = new ScreenSpaceLines3D { Color = Colors.Green }; view1.Children.Add(screenSpaceLines); } if (!ShowScreenSpaceLines3D && screenSpaceLines != null) { view1.Children.Remove(screenSpaceLines); screenSpaceLines = null; } if (ShowWireLines && wireLines == null) { wireLines = new WireLines { Color = Colors.Pink }; view1.Children.Add(wireLines); } if (!ShowWireLines && wireLines != null) { view1.Children.Remove(wireLines); wireLines = null; } if (Points==null || Points.Count != N || isAnimating) { Points = GeneratePoints(N, watch.ElapsedMilliseconds*0.001); RaisePropertyChanged("Points"); } if (lines != null) lines.Points = Points; if (points != null) points.Points = Points; if (screenSpaceLines != null) screenSpaceLines.Points = Points; if (wireLines != null) wireLines.Lines = Points; }
public void DrawArc(LinesVisual3D lines, double x_start, double y_start, double z_start, double x_stop, double y_stop, double z_stop, double j_pos, double i_pos, bool absoluteIJKMode, bool clockwise) { Point3D initial = new Point3D(x_start, y_start, z_start); Point3D nextpoint = new Point3D(x_stop, y_stop, z_stop); double k = Double.NaN; double radius = Double.NaN; Point3D center = updateCenterWithCommand(initial, nextpoint, j_pos, i_pos, k, radius, absoluteIJKMode, clockwise); List<Point3D> kreispunkte = generatePointsAlongArcBDring(initial, nextpoint, center, clockwise, 0, 15); // Dynamic resolution Point3D old_point = new Point3D(); foreach (Point3D point in kreispunkte) { if (old_point.X != 0) { DrawLine(lines, old_point, point); } old_point = point; } }
private void CreateWireFrameModels(IFCItem item, Vector3D center) { while (item != null) { if (item.ifcID != IntPtr.Zero && item.noVerticesForWireFrame != 0 && item.noPrimitivesForWireFrame != 0) { var points = new Point3DCollection(); Point3DCollection positions; if (item.verticesForWireFrame != null) { for (int i = 0; i < item.noVerticesForWireFrame; i++) { points.Add(new Point3D((item.verticesForWireFrame[3 * i + 0] - center.X), (item.verticesForWireFrame[3 * i + 1] - center.Y), (item.verticesForWireFrame[3 * i + 2] - center.Z))); } } if (item.indicesForWireFrameLineParts != null) { positions = new Point3DCollection(); for (int i = 0; i < item.noPrimitivesForWireFrame; i++) { var idx = item.indicesForWireFrameLineParts[2 * i + 0]; positions.Add(points[idx]); idx = item.indicesForWireFrameLineParts[2 * i + 1]; positions.Add(points[idx]); } } else { positions = points; } LinesVisual3D wireframe = new LinesVisual3D(); wireframe.Points = positions; wireframe.Color = _defaultLineColor; item.Wireframe = wireframe; hVp3D.Children.Add(wireframe); } CreateFaceModels(item.child, center); item = item.next; } }
public void DrawLine(LinesVisual3D lines, Point3D start, Point3D end) { lines.Points.Add(start); lines.Points.Add(end); }
public void DrawLine(LinesVisual3D lines, double x_start, double y_start, double z_start, double x_stop, double y_stop, double z_stop) { lines.Points.Add(new Point3D(x_start, y_start, z_start)); lines.Points.Add(new Point3D(x_stop, y_stop, z_stop)); }
public static void GetPreviewModel(Vector2 min, Vector2 max, double gridSize, LinesVisual3D border, PointsVisual3D pointv) { Vector2 min_temp = new Vector2(Math.Min(min.X, max.X), Math.Min(min.Y, max.Y)); Vector2 max_temp = new Vector2(Math.Max(min.X, max.X), Math.Max(min.Y, max.Y)); min = min_temp; max = max_temp; if ((max.X - min.X) == 0 || (max.Y - min.Y) == 0) { pointv.Points.Clear(); border.Points.Clear(); return; } int pointsX = (int)Math.Ceiling((max.X - min.X) / gridSize) + 1; int pointsY = (int)Math.Ceiling((max.Y - min.Y) / gridSize) + 1; GetPreviewModel(min, max, pointsX, pointsY, border, pointv); }
// Draw the shed in the drawing window thing public void DrawShed(HelixViewport3D view, Data data) { double toRadians = Math.PI/180; double apex = data.eaveHeight + ((data.span/2) * Math.Tan(data.roofPitch * toRadians)); double highEave = data.eaveHeight + (data.span * Math.Tan(data.roofPitch * toRadians)); double length = -data.baySpacing * data.numberOfBays; double z = 0; LinesVisual3D lines = new LinesVisual3D(); lines.Thickness = 4; view.Children.Clear(); view.Children.Add(new SunLight()); // Draw portals for (int i = 0; i < (data.numberOfBays + 1); i++) { z = -data.baySpacing * i; lines.Points.Add(new Point3D(z, 0, 0)); lines.Points.Add(new Point3D(z, 0, data.eaveHeight)); if (data.roofType == "Gable") { lines.Points.Add(new Point3D(z, 0, data.eaveHeight)); lines.Points.Add(new Point3D(z, (data.span / 2), apex)); lines.Points.Add(new Point3D(z, (data.span / 2), apex)); lines.Points.Add(new Point3D(z, data.span, data.eaveHeight)); lines.Points.Add(new Point3D(z, data.span, data.eaveHeight)); lines.Points.Add(new Point3D(z, data.span, 0)); } else { lines.Points.Add(new Point3D(z, 0, data.eaveHeight)); lines.Points.Add(new Point3D(z, data.span, highEave)); lines.Points.Add(new Point3D(z, data.span, highEave)); lines.Points.Add(new Point3D(z, data.span, 0)); } } // Draw ridge and eave elements along building lines.Points.Add(new Point3D(0, 0, data.eaveHeight)); lines.Points.Add(new Point3D(length, 0, data.eaveHeight)); if (data.roofType == "Gable") { if (data.numberOfMullions == 0 || data.numberOfMullions == 2 || data.numberOfMullions == 4) { lines.Points.Add(new Point3D(0, (data.span / 2), apex)); lines.Points.Add(new Point3D(length, (data.span / 2), apex)); } lines.Points.Add(new Point3D(0, data.span, data.eaveHeight)); lines.Points.Add(new Point3D(length, data.span, data.eaveHeight)); } else { lines.Points.Add(new Point3D(0, data.span, highEave)); lines.Points.Add(new Point3D(length, data.span, highEave)); } // Draw knee braces double kneeX1 = 0, kneeY1 = 0, kneeX2 = 0, kneeY2 = 0, kneeX3 = 0, kneeY3 = 0, kneeX4 = 0, kneeY4 = 0; if (data.endKneeBraceType != "None" || data.midKneeBraceType != "None") { kneeX1 = 0; kneeY1 = data.eaveHeight - (data.eaveHeight * (data.kneeBracePercentEave / 100)); kneeX2 = data.span * data.kneeBracePercentSpan / 100; kneeY2 = data.eaveHeight + (Math.Tan(data.roofPitch * toRadians) * (data.kneeBracePercentSpan / 100) * data.span); kneeX3 = data.span - kneeX2; kneeY3 = data.roofType == "Gable" ? kneeY2 : highEave - ((data.kneeBracePercentSpan / 100) * data.span * Math.Tan(data.roofPitch * toRadians)); kneeX4 = data.span; kneeY4 = data.roofType == "Gable" ? kneeY1 : highEave - (highEave * (data.kneeBracePercentEave / 100)); } if (data.endKneeBraceType != "None") { lines.Points.Add(new Point3D(0, kneeX1, kneeY1)); lines.Points.Add(new Point3D(0, kneeX2, kneeY2)); lines.Points.Add(new Point3D(0, kneeX3, kneeY3)); lines.Points.Add(new Point3D(0, kneeX4, kneeY4)); lines.Points.Add(new Point3D(length, kneeX1, kneeY1)); lines.Points.Add(new Point3D(length, kneeX2, kneeY2)); lines.Points.Add(new Point3D(length, kneeX3, kneeY3)); lines.Points.Add(new Point3D(length, kneeX4, kneeY4)); } if (data.midKneeBraceType != "None") { for (int i = 1; i < data.numberOfBays; i++) { lines.Points.Add(new Point3D(-i * data.baySpacing, kneeX1, kneeY1)); lines.Points.Add(new Point3D(-i * data.baySpacing, kneeX2, kneeY2)); lines.Points.Add(new Point3D(-i * data.baySpacing, kneeX3, kneeY3)); lines.Points.Add(new Point3D(-i * data.baySpacing, kneeX4, kneeY4)); lines.Points.Add(new Point3D(-i * data.baySpacing, kneeX1, kneeY1)); lines.Points.Add(new Point3D(-i * data.baySpacing, kneeX2, kneeY2)); lines.Points.Add(new Point3D(-i * data.baySpacing, kneeX3, kneeY3)); lines.Points.Add(new Point3D(-i * data.baySpacing, kneeX4, kneeY4)); } } // Draw apex braces if (data.roofType == "Gable") { double apexX1 = 0, apexY1 = 0, apexX2 = 0, apexY2 = 0; if (data.endApexBraceType != "None" || data.midApexBraceType != "None") { apexX1 = data.span * (1.0 / 3.0); apexY1 = data.eaveHeight + ((data.span / 3) * Math.Tan(data.roofPitch * toRadians)); apexX2 = data.span * (2.0 / 3.0); apexY2 = apexY1; } if (data.endApexBraceType != "None") { lines.Points.Add(new Point3D(0, apexX1, apexY1)); lines.Points.Add(new Point3D(0, apexX2, apexY2)); lines.Points.Add(new Point3D(length, apexX1, apexY1)); lines.Points.Add(new Point3D(length, apexX2, apexY2)); } if (data.midApexBraceType != "None") { for (int i = 1; i < data.numberOfBays; i++) { lines.Points.Add(new Point3D(-i * data.baySpacing, apexX1, apexY1)); lines.Points.Add(new Point3D(-i * data.baySpacing, apexX2, apexY2)); } } } // Draw Mullions & compression struts if (data.numberOfMullions > 0) { double[] xCoords = new double[data.numberOfMullions]; double[] yCoords = new double[data.numberOfMullions]; // Get x, y coords for (int i = 0; i < data.numberOfMullions; i++) xCoords[i] = (data.span / (data.numberOfMullions + 1)) * (i + 1); if (data.roofType == "Skillion") { for (int i = 0; i < data.numberOfMullions; i++) yCoords[i] = data.eaveHeight + (xCoords[i] * Math.Tan(data.roofPitch * toRadians)); } else { for (int i = 0; i < data.numberOfMullions; i++) { if (xCoords[i] <= (data.span / 2)) yCoords[i] = data.eaveHeight + (xCoords[i] * Math.Tan(data.roofPitch * toRadians)); else yCoords[i] = (data.eaveHeight + (xCoords[i] * Math.Tan(data.roofPitch * toRadians))) - ((2 * Math.Tan(data.roofPitch * toRadians)) * ((data.span / 2) - (data.span - xCoords[i]))); } } // Draw mullions for (int i = 0; i < data.numberOfMullions; i++) { lines.Points.Add(new Point3D(0, xCoords[i], 0)); lines.Points.Add(new Point3D(0, xCoords[i], yCoords[i])); lines.Points.Add(new Point3D(length, xCoords[i], 0)); lines.Points.Add(new Point3D(length, xCoords[i], yCoords[i])); } // Draw Compression Struts for (int i = 0; i < data.numberOfMullions; i++) { for (int j = 0; j < data.numberOfBays; j++) { lines.Points.Add(new Point3D(-data.baySpacing * j, xCoords[i], yCoords[i])); lines.Points.Add(new Point3D(-data.baySpacing * (j + 1), xCoords[i], yCoords[i])); } } } // Add lines to view and update default camera view.Children.Add(lines); }
/// <summary> /// Creates a rather ugly visual representatino of the polyline. /// Fixed in size with respect to the model. /// </summary> /// <param name="highlighted">The destination visual component to replace the content of.</param> internal void SetToVisual(MeshVisual3D highlighted) { if (_geomPoints == null) return; var lines = new LinesVisual3D { Color = Colors.Yellow }; var axesMeshBuilder = new MeshBuilder(); List<Point3D> path = new List<Point3D>(); foreach (var item in _geomPoints) { axesMeshBuilder.AddSphere(item.Point, 0.1); path.Add(item.Point); } if (_geomPoints.Count > 1) { double lineThickness = 0.05; axesMeshBuilder.AddTube(path, lineThickness, 9, false); } highlighted.Content = new GeometryModel3D(axesMeshBuilder.ToMesh(), Materials.Yellow); }
public override void Initialize(double cubeSize) { base.N = 2; base.Initialize(); cubeLength = cubeSize; joints = new LinesVisual3D(); jointForces = new Vector3D[N,N,N]; controlPointsOrigin = new Point3D[N, N, N]; double x, y, z; double halfCubeLength = cubeLength/2; for (int i = 0; i < N; i++) { z = i * cubeLength - halfCubeLength; for (int j = 0; j < N; j++) { y = j * cubeLength - halfCubeLength; for (int k = 0; k < N; k++) { x = k * cubeLength - halfCubeLength; controlPoints[i,j,k] = new Point3D(x, y, z); controlPointsOrigin[i, j, k] = new Point3D(x, y, z); } } } points.Points = GetControlPoints(); lines.Points = GetControlLines(); }
public void GetModel(LinesVisual3D line, LinesVisual3D rapid, LinesVisual3D arc) { var sw = System.Diagnostics.Stopwatch.StartNew(); Point3DCollection linePoints = new Point3DCollection(); Point3DCollection rapidPoints = new Point3DCollection(); Point3DCollection arcPoints = new Point3DCollection(); foreach (Command c in Toolpath) { var l = c as Line; if (l != null) { if (l.Rapid) { rapidPoints.Add(l.Start.ToPoint3D()); rapidPoints.Add(l.End.ToPoint3D()); } else { linePoints.Add(l.Start.ToPoint3D()); linePoints.Add(l.End.ToPoint3D()); } continue; } var a = c as Arc; if (a != null) { foreach (Motion sub in a.Split(Settings.Default.ViewportArcSplit)) { arcPoints.Add(sub.Start.ToPoint3D()); arcPoints.Add(sub.End.ToPoint3D()); } } } line.Points = linePoints; rapid.Points = rapidPoints; arc.Points = arcPoints; sw.Stop(); System.Console.WriteLine("Generating the Toolpath Model took {0} ms", sw.ElapsedMilliseconds); }
protected virtual void OnScaleFactorPropertyChanged(DependencyPropertyChangedEventArgs e) { var oldValue = (int)e.OldValue; var newValue = (int)e.NewValue; if (oldValue != newValue) { if (newValue > 0) { if (_lines != null) { RemoveVisualChildren(_lines, _xaxis, _yaxis, _zaxis); } _lines = new LinesVisual3D { Thickness = 0.5, Color = Colors.Black, Points = new Point3DCollection(new[] { new Point3D(-newValue, +newValue, +newValue), new Point3D(+newValue, +newValue, +newValue), new Point3D(-newValue, +newValue, -newValue), new Point3D(+newValue, +newValue, -newValue), new Point3D(-newValue, -newValue, +newValue), new Point3D(+newValue, -newValue, +newValue), new Point3D(-newValue, -newValue, -newValue), new Point3D(+newValue, -newValue, -newValue), new Point3D(+newValue, -newValue, +newValue), new Point3D(+newValue, +newValue, +newValue), new Point3D(+newValue, -newValue, -newValue), new Point3D(+newValue, +newValue, -newValue), new Point3D(-newValue, -newValue, +newValue), new Point3D(-newValue, +newValue, +newValue), new Point3D(-newValue, -newValue, -newValue), new Point3D(-newValue, +newValue, -newValue), new Point3D(+newValue, +newValue, -newValue), new Point3D(+newValue, +newValue, +newValue), new Point3D(+newValue, -newValue, -newValue), new Point3D(+newValue, -newValue, +newValue), new Point3D(-newValue, +newValue, -newValue), new Point3D(-newValue, +newValue, +newValue), new Point3D(-newValue, -newValue, -newValue), new Point3D(-newValue, -newValue, +newValue), }) }; _xaxis = MakeArrowVisual(newValue, 0, 0, Brushes.Red); _yaxis = MakeArrowVisual(0, newValue, 0, Brushes.Green); _zaxis = MakeArrowVisual(0, 0, newValue, Brushes.Blue); AddVisualChildren(_lines, _xaxis, _yaxis, _zaxis); } } }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: #line 11 "..\..\MainWindow.xaml" ((Mapper.Wpf.MainWindow)(target)).Loaded += new System.Windows.RoutedEventHandler(this.OnLoaded); #line default #line hidden #line 12 "..\..\MainWindow.xaml" ((Mapper.Wpf.MainWindow)(target)).Unloaded += new System.Windows.RoutedEventHandler(this.OnUnloaded); #line default #line hidden return; case 2: this.Viewport = ((HelixToolkit.Wpf.HelixViewport3D)(target)); return; case 3: this.MapPlotter = ((HelixToolkit.Wpf.LinesVisual3D)(target)); return; case 4: this.FileModelVisual3D = ((HelixToolkit.Wpf.FileModelVisual3D)(target)); return; case 5: this.LogScrollViewer = ((System.Windows.Controls.ScrollViewer)(target)); return; case 6: this.LogTextBox = ((System.Windows.Controls.TextBox)(target)); return; case 7: this.StartButton = ((System.Windows.Controls.Button)(target)); #line 114 "..\..\MainWindow.xaml" this.StartButton.Click += new System.Windows.RoutedEventHandler(this.StartButtonOnClick); #line default #line hidden return; case 8: this.StopButton = ((System.Windows.Controls.Button)(target)); #line 120 "..\..\MainWindow.xaml" this.StopButton.Click += new System.Windows.RoutedEventHandler(this.StopButtonOnClick); #line default #line hidden return; case 9: this.DisconnectButton = ((System.Windows.Controls.Button)(target)); #line 126 "..\..\MainWindow.xaml" this.DisconnectButton.Click += new System.Windows.RoutedEventHandler(this.DisconnectButtonOnClick); #line default #line hidden return; case 10: this.ResetViewButton = ((System.Windows.Controls.Button)(target)); #line 132 "..\..\MainWindow.xaml" this.ResetViewButton.Click += new System.Windows.RoutedEventHandler(this.ResetViewButtonOnClick); #line default #line hidden return; case 11: this.CarNameTextBlock = ((System.Windows.Controls.TextBlock)(target)); return; case 12: this.SpeedSlider = ((System.Windows.Controls.Slider)(target)); return; case 13: this.MinDistanceSlider = ((System.Windows.Controls.Slider)(target)); return; case 14: this.SaveButton = ((System.Windows.Controls.Button)(target)); #line 230 "..\..\MainWindow.xaml" this.SaveButton.Click += new System.Windows.RoutedEventHandler(this.SaveButtonOnClick); #line default #line hidden return; } this._contentLoaded = true; }
private void OnCompositionTargetRendering(object sender, EventArgs e) { if (this.ShowLinesVisual3D && this.linesVisual == null) { this.linesVisual = new LinesVisual3D { Color = Colors.Blue }; View1.Children.Add(this.linesVisual); } if (!this.ShowLinesVisual3D && this.linesVisual != null) { this.linesVisual.IsRendering = false; View1.Children.Remove(this.linesVisual); this.linesVisual = null; } if (this.ShowPointsVisual3D && this.pointsVisual == null) { this.pointsVisual = new PointsVisual3D { Color = Colors.Red, Size = 6 }; View1.Children.Add(this.pointsVisual); } if (!this.ShowPointsVisual3D && this.pointsVisual != null) { this.pointsVisual.IsRendering = false; View1.Children.Remove(this.pointsVisual); this.pointsVisual = null; } if (this.ShowScreenSpaceLines3D && this.screenSpaceLines == null) { this.screenSpaceLines = new ScreenSpaceLines3D { Color = Colors.Green }; View1.Children.Add(this.screenSpaceLines); } if (!this.ShowScreenSpaceLines3D && this.screenSpaceLines != null) { View1.Children.Remove(this.screenSpaceLines); this.screenSpaceLines = null; } if (this.ShowWireLines && this.wireLines == null) { this.wireLines = new WireLines { Color = Colors.Pink }; View1.Children.Add(this.wireLines); } if (!this.ShowWireLines && this.wireLines != null) { View1.Children.Remove(this.wireLines); this.wireLines = null; } if (this.Points == null || this.Points.Count != this.NumberOfPoints) { this.Points = new Point3DCollection(GeneratePoints(this.NumberOfPoints, this.watch.ElapsedMilliseconds * 0.001)); } if (this.linesVisual != null) { this.linesVisual.Points = this.Points; } if (this.pointsVisual != null) { this.pointsVisual.Points = this.Points; } if (this.screenSpaceLines != null) { this.screenSpaceLines.Points = this.Points; } if (this.wireLines != null) { this.wireLines.Lines = this.Points; } }
public static void GetPreviewModel(Vector2 min, Vector2 max, int pointsX, int pointsY, LinesVisual3D border, PointsVisual3D pointv) { Vector2 min_temp = new Vector2(Math.Min(min.X, max.X), Math.Min(min.Y, max.Y)); Vector2 max_temp = new Vector2(Math.Max(min.X, max.X), Math.Max(min.Y, max.Y)); min = min_temp; max = max_temp; double gridX = (max.X - min.X) / (pointsX - 1); double gridY = (max.Y - min.Y) / (pointsY - 1); Point3DCollection points = new Point3DCollection(); for (int x = 0; x < pointsX; x++) { for (int y = 0; y < pointsY; y++) { points.Add(new Point3D(min.X + x * gridX, min.Y + y * gridY, 0)); } } pointv.Points.Clear(); pointv.Points = points; Point3DCollection b = new Point3DCollection(); b.Add(new Point3D(min.X, min.Y, 0)); b.Add(new Point3D(min.X, max.Y, 0)); b.Add(new Point3D(min.X, max.Y, 0)); b.Add(new Point3D(max.X, max.Y, 0)); b.Add(new Point3D(max.X, max.Y, 0)); b.Add(new Point3D(max.X, min.Y, 0)); b.Add(new Point3D(max.X, min.Y, 0)); b.Add(new Point3D(min.X, min.Y, 0)); border.Points.Clear(); border.Points = b; }
/// <summary> /// Creates the grid. /// </summary> protected void CreateGrid() { var majorLinePoints = new Point3DCollection(); var minorLinePoints = new Point3DCollection(); var xlinePoints = new Point3DCollection(); var ylinePoints = new Point3DCollection(); this.lengthDirection = this.LengthDirection; this.lengthDirection.Normalize(); this.widthDirection = Vector3D.CrossProduct(this.Normal, this.lengthDirection); this.widthDirection.Normalize(); double minX = -this.Width / 2; double minY = -this.Length / 2; double maxX = this.Width / 2; double maxY = this.Length / 2; double z = this.MajorDistance * 1e-4; double x = minX; double eps = this.MinorDistance / 10; while (x <= maxX + eps) { var pc = IsMultipleOf(x, this.MajorDistance) ? majorLinePoints : minorLinePoints; if (Math.Abs(x) < double.Epsilon) { this.AddLine(pc, this.GetPoint(x, minY, z), this.GetPoint(x, 0, z)); this.AddLine(ylinePoints, this.GetPoint(x, 0, 2 * z), this.GetPoint(x, maxY, 2 * z)); } else { this.AddLine(pc, this.GetPoint(x, minY, z), this.GetPoint(x, maxY, z)); } x += this.MinorDistance; } double y = minY; while (y <= maxY + eps) { var pc = IsMultipleOf(y, this.MajorDistance) ? majorLinePoints : minorLinePoints; if (Math.Abs(y) < double.Epsilon) { this.AddLine(pc, this.GetPoint(minX, y), this.GetPoint(0, y)); this.AddLine(xlinePoints, this.GetPoint(0, y, 2 * z), this.GetPoint(maxX, y, 2 * z)); } else { this.AddLine(pc, this.GetPoint(minX, y), this.GetPoint(maxY, y)); } y += this.MinorDistance; } var majorLines = new LinesVisual3D { Color = this.MajorLineColor, Thickness = this.MajorLineThickness, Points = majorLinePoints, IsRendering = true }; var minorLines = new LinesVisual3D { Color = this.MinorLineColor, Thickness = this.MinorLineThickness, Points = minorLinePoints, IsRendering = true }; var xlines = new LinesVisual3D { Color = this.YAxisLineColor, Thickness = this.MajorLineThickness, Points = xlinePoints, IsRendering = true }; var ylines = new LinesVisual3D { Color = this.XAxisLineColor, Thickness = this.MajorLineThickness, Points = ylinePoints, IsRendering = true }; this.Children.Add(majorLines); this.Children.Add(minorLines); this.Children.Add(xlines); this.Children.Add(ylines); }
public override void SetupCustomUIElements(Controls.dynNodeView nodeUI) { MenuItem mi = new MenuItem(); mi.Header = "Zoom to Fit"; mi.Click += new RoutedEventHandler(mi_Click); nodeUI.MainContextMenu.Items.Add(mi); //take out the left and right margins and make this so it's not so wide //NodeUI.inputGrid.Margin = new Thickness(10, 10, 10, 10); //add a 3D viewport to the input grid //http://helixtoolkit.codeplex.com/wikipage?title=HelixViewport3D&referringTitle=Documentation _watchView = new WatchView(); _watchView.watch_view.DataContext = this; RenderOptions.SetEdgeMode(_watchView, EdgeMode.Unspecified); Points = new Point3DCollection(); Lines = new Point3DCollection(); _points = new PointsVisual3D { Color = Colors.Red, Size = 6 }; _lines = new LinesVisual3D { Color = Colors.Blue, Thickness = 1 }; _points.Points = Points; _lines.Points = Lines; _watchView.watch_view.Children.Add(_lines); _watchView.watch_view.Children.Add(_points); _watchView.watch_view.Children.Add(new DefaultLights()); _watchView.Width = 400; _watchView.Height = 300; System.Windows.Shapes.Rectangle backgroundRect = new System.Windows.Shapes.Rectangle(); backgroundRect.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; backgroundRect.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; //backgroundRect.RadiusX = 10; //backgroundRect.RadiusY = 10; backgroundRect.IsHitTestVisible = false; BrushConverter bc = new BrushConverter(); Brush strokeBrush = (Brush)bc.ConvertFrom("#313131"); backgroundRect.Stroke = strokeBrush; backgroundRect.StrokeThickness = 1; SolidColorBrush backgroundBrush = new SolidColorBrush(System.Windows.Media.Color.FromRgb(250, 250, 216)); backgroundRect.Fill = backgroundBrush; //nodeUI.inputGrid.Children.Add(backgroundRect); //nodeUI.inputGrid.Children.Add(_watchView); nodeUI.grid.Children.Add(backgroundRect); nodeUI.grid.Children.Add(_watchView); backgroundRect.SetValue(Grid.RowProperty,2); backgroundRect.SetValue(Grid.ColumnSpanProperty,3); _watchView.SetValue(Grid.RowProperty, 2); _watchView.SetValue(Grid.ColumnSpanProperty, 3); _watchView.Margin = new Thickness(5,0,5,5); backgroundRect.Margin = new Thickness(5, 0, 5, 5); CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering); }
private void SetDraw(object sender, RoutedEventArgs e) { if (checkDraw.IsChecked.GetValueOrDefault()) { tmpArrete = new LinesVisual3D(); tmpArrete.Color = colorLines; tmpArrete.Thickness = 0.01; tmpPoints = new PointsVisual3D(); tmpPoints.Color = colorPoints; tmpPoints.Size = 0.05; bufArrete = new Point3DCollection(); bufPoint = new Point3DCollection(); listePoints.Add(tmpPoints); listeLignes.Add(tmpArrete); ViewPort.Children.Add(listeLignes.Last()); ViewPort.Children.Add(listePoints.Last()); nbTraits.Content = "Nombre de traits : " + listeLignes.Count; timer.Tick += new EventHandler(drawPoints); timer.Start(); } }
private void Button_Click(object sender, RoutedEventArgs e) { var ofd = new OpenFileDialog(); ofd.FileOk += (_, __) => { var file = ofd.FileName; Result r; using (var fs = File.OpenRead(file)) r = ProtoBuf.Serializer.Deserialize<Result>(fs); _model.Children.Clear(); var nLines = r.Elements.SelectMany(x => x.Geometries).Select(g => r.Geometries[g.GeometryIndex]).Select(x => ((TriangulatedGeometryData)x).Lines.Length).Sum(); var nTriangles = r.Elements.SelectMany(x => x.Geometries).Select(g => r.Geometries[g.GeometryIndex]).Select(x => ((TriangulatedGeometryData)x).Triangles.Length).Sum(); Debug.WriteLine($"Model contains {nLines} Lines and {nTriangles} Triangles"); var material = MaterialHelper.CreateMaterial(Colors.Red, 1); foreach (var ele in r.Elements) { foreach (var geoRef in ele.Geometries) { var geo = r.Geometries[geoRef.GeometryIndex]; var triangulated = geo as TriangulatedGeometryData; if (triangulated != null) { var builder = new MeshBuilder(true, false); foreach (var t in triangulated.Triangles) { var a = r.PointsAndVectors[t.A].ToWpfPoint(); var b = r.PointsAndVectors[t.B].ToWpfPoint(); var c = r.PointsAndVectors[t.C].ToWpfPoint(); builder.AddTriangle(a, c, b); } var mesh = builder.ToMesh(true); var geoModel = new GeometryModel3D { Geometry = mesh, Material = material }; Transform3D matrix = null; if (geoRef.Transform != null) { matrix = new MatrixTransform3D(MatrixHelper.FromArray(geoRef.Transform.Matrix)); geoModel.Transform = matrix; } var modelVisual = new ModelVisual3D { Content = geoModel }; if (_lines.IsChecked == true) { foreach (var l in triangulated.Lines) { var a = r.PointsAndVectors[l.A].ToWpfPoint(); var b = r.PointsAndVectors[l.B].ToWpfPoint(); var lineGeo = new LinesVisual3D { Color = Colors.Green, Points = new[] { a, b } }; if (matrix != null) lineGeo.Transform = matrix; modelVisual.Children.Add(lineGeo); } } _model.Children.Add(modelVisual); } else { throw new Exception("unknown geo data: " + geo.GetType()); } } } _viewPort.ZoomExtents(500); }; ofd.ShowDialog(); }
public dyn3DPreview() { InPortData.Add(new PortData("IN", "Incoming geometry objects.", typeof(object))); OutPortData.Add(new PortData("OUT", "Watch contents, passed through", typeof(object))); NodeUI.RegisterAllPorts(); //get rid of right click delete //this.MainContextMenu.Items.Clear(); MenuItem mi = new MenuItem(); mi.Header = "Zoom to Fit"; mi.Click +=new RoutedEventHandler(mi_Click); NodeUI.MainContextMenu.Items.Add(mi); //take out the left and right margins //and make this so it's not so wide NodeUI.inputGrid.Margin = new Thickness(10, 10, 10, 10); isScreenShot = true; if (isScreenShot) { NodeUI.topControl.Width = 800; NodeUI.topControl.Height = 500; } else { NodeUI.topControl.Width = 400; NodeUI.topControl.Height = 300; } //this.elementShine.Visibility = System.Windows.Visibility.Hidden; //this.elementRectangle.Visibility = System.Windows.Visibility.Hidden; //add a 3D viewport to the input grid //http://helixtoolkit.codeplex.com/wikipage?title=HelixViewport3D&referringTitle=Documentation view = new HelixViewport3D(); view.DataContext = this; view.CameraRotationMode = CameraRotationMode.Turntable; view.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; view.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; //RenderOptions.SetEdgeMode(view,EdgeMode.Aliased); RenderOptions.SetEdgeMode(view, EdgeMode.Unspecified); view.ShowViewCube = false; //view.IsHitTestVisible = true; view.ShowFrameRate = true; view.MouseRightButtonUp += new System.Windows.Input.MouseButtonEventHandler(view_MouseRightButtonUp); view.PreviewMouseRightButtonDown += new System.Windows.Input.MouseButtonEventHandler(view_PreviewMouseRightButtonDown); fixedPoints = new PointsVisual3D { Color = Colors.Red, Size = 8 }; view.Children.Add(fixedPoints); points = new PointsVisual3D { Color = Colors.Black, Size = 4 }; view.Children.Add(points); // a list of 10 colors to be used for // mapping analysis results colors.Add(Colors.Black); //01 colors.Add(Colors.LightBlue); //02 colors.Add(Colors.Blue); //03 colors.Add(Colors.Purple); //04 colors.Add(Colors.LightGreen); //05 colors.Add(Colors.GreenYellow); //06 colors.Add(Colors.Yellow); //07 colors.Add(Colors.Orange); //08 colors.Add(Colors.OrangeRed); //09 colors.Add(Colors.Red); //10 colors.Add(Colors.Black);//11 for naked lines and curves FixedPoints = new Point3DCollection(); Points = new List<Point3DCollection>(); for (int i = 0; i < colors.Count(); i++) { Points.Add(new Point3DCollection()); } linesList = new List<LinesVisual3D>(); for (int i = 0; i < colors.Count(); i++) { LinesVisual3D lines = new LinesVisual3D { Color = colors[i], Thickness = 1 }; linesList.Add(lines); view.Children.Add(lines); } System.Windows.Shapes.Rectangle backgroundRect = new System.Windows.Shapes.Rectangle(); backgroundRect.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; backgroundRect.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; backgroundRect.RadiusX = 10; backgroundRect.RadiusY = 10; backgroundRect.IsHitTestVisible = false; BrushConverter bc = new BrushConverter(); Brush strokeBrush = (Brush)bc.ConvertFrom("#313131"); backgroundRect.Stroke = strokeBrush; backgroundRect.StrokeThickness = 1; SolidColorBrush backgroundBrush = new SolidColorBrush(System.Windows.Media.Color.FromRgb(250,250,216)); backgroundRect.Fill = backgroundBrush; NodeUI.inputGrid.Children.Add(backgroundRect); NodeUI.inputGrid.Children.Add(view); CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering); }
public void GetPreviewModel(LinesVisual3D border, PointsVisual3D pointv) { GetPreviewModel(Min, Max, SizeX, SizeY, border, pointv); }