示例#1
0
        public void Execute()
        {
            var rectContourVertices = new List <Vertex>();

            rectContourVertices.Add(new Vertex(0.0, 0.0, 1));
            rectContourVertices.Add(new Vertex(10.0, 0.0, 2));
            rectContourVertices.Add(new Vertex(10.0, 10.0, 3));
            rectContourVertices.Add(new Vertex(0.0, 10.0, 4));
            var segmentMarking     = SegmentMarkingType.Consecutively;
            var rectangularContour = new Contour(rectContourVertices, 18, segmentMarking);

            var innerrectContourVertices = new List <Vertex>();

            innerrectContourVertices.Add(new Vertex(2.0, 4.0, 1));
            innerrectContourVertices.Add(new Vertex(8.0, 4.0, 2));
            innerrectContourVertices.Add(new Vertex(6.5, 2.2, 2));
            innerrectContourVertices.Add(new Vertex(5.2, 1.5, 3));
            innerrectContourVertices.Add(new Vertex(4.8, 1.5, 4));
            innerrectContourVertices.Add(new Vertex(3.5, 2.2, 2));

            var innerContour = new Contour(innerrectContourVertices, 37, segmentMarking);
            var polygon      = new Polygon(5, true);

            polygon.Add(new Vertex(0.0, 0.05));
            var face = Example2.Circle(5, new Point(5, 5), 0.5, 69);

            polygon.Add(face, hole: false, regionlabel: 10);
            var pointLabels   = polygon.Points.Select(p => p.Label);
            var segmentLabels = polygon.Segments.Select(s => s.Label);

            polygon.Add(rectangularContour, hole: false, regionlabel: 1);
            pointLabels   = polygon.Points.Select(p => p.Label);
            segmentLabels = polygon.Segments.Select(s => s.Label);

            polygon.Add(innerContour, hole: false, regionlabel: 45);
            pointLabels   = polygon.Points.Select(p => p.Label);
            segmentLabels = polygon.Segments.Select(s => s.Label);


            var lefteye = Example2.Circle(0.5, new Point(3, 7), 0.5, 100);

            polygon.Add(lefteye, hole: false, regionlabel: 100);
            var righteye = Example2.Circle(0.5, new Point(7, 7), 0.5, 100);

            polygon.Add(righteye, hole: false, regionlabel: 100);
            var mesh = polygon.Triangulate(new QualityOptions()
            {
                MinimumAngle = 25.0, VariableArea = true
            });

            //var mesh = polygon.Triangulate(new QualityOptions() { MinimumAngle = 30.0, MaximumArea = 0.3, VariableArea = true});
            InputGenerated(mesh, EventArgs.Empty);
        }
示例#2
0
        public static Mesh RefineRegions()
        {
            // Generate the input geometry.
            var poly = new Polygon();

            var center = new Point(0, 0);

            // Three concentric circles.
            poly.Add(Example2.Circle(1.0, center, 0.1, 1), center);
            poly.Add(Example2.Circle(2.0, center, 0.1, 2));
            poly.Add(Example2.Circle(3.0, center, 0.3, 3));

            // Define regions.
            poly.Regions.Add(new RegionPointer(1.5, 0.0, 1));
            poly.Regions.Add(new RegionPointer(2.5, 0.0, 2));

            // Set quality and constraint options.
            var options = new ConstraintOptions()
            {
                ConformingDelaunay = true
            };
            var quality = new QualityOptions()
            {
                MinimumAngle = 25.0
            };

            // Generate mesh.
            var mesh = (Mesh)poly.Triangulate(options, quality);

            var smoother = new SimpleSmoother();

            // Smooth mesh and re-apply quality options.
            smoother.Smooth(mesh);
            mesh.Refine(quality);

            // Calculate mesh quality
            var statistic = new QualityMeasure();

            statistic.Update(mesh);

            // Use the minimum triangle area for region refinement
            double area = 1.75 * statistic.AreaMinimum;

            foreach (var t in mesh.Triangles)
            {
                // Set area constraint for all triangles in region 1
                if (t.Label == 1)
                {
                    t.Area = area;
                }
            }

            // Use per triangle area constraint for next refinement
            quality.VariableArea = true;

            // Refine mesh to meet area constraint.
            mesh.Refine(quality);

            // Smooth once again.
            smoother.Smooth(mesh);

            return(mesh);
        }