public VoronoiGrid CreateGrid(List <T> nodes, int firstCornerNodeIndice) { CreateMesh(nodes, firstCornerNodeIndice); VoronoiGrid grid = gridConverter.ConvertToVoronoiGrid(mesh); return(grid); }
public void LShapePeriodicBoundaries() { byte[] tags = { 1, 1, 181, 1, 1, 181 }; SortedList <byte, string> tagNames = new SortedList <byte, string>(2) { { 1, "Dirichlet" }, { 181, "Periodic" } }; MultidimensionalArray nodes = MultidimensionalArray.Create(6, 2); nodes.SetRow(0, new double[] { -0.5, 0.5 }); nodes.SetRow(1, new double[] { -0.8, -0.4 }); nodes.SetRow(2, new double[] { 0, 0 }); nodes.SetRow(3, new double[] { 0.8, 0.8 }); nodes.SetRow(4, new double[] { 0.9, 0.2 }); nodes.SetRow(5, new double[] { 0.5, -0.6 }); VoronoiBoundary gridBoundary = new VoronoiBoundary { Polygon = GridShapes.LShape(), EdgeTags = tags, EdgeTagNames = tagNames }; VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 1); }
public void SetBoundaryTags() { byte[] tags = { 1, 1, 1, 1 }; SortedList <byte, string> tagNames = new SortedList <byte, string>(1); tagNames.Add(1, "A"); VoronoiBoundary rectangle = new VoronoiBoundary { Polygon = GridShapes.Rectangle(2, 2), EdgeTags = tags, EdgeTagNames = tagNames }; MultidimensionalArray nodes = MultidimensionalArray.Create(5, 2); nodes.SetRow(0, new double[] { -0.5, 0.5 }); nodes.SetRow(1, new double[] { -0.8, -0.4 }); nodes.SetRow(2, new double[] { 0, 0 }); nodes.SetRow(3, new double[] { 0.8, 0.4 }); nodes.SetRow(4, new double[] { 0.5, -0.5 }); VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, rectangle, 10, 0); bool tagsAreCorrect = CheckAllBoundaryTagsAre(1, grid.iGridData); Assert.IsTrue(tagsAreCorrect); }
public void AllPeriodicBoundariesOutside() { byte[] tags = { 182, 181, 182, 181 }; SortedList <byte, string> tagNames = new SortedList <byte, string>(2) { { 181, "Periodic-X" }, { 182, "Periodic-Y" } }; VoronoiBoundary gridBoundary = new VoronoiBoundary { Polygon = GridShapes.Rectangle(2, 2), EdgeTags = tags, EdgeTagNames = tagNames }; MultidimensionalArray nodes = MultidimensionalArray.Create(6, 2); nodes.SetRow(0, new double[] { -1.1, 1.1 }); nodes.SetRow(1, new double[] { 0.6, 1.4 }); nodes.SetRow(2, new double[] { 0, 0 }); nodes.SetRow(3, new double[] { 1, -0.9 }); nodes.SetRow(4, new double[] { -0.9, -1.2 }); nodes.SetRow(5, new double[] { -1.1, 0.2 }); VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 10, 0); }
public void Shift() { double offset = 1e-7; MultidimensionalArray nodes = MultidimensionalArray.Create(6, 2); nodes.SetRowPt(0, new Vector(0.5 + offset, 0.5)); nodes.SetRowPt(1, new Vector(-0.5 + offset, 0.5)); nodes.SetRowPt(2, new Vector(0.5 - offset, -0.5)); nodes.SetRowPt(3, new Vector(-0.5 - offset, -0.5)); nodes.SetRowPt(4, new Vector(0, -0.5)); nodes.SetRowPt(5, new Vector(0, 0.5)); // ### Grid byte[] tags = { 1, 181, 1, 181 }; SortedList <byte, string> tagNames = new SortedList <byte, string>(2) { { 1, "AdiabaticSlipWall" }, { 181, "Periodic-X" } }; var gridBoundary = new VoronoiBoundary { Polygon = GridShapes.Rectangle(2, 2), EdgeTags = tags, EdgeTagNames = tagNames }; VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0); }
public VoronoiGrid CreateGrid(VoronoiNodes nodes, int firstCornerNodeIndice) { List <Node> mesherNodes = WrapInMesherNodes(nodes.Nodes); VoronoiGrid grid = CreateGrid(mesherNodes, firstCornerNodeIndice); return(grid); }
public void PeriodicPairSkewCheckerBoard() { byte[] tags = { 1, 181, 1, 181 }; SortedList <byte, string> tagNames = new SortedList <byte, string>(2) { { 181, "Periodic-X" }, { 1, "Dirichlet" } }; VoronoiBoundary gridBoundary = new VoronoiBoundary { Polygon = GridShapes.Rectangle(2, 2), EdgeTags = tags, EdgeTagNames = tagNames }; MultidimensionalArray nodes = MultidimensionalArray.Create(6, 2); nodes.SetRow(0, new double[] { -0.71, 0.7 }); nodes.SetRow(1, new double[] { 0.8, 0.7 }); nodes.SetRow(2, new double[] { 0, 0.5 }); nodes.SetRow(3, new double[] { -0.7, -0.7 }); nodes.SetRow(4, new double[] { 0.7, -0.7 }); nodes.SetRow(5, new double[] { 0, -0.5 }); VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0); }
public void PeriodicPairCheckerBoard() { // ### Grid byte[] tags = { 1, 181, 1, 181 }; SortedList <byte, string> tagNames = new SortedList <byte, string>(2) { { 1, "AdiabaticSlipWall" }, { 181, "Periodic-X" } }; var gridBoundary = new VoronoiBoundary { Polygon = GridShapes.Rectangle(1, 0.5), EdgeTags = tags, EdgeTagNames = tagNames }; double[] xTics = GenericBlas.Linspace(-0.5, 0.5, 3); double[] yTics = GenericBlas.Linspace(-0.25, 0.25, 5); for (int i = 0; i < yTics.Length; ++i) { yTics[i] *= -1; } MultidimensionalArray nodes = Checkerize(xTics, yTics); VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0); Plotter.Plot(grid); }
public void Large() { var rectangle = GridShapes.Rectangle(2, 2); VoronoiGrid grid = VoronoiGrid2D.Polygonal(rectangle, 0, 10000); Plotter.Plot(grid); }
public VoronoiGrid CreateGrid(VoronoiNodes nodes, Settings settings) { List <Node> mesherNodes = WrapInMesherNodes(nodes.Nodes); BoundaryMesh <Node> mesh = CreateMesh(mesherNodes, settings); VoronoiGrid grid = Convert2VoronoiGrid(mesh, settings); return(grid); }
public void CornerSpeziale() { MultidimensionalArray nodes1 = MultidimensionalArray.Create(3, 2); nodes1.SetRowPt(0, new Vector(-1, 1)); nodes1.SetRowPt(1, new Vector(1, 1)); nodes1.SetRowPt(2, new Vector(-1, -1)); VoronoiGrid grid1 = VoronoiGrid2D.Polygonal(nodes1, GridShapes.Rectangle(2, 2), 0, 0); }
public void SomeEdgesOnBoundary() { MultidimensionalArray nodes1 = MultidimensionalArray.Create(4, 2); nodes1.SetRowPt(0, new Vector(0, 2)); nodes1.SetRowPt(1, new Vector(0, 0)); nodes1.SetRowPt(2, new Vector(-1, 0)); nodes1.SetRowPt(3, new Vector(-1, -1)); VoronoiGrid grid1 = VoronoiGrid2D.Polygonal(nodes1, GridShapes.Rectangle(2, 2), 0, 0); }
static VoronoiGrid CreateVoronoiGrid() { Vector[] DomainBndyPolygon = new[] { new Vector(-1, 1), new Vector(1, 1), new Vector(1, -1), new Vector(-1, -1) }; VoronoiGrid grid = VoronoiGrid2D.Polygonal(DomainBndyPolygon, 0, 400); return(grid); }
public VoronoiGrid ConvertToVoronoiGrid( IMesh <T> mesh) { boundaryConverter.Clear(); (GridCommons grid, int[][] aggregation) = ExtractGridCommonsAndCellAggregation(mesh.Cells, boundaryConverter); VoronoiNodes nodes = ExtractVoronoiNodes(mesh); VoronoiGrid voronoiGrid = new VoronoiGrid(grid, aggregation, nodes, boundary); voronoiGrid.FirstCornerNodeIndice = mesh.CornerNodeIndice; return(voronoiGrid); }
public void Remap() { byte[] tags = { 1, 181, 1, 181 }; SortedList <byte, string> tagNames = new SortedList <byte, string>(2) { { 181, "Periodic-X" }, { 1, "bondary" } }; VoronoiBoundary gridBoundary = new VoronoiBoundary { Polygon = GridShapes.Rectangle(2, 2), EdgeTags = tags, EdgeTagNames = tagNames }; double[] positions = new double[] { -0.64874644688322713, 0.83818004313993111, -0.39475947428553138, 0.23663302374998896, 0.58922918492853482, 0.83854511946848365, -0.811382461267156, -0.4159610860057516, -0.19666215667077264, -0.24376388607043981, 0.3385324063754323, 0.086134041417832763, 0.80498108279434089, 0.22350558445791927, -0.68131747598283521, -0.87257764806623139, 0.48863086193005234, -0.51183362983054159, 0.99309783411349173, -0.10141430352239808, }; MultidimensionalArray nodes = MultidimensionalArray.CreateWrapper(positions, 10, 2); for (int i = 0; i < 10; ++i) { nodes[i, 0] += 0.01; } VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0); Plotter.Plot(grid); }
public void EquidistandGrid() { double offset = 1e-7; MultidimensionalArray nodes = MultidimensionalArray.Create(4, 2); nodes.SetRowPt(0, new Vector(0.5 + offset, 0.5)); nodes.SetRowPt(1, new Vector(-0.5 + offset, 0.5)); nodes.SetRowPt(2, new Vector(0.5, -0.5)); nodes.SetRowPt(3, new Vector(-0.5, -0.5)); VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, GridShapes.Rectangle(2, 2), 0, 1); Plotter.Plot(grid); }
public void OnlyEdgesOnBoundary() { MultidimensionalArray nodes1 = MultidimensionalArray.Create(8, 2); nodes1.SetRowPt(0, new Vector(0, 1.5)); nodes1.SetRowPt(1, new Vector(-0.5, 0)); nodes1.SetRowPt(2, new Vector(0, -0.5)); nodes1.SetRowPt(3, new Vector(0.5, 0)); nodes1.SetRowPt(4, new Vector(0, 0.5)); nodes1.SetRowPt(5, new Vector(1.5, 0)); nodes1.SetRowPt(6, new Vector(-1.5, 0)); nodes1.SetRowPt(7, new Vector(0, -1.5)); VoronoiGrid grid1 = VoronoiGrid2D.Polygonal(nodes1, GridShapes.Rectangle(2, 2), 0, 1); }
public static VoronoiGrid Convert2VoronoiGrid <T>(BoundaryMesh <T> mesh, VoronoiInfo info) where T : IVoronoiNodeCastable { IReadOnlyList <MeshCell <T> > cells = mesh.GetCells(); (GridCommons grid, int[][] aggregation) = ExtractGridCommonsAndCellAggregation(cells); IList <T> nodeList = mesh.GetNodes(); IList <VoronoiNode> voronoiNodeList = Cast(nodeList); VoronoiNodes nodes = new VoronoiNodes(voronoiNodeList); VoronoiGrid voronoiGrid = new VoronoiGrid(grid, aggregation, nodes, info); return(voronoiGrid); }
public MappedVoronoiGrid CreateGrid(VoronoiNodes nodes, int firstCornerNodeIndice) { List <TrackableNode> mesherNodes = WrapInMesherNodes(nodes.Nodes); VoronoiGrid grid = CreateGrid(mesherNodes, firstCornerNodeIndice); ConnectionMap resultMap = ExtractMap(base.mesh.Nodes); ConnectionMap inputMap = GetInputMap(resultMap, nodes.Count); MappedVoronoiGrid movingGrid = new MappedVoronoiGrid { Result = grid, InputNodesToResultNodes = inputMap, ResultNodesToInputNodes = resultMap }; return(movingGrid); }
public TrackedVoronoiGrid CreateGrid(VoronoiNodes nodes, Settings settings) { List <TrackableNode> mesherNodes = WrapInMesherNodes(nodes.Nodes); BoundaryMesh <TrackableNode> mesh = CreateMesh(mesherNodes, settings); VoronoiGrid grid = Convert2VoronoiGrid(mesh, settings); OneWayArrayMap resultMap = ExtractMap(mesh.GetNodes()); OneWayArrayMap inputMap = GetInputMap(resultMap, nodes.Count); TrackedVoronoiGrid movingGrid = new TrackedVoronoiGrid { Result = grid, InputNodesToResultNodes = inputMap, ResultNodesToInputNodes = resultMap }; return(movingGrid); }
public void FShape() { byte[] tags = { 1, 181, 1, 1, 1, 182, 1, 1, 181, 1, 1, 182, 1, 1 }; SortedList <byte, string> tagNames = new SortedList <byte, string>(2) { { 1, "Dirichlet" }, { 181, "Periodic" } }; VoronoiBoundary gridBoundary = new VoronoiBoundary { Polygon = GridShapes.FShape(), EdgeTags = tags, EdgeTagNames = tagNames }; VoronoiGrid grid = VoronoiGrid2D.Polygonal(gridBoundary, 40, 500); }
public void PeriodicBoundaryPairBoundaryOnEdge() { byte[] tags = { 1, 181, 1, 181 }; SortedList <byte, string> tagNames = new SortedList <byte, string>(2) { { 181, "Periodic-X" }, { 1, "Dirichlet" } }; MultidimensionalArray nodes = MultidimensionalArray.Create(6, 2); nodes.SetRowPt(0, new Vector(-0.8, 0.6)); nodes.SetRowPt(1, new Vector(-0.8, -0.6)); nodes.SetRowPt(2, new Vector(-0.2, 0.0)); nodes.SetRowPt(3, new Vector(0.2, 0.0)); nodes.SetRowPt(4, new Vector(0.8, 0.6)); nodes.SetRowPt(5, new Vector(0.8, -0.6)); VoronoiBoundary gridBoundary = new VoronoiBoundary { Polygon = GridShapes.Rectangle(2, 2), EdgeTags = tags, EdgeTagNames = tagNames }; VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0); }
public void PeriodicBoundaryPairLarge() { byte[] tags = { 1, 181, 1, 181 }; SortedList <byte, string> tagNames = new SortedList <byte, string>(2) { { 181, "Periodic-X" }, { 1, "Dirichlet" } }; VoronoiBoundary gridBoundary = new VoronoiBoundary { Polygon = GridShapes.Rectangle(8, 8), EdgeTags = tags, EdgeTagNames = tagNames }; Random random = new Random(10); MultidimensionalArray nodes = default(MultidimensionalArray); for (int i = 0; i < 10; i += 1) { Console.WriteLine($"Roll number{i}"); nodes = RandomNodesInSquare(4.09, 4.0, 300, random); nodes[0, 0] = -1 + 1e-5; nodes[0, 1] = 1 - 1e-5; try { VoronoiGrid garid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0); } catch (Exception e) { Console.WriteLine(e); } } //VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0); //Plotter.Plot(grid); }
public void AllPeriodicBoundariesLarge() { byte[] tags = { 182, 181, 182, 181 }; SortedList <byte, string> tagNames = new SortedList <byte, string>(2) { { 181, "Periodic-X" }, { 182, "Periodic-Y" } }; VoronoiBoundary gridBoundary = new VoronoiBoundary { Polygon = GridShapes.Rectangle(2, 2), EdgeTags = tags, EdgeTagNames = tagNames }; Random random = new Random(1); MultidimensionalArray nodes = default(MultidimensionalArray); for (int i = 0; i < 48; ++i) { Console.WriteLine($"Roll number {i}"); nodes = RandomNodesInSquare(1.0, 1.0, 300, random); nodes[0, 0] = -1 + 1e-6; nodes[0, 1] = 1 - 1e-6; try { //VoronoiGrid garid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0); //Plotter.Plot(grid); } catch (Exception e) { Console.WriteLine(e); } } VoronoiGrid grid = VoronoiGrid2D.Polygonal(nodes, gridBoundary, 0, 0); }
internal VoronoiGrid Convert2VoronoiGrid(BoundaryMesh <T> mesh, Settings settings) { VoronoiGrid grid = GridConverter.Convert2VoronoiGrid(mesh, settings.GridInfo); return(grid); }
public override void OnInspectorGUI() { VoronoiGrid grid = (VoronoiGrid)target; #region Seed EditorGUI.BeginChangeCheck(); grid.UseRandomSeed = EditorGUILayout.Toggle("Random Seed", grid.UseRandomSeed); EditorGUI.BeginDisabledGroup(grid.UseRandomSeed); grid.Seed = EditorGUILayout.IntField("Seed", grid.Seed); EditorGUI.EndDisabledGroup(); if (EditorGUI.EndChangeCheck()) { if (grid.Seed < 0) { grid.Seed = 0; } } #endregion #region Grid Properties EditorGUI.BeginChangeCheck(); grid.Radius = EditorGUILayout.FloatField("Sphere Radius", grid.Radius); EditorGUI.BeginDisabledGroup(grid.OverrideCellCount); grid.CellSize = EditorGUILayout.FloatField("Cell Size", grid.CellSize); EditorGUI.EndDisabledGroup(); grid.OverrideCellCount = EditorGUILayout.Toggle("Override Cell Count", grid.OverrideCellCount); EditorGUI.BeginDisabledGroup(!grid.OverrideCellCount); grid.CellCount = EditorGUILayout.IntField("Cell Count", grid.CellCount); EditorGUI.EndDisabledGroup(); if (EditorGUI.EndChangeCheck()) { if (grid.Radius < Mathf.Epsilon) { grid.Radius = Mathf.Epsilon; } if (grid.CellSize < Mathf.Epsilon) { grid.CellSize = Mathf.Epsilon; } if (!grid.OverrideCellCount) { grid.CellCount = Mathf.RoundToInt(4 * Mathf.PI * grid.Radius * grid.Radius / grid.CellSize); } else if (grid.CellCount < 4) { grid.CellCount = 4; } } #endregion #region Relaxation EditorGUI.BeginChangeCheck(); grid.RelaxationShader = (ComputeShader)EditorGUILayout.ObjectField("Relaxation Shader", grid.RelaxationShader, typeof(ComputeShader), true); grid.RelaxationSteps = EditorGUILayout.IntField("Relaxation Steps", grid.RelaxationSteps); if (EditorGUI.EndChangeCheck()) { if (grid.RelaxationSteps < 0) { grid.RelaxationSteps = 0; } } #endregion #region Color grid.DefaultColor = EditorGUILayout.ColorField("Default Color", grid.DefaultColor); #endregion #region Noise grid.NoiseSource = (Texture2D)EditorGUILayout.ObjectField("Noise Source", grid.NoiseSource, typeof(Texture2D), true); #endregion #region Prefabs grid.CellPrefab = (VoronoiCell)EditorGUILayout.ObjectField("Cell Prefab", grid.CellPrefab, typeof(VoronoiCell), true); grid.ChunkPrefab = (VoronoiGridChunk)EditorGUILayout.ObjectField("Chunk Prefab", grid.ChunkPrefab, typeof(VoronoiGridChunk), true); #endregion #region Generate if (GUILayout.Button("Generate Grid")) { if (EditorApplication.isPlaying) { if (grid.UseRandomSeed) { grid.Seed = Random.Range(0, int.MaxValue); } grid.StartCoroutine(grid.Generate()); } else { Debug.LogError("Cannot generate grid outside of play mode."); } } #endregion }