Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
        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);
        }