/// <summary> /// Shows the with convex hull. /// </summary> /// <param name="ts">The ts.</param> public static void ShowWithConvexHull(TessellatedSolid ts) { var window = new Window3DPlot(); window.view1.Children.Add(MakeModelVisual3D(ts)); var positions = ts.ConvexHull.Faces.SelectMany( f => f.Vertices.Select(v => new Point3D(v.Position[0], v.Position[1], v.Position[2]))); var normals = ts.ConvexHull.Faces.SelectMany(f => f.Vertices.Select(v => new Vector3D(f.Normal[0], f.Normal[1], f.Normal[2]))); window.view1.Children.Add( new ModelVisual3D { Content = new GeometryModel3D { Geometry = new MeshGeometry3D { Positions = new Point3DCollection(positions), // TriangleIndices = new Int32Collection(triIndices), Normals = new Vector3DCollection(normals) }, Material = MaterialHelper.CreateMaterial(new System.Windows.Media.Color { A = 189, G = 189, B = 189 }) } }); window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); //window.Show(); window.ShowDialog(); }
/// <summary> /// Shows vertex paths. Assumes paths are closed. /// </summary> /// <param name="vertexPaths">The vertex paths.</param> public static void ShowVertexPaths(IList <List <List <Vertex> > > vertexPaths) { var window = new Window3DPlot(); foreach (var crossSection in vertexPaths) { foreach (var path in crossSection) { var contour = path.Select(point => new Point3D(point.X, point.Y, point.Z)).ToList(); //No create a line collection by doubling up the points var lineCollection = new List <Point3D>(); foreach (var t in contour) { lineCollection.Add(t); lineCollection.Add(t); } lineCollection.RemoveAt(0); lineCollection.Add(lineCollection.First()); var lines = new LinesVisual3D { Points = new Point3DCollection(lineCollection) }; window.view1.Children.Add(lines); } } window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); window.ShowDialog(); }
public static void ShowAndHang(VoxelizedSolid solid, IEnumerable <Polygon> polygons) { var window = new Window3DPlot(); var models = new List <Visual3D>(); Visual3D model = MakeModelVisual3D(solid); models.Add(model); window.view1.Children.Add(model); foreach (var polygon in polygons.SelectMany(poly => poly.AllPolygons)) { //Now create a line collection by doubling up the points var lineCollection = new List <Point3D>(); foreach (var line in polygon.Edges) { lineCollection.Add(new Point3D(line.FromPoint.X, line.FromPoint.Y, 0)); lineCollection.Add(new Point3D(line.ToPoint.X, line.ToPoint.Y, 0)); } var lines = new LinesVisual3D { Points = new Point3DCollection(lineCollection), Thickness = 5, Color = Colors.Red }; window.view1.Children.Add(lines); } window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); window.ShowDialog(); }
/// <summary> /// Shows the vertex paths with solid. /// </summary> /// <param name="segments">The segments.</param> /// <param name="solids">The solids.</param> public static void ShowVertexPathsWithSolid(IList <double[]> segments, IList <TessellatedSolid> solids) { var window = new Window3DPlot(); var models = new List <Visual3D>(); foreach (var tessellatedSolid in solids) { var model = MakeModelVisual3D(tessellatedSolid); models.Add(model); window.view1.Children.Add(model); } foreach (var point in segments) { var lineCollection = new List <Point3D> { new Point3D(point[0], point[1], point[2]), new Point3D(point[3], point[4], point[5]) }; var color = new System.Windows.Media.Color(); color.R = 255; //G & B default to 0 to form red var lines = new LinesVisual3D { Points = new Point3DCollection(lineCollection) }; window.view1.Children.Add(lines); } window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); window.ShowDialog(); }
/// <summary> /// Shows the and hang. /// </summary> /// <param name="tessellatedSolid">The tessellated solid.</param> public static void ShowAndHang(TessellatedSolid tessellatedSolid) { var window = new Window3DPlot(); window.view1.Children.Add(MakeModelVisual3D(tessellatedSolid)); window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); window.ShowDialog(); }
/// <summary> /// Shows the vertex paths with solid. /// </summary> /// <param name="vertexPaths">The vertex paths.</param> /// <param name="solids">The solids.</param> public static void ShowVertexPathsWithSolid(IEnumerable <IEnumerable <IEnumerable <Vector3> > > vertexPaths, IEnumerable <TessellatedSolid> solids, bool closeLoops = true) { var window = new Window3DPlot(); var models = new List <Visual3D>(); foreach (var tessellatedSolid in solids) { var model = MakeModelVisual3D(tessellatedSolid); models.Add(model); window.view1.Children.Add(model); } var random = new Random(); foreach (var crossSection in vertexPaths) { foreach (var path in crossSection) { var contour = path.Select(point => new Point3D(point.X, point.Y, point.Z)).ToList(); //Now create a line collection by doubling up the points var lineCollection = new List <Point3D>(); foreach (var t in contour) { lineCollection.Add(t); lineCollection.Add(t); } lineCollection.RemoveAt(0); if (closeLoops) { lineCollection.Add(lineCollection.First()); } else { lineCollection.RemoveAt(lineCollection.Count - 1); } var colFamily = Constants.ColorDictionary[(TVGL.ColorFamily)random.Next(12)]; var colorKeyList = colFamily.Keys.ToList(); var tvglcolor = colFamily[colorKeyList[random.Next(colorKeyList.Count)]]; var color = new System.Windows.Media.Color(); color.R = tvglcolor.R; color.G = tvglcolor.G; color.B = tvglcolor.B; var lines = new LinesVisual3D { Points = new Point3DCollection(lineCollection), Color = color, Thickness = 3.0 }; window.view1.Children.Add(lines); } } window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); window.ShowDialog(); }
public static void ShowAndHang(VoxelizedSolid solid) { var window = new Window3DPlot(); var models = new List <Visual3D>(); Visual3D model = MakeModelVisual3D(solid); models.Add(model); window.view1.Children.Add(model); window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); window.ShowDialog(); }
public static void ShowAndHang(IList <TessellatedSolid> tessellatedSolids) { var window = new Window3DPlot(); var models = new List <Visual3D>(); foreach (var tessellatedSolid in tessellatedSolids) { var model = MakeModelVisual3D(tessellatedSolid); models.Add(model); window.view1.Children.Add(model); } window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); window.ShowDialog(); }
/// <summary> /// Shows the provided objects and "hangs" (halts code until user closes presenter window). /// </summary> /// <param name="tessellatedSolid">The tessellated solid.</param> public static void ShowAndHang(IEnumerable <PolygonalFace> faces, TVGL.Color color = null) { var window = new Window3DPlot(); var sysWindowsColor = color != null ? new System.Windows.Media.Color { A = color.A, B = color.B, G = color.G, R = color.R } : System.Windows.Media.Colors.Blue; window.view1.Children.Add(MakeModelVisual3DMultiColorFaces(faces, MaterialHelper.CreateMaterial(sysWindowsColor))); window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); window.ShowDialog(); }
/// <summary> /// Shows the and hang transparents and solids. /// </summary> /// <param name="transparents">The transparents.</param> /// <param name="solids">The solids.</param> public static void ShowAndHangTransparentsAndSolids(IList <TessellatedSolid> transparents, IList <TessellatedSolid> solids) { var window = new Window3DPlot(); foreach (var ts in solids) { window.view1.Children.Add(MakeModelVisual3D(ts)); } foreach (var ts in transparents) { var positions = ts.Faces.SelectMany( f => f.Vertices.Select(v => new Point3D(v.Position[0], v.Position[1], v.Position[2]))); var normals = ts.Faces.SelectMany(f => f.Vertices.Select(v => new Vector3D(f.Normal[0], f.Normal[1], f.Normal[2]))); var r = ts.SolidColor.R; var g = ts.SolidColor.G; var b = ts.SolidColor.B; window.view1.Children.Add( new ModelVisual3D { Content = new GeometryModel3D { Geometry = new MeshGeometry3D { Positions = new Point3DCollection(positions), Normals = new Vector3DCollection(normals) }, Material = MaterialHelper.CreateMaterial(new System.Windows.Media.Color { A = 120, R = r, G = g, B = b }) } }); } window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); window.ShowDialog(); }
public static void ShowAndHang(IList <Solid> solids) { var window = new Window3DPlot(); var models = new List <Visual3D>(); foreach (var s in solids) { Visual3D model = null; if (s is TessellatedSolid) { model = MakeModelVisual3D((TessellatedSolid)s); } else if (s is VoxelizedSolid) { model = MakeModelVisual3D((VoxelizedSolid)s); } models.Add(model); window.view1.Children.Add(model); } window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); window.ShowDialog(); }
/// <summary> /// Shows the vertex paths. /// </summary> /// <param name="segments">The segments.</param> public static void ShowVertexPaths(IEnumerable <double[]> segments) { var window = new Window3DPlot(); var models = new List <Visual3D>(); foreach (var point in segments) { var lineCollection = new List <Point3D> { new Point3D(point[0], point[1], point[2]), new Point3D(point[3], point[4], point[5]) }; var color = new System.Windows.Media.Color(); color.R = 255; //G & B default to 0 to form red var lines = new LinesVisual3D { Points = new Point3DCollection(lineCollection), Color = color }; window.view1.Children.Add(lines); } window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); window.ShowDialog(); }
/// <summary> /// Shows the vertex paths with solid. /// </summary> /// <param name="vertexPaths">The vertex paths.</param> /// <param name="solids">The solids.</param> public static void ShowVertexPathsWithSolid(IList <List <List <double[]> > > vertexPaths, IList <TessellatedSolid> solids) { var window = new Window3DPlot(); var models = new List <Visual3D>(); foreach (var tessellatedSolid in solids) { var model = MakeModelVisual3D(tessellatedSolid); models.Add(model); window.view1.Children.Add(model); } foreach (var crossSection in vertexPaths) { foreach (var path in crossSection) { var contour = path.Select(point => new Point3D(point[0], point[1], point[2])).ToList(); //Now create a line collection by doubling up the points var lineCollection = new List <Point3D>(); foreach (var t in contour) { lineCollection.Add(t); lineCollection.Add(t); } lineCollection.RemoveAt(0); lineCollection.Add(lineCollection.First()); var color = new System.Windows.Media.Color(); color.R = 255; //G & B default to 0 to form red var lines = new LinesVisual3D { Points = new Point3DCollection(lineCollection), Color = color }; window.view1.Children.Add(lines); } } window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); window.ShowDialog(); }
/// <summary> /// Shows the vertex paths with solid. /// </summary> /// <param name="paths"></param> /// <param name="closePaths"></param> /// <param name="solid"></param> public static void ShowVertexPaths(IList <List <double[]> > paths, bool closePaths = true, TessellatedSolid solid = null) { var window = new Window3DPlot(); var models = new List <Visual3D>(); if (solid != null) { var model = MakeModelVisual3D(solid); models.Add(model); window.view1.Children.Add(model); } foreach (var path in paths) { var contour = path.Select(point => new Point3D(point[0], point[1], point[2])).ToList(); //Now create a line collection by doubling up the points var lineCollection = new List <Point3D>(); foreach (var t in contour) { lineCollection.Add(t); lineCollection.Add(t); } lineCollection.RemoveAt(0); if (closePaths) { lineCollection.Add(lineCollection.First()); } var lines = new LinesVisual3D { Points = new Point3DCollection(lineCollection) }; window.view1.Children.Add(lines); } window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); window.ShowDialog(); }
public static void ShowAndHang(IEnumerable <Solid> solids) { var window = new Window3DPlot(); var models = new List <Visual3D>(); foreach (var s in solids) { if (s is CrossSectionSolid) { var contours = MakeLinesVisual3D(((CrossSectionSolid)s).GetCrossSectionsAs3DLoops(), true); models.AddRange(contours); foreach (var contour in contours) { window.view1.Children.Add(contour); } } else { Visual3D model = null; if (s is TessellatedSolid) { model = MakeModelVisual3D((TessellatedSolid)s); } else if (s is VoxelizedSolid) { model = MakeModelVisual3D((VoxelizedSolid)s); } else if (s is ImplicitSolid) { model = MakeModelVisual3D(((ImplicitSolid)s).ConvertToTessellatedSolid()); } models.Add(model); window.view1.Children.Add(model); } } window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); window.ShowDialog(); }
/// <summary> /// Shows vertex paths. Assumes paths are closed. /// </summary> /// <param name="vertices">The vertices.</param> /// <param name="colors">The colors.</param> /// <param name="ts">The ts.</param> public static void ShowGaussSphereWithIntensity(IList <Vertex> vertices, IList <Color> colors, TessellatedSolid ts) { var window = new Window3DPlot(); var pt0 = new Point3D(ts.Center[0], ts.Center[1], ts.Center[2]); var x = ts.XMax - ts.XMin; var y = ts.YMax - ts.YMin; var z = ts.ZMax - ts.ZMin; var radius = System.Math.Max(System.Math.Max(x, y), z) / 2; //Add the solid to the visual var model = MakeModelVisual3D(ts); window.view1.Children.Add(model); //Add a transparent unit sphere to the visual var sphere = new SphereVisual3D(); sphere.Radius = radius; sphere.Center = pt0; sphere.Material = MaterialHelper.CreateMaterial(new System.Windows.Media.Color { A = 15, R = 200, G = 200, B = 200 }); //window.view1.Children.Add(sphere); var i = 0; foreach (var point in vertices) { var color = colors[i]; var pt1 = new Point3D(pt0.X + point.X * radius, pt0.Y + point.Y * radius, pt0.Z + point.Z * radius); //No create a line collection by doubling up the points var lineCollection = new List <Point3D>(); lineCollection.Add(pt0); lineCollection.Add(pt1); var systemColor = new System.Windows.Media.Color(); systemColor.A = 255; systemColor.R = color.R; systemColor.G = color.G; systemColor.B = color.B; var lines = new LinesVisual3D { Points = new Point3DCollection(lineCollection), Color = systemColor, Thickness = 5 }; var pointsVisual = new PointsVisual3D { Color = systemColor, Size = 5 }; pointsVisual.Points = new Point3DCollection() { pt1 }; window.view1.Children.Add(pointsVisual); window.view1.Children.Add(lines); i++; } window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection); window.ShowDialog(); }