private void DelaunayRefine(int scenario) { var sw = new Stopwatch(); sw.Start(); Random rng = new Random(); BoundingBox box = new BoundingBox(0, 10, -10, 0, 0, 0); int size = 50; Geometry.Vector[] points; if (scenario == 1) { points = box.RandomPointsInside(rng, size); } else if (scenario == 2) { points = new Geometry.Vector[] { new Geometry.Vector(10, -9.5), new Geometry.Vector(0, -9.5), new Geometry.Vector(2, -0.5), new Geometry.Vector(8, -0.5) //new Geometry.Vector(4.5,-0.5), //new Geometry.Vector(5.5,-0.5) }; } else { points = new Geometry.Vector[] { new Geometry.Vector(10, -6), new Geometry.Vector(10, -2), new Geometry.Vector(0, -6), //new Geometry.Vector(0, -6) }; } VertexCollection verts = new VertexCollection(points); MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts); faces.Quadrangulate(); faces = faces.Refine(0.5); //Dictionary<Vertex, MeshFace> voronoi = Mesh.VoronoiFromDelaunay(verts, faces); //ShapeCollection geometry = new MeshFaceCollection(voronoi.Values).ExtractFaceBoundaries(); CurveCollection edges = faces.ExtractFaceBoundaries(); VertexGeometryCollection geometry = new VertexGeometryCollection(); foreach (var edge in edges) { var region = new PlanarRegion(edge); geometry.Add(region); region.Attributes = new GeometryAttributes(new Colour(128, 0, 255, 128)); geometry.Add(edge); edge.Attributes = new GeometryAttributes(new Colour(64, 0, 0, 0)); } geometry.Add(new Cloud(verts.ExtractPoints())); sw.Stop(); MeshingTimeText.Text = "Completed: " + faces.Count + " faces in " + sw.Elapsed; DelaunayCanvas.Geometry = geometry; }
private void VoronoiButton_Click(object sender, RoutedEventArgs e) { Random rng = null; if (VoronoiSeedBox.Text.IsNumeric()) { int seed = int.Parse(VoronoiSeedBox.Text); rng = new Random(seed); } else { rng = new Random(); } BoundingBox box = new BoundingBox(0, 10, -10, 0, 0, 0); int size = 500; Geometry.Vector[] points = box.RandomPointsInside(rng, size); VertexCollection verts = new VertexCollection(points); MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts, null, box, false); Dictionary <Vertex, MeshFace> voronoi = Mesh.VoronoiFromDelaunay(verts, faces); MeshFaceCollection outFaces = new MeshFaceCollection(voronoi.Values); PolyLine rect = PolyLine.Rectangle(0, -10, 10, 0); outFaces = outFaces.TrimToPolygonXY(rect.Vertices); outFaces = outFaces.TrimToPolygonXY(rect.Vertices); //Test duplicate edges VertexGeometryCollection geometry = new VertexGeometryCollection(outFaces.ExtractFaceBoundaries()); //ShapeCollection geometry = faces.ExtractFaceBoundaries(); geometry.Add(new Cloud(verts.ExtractPoints())); VoronoiCanvas.Geometry = geometry; }
private void DelaunayButton_Click(object sender, RoutedEventArgs e) { Random rng = new Random(); BoundingBox box = new BoundingBox(0, 10, -10, 0, 0, 0); int size = 100; Geometry.Vector[] points = box.RandomPointsInside(rng, size); VertexCollection verts = new VertexCollection(points); MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts); faces.Quadrangulate(); //Dictionary<Vertex, MeshFace> voronoi = Mesh.VoronoiFromDelaunay(verts, faces); //ShapeCollection geometry = new MeshFaceCollection(voronoi.Values).ExtractFaceBoundaries(); CurveCollection edges = faces.ExtractFaceBoundaries(); VertexGeometryCollection geometry = new VertexGeometryCollection(); foreach (var edge in edges) { var region = new PlanarRegion(edge); geometry.Add(region); region.Attributes = new GeometryAttributes(new Colour(128, 0, 255, 128)); geometry.Add(edge); edge.Attributes = new GeometryAttributes(new Colour(64, 0, 0, 0)); } geometry.Add(new Cloud(verts.ExtractPoints())); DelaunayCanvas.Geometry = geometry; }
/// <summary> /// Generate edge division structures for the specified collection /// of mesh faces /// </summary> /// <param name="faces"></param> public void GenerateForFaces(MeshFaceCollection faces) { foreach (MeshFace face in faces) { for (int i = 0; i < face.Count; i++) { string edgeID = MeshDivisionEdge.IDFor(face, i); if (!Contains(edgeID)) { Add(new MeshDivisionEdge(face, i)); } } } }
private void AnalysisMeshButton_Click(object sender, RoutedEventArgs e) { Random rng = new Random(); BoundingBox box = new BoundingBox(1, 9, -9, -1, 0, 0); int size = 100; //Geometry.Vector[] points = box.RandomPointsInside(rng, size); //VertexCollection verts = new VertexCollection(points); VertexCollection verts = new VertexCollection(); //verts.Add(new Vertex(1, -1)); int divs = 5; for (int i = 0; i <= divs; i++) { for (int j = 0; j <= divs; j++) { Geometry.Vector pt = new Geometry.Vector(box.X.ValueAt(((double)i) / divs), box.Y.ValueAt(((double)j) / divs)); verts.Add(new Vertex(pt)); } } MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts); faces.Quadrangulate(); //Dictionary<Vertex, MeshFace> voronoi = Mesh.VoronoiFromDelaunay(verts, faces); //ShapeCollection geometry = new MeshFaceCollection(voronoi.Values).ExtractFaceBoundaries(); CurveCollection edges = faces.ExtractFaceBoundaries(); VertexGeometryCollection geometry = new VertexGeometryCollection(); foreach (var edge in edges) { var region = new PlanarRegion(edge); geometry.Add(region); region.Attributes = new GeometryAttributes(new Colour(128, 0, 255, 128)); geometry.Add(edge); edge.Attributes = new GeometryAttributes(new Colour(64, 0, 0, 0)); } geometry.Add(new Cloud(verts.ExtractPoints())); DelaunayCanvas.Geometry = geometry; }
public override bool Execute(ExecutionInfo exInfo = null) { Beams = new LinearElementCollection(); VertexCollection verts = new VertexCollection(SupportPoints); MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts); if (Perimeter != null) { faces.CullOutsideXY(Perimeter); } faces.Quadrangulate(); IList <MeshEdge> edges = faces.ExtractUniqueEdges(); foreach (MeshEdge mE in edges) { LinearElement lEl = Model.Create.LinearElement(mE.ToLine(), exInfo); lEl.Family = BeamSection; Beams.Add(lEl); } PanelBoundaries = faces.ExtractFaceBoundaries(); return(true); }
public static TimeSpan DelaunayTest(int size) { Stopwatch sw = new Stopwatch(); Random rng = new Random(); BoundingBox box = new BoundingBox(0, 100, 0, 100, 0, 100); Vector[] points = box.RandomPointsInside(rng, size); VertexCollection verts = new VertexCollection(points); sw.Start(); MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts); sw.Stop(); Stopwatch sw2 = new Stopwatch(); sw2.Start(); Mesh.VoronoiFromDelaunay(verts, faces); sw2.Stop(); Core.Print("Triangulation: " + sw.Elapsed.ToString() + " " + faces.Count + " Tris, Voronoi: " + sw2.Elapsed.ToString()); return(sw.Elapsed); }
/// <summary> /// Initialise a collection of MeshDivisionEdges generated from the specified /// face collection. /// </summary> /// <param name="generateFrom"></param> public MeshDivisionEdgeCollection(MeshFaceCollection generateFrom) { GenerateForFaces(generateFrom); }
public GeometryVisualiserDialog(object visualise) : this() { VertexGeometryCollection geometry = new VertexGeometryCollection(); if (_StorePath.Exists) { try { Stream stream = new FileStream(_StorePath, FileMode.Open, FileAccess.Read, FileShare.Read); stream.Seek(0, SeekOrigin.Begin); IFormatter formatter = new BinaryFormatter(); formatter.Binder = new CustomSerializationBinder(); var storedGeo = formatter.Deserialize(stream) as VertexGeometryCollection; stream.Close(); if (storedGeo != null) { geometry.AddRange(storedGeo); } } catch { } } if (visualise is MeshFace) { visualise = new MeshFaceCollection((MeshFace)visualise); } //else if (visualise is Mesh) visualise = ((Mesh)visualise).Faces; if (visualise is IList <VertexGeometry> ) { geometry.TryAddRange((IList <VertexGeometry>)visualise); } else if (visualise is IList <Curve> ) { geometry.TryAddRange((IList <Curve>)visualise); } else if (visualise is IList <PlanarRegion> ) { geometry.TryAddRange((IList <PlanarRegion>)visualise); } else if (visualise is VertexGeometry) { geometry.TryAdd((VertexGeometry)visualise); } else if (visualise is MeshFaceCollection) { var faces = (MeshFaceCollection)visualise; CurveCollection edges = faces.ExtractFaceBoundaries(); foreach (var edge in edges) { var region = new PlanarRegion(edge); geometry.Add(region); region.Attributes = new GeometryAttributes(new Colour(128, 0, 255, 128)); geometry.Add(edge); edge.Attributes = new GeometryAttributes(new Colour(64, 0, 0, 0)); } } else if (visualise is IList <Vertex> ) { var verts = (IList <Vertex>)visualise; var cloud = new Cloud(verts.GetPositions()); geometry.Add(cloud); } else if (visualise is IList <Geometry.Vector> ) { var v = (IList <Geometry.Vector>)visualise; var cloud = new Cloud(v); geometry.Add(cloud); } else if (visualise is MeshDivisionEdge) { var mDE = (MeshDivisionEdge)visualise; var line = new Geometry.Line(mDE.Start, mDE.End); geometry.Add(line); if (mDE.Vertices != null && mDE.Vertices.Count > 0) { var cloud = new Cloud(mDE.Vertices.GetPositions()); geometry.Add(cloud); } } else if (visualise is IList <MeshDivisionEdge> ) { foreach (var mDC in (IList <MeshDivisionEdge>)visualise) { var mDE = (MeshDivisionEdge)visualise; var line = new Geometry.Line(mDE.Start, mDE.End); geometry.Add(line); if (mDE.Vertices != null && mDE.Vertices.Count > 0) { var cloud = new Cloud(mDE.Vertices.GetPositions()); geometry.Add(cloud); } } } else if (visualise is IWidePath) { IWidePath path = (IWidePath)visualise; AddWidePath(geometry, path); } else if (visualise is IList <IWidePath> ) { foreach (var path in (IList <IWidePath>)visualise) { AddWidePath(geometry, path); } } // TODO: Convert other types to vertexgeometry BoundingBox bBox = geometry.BoundingBox; /*MinX.Text = bBox.MinX.ToString(); * MaxX.Text = bBox.MaxX.ToString(); * MinY.Text = bBox.MinY.ToString(); * MaxY.Text = bBox.MaxY.ToString();*/ Canvas.CurveThickness = 0.005 * bBox.SizeVector.Magnitude(); Canvas.PointDiameter = 0.01 * bBox.SizeVector.Magnitude(); Canvas.DefaultBrush = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)); //Canvas.FillBrush = new SolidColorBrush(Color.FromArgb(64, 0, 0, 0)); Canvas.Geometry = geometry; /*var xDivs = bBox.X.ReasonableDivisions(10); * var yDivs = bBox.Y.ReasonableDivisions(10); * * foreach (double x in xDivs) * { * var line = new Geometry.Line(x, bBox.MinY - 10, x, bBox.MaxY + 10); * line.Attributes = new GeometryAttributes(Rendering.Colour.Green, 0.1); * Canvas.AddContents(line); * }*/ }