예제 #1
0
        public void AdaptiveGridAddVertex()
        {
            var adaptiveGrid = new AdaptiveGrid(new Transform());
            var points       = new List <Vector3>()
            {
                new Vector3(-6, -4),
                new Vector3(-2, -4),
                new Vector3(3, -4),
                new Vector3(1, 4.5, 3),
                new Vector3(6, 3, -2),
            };

            adaptiveGrid.AddFromPolygon(Polygon.Rectangle(15, 10), points);

            ulong id;

            Assert.True(adaptiveGrid.TryGetVertexIndex(new Vector3(-2, -4), out id));
            var oldV        = adaptiveGrid.GetVertex(id);
            var edgesBefore = oldV.Edges.Count;

            var newV = adaptiveGrid.AddVertex(new Vector3(-2, -4, 2), new List <Vertex> {
                oldV
            });

            Assert.NotNull(newV);
            Assert.False(newV.Id == 0);
            Assert.Single(newV.Edges);
            Assert.True(newV.Edges.First().StartId == id || newV.Edges.First().EndId == id);
            Assert.Equal(edgesBefore + 1, oldV.Edges.Count());
            Assert.Contains(oldV.Edges, e => e.StartId == newV.Id || e.EndId == newV.Id);
        }
예제 #2
0
        public void AdaptiveGridTwoAlignedSections()
        {
            var adaptiveGrid = new AdaptiveGrid(new Transform());
            var polygon1     = Polygon.Rectangle(new Vector3(0, 0), new Vector3(10, 10));
            var polygon2     = Polygon.Rectangle(new Vector3(10, 2), new Vector3(20, 12));

            var points = new List <Vector3>();

            points.AddRange(polygon1.Vertices);
            points.AddRange(polygon2.Vertices);

            adaptiveGrid.AddFromExtrude(polygon1, Vector3.ZAxis, 2, points);
            adaptiveGrid.AddFromExtrude(polygon2, Vector3.ZAxis, 2, points);

            ulong id;

            Assert.True(adaptiveGrid.TryGetVertexIndex(new Vector3(10, 2), out id));
            var vertex = adaptiveGrid.GetVertex(id);

            //Up, North, South, East, West
            Assert.Equal(5, vertex.Edges.Count);
            Assert.True(adaptiveGrid.TryGetVertexIndex(new Vector3(10, 10), out id));
            vertex = adaptiveGrid.GetVertex(id);
            Assert.Equal(5, vertex.Edges.Count);
        }
예제 #3
0
        public void AdaptiveGridSubtractBoxCutEdges()
        {
            var adaptiveGrid = new AdaptiveGrid(new Transform());
            var polygon      = Polygon.Rectangle(new Vector3(0, 0), new Vector3(10, 10));

            var points = new List <Vector3>();

            for (int i = 1; i < 10; i++)
            {
                points.Add(new Vector3(i, i, 1));
            }

            adaptiveGrid.AddFromExtrude(polygon, Vector3.ZAxis, 2, points);
            Assert.True(adaptiveGrid.TryGetVertexIndex(new Vector3(5, 5, 1), out _));
            Assert.False(adaptiveGrid.TryGetVertexIndex(new Vector3(5, 4.9, 1), out _));

            adaptiveGrid.TryGetVertexIndex(new Vector3(5, 4, 1), out var borderId);
            var borderV     = adaptiveGrid.GetVertex(borderId);
            var numEdges    = borderV.Edges.Count;
            var numVertices = adaptiveGrid.GetVertices().Count;

            var box = new BBox3(new Vector3(4.9, 4.9, 0), new Vector3(5.1, 5.1, 2));

            adaptiveGrid.SubtractBox(box, true);
            Assert.False(adaptiveGrid.TryGetVertexIndex(new Vector3(5, 5, 1), out _));
            Assert.False(adaptiveGrid.TryGetVertexIndex(new Vector3(5, 4.9, 1), out _));

            Assert.Equal(numEdges - 1, borderV.Edges.Count);
            //On each elevation one vertex is removed and no added
            Assert.Equal(numVertices - (3 * 1), adaptiveGrid.GetVertices().Count);
        }
예제 #4
0
 public AdaptiveGridArchive(int maxSize, int bisections, int objectives)
     : base(maxSize)
 {
     _maxSize = maxSize;
     _dominance = new DominanceComparator();
     Grid = new AdaptiveGrid(bisections, objectives);
 }
예제 #5
0
        public void AdaptiveGridSubtractBoxKeepEdges()
        {
            var adaptiveGrid = new AdaptiveGrid(new Transform());
            var polygon      = Polygon.Rectangle(new Vector3(0, 0), new Vector3(10, 10));

            var points = new List <Vector3>();

            for (int i = 1; i < 10; i++)
            {
                points.Add(new Vector3(i, i, 1));
            }
            adaptiveGrid.AddFromExtrude(polygon, Vector3.ZAxis, 2, points);
            Assert.True(adaptiveGrid.TryGetVertexIndex(new Vector3(5, 5, 1), out _));
            Assert.False(adaptiveGrid.TryGetVertexIndex(new Vector3(5, 4.9, 1), out _));
            var numVertices = adaptiveGrid.GetVertices().Count;

            var box = new BBox3(new Vector3(4.9, 4.9, 0), new Vector3(5.1, 5.1, 2));

            adaptiveGrid.SubtractBox(box, false);
            Assert.False(adaptiveGrid.TryGetVertexIndex(new Vector3(5, 5, 1), out _));
            Assert.True(adaptiveGrid.TryGetVertexIndex(new Vector3(5, 4.9, 1), out var cutEdgeId));

            var v = adaptiveGrid.GetVertex(cutEdgeId);

            Assert.Single(v.Edges);
            adaptiveGrid.TryGetVertexIndex(new Vector3(5, 4, 1), out var borderId);
            Assert.True(v.Edges.First().StartId == borderId || v.Edges.First().EndId == borderId);
            //On each elevation one vertex is removed but 4 added
            Assert.Equal(numVertices + (3 * (4 - 1)), adaptiveGrid.GetVertices().Count);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maxSize">The maximum size of the archive</param>
 /// <param name="bisections">The maximum number of bi-divisions for the adaptive grid.</param>
 /// <param name="objectives">The number of objectives.</param>
 public AdaptiveGridArchive(int maxSize, int bisections, int objectives)
     : base(maxSize)
 {
     this.maxSize = maxSize;
     dominance    = new DominanceComparator();
     Grid         = new AdaptiveGrid(bisections, objectives);
 }
예제 #7
0
        public void AdaptiveGridLongSectionDoNowThrow()
        {
            var adaptiveGrid = new AdaptiveGrid(new Transform());
            var polygon      = Polygon.Rectangle(new Vector3(0, 0), new Vector3(200000, 10));

            var points = new List <Vector3>();

            points.Add(new Vector3(1, 5));
            points.Add(new Vector3(1999, 5));

            adaptiveGrid.AddFromExtrude(polygon, Vector3.ZAxis, 2, points);
        }
예제 #8
0
        public void AdaptiveGridBboxKeyPointsExample()
        {
            this.Name = "Elements_Spatial_AdaptiveGrid_AdaptiveGridBboxKeyPoints";
            var random = new Random();

            var adaptiveGrid = new AdaptiveGrid(new Transform());
            var points       = new List <Vector3>()
            {
                new Vector3(-6, -4),
                new Vector3(-2, -4),
                new Vector3(3, -4),
                new Vector3(1, 4.5, 3),
                new Vector3(6, 3, -2),
            };

            adaptiveGrid.AddFromBbox(new BBox3(new Vector3(-7.5, -5, -3), new Vector3(10, 10, 3)), points);

            points = new List <Vector3>()
            {
                new Vector3(-6, -4, 3),
                new Vector3(-2, 0, 3),
                new Vector3(0, 4, 3),
                new Vector3(2, 6, 3)
            };
            var rectangle = Polygon.Rectangle(new Vector3(-10, -5), new Vector3(15, 10));

            adaptiveGrid.AddFromPolygon(rectangle.TransformedPolygon(new Transform(new Vector3(0, 0, 3))), points);
            points = new List <Vector3>()
            {
                new Vector3(-6, -4, 2),
                new Vector3(-2, 0, 2),
                new Vector3(0, 4, 2),
                new Vector3(2, 6, 2)
            };
            adaptiveGrid.AddFromPolygon(rectangle.TransformedPolygon(new Transform(new Vector3(0, 0, 2))), points);

            foreach (var edge in adaptiveGrid.GetEdges())
            {
                Model.AddElement(new ModelCurve(edge.GetGeometry(), material: random.NextMaterial()));
            }
        }
예제 #9
0
        public void AdaptiveGridSubtractBoxSmallDifference()
        {
            var adaptiveGrid = new AdaptiveGrid(new Transform());
            var polygon      = Polygon.Rectangle(new Vector3(-41, -51), new Vector3(-39, -49));

            var points = new List <Vector3>();

            points.Add(new Vector3(-40, -49.9, 1));
            points.Add(new Vector3(-40, -49.80979, 1));

            adaptiveGrid.AddFromExtrude(polygon, Vector3.ZAxis, 2, points);
            Assert.True(adaptiveGrid.TryGetVertexIndex(new Vector3(-40, -49.9, 1), out _));
            Assert.True(adaptiveGrid.TryGetVertexIndex(new Vector3(-40, -49.9, 2), out _));

            var box = new BBox3(new Vector3(-40.2, -50.190211303259034, 0),
                                new Vector3(-39.8, -49.809788696740966, 2));

            adaptiveGrid.SubtractBox(box);
            Assert.False(adaptiveGrid.TryGetVertexIndex(new Vector3(-40, -49.9, 1), out _));
            Assert.False(adaptiveGrid.TryGetVertexIndex(new Vector3(-40, -49.9, 2), out _));
        }
예제 #10
0
        public void AdaptiveGridDoesntAddTheSameVertex()
        {
            var adaptiveGrid = new AdaptiveGrid(new Transform());
            var polygon      = Polygon.Rectangle(new Vector3(0, 0), new Vector3(10, 10));

            adaptiveGrid.AddFromPolygon(polygon, new List <Vector3>());
            Assert.True(adaptiveGrid.TryGetVertexIndex(new Vector3(0, 10), out var id));
            var vertex   = adaptiveGrid.GetVertex(id);
            var halfTol  = adaptiveGrid.Tolerance / 2;
            var modified = vertex.Point + new Vector3(0, 0, halfTol);

            adaptiveGrid.TryGetVertexIndex(new Vector3(10, 0), out var otherId);
            var newVertex = adaptiveGrid.AddVertex(modified,
                                                   new List <Vertex> {
                adaptiveGrid.GetVertex(otherId)
            });

            Assert.Equal(id, newVertex.Id);
            modified = vertex.Point + new Vector3(-halfTol, -halfTol, -halfTol);
            adaptiveGrid.TryGetVertexIndex(modified, out otherId, adaptiveGrid.Tolerance);
            Assert.Equal(id, otherId);
        }
예제 #11
0
        public void AdaptiveGridPolygonKeyPointsExample()
        {
            this.Name = "Elements_Spatial_AdaptiveGrid_AdaptiveGridPolygonKeyPoints";
            var random = new Random();

            var adaptiveGrid = new AdaptiveGrid(new Transform());
            var points       = new List <Vector3>()
            {
                new Vector3(-6, -4),
                new Vector3(-2, -4),
                new Vector3(3, -4),
                new Vector3(1, 4.5),
                new Vector3(6, 3),
            };

            adaptiveGrid.AddFromPolygon(Polygon.Rectangle(15, 10).TransformedPolygon(
                                            new Transform(new Vector3(), new Vector3(10, 0, 10))), points);

            foreach (var edge in adaptiveGrid.GetEdges())
            {
                Model.AddElement(new ModelCurve(edge.GetGeometry(), material: random.NextMaterial()));
            }
        }
        private static FrameworkElement GenerateGroup(
            AdaptiveGroup group,
            bool isFirstGroup,
            bool needsImageMargin,
            Thickness externalMargin)
        {
            if (group.Subgroups.Count == 0)
            {
                return(null);
            }

            double topMarginOffset = 0;

            if (!isFirstGroup)
            {
                topMarginOffset = GetSubgroupsTopMarginOffset(group.Subgroups);
            }

            if (needsImageMargin)
            {
                // Ensure that top margin will be at least the image margin, even though we haven't an image
                if (topMarginOffset < AdaptiveConstants.DefaultImageMargin)
                {
                    topMarginOffset = AdaptiveConstants.DefaultImageMargin;
                }
            }

            Thickness groupMargin = new Thickness(
                0,
                isFirstGroup ? 0.0 : AdaptiveConstants.DefaultGroupTopMargin,
                0,
                0);

            if (group.Subgroups.Count == 1)
            {
                AdaptiveStackPanel sp = GenerateSubgroup(
                    subgroup: group.Subgroups[0],
                    isFirstGroup: isFirstGroup,
                    topMarginOffset: topMarginOffset,
                    externalMargin: externalMargin);

                sp.Margin = new Thickness(
                    sp.Margin.Left,
                    sp.Margin.Top + groupMargin.Top,
                    sp.Margin.Right,
                    sp.Margin.Bottom);

                if (group.ActionId != null)
                {
                    sp.Background = GetActionBackgroundBrush();
                }

                return(sp);
            }

            else
            {
                Grid g = new AdaptiveGrid()
                {
                    Margin = groupMargin
                };

                // Get the calculated weights
                int[] weights = CalculateWeights(group.Subgroups);


                for (int i = 0; i < group.Subgroups.Count; i++)
                {
                    var subgroup = group.Subgroups[i];
                    int weight   = weights[i];

                    //add column for the subgroup
                    g.ColumnDefinitions.Add(new ColumnDefinition()
                    {
                        Width = weight == AdaptiveSubgroup.WEIGHT_AUTO ? GridLength.Auto : new GridLength(weight, GridUnitType.Star)
                    });

                    //and create the subgroup visual
                    var subgroupEl = GenerateSubgroup(subgroup, isFirstGroup, topMarginOffset, externalMargin);
                    Grid.SetColumn(subgroupEl, g.ColumnDefinitions.Count - 1); //assign it to this column

                    //set text stacking
                    switch (subgroup.HintTextStacking)
                    {
                    case HintTextStacking.Bottom:
                        subgroupEl.VerticalAlignment = VerticalAlignment.Bottom;
                        break;

                    case HintTextStacking.Center:
                        subgroupEl.VerticalAlignment = VerticalAlignment.Center;
                        break;
                    }

                    //and then add that subgroup visual to the group visual
                    g.Children.Add(subgroupEl);

                    //always add 8 pixel padding between columns (but not on the right, last, side)
                    if (i != group.Subgroups.Count - 1)
                    {
                        g.ColumnDefinitions.Add(new ColumnDefinition()
                        {
                            Width = new GridLength(8)
                        });
                    }

                    if (subgroup.ActionId != null)
                    {
                        subgroupEl.Background = GetActionBackgroundBrush();
                    }
                }

                if (group.ActionId != null)
                {
                    g.Background = GetActionBackgroundBrush();
                }

                return(g);
            }
        }
예제 #13
0
 private void Cancel_OnClick(object sender, RoutedEventArgs e)
 {
     AdaptiveGrid.DeselectRange(new ItemIndexRange(0, (uint)AdaptiveGrid.Items.Count));
 }
예제 #14
0
 private void SelectAll_OnClick(object sender, RoutedEventArgs e)
 {
     AdaptiveGrid.SelectAll();
 }